Commit c719f84
authored
fix(core,sdk): stop chat.agent losing messages during recovery (#4907)
## Summary
When a chat.agent run boots to continue a session (a version handover,
or a retry after a crash), it replays the unacknowledged user messages
off `session.in` and dispatches them itself. A previous change stopped
the live tail from re-answering those same messages by folding them into
the resume cursor in one step. That cursor is what the next boot reads
to know where to resume, and folding in every recovered message at once
let it advance past a message the run had not answered yet. So if the
run answered the first recovered message, wrote its turn boundary, then
crashed before dispatching the rest, the next boot resumed past those
messages and they were never answered.
## Fix
A recovered message is now claimed on the session-stream router instead
of folded into the cursor. A claim does two independent things:
- it drops the message however late the live tail re-delivers it, so a
recovered message is never answered twice;
- it holds the resume cursor behind that message until the boot has
dispatched it, so a turn boundary never publishes a cursor past a
message still waiting for a turn.
The boot settles each claim as it dispatches the message, or right away
for a message it folds into the seed chain or deliberately skips, so the
cursor only advances over messages that have actually been handled. A
claimed record whose route re-read never arrives over the tail degrades
to being answered twice on the next boot, never to being dropped.
Covered by router-level unit tests for the claim/settle floor and a
chat.agent boot test asserting the cursor published after the first
recovered turn stays behind the still-unanswered ones.1 parent 6f5c49c commit c719f84
5 files changed
Lines changed: 413 additions & 33 deletions
File tree
- .changeset
- packages
- core/src/v3/sessionStreams
- trigger-sdk
- src/v3
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
573 | 573 | | |
574 | 574 | | |
575 | 575 | | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
64 | | - | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
65 | 72 | | |
66 | 73 | | |
67 | 74 | | |
| |||
143 | 150 | | |
144 | 151 | | |
145 | 152 | | |
| 153 | + | |
| 154 | + | |
146 | 155 | | |
147 | 156 | | |
148 | 157 | | |
| |||
197 | 206 | | |
198 | 207 | | |
199 | 208 | | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
200 | 260 | | |
201 | 261 | | |
202 | 262 | | |
| |||
213 | 273 | | |
214 | 274 | | |
215 | 275 | | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
216 | 280 | | |
217 | 281 | | |
218 | 282 | | |
| |||
308 | 372 | | |
309 | 373 | | |
310 | 374 | | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
311 | 378 | | |
312 | 379 | | |
313 | 380 | | |
| |||
518 | 585 | | |
519 | 586 | | |
520 | 587 | | |
| 588 | + | |
| 589 | + | |
521 | 590 | | |
522 | 591 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2322 | 2322 | | |
2323 | 2323 | | |
2324 | 2324 | | |
2325 | | - | |
| 2325 | + | |
| 2326 | + | |
| 2327 | + | |
| 2328 | + | |
| 2329 | + | |
2326 | 2330 | | |
2327 | 2331 | | |
2328 | 2332 | | |
| |||
2353 | 2357 | | |
2354 | 2358 | | |
2355 | 2359 | | |
2356 | | - | |
2357 | | - | |
2358 | | - | |
2359 | | - | |
2360 | | - | |
2361 | | - | |
2362 | | - | |
2363 | | - | |
2364 | | - | |
2365 | | - | |
2366 | | - | |
2367 | 2360 | | |
2368 | 2361 | | |
2369 | 2362 | | |
| 2363 | + | |
| 2364 | + | |
| 2365 | + | |
| 2366 | + | |
2370 | 2367 | | |
2371 | 2368 | | |
2372 | 2369 | | |
| |||
7272 | 7269 | | |
7273 | 7270 | | |
7274 | 7271 | | |
| 7272 | + | |
| 7273 | + | |
| 7274 | + | |
| 7275 | + | |
| 7276 | + | |
| 7277 | + | |
| 7278 | + | |
| 7279 | + | |
| 7280 | + | |
| 7281 | + | |
| 7282 | + | |
| 7283 | + | |
| 7284 | + | |
| 7285 | + | |
7275 | 7286 | | |
7276 | 7287 | | |
7277 | 7288 | | |
| |||
7437 | 7448 | | |
7438 | 7449 | | |
7439 | 7450 | | |
7440 | | - | |
7441 | | - | |
7442 | | - | |
7443 | | - | |
7444 | | - | |
7445 | | - | |
7446 | | - | |
7447 | | - | |
| 7451 | + | |
7448 | 7452 | | |
7449 | 7453 | | |
7450 | 7454 | | |
7451 | | - | |
| 7455 | + | |
7452 | 7456 | | |
7453 | 7457 | | |
7454 | 7458 | | |
| |||
7538 | 7542 | | |
7539 | 7543 | | |
7540 | 7544 | | |
7541 | | - | |
| 7545 | + | |
7542 | 7546 | | |
7543 | 7547 | | |
7544 | 7548 | | |
| |||
7547 | 7551 | | |
7548 | 7552 | | |
7549 | 7553 | | |
7550 | | - | |
| 7554 | + | |
| 7555 | + | |
| 7556 | + | |
| 7557 | + | |
| 7558 | + | |
| 7559 | + | |
| 7560 | + | |
| 7561 | + | |
| 7562 | + | |
| 7563 | + | |
7551 | 7564 | | |
7552 | | - | |
| 7565 | + | |
| 7566 | + | |
| 7567 | + | |
7553 | 7568 | | |
7554 | | - | |
| 7569 | + | |
7555 | 7570 | | |
7556 | 7571 | | |
7557 | 7572 | | |
| |||
7582 | 7597 | | |
7583 | 7598 | | |
7584 | 7599 | | |
7585 | | - | |
| 7600 | + | |
| 7601 | + | |
7586 | 7602 | | |
7587 | 7603 | | |
7588 | 7604 | | |
7589 | 7605 | | |
7590 | | - | |
| 7606 | + | |
7591 | 7607 | | |
7592 | 7608 | | |
7593 | 7609 | | |
| |||
7596 | 7612 | | |
7597 | 7613 | | |
7598 | 7614 | | |
7599 | | - | |
| 7615 | + | |
| 7616 | + | |
| 7617 | + | |
| 7618 | + | |
| 7619 | + | |
| 7620 | + | |
| 7621 | + | |
| 7622 | + | |
| 7623 | + | |
| 7624 | + | |
| 7625 | + | |
7600 | 7626 | | |
7601 | 7627 | | |
7602 | 7628 | | |
| |||
7780 | 7806 | | |
7781 | 7807 | | |
7782 | 7808 | | |
7783 | | - | |
| 7809 | + | |
7784 | 7810 | | |
7785 | 7811 | | |
7786 | 7812 | | |
| |||
8031 | 8057 | | |
8032 | 8058 | | |
8033 | 8059 | | |
8034 | | - | |
| 8060 | + | |
8035 | 8061 | | |
8036 | 8062 | | |
8037 | 8063 | | |
| |||
8686 | 8712 | | |
8687 | 8713 | | |
8688 | 8714 | | |
| 8715 | + | |
8689 | 8716 | | |
8690 | 8717 | | |
8691 | 8718 | | |
| |||
9504 | 9531 | | |
9505 | 9532 | | |
9506 | 9533 | | |
| 9534 | + | |
| 9535 | + | |
9507 | 9536 | | |
9508 | 9537 | | |
9509 | 9538 | | |
| |||
9634 | 9663 | | |
9635 | 9664 | | |
9636 | 9665 | | |
9637 | | - | |
| 9666 | + | |
9638 | 9667 | | |
9639 | 9668 | | |
9640 | 9669 | | |
| |||
10012 | 10041 | | |
10013 | 10042 | | |
10014 | 10043 | | |
10015 | | - | |
| 10044 | + | |
10016 | 10045 | | |
10017 | 10046 | | |
10018 | 10047 | | |
| |||
0 commit comments