Skip to content

perf(terminal): cheap-tier process inspection for anchored local agent panes - #18780

Merged
nwparker merged 3 commits into
mainfrom
perf/cheap-tier-process-inspection
Sep 5, 2026
Merged

nwparker merged 3 commits into
mainfrom
perf/cheap-tier-process-inspection

Conversation

@nwparker

@nwparker nwparker commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1148 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1148
Prod 23 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​466 $\color{#cf222e}{\Huge{\mathbf{−}}}$​38 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​428

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 (macOS pid,ppid,pgid,tpgid,stat,lstart; Linux drops lstart and reads /proc/<pid>/stat field 22 for the pane subtree only) and a lenient parseCheapProcessTableRows.
  • src/shared/cheap-process-table-snapshot-reader.ts: second createProcessTableSnapshotReader instance with the same TTL/coalescing/budget as the strict reader, so 8 panes share one cheap fork per tick. Spawns through runProcess (Orca's single child-process entry point; the import-boundary and windowsHide ratchet tests reject a direct node:child_process import), mapping outputTruncated/timedOut/non-zero exit onto the existing ProcessTableCaptureError vocabulary.
  • src/main/providers/posix-pane-foreground-fingerprint.ts: per-pane fingerprint = root shell pid@startTime, tpgid, job-control state, plus every descendant's pid@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: a WeakMap<Session, anchor> set only after a full capture returns live with a recognized agent name; cleared on any full capture that does not.
  • src/main/daemon/terminal-host-process-inspection.ts: when steadyState: true and 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 no foregroundProcessEvidence member. 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-daemon LocalPtyProvider. Stores the fingerprint alongside ptyLastRecognizedForeground.
  • steadyState plumbed as an optional field: preload pty-api.ts / bridge, inspect.ts IPC handler, PtyProcessInspectionOptions, DaemonPtyProcessInspection, DaemonPtyRouter, TerminalHost, daemon request router, InspectProcessRequest. The renderer sets it only for priority === '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 full ps as 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 live verdict 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 an unverifiable read, and every pane with a fresh incarnation pays exactly what it paid before. The one case the cheap tier cannot see (a non-leader descendant execing 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 foregroundProcess series is identical (toEqual).

What still costs the same as today:

  • The first cadence tick of every pane, and the first tick after any change.
  • Every pending-title read (decides a completion once).
  • Every remote/paired-runtime terminal.inspectProcess and the restore path; neither sends steadyState and both keep consuming full evidence.
  • Every confirmForegroundProcess / confirmShellForeground.
  • Windows entirely.

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 real ps portably.

full forks cheap forks
Before (or any caller that does not opt in) 30 0
After 1 29

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 of ps CPU 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

steadyState is a new optional field on an existing daemon request and IPC payload (Rule 1 in docs/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.ts covers: 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 padded lstart, 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 /proc reads 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; no steadyState always 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.

@pullfrog

pullfrog Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

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.

provider error: {"code":502,"message":"Upstream error from StreamLake: The service is currently unable to handle additional requests due to server overload. Please retry later. Request id: 02178857908111197ebbf7316b3ea9a3b0d136bee84b9631fa864","metadata":{"error_type":"provider_unavailable"}}

Pullfrog  | Rerun failed job ➔ | View workflow run | via Pullfrog | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@coderabbitai

coderabbitai Bot commented Sep 5, 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: Team

Run ID: 699b8f5d-1e8b-4690-8cc5-1139b0a6ad0d

📥 Commits

Reviewing files that changed from the base of the PR and between 4c5077d and 486f4ba.

📒 Files selected for processing (30)
  • src/main/daemon/daemon-foreground-process-protocol.ts
  • src/main/daemon/daemon-pty-adapter-steady-state-compat.test.ts
  • src/main/daemon/daemon-pty-process-inspection.ts
  • src/main/daemon/daemon-pty-router.ts
  • src/main/daemon/daemon-request-router.ts
  • src/main/daemon/pty-subprocess/foreground-process-tracker.ts
  • src/main/daemon/session-subprocess-handle.ts
  • src/main/daemon/session.ts
  • src/main/daemon/terminal-host-cheap-tier-ps-scan-volume.test.ts
  • src/main/daemon/terminal-host-process-inspection-cheap-tier.test.ts
  • src/main/daemon/terminal-host-process-inspection.ts
  • src/main/daemon/terminal-host-steady-state-anchor.ts
  • src/main/daemon/terminal-host.ts
  • src/main/ipc/pty/ipc/inspect.ts
  • src/main/providers/local-pty-foreground-inspection-cheap-tier.test.ts
  • src/main/providers/local-pty-foreground-inspection.ts
  • src/main/providers/local-pty-provider-state.ts
  • src/main/providers/posix-pane-foreground-fingerprint.test.ts
  • src/main/providers/posix-pane-foreground-fingerprint.ts
  • src/main/providers/pty-process-inspection.ts
  • src/preload/api/pty-api.ts
  • src/preload/api/pty-bridge-stream-and-serialization.ts
  • src/renderer/src/components/terminal-pane/agent-completion-coordinator-types.ts
  • src/renderer/src/components/terminal-pane/agent-completion-process-monitor.ts
  • src/renderer/src/components/terminal-pane/agent-completion-steady-state-opt-in.test.ts
  • src/renderer/src/runtime/runtime-terminal-inspection.ts
  • src/shared/cheap-process-table-snapshot-reader.ts
  • src/shared/cheap-process-table-snapshot.test.ts
  • src/shared/process-table-snapshot-reader.ts
  • src/shared/process-table-snapshot.ts
🚧 Files skipped from review as they are similar to previous changes (29)
  • src/main/providers/local-pty-provider-state.ts
  • src/main/daemon/pty-subprocess/foreground-process-tracker.ts
  • src/renderer/src/components/terminal-pane/agent-completion-steady-state-opt-in.test.ts
  • src/preload/api/pty-bridge-stream-and-serialization.ts
  • src/shared/process-table-snapshot.ts
  • src/main/daemon/terminal-host.ts
  • src/main/providers/pty-process-inspection.ts
  • src/shared/cheap-process-table-snapshot.test.ts
  • src/main/daemon/daemon-request-router.ts
  • src/main/daemon/terminal-host-steady-state-anchor.ts
  • src/main/providers/posix-pane-foreground-fingerprint.ts
  • src/main/providers/posix-pane-foreground-fingerprint.test.ts
  • src/main/daemon/terminal-host-process-inspection.ts
  • src/main/daemon/terminal-host-cheap-tier-ps-scan-volume.test.ts
  • src/main/daemon/daemon-foreground-process-protocol.ts
  • src/preload/api/pty-api.ts
  • src/main/daemon/session.ts
  • src/renderer/src/components/terminal-pane/agent-completion-process-monitor.ts
  • src/renderer/src/components/terminal-pane/agent-completion-coordinator-types.ts
  • src/main/ipc/pty/ipc/inspect.ts
  • src/main/daemon/session-subprocess-handle.ts
  • src/renderer/src/runtime/runtime-terminal-inspection.ts
  • src/main/providers/local-pty-foreground-inspection.ts
  • src/main/providers/local-pty-foreground-inspection-cheap-tier.test.ts
  • src/shared/cheap-process-table-snapshot-reader.ts
  • src/main/daemon/daemon-pty-process-inspection.ts
  • src/main/daemon/daemon-pty-adapter-steady-state-compat.test.ts
  • src/main/daemon/terminal-host-process-inspection-cheap-tier.test.ts
  • src/main/daemon/daemon-pty-router.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The 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 steadyState flag now propagates through renderer, preload, IPC, daemon, and terminal-host APIs. Tests cover capture parsing, fingerprints, fallback behavior, fork volume, lifecycle changes, API compatibility, and renderer opt-in rules.

Merge Risk: ⚪ Minimal · up to 486f4

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)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the implementation, rationale, compatibility behavior, performance measurements, and tests in detail. However, it omits several required template sections, including Linked Is… Add and complete all missing required sections. Include a linked issue after Fixes #, add Visual Proof with N/A and a reason if there is no visual or interaction change, complete the Testing checkboxes with tested platforms and verifica…
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 42 functions across 30 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely identifies the main change: adding a cheap-tier process inspection path for anchored local agent panes.
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.
Full details: Description check

Explanation

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 Fixes #, add Visual Proof with N/A and a reason if there is no visual or interaction change, complete the Testing checkboxes with tested platforms and verification steps, provide the AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist sections, and confirm the required commands or CI coverage.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: e4e1abcb-8805-4d66-948b-6a7f60e69174

📥 Commits

Reviewing files that changed from the base of the PR and between 974acc9 and 7352de6.

📒 Files selected for processing (30)
  • src/main/daemon/daemon-foreground-process-protocol.ts
  • src/main/daemon/daemon-pty-adapter-steady-state-compat.test.ts
  • src/main/daemon/daemon-pty-process-inspection.ts
  • src/main/daemon/daemon-pty-router.ts
  • src/main/daemon/daemon-request-router.ts
  • src/main/daemon/pty-subprocess/foreground-process-tracker.ts
  • src/main/daemon/session-subprocess-handle.ts
  • src/main/daemon/session.ts
  • src/main/daemon/terminal-host-cheap-tier-ps-scan-volume.test.ts
  • src/main/daemon/terminal-host-process-inspection-cheap-tier.test.ts
  • src/main/daemon/terminal-host-process-inspection.ts
  • src/main/daemon/terminal-host-steady-state-anchor.ts
  • src/main/daemon/terminal-host.ts
  • src/main/ipc/pty/ipc/inspect.ts
  • src/main/providers/local-pty-foreground-inspection-cheap-tier.test.ts
  • src/main/providers/local-pty-foreground-inspection.ts
  • src/main/providers/local-pty-provider-state.ts
  • src/main/providers/posix-pane-foreground-fingerprint.test.ts
  • src/main/providers/posix-pane-foreground-fingerprint.ts
  • src/main/providers/pty-process-inspection.ts
  • src/preload/api/pty-api.ts
  • src/preload/api/pty-bridge-stream-and-serialization.ts
  • src/renderer/src/components/terminal-pane/agent-completion-coordinator-types.ts
  • src/renderer/src/components/terminal-pane/agent-completion-process-monitor.ts
  • src/renderer/src/components/terminal-pane/agent-completion-steady-state-opt-in.test.ts
  • src/renderer/src/runtime/runtime-terminal-inspection.ts
  • src/shared/cheap-process-table-snapshot-reader.ts
  • src/shared/cheap-process-table-snapshot.test.ts
  • src/shared/process-table-snapshot-reader.ts
  • src/shared/process-table-snapshot.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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.ts now spawns ps via Orca's single child-process entry point, closing the import-boundary ratchet gap the first commit would have tripped (the child-process-import-boundary test 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 runProcess rather than node:child_process, and the reader test asserts the buffer ceiling and timeout are forwarded.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ 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 — buildPaneProcessFingerprint now returns null when 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.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@nwparker
nwparker force-pushed the perf/cheap-tier-process-inspection branch from ccfce46 to bf7c215 Compare September 5, 2026 06:59
@nwparker
nwparker force-pushed the perf/cheap-tier-process-inspection branch 2 times, most recently from 78db299 to 623cf07 Compare September 5, 2026 07:18
…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`.
@nwparker
nwparker force-pushed the perf/cheap-tier-process-inspection branch from 623cf07 to 486f4ba Compare September 5, 2026 07:35
@coderabbitai

coderabbitai Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

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.

@nwparker
nwparker merged commit e95d247 into main Sep 5, 2026
35 of 37 checks passed
@nwparker
nwparker deleted the perf/cheap-tier-process-inspection branch September 5, 2026 07:57
nwparker added a commit that referenced this pull request Sep 5, 2026
… 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`.
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Sep 5, 2026
… 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
andremohrmann pushed a commit to andremohrmann/orca that referenced this pull request Sep 6, 2026
… 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`.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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`.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
… 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`.
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