Conversation
…stream The processor retries a whole stream when it fails with a retryable error, but it never removed what the failed attempt had already written. A retry after partial output left duplicate text and reasoning, parts that were never closed, and could run a tool the failed attempt had already started a second time. Before a retry, remove the parts the failed attempt created and restore the message's finish, cost, tokens and file snapshot to what they were when the attempt started. If a tool from that attempt had started running, don't retry; end the turn with the error. A stream that ends with no finish reason, no usage and no text or tool output is now a retryable stream error instead of a normal stop, so a dropped connection is retried and, once retries run out, shows an error.
Contributor
|
The following comment was made by an LLM, it may be inaccurate: |
3 of 6 tasks
This branch has not been deployed
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.
Issue for this PR
Closes #44894
Closes #37852
Related: #48454 / #48453 cover this among a wider set of changes (+6.8k lines); this PR is the retry part alone. The empty-stream half takes the same approach as #43881 (closed by the stale-PR bot), reusing
ResponseStreamError.Type of change
What does this PR do?
SessionProcessorwraps the whole stream inEffect.retry(SessionRetry.policy(...)). Each attempt resetscurrentTextandreasoningMapand publishes new parts, but nothing removes what a failed attempt already wrote. So when a stream fails after producing output (a dropped connection, a 5xx mid-stream):This PR:
session.removePart(so clients get the normal removal events), and restores the assistant message'sfinish,cost,tokensand the file snapshot to their values at the start of the attempt. Parts from earlier completed steps are not touched.pending). The turn ends with the error, as it does today for non-retryable errors.ResponseStreamError(Aborted provider stream recorded as clean stop (finish=unknown, zero usage, no text) — subagent returns empty with no error #37852). Today that is stored as a normalfinish: "unknown"stop, so a dropped connection looks like the model said nothing. Streams that end without a finish reason but did produce text or tool calls behave as before.The snapshot restore matters when a failed attempt got as far as
step-finish: that clearsctx.snapshotand writes a patch part, and after the discard removes the patch, re-tracking at the retry'sstep-startwould take the snapshot after the edits and drop them from the turn's patch.Behavior change: for an empty finish-less stream, the processor now retries within the turn with the normal backoff and ends with an error once retries run out, instead of the prompt loop starting another turn. The existing
loop continues when finish is unknowntest still passes; its second request now comes from the processor's retry.How did you verify your code works?
test/session/processor-effect.test.ts, each shown failing before the change: duplicate text after a retry, removal events for the failed attempt's parts, no retry after a tool ran (the tool runs once, not twice), an empty stream retried and then surfaced as an error, and a failed attempt's patch surviving the retry. Retry waits useTestClock, so no test sleeps for real.bun test test/session(424 pass, 0 fail) andbun typecheckinpackages/opencode.Screenshots / recordings
Not a UI change.
Checklist