Skip to content

IsTerminal must not kill the turn on recoverable failures - #9

Open
timothyerwin wants to merge 1 commit into
mainfrom
fix-worker-fatal-classification
Open

IsTerminal must not kill the turn on recoverable failures#9
timothyerwin wants to merge 1 commit into
mainfrom
fix-worker-fatal-classification

Conversation

@timothyerwin

Copy link
Copy Markdown
Contributor

A real bug in v0.31.0, found while setting up a test PR to verify the reviewer.

The bug

v0.31.0 added IsTerminal so a delegated worker's terminal failure ends the turn instead of coming back as a retryable tool error the model retries forever. It was written as a one-line alias:

func IsTerminal(err error) bool { return err != nil && terminalForFallback(err) }

But those two functions answer different questions.

terminalForFallback asks "should the fallback walk stop here?" Several of its cases stop the walk precisely because something else recovers them:

cause what actually recovers it
ErrContextOverflow compact-and-retry in runLoop
ErrStreamIncomplete same-call transport retry
ErrLaneExhausted raises the user's fallback-choice card

IsTerminal asks the narrower question: "does this end the turn?" Aliasing them means a worker that merely overflowed its context now kills the parent turn instead of compacting — replacing a working recovery with a hard failure.

The irony is that the failure would look like a sub-agent dying abruptly on a long task, which is close to the hang this classification was added to prevent.

The fix

IsTerminal excludes the recoverable causes explicitly, then defers to terminalForFallback for the rest. Request-shape 4xx, auth, and billing states stay terminal; overflow, stream cuts, rate limits, 5xx and transport failures do not.

Verification

The new table test fails against the shipped v0.31.0 build (context overflow and incomplete stream both report IsTerminal = true) and passes here. Full gate clean: gofmt, go vet, go test -race ./....

Why this PR exists

Opened partly as a live end-to-end check that PR review works again after the Gemini thought-signature fix chain (#8, released as v0.31.0, reviewer image rebuilt at that tag). It turned into a real fix, which is a better test than a dummy edit.

IsTerminal was an alias for terminalForFallback, but the two answer different
questions. terminalForFallback asks "should the fallback walk stop here?", and
several of its cases stop the walk precisely BECAUSE something else recovers
them: a context overflow compacts and retries, an incomplete stream retries the
same call, an exhausted lane raises the user's fallback-choice card.

IsTerminal decides whether a delegated worker's failure ENDS THE TURN, which is
strictly narrower. As written, a worker that merely overflowed its context would
kill the parent turn instead of compacting — replacing a working recovery with a
hard failure, and looking very much like the hang this classification was added
to prevent.

Shipped in v0.31.0; the new table test fails against that build and passes here.

@memcode-ai memcode-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Walkthrough

Separates IsTerminal from terminalForFallback so recoverable errors do not abort the parent agent turn. Worker failures caused by context overflow, incomplete streams, or exhausted lanes now remain recoverable rather than triggering turn-fatal errors.

  • Explicitly filters out wire.ErrContextOverflow, wire.ErrStreamIncomplete, and provider.ErrLaneExhausted before delegating to terminalForFallback.
  • Adds TestIsTerminalExcludesRecoverableCauses covering malformed requests, auth issues, context overflows, rate limits, transport failures, and lane exhaustion.

The change cleanly isolates turn-killing terminal errors from fallback-stopping conditions and is well-covered by targeted tests.


No findings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant