Commit ad7e163
authored
🤖 fix: prevent compaction summary loss from race condition (#1007)
## Problem
When compaction completes, there's a race condition that can cause the
compaction summary to be lost from context:
1. StreamManager emits `stream-end` then continues to
`deletePartial`/`updateHistory`
2. CompactionHandler runs (async), clears history, appends summary
3. `sendQueuedMessages` triggers `commitToHistory`
4. `commitToHistory` finds stale `partial.json` (not yet deleted by
StreamManager)
5. The stale partial has the OLD historySequence from pre-compaction
6. `commitToHistory` appends this stale message to history, corrupting
context
## Solution
CompactionHandler now deletes `partial.json` BEFORE clearing history.
This ensures any concurrent `commitToHistory` calls find no partial and
become no-ops.
## Changes
- `src/node/services/compactionHandler.ts` - Delete partial before
compaction
- `src/node/services/agentSession.ts` - Pass partialService to
CompactionHandler
- `src/node/services/compactionHandler.test.ts` - Test for the fix
_Generated with `mux`_1 parent efd8a16 commit ad7e163
File tree
3 files changed
+58
-0
lines changed- src/node/services
3 files changed
+58
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
| 113 | + | |
113 | 114 | | |
114 | 115 | | |
115 | 116 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
51 | 72 | | |
52 | 73 | | |
53 | 74 | | |
| |||
112 | 133 | | |
113 | 134 | | |
114 | 135 | | |
| 136 | + | |
115 | 137 | | |
116 | 138 | | |
117 | 139 | | |
| |||
122 | 144 | | |
123 | 145 | | |
124 | 146 | | |
| 147 | + | |
125 | 148 | | |
126 | 149 | | |
127 | 150 | | |
128 | 151 | | |
| 152 | + | |
129 | 153 | | |
130 | 154 | | |
131 | 155 | | |
| |||
209 | 233 | | |
210 | 234 | | |
211 | 235 | | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
212 | 253 | | |
213 | 254 | | |
214 | 255 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| 17 | + | |
16 | 18 | | |
17 | 19 | | |
18 | 20 | | |
| |||
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
| 32 | + | |
30 | 33 | | |
31 | 34 | | |
32 | 35 | | |
33 | 36 | | |
34 | 37 | | |
35 | 38 | | |
| 39 | + | |
36 | 40 | | |
37 | 41 | | |
38 | 42 | | |
| |||
106 | 110 | | |
107 | 111 | | |
108 | 112 | | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
109 | 125 | | |
110 | 126 | | |
111 | 127 | | |
| |||
0 commit comments