Skip to content

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

Closed

Description

@acmore

Description

The session retry layer's RETRYABLE_MESSAGE_PATTERNS in packages/opencode/src/session/retry.ts matches status codes as raw substrings:

/429|500|502|503|504|524/i

Any error message that merely contains those digits inside a larger number is misclassified as retryable. For example, a deterministic 400 whose message includes a large token count:

  • "The input (523659 tokens) is longer than the model's context length (500000 tokens)" → matches "500"
  • "... 4290 requests ..." → matches "429"
  • "... id 503123 not found ..." → matches "503"

When such an error reaches retryable() as a plain APIError (i.e. when it was not classified as ContextOverflowError upstream), the policy retries a request that can never succeed, up to 5 times with exponential backoff, before surfacing the error to the user.

This is a distinct failure mode from the context-overflow classification in packages/llm/src/provider-error.ts (isContextOverflow): the classifier handles the known phrasings, but any 4xx error carrying one of these numbers in its text — from a gateway, proxy, or a provider phrasing not in the pattern list — still falls through to the retry layer and hits the substring match.

Steps to reproduce

Unit-level (deterministic):

  1. An APIError is constructed from a 4xx response whose message contains a large number, e.g. ... context length (500000 tokens)
  2. SessionRetry.retryable(error) → matchesRetryableMessage(message) matches "500" inside "500000"
  3. The retry policy treats the deterministic failure as retryable

Live: send a request that a gateway rejects with 4xx and an error body containing any of 429/500/502/503/504/524 as a substring of a larger number.

Expected behavior

Status codes embedded in larger numbers must not make an error retryable; a deterministic 4xx should surface immediately.

OpenCode version

v1.18.25 through current dev (packages/opencode/src/session/retry.ts)

Operating System / Terminal

macOS / any — logic is OS-independent

Additional context

Fix proposed in #52460: word-bounded status code pattern plus a non-retryable guard for common context-overflow phrasings at the retry layer.

Activity

  1. added
    needs:complianceThis means the issue will auto-close after 2 hours.
    and removed
    needs:complianceThis means the issue will auto-close after 2 hours.
    on Oct 1, 2026
  2. github-actions commented on Oct 2, 2026

    @github-actions
    Contributor

    Thanks for updating the issue with reproduction steps and system details!

  3. rekram1-node commented on Oct 2, 2026

    @rekram1-node
    Collaborator
  4. rekram1-node commented on Oct 5, 2026

    @rekram1-node
    Collaborator

    recommend updating to v2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions