Skip to content

fix: add missing context overflow pattern for OpenAI-compatible providers#27628

Open
realcarsonterry wants to merge 1 commit into
anomalyco:devfrom
realcarsonterry:fix/context-overflow-pattern
Open

fix: add missing context overflow pattern for OpenAI-compatible providers#27628
realcarsonterry wants to merge 1 commit into
anomalyco:devfrom
realcarsonterry:fix/context-overflow-pattern

Conversation

@realcarsonterry
Copy link
Copy Markdown

@realcarsonterry realcarsonterry commented May 14, 2026

Issue for this PR

Closes #27519

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

This PR adds a missing overflow pattern to prevent infinite retry loops when OpenAI-compatible providers return context overflow errors.

Some OpenAI-compatible providers return "tokens in request more than max tokens allowed" when the context window is exceeded. This pattern wasn't recognized in the OVERFLOW_PATTERNS array, causing the system to infinitely retry instead of triggering context compaction.

The fix adds the pattern /tokens in request more than max tokens allowed/i to the OVERFLOW_PATTERNS array in packages/opencode/src/provider/error.ts.

How did you verify your code works?

Screenshots / recordings

N/A - This is a backend error handling fix

Checklist

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

Fixes anomalyco#27519

Some OpenAI-compatible providers return the error message "tokens in request more than max tokens allowed" when the context window is exceeded. This pattern was not recognized by the overflow detection logic, causing the system to retry indefinitely instead of triggering context compaction.

This adds the missing pattern to OVERFLOW_PATTERNS to ensure proper handling of this error across all OpenAI-compatible providers.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

Hey! Your PR title Add missing context overflow pattern for OpenAI-compatible providers doesn't follow conventional commit format.

Please update it to start with one of:

  • feat: or feat(scope): new feature
  • fix: or fix(scope): bug fix
  • docs: or docs(scope): documentation changes
  • chore: or chore(scope): maintenance tasks
  • refactor: or refactor(scope): code refactoring
  • test: or test(scope): adding or updating tests

Where scope is the package name (e.g., app, desktop, opencode).

See CONTRIBUTING.md for details.

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label May 14, 2026
@github-actions
Copy link
Copy Markdown
Contributor

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

Related PRs Found

I found two related PRs that address similar context overflow detection improvements:

  1. PR fix: enable auto-compaction for sub-agents and improve context overflow detection #25180 - fix: enable auto-compaction for sub-agents and improve context overflow detection

    • Addresses context overflow detection improvements, likely related to the same OVERFLOW_PATTERNS functionality
  2. PR fix: treat Anthropic long context billing error as context overflow #18683 - fix: treat Anthropic long context billing error as context overflow

These PRs are related to the same system for detecting and handling context overflow errors across different providers. They may provide context on how similar patterns have been added previously or could complement your changes.

@realcarsonterry realcarsonterry changed the title Add missing context overflow pattern for OpenAI-compatible providers fix: add missing context overflow pattern for OpenAI-compatible providers May 14, 2026
@github-actions github-actions Bot removed needs:title needs:compliance This means the issue will auto-close after 2 hours. labels May 14, 2026
@github-actions
Copy link
Copy Markdown
Contributor

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

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.

fix(provider): classify "tokens in request more than max tokens allowed" as context overflow

1 participant