Repository navigation
Commit 4f6c187
* fix: serialize Init against Start (#24)
Init publishes the runtime context, the network mappings, port, grpcPort
and the environment-variable entries that Start consumes, all outside any
lock, while Start reads them under runnerMu. An overlapping Start could
launch uvicorn on a half-written port, and go test -race flags the pair.
Guarding only port and grpcPort would leave the environment manager
racing: resources.EnvironmentVariableManager has no synchronization of
its own, so the two calls are serialized outright, under a lock of their
own so Stop and Destroy can still interrupt Init's runner section.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* fix: decide restarts on what was launched, not just the request (#24)
Start answered "nothing to do" whenever the StartRequest matched the one
the running process was launched with. The request does not carry this
service's own port: s.port and s.grpcPort come from the InitRequest's
proposed network mappings. An Init that republished them between two
identical Starts therefore left uvicorn bound to the superseded port
while the agent answered STARTED, so the orchestrator routed to a port
nothing was listening on and the agent reported healthy throughout.
Folding the ports into startInputs would have been wrong: that
fingerprint also gates applyStartInputs, which must fire only when the
request itself changed, because the environment manager appends
overrides and endpoints and never removes them. The two questions are
distinct, so they now have distinct fingerprints — startInputs for "did
the request change", launchInputs for "is the running process still the
one this request describes". launchInputs covers every input to the
command line, hot-reload included, not just the ports this was found
through.
Start also acted on requests its caller had abandoned. It can wait on
initMu for as long as an Init takes, and the process it launches runs on
a background context, so a Start acquiring the lock after its deadline
passed would leave a service running for a request nobody awaited.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* test: make the Init/Start race test detect the race (#24)
TestInitIsSafeWithConcurrentStart released Init and Start from a bare
start gate. Measured against code with initMu removed, it reported the
race 0 times in 10: Init takes runnerMu three times (destroyed,
SetRuntimeContext, runnerEnv), and each acquisition orders the two
bodies against Start's own runnerMu section, so the detector sees no
concurrency. Its one postcondition — that a uvicorn process exists —
also held in the interleaving where Start ran first and launched on port
0. #25 had already retired this shape for the teardown test; this
repeats its fix, gating on the window Init is vulnerable in and
repeating so the detection is reliable rather than sampled.
The suite never exercised a cold Init, because a pre-installed
environment sends Init down runnerEnv's already-published branch and
skips CreateRunnerEnvironment — where the network mappings and the whole
environment manager are read and ActiveEnv is published. That was
untestable while #23 was open and is not any more, so the cold path gets
its own overlap, with Start pointed at a missing source location so it
reads everything and then fails in exec instead of launching a real
uvicorn. Both tests now detect the race 5/5 with initMu removed.
The 100ms sleep now fails fast: a Start that completes while Init is
still gated is the defect, so it is observed and reported rather than
waited out. It is deliberately only observed on that side — receiving
from the channel on the passing path would order Start ahead of Init's
release and hide the race. Reuses initTestRuntime rather than carrying a
second copy of the same fixture, and stops indexing past --port blindly.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent da01e1f commit 4f6c187
3 files changed
Lines changed: 345 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 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 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
76 | | - | |
77 | | - | |
78 | | - | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
79 | 85 | | |
80 | 86 | | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
81 | 113 | | |
82 | 114 | | |
83 | 115 | | |
84 | 116 | | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
85 | 125 | | |
86 | 126 | | |
87 | 127 | | |
| |||
175 | 215 | | |
176 | 216 | | |
177 | 217 | | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
178 | 223 | | |
179 | 224 | | |
180 | 225 | | |
| |||
330 | 375 | | |
331 | 376 | | |
332 | 377 | | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
333 | 381 | | |
334 | 382 | | |
335 | 383 | | |
| |||
448 | 496 | | |
449 | 497 | | |
450 | 498 | | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
451 | 510 | | |
452 | 511 | | |
453 | 512 | | |
| |||
458 | 517 | | |
459 | 518 | | |
460 | 519 | | |
| 520 | + | |
461 | 521 | | |
462 | 522 | | |
463 | 523 | | |
| |||
466 | 526 | | |
467 | 527 | | |
468 | 528 | | |
469 | | - | |
470 | | - | |
471 | | - | |
472 | | - | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
473 | 536 | | |
474 | 537 | | |
475 | 538 | | |
| |||
529 | 592 | | |
530 | 593 | | |
531 | 594 | | |
| 595 | + | |
532 | 596 | | |
533 | 597 | | |
534 | 598 | | |
| |||
722 | 786 | | |
723 | 787 | | |
724 | 788 | | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
725 | 802 | | |
726 | 803 | | |
727 | 804 | | |
| |||
0 commit comments