Repository navigation
test(runner): wait for the hung first refresh with bounds a loaded host can meet (#2261) - #2267
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 12 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
CodeRabbit did not review this head (review limit reached). This is the review that stands in for it. omo-native-code-reviewer (adversarial, read-only), on the first version of this commit: REQUEST_CHANGES. Every finding is resolved in d5e44ce:
The reviewer confirmed that the cache-wait case still fails when run.sh ignores |
…st can meet (#2261) The --cache-wait case had Bun's 5 s default timeout for two launcher runs and fixed 5 s / 1 s bounds in runRunnerUntilHung; pinned to two cores beside eight busy loops it failed 10/10. --cache-wait counts whole bash SECONDS, so it can also end before the refresh reaches its hung stub. The gh stub now withholds the registration token (for up to 60 s) until an armed hang has happened. Every bound in the helper is 30 s and ends at its event, except the stop on SIGTERM, which keeps 4 s: under the 5 s after which run.sh's timeouts kill what ignored it. The hung stubs sleep 120 s, longer than the bound, so a launcher that waits for them still fails, and the three hang tests get timeouts that cover their runs. Under the same load the three pass 30/30; with run.sh's cache-wait deadline removed the case still fails with "still running". Closes #2261
The test polled for the stub's hang file every 10 ms, and the gh stub polled for it every 50 ms with a try count that is no real deadline under load. Now the hanging stub writes a byte to a FIFO as it hangs and the test blocks reading it (killed after the 30 s bound); the gh stub hands out a token only after reading a second FIFO, which the test opens once it has seen the hang.
d5e44ce to
a554080
Compare
|
Merging a554080 (test only; closes #2261). The runner test that failed under load ('starts the runners after --cache-wait when the first refresh hangs') now waits on FIFO handshakes instead of polling: the hanging stub writes a byte the test blocks on, and the gh stub hands out a token only after a second FIFO, within one 30 s bound; the remaining timers are upper bounds in Promise.race. scripts/self-hosted-runner/run.sh is unchanged, the test still fails when run.sh ignores --cache-wait, and the first review passed it 3/3 at load 88-105 before the polling was replaced (30/30 per the lane after). Reviewed by an omo reviewer; one round removed the polling, per the maintainer side (Dori). |
…changes (#772) (#2260) ## Change A burst of agent status changes closed the browser's live event stream (`/api/machines/events`), and the sidebar went stale for about three seconds. The stream's slow-consumer guard (`server/machine-api.ts`) ended the response once `controller.desiredSize < -4`. With the default count strategy (high-water mark 1) that is **more than five queued chunks**, whatever their size. With 20 or more agents changing status at once, more than five frames were queued before the response was written out (44 of 120 measured bursts on main, at 20 to 300 panes), the stream closed, EventSource waited its ~3 s retry, and the page re-read preferences, read finishes, herdr's row tokens and the whole roster. Status frames that were still queued were lost. The roster read after the reconnect only seeds statuses (`useAlertSignals.onRoster`), so a finish in that gap rang no sound and showed no drop-in. The guard now counts bytes, per stream and for all streams together: - **Per stream:** a browser that fell behind may have 4 MiB waiting for it. A frame larger than that, such as the roster of thousands of panes a stream opens with, is let through on top of the 4 MiB only while that frame is still queued (tracked by byte offsets). Once it has been read, the stream is held to 4 MiB again, so one large roster is never a lasting multiplier. - **All streams together**, watching devices included, every queued byte counted, large frames too: 32 MiB. Past it, the streams that stopped reading are ended, the one holding the most first. A stream has stopped reading when its browser has taken nothing from a waiting queue for 30 s. A browser that reads on is never that, however much it has waiting. A stream that has just been sent its roster has not stopped reading, so browsers opening together with 5,000-pane rosters keep theirs, and so does one stream sent a roster larger than the whole total. - **Ceiling:** even while no stream has stopped reading yet, all of them together never hold more than 64 MiB. A frame past that is refused and its stream ended, and that browser opens it again. The exception is a frame its stream is alone in holding: one roster larger than everything still gets through. - **Ending:** a stream that falls behind, is refused, or whose browser goes away (abort) is ended with `controller.error()`, not `close()`, so what waited for it is dropped instead of kept readable. A revoked device that keeps up still gets a clean end, as before. One with a backlog waiting has it dropped. - **What stalled browsers can hold:** 64 MiB at most, all of them together, and 32 MiB once they have taken nothing for 30 s. Main's limit was six chunks of any size per browser, with no total. - **Cost:** the total is kept as an upper bound from each stream's last write and counted exactly only near the budget, so a frame costs the same with a thousand streams as with a few. For scale, a 300-pane roster frame is 288 KB, so at the sizes measured below each stream's bound is 4 MiB. Not touched: herdr RPC, attach streams, focus, `--takeover`. Remote PCs' events reach the browser through the same stream and get the same fix. ## Measurement `scripts/roster-bench.ts` (new) opens N panes in the isolated herdr of a check run (four per workspace), reports a Claude agent in each through `pane.report_agent`, starts the Ovis server in a child process (temp state dir and HOME, port 0), and opens the built client in headless Chrome at 1440x900 with reduced motion. One run is two bursts: every pane reports `working`, then every pane reports `idle` (a finish). Each burst is measured from its first report until every agent row shows the new status and the event stream has been quiet for 750 ms. Metrics: Chrome's TaskDuration (browser main thread), time until the last row updated, server CPU time over the same window, and stream drops (EventSource `error`). ``` bun run check run --build bun scripts/roster-bench.ts --panes 20,100,300 --runs 5 --out <file.json> ``` Runs alternated main and this branch under `dori heavy` on a 128-core host that was also running other work (load average 42–103; CPU 16–67% busy, recorded per run). Each row pools every run of that size: 2 rounds × 5 runs at 20 and 300 panes, plus two focused 100-pane series at 100. Medians, with the 10th–90th percentile in brackets. | Panes | Burst | Variant | Bursts | Stream dropped | Rows updated, ms | Browser main thread, ms | Server CPU, ms | Slowest rows update, ms | |---:|---|---|---:|---:|---:|---:|---:|---:| | 20 | to working | main | 10 | 6 | 1903 (878–3156) | 697 (482–1303) | 97 (46–144) | 3156 | | 20 | to working | fix | 10 | 0 | 218 (162–328) | 292 (247–631) | 39 (23–86) | 328 | | 20 | to done | main | 10 | 7 | 1216 (252–3118) | 526 (302–1292) | 100 (51–162) | 3118 | | 20 | to done | fix | 10 | 0 | 221 (182–407) | 233 (142–620) | 45 (15–221) | 407 | | 100 | to working | main | 40 | 15 | 327 (203–3182) | 607 (308–1983) | 55 (20–271) | 3269 | | 100 | to working | fix | 40 | 0 | 310 (211–444) | 672 (514–1049) | 64 (35–213) | 518 | | 100 | to done | main | 40 | 11 | 294 (189–3288) | 293 (159–1775) | 66 (20–304) | 3382 | | 100 | to done | fix | 40 | 0 | 270 (224–407) | 336 (229–640) | 53 (29–335) | 497 | | 300 | to working | main | 10 | 3 | 1565 (724–4484) | 1972 (1154–4965) | 163 (78–1188) | 4484 | | 300 | to working | fix | 10 | 0 | 993 (640–1626) | 1650 (1382–2595) | 148 (89–1266) | 1626 | | 300 | to done | main | 10 | 2 | 906 (502–2004) | 1227 (512–2019) | 292 (64–1125) | 2004 | | 300 | to done | fix | 10 | 0 | 701 (542–1233) | 759 (660–1255) | 138 (93–788) | 1233 | Stream drops: **main 44 of 120 bursts, this branch 0 of 120.** Server memory after the runs: 48–86 MB on both, no trend. ### Control: is the cost of a burst the fix's, or the frames'? On bursts where main did not drop, a 100-pane series showed main using less browser time than this branch. Those bursts select themselves: a burst light enough not to overflow the old queue is also a cheap one to draw. As a control, main's own code with only the close check disabled (`< -1e9`: main's delivery, never dropping) ran beside both, 100 panes, 2 rounds × 5 runs, alternating: | Burst | Variant | Stream dropped | Rows updated, ms | Browser main thread, ms | Server CPU, ms | |---|---|---:|---:|---:|---:| | to working | main, no close | 0/10 | 473 (352–665) | 925 (808–1165) | 106 (89–401) | | to working | this branch | 0/10 | 346 (298–706) | 860 (633–1382) | 91 (51–337) | | to working | main | 5/10 | 913 (378–4020) | 1260 (717–3776) | 230 (71–683) | | to done | main, no close | 0/10 | 437 (370–669) | 591 (516–941) | 96 (80–283) | | to done | this branch | 0/10 | 395 (260–597) | 508 (316–774) | 86 (45–418) | | to done | main | 5/10 | 1339 (348–3938) | 1237 (645–3520) | 158 (84–842) | This branch costs no more than main's own delivery of every frame: the byte bound adds nothing, and what a burst costs is the frames themselves. That series ran on a busy host (load 80–115, CPU 28–60% busy). ### After the merge-pass fixes The same harness, run again on the final head (main, then this head, 3 runs per size; ranges are min–max; load 64–104, CPU 32–55% busy): | Panes | Burst | Variant | Bursts | Stream dropped | Rows updated, ms | Browser main thread, ms | Server CPU, ms | |---:|---|---|---:|---:|---:|---:|---:| | 20 | to working | main | 3 | 2 | 2296 (210–3214) | 970 (224–1002) | 146 (24–148) | | 20 | to working | this head | 3 | 0 | 195 (133–299) | 416 (298–508) | 82 (29–199) | | 20 | to done | main | 3 | 3 | 3125 (1176–3176) | 808 (771–833) | 128 (85–199) | | 20 | to done | this head | 3 | 0 | 210 (149–223) | 150 (142–255) | 31 (26–44) | | 100 | to working | main | 3 | 2 | 1728 (424–2904) | 1207 (670–1590) | 203 (57–342) | | 100 | to working | this head | 3 | 0 | 576 (494–595) | 1169 (1162–1186) | 145 (131–297) | | 100 | to done | main | 3 | 1 | 304 (222–3241) | 368 (223–1537) | 29 (28–139) | | 100 | to done | this head | 3 | 0 | 430 (395–511) | 562 (514–691) | 143 (135–533) | | 300 | to working | main | 3 | 1 | 665 (569–3523) | 1089 (1020–2977) | 104 (91–292) | | 300 | to working | this head | 3 | 0 | 1200 (979–1217) | 2295 (2263–3080) | 379 (219–1183) | | 300 | to done | main | 3 | 2 | 3615 (914–3759) | 1824 (1062–2733) | 758 (139–967) | | 300 | to done | this head | 3 | 0 | 921 (875–2119) | 1056 (1014–2200) | 225 (156–722) | Stream drops: **main 11 of 18 bursts, this head 0 of 18.** Slowest rows update: main 3759 ms, this head 2119 ms. Server RSS after the runs: main 63.8–83.7 MB, this head 45.3–66.5 MB. Where main dropped nothing, the medians fall within the spread seen across the earlier rounds, and the round-1 control showed that delivering every frame costs main as much. ## Tests `server/machine-api.test.ts` (new) drives the real stream handler with a stand-in roster that tells every open stream. The tests write the policy as their own numbers (4 MiB, 32 MiB): doubling either production constant fails them. - 300 status frames written before the reader reads one all arrive, and the stream stays open. On main the stream ends. - A frame larger than 4 MiB, followed by 20 more, stays open and delivers all of them. - A reader that never reads keeps 4 MiB waiting. Past that, its stream is errored, nothing that waited is delivered, and the stream leaves the total. - A large frame gives room only while it waits: once it has been read, the stream is held to 4 MiB again. - A second large frame waiting behind the first ends the stream. - A stream that opens with a frame larger than the 32 MiB total gets it and the 20 frames after it, and seven streams opening together each get a 5,000-pane roster (5.3 MB). Neither ends a stream. - A revoked device that keeps up gets a clean end. One that stopped reading is errored with nothing delivered. - - Five streams at 3.9 MiB and five at 3.0 MiB whose browsers have taken nothing for 30 s, plus one that has just been sent a frame: passing 32 MiB ends one of the 3.9 MiB five, never a 3.0 MiB one, never the fresh one. - Twelve streams at 3.5 MiB (42 MiB) stay within 64 MiB while they are fresh, and are held to 32 MiB once they have stopped reading. A reader that keeps up still gets a full 300-frame burst. - 128 streams each sent a 5.3 MB roster hold 64 MiB at most at once, and 32 MiB once they have stopped reading. - A browser that goes away has its stream errored: nothing that waited is still readable, it counts for nothing, and eight streams opened after it get the whole total. - A browser that keeps a steady 2 MiB backlog while reading 1 MiB a second for 31 s is never ended, even when eleven fresh streams take the total past 32 MiB. - Twenty fresh streams fed 3.9 MiB each reach the 64 MiB ceiling to within one small frame and never pass it, so a ceiling of 63 or 65 MiB fails the test. - The tests move the streams' clock on (`machineEventsClock`) instead of waiting 30 s, and give it back after each test. Each rule has a test that fails without it. Checked with mutants: 457b7af's guard, 987d4a1 (the round-2 head), e315c7b (the round-3 head), a stall rule that ignores reading progress, ceilings of 63 and 65 MiB, a revoke that always errors or always closes, an abort that closes, staleness ignored, no ceiling, the least-holding stream ended first, and each budget doubled. `server/device-access.contract.test.ts` (revocation over real HTTP, isolated herdr) passes. ### Memory, real handler, stalled response bodies (`Bun.gc` before each reading) | Case | 457b7af | 987d4a1 | this head | |---|---:|---:|---:| | 128 stalled streams × 26,051 status frames (the first merge-pass repro): RSS | 890–976 MB, kept after the streams end | 35 MB | — | | 128 streams, one 5.3 MB roster each (the second merge-pass repro): live heap | — | 659 MB, 128 open | 68 MB, 12 open | | Same, then every browser aborts: live heap, and bytes still readable from an aborted stream | — | 654 MB, 5.3 MB readable | 7 MB, nothing readable | | 128 streams × 3.9 MiB of status frames, then every browser aborts: live heap after | — | 54 MB | 7 MB | | 20 stalled streams, 5,000-pane rosters (5.34 MB) × 10: live heap | 649 MB | 7 MB | — | `bun run check fast` passes. Two earlier runs on this head failed only on `scripts/self-hosted-runner.test.ts`'s `--cache-wait` case, the known load flake #2261 (fix in #2267), which passes on its own. ## Reviews An omo code review and a Codex review (Sol 6.1, fast, xhigh) ran on the first two commits, and both reviewed again after the fixes. Every HIGH and MEDIUM finding is fixed: - A roster frame over 4 MiB ended every stream right after it opened, so the browser reconnected forever (both reviews, MEDIUM). Fixed by letting such a frame through while it is queued, with a test. - The bench could reach a live herdr under `HERDR_TEST_LIVE=1` or with no herdr binary (Codex, HIGH). It now refuses to start unless it is on the test session's socket. - The bench left panes and its server child behind on a failure, and hung if the child died before it reported its port (both reviews, MEDIUM). Fixed with an undo stack per roster size, and by racing every wait against the child's exit. - On a failed split, the bench's other workers went on opening workspaces after cleanup had run (Codex re-review, MEDIUM; a probe of the old pool left 19 behind). The pool now stops new work and waits for work in flight. A live server child that stopped answering hung the run (Codex re-review, MEDIUM): every wait on it now also ends after 60 s. - The stalled-reader tests did not pin the byte budget or the six-frame allowance, and a burst could settle while a reconnect was still pending (Codex and omo, LOW). All fixed. - Left as is: a stalled herdr call in the bench still waits for herdr's own RPC timeout. - The merge pass (omo, BLOCK at 457b7af) reproduced a HIGH: the per-stream allowance had no total. 128 stalled responses held about 1 GB, and `close()` kept it queued after the streams ended. Its MEDIUM: the tests read their limits from the code. Both were fixed in 61ef3dd by a total budget, a finite large-frame credit, ending with `error()`, and tests with their own numbers. The first row of the memory table is that repro. - A Codex review (Sol 6.1, fast, xhigh) of the total-budget commit found that a roster larger than 32 MiB, or several 5,000-pane rosters opening together, could end its own or each other's stream before the first read (HIGH and MEDIUM). That was first fixed by charging the total only with backlog beyond each stream's large frame. Doing so left large frames outside the total, which the next merge-pass review caught (below). Fresh rosters are now protected by how long a queue has waited instead. It also found that sending cost grew with the number of streams (MEDIUM: 22 µs per frame at 1,024 streams, down to 1.3 µs now), and that the tests did not pin which stream is ended (MEDIUM: now pinned). Its re-review confirmed the upper-bound argument for the total, and found that a second large frame was charged as no backlog (MEDIUM). Fixed in 6a33f1e: a frame's backlog is counted before it is queued, so a stream never holds more than 4 MiB beyond one large frame. - The merge pass's second review (omo, at 987d4a1) reproduced two HIGHs. Large frames were exempt from the total, so 128 stalled streams held about 650 MiB. An abort closed the stream rather than dropping its queue, so an aborted stream's bytes stayed readable after they had left the count. Both are fixed in the last commit: every queued byte counts, stalled streams are ended past 32 MiB, a 64 MiB ceiling holds while none has stalled yet, and an abort errors the stream. The memory table above has both repros. - The merge pass's third review (omo, at e315c7b) reproduced a HIGH: the stall rule measured how long a queue had stayed non-empty. So a browser reading a steady 1 MiB a second with about 2 MiB waiting was ended as stalled after 30 s once the total passed 32 MiB, while fresh streams stayed. The last commit fixes it: a stream now counts as stalled only when its browser has taken nothing for 30 s. It also adds a test that catches the ceiling moving by a mebibyte, and gives the test clock back after each test. - The revocation contract is unchanged: `server/device-access.contract.test.ts` (14 tests) passes, because a revoked device that keeps up still gets a clean end. ## Not in this PR - With 300 agents changing at once, the page still spends ~1–2 s of main thread per burst: every `pane-status` frame is its own `setMachines` and sidebar render. Coalescing frames per animation frame on the client would be the next step for very large rosters, after a profile. - #772's sidebar search, status filters and retention rules are product work this PR does not do. Refs #772
Why
scripts/self-hosted-runner.test.ts"starts the runners after --cache-wait when the first refresh hangs" (from #2215) fails on a loaded host: the merge pass hitexpected 0, received "still running"twice at load ~79, lane docs-winvm-agents hit it on unchanged main, and two other lanes hitself-hosted-runnertimeouts. Details in #2261.The races are all in the test;
run.shbehaves as designed (it waits at most--cache-waitseconds), so it is unchanged:runRunnerUntilHungused fixed wall-clock bounds: 5 s to reach the hang, 5 s to end after it, 1 s for stderr.--cache-wait 1is counted in whole bashSECONDS, so it can end after ~0.2 s (measured), before the first refresh reaches its hung stub. The runner then starts, the launcher stops the refresh before it hangs, and the test fails with "the stub never hung".What (test-only)
<tempDir>/hung) as it hangs, and the test blocks reading it (head -c 1, killed after the 30 s bound). The gh stub hands out a registration token only after reading a second FIFO (token-gate), which the test opens once it has seen the hang. So no runner starts before the refresh hangs, however soon--cache-waitruns out.runRunnerUntilHungisLOADED_BOUND_MS(30 s) and ends at its event (the FIFO byte, process exit, stderr closing).run.sh'stimeout -k 5kills a stubborn child, so a stop that falls back to the kill still fails.Verification
All of it ran on this PC, with the test and 8 busy loops pinned to the same two cores (
taskset -c 120,121):this test timed out after 5000ms)run.shwith the--cache-waitdeadline removed"still running"), on both versions, so it still catches the regression it namesbun test scripts/self-hosted-runner.test.ts scripts/conventions.test.tsbun run check fastReview
omo-native-code-reviewer reviewed it adversarially and returned REQUEST_CHANGES. Every finding was fixed in this head:
Test-only change: no CodeRabbit re-review needed beyond the one this PR opens.
Closes #2261