Skip to content

fix(machines): keep the events stream open through a burst of status changes (#772) - #2260

Merged
devswha merged 11 commits into
mainfrom
perf/large-rosters
Oct 28, 2026
Merged

devswha merged 11 commits into
mainfrom
perf/large-rosters

Conversation

@devswha

@devswha devswha commented Oct 28, 2026 •

Copy link
Copy Markdown
Owner

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.
  • Keep large automated agent and workspace rosters usable #772's sidebar search, status filters and retention rules are product work this PR does not do.

Refs #772

…changes

The machine events stream ended a browser's response once more than five chunks were queued for it,
whatever their size. With 20 or more agents changing status at once that limit was passed, the
browser reconnected about three seconds later and read the whole roster again, and the status frames
still queued were lost, with their in-page finish alerts. The guard now counts bytes: a browser may
fall up to 4 MiB behind (a 300-pane roster frame is 288 KB) before its stream is ended.

Refs #772
scripts/roster-bench.ts opens N panes in the isolated herdr of a check run, reports an agent in
each, and times what a burst of status changes costs the browser and the server: time until every
row shows it, Chrome's main-thread time, server CPU and memory, and event stream drops.

Refs #772
…e queue bound

The roster a stream opens with is one frame, and with thousands of panes it can pass 4 MiB on its
own: the next frame then found the queue over the bound and ended the stream, and the browser
reconnected into the same end forever. A stream now may hold six of its largest frames when that
is more than 4 MiB, so it never ends where the old six-chunk limit kept it open. The test of a
stalled reader now checks that everything up to the byte bound waits for it.

Refs #772
roster-bench.ts now stops before any herdr call unless it runs on the test session's socket, as
test-herdr.ts leaves the inherited socket in live mode or without a herdr binary. Each roster
size undoes its workspaces, server and page when it ends or fails, waits on the server end when
it exits, and a burst is settled only once the event stream is open again.

Refs #772
…n the six-frame allowance

A failed split no longer leaves workspaces opened after the run has unwound: the pool stops new
work and waits for what is in flight before it fails. Waits on the server child end after 60 s as
well as on its exit. The large-frame test now keeps the stream open while seven large frames wait
(the seventh is measured against the six before it) and ends it at the eighth, so any other
allowance fails it. The changelog line is rewrapped.

Refs #772
@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 02f8ae6 and 774e0b2.

Files selected for processing: 4
  • changelog.d/machine-events-burst.md
  • scripts/roster-bench.ts
  • server/machine-api.test.ts
  • server/machine-api.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 0 remain after this review.

📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • Improved sidebar updates during bursts of agent status changes, reducing the chance that displayed statuses become stale.
    • Browser event streams that fall behind are now managed within limits, helping keep status updates responsive without allowing queued data to grow unchecked.

The machine-events stream now tracks queued bytes and applies per-stream and aggregate limits, including eviction of stalled streams. New tests cover queue and stream lifecycle behavior. A benchmark measures working and idle status bursts across configurable agent roster sizes.

Changes: Machine events

Layer / File(s) Summary
Queue limits and stream lifecycle
server/machine-api.ts, server/machine-api.test.ts
The stream tracks queued bytes, allows one oversized frame, and applies per-stream and aggregate limits. It drops stalled streams and handles abort, revocation, and cancellation. Tests cover burst delivery, queue limits, eviction, and disconnect cleanup.
Status-burst benchmark
scripts/roster-bench.ts, changelog.d/machine-events-burst.md
The benchmark runs an isolated Ovis server and headless Chrome to measure working and idle bursts across pane counts. It records browser, event-stream, CPU, and memory metrics. The changelog records the stream limits and benchmark.

Priority: Normal

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Bug fix · Severity of issue fixed: Low

Merge Risk: Minimal · up to 774e0

This change replaces the machine-events stream's queued-chunk limit with byte-based per-stream and aggregate limits, so status bursts should no longer close the stream and delay sidebar updates. No concrete merge-blocking risk was found. The benchmark script and changelog entry add no runtime risk.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary fix: keeping the machine events stream open during bursts of status changes.
Description check Passed The description explains the problem, implementation, behavior, scope, measurements, tests, contract coverage, and known validation limitations. It uses a "Tests" section instead of the template's "Va…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description explains the problem, implementation, behavior, scope, measurements, tests, contract coverage, and known validation limitations. It uses a "Tests" section instead of the template's "Validation" heading, but it contains the required validation information and is complete overall.

Full details: Docstring Coverage

Explanation

Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 3 functions across 3 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

…p a stalled stream's queue

One stream may hold 4 MiB for a browser that fell behind, plus a frame larger than that only while
it is still queued, so one large roster no longer raises the allowance for good. Every events
stream together, watching devices included, may hold 32 MiB: past it the streams with the most
waiting are ended first, never one that keeps up. A stream that falls behind, or whose device is
revoked, is errored rather than closed, so what waited for it is dropped instead of kept for
delivery. The tests state the policy as numbers of their own.

Refs #772
…) per frame, and end a keeping-up revoked stream cleanly

A roster that is only waiting to be read is no backlog: the total of every stream now counts what
each one holds beyond its one large frame, so a stream opening with a roster larger than the total,
or several opening together with 5,000-pane rosters, neither ends itself nor one another. 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. A revoked device that keeps up gets a
clean end again, as before this change; one with a backlog waiting has it dropped.

Refs #772
…large frame included

A large frame was charged as no backlog even with another one already waiting, so two unread
large frames could pass the total until the next write. The backlog a frame adds (all of a small
one; for a large one, what the large frame already waiting does not cover) is now checked against
the stream's 4 MiB and the total before the frame is queued.

Refs #772
…n aborted stream's queue

Large frames now count toward the 32 MiB that every events stream together may hold. Past it, the
streams that stopped reading (a queue not emptied for 30 s) are ended, the one holding the most
first; a stream just sent its roster has not stopped reading, so browsers opening together with
large rosters keep them. Even then nothing passes 64 MiB: a frame past it is refused and its stream
ended, unless the stream is alone in holding any. A browser that went away has its stream errored, so
what waited for it is dropped instead of still readable. The tests move the streams' clock on.

Refs #772
…ing, and pin the ceiling

A browser reading on with a steady backlog never empties its queue, so the stall rule took it for one
that stopped reading and ended it once the total was passed, while fresh streams stayed. A stream now
counts as stalled only when its browser has taken nothing from a waiting queue for 30 s. The ceiling
test now catches the ceiling moving by a mebibyte, and each test gives the streams' clock back.

Refs #772
devswha added a commit that referenced this pull request Oct 28, 2026
…r-fit timing out under load (#2287)

Closes #2285

## What was wrong

`Browser regression (other scripts)` kept ending as cancelled at its
50-minute `timeout-minutes`. It looked like hung demo scripts, but no
script hung. Each job waited a long time for a herdr check slot
(`scripts/check.ts`, `check: took a slot after Ns`) and then ran the
lane until the job timeout stopped it:

| job | PR | slot wait | lane before the cancel |
| --- | --- | --- | --- |
| 122862337418 | #2266 attempt 1 | 1340 s | finished, 107/108 in 1238 s
(a real `file-viewer-regression.ts:1395` failure) |
| 122889113275 | #2266 attempt 2 | 2110 s | 14 min, cancelled |
| 122878703515 | #2260 | 1755 s | 20 min, cancelled |
| 122872125320 | #2275 | 1635 s | 22 min, cancelled |

The scripts that "STARTed and never finished" were the ones running at
the cancel. Their logs in the browser-logs artifact print `PASS` lines
up to the cancel second. For example,
`sidebar-activity-demo-regression.log` ends with a PASS at 15:35:59, the
same second as `##[error]The operation was canceled.` The longest single
script run in these jobs was 357 s.

`ci.yml` gives these jobs `timeout-minutes: 50` and `CHECK_WAIT_SECONDS:
2400`, and time spent waiting for a slot counts against the timeout. On
2026-10-28 the P620 had 20 runners queuing for 4 slots
(`CHECK_HOST_MAX_RUNS=4`), and waits reached 37.6 min.

## What this PR changes

`scripts/ci-browser-parallel.ts` now limits each run of a script to
`BROWSER_SCRIPT_TIMEOUT_SECONDS` (default 600 s, about twice the slowest
run seen on a loaded host). Before this, a script that really hung, or a
process it started that kept its output open, would have used up the
whole job. Past the limit:
- the script's whole process tree (read from `ps` before anything is
signalled, so Chromium and servers it started are included) gets
SIGTERM, then SIGKILL after 5 s;
- the lane prints `TIMEOUT <script>` and the script's last 40 log lines
straight away;
- the script fails with exit 124 and is not run a second time;
- the summary, `summary.json`, the `::error` annotation and the job
summary all name it with `Timed out after Ns`.

It also fails a script that exits but leaves a process holding its
output open: if the output is still open 5 s after the exit, the run
fails with `Exited N, but a process it started still held its output`. A
run's processes carry a mark in their environment, so the stop finds
them through `/proc` on Linux even after they are moved to init.
Anything still alive after the SIGTERM grace gets SIGKILL, including a
child that ignores SIGTERM and writes nowhere. The script's own pid is
only signalled while the script is still running.

`scripts/composer-fit-demo-regression.ts:278` gave `setInputFiles` a 32
MiB + 1 byte buffer. Playwright sends a buffer to the page as base64
(about 45 MB), which on a loaded host ran past the 30 s timeout. That is
a real load failure inside this job: it failed twice in #2260's job and
twice in a row locally at load 80-110. It now passes a sparse file of
the same size by path. Chromium reads only its size, and the app still
refuses it by size (`src/lib/api.ts`) before reading.

`docs/development.md` documents the setting and says to check the slot
wait first when a job is cancelled at its timeout.

No workflow file is changed.

## Done outside this PR

- Host (Dori's call): the P620's runner count goes from 20 to 8 (2
reserved for main, 6 for PRs), with `CHECK_HOST_MAX_RUNS=4` kept. With 4
slots, at most 4 jobs can wait, so in the worst case a job waits one
slot round (about 20 min) and then runs the lane (about 21 min), within
50 min. Jobs beyond that now queue at GitHub, which does not count
toward `timeout-minutes`.
- Proposal for the owner, not applied: `timeout-minutes: 50` -> `75` for
Integration tests, Browser regression (ui-regression) and Browser
regression (other scripts), so the 40-minute `CHECK_WAIT_SECONDS` budget
and the lane both fit inside the job.

## Verification

- `bun test scripts/ci-browser-parallel.test.ts`: 4 pass. The two
deadline tests fail on the runner before this PR: the hung stub runs
into the test's 15 s spawn limit, and the exit-but-holding stub is never
caught.
- The real runner on a hung stub that leaves a child holding stdout,
with `BROWSER_SCRIPT_TIMEOUT_SECONDS=2`. Before this PR it still showed
only `START` when the outer bound killed it at 30 s, and the child was
left alive. With it, the run exits 1 after 2.4 s, with `TIMEOUT`, the
script's last lines and exit 124, and the child is gone.
- A child that ignores SIGTERM and writes nowhere. It survived the first
commit of this PR (Codex's HIGH) and is killed by the second.
- The six scripts named in the issue, run through the parallel runner
with 6 workers and `BROWSER_RETRY=0` under `dori heavy` on a host at
load 60-110:
- with the composer-fit fix: 6/6 in each of three runs (359 s, 334 s,
320 s);
- before it: 5/6 twice, both times composer-fit failing with
`setInputFiles` timing out at line 278.
The other five scripts passed every time. None hung, and none was
reported STOPPED with real Chromium.
- `bun run check fast` on 72d6486: typecheck, build, and unit tests
(8250 pass, 0 fail).
- Reviews:
- omo-native-code-reviewer: PASS, with one MEDIUM (a script that exits
but leaves a process holding its output) that is now fixed.
- Codex Sol 6.1 fast xhigh: first review BLOCK, on a HIGH (a child
ignoring SIGTERM survived), two MEDIUMs (re-parented children, stale
pids) and one LOW (zombies in the test). All were reproduced and fixed,
and the re-review is a PASS. Known limits it names: on Linux, orphans
are found through `/proc`, and a narrow pid-reuse race remains between
reading and signalling.
  - The composer-fit change (test only) had no separate reviewer.
@devswha

devswha commented Oct 28, 2026

Copy link
Copy Markdown
Owner Author

Merging 774e0b2 (closes #772), after its extra round. Codex was at capacity, so an omo reviewer on gpt-6.1-sol re-reviewed each round with independent reproductions against the real handler. The machine events stream now keeps every queued byte inside a 32 MiB budget: past it, streams whose browser took nothing from a waiting queue for 30 s end, most-held first; a 64 MiB ceiling holds even while every stream is fresh; abort errors the stream so its queue is dropped. Verified at this head: a steady reader (1 MiB/s with a ~2 MiB backlog) stays subscribed while 11 fresh streams push the total past 32 MiB; a truly stalled reader is ended at 30 s with the most-held first; 128 stalled streams with one 5.3 MB roster each keep 12 frames (64.07 MB, under the 64 MiB ceiling), down to 6 (32.0 MB) after the stall rule; after abort nothing is readable and accounting is zero; 300-frame bursts arrive in order; tests fail when either limit changes. Earlier rounds fixed oversized frames bypassing the budget and abort keeping queues readable. Not filed: a reader that takes a small chunk at least every 30 s keeps its queue indefinitely by design, bounded by the 4 MiB per-stream and 64 MiB total limits; one oversized frame per stream (and a single holder over 64 MiB) remain explicit exceptions; the ceiling limits retained payload, not momentary RSS.

@devswha
devswha merged commit 7fafefb into main Oct 28, 2026
32 of 38 checks passed
@devswha
devswha deleted the perf/large-rosters branch October 28, 2026 17:45
devswha added a commit that referenced this pull request Nov 5, 2026
…#772) (#3071)

## Change

Part of #772. Settings > Appearance > **Fold helpers under their agent**
is a new device setting. It is **off by default**, and while off the
Agents list is exactly as it is today.

When it is on, each agent row that has helpers in the same list
(herdr-core's `parent_pane_id`, the rows the sidebar already nests under
their agent) gets one line right under it: a caret, **Helpers**, a dot
for each state among them that asks for a look (as a named group's
heading: needs you, working), and their count. The line folds and opens
the helpers.

- **Nothing that needs you is folded away.** A helper that is blocked,
and the selected helper, stay in sight under the line, so automation
that starts many workers never hides a question.
- **Start folded, kept per device.** Every agent starts folded. The
agents opened are kept on this device by pin key
(`ovis:agents-helpers-open`), read anew on each change so two tabs keep
each other's choices, and pruned as the pins are: a pane gone from a
loaded PC leaves, nothing of a PC still loading or hidden on this device
does.
- **Per top-level family.** A helper's own helpers fold under the same
line; one kept in sight is drawn at its depth.
- **Focus and names.** A helper with the focus that folds away (it
stopped needing you, or the selection moved) hands the focus to the
line. Each line is announced as "Helpers of <agent>" with its states and
count.
- **The filter folds nothing.** While the sidebar filter holds words,
the helpers line is not drawn and every row the filter keeps is shown,
as the filter already opens the other folds.
- **Rows stay in the list.** Folded rows keep their element (`hidden`),
so a row that comes back keeps its focus and open menu, like the
Background agents and named group folds. Tree lines are drawn for the
rows in sight. A helper unpinned from its row menu into a folded family
hands the focus to the nearest fold line above it (its helpers line,
else the Background agents heading), as an unpin into the folded
Background agents part already did.
- Works in every arrangement the list already has: plain, grouped by
state, named groups and the Background agents part. The pinned card does
not nest helpers, so nothing folds there.

### What #772 asks and what main already has

- Recorded large-roster fixture and latency: `scripts/roster-bench.ts`
(#2260), with the event-stream fix it found.
- Search and live filters: the sidebar filter (`lib/sidebarFilter.ts`).
Active rows reachable: pinned card, Group agents by state (needs you
first), and the Background agents part.
- This PR adds the remaining "collapse workers" part. The list is **not
virtualized**: #772 asks for that only after a measured roster shows
drawing the rows is what costs, and the helpers fold cuts the rows drawn
without changing keyboard or screen-reader order.

### Design reference

It follows the disclosure rows of Zed's and VS Code's tree views (a
parent row whose children fold under it, with a count). The line is
drawn where a helper stands (its elbow from the agent's mark, a helper's
height, the caret where a helper's mark is), so the family still reads
as one tree. DESIGN.md has the entry.

## Screenshots

Demo roster: checkout-api's Claude is given three helpers
(web-dashboard's Codex, which is blocked, and the OMP and CLI agents).

| | Folded | Opened |
|---|---|---|
| 1280 dark | <img
src="https://raw.githubusercontent.com/devswha/ovis/1bf25ca4935f9dfa1a9898648e7ac9b8528ccd14/helpers-fold-folded-1280-dark.png"
width="320"> | <img
src="https://raw.githubusercontent.com/devswha/ovis/1bf25ca4935f9dfa1a9898648e7ac9b8528ccd14/helpers-fold-open-1280-dark.png"
width="320"> |
| 1280 light | <img
src="https://raw.githubusercontent.com/devswha/ovis/1bf25ca4935f9dfa1a9898648e7ac9b8528ccd14/helpers-fold-folded-1280-light.png"
width="320"> | <img
src="https://raw.githubusercontent.com/devswha/ovis/1bf25ca4935f9dfa1a9898648e7ac9b8528ccd14/helpers-fold-open-1280-light.png"
width="320"> |
| 390 dark | <img
src="https://raw.githubusercontent.com/devswha/ovis/1bf25ca4935f9dfa1a9898648e7ac9b8528ccd14/helpers-fold-folded-390-dark.png"
width="320"> | <img
src="https://raw.githubusercontent.com/devswha/ovis/1bf25ca4935f9dfa1a9898648e7ac9b8528ccd14/helpers-fold-open-390-dark.png"
width="320"> |
| 390 light | <img
src="https://raw.githubusercontent.com/devswha/ovis/1bf25ca4935f9dfa1a9898648e7ac9b8528ccd14/helpers-fold-folded-390-light.png"
width="320"> | <img
src="https://raw.githubusercontent.com/devswha/ovis/1bf25ca4935f9dfa1a9898648e7ac9b8528ccd14/helpers-fold-open-390-light.png"
width="320"> |

## Validation

- `bun run check fast`: passed at this head (unit 12405 pass, 0 fail;
typecheck, build, generated files).
- Failing first: `src/components/AgentSidebar.test.ts` "AgentSidebar
folded helpers (#772)" (4 tests); the 3 tests of the setting on failed
on main's component, the off-by-default one passed on both. Review
round: the line's accessible name and `AgentSidebar.test.tsx` "opening
an agent's helpers keeps another tab's choices and a loading PC's, and
drops a gone pane's" failed on the reviewed head f200297 and pass now.
- `bun scripts/agent-groups-demo-regression.ts` re-run after the review
round (named-group walk): 390 and 1280, light and dark, passed.
- `bun scripts/agent-helpers-fold-demo-regression.ts` (new, in
`ci-browser.sh`): 390 and 1280, light and dark. Off by default; on, a
counted line with the blocked helper in sight, opens, stays open across
a reload, folds again, a helper unpinned while folded hands the focus to
the helpers line (that step timed out on the phone without the focus
change), gives way to the filter. Ran 3 times in a row, all passed.
- Browser regressions that cover the Agents list, run in the self-hosted
CI runner image (`herdr-ci-runner:local`, `ci-browser-parallel.ts`):
25/25 passed in 319 s (agent-groups, agent-helpers-fold, agent-lock,
background-agent-detail, chat-working-line, deep-link, file-viewer,
gjc-status-browser, hide-pc, omo-plan-browser, palette-machines,
pane-lifetime, pane-mute, sidebar-activity, sidebar-context-ring,
sidebar-filter, sidebar-heads, sidebar-selection-contrast,
sidebar-spacing, sidebar-split-access, sidebar-split, sidebar-tokens,
terminal-arrows-clicks, ui-regression and one more Agents-list script).
- Skipped: integration suite (no server/shared change), Windows/macOS.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant