Skip to content

fix(session): prevent context overflow by adding safety margin to compaction check#6562

Closed
o1x3 wants to merge 2 commits intoanomalyco:devfrom
o1x3:fix/auto-compaction-overflow
Closed

fix(session): prevent context overflow by adding safety margin to compaction check#6562
o1x3 wants to merge 2 commits intoanomalyco:devfrom
o1x3:fix/auto-compaction-overflow

Conversation

@o1x3
Copy link

@o1x3 o1x3 commented Jan 1, 2026

Summary

Fixes #6068 - Auto compaction not triggering reliably with Anthropic models causing "prompt is too long" errors.

Root cause: The overflow check happens before system prompts (~25K tokens) and tool definitions (~10K tokens) are added to the request, so 40-60K tokens of overhead aren't accounted for.

Changes:

  • Add 50K overhead buffer to isOverflow() calculation
  • Add mid-turn overflow detection in finish-step handler
  • Add 30K truncation for MCP tool outputs and webfetch results

Test plan

  • Typecheck passes
  • Session tests pass
  • Tool tests pass

o1x3 and others added 2 commits January 1, 2026 11:23
…paction check

- Add 50K overhead buffer to account for system prompts and tool definitions
- Add mid-turn overflow detection in finish-step to catch runaway tool loops
- Add 30K truncation for MCP tool outputs and webfetch results
- Handle compact signal to trigger compaction mid-turn

Fixes anomalyco#6068
@github-actions
Copy link
Contributor

github-actions bot commented Mar 7, 2026

Closing this pull request because it has had no updates for more than 60 days. If you plan to continue working on it, feel free to reopen or open a new PR.

@github-actions github-actions bot closed this Mar 7, 2026
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.

[BUG]: Auto compaction not triggering reliably with Anthropic models

1 participant