Repository navigation
perf(terminal): cheap-tier process inspection for anchored local agent panes - #18780
Conversation
|
the model provider had a temporary upstream failure. The provider refused or dropped the request mid-run — nothing in your repo or your credentials is at fault. Re-trigger Pullfrog; if it keeps happening, check the provider's status page.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (30)
🚧 Files skipped from review as they are similar to previous changes (29)
Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe change adds cheap process-table snapshots and deterministic POSIX pane fingerprints. Session anchors enable steady-state inspections to use cheap validation and escalate to full captures when process state changes. Cached local foreground recognition stores fingerprint metadata and revalidates it. The optional Merge Risk: ⚪ Minimal · up to This change adds lightweight steady-state process inspection while retaining full-inspection fallback behavior. No current merge-readiness risk is identified. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description explains the implementation, rationale, compatibility behavior, performance measurements, and tests in detail. However, it omits several required template sections, including Linked Issue, Visual Proof or an explicit N/A justification, AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist. It also does not provide the required testing checklist or platform coverage. Resolution Add and complete all missing required sections. Include a linked issue after
✨ Finishing Touches 💡 1📝 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
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Team
Run ID: e4e1abcb-8805-4d66-948b-6a7f60e69174
📒 Files selected for processing (30)
src/main/daemon/daemon-foreground-process-protocol.tssrc/main/daemon/daemon-pty-adapter-steady-state-compat.test.tssrc/main/daemon/daemon-pty-process-inspection.tssrc/main/daemon/daemon-pty-router.tssrc/main/daemon/daemon-request-router.tssrc/main/daemon/pty-subprocess/foreground-process-tracker.tssrc/main/daemon/session-subprocess-handle.tssrc/main/daemon/session.tssrc/main/daemon/terminal-host-cheap-tier-ps-scan-volume.test.tssrc/main/daemon/terminal-host-process-inspection-cheap-tier.test.tssrc/main/daemon/terminal-host-process-inspection.tssrc/main/daemon/terminal-host-steady-state-anchor.tssrc/main/daemon/terminal-host.tssrc/main/ipc/pty/ipc/inspect.tssrc/main/providers/local-pty-foreground-inspection-cheap-tier.test.tssrc/main/providers/local-pty-foreground-inspection.tssrc/main/providers/local-pty-provider-state.tssrc/main/providers/posix-pane-foreground-fingerprint.test.tssrc/main/providers/posix-pane-foreground-fingerprint.tssrc/main/providers/pty-process-inspection.tssrc/preload/api/pty-api.tssrc/preload/api/pty-bridge-stream-and-serialization.tssrc/renderer/src/components/terminal-pane/agent-completion-coordinator-types.tssrc/renderer/src/components/terminal-pane/agent-completion-process-monitor.tssrc/renderer/src/components/terminal-pane/agent-completion-steady-state-opt-in.test.tssrc/renderer/src/runtime/runtime-terminal-inspection.tssrc/shared/cheap-process-table-snapshot-reader.tssrc/shared/cheap-process-table-snapshot.test.tssrc/shared/process-table-snapshot-reader.tssrc/shared/process-table-snapshot.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — this run covered the single new commit since the prior review, which migrates the cheap-tier ps capture off a direct node:child_process import and onto runProcess.
- Routed the cheap capture through
runProcess—cheap-process-table-snapshot-reader.tsnow spawnspsvia Orca's single child-process entry point, closing the import-boundary ratchet gap the first commit would have tripped (thechild-process-import-boundarytest now passes with the pin unchanged). - Translated runner outcomes into the capture-error vocabulary —
outputTruncated→capture_truncated,timedOut→capture_timeout, non-zero exit →ps_exit_<code>. Both consumers catch any rejection and escalate to the full capture, so runtime behavior is unchanged. - Moved the test seams — the cheap-tier unit, daemon, and scan-volume tests now mock
runProcessrather thannode:child_process, and the reader test asserts the buffer ceiling and timeout are forwarded.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
ℹ️ No critical issues — the fix cleanly closes the missing-descendant-marker gap; one minor doc nit inline.
Reviewed changes
- Refused fingerprints with any unreadable descendant start marker —
buildPaneProcessFingerprintnow returnsnullwhen a descendant's start marker can't be read, instead of stamping a?placeholder, so two captures that both fail to read it can no longer compare equal across a recycled PID.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
| * and job-control state. Two captures with equal fingerprints describe the same pane | ||
| * subtree, so the name resolved from the last full capture still holds. | ||
| * | ||
| * Null when the root is missing or unfenced (no start marker, no group columns): callers |
There was a problem hiding this comment.
The function JSDoc still says the fingerprint is null only when the root is missing or unfenced (no start marker, no group columns), but the loop below now also returns null when any descendant's start marker is unreadable. Worth a one-line update so the null contract is accurate.
ccfce46 to
bf7c215
Compare
78db299 to
623cf07
Compare
…t panes Every idle local pane's completion cadence ran a full whole-host `ps` (with `tty=` and `command=`, 0.34-0.50s on a 1,900-process Mac, 1.15s on Linux) purely to build `foregroundProcessEvidence` that the renderer then discards for local ids. Add a cheap tier (same job-control columns, no tty/command, 0.03s) gated so that it introduces no user-facing trade-off: - Only a pane whose last FULL capture proved a recognized agent may take the cheap tier. Panes with no anchor always take the full capture, so start discovery keeps today's exact behaviour. - The cheap tick compares a per-pane fingerprint (root shell pid+start, tpgid, every descendant's pid+start+pgid+job-control state). Any change, a changed node-pty foreground name, an unreadable capture, or an incarnation mismatch escalates to the full capture. A recognized agent's exit is always a pid vanishing, which the fingerprint always sees. - A cheap answer OMITS evidence rather than fabricating a tty-less fence. Remote/restore consumers never send `steadyState`, so they keep the full capture unchanged. - `steadyState` is a new optional request field; an old daemon ignores it and answers with the full capture. Measured (8 idle panes, 60s, idle cadence, forks counted by column set): 30 full -> 1 full + 29 cheap.
The cheap-tier reader imported node:child_process directly, which the child-process import-boundary and windowsHide ratchet tests reject (CI shards 1/8 and 3/8). Use Orca's single spawn entry point instead; it pins windowsHide and encodes argv. Map its result onto the capture-error vocabulary: outputTruncated -> capture_truncated, timedOut -> capture_timeout, non-zero exit -> ps_exit_<code>. Tests mock at the runProcess seam.
… is missing `buildPaneProcessFingerprint` rejected only a missing root start marker; a missing descendant marker was stamped as `?`. Two captures that both failed to read the same descendant therefore compared equal, which removes the pid-reuse protection the fingerprint exists to provide: a recycled pid could make a vanished agent look unchanged, and the cheap tier would keep serving its name instead of escalating. Reachable on Linux, where `readLinuxProcStartTime` legitimately returns null when a process exits between the `ps` capture and the `/proc/<pid>/stat` read. Every subtree member now needs a start marker or the fingerprint is refused, which sends the caller to the full capture — the same conservative default every other uncertain path takes. Reported by CodeRabbit on #18780. The two new tests fail against the previous code with `expected '4242@2400#4300:|4300@?:4300:+' to be null`.
623cf07 to
486f4ba
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
… at boot (#18814) Every Electron E2E spec that boots the app has been failing on `workspaceSessionReady did not become true`, and the app itself has been launching to a blank white window: the renderer threw `ReferenceError: process is not defined` while evaluating a shared chunk, so React never mounted and no startup step ever ran. `agent-completion-poll-interval.ts` (renderer) imported one constant, `PROCESS_TABLE_SNAPSHOT_MAX_STALENESS_MS`, out of `shared/process-table-snapshot-reader.ts` — a `node:child_process` / `node:fs/promises` module whose dependency evaluates `process.platform` at module scope to pick `ps` columns. The renderer runs sandboxed with contextIsolation, where `process` is undefined, so that module-scope read threw and took the whole chunk with it. Introduced by #18742; #18780 added a second module-scope read next to the first. The constant now lives in `shared/process-table-snapshot.ts`, the environment-neutral half of the pair, and the reader re-exports it so host callers are unchanged. The two `ps` column sets read the platform behind a `typeof process` guard, which defuses the same landmine for any future renderer import of that module — only hosts ever run the argv. The regression test walks the renderer import graph (lazy routes included) from all three entries and refuses any module that reaches a `node:` builtin. It fails on the pre-fix import with the full 10-hop chain from `main.tsx`.
… at boot (stablyai#18814) Every Electron E2E spec that boots the app has been failing on `workspaceSessionReady did not become true`, and the app itself has been launching to a blank white window: the renderer threw `ReferenceError: process is not defined` while evaluating a shared chunk, so React never mounted and no startup step ever ran. `agent-completion-poll-interval.ts` (renderer) imported one constant, `PROCESS_TABLE_SNAPSHOT_MAX_STALENESS_MS`, out of `shared/process-table-snapshot-reader.ts` — a `node:child_process` / `node:fs/promises` module whose dependency evaluates `process.platform` at module scope to pick `ps` columns. The renderer runs sandboxed with contextIsolation, where `process` is undefined, so that module-scope read threw and took the whole chunk with it. Introduced by stablyai#18742; stablyai#18780 added a second module-scope read next to the first. The constant now lives in `shared/process-table-snapshot.ts`, the environment-neutral half of the pair, and the reader re-exports it so host callers are unchanged. The two `ps` column sets read the platform behind a `typeof process` guard, which defuses the same landmine for any future renderer import of that module — only hosts ever run the argv. The regression test walks the renderer import graph (lazy routes included) from all three entries and refuses any module that reaches a `node:` builtin. It fails on the pre-fix import with the full 10-hop chain from `main.tsx`. Mirror-Of: 0bbf86b
… at boot (stablyai#18814) Every Electron E2E spec that boots the app has been failing on `workspaceSessionReady did not become true`, and the app itself has been launching to a blank white window: the renderer threw `ReferenceError: process is not defined` while evaluating a shared chunk, so React never mounted and no startup step ever ran. `agent-completion-poll-interval.ts` (renderer) imported one constant, `PROCESS_TABLE_SNAPSHOT_MAX_STALENESS_MS`, out of `shared/process-table-snapshot-reader.ts` — a `node:child_process` / `node:fs/promises` module whose dependency evaluates `process.platform` at module scope to pick `ps` columns. The renderer runs sandboxed with contextIsolation, where `process` is undefined, so that module-scope read threw and took the whole chunk with it. Introduced by stablyai#18742; stablyai#18780 added a second module-scope read next to the first. The constant now lives in `shared/process-table-snapshot.ts`, the environment-neutral half of the pair, and the reader re-exports it so host callers are unchanged. The two `ps` column sets read the platform behind a `typeof process` guard, which defuses the same landmine for any future renderer import of that module — only hosts ever run the argv. The regression test walks the renderer import graph (lazy routes included) from all three entries and refuses any module that reaches a `node:` builtin. It fails on the pre-fix import with the full 10-hop chain from `main.tsx`.
…t panes (stablyai#18780) * perf(terminal): cheap-tier process inspection for anchored local agent panes Every idle local pane's completion cadence ran a full whole-host `ps` (with `tty=` and `command=`, 0.34-0.50s on a 1,900-process Mac, 1.15s on Linux) purely to build `foregroundProcessEvidence` that the renderer then discards for local ids. Add a cheap tier (same job-control columns, no tty/command, 0.03s) gated so that it introduces no user-facing trade-off: - Only a pane whose last FULL capture proved a recognized agent may take the cheap tier. Panes with no anchor always take the full capture, so start discovery keeps today's exact behaviour. - The cheap tick compares a per-pane fingerprint (root shell pid+start, tpgid, every descendant's pid+start+pgid+job-control state). Any change, a changed node-pty foreground name, an unreadable capture, or an incarnation mismatch escalates to the full capture. A recognized agent's exit is always a pid vanishing, which the fingerprint always sees. - A cheap answer OMITS evidence rather than fabricating a tty-less fence. Remote/restore consumers never send `steadyState`, so they keep the full capture unchanged. - `steadyState` is a new optional request field; an old daemon ignores it and answers with the full capture. Measured (8 idle panes, 60s, idle cadence, forks counted by column set): 30 full -> 1 full + 29 cheap. * fix(terminal): route the cheap ps capture through runProcess The cheap-tier reader imported node:child_process directly, which the child-process import-boundary and windowsHide ratchet tests reject (CI shards 1/8 and 3/8). Use Orca's single spawn entry point instead; it pins windowsHide and encodes argv. Map its result onto the capture-error vocabulary: outputTruncated -> capture_truncated, timedOut -> capture_timeout, non-zero exit -> ps_exit_<code>. Tests mock at the runProcess seam. * fix(perf): refuse a pane fingerprint when any descendant start marker is missing `buildPaneProcessFingerprint` rejected only a missing root start marker; a missing descendant marker was stamped as `?`. Two captures that both failed to read the same descendant therefore compared equal, which removes the pid-reuse protection the fingerprint exists to provide: a recycled pid could make a vanished agent look unchanged, and the cheap tier would keep serving its name instead of escalating. Reachable on Linux, where `readLinuxProcStartTime` legitimately returns null when a process exits between the `ps` capture and the `/proc/<pid>/stat` read. Every subtree member now needs a start marker or the fingerprint is refused, which sends the caller to the full capture — the same conservative default every other uncertain path takes. Reported by CodeRabbit on stablyai#18780. The two new tests fail against the previous code with `expected '4242@2400#4300:|4300@?:4300:+' to be null`.
… at boot (stablyai#18814) Every Electron E2E spec that boots the app has been failing on `workspaceSessionReady did not become true`, and the app itself has been launching to a blank white window: the renderer threw `ReferenceError: process is not defined` while evaluating a shared chunk, so React never mounted and no startup step ever ran. `agent-completion-poll-interval.ts` (renderer) imported one constant, `PROCESS_TABLE_SNAPSHOT_MAX_STALENESS_MS`, out of `shared/process-table-snapshot-reader.ts` — a `node:child_process` / `node:fs/promises` module whose dependency evaluates `process.platform` at module scope to pick `ps` columns. The renderer runs sandboxed with contextIsolation, where `process` is undefined, so that module-scope read threw and took the whole chunk with it. Introduced by stablyai#18742; stablyai#18780 added a second module-scope read next to the first. The constant now lives in `shared/process-table-snapshot.ts`, the environment-neutral half of the pair, and the reader re-exports it so host callers are unchanged. The two `ps` column sets read the platform behind a `typeof process` guard, which defuses the same landmine for any future renderer import of that module — only hosts ever run the argv. The regression test walks the renderer import graph (lazy routes included) from all three entries and refuses any module that reaches a `node:` builtin. It fails on the pre-fix import with the full 10-hop chain from `main.tsx`.

ELI5
Every terminal pane running an agent asks the daemon "what's in front?" every couple of seconds. To answer, the daemon read the entire machine's process table with two expensive columns (
tty=,command=) so it could build a proof-of-identity record. For local panes the renderer never reads that proof; it only uses the process name. So we were paying 0.34-0.50s (macOS, 1,900 procs) or 1.15s (Linux) per tick for a record that was thrown away.Now, once a pane has already been proven to be running a recognized agent, each tick first takes a 0.03s "cheap" look (same job-control columns, no tty/command) and checks whether the pane's process subtree is byte-for-byte what the last full look saw. If yes, the cached name is served. If anything at all differs, it does the full look exactly as before.
What changed
src/shared/process-table-snapshot.ts:CHEAP_PS_ARGS(macOSpid,ppid,pgid,tpgid,stat,lstart; Linux dropslstartand reads/proc/<pid>/statfield 22 for the pane subtree only) and a lenientparseCheapProcessTableRows.src/shared/cheap-process-table-snapshot-reader.ts: secondcreateProcessTableSnapshotReaderinstance with the same TTL/coalescing/budget as the strict reader, so 8 panes share one cheap fork per tick. Spawns throughrunProcess(Orca's single child-process entry point; the import-boundary andwindowsHideratchet tests reject a directnode:child_processimport), mappingoutputTruncated/timedOut/non-zero exit onto the existingProcessTableCaptureErrorvocabulary.src/main/providers/posix-pane-foreground-fingerprint.ts: per-pane fingerprint = root shellpid@startTime,tpgid, job-control state, plus every descendant'spid@startTime:pgid:jobControlState(sorted). Job-control state keeps only stopped/zombie/+; the scheduler letter is deliberately excluded because a working agent flips R/S every tick.src/main/daemon/terminal-host-steady-state-anchor.ts: aWeakMap<Session, anchor>set only after a full capture returnslivewith a recognized agent name; cleared on any full capture that does not.src/main/daemon/terminal-host-process-inspection.ts: whensteadyState: trueand the incarnation matches and an anchor exists and node-pty's raw name is unchanged and the cheap fingerprint matches, return{ foregroundProcess, hasChildProcesses: true }with noforegroundProcessEvidencemember. Every other path is today's code unchanged.src/main/providers/local-pty-foreground-inspection.ts: POSIX twin of the existing Windows job-membership short-circuit, for the non-daemonLocalPtyProvider. Stores the fingerprint alongsideptyLastRecognizedForeground.steadyStateplumbed as an optional field: preloadpty-api.ts/ bridge,inspect.tsIPC handler,PtyProcessInspectionOptions,DaemonPtyProcessInspection,DaemonPtyRouter,TerminalHost, daemon request router,InspectProcessRequest. The renderer sets it only forpriority === 'cadence'on a local pane.foreground-process-tracker.ts: one new read option,getForegroundProcess({ rawFallback: true }), which returns node-pty's own name with no cache and no background refresh. Needed so the cheap tick cannot trigger a fullpsas a side effect.Deliberately not touched:
windows-process-table.ts,windows-agent-foreground-process.ts,pty-handler.ts(relay/SSH),terminal-query-methods.ts/unary-schemas.ts(runtime RPC),confirmForegroundProcess, pending-title reads.Negative user-facing trade-offs
Panes without a recognized agent anchor always take the full capture, which is why start discovery is unchanged. The cheap tier is only ever consulted on a pane whose last full capture returned a
liveverdict naming a recognized agent. A pane at a shell prompt, a pane whose agent was just launched, a pane whose agent just exited, a pane after anunverifiableread, and every pane with a fresh incarnation pays exactly what it paid before. The one case the cheap tier cannot see (a non-leader descendantexecing into an agent with the same pid/pgid/start time) can therefore only occur on a pane that is already anchored, and on such a pane it is by definition not a start.Completion detection: a recognized agent's exit is always a pid disappearing from the subtree, or a start-time change if the pid is reused, and both change the fingerprint. The scan-volume test drives an exit, a restart, and a second exit through the same tick sequence with the tier on and off and asserts the
foregroundProcessseries is identical (toEqual).What still costs the same as today:
pending-titleread (decides a completion once).terminal.inspectProcessand the restore path; neither sendssteadyStateand both keep consuming full evidence.confirmForegroundProcess/confirmShellForeground.Nothing gets slower. Nothing is detected later than before.
Measured
src/main/daemon/terminal-host-cheap-tier-ps-scan-volume.test.ts: 8 idle agent panes, 60s at the 2,000ms idle cadence (30 ticks), forks counted by column set because CI cannot time a realpsportably.Per-fork cost measured by hand on this Mac (1,924 procs, 3 runs each): full column set 0.34-0.49s, cheap column set 0.03s.
tty=alone is 0.29s of the full cost. So for this workload, ~10-15s ofpsCPU per minute becomes ~0.3-0.5s + one full capture.Honest caveat: the "1 full" is the best case (every pane anchored on tick 1 and nothing changes for 60s). Any real event (an agent spawning a subprocess, a child exiting, Ctrl-Z) costs one full capture on that tick, then returns to cheap. Agents that spawn short-lived helpers every tick would see little benefit; they would see no regression either, since a changed fingerprint costs a cheap fork plus the full fork that was already being paid.
Wire compatibility
steadyStateis a new optional field on an existing daemon request and IPC payload (Rule 1 indocs/reference/remote-wire-compatibility.md). An old daemon ignores it and answers with the full capture; the client then reads evidence it did not strictly need, which is today's behaviour.daemon-pty-adapter-steady-state-compat.test.tscovers: field sent when requested, wire byte-identical when not, old daemon's full-shape answer accepted, pre-inspection daemon never sees it. It is not sent over the runtime RPC or the SSH relay at all.Tests
cheap-process-table-snapshot.test.ts: parser (macOS paddedlstart, Linux, malformed rows, empty capture), reader (column set, coalescing/TTL, truncation).posix-pane-foreground-fingerprint.test.ts: stability under scheduler-state/row-order/foreign-pane changes; escalation on agent exit, exit-and-replace, Ctrl-Z,bg, child churn (spawn, nest, leave group), shell replaced; null on unfenced root; Linux/procreads scoped to the subtree.terminal-host-process-inspection-cheap-tier.test.ts: no-anchor pane never takes the cheap path; anchored pane served cheap with no evidence member; nosteadyStatealways gets full + evidence; escalation matrix; changed node-pty name escalates without a cheap fork; cheap fork failure and incarnation mismatch fall through; dead session never served; anchor dropped when a full capture stops naming an agent.local-pty-foreground-inspection-cheap-tier.test.ts: same gate on the non-daemon provider.agent-completion-steady-state-opt-in.test.ts: cadence on local pane sends it; pending-title does not; remote pane never does.terminal-host-cheap-tier-ps-scan-volume.test.ts: the numbers above plus the on/off differential proof.Zero existing tests modified.