Repository navigation
Commit 5e23839
committed
fix(daemon): make request completion transactional and EOF drain-safe
Back-to-back requests on one frontend<->daemon connection failed roughly
half the time on loaded Windows hosts, surfacing as wandering MCP session
drops (smoke Phase 5/5e/5f "no tools/list response", "timed out waiting for
id=2"). Root cause, confirmed on real Windows: the application worker stored
its done flag AFTER writing the response, so a client that pipelines its
next request the instant it sees a response raced the previous worker's
final instructions and its join, and admission rejected the new request
with BUSY. On EOF that BUSY was then classified as an expected shutdown and
the response was silently dropped with a success exit; mid-session it exited
non-zero. A timing-sensitive heisenbug — any added stderr shifted the window
and it passed.
- runtime_application_worker publishes the done flag BEFORE sending the
response, so completion is one atomic transition from the client's view:
by the time any client can react, the slot already reads reusable. The
admission side joins the thread after observing the flag, which absorbs
the send tail. No timing constants.
- frontend_should_stop's input-closed leg now also requires no request
in flight, so a daemon-side failure of the final post-EOF item is loud,
never swallowed as an expected stop.
- The EOF drain is now progress-aware: it resets its window on each
completed item, bounding stuckness rather than total batch length, so a
slow cold daemon spawn no longer abandons queued tail responses.
- Latch the never-connected shutdown window on a monotonic admitted-total
counter instead of sampling the live client count, which can read zero
between two short-lived sessions and stop a daemon mid-conversation.
- Add structured lifecycle diagnostics (daemon.runtime_stopping reason=,
lifetime_end reason=, connection_end) so this class is observable in the
logs instead of being inferred.
Validated: real-Windows loop 12/12 (was ~50% loss), macOS daemon suites
143/143.
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>1 parent aa90491 commit 5e23839
4 files changed
Lines changed: 108 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
31 | 30 | | |
32 | 31 | | |
33 | 32 | | |
34 | 33 | | |
35 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
36 | 42 | | |
37 | 43 | | |
38 | 44 | | |
| |||
71 | 77 | | |
72 | 78 | | |
73 | 79 | | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
74 | 84 | | |
75 | 85 | | |
76 | 86 | | |
| |||
190 | 200 | | |
191 | 201 | | |
192 | 202 | | |
193 | | - | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
194 | 212 | | |
195 | 213 | | |
196 | 214 | | |
| |||
438 | 456 | | |
439 | 457 | | |
440 | 458 | | |
| 459 | + | |
441 | 460 | | |
442 | 461 | | |
443 | 462 | | |
| |||
540 | 559 | | |
541 | 560 | | |
542 | 561 | | |
| 562 | + | |
543 | 563 | | |
544 | 564 | | |
545 | 565 | | |
| |||
598 | 618 | | |
599 | 619 | | |
600 | 620 | | |
601 | | - | |
602 | | - | |
603 | | - | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
604 | 635 | | |
605 | 636 | | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
606 | 643 | | |
607 | 644 | | |
608 | 645 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
679 | 679 | | |
680 | 680 | | |
681 | 681 | | |
682 | | - | |
683 | 682 | | |
684 | 683 | | |
685 | 684 | | |
686 | 685 | | |
| 686 | + | |
687 | 687 | | |
688 | 688 | | |
689 | 689 | | |
| |||
696 | 696 | | |
697 | 697 | | |
698 | 698 | | |
699 | | - | |
700 | | - | |
701 | | - | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
702 | 705 | | |
703 | 706 | | |
| 707 | + | |
| 708 | + | |
704 | 709 | | |
705 | 710 | | |
706 | 711 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
142 | 142 | | |
143 | 143 | | |
144 | 144 | | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
145 | 151 | | |
146 | 152 | | |
147 | 153 | | |
| |||
1019 | 1025 | | |
1020 | 1026 | | |
1021 | 1027 | | |
1022 | | - | |
| 1028 | + | |
| 1029 | + | |
1023 | 1030 | | |
1024 | 1031 | | |
1025 | 1032 | | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
1026 | 1038 | | |
1027 | 1039 | | |
1028 | 1040 | | |
| |||
1033 | 1045 | | |
1034 | 1046 | | |
1035 | 1047 | | |
1036 | | - | |
| 1048 | + | |
| 1049 | + | |
1037 | 1050 | | |
1038 | 1051 | | |
1039 | | - | |
| 1052 | + | |
1040 | 1053 | | |
1041 | 1054 | | |
1042 | 1055 | | |
| |||
1084 | 1097 | | |
1085 | 1098 | | |
1086 | 1099 | | |
1087 | | - | |
| 1100 | + | |
| 1101 | + | |
1088 | 1102 | | |
1089 | 1103 | | |
1090 | 1104 | | |
| |||
1098 | 1112 | | |
1099 | 1113 | | |
1100 | 1114 | | |
1101 | | - | |
| 1115 | + | |
| 1116 | + | |
1102 | 1117 | | |
1103 | 1118 | | |
1104 | 1119 | | |
| |||
1121 | 1136 | | |
1122 | 1137 | | |
1123 | 1138 | | |
| 1139 | + | |
1124 | 1140 | | |
1125 | 1141 | | |
1126 | 1142 | | |
| |||
1202 | 1218 | | |
1203 | 1219 | | |
1204 | 1220 | | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
1205 | 1232 | | |
1206 | 1233 | | |
1207 | 1234 | | |
1208 | 1235 | | |
1209 | 1236 | | |
1210 | 1237 | | |
1211 | | - | |
1212 | 1238 | | |
1213 | 1239 | | |
1214 | 1240 | | |
| |||
1383 | 1409 | | |
1384 | 1410 | | |
1385 | 1411 | | |
1386 | | - | |
| 1412 | + | |
1387 | 1413 | | |
1388 | 1414 | | |
1389 | 1415 | | |
| |||
1569 | 1595 | | |
1570 | 1596 | | |
1571 | 1597 | | |
| 1598 | + | |
| 1599 | + | |
| 1600 | + | |
| 1601 | + | |
| 1602 | + | |
| 1603 | + | |
| 1604 | + | |
| 1605 | + | |
| 1606 | + | |
1572 | 1607 | | |
1573 | 1608 | | |
1574 | 1609 | | |
| |||
2026 | 2061 | | |
2027 | 2062 | | |
2028 | 2063 | | |
| 2064 | + | |
| 2065 | + | |
| 2066 | + | |
| 2067 | + | |
| 2068 | + | |
| 2069 | + | |
| 2070 | + | |
| 2071 | + | |
| 2072 | + | |
| 2073 | + | |
2029 | 2074 | | |
2030 | 2075 | | |
2031 | 2076 | | |
| |||
2129 | 2174 | | |
2130 | 2175 | | |
2131 | 2176 | | |
2132 | | - | |
| 2177 | + | |
2133 | 2178 | | |
2134 | 2179 | | |
2135 | 2180 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
248 | 248 | | |
249 | 249 | | |
250 | 250 | | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
251 | 255 | | |
252 | 256 | | |
253 | 257 | | |
| |||
0 commit comments