fix(provider): treat Anthropic billing_error as context overflow for auto-compaction#17766
fix(provider): treat Anthropic billing_error as context overflow for auto-compaction#17766codeg-dev wants to merge 2 commits intoanomalyco:devfrom
Conversation
…rror "Extra usage is required for long context requests." from Anthropic(HTTP 403, billing_error type) was not recognized by OVERFLOW_PATTERNS,causing it to be treated as a generic retryable API error.This resulted in infinite retry loops (57+ retries observed) instead oftriggering automatic compaction to reduce the context size.Adding the pattern causes opencode to automatically compact the sessionwhen this error occurs, which resolves the underlying context size issue.
|
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. |
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
The following comment was made by an LLM, it may be inaccurate: ResultsNo duplicate PRs found. However, I found several related PRs that address context overflow and compaction, though they address different aspects:
These PRs are in the same feature area but target different error scenarios or approaches, so they're not duplicates of PR #17766. |
|
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. |
Problem
Anthropic returns HTTP 403 with
billing_errortype and the message:This occurs when a session context exceeds ~200K tokens for accounts not in Anthropic usage tier 4.
Root Cause
The
OVERFLOW_PATTERNSarray inprovider/error.tsdid not include this error message. As a result:parseAPICallError()classifies it as a genericapi_error(notcontext_overflow)retry.tstreats it as retryable (depending on HTTP status interpretation)Observed in production: 57 consecutive failures over 2 hours on a session with 452K tokens.
Fix
Add
/extra usage is required for long context/itoOVERFLOW_PATTERNS.This causes opencode to:
ContextOverflowErrorinstead ofAPIErrorTesting
Manually verified on a session with 452K+ tokens hitting this error. After fix, compaction is triggered automatically instead of infinite retry.