Uh oh!
There was an error while loading. Please reload this page.
fix(provider): detect max-token request overflow errors - #27524
Conversation
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
Please edit this PR description to address the above within 2 hours, or it will be automatically closed. If you believe this was flagged incorrectly, please let a maintainer know. |
The following comment was made by an LLM, it may be inaccurate: Based on my search, I found several related PRs that deal with overflow/context limit error handling: Potentially Related PRs:
These are related efforts in the overflow/error handling space but address different aspects (compaction, Anthropic-specific handling, etc.). PR #27524 appears to be a provider-layer detection fix, which is distinct from these higher-level error management approaches. |
There was a problem hiding this comment.
Pull request overview
Adds provider-layer detection for “max tokens in request/context overflow” errors so they’re classified as ContextOverflowError instead of generic API errors, preventing retry loops and enabling upstream recovery behaviors (e.g., auto-compaction).
Changes:
- Expanded context-overflow detection with an additional regex covering “tokens in request/input … exceeds max tokens allowed” variants and added normalization to improve matching.
- Extended
parseAPICallErrorto also scanresponseBodytext for overflow indicators (in addition to the derived message and known codes/statuses). - Added tests ensuring these errors are detected as context overflow and are not retried, while avoiding misclassification of
max_tokensparameter validation errors.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/opencode/src/provider/error.ts | Extends overflow detection patterns/normalization and checks overflow signals in response bodies. |
| packages/opencode/test/session/retry.test.ts | Verifies request max-token overflow errors are classified as overflow and not retried. |
| packages/opencode/test/session/message-v2.test.ts | Adds coverage for new overflow variants and a non-overflow max_tokens validation case. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window. Feel free to open a new pull request that follows our guidelines. |
Fixes#27519
Adds detection of context overflow / max-token request errors in the provider layer. When the model returns a 400 error indicating the context window is exceeded (e.g., "maximum context length exceeded" or similar token limit errors), this change:
This prevents cryptic provider errors from bubbling up unhandled and allows the caller to respond appropriately (e.g., by reducing context or switching models).