Skip to content

Conversation

@ammar-agent
Copy link
Collaborator

Two related bugs were causing compaction to loop forever:

Bug 1: Message queue overwrote compaction metadata

When a user typed a follow-up message while a compaction was queued, the queue would overwrite latestOptions, losing the muxMetadata that marks the message as a compaction-request. The compaction would then be sent as a normal message, never triggering actual history replacement.

Fix: Follow-up messages added after a compaction request are now merged into the compaction's continueMessage field rather than overwriting options. This preserves compaction metadata and sends follow-ups after compaction completes.

Bug 2: Usage display showed pre-compaction context

After compaction, the summary message's usage field contained the pre-compaction context size (since that's what was sent to generate the summary). This inflated the context window display, making it appear usage was still high and triggering auto-compaction again.

Fix: Skip compacted messages when computing lastContextUsage. The summary's usage reflects historical cost, not current context.


Generated with mux

Two related bugs were causing compaction to loop forever:

1. **Message queue overwrote compaction metadata**: When follow-up
   messages were queued after a compaction request, the queue's
   latestOptions got overwritten, losing the muxMetadata that marks
   the message as a compaction-request. The compaction would then be
   sent as a normal message, never triggering history replacement.

   Fix: Preserve the first muxMetadata and use it in produceMessage().
   This ensures compaction metadata survives even when follow-ups are
   queued afterward.

2. **Usage display showed pre-compaction context**: After compaction,
   the summary message's usage field contained the pre-compaction
   context size (since that's what was sent to generate the summary).
   This inflated the context window display, making it appear usage
   was still high and triggering auto-compaction again.

   Fix: Skip compacted messages when computing lastContextUsage.
   The summary's usage reflects historical cost, not current context.

_Generated with `mux`_
@ammar-agent ammar-agent force-pushed the fix-compaction-infinite-loop branch from e70d6d8 to 70b029f Compare December 3, 2025 18:31
@ammar-agent ammar-agent force-pushed the fix-compaction-infinite-loop branch from 38df95b to 88a6ad3 Compare December 3, 2025 18:50
@ammario ammario merged commit 9660f51 into main Dec 3, 2025
16 checks passed
@ammario ammario deleted the fix-compaction-infinite-loop branch December 3, 2025 18:57
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.

2 participants