Skip to content

Conversation

@ammar-agent
Copy link
Collaborator

@ammar-agent ammar-agent commented Jan 15, 2026

Summary

Fixes bug where queued follow-up messages were sent after compaction failed.

Problem:
When compaction fails (e.g., Gemini "completing" without producing a valid summary), the queued follow-up message was still being sent. This caused the follow-up to go into the non-compacted chat, potentially hitting context limits again.

Root cause:
handleCompletion() returned boolean where false meant both "not a compaction stream" (normal) AND "compaction failed" (bad). The sendQueuedMessages() was called unconditionally on stream-end.

Solution:
Introduce CompactionResult discriminated union:

  • "not-compaction": Normal stream end, proceed with queued messages
  • "success": Compaction succeeded, proceed with queued messages
  • "failed": Compaction was attempted but failed - do NOT send queued messages

This prevents the follow-up from being injected into a non-compacted chat when the model fails to produce a valid summary.

Test Plan

  • Updated compactionHandler.test.ts assertions to use new CompactionResult type
  • All 36 compactionHandler tests passing
  • make static-check passes

Generated with mux • Model: anthropic:claude-opus-4-5 • Thinking: high • Cost: $12.22

@github-actions github-actions bot added the enhancement New feature or functionality label Jan 15, 2026
@ammar-agent
Copy link
Collaborator Author

@mux retry

After compaction completes, the queued follow-up message was sent as raw
text without any context. This made it unclear to the model that this
message triggered compaction and that relevant context is in the summary.

The fix wraps non-default follow-up messages with a context note:
  "(This was the message that triggered compaction - context is in the
   summary above)"

The default resume sentinel ("Continue") is excluded since it's just a
signal to continue, not meaningful user content.

This is NOT a regression - the original implementation (dacc278, Nov 2025)
always sent follow-ups as raw text. This change improves upon that design.
When compaction fails (e.g., Gemini 'completing' without producing
a valid summary), the queued follow-up message was still being sent.
This caused the follow-up to go into the non-compacted chat, potentially
hitting context limits again.

The fix introduces a CompactionResult discriminated union:
- 'not-compaction': Normal stream end, not a compaction request
- 'success': Compaction completed successfully
- 'failed': Compaction was attempted but failed

Queued messages are now only sent when result is not 'failed',
preventing the follow-up from being injected into a non-compacted chat.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant