fix(session): classify context overflow from generic errors before unknown fallback#33667
Open
Haohao-end wants to merge 1 commit into
Open
fix(session): classify context overflow from generic errors before unknown fallback#33667Haohao-end wants to merge 1 commit into
Haohao-end wants to merge 1 commit into
Conversation
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 #33376
Type of change
What does this PR do?
When a provider returns a context-length error wrapped in a generic
Error(not anAPICallError),fromError()inmessage-v2.tsclassifies it asUnknownErrorinstead ofContextOverflowError. This means the processor never triggers auto-compaction — the session dies with "Network connection lost." and no recovery is possible.The root cause is the
case e instanceof Error:branch infromError()— it returnsNamedError.Unknownwithout checking whether the error message indicates context overflow. Thedefaultbranch does callProviderError.parseStreamError()which can detect overflow, but genericErrorinstances never reach it.This PR adds an
isContextOverflow(msg)check before the unknown fallback.isContextOverflowalready exists in@opencode-ai/llmwith 18+ patterns covering messages from OpenAI, Anthropic, Bedrock, and others — so any provider whose overflow error lands as a plainErrornow gets correctly classified, and the processor setsneedsCompaction = trueinstead of killing the session.How did you verify your code works?
bun typecheckfrompackages/opencode— passesbun test test/session/message-v2.test.ts --test-name-pattern "fromError"— 12/12 passContextOverflowError"Network connection lost."still classifies asUnknownErrorScreenshots / recordings
N/A — logic change only.
Checklist