Skip to content

Conversation

@rahulrajaram
Copy link

Fix: Conversation overflow, terminal responsiveness, and transcript accuracy

Changes

  1. Conversation overflow with token-based compaction
  • Fixed bug where message count was used instead of token count, causing overflow errors with large tool outputs
  • Track cumulative token usage (input + output) from backend MetadataEvent
  • Trigger proactive compaction at 98% of context window based on actual tokens
  • Add MetadataEvent support to ChatResponseStream
  1. Ctrl+C handling during hook execution
  • CLI no longer freezes during "Thinking..." state when hooks are running
  • Hooks now respond immediately to Ctrl+C instead of waiting for 30s timeout
  • Uses tokio::select! to monitor both hook completion and Ctrl+C signals
  1. Transcript sanitization
  • Fixed bug where hidden unicode characters appeared in transcript but not in messages sent to LLM
  • Moved transcript append to after sanitization step
  1. ANSI escape codes in /clear command
  • Replaced StyledText helpers with direct crossterm commands for consistent rendering across terminals

- Track cumulative token usage (input + output) in ConversationState
- Capture token usage from MetadataEvent in response stream
- Add MetadataEvent support to ChatResponseStream enum
- Trigger proactive compaction at 98% of context window
- Add tests for threshold calculation and overflow prevention

This fixes the bug where message count was used instead of token count,
causing overflow errors when conversations had many messages with large
tool outputs. Now compaction triggers before overflow based on actual
token usage from the backend.
- Replace StyledText helper methods with direct crossterm color commands
- Ensures consistent ANSI escape sequence generation across terminals
- Add unit test to verify proper rendering of prompt with colors
- Remove unused StyledText import

The fix replaces StyledText::secondary_fg() and StyledText::success_fg()
with style::SetForegroundColor() calls using Color::DarkGrey and Color::Green,
and StyledText::reset() with style::ResetColor for proper ANSI code output.
Test verifies that user input is sanitized before being appended to
the transcript. Currently fails, demonstrating that hidden unicode
characters are preserved in the transcript when they should be removed.
Move append_user_transcript() call to after sanitize_unicode_tags() in
handle_input(). This ensures the transcript contains the sanitized
version of user input, matching what is actually sent to the LLM.

Previously, the transcript was appended in prompt_user() before
sanitization, causing hidden unicode characters and control characters
to be preserved in the transcript while being removed from the actual
message sent to the model.
Test shows that run_hooks() executes for full duration without
responding to Ctrl+C signals, causing terminal to appear frozen.

This validates the reported issue where CLI becomes unresponsive
during 'Thinking...' state when hooks are executing.
Hooks now respond to Ctrl+C signals during execution instead of
running for the full 30-second timeout. Uses tokio::select! to
monitor both hook completion and Ctrl+C signals.

Fixes terminal freeze issue where CLI becomes unresponsive during
hook execution in 'Thinking...' state.
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.

1 participant