Skip to content

fix(opencode): classify OpenRouter's typeless 502 overflow chunk as ContextOverflowError - #43

Merged
PierrotAWB merged 1 commit into
devfrom
andrew/use-2673-openrouter-overflow
Sep 10, 2026
Merged

PierrotAWB merged 1 commit into
devfrom
andrew/use-2673-openrouter-overflow

Conversation

@PierrotAWB

@PierrotAWB PierrotAWB commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator

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 type field:

{ "code": 502, "message": "Your input exceeds the context window of this model. Please adjust your input and try again.", "metadata": { "error_type": "provider_unavailable" } }

parseStreamError gated everything on body.type === "error", so this chunk returned undefined, fromError fell through to UnknownError with the JSON stringified into message, 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/llm already match this message, but only ran on the APICallError branch. This PR checks the message text (at error.message or top-level message) against those patterns before the type gate, and folds the existing context_length_exceeded case into the same check so overflow is classified in one place.

Now the chunk becomes ContextOverflowError, which the processor already handles: it flags needsCompaction, 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_VERSION bump in apps/daytona-snapshot/Dockerfile in 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.

  • parseStreamError no longer requires body.type === "error" to match overflow message text; the context_length_exceeded code check is folded into the same pre-gate match.
  • Adds a regression test for the typeless chunk shape.
  • Shipping needs a fork release tag and an OPENCODE_VERSION bump in apps/daytona-snapshot/Dockerfile.

Written for commit b697a6a. Summary will update on new commits.

Review in cubic

@github-actions

Copy link
Copy Markdown

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions

Copy link
Copy Markdown

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
PierrotAWB force-pushed the andrew/use-2673-openrouter-overflow branch from 69811e1 to b697a6a Compare September 10, 2026 22:11
@PierrotAWB
PierrotAWB merged commit 0cc3c7b into dev Sep 10, 2026
11 checks passed
@PierrotAWB
PierrotAWB deleted the andrew/use-2673-openrouter-overflow branch September 10, 2026 22:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant