fix(opencode): classify OpenRouter's typeless 502 overflow chunk as ContextOverflowError - #43
Merged
Merged
Conversation
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
The following comment was made by an LLM, it may be inaccurate: |
…ontextOverflowError
OpenRouter relays an upstream context-window overflow mid-stream as
{ code: 502, message, metadata } with no type field, so parseStreamError
returned undefined and the turn died as an opaque UnknownError instead of
triggering compaction. Match the message text with the shared overflow
patterns before the type gate. USE-2673.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
PierrotAWB
force-pushed
the
andrew/use-2673-openrouter-overflow
branch
from
September 10, 2026 22:11
69811e1 to
b697a6a
Compare
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.
Description
Fixes USE-2673.
When the model's context fills up behind OpenRouter, OpenRouter does not fail the HTTP request. It relays the upstream overflow as a mid-stream chunk with no
typefield:{ "code": 502, "message": "Your input exceeds the context window of this model. Please adjust your input and try again.", "metadata": { "error_type": "provider_unavailable" } }parseStreamErrorgated everything onbody.type === "error", so this chunk returnedundefined,fromErrorfell through toUnknownErrorwith the JSON stringified intomessage, and the processor treated the turn as a generic failure. Users saw "Something went wrong" with a Retry button that re-sent the same oversized prompt: prod shows ten identical failures in three minutes for one session.The overflow text patterns in
@opencode-ai/llmalready match this message, but only ran on theAPICallErrorbranch. This PR checks the message text (aterror.messageor top-levelmessage) against those patterns before the type gate, and folds the existingcontext_length_exceededcase into the same check so overflow is classified in one place.Now the chunk becomes
ContextOverflowError, which the processor already handles: it flagsneedsCompaction, compacts once, and replays the prompt (converging per #41) instead of surfacing an opaque error.Shipping this to the fleet needs a fork release tag and an
OPENCODE_VERSIONbump inapps/daytona-snapshot/Dockerfilein andytown.Testing
TODO
🤖 Generated with Claude Code
Summary by cubic
Fixes OpenRouter's typeless 502 overflow chunks showing up as a generic "Something went wrong" error. These chunks now classify as
ContextOverflowError, so the existing compaction and prompt-replay path runs instead of a Retry that re-sends the oversized prompt.parseStreamErrorno longer requiresbody.type === "error"to match overflow message text; thecontext_length_exceededcode check is folded into the same pre-gate match.OPENCODE_VERSIONbump inapps/daytona-snapshot/Dockerfile.Written for commit b697a6a. Summary will update on new commits.