feat: auto-compact and retry on context window errors#2808
Draft
TheArchitectit wants to merge 1 commit intoultraworkers:mainfrom
Draft
feat: auto-compact and retry on context window errors#2808TheArchitectit wants to merge 1 commit intoultraworkers:mainfrom
TheArchitectit wants to merge 1 commit intoultraworkers:mainfrom
Conversation
When the model API returns a context_window_blocked error (because the request exceeds the model's context window), the CLI now automatically: 1. Compact the session (remove old messages to free up space) 2. Retry the original request with the compacted session 3. Report results to the user This eliminates the need for users to manually run /compact when they hit context limits - the recovery happens automatically. ## Technical Details - Detection: Looks for 'context_window' or 'Context window' in error message - Uses runtime::compact_session() to aggressively compact (max_estimated_tokens=0) - Creates new runtime with compacted session and retries the turn - Reports compaction results and final status to user ## Testing Tested successfully with a request that exceeded model's context: - Auto-compact triggered: 'Messages removed 19, Messages kept 5' - Successfully retried and completed after compaction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
context_window_blocked)/compactwhen hitting context limits — recovery happens transparently"context_window"or"Context window"in the error message, covering variants likecontext_window_blockedand token-limit messagesChanges
rust/crates/rusty-claude-cli/src/main.rs: Added auto-compact retry block after the existing error path in the turn loop. When a context window error is detected, the session is compacted withmax_estimated_tokens: 0(aggressive), the turn is retried with a fresh runtime, and results are reported.Test plan
🤖 Generated with Claude Code