Skip to content

Conversation

@continue
Copy link
Contributor

@continue continue bot commented Oct 7, 2025

Summary

This PR addresses CON-4274 by adding two improvements to handle large context in the CLI:

  1. Pruning fallback: When context length validation fails before sending chat messages, we now use the existing compileChatMessages pruning logic from core/llm/countTokens.js as a fallback. This removes older messages while preserving the system message, tools, and the most recent user/tool sequence.

  2. Bash tool output truncation: The Bash tool now truncates output by both:

    • Lines: 5000 lines (existing)
    • Characters: 200,000 characters (new)

    Whichever limit is hit first will trigger truncation with an appropriate message.

Changes

  • extensions/cli/src/stream/streamChatResponse.ts: Added pruning fallback in processStreamingResponse when context validation fails
  • extensions/cli/src/tools/runTerminalCommand.ts: Added character-based truncation to Bash tool output

Testing

  • The pruning logic reuses the well-tested compileChatMessages function from core
  • Character truncation follows the same pattern as the existing line truncation

Fixes CON-4274


This agent session was co-authored by nate and Continue.


Summary by cubic

Prevents oversized contexts from breaking CLI requests by always pruning chat history and truncating Bash tool output. Fixes CON-4274 and improves reliability with large conversations and long command results.

  • New Features
    • Always uses compileChatMessages to prune chat history; preserves system, tools, and the latest exchange.
    • Truncates Bash tool output to the last 5000 lines or last 200,000 characters (whichever comes first) with a clear truncation notice.

Written for commit fdcdcb6. Summary will update automatically on new commits.

- Add compileChatMessages pruning as fallback when context length validation fails
- Truncate Bash tool output by both lines (5000) and characters (200000)
- Reuse existing pruning logic from core/llm/countTokens.js
- Log pruning details when it occurs

Fixes CON-4274

Generated with [Continue](https://continue.dev)

Co-Authored-By: Continue <noreply@continue.dev>
Co-authored-by: nate <nate@continue.dev>
@chezsmithy
Copy link
Contributor

I'd recommend a different truncation strategy for the bash output. Perhaps keep the last X lines from the end backwards to capture the outcome of tests and installs.

@TyDunn TyDunn marked this pull request as ready for review October 16, 2025 18:45
@TyDunn TyDunn requested a review from a team as a code owner October 16, 2025 18:45
@TyDunn TyDunn requested review from RomneyDa and removed request for a team October 16, 2025 18:45
@github-actions
Copy link

⚠️ PR Title Format

Your PR title doesn't follow the conventional commit format, but this won't block your PR from being merged. We recommend using this format for better project organization.

Expected Format:

<type>[optional scope]: <description>

Examples:

  • feat: add changelog generation support
  • fix: resolve login redirect issue
  • docs: update README with new instructions
  • chore: update dependencies

Valid Types:

feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert

This helps with:

  • 📝 Automatic changelog generation
  • 🚀 Automated semantic versioning
  • 📊 Better project history tracking

This is a non-blocking warning - your PR can still be merged without fixing this.

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Oct 16, 2025
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Copy link
Collaborator

@RomneyDa RomneyDa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compile chat messages already supports unified history, no need to convert between the two. CLI should just always use compile chat messages, no need for a duplicate token counting validation step.

@github-project-automation github-project-automation bot moved this from Todo to In Progress in Issues and PRs Oct 28, 2025
@RomneyDa
Copy link
Collaborator

@continue also implement @chezsmithy's truncation recommendation

Copy link
Collaborator

@RomneyDa RomneyDa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TomIsion thanks for the contribution! could you check cubic feedback and rebase main?
EDIT ignore this, mistaken comment

@RomneyDa
Copy link
Collaborator

RomneyDa commented Dec 2, 2025

kicked off a session to address comments.

…ation

- Remove duplicate token validation logic; use compileChatMessages directly
- Eliminate unnecessary conversions between unified history and ChatMessage formats
- Change bash tool truncation to keep LAST X lines/chars instead of first X
  - Better captures test/install outcomes at the end of command output
- Simplify pruning flow: always use compileChatMessages for context management

Addresses feedback from @RomneyDa and @chezsmithy

Co-authored-by: dallin <dallin@continue.dev>
@github-actions
Copy link

github-actions bot commented Dec 2, 2025


Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


1 out of 2 committers have signed the CLA.
✅ (sestinj)[https://github.com/sestinj]
@continue
Continue seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

@continue
Copy link
Contributor Author

continue bot commented Dec 2, 2025

Changes Made

Addressed the review feedback:

1. Simplified Context Handling (per @RomneyDa)

  • Removed duplicate token validation logic - no longer calling validateContextLength separately
  • Use compileChatMessages directly - this function already handles unified history format properly
  • Eliminated unnecessary format conversions - reduced back-and-forth between ChatHistoryItem[] and ChatMessage[] formats
  • The pruning now happens in one clean pass through compileChatMessages

2. Improved Bash Tool Truncation (per @chezsmithy)

  • Changed truncation strategy to keep LAST X lines instead of first X lines
  • Uses .slice(-MAX_OUTPUT_LINES) to capture the end of output
  • For character truncation, also keeps the last X characters
  • This better captures test results, installation outcomes, and error messages that typically appear at the end of command output
  • Updated truncation messages to clearly indicate we're showing the "last" portion

Technical Details

The changes reduce complexity by ~37 lines while improving functionality:

  • Removed the validateContextLength pre-check and error handling
  • Removed the convertToUnifiedHistory conversion step after pruning
  • Simplified the flow: unified history → ChatMessage → compileChatMessages → OpenAI format
  • Bash truncation now properly prioritizes the most relevant output (the end result)

These changes make the code more maintainable and align with how compileChatMessages was designed to be used.

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

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

4 participants