🤖 fix: prevent compaction infinite loop and stale usage display#886
Merged
🤖 fix: prevent compaction infinite loop and stale usage display#886
Conversation
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`_
e70d6d8 to
70b029f
Compare
38df95b to
88a6ad3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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 themuxMetadatathat marks the message as acompaction-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
continueMessagefield 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