Repository navigation
fix(dispatch): stop blocking tasks when the Claude API refuses a session - #13
Merged
Merged
Conversation
A usage limit and a safeguard flag both end `claude -p` with subtype "success" and no outcome. Foreman read either one as "the session ended without an outcome", resumed it three times into the same refusal, and then blocked the issue with "success after retries". Two of those blocks held a whole phase through `limits.blockedPerPhase`. - `src/session-end.ts` holds `classifyEnd`, the only place that matches the API's wording. It returns usage_limit, safeguard or other, the request id, and the reset time from the rate-limit event. - Usage limit: no retry and no block. The claim stays open, as after `stop`, with one note on the issue. Dispatching pauses until the reset plus 2 minutes, or 30 minutes when the reset is unknown. The pause is persisted as `pausedUntil`/`pauseReason`, kept across a restart, refused by preflight, slept on by the tick loop, shown in `status` and on the page, and cleared by `go`. A session that returns an outcome as its window runs out also pauses the next one. - Safeguard flag: the flagged session id is never resumed. One retry runs as a new session in the same worktree, and its prompt says the earlier work is already there. A second flag blocks the issue with "safeguard flag on 2 sessions (req_…)". - Other: unchanged, including the "<subtype> after retries" wording. - The stream fold keeps the seven-day reset, a seven-day-only event, and the synthetic message's `error` field, and never reports a 1970 reset. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JrFSqqRUhJMJH3aK6TDP69
…tick lastApiError - A safeguard flag on the last allowed attempt, or with `limits.attempts: 1`, now still gets its one fresh session instead of blocking after one flag. - `activity.lastApiError` is set per assistant message, so an error the session recovered from no longer reads as a usage limit when the session ends for some other reason. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JrFSqqRUhJMJH3aK6TDP69
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On 2026-11-09 the API stopped two builder sessions: a usage limit (#794) and a safeguard flag. Both
claude -presults reportedsubtype: "success"with no outcome. Foreman treated each as "session ended without outcome" and resumed it 3 times. Every resume got the same refusal. It then labelled the issueblockedwith the comment "success after retries". Withlimits.blockedPerPhase: 2, these two false blocks held the whole phase until someone stepped in.Change
src/session-end.ts:classifyEnd(result, activity)returnsusage_limit,safeguardorother, plus the request id and the reset time. It holds every match on the API's wording. It does not look atsubtype.limits.attempts.stop: assignee, worktree and session id are all kept. One note goes on the issue, and the first tick after the reset resumes the session with its context.resetsAtplus 2 minutes, or for 30 minutes when the reset time is unknown. The pause is saved aspausedUntil/pauseReasonin state.json and is kept across a restart.runForeversleeps until the pause ends.go(from the page, fromctl govia SIGUSR2, or written to state.json when no daemon is running) clears it.foreman statusand the page showpaused: usage limit until 22:52Z.--session-id, new id) in the same worktree. Its prompt says the earlier work, committed and uncommitted, is already there.safeguard flag on 2 sessions (req_…).<subtype> after retrieswording.stream.ts)errorfield for each message.Decisions for review
reviewer:changes/validator:failedremoved byprepareSession. Releasing the claim would leave nothing to queue that fix round again. Resuming the session also keeps its context.go.Not verified
test/fixtures/refusal-*.jsonlare built from foreman's normalized activity logs. No raw stream-json from a refusal was on disk.resultline setsis_erroris unconfirmed."status":"rejected"field in the rate-limit event is a guess.error: "rate_limit"field on the synthetic message comes from real transcripts.Testing
pnpm lint && pnpm typecheck && pnpm testpass (746 tests). New tests cover:classifyEndfor all three causes, and for a session that ends with neither refusal text.pausedUntil.goclearing the pause.🤖 Generated with Claude Code
https://claude.ai/code/session_01JrFSqqRUhJMJH3aK6TDP69