Repository navigation
perf: throttle hidden-pane agent inspection cadence to a 3s backstop (#6288 follow-up) - #6693
Conversation
A terminal pane that has ever run an agent keeps polling the OS process table for completion detection even while HIDDEN. The cadence (750ms active / 2000ms idle) did not depend on visibility, so a backgrounded pane forked a `ps`-scan every ~750ms purely to keep the process-exit backstop alive — wasting idle CPU, especially on shared SSH relays. Follow-up to #6288 / PR #6667 (merged), which deduped scans WITHIN a poll tick via a 500ms-TTL snapshot cache. This attacks the orthogonal axis: the number of ticks a hidden pane runs. Hidden panes now poll at a 3s cadence (HIDDEN_POLL_INTERVAL_MS). This is safe because the process poll is only a BACKSTOP: the primary completion signals — Orca-managed agent hooks (observeHookStatus, push via IPC) and xterm title changes (observeTitle) — are event-driven and fire regardless of poll cadence or visibility. Only a non-hooked agent with no recognizable completion title relies solely on the poll; for that case worst-case hidden completion-notification latency rises to ~2x3s (~6s, repeat-idle-sample) from ~2x750ms. Visible-pane cadence is unchanged (750ms). Becoming visible re-arms the slow hidden timer at full cadence immediately, so switching back to a throttled pane is not sluggish (scheduleNextPoll previously no-oped while any timer was pending). Measured inspection calls over 60s: hidden 78->20 (-74%); visible 78->78. Co-authored-by: Orca <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughA new 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
…tablyai#6693) A terminal pane that has ever run an agent keeps polling the OS process table for completion detection even while HIDDEN. The cadence (750ms active / 2000ms idle) did not depend on visibility, so a backgrounded pane forked a `ps`-scan every ~750ms purely to keep the process-exit backstop alive — wasting idle CPU, especially on shared SSH relays. Follow-up to stablyai#6288 / PR stablyai#6667 (merged), which deduped scans WITHIN a poll tick via a 500ms-TTL snapshot cache. This attacks the orthogonal axis: the number of ticks a hidden pane runs. Hidden panes now poll at a 3s cadence (HIDDEN_POLL_INTERVAL_MS). This is safe because the process poll is only a BACKSTOP: the primary completion signals — Orca-managed agent hooks (observeHookStatus, push via IPC) and xterm title changes (observeTitle) — are event-driven and fire regardless of poll cadence or visibility. Only a non-hooked agent with no recognizable completion title relies solely on the poll; for that case worst-case hidden completion-notification latency rises to ~2x3s (~6s, repeat-idle-sample) from ~2x750ms. Visible-pane cadence is unchanged (750ms). Becoming visible re-arms the slow hidden timer at full cadence immediately, so switching back to a throttled pane is not sluggish (scheduleNextPoll previously no-oped while any timer was pending). Measured inspection calls over 60s: hidden 78->20 (-74%); visible 78->78. Co-authored-by: Orca <[email protected]>
Summary
A terminal pane that has ever run an agent keeps polling the OS process table for agent-completion detection even while hidden (the user isn't looking at it). The poll cadence — 750ms active / 2000ms idle — did not depend on visibility, so a backgrounded pane forked a
ps-scan roughly every 750ms purely to keep the process-exit backstop alive. On a machine with several panes, and especially on shared SSH relays where many users' panes scan the same host, that idle churn adds up.This makes hidden panes poll at a 3s cadence (
HIDDEN_POLL_INTERVAL_MS). Visible-pane cadence is unchanged (750ms).Follow-up to #6288 / PR #6667 (merged), which deduped scans within a poll tick via a 500ms-TTL snapshot cache. This PR attacks the orthogonal axis: the number of ticks a hidden pane runs.
Why this is safe — the poll is only a backstop
The primary "agent finished" signals are event-driven and fire regardless of poll cadence or visibility:
observeHookStatus): push-fed via IPC from the main-process hook server. Almost all agents have Orca-managed completion hooks — claude, codex, gemini, cursor, droid, copilot, grok, hermes, devin, amp, … — and the hook path is gated on PTY liveness, not visibility.observeTitle): push-fed from xtermonTitleChange. Generic-completion-title validation uses apending-titleinspection that is exempt from the cadence gate.So the process-table poll is the sole completion detector only for the narrow case of an agent with no managed hook AND no recognizable completion title (e.g. aider, native
pi), running in a hidden pane. For that case alone, completion detection slows down.The tradeoff (stated explicitly)
The process-exit path requires a repeated idle sample before announcing (it debounces transient macOS handoff blips). So worst-case "background agent finished" detection for the no-hook/no-title hidden case is roughly 2–3 × the interval:
This applies only to a pane the user is not watching, and only to agents that emit neither a hook nor a completion title. Every hooked agent (the common case) notifies promptly and unchanged. The moment the user switches back to the pane, full cadence re-arms immediately (below).
Before / after evidence
Driving the real coordinator with fake timers over a 60s window, pane with agent evidence, jitter pinned:
No regression to visible panes / switch-back
Becoming visible previously called
startProcessTracking()→scheduleNextPoll(), which no-ops while a timer is already armed. So without care, a pane hidden mid-cycle would keep its slow 3s timer even after the user switched back, adding up to ~3s of catch-up lag. The fix tracks whether the armed timer is the slow backstop (pollTimerIsHiddenBackstop) and, on the hidden→visible flip, clears it and re-arms at full cadence immediately. Switching back to a throttled pane is not sluggish.Tests
Added to
agent-completion-coordinator.test.ts(all fail on pre-fix code, pass after — verified by stashing the source change):pnpm run typecheckclean (all three projects);oxlintclean; fullterminal-panesuite green (1273 tests).Cross-platform / SSH
Renderer-only TypeScript; visibility is computed identically on macOS/Linux/Windows (no platform branch). The remote/SSH hook-completion coordinator is a separate instance with
inspectProcesshardwired to null and noshouldPollProcessCadenceoption, so it is unaffected by this throttle.Notes
Incremental follow-up to the already-closed #6288; references PR #6667 for context. Does not close an issue.
🤖 Generated with Claude Code