Skip to content

perf(terminals): let idle panes share one process-table capture instead of forking their own - #18742

Merged
nwparker merged 2 commits into
mainfrom
perf/agent-inspection-poll-alignment
Sep 5, 2026
Merged

nwparker merged 2 commits into
mainfrom
perf/agent-inspection-poll-alignment

Conversation

@nwparker

@nwparker nwparker commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​72 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​72
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​195 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​194

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

  • New 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 to PROCESS_TABLE_SNAPSHOT_MAX_STALENESS_MS (500 ms), so a pane off the grid walks onto it over at most tier / 500ms steps.
  • agent-completion-poll-scheduler.ts — calls it, passing alignToSharedGrid only when the pane is genuinely idle: no foreground agent and no pane activity inside the 10 s hot window.

Deliberately left alone:

  • Panes with a foreground agent and panes inside the post-activity hot window keep their exact interval and their own phase, so the bounded hot cadence contract is untouched.
  • The error-backoff path keeps its jitter — spreading retries is exactly right when a host has just failed.

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 one ps and the snapshot serves everything inside its TTL.

visible panes ps captures/min before after reduction
1 29 29 0%
2 42 30 29%
4 62 31 50%
8 82 32 61%

The 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.

  • Detection is never slower. An aligned interval is bounded above by the tier interval — the same bound as before. The benchmark fails if any phase produces a longer wait.
  • Detection is at most 500 ms faster, once. The pull-forward is clamped to the snapshot TTL, so no interval is more than 500 ms shorter than its tier. Total phase shift over a pane's life is under one interval, so it costs at most one extra inspection, ever — which then pays for itself many times over.
  • The hot cadence is unchanged. All 19 tests in agent-completion-no-evidence-cadence.test.ts, which pin both the relaxed 15s tier and the bounded post-output 2s window, pass unmodified.
  • No thundering herd. The herd is the design here — the queue exists to collapse a synchronous burst onto one capture. Jitter is retained on the one path where spreading genuinely matters (error backoff against a failing host).

Worth stating: this makes idle panes converge, so a sampling profile of ps spawns 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 ✅
  • New 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.

@coderabbitai

coderabbitai Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: b6bb8002-7e8d-41bd-af04-9a899911fb9d

📥 Commits

Reviewing files that changed from the base of the PR and between 3bafdf88e4632f600dfe885e602db5c7afbd2657 and f5c6d1e.

📒 Files selected for processing (1)
  • package.json

Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review.


📝 Walkthrough

Walkthrough

Adds nextCadenceInspectionDelayMs for shared-grid alignment of idle pane inspections. Preserves jitter for error backoff and non-idle panes. Updates poll scheduling to use the helper. Adds tests for convergence, delay bounds, jitter, and invalid intervals. Adds a benchmark and npm script for TTL-batched capture measurements.

Merge Risk: ⚪ Minimal · up to f5c6d

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)

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. Analyzed 6 functions across 4 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: aligning idle terminal panes to share process-table captures.
Description check ✅ Passed The description is detailed and covers the change, rationale, scope, measurements, trade-offs, and testing. It omits the required Linked Issue and Visual Proof sections, and it does not include the re…
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: 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. Analyzed 6 functions across 4 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: 6a2add4d-0cfd-4799-b165-ef7add947e68

📥 Commits

Reviewing files that changed from the base of the PR and between 0a821e5 and b70a21b.

📒 Files selected for processing (5)
  • config/scripts/agent-inspection-cadence-batching-benchmark.mjs
  • package.json
  • src/renderer/src/components/terminal-pane/agent-completion-poll-interval.test.ts
  • src/renderer/src/components/terminal-pane/agent-completion-poll-interval.ts
  • src/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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ Minor suggestion inline — the algorithm, tests, and benchmark all check out.

Reviewed changes

  • Shared process-table capture for idle panes — a new pure nextCadenceInspectionDelayMs snaps idle panes onto an epoch-anchored deadline grid, clamping pull-forward to the snapshot TTL; createAgentCompletionPollScheduler opts 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.ts pins convergence and the latency bound in both directions, and a new bench:agent-inspection-cadence script 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.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker force-pushed the perf/agent-inspection-poll-alignment branch from b70a21b to 8762290 Compare September 5, 2026 00:48

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: 40a57825-c0bf-4670-8baa-27125bc170b3

📥 Commits

Reviewing files that changed from the base of the PR and between b70a21b and 8762290.

📒 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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes — since the prior pullfrog review, only the benchmark changed:

  • Shared TTL constant — replaced the benchmark's hardcoded 500 ms TTL with PROCESS_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.

Pullfrog  | View workflow run | Using 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.
@nwparker
nwparker force-pushed the perf/agent-inspection-poll-alignment branch from 3bafdf8 to f5c6d1e Compare September 5, 2026 06:52
@nwparker
nwparker merged commit e1599c9 into main Sep 5, 2026
28 checks passed
@nwparker
nwparker deleted the perf/agent-inspection-poll-alignment branch September 5, 2026 07:05
nwparker added a commit that referenced this pull request Sep 5, 2026
… 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`.
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Sep 5, 2026
… 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
andremohrmann pushed a commit to andremohrmann/orca that referenced this pull request Sep 6, 2026
… 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`.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
… 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`.
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