← Back to PRs

#6353: fix(agents): detect Anthropic 'exceed context limit' error for auto-compaction

by Glucksberg open 2026-02-01 15:27 View on GitHub →
agents size: XS experienced-contributor
## Summary Detect Anthropic's 'input length and max_tokens exceed context limit' error to trigger auto-compaction. ## Problem When using extended thinking with large contexts, Anthropic returns this specific error: ``` input length and max_tokens exceed context limit: 156321 + 48384 > 200000 ``` Without detection, auto-compaction is not triggered and the request fails. ## Solution Add 'exceed context limit' pattern matching in `isContextOverflowError()`. ## Testing Added test cases for the new error format. Supersedes #4266 <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR extends `isContextOverflowError()` to recognize Anthropic’s extended-thinking context overflow error string ("…exceed context limit…"), and adds Vitest coverage for the new format. There are also small docs formatting tweaks in provider docs/onboarding/canvas docs. The main behavior change is in `src/agents/pi-embedded-helpers/errors.ts`, where additional substring matching allows auto-compaction logic to treat the new Anthropic error as a context overflow and retry accordingly. <h3>Confidence Score: 4/5</h3> - This PR is likely safe to merge; it adds a narrow error-pattern match and corresponding tests. - The code change is a simple additional substring check in a well-scoped helper, and tests cover representative raw/plain-text variants. Primary risk is around the doc marker syntax change potentially rendering unintended text in docs builds. - docs/concepts/model-providers.md, docs/providers/moonshot.md <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs