Skip to content

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

Closed
Glucksberg wants to merge 1 commit intoopenclaw:mainfrom
Glucksberg:fix/context-overflow-anthropic
Closed

fix(agents): detect Anthropic 'exceed context limit' error for auto-compaction#4266
Glucksberg wants to merge 1 commit intoopenclaw:mainfrom
Glucksberg:fix/context-overflow-anthropic

Conversation

@Glucksberg
Copy link
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 pattern matching for this error format in isContextOverflowError().

Testing

Added test cases for the new error format.

@openclaw-barnacle openclaw-barnacle bot added the agents Agent runtime and tooling label Jan 30, 2026
…ompaction

Add detection for Anthropic's 'input length and max_tokens exceed context limit'
error message to trigger auto-compaction. Without this fix, extended thinking
sessions with large contexts would fail without attempting compaction.

Fixes cases like:
- 'input length and max_tokens exceed context limit: 156321 + 48384 > 200000'
- JSON wrapped versions of the same error
@Glucksberg
Copy link
Contributor Author

Superseded by new PR with rebased branch. Creating fresh PR.

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

Labels

agents Agent runtime and tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant