Skip to content

perf: throttle hidden-pane agent inspection cadence to a 3s backstop (#6288 follow-up) - #6693

Merged
nwparker merged 1 commit into
mainfrom
nwparker/throttle-hidden-pane-inspection
Jun 29, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/throttle-hidden-pane-inspection

Conversation

@nwparker

@nwparker nwparker commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • Hooks (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.
  • Titles (observeTitle): push-fed from xterm onTitleChange. Generic-completion-title validation uses a pending-title inspection 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:

Before (hidden) After (hidden)
Poll cadence 750ms 3000ms
Worst-case process-exit-only detection ~1.5–2.25s ~6–10s

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:

Scenario Before After
Hidden pane inspection calls / 60s 78 20 (−74%)
Visible pane inspection calls / 60s 78 78 (unchanged)

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):

  1. Throttle repro — hidden agent pane makes 15–25 inspections over 60s (was ~78). Guards the win.
  2. Visible unchanged — visible pane still ≥70 inspections over 60s.
  3. Switch-back re-arm — a throttled hidden pane that becomes visible re-arms full cadence immediately instead of waiting out the slow interval.
  4. Unannounced-exit backstop — a hidden agent that exits with no hook/title is still detected, at the slower cadence (~2 idle samples).

pnpm run typecheck clean (all three projects); oxlint clean; full terminal-pane suite 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 inspectProcess hardwired to null and no shouldPollProcessCadence option, 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

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]>
@coderabbitai

coderabbitai Bot commented Jun 29, 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: Pro

Run ID: f27bd31e-14d5-402e-bc43-2d2c54c73778

📥 Commits

Reviewing files that changed from the base of the PR and between e59f597 and b065df2.

📒 Files selected for processing (2)
  • src/renderer/src/components/terminal-pane/agent-completion-coordinator.test.ts
  • src/renderer/src/components/terminal-pane/agent-completion-coordinator.ts

📝 Walkthrough

Walkthrough

A new HIDDEN_POLL_INTERVAL_MS constant (~3s) is introduced to throttle OS process inspections for agent panes that are not visible. A pollTimerIsHiddenBackstop boolean tracks whether the currently armed timer used this slower cadence. isHiddenBackstop() checks shouldPollProcessCadence?.() === false; nextPollInterval() selects the interval accordingly. scheduleNextPoll() now conditionally clears a pending hidden-backstop timer when the pane becomes visible, immediately re-arming at full cadence. Tests cover cadence bounds, visibility transitions, and unannounced process exits.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The summary and testing notes are strong, but the required Screenshots, AI Review Report, and Security Audit sections are missing. Add the missing Screenshots, AI Review Report, and Security Audit sections, and format Testing as the repository’s checkbox checklist.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: throttling hidden-pane agent inspection cadence.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

@nwparker
nwparker merged commit 1dc63e9 into main Jun 29, 2026
2 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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]>
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