Repository navigation
fix(machines): keep the events stream open through a burst of status changes (#772) - #2260
Conversation
…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
|
No actionable comments were generated in the recent review.
|
| 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:
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: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
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.
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
…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.
|
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. |
…#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.
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 oncecontroller.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:
controller.error(), notclose(), 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.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 throughpane.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 reportsworking, then every pane reportsidle(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 (EventSourceerror).Runs alternated main and this branch under
dori heavyon 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.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: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):
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.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.gcbefore each reading)bun run check fastpasses. Two earlier runs on this head failed only onscripts/self-hosted-runner.test.ts's--cache-waitcase, 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:
HERDR_TEST_LIVE=1or with no herdr binary (Codex, HIGH). It now refuses to start unless it is on the test session's socket.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 witherror(), and tests with their own numbers. The first row of the memory table is that repro.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
pane-statusframe is its ownsetMachinesand sidebar render. Coalescing frames per animation frame on the client would be the next step for very large rosters, after a profile.Refs #772