Skip to content

perf(remote): apply the no-evidence inspection cadence to remote panes (30 -> 4 host round trips/min/idle pane) - #18146

Merged
nwparker merged 1 commit into
mainfrom
perf/remote-no-evidence-inspection-cadence
Sep 2, 2026
Merged

nwparker merged 1 commit into
mainfrom
perf/remote-no-evidence-inspection-cadence

Conversation

@nwparker

@nwparker nwparker commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​78 $\color{#cf222e}{\Huge{\mathbf{−}}}$​7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​71
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​34 $\color{#cf222e}{\Huge{\mathbf{−}}}$​16 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​18

ELI5

If you have a terminal open on a remote machine (SSH or a paired runtime) and you have never run an agent in it, Orca was asking that machine "what are you running right now?" every 2 seconds, forever — and getting "nothing" every single time. That question is a network round trip plus a process scan on the far end. This PR makes Orca ask every 15 seconds instead, and go straight back to every 2 seconds the instant the terminal does anything at all.

The finding

currentPollTier() (agent-completion-process-monitor.ts:211-229) only returns the no-evidence tier when options.isProcessInspectionCostly?.() === true. That callback was, effectively:

if (!navigator.userAgent.includes('Windows')) return false
const ptyId = session.transport.getPtyId()
return ptyId !== null && !isRemoteExecutionHostPtyId(ptyId)   // remote explicitly EXCLUDED

So "costly" meant local Windows only, and a remote-execution-host PTY was the one shape deliberately excluded — even though a remote inspection is the most expensive inspection in the codebase:

  • paired runtime: inspectRuntimeTerminalProcess -> terminal.inspectProcess RPC, timeoutMs: 15_000 (src/renderer/src/runtime/runtime-terminal-inspection.ts:115-142)
  • direct SSH: window.api.pty.inspectProcess -> main -> SSH-mux pty.inspectProcess (src/main/providers/ssh-pty-provider.ts:282-283), which on the relay runs getForegroundProcessName(pid) + processHasChildren(pid) per call (src/relay/pty-handler.ts:2378-2395)

There is no cache anywhere on that path (inspectPtyProviderProcess calls straight through).

The intent is stated verbatim at the top of agent-completion-no-evidence-cadence.test.ts: "bound the volume of cadence process inspections a visible, idle terminal with NO agent evidence drives on hosts where each inspection is a whole-process-table scan." Remote hosts fit that description; the predicate just did not cover them.

Why the exclusion existed, and why it can go now

#17525 (feat(ssh): batch process evidence in PTY inventory) built the host side of the real endgame — direct-SSH/remote authorities now publish batched foreground evidence with their PTY inventory — and added shouldPollNoEvidenceProcessCadence so those panes can eventually go fully push-driven (zero idle host reads). That producer is intentionally not wired yet, because this renderer does not consume the inventory evidence and cannot tell "no evidence published" from "host too old to publish it". The comment that shipped with it (Keep the no-evidence cadence enabled until inventory evidence is consumed by this renderer) was about that pending work, and left remote panes at the full 2s cadence in the meantime.

This PR is the interim measure that does not depend on the inventory work: 2s -> 15s now, and shouldPollNoEvidenceProcessCadence still lands later for 15s -> 0. The two compose: when a producer is wired, shouldRunCadenceInspection() returns false and no timer is armed at all, so isProcessInspectionCostly becomes moot in that state.

The change

isProcessInspectionCostly moves to src/renderer/src/components/terminal-pane/agent-process-inspection-cost.ts (so it is unit-testable without a full pane session) and gains one leading branch:

if (ptyId !== null && isRemoteExecutionHostPtyId(ptyId)) return true
if (!userAgent.includes('Windows')) return false
return ptyId !== null

The local branch is byte-identical. Nothing else in the monitor, the cadence table, or the wire changed.

Measurements

Deterministic counts from agent-completion-no-evidence-cadence.test.ts with Math.random pinned to 0.5 (which makes the ±10% jitter factor exactly 1.0), over a 60s window. On a remote pane one inspection == one RPC round trip to the execution host.

Pane state Tier before Tier after Inspections/min before after
Visible remote, no agent evidence, no activity for >10s idle 2000ms no-evidence 15000ms 30 4
Visible remote, within 10s of output/title/hook activity idle 2000ms idle 2000ms 30 30
Visible remote, agent evidence, no foreground agent idle 2000ms idle 2000ms 30 30
Visible remote, recognized agent in foreground active 750ms active 750ms ~78 ~78
Visible remote, inspections erroring error backoff (>=10s, capped at tier) same, floor 15s 4 4
Hidden remote, no agent evidence not armed at all not armed at all 0 0
Local POSIX (any PTY) idle 2000ms idle 2000ms 30 30
Local Windows, no evidence, idle no-evidence 15000ms no-evidence 15000ms 4 4

Net: 30 -> 4 host round trips per minute per idle remote pane (-26/min, -87%). Decay is measured too: after one output byte a remote pane runs 5 inspections in the 10s hot window, then only 3 more over the following 45s.

For scale, the global inspection queue caps at MAX_INSPECTION_STARTS_PER_SECOND = 8 / MAX_CONCURRENT_INSPECTIONS = 4 (agent-process-inspection-queue.ts), so before this change ~16 visible idle remote panes were enough to start contending for that budget with the inspections that actually matter.

Negative user-facing trade-offs

This is not a strictly zero-behavior-change fix, and it should not be sold as one. It applies to remote hosts the same trade already shipped for local Windows.

The change: a remote pane with hasAgentRunEvidence === false AND lastForegroundAgent === null AND no pane activity in the last NO_EVIDENCE_ACTIVITY_HOT_WINDOW_MS (10s) polls every 15s instead of every 2s. That is the entire blast radius — every other state keeps its previous tier (see the table above).

Point by point, why no user-observable detection is delayed:

  1. Agent start stays event-driven, not 15s-delayed. recordActivity() (agent-completion-process-monitor.ts:265-270) re-arms immediately and specifically clears a no-evidence timer mid-interval (state.pollTimerTier === 'no-evidence' -> clearPollTimer in scheduleNextPoll). Every live PTY byte calls it (live-data-callback.ts:38), as does every title change (title-spawn-bell.ts:55) and every hook status (agent-completion-hook-observer.ts:76). A starting agent always prints; the covering test asserts that at t=14s of a 15s interval, one output byte produces an inspection 2s later. Deferred reattach chunks re-enter the same dataCallback, so they re-arm too.
  2. Agent finish detection and completion notifications are bit-for-bit unchanged. Once establishAgentEvidence() runs, currentPollTier() returns active (750ms, foreground agent present) or idle (2000ms, evidence without a foreground agent) and never reaches the no-evidence branch. The two-consecutive-idle-samples process-exit confirmation, pendingProcessExitAgent, and both suppression hooks are untouched. Covered by the existing "keeps a recognized agent on the full active cadence" and "still detects an unannounced agent exit promptly after escalating from the relaxed tier" tests.
  3. Hook-driven completion never touches this path. hasPendingHookDone() short-circuits handleInspectionResult before any tier decision, and hook-only coordinators never call startProcessTracking() at all — the existing "keeps cadence disarmed and the done quiet window intact when tracking never starts" test pins that.
  4. Transport failure behaves exactly as before. The result.unavailable === true branch (agent-completion-process-monitor.ts:71-76) and the consecutiveInspectionErrors backoff are unmodified: an unreachable host still yields the same non-committal outcome and never an exit claim. The backoff ceiling (Math.min(Math.max(10_000, base), base * 2 ** n)) already cannot undercut the 15s tier, so erroring remote scans do not start polling more often than healthy ones.
  5. live / unverifiable / exited is not involved. Nothing here produces or consumes an UnstoppedPtyVerdict. Confirmed: this path's only outputs are internal coordinator state and dispatchCompletion(...) (a notification), and a failed/absent inspection results in no claim rather than a downgraded one. Per docs/reference/ssh-execution-boundary.md, loss of contact remains unverifiable by construction — this PR does not add a new way to infer death from silence, it only asks a live host less often.
  6. No wire change. No new RPC param, no new field, no new stream opcode, nothing capability-negotiated. Purely a client-side timer choice, so mixed client/host versions are unaffected.

The one honest residual, stated plainly: the very first cadence inspection after a silent reattach moves from ~2s to ~15s. Reattach replay/snapshot is painted through the connect result, not through dataCallback, so lastPaneActivityAt can still be null right after a restore. Consequence: on an Orca restart with a remote agent that is running but printing nothing, the coordinator arms its process-exit detector up to ~13s later. Nothing user-visible is fed by that inspection (establishAgentEvidence() sets internal state only — the pane's agent badge comes from hooks and titles, and the foreground-agent tracker is disabled for remote PTYs anyway at pane-agent-identity.ts:129-131). To actually lose a notification you would need that agent to also exit inside the same 15s window with no output, no title change, and no done hook — and its exit returns a shell prompt, which is output. Local Windows has shipped with this identical window since the tier was introduced.

If a follow-up wants that window closed too, the clean fix is to record pane activity on reattach paint, not to keep the 2s cadence.

Reliability contract

  • Invariant: relaxing the no-evidence cadence must not change any completion outcome — only the timing of inspections that return no agent.
  • Failure source: #6288-shaped inspection volume, applied to the remote round-trip shape that #17525 documented but left on the full cadence.
  • Oracle: deterministic inspection counts per state under fake timers with jitter pinned, plus the existing exit/notification assertions that must remain unchanged.
  • Gate: extends the incumbent agent-completion-no-evidence-cadence.test.ts regression guard. That file is not referenced by config/reliability-gates.jsonc today (pre-existing gap, unchanged here); the adjacent agent-session.remote-host-authority gate's cadence tests were run and pass.
  • Provider/platform coverage: direct SSH + paired runtime covered (both id shapes asserted); local POSIX, local Windows, daemon, WSL unaffected (predicate asserted byte-identical); mobile/relay unaffected (no wire change).
  • Performance budget: no polling, timers, listeners, subprocesses, or scans added; one timer interval increased. Counts above.
  • Diagnostics: none added — the tier is already inferable from state.pollTimerTier.

Tests

Added to agent-completion-no-evidence-cadence.test.ts (extended, not a new file):

  • bounds a visible idle remote pane through the shipped cost predicate — SSH pty id through the real predicate: 4 round trips in 60s (was 30).
  • re-arms the remote pane to the 2s cadence on the first byte of PTY output — paired-runtime pty id, output at t=14s produces an inspection at t=16s.
  • isAgentProcessInspectionCostly unit block — remote costly on both Mac and Windows UAs across all three remote id shapes; local branch unchanged (Windows costly, POSIX cheap, null cheap); a bare ssh:target-1 with no relay pty id does not relax a POSIX pane.

Verification

  • pnpm tc — clean.
  • npx oxlint <changed files> — clean. npx oxfmt --check — clean.
  • npx vitest run --config config/vitest.config.ts src/renderer/src/components/terminal-pane — the target file is 19/19 green. The suite has pre-existing load-related timeout flake on this machine (~10 agents running vitest concurrently): a clean-tree baseline run of the same directory failed 19 tests across 12 files, all Test timed out in 30000ms in remote-runtime-pty-transport-* / remote-runtime-outage-* / pty-connection-*. Every file that failed in the with-change run and not in the baseline was re-run in isolation and passes.
  • Also green: agent-completion-coordinator-process-cadence, agent-completion-coordinator-pending-title-inspection, remote-execution-host-pty, pty-connection-task-complete-dispatch.

A visible remote/SSH terminal that has never run an agent inspected its
execution host every ~2s forever for a strictly negative answer — ~30
RPC round trips per minute per pane, each a network hop plus a host-side
foreground process scan.

The `no-evidence` 15s cadence tier exists to bound exactly that volume,
but `isProcessInspectionCostly` gated it on local Windows only and
explicitly excluded remote-execution-host PTYs — the most expensive
inspection shape in the codebase.

Extract the predicate to `agent-process-inspection-cost.ts` and treat a
remote-execution-host PTY as costly on every client platform. The local
branch (Windows costly, POSIX cheap) is byte-identical.

Client-side timer choice only: no wire change, no new field, no opcode.
Activity (output/title/hook) re-arms the 2s cadence, agent evidence
returns the tier to active/idle, and the `unavailable` branch and its
error backoff are untouched.
@coderabbitai

coderabbitai Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 5 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: 8366744c-d44d-46bb-beaf-cf5574e1828e

📥 Commits

Reviewing files that changed from the base of the PR and between f37d2fe and f37ca8d.

📒 Files selected for processing (4)
  • src/renderer/src/components/terminal-pane/agent-completion-coordinator-types.ts
  • src/renderer/src/components/terminal-pane/agent-completion-no-evidence-cadence.test.ts
  • src/renderer/src/components/terminal-pane/agent-process-inspection-cost.ts
  • src/renderer/src/components/terminal-pane/pty-connection/terminal-keydown-fit.ts

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.

@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

  • Extracted cost predicate — the isProcessInspectionCostly closure in terminal-keydown-fit.ts moves into a pure, unit-testable isAgentProcessInspectionCostly(userAgent, ptyId) in a new agent-process-inspection-cost.ts.
  • Remote panes now costly on every platform — a leading branch returns true for remote-execution-host PTYs (paired-runtime remote: and direct-SSH ssh:…@@…), relaxing idle no-evidence panes from 2s to 15s. The local Windows/POSIX branch is byte-identical to the prior logic.
  • Tests — integration tests exercise the shipped predicate for SSH and paired-runtime id shapes (4 trips/60s, output re-arms to 2s), plus a unit block pinning the local branch and the bare ssh: edge case.

The predicate refactor is faithful: for non-remote PTYs the new function returns the same result as the old inline closure on every platform (non-Windows false, Windows ptyId !== null), and the only behavioral change is remote PTYs flipping from false to true on all platforms — which is the entire intent. The remote-id detection is correct (remote: prefix and ssh:<conn>@@<pty> are costly; a bare ssh:target-1 is not), the target test file is green (19/19), and there is no wire change.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker merged commit d8ca420 into main Sep 2, 2026
33 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
stablyai#18146)

A visible remote/SSH terminal that has never run an agent inspected its
execution host every ~2s forever for a strictly negative answer — ~30
RPC round trips per minute per pane, each a network hop plus a host-side
foreground process scan.

The `no-evidence` 15s cadence tier exists to bound exactly that volume,
but `isProcessInspectionCostly` gated it on local Windows only and
explicitly excluded remote-execution-host PTYs — the most expensive
inspection shape in the codebase.

Extract the predicate to `agent-process-inspection-cost.ts` and treat a
remote-execution-host PTY as costly on every client platform. The local
branch (Windows costly, POSIX cheap) is byte-identical.

Client-side timer choice only: no wire change, no new field, no opcode.
Activity (output/title/hook) re-arms the 2s cadence, agent evidence
returns the tier to active/idle, and the `unavailable` branch and its
error backoff are untouched.
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