Repository navigation
Commit a8e7e8c
fix(infra): refuse blind replay of a recovered session delivery once its turn has run
The session-delivery recovery path drainQueuedEntry
(src/infra/session-delivery-queue-recovery.ts) delivers an entry then acks it
(at-least-once). If the agent turn re-runs (dispatchAssembledChannelTurn, which can
send via the message tool) but the process dies before ack, the entry stays pending
and the next recovery blind-replays it: the same turn runs twice (non-idempotent
LLM/tool side effects) and its reply is sent twice.
#88665 moved both delivery queues onto a shared SQLite backing with a recovery_state
column; the parallel outbound queue uses it to refuse a blind replay without adapter
reconciliation, but the session-delivery drain neither set nor read it.
Wire recovery_state into the session drain at the turn-execution boundary so the
refuse decision is precise:
- The deliver seam (server-restart-sentinel.ts) reports onSendAttemptStart right
before the agent turn runs, and onSendDeferred if that attempt was merely deferred
because the session was busy (the busy turn produces a busy-retry response, no
durable work). The no-op deliver paths (systemEvent / changed-session / no-route)
never run the turn and report neither.
- drainQueuedEntry persists the send marker on onSendAttemptStart (and clears it on
onSendDeferred). A recovered entry still carrying the marker is refused (fail-safe
moveToFailed). On a thrown deliver, a turn that began running (sendAttempted) is
refused even if it threw after sending, while a pre-send / busy-deferred / no-op
failure stays retryable (at-least-once preserved for genuine pre-send failures).
This matches the outbound queue's no-reconcile contract and addresses the
sent-before-error case (a turn that sends then throws is no longer cleared and
replayed). Tradeoff: a crash in the narrow window after the turn starts but before
ack moves the entry to failed/ rather than replaying it (fail-safe over at-least-once),
the same product choice the outbound queue makes without a reconcile capability.
Adds regression tests: crash-before-ack, recovered-marker refuse, sent-before-error
throw refuse, and pre-send failure stays retryable.
AI-assisted: drafted with claude code (claude-opus-4-8).
Co-Authored-By: Claude Opus 4.8 <[email protected]>1 parent 2dbbef4 commit a8e7e8c
4 files changed
Lines changed: 329 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
241 | 241 | | |
242 | 242 | | |
243 | 243 | | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
244 | 251 | | |
245 | 252 | | |
246 | 253 | | |
| |||
313 | 320 | | |
314 | 321 | | |
315 | 322 | | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
316 | 327 | | |
317 | 328 | | |
318 | 329 | | |
| |||
353 | 364 | | |
354 | 365 | | |
355 | 366 | | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
356 | 376 | | |
357 | 377 | | |
358 | 378 | | |
| |||
408 | 428 | | |
409 | 429 | | |
410 | 430 | | |
411 | | - | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
412 | 438 | | |
413 | 439 | | |
414 | 440 | | |
| |||
435 | 461 | | |
436 | 462 | | |
437 | 463 | | |
438 | | - | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
439 | 471 | | |
440 | 472 | | |
441 | 473 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| 14 | + | |
13 | 15 | | |
14 | 16 | | |
15 | 17 | | |
| |||
23 | 25 | | |
24 | 26 | | |
25 | 27 | | |
26 | | - | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
27 | 43 | | |
28 | 44 | | |
29 | 45 | | |
| |||
111 | 127 | | |
112 | 128 | | |
113 | 129 | | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
114 | 145 | | |
115 | 146 | | |
116 | 147 | | |
| |||
119 | 150 | | |
120 | 151 | | |
121 | 152 | | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
122 | 176 | | |
123 | | - | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
124 | 187 | | |
125 | 188 | | |
126 | 189 | | |
127 | 190 | | |
128 | 191 | | |
129 | 192 | | |
130 | 193 | | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
131 | 204 | | |
132 | 205 | | |
133 | 206 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
65 | 73 | | |
66 | 74 | | |
67 | 75 | | |
| |||
149 | 157 | | |
150 | 158 | | |
151 | 159 | | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
0 commit comments