Repository navigation
Commit 37b03c7
committed
fix(daemon): re-issue the interrupted request against a replacement daemon
When the shared daemon dies under a live MCP frontend (#2796), the worker's
daemon exchange fails and the current failure path calls _Exit(EXIT_FAILURE)
— "a failed daemon transport cannot wake a thread blocked in stdio
portably". The agent then sees server EOF and every pooled connection to the
same daemon breaks at once. On Windows this happens whenever a client reaps
its spawned endpoint tree: DETACHED_PROCESS detaches the console, not the
process tree, so the shared daemon dies with the endpoint that spawned it.
Keep the reader untouched and recover on the worker instead: when
cbm_daemon_application_client_mcp_tagged fails and the caller supplied a
replacement supplier (new daemon_lost callback on mcp_run), swap in the
replacement client, re-mint the request token (tokens are scoped to the
client that reserved them), and re-issue the very request whose exchange was
interrupted. Bounded by FRONTEND_DAEMON_RECONNECT_MAX; without a callback or
once the budget is spent the old immediate-exit path stays. A cancellation
that arrives mid-reconnect targets the old token and is dropped — the
re-issued request completes instead.
main() supplies the callback: it owns the dead client (closes it), re-runs
the connect-or-spawn leg plus session context, and returns the replacement.
UI flags are not re-applied; the daemon persists its UI configuration.
Verified on WSL/gcc 13.3 with a real daemon: two stdio endpoints sharing one
daemon, kill -9 the daemon, the next request on the survivor is served by a
re-spawned daemon (stderr: one daemon_lost_reconnect warning); pre-fix the
same scenario exits 1 and the request is lost. scripts/test.sh --suites
daemon_frontend stays green.
Fixes #2796
Signed-off-by: Minervaowl7 <127482476+Minervaowl7@users.noreply.github.com>1 parent 10ab613 commit 37b03c7
4 files changed
Lines changed: 158 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
42 | 46 | | |
43 | 47 | | |
44 | 48 | | |
| |||
90 | 94 | | |
91 | 95 | | |
92 | 96 | | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
93 | 103 | | |
94 | 104 | | |
95 | 105 | | |
| |||
502 | 512 | | |
503 | 513 | | |
504 | 514 | | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
505 | 574 | | |
506 | 575 | | |
507 | 576 | | |
| |||
523 | 592 | | |
524 | 593 | | |
525 | 594 | | |
526 | | - | |
527 | | - | |
528 | | - | |
| 595 | + | |
529 | 596 | | |
530 | 597 | | |
531 | 598 | | |
| |||
544 | 611 | | |
545 | 612 | | |
546 | 613 | | |
547 | | - | |
548 | | - | |
549 | | - | |
550 | | - | |
551 | | - | |
552 | | - | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
553 | 622 | | |
554 | 623 | | |
555 | 624 | | |
| |||
657 | 726 | | |
658 | 727 | | |
659 | 728 | | |
660 | | - | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
661 | 732 | | |
662 | 733 | | |
663 | 734 | | |
664 | 735 | | |
665 | 736 | | |
666 | 737 | | |
667 | 738 | | |
| 739 | + | |
| 740 | + | |
668 | 741 | | |
669 | 742 | | |
670 | 743 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
20 | 28 | | |
21 | 29 | | |
22 | 30 | | |
| |||
66 | 74 | | |
67 | 75 | | |
68 | 76 | | |
69 | | - | |
70 | | - | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
71 | 82 | | |
72 | | - | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
73 | 86 | | |
74 | 87 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2785 | 2785 | | |
2786 | 2786 | | |
2787 | 2787 | | |
| 2788 | + | |
| 2789 | + | |
| 2790 | + | |
| 2791 | + | |
| 2792 | + | |
| 2793 | + | |
| 2794 | + | |
| 2795 | + | |
| 2796 | + | |
| 2797 | + | |
| 2798 | + | |
| 2799 | + | |
| 2800 | + | |
| 2801 | + | |
| 2802 | + | |
| 2803 | + | |
| 2804 | + | |
| 2805 | + | |
| 2806 | + | |
| 2807 | + | |
| 2808 | + | |
| 2809 | + | |
| 2810 | + | |
| 2811 | + | |
| 2812 | + | |
| 2813 | + | |
| 2814 | + | |
| 2815 | + | |
| 2816 | + | |
| 2817 | + | |
| 2818 | + | |
| 2819 | + | |
| 2820 | + | |
| 2821 | + | |
| 2822 | + | |
| 2823 | + | |
| 2824 | + | |
| 2825 | + | |
| 2826 | + | |
| 2827 | + | |
| 2828 | + | |
| 2829 | + | |
| 2830 | + | |
| 2831 | + | |
| 2832 | + | |
| 2833 | + | |
| 2834 | + | |
2788 | 2835 | | |
2789 | 2836 | | |
2790 | 2837 | | |
| |||
3433 | 3480 | | |
3434 | 3481 | | |
3435 | 3482 | | |
3436 | | - | |
| 3483 | + | |
| 3484 | + | |
| 3485 | + | |
| 3486 | + | |
| 3487 | + | |
| 3488 | + | |
| 3489 | + | |
| 3490 | + | |
3437 | 3491 | | |
3438 | 3492 | | |
3439 | 3493 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
213 | 213 | | |
214 | 214 | | |
215 | 215 | | |
216 | | - | |
| 216 | + | |
217 | 217 | | |
218 | 218 | | |
219 | 219 | | |
| |||
579 | 579 | | |
580 | 580 | | |
581 | 581 | | |
582 | | - | |
| 582 | + | |
583 | 583 | | |
584 | 584 | | |
585 | 585 | | |
| |||
920 | 920 | | |
921 | 921 | | |
922 | 922 | | |
923 | | - | |
| 923 | + | |
924 | 924 | | |
925 | 925 | | |
926 | 926 | | |
| |||
1419 | 1419 | | |
1420 | 1420 | | |
1421 | 1421 | | |
1422 | | - | |
| 1422 | + | |
1423 | 1423 | | |
1424 | 1424 | | |
1425 | 1425 | | |
| |||
0 commit comments