Repository navigation
perf(terminals): let idle panes share one process-table capture instead of forking their own - #18742
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Team Run ID: 📥 CommitsReviewing files that changed from the base of the PR and between 3bafdf88e4632f600dfe885e602db5c7afbd2657 and f5c6d1e. 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review. 📝 WalkthroughWalkthroughAdds Merge Risk: ⚪ Minimal · up to Idle terminal panes now converge on shared inspection deadlines to reduce redundant process-table captures, while active panes and error retries retain their prior timing behavior. No current merge-blocking risk is identified. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 4 files. (1 skipped: 1 unsupported.)
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Team
Run ID: 6a2add4d-0cfd-4799-b165-ef7add947e68
📒 Files selected for processing (5)
config/scripts/agent-inspection-cadence-batching-benchmark.mjspackage.jsonsrc/renderer/src/components/terminal-pane/agent-completion-poll-interval.test.tssrc/renderer/src/components/terminal-pane/agent-completion-poll-interval.tssrc/renderer/src/components/terminal-pane/agent-completion-poll-scheduler.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review.
There was a problem hiding this comment.
ℹ️ Minor suggestion inline — the algorithm, tests, and benchmark all check out.
Reviewed changes
- Shared process-table capture for idle panes — a new pure
nextCadenceInspectionDelayMssnaps idle panes onto an epoch-anchored deadline grid, clamping pull-forward to the snapshot TTL;createAgentCompletionPollScheduleropts in only when a pane has no foreground agent and no activity inside the 10s hot window. - Backoff and hot-window contracts preserved — the error-backoff path keeps its jitter, and panes inside the post-activity hot window keep their exact interval; the existing
agent-completion-no-evidence-cadence.test.ts(19 tests) passes unmodified. - Unit tests + benchmark — a new
agent-completion-poll-interval.test.tspins convergence and the latency bound in both directions, and a newbench:agent-inspection-cadencescript reproduces the pre-change jitter to measure capture-count reduction.
I traced the grid math (deadline clamp, ≤ baseMs / TTL step convergence, the "at most one extra inspection" bound) and ran both affected test files plus the benchmark locally — all green, and the reduction figures match the PR description. The isIdlePane gate is correctly unreachable for remote panes (they bail earlier in shouldRunCadenceInspection), so this stays local-only.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
b70a21b to
8762290
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Team
Run ID: 40a57825-c0bf-4670-8baa-27125bc170b3
📒 Files selected for processing (1)
config/scripts/agent-inspection-cadence-batching-benchmark.mjs
Included review availability: Your plan provides up to 10 included reviews per hour; 2 remain after this review.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — since the prior pullfrog review, only the benchmark changed:
- Shared TTL constant — replaced the benchmark's hardcoded
500ms TTL withPROCESS_TABLE_SNAPSHOT_MAX_STALENESS_MS, imported from the same shared reader the production clamp uses, resolving the prior review's one open thread. - TTL-from-capture accounting — reworked capture counting from epoch-grid bucketing to a model that charges a new capture only when a wake lands past the prior capture's TTL window (
snapshotExpiresAt = wakeAt + TTL), matching the reader's real "valid for TTL after the capture" semantics rather than a fixed epoch grid.
The prior feedback is cleanly addressed, and the new capture-count model is more faithful to the reader's actual TTL behavior (still conservative — it ignores in-flight dedup and the TTL keying on completedAtMs). The benchmark runs green; the four production/test files are unchanged from the previously-reviewed b70a21b.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
…ad of forking their own Every visible local pane runs an agent-completion cadence that resolves through `getStrictProcessTableSnapshot`, and the inspection queue already collapses every shared-observation task enqueued in the same tick onto a single whole-host `ps`. Independent ±10% jitter per pane defeated that: the jitter was re-rolled on each reschedule, so panes drifted permanently apart, each landing in its own tick and each missing the snapshot's 500 ms TTL. Four idle panes cost four captures where one would have served all of them. Idle panes now aim at a deadline grid anchored at the epoch. The pull-forward is clamped to the snapshot TTL, so no interval is ever longer than its tier and none is more than 500 ms shorter: a pane off the grid walks onto it over at most `tier / TTL` steps, costs at most one extra inspection in total, and no inspection is ever delayed. Scoped deliberately. A pane with a foreground agent, or one still inside the 10 s post-activity hot window, keeps its exact interval and its own phase, so the bounded hot cadence is unchanged. The error-backoff path keeps its jitter, where spreading retries across panes is the point. Measured by `pnpm bench:agent-inspection-cadence` — whole-host `ps` captures over 60 s at the 2 s idle tier, median of 21 rounds: | visible panes | before | after | reduction | | --- | --- | --- | --- | | 1 | 29 | 29 | 0% | | 2 | 42 | 30 | 29% | | 4 | 62 | 31 | 50% | | 8 | 82 | 32 | 61% | `process-table-snapshot-reader.ts` measures the `command=` column at 1.15 s of work for 1,948 processes, so these are captures a quiet app was paying for continuously. All 4,202 existing terminal-pane tests pass unchanged, including the no-evidence cadence suite that pins the relaxed and hot intervals.
… the cadence benchmark A window shorter than one cadence tier leaves the baseline capture count at zero, and the reduction line then divided by it and printed a meaningless percentage. Reported by CodeRabbit on #18742.
3bafdf8 to
f5c6d1e
Compare
… at boot (#18814) Every Electron E2E spec that boots the app has been failing on `workspaceSessionReady did not become true`, and the app itself has been launching to a blank white window: the renderer threw `ReferenceError: process is not defined` while evaluating a shared chunk, so React never mounted and no startup step ever ran. `agent-completion-poll-interval.ts` (renderer) imported one constant, `PROCESS_TABLE_SNAPSHOT_MAX_STALENESS_MS`, out of `shared/process-table-snapshot-reader.ts` — a `node:child_process` / `node:fs/promises` module whose dependency evaluates `process.platform` at module scope to pick `ps` columns. The renderer runs sandboxed with contextIsolation, where `process` is undefined, so that module-scope read threw and took the whole chunk with it. Introduced by #18742; #18780 added a second module-scope read next to the first. The constant now lives in `shared/process-table-snapshot.ts`, the environment-neutral half of the pair, and the reader re-exports it so host callers are unchanged. The two `ps` column sets read the platform behind a `typeof process` guard, which defuses the same landmine for any future renderer import of that module — only hosts ever run the argv. The regression test walks the renderer import graph (lazy routes included) from all three entries and refuses any module that reaches a `node:` builtin. It fails on the pre-fix import with the full 10-hop chain from `main.tsx`.
… at boot (stablyai#18814) Every Electron E2E spec that boots the app has been failing on `workspaceSessionReady did not become true`, and the app itself has been launching to a blank white window: the renderer threw `ReferenceError: process is not defined` while evaluating a shared chunk, so React never mounted and no startup step ever ran. `agent-completion-poll-interval.ts` (renderer) imported one constant, `PROCESS_TABLE_SNAPSHOT_MAX_STALENESS_MS`, out of `shared/process-table-snapshot-reader.ts` — a `node:child_process` / `node:fs/promises` module whose dependency evaluates `process.platform` at module scope to pick `ps` columns. The renderer runs sandboxed with contextIsolation, where `process` is undefined, so that module-scope read threw and took the whole chunk with it. Introduced by stablyai#18742; stablyai#18780 added a second module-scope read next to the first. The constant now lives in `shared/process-table-snapshot.ts`, the environment-neutral half of the pair, and the reader re-exports it so host callers are unchanged. The two `ps` column sets read the platform behind a `typeof process` guard, which defuses the same landmine for any future renderer import of that module — only hosts ever run the argv. The regression test walks the renderer import graph (lazy routes included) from all three entries and refuses any module that reaches a `node:` builtin. It fails on the pre-fix import with the full 10-hop chain from `main.tsx`. Mirror-Of: 0bbf86b
… at boot (stablyai#18814) Every Electron E2E spec that boots the app has been failing on `workspaceSessionReady did not become true`, and the app itself has been launching to a blank white window: the renderer threw `ReferenceError: process is not defined` while evaluating a shared chunk, so React never mounted and no startup step ever ran. `agent-completion-poll-interval.ts` (renderer) imported one constant, `PROCESS_TABLE_SNAPSHOT_MAX_STALENESS_MS`, out of `shared/process-table-snapshot-reader.ts` — a `node:child_process` / `node:fs/promises` module whose dependency evaluates `process.platform` at module scope to pick `ps` columns. The renderer runs sandboxed with contextIsolation, where `process` is undefined, so that module-scope read threw and took the whole chunk with it. Introduced by stablyai#18742; stablyai#18780 added a second module-scope read next to the first. The constant now lives in `shared/process-table-snapshot.ts`, the environment-neutral half of the pair, and the reader re-exports it so host callers are unchanged. The two `ps` column sets read the platform behind a `typeof process` guard, which defuses the same landmine for any future renderer import of that module — only hosts ever run the argv. The regression test walks the renderer import graph (lazy routes included) from all three entries and refuses any module that reaches a `node:` builtin. It fails on the pre-fix import with the full 10-hop chain from `main.tsx`.
…ad of forking their own (stablyai#18742) * perf(terminals): let idle panes share one process-table capture instead of forking their own Every visible local pane runs an agent-completion cadence that resolves through `getStrictProcessTableSnapshot`, and the inspection queue already collapses every shared-observation task enqueued in the same tick onto a single whole-host `ps`. Independent ±10% jitter per pane defeated that: the jitter was re-rolled on each reschedule, so panes drifted permanently apart, each landing in its own tick and each missing the snapshot's 500 ms TTL. Four idle panes cost four captures where one would have served all of them. Idle panes now aim at a deadline grid anchored at the epoch. The pull-forward is clamped to the snapshot TTL, so no interval is ever longer than its tier and none is more than 500 ms shorter: a pane off the grid walks onto it over at most `tier / TTL` steps, costs at most one extra inspection in total, and no inspection is ever delayed. Scoped deliberately. A pane with a foreground agent, or one still inside the 10 s post-activity hot window, keeps its exact interval and its own phase, so the bounded hot cadence is unchanged. The error-backoff path keeps its jitter, where spreading retries across panes is the point. Measured by `pnpm bench:agent-inspection-cadence` — whole-host `ps` captures over 60 s at the 2 s idle tier, median of 21 rounds: | visible panes | before | after | reduction | | --- | --- | --- | --- | | 1 | 29 | 29 | 0% | | 2 | 42 | 30 | 29% | | 4 | 62 | 31 | 50% | | 8 | 82 | 32 | 61% | `process-table-snapshot-reader.ts` measures the `command=` column at 1.15 s of work for 1,948 processes, so these are captures a quiet app was paying for continuously. All 4,202 existing terminal-pane tests pass unchanged, including the no-evidence cadence suite that pins the relaxed and hot intervals. * test(terminals): report n/a instead of dividing by a zero baseline in the cadence benchmark A window shorter than one cadence tier leaves the baseline capture count at zero, and the reduction line then divided by it and printed a meaningless percentage. Reported by CodeRabbit on stablyai#18742.
… at boot (stablyai#18814) Every Electron E2E spec that boots the app has been failing on `workspaceSessionReady did not become true`, and the app itself has been launching to a blank white window: the renderer threw `ReferenceError: process is not defined` while evaluating a shared chunk, so React never mounted and no startup step ever ran. `agent-completion-poll-interval.ts` (renderer) imported one constant, `PROCESS_TABLE_SNAPSHOT_MAX_STALENESS_MS`, out of `shared/process-table-snapshot-reader.ts` — a `node:child_process` / `node:fs/promises` module whose dependency evaluates `process.platform` at module scope to pick `ps` columns. The renderer runs sandboxed with contextIsolation, where `process` is undefined, so that module-scope read threw and took the whole chunk with it. Introduced by stablyai#18742; stablyai#18780 added a second module-scope read next to the first. The constant now lives in `shared/process-table-snapshot.ts`, the environment-neutral half of the pair, and the reader re-exports it so host callers are unchanged. The two `ps` column sets read the platform behind a `typeof process` guard, which defuses the same landmine for any future renderer import of that module — only hosts ever run the argv. The regression test walks the renderer import graph (lazy routes included) from all three entries and refuses any module that reaches a `node:` builtin. It fails on the pre-fix import with the full 10-hop chain from `main.tsx`.

ELI5
Every terminal pane you can see periodically asks the operating system "what processes are running?" so Orca can tell when an agent finished. Answering that question is expensive — it lists every process on your machine (the code's own note measures 1.15s of work for ~1,950 processes).
Orca was already smart about this: if several panes ask at the same moment, they all share one answer. But each pane added a random ±10% wobble to its own timer, re-rolled every cycle, so the panes drifted apart and each one ended up asking on its own. Four idle panes meant four separate full process listings instead of one.
This PR lines idle panes up on a shared schedule so they ask together and share one answer. At 8 panes that's 82 → 32 process listings per minute while you're doing nothing.
The alignment is one-directional: a pane can be nudged earlier by at most half a second, never later. So nothing gets slower to detect.
What changed
agent-completion-poll-interval.ts— a pure function that picks the delay. Idle panes aim at a deadline grid anchored at the epoch; the pull-forward is clamped toPROCESS_TABLE_SNAPSHOT_MAX_STALENESS_MS(500 ms), so a pane off the grid walks onto it over at mosttier / 500mssteps.agent-completion-poll-scheduler.ts— calls it, passingalignToSharedGridonly when the pane is genuinely idle: no foreground agent and no pane activity inside the 10 s hot window.Deliberately left alone:
Measurements
pnpm bench:agent-inspection-cadence(new, checked in). Drives the production interval picker against a baseline reproducing the pre-change jitter over a simulated 60s window. A capture is charged only when a wake lands past the previous capture's 500 ms snapshot TTL (the TTL window starts at the capture, not on an epoch grid), since the queue collapses same-tick shared-observation tasks onto onepsand the snapshot serves everything inside its TTL.pscaptures/min beforeThe benchmark also asserts the latency invariant across 100,000 clock phases: worst observed wait is exactly the tier interval, never above it.
Negative user-facing trade-offs
None identified.
agent-completion-no-evidence-cadence.test.ts, which pin both the relaxed 15s tier and the bounded post-output 2s window, pass unmodified.Worth stating: this makes idle panes converge, so a sampling profile of
psspawns will look burstier (one cluster instead of a smear) even though total spawns drop ~60%. That is the intended shape, not a regression.Test plan
pnpm tc✅pnpm test src/renderer/src/components/terminal-pane— 4202 passed, 0 modified ✅pnpm run check:code-quality:changed✅agent-completion-poll-interval.test.ts: convergence onto one deadline, the latency bound in both directions, jitter retained under backoff, safe degradation on a non-positive interval.