Repository navigation
perf(windows): relax whole-process-table scans for terminals with no agent evidence - #7607
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThis PR adds tiered polling cadence controls for foreground and process-inspection checks in the daemon and renderer. The daemon now tracks recent PTY output to slow idle Windows foreground scans. The renderer coordinator adds a no-evidence polling tier, activity tracking, and a new output-activity signal. PTY connection code now reports output activity and narrows the costly-inspection check to local Windows PTYs. Regression tests cover the new cadence behavior and timer handling. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
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
🧹 Nitpick comments (1)
src/main/daemon/pty-subprocess.ts (1)
71-72: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick winKeep the 15s retry floor in sync with the renderer. This matches
NO_EVIDENCE_POLL_INTERVAL_MSnow, but the duplicated constant can drift; source both from one shared value.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: e652e267-460f-4752-b793-0271059ac9d3
📒 Files selected for processing (6)
src/main/daemon/pty-subprocess-foreground-scan-cadence.test.tssrc/main/daemon/pty-subprocess.tssrc/renderer/src/components/terminal-pane/agent-completion-coordinator-types.tssrc/renderer/src/components/terminal-pane/agent-completion-coordinator.tssrc/renderer/src/components/terminal-pane/agent-completion-no-evidence-cadence.test.tssrc/renderer/src/components/terminal-pane/pty-connection.ts
|
Priority: P0 — from the 2026-07-06 perf audit. Issue: on Windows, any visible terminal pane — even an idle shell with no agent — triggered a whole-process-table This PR: adds a 15s no-evidence tier (local Windows only) with event-driven escalation back to the hot cadence on PTY output/title/hook/inspection evidence; agent-finish detection and macOS/Linux/SSH cadences unchanged; daemon-owned sessions covered. |
…agent evidence A visible, idle terminal with no agent evidence previously drove a whole-process-table powershell.exe/CIM scan every 2s forever on Windows (~30 cold-starts/min). The agent-completion coordinator now relaxes such panes to a 15s no-evidence cadence on costly hosts (local Windows only), with event-driven escalation back to the hot cadence on PTY output, title changes, hook status, or an inspection hit. The daemon's foreground refresh for persisted sessions gains the same tier: idle no-evidence Windows shells retry at 15s instead of 5s unless output arrived within the last 10s. Agent-finish detection is unchanged: panes with agent evidence keep the existing 750ms/2s cadences, cached daemon identities keep the 1s refresh TTL, and macOS/Linux/SSH/remote panes keep full cadence everywhere. Co-authored-by: Orca <help@stably.ai>
The new activity bumps (output/title/hook) could arm cadence poll timers before the bind path called startProcessTracking, which made pty-connection tests' timer-drain helpers spin forever on CI (4 failures in verify). scheduleNextPoll now no-ops until startProcessTracking has run once, matching the production lifecycle where cadence only begins at PTY bind; coordinator tests that relied on observeTitle alone starting polls now start tracking explicitly. Co-authored-by: Orca <help@stably.ai>
b1a1d61 to
915592f
Compare
Co-authored-by: Orca <help@stably.ai>
Real-Windows validation resultsValidated on a physical Windows machine running this branch (dev build, daemon-persisted session). Idle scan counting used a branch-owned Idle scan rate (headline fix): 6 foreground scans over 125s; steady-state tail 2.85 scans/min vs ~30/min pre-fix and the ≤4/min target. Scan timestamps (s): 4.66, 23.38, 52.21, 82.00, 97.85, 114.11 — gaps alternate ~15–16s and ~29–30s, the renderer×daemon throttle beat described in the PR body's latency section. Agent-start attribution: Codex foreground attribution/icon appeared ~1.8s after launch output — the output-escalation path working as designed (the theoretical 15s bound only applies to an agent that never prints). Agent-finish: Codex Caveats from the run: the harness shell wasn't elevated, so the OS-native notification banner itself wasn't observed — but the coordinator's dispatch (which is all this PR touches) is proven by the in-app markers above; the native-banner path is untouched downstream code. Evidence JSON/screenshots are on the validation machine under |
The 10s error-backoff ceiling would undercut the 15s no-evidence tier (erroring scans polling more often than healthy ones); the Math.max cap prevents that but had no regression guard. Co-authored-by: Orca <help@stably.ai>
…indow intact Adversarial review of the pollTrackingStarted gate surfaced the one real behavioral delta: hook-only coordinators (which never start process tracking) previously armed stub cadence polls whose null inspections cleared workingStatusObserved ~2s after each hook, silently bypassing the designed 1.5s done quiet window on panes only the hook coordinator observes. The gate makes them purely push-driven; this pins that as intentional. Co-authored-by: Orca <help@stably.ai>
Clean auto-merge, no conflicts. Brought in from main: - daemon boot hardening: fail builds/CI when terminal daemon can't start; plain-node-entry-guard + verify-packaged-daemon-entry (electron require leaked into daemon-entry chunk, #7844/#7849) - perf(windows): relax whole-process-table scans for terminals with no agent evidence (#7607) — foreground-scan-cadence - fix(agents): route WSL OMP hooks to the Windows listener (#7565/#7641) - fix: recover fresh local terminal spawns from a deleted saved cwd (#7847) - native-chat: upload composer attachments over SSH (#7832) - mobile: keyboard dismiss control; agent-tab launch fix - new GitHub issue draft persistence (#7778) Perf-branch structure preserved (clean auto-merge; no restructured terminal files conflicted). Gates: typecheck 0 errors; terminal-pane + ipc/pty + daemon + pane-manager suites 4497 passed / 14 skipped / 0 failed. Co-authored-by: Orca <help@stably.ai>
…agent evidence (stablyai#7607) Co-authored-by: Orca <help@stably.ai>
Problem
On Windows, agent-completion tracking (default-on via notifications) inspects the terminal's process tree by forking
powershell.exe -NoProfile ... Get-CimInstance Win32_Process— a whole-process-table scan costing a ~250–700ms PowerShell cold-start per fork (plus a Defender scan of every launch), ~10–40× heavier than the POSIXpspath.A single visible, idle, plain shell with no agent paid that scan every 2s, forever (~30 cold-starts/min): the renderer cadence (
IDLE_POLL_INTERVAL_MS = 2000) is gated only on tracking-enabled + visibility, and the shared 500ms-TTL snapshot (src/shared/process-table-snapshot.ts) dedupes concurrent panes within a tick but does not slow the tick. Windows carries 64% of Orca crash reports plus an open hang cluster (STA-1073,STA-1248,STA-1169), so idle overhead there is expensive.Design
Renderer (shared scheduling, platform-clean). The coordinator's cadence tiers (
active750ms /idle2s /hidden3s from#6667) gain a fourth tier:no-evidence= 15s, applied only when the pane has no agent evidence and the new injectedisProcessInspectionCostly()option returns true.pty-connectionsupplies the policy with runtime checks: Windows renderer and local PTY (SSHssh:/remoteremote:PTYs run their scans on the remote host, so they keep full cadence). The coordinator itself stays platform-free.Event-driven escalation back to the hot cadence, so agent-start detection does not wait out the 15s interval:
observeOutputActivity()wired into the pane data callback (a starting agent always prints); opens a 10s hot window at the full 2s idle cadence, re-arming an armed slow timer immediately.Daemon (persisted sessions).
pty-subprocess.tsruns its own scan when readers callgetForegroundProcess(throttled at 5s for no-identity shells). That throttle now has the same shape: 15s on win32 for an idle shell with no cached agent identity and no output in the last 10s; output re-arms the 5s retry. This bounds daemon scans regardless of how many readers poll. POSIX keeps 5s; cached agent identities keep the 1s refresh TTL.Latency tradeoff (stated bound)
#6288guards): untouched; both existing scan-volume suites pass.Cost effect
Tests
Deterministic scan-count regression tests mirroring the
#6288guard style (pinned jitter, fake timers, exact counts):agent-completion-no-evidence-cadence.test.ts(renderer): idle no-evidence pane → exactly 4 inspections/60s on a costly host (pre-fix 30); cheap host and no-cost-source coordinators stay at 30; output/title escalation re-arms within 2s; hot window decays back to 15s (exact 5-then-3 poll counts); recognized agent keeps ≥70 inspections/60s; unannounced agent exit after escalation still dispatches completion.pty-subprocess-foreground-scan-cadence.test.ts(daemon): idle win32 shell polled every 2s for 60s → exactly 4 scans (pre-fix 11); output re-arms the fast retry and the resolved identity serves from cache; cached-identity sessions refresh every read past the 1s TTL; POSIX idle shell keeps the 5s retry (exact 6 scans/30s).All 161 tests across the touched suites pass;
pnpm typecheckclean; oxfmt/oxlint clean. (Pre-existing onmainand unrelated:pty-connection.test.ts+ 4 sibling suites fail to resolve a path alias in vitest — identical failure set with and without this change.)Real-Windows validation
Measured on a Windows machine running this branch (dev build, daemon-persisted session), using a branch-owned
execFile('powershell.exe')probe to avoid cross-instance noise:done).Adversarial review outcome
Two independent review passes (correctness/lifecycle lens and environment-matrix lens) plus a perf audit over the final diff. No Critical/High findings. Two items worth recording:
agent-hook-completion-notifications.ts— panes on worktrees without a mounted pane) never callstartProcessTracking, so the new gate stops their stub cadence polls. Onmainthose polls' null inspections clearedworkingStatusObserved~2s after each hook, silently bypassing the designed 1.5s done quiet window; with the gate the quiet window applies there as designed (≤1.5s added notification latency on that path, in exchange for suppressing premature milestone-done notifications, and the perpetual 2s stub-poll loop is gone). Pinned as intentional by the "keeps cadence disarmed and the done quiet window intact" test. Mounted panes are unaffected (primary coordinator unchanged; notification IDs dedupe).isProcessInspectionCostlykeys on the renderer's UA, so a paired web/mobile client driving a Windows host keeps 2sterminal.inspectProcessRPCs. The daemon-side 15s throttle still bounds actual CIM scans host-side regardless of caller, so the residual is RPC chatter, not scans — except in degraded-daemon mode (unthrottledLocalPtyProviderscans), which is rare and matches pre-PR cadence. Follow-up idea: derive "costly" from a host capability flag over runtime RPC instead of the client UA.Made with Orca 🐋