Commit 9660f51
authored
🤖 fix: prevent compaction infinite loop and stale usage display (#886)
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`_1 parent b709eb3 commit 9660f51
File tree
3 files changed
+113
-21
lines changed- src
- browser/stores
- node/services
3 files changed
+113
-21
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
476 | 476 | | |
477 | 477 | | |
478 | 478 | | |
| 479 | + | |
479 | 480 | | |
480 | 481 | | |
481 | 482 | | |
482 | 483 | | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
483 | 489 | | |
484 | 490 | | |
485 | 491 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| |||
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
120 | 162 | | |
121 | 163 | | |
122 | 164 | | |
| |||
127 | 169 | | |
128 | 170 | | |
129 | 171 | | |
130 | | - | |
| 172 | + | |
131 | 173 | | |
132 | 174 | | |
133 | 175 | | |
| |||
140 | 182 | | |
141 | 183 | | |
142 | 184 | | |
143 | | - | |
144 | | - | |
| 185 | + | |
145 | 186 | | |
146 | | - | |
| 187 | + | |
| 188 | + | |
147 | 189 | | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
148 | 199 | | |
149 | 200 | | |
150 | 201 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
23 | 28 | | |
24 | 29 | | |
25 | | - | |
| 30 | + | |
26 | 31 | | |
27 | 32 | | |
28 | 33 | | |
| 34 | + | |
29 | 35 | | |
30 | 36 | | |
31 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
32 | 45 | | |
33 | 46 | | |
34 | | - | |
35 | | - | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
36 | 51 | | |
37 | 52 | | |
38 | 53 | | |
| |||
43 | 58 | | |
44 | 59 | | |
45 | 60 | | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
46 | 73 | | |
47 | 74 | | |
48 | 75 | | |
49 | 76 | | |
50 | 77 | | |
51 | 78 | | |
52 | 79 | | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
53 | 85 | | |
54 | 86 | | |
55 | 87 | | |
| |||
68 | 100 | | |
69 | 101 | | |
70 | 102 | | |
71 | | - | |
| 103 | + | |
72 | 104 | | |
73 | 105 | | |
74 | 106 | | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
| 107 | + | |
| 108 | + | |
79 | 109 | | |
80 | 110 | | |
81 | 111 | | |
| |||
90 | 120 | | |
91 | 121 | | |
92 | 122 | | |
93 | | - | |
94 | 123 | | |
95 | 124 | | |
96 | 125 | | |
97 | 126 | | |
98 | 127 | | |
99 | 128 | | |
100 | | - | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
101 | 134 | | |
102 | 135 | | |
103 | 136 | | |
| 137 | + | |
104 | 138 | | |
105 | 139 | | |
106 | 140 | | |
| |||
113 | 147 | | |
114 | 148 | | |
115 | 149 | | |
| 150 | + | |
116 | 151 | | |
117 | 152 | | |
118 | 153 | | |
| |||
0 commit comments