Repository navigation
perf(remote): apply the no-evidence inspection cadence to remote panes (30 -> 4 host round trips/min/idle pane) - #18146
Conversation
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.
|
Warning Review limit reachedNext included review available in 5 minutes. View limit detailsLimit 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. Review configuration: ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (4)
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.
✅ No new issues found.
Reviewed changes
- Extracted cost predicate — the
isProcessInspectionCostlyclosure interminal-keydown-fit.tsmoves into a pure, unit-testableisAgentProcessInspectionCostly(userAgent, ptyId)in a newagent-process-inspection-cost.ts. - Remote panes now costly on every platform — a leading branch returns
truefor remote-execution-host PTYs (paired-runtimeremote:and direct-SSHssh:…@@…), 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.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
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.

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 theno-evidencetier whenoptions.isProcessInspectionCostly?.() === true. That callback was, effectively: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:
inspectRuntimeTerminalProcess->terminal.inspectProcessRPC,timeoutMs: 15_000(src/renderer/src/runtime/runtime-terminal-inspection.ts:115-142)window.api.pty.inspectProcess-> main -> SSH-muxpty.inspectProcess(src/main/providers/ssh-pty-provider.ts:282-283), which on the relay runsgetForegroundProcessName(pid)+processHasChildren(pid)per call (src/relay/pty-handler.ts:2378-2395)There is no cache anywhere on that path (
inspectPtyProviderProcesscalls 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 addedshouldPollNoEvidenceProcessCadenceso 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
shouldPollNoEvidenceProcessCadencestill lands later for 15s -> 0. The two compose: when a producer is wired,shouldRunCadenceInspection()returns false and no timer is armed at all, soisProcessInspectionCostlybecomes moot in that state.The change
isProcessInspectionCostlymoves tosrc/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: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.tswithMath.randompinned to0.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.idle2000msno-evidence15000msidle2000msidle2000msidle2000msidle2000msactive750msactive750msidle2000msidle2000msno-evidence15000msno-evidence15000msNet: 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 === falseANDlastForegroundAgent === nullAND no pane activity in the lastNO_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:
recordActivity()(agent-completion-process-monitor.ts:265-270) re-arms immediately and specifically clears ano-evidencetimer mid-interval (state.pollTimerTier === 'no-evidence'->clearPollTimerinscheduleNextPoll). 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 samedataCallback, so they re-arm too.establishAgentEvidence()runs,currentPollTier()returnsactive(750ms, foreground agent present) oridle(2000ms, evidence without a foreground agent) and never reaches theno-evidencebranch. 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.hasPendingHookDone()short-circuitshandleInspectionResultbefore any tier decision, and hook-only coordinators never callstartProcessTracking()at all — the existing "keeps cadence disarmed and the done quiet window intact when tracking never starts" test pins that.result.unavailable === truebranch (agent-completion-process-monitor.ts:71-76) and theconsecutiveInspectionErrorsbackoff 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.live/unverifiable/exitedis not involved. Nothing here produces or consumes anUnstoppedPtyVerdict. Confirmed: this path's only outputs are internal coordinator state anddispatchCompletion(...)(a notification), and a failed/absent inspection results in no claim rather than a downgraded one. Perdocs/reference/ssh-execution-boundary.md, loss of contact remainsunverifiableby construction — this PR does not add a new way to infer death from silence, it only asks a live host less often.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, solastPaneActivityAtcan still benullright 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 atpane-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
#6288-shaped inspection volume, applied to the remote round-trip shape that#17525documented but left on the full cadence.agent-completion-no-evidence-cadence.test.tsregression guard. That file is not referenced byconfig/reliability-gates.jsonctoday (pre-existing gap, unchanged here); the adjacentagent-session.remote-host-authoritygate's cadence tests were run and pass.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.isAgentProcessInspectionCostlyunit 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 baressh:target-1with 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, allTest timed out in 30000msinremote-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.agent-completion-coordinator-process-cadence,agent-completion-coordinator-pending-title-inspection,remote-execution-host-pty,pty-connection-task-complete-dispatch.