Add pruning fallback and character truncation for large context #8122
+112
−30
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
This PR addresses CON-4274 by adding two improvements to handle large context in the CLI:
Pruning fallback: When context length validation fails before sending chat messages, we now use the existing
compileChatMessages
pruning logic fromcore/llm/countTokens.js
as a fallback. This removes older messages while preserving the system message, tools, and the most recent user/tool sequence.Bash tool output truncation: The Bash tool now truncates output by both:
Whichever limit is hit first will trigger truncation with an appropriate message.
Changes
extensions/cli/src/stream/streamChatResponse.ts
: Added pruning fallback inprocessStreamingResponse
when context validation failsextensions/cli/src/tools/runTerminalCommand.ts
: Added character-based truncation to Bash tool outputTesting
compileChatMessages
function from coreFixes CON-4274
This agent session was co-authored by nate and Continue.
Summary by cubic
Prevents oversized contexts from breaking CLI requests by pruning chat history and truncating Bash tool output. Fixes CON-4274 and improves reliability with large conversations and long command results.