Skip to content

fix(retry): don't retry server-side context overflow; require word-bounded status codes - #52460

Closed
acmore wants to merge 2 commits into
anomalyco:devfrom
acmore:fix/retry-context-overflow
Closed

acmore wants to merge 2 commits into
anomalyco:devfrom
acmore:fix/retry-context-overflow

Conversation

@acmore

@acmore acmore commented Oct 1, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #52464

Type of change

  • Bug fix

What does this PR do?

Two hardening changes in the session retry layer (packages/opencode/src/session/retry.ts):

  • Word-boundary fix (core): RETRYABLE_MESSAGE_PATTERNS matches 429|500|502|503|504|524 as raw substrings, so any error message containing those digits inside a larger number (e.g. "context length (500000 tokens)", "4290 requests", "id 503123") is misclassified as retryable. This anchors the pattern with \b so only standalone status codes match.
  • Non-retryable guard (defense-in-depth): adds non-retryable patterns for common server-side context-overflow phrasings (vLLM/SGLang, OpenAI context_length_exceeded, Anthropic "prompt is too long", Gemini), checked before the retryable heuristics. Context overflow is already handled upstream via isContextOverflow → ContextOverflowError; this guard covers the fall-through case where an overflow error arrives as a plain APIError.

Known narrowing: plural forms like "returning 500s" no longer match the message pattern; real 5xx remain covered by statusCode >= 500 / isRetryable.

How did you verify your code works?

  • 4 new test cases in packages/opencode/test/session/retry.test.ts (real overflow message shapes → not retried; standalone status codes → still retried).
  • bun test test/session/retry.test.ts: 64 pass / 0 fail (60 existing + 4 new).
  • Regex behavior additionally verified against all message shapes in isContextOverflow's pattern list.

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels Oct 1, 2026
@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

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

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

@github-actions github-actions Bot removed needs:issue needs:compliance This means the issue will auto-close after 2 hours. labels Oct 1, 2026
@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Oct 2, 2026
@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@thdxr

thdxr commented Oct 10, 2026

Copy link
Copy Markdown
Member

This branch has been upgraded to V2. We're no longer taking PRs for V1. If you think this is still relevant, please port it over and open it for V2.

— from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

@thdxr thdxr closed this Oct 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Context overflow 400 is retried because the error message contains "500000" (substring match of "500")

2 participants