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: |
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.
Stacked on #51548; only the last commit is new.
Issue for this PR
Related: #44894, #37852 (closed by #51548).
Type of change
What does this PR do?
#51548 retries a stream that fails partway, after discarding what the failed attempt wrote. A provider plugin with its own
fetch, such as a WebSocket transport, has no supported way to say that a failure is transient. So when the connection drops after output has started, its errors are never retried.With this change, a custom
fetchcan throw anErrorwithisRetryable: true, optionally withresponseHeaderscarryingretry-afterorretry-after-ms. AI SDKAPICallError.isRetryablealready worked; this covers errors that aren't anAPICallError. Retries stay bounded and stop once a tool call has started. The contract is documented inproviders.mdxand onAuthHook.loader.How did you verify your code works?
From
packages/opencode:bun test test/session/processor-effect.test.ts test/session/retry.test.ts, 94 pass / 0 fail. The new tests fail without the change.Screenshots / recordings
Not applicable.
Checklist