Skip to content

Local PTY inspection: degraded reads become unverifiable evidence, not agent exits - #16955

Closed
brennanb2025 wants to merge 9 commits into
brennanb2025/relay-completion-unverifiable-r1from
brennanb2025/local-inspection-unverifiable-r1
Closed

brennanb2025 wants to merge 9 commits into
brennanb2025/relay-completion-unverifiable-r1from
brennanb2025/local-inspection-unverifiable-r1

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1109 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1109
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​163 $\color{#cf222e}{\Huge{\mathbf{−}}}$​9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​154

Remediates coercion site 5 of the "failure becomes fact" class: local child-process inspection. Sibling PRs: #16900, #16908, #16926 (relay leg of this same monitor), #16932.

Stacked on #16926 (brennanb2025/relay-completion-unverifiable-r1, live head 91f761a706a2a0c65b985ea2903a0d0b7c9c79d0, re-resolved with git ls-remote; an earlier revision of this page pinned 2910404020, which the base branch has since moved past) — it defines the processEvidence contract and the monitor's consumption of it. Merge #16926 first, then retarget/rebase this onto main; this PR adds no hunks to the files #16926 owns (src/relay/pty-process-probes.ts, the pty-api.ts processEvidence hunk, daemon pid-publish paths are all untouched). Both halves re-verified at head a7ce56571ee14cbb0f99ae3f7b08654634d4f85a: 91f761a706 is an ancestor of this head, and of the 11 files this PR changes the only relay file is pty-process-probes.test.ts.

ELI5

Orca watches each terminal to notice when your agent (Codex, Claude Code, …) finishes, by asking the operating system "what's running in this terminal?". On a busy machine that question can fail — the process list comes back without your terminal in it, or the lookup dies. The old code treated "I couldn't look" exactly like "I looked and the agent is gone", so a perfectly alive agent could be announced as done. Now the local inspection says "I couldn't tell" when it couldn't tell, and the watcher just checks again instead of concluding.

User-facing before/after

When you'd hit this: you run an agent in a local terminal (macOS/Linux/Windows, including WSL panes and the fallback path used when the terminal daemon is unreachable) while the machine is under heavy load — e.g. big builds, test fanouts, or many agent panes forking ps/PowerShell scans at once. Exactly the moment you're most likely to be multitasking away from the pane.

  • Before: under load, the process scan degrades; Orca could fire "agent task complete" (with terminalIdleConfirmed) for an agent that is still working. If you trusted the notification and came back later, you found a half-finished run — or automations keyed on completion acted on a live terminal.
  • After: a degraded scan is recorded as unverifiable: no completion is announced from it, the monitor re-arms and backs off, and the completion fires only once a real observation confirms the exit. Genuine exits are still detected exactly as before (pinned by test). As a bonus, the pane's agent identity no longer flaps to the shell name during scan blackouts, so close-guards and status stay truthful.

The defect (verified real at origin/main 4f14d6d)

LocalPtyProvider publishes no evidence, so even with #16926's monitor the local leg collapses failures into facts:

  1. agent-foreground-process.ts (POSIX, cached-snapshot path): a table containing none of the pane (no shell row, no child rows) was treated as available: true → "no agent" → the provider's last-recognized-agent cache was cleared by a scan that observed nothing.
  2. local-pty-provider.ts:1415 (the sweep's cited catch): a thrown inspection fell back to cachedName ?? null — the comment itself admitted "null reads as an exit".
  3. hasChildProcesses coerces failures to false, and pty-process-inspection.ts:24-26 merges these into {foregroundProcess: <shell>, hasChildProcesses: false} — byte-identical to positive exit evidence for the completion monitor.

Pre-fix reproduction (real LocalPtyProvider + real completion coordinator/monitor, only ps and node-pty mocked at the OS boundary) fails on the unfixed tree with a concrete false completion:

AssertionError: expected "vi.fn()" to not be called at all, but actually been called 1 times
  1st vi.fn() call:
    [ "codex", { "quietedHookDone": false, "source": "process-exit", "terminalIdleConfirmed": true } ]

A live codex, recorded as complete with "terminal idle confirmed", from two reads that observed nothing.

The fix (contract-first, same vocabulary as the relay leg)

  • LocalPtyProvider.inspectProcess() now publishes processEvidence using the shared PtyProcessInspectionEvidence contract from Keep relay completion evidence live/unverifiable/exited, never coerced #16926 — no parallel evidence type. Legacy foregroundProcess/hasChildProcesses keep the exact pre-fix collapse (pinned by exact-equality tests), so old clients and evidence-blind consumers see identical values.
  • The foreground observation is threaded availability-first through the existing resolution (observeForegroundProcess): completed scan → observed; degraded scan / thrown inspection / pty replaced mid-read → unverifiable with a reason. Successful Windows job reads (confirmed/unproven) remain positive observations, preserving their legacy semantics.
  • Children evidence is distress-coupled: "title == shell" is only exited when the foreground scan completed, because node-pty's POSIX title read silently falls back to the spawned shell name when the native read fails — under the same distress that degrades the scan, the title observes nothing.
  • The POSIX cached-table scan now reports available: false when the table contains neither the pane's shell row nor any direct child of it (the fresh path keeps its stricter historical shell-row requirement).

live / unverifiable / exited per docs/reference/ssh-execution-boundary.md; loss of contact is never evidence of process death.

Consumers audited (compile-unchanged check)

Consumer Effect
LocalPtyProvider.confirmForegroundProcess (fresh scan) unchanged (strict fresh check preserved)
daemon foreground-process-tracker (scheduleRefresh) already availability-honest; now holds identity on never-observed tables instead of retiring it — conservative
daemon tracker confirmForegroundProcess (fresh) unchanged
resolveAgentForegroundProcess name-only callers identical names in every affected case (only available flips)
orca-runtime status/summary sites reading getForegroundProcess steadier identity during scan blackouts (cached agent instead of shell flap); real exits still clear via available scans
completion monitor (#16926) consumes the new evidence — the fix
evidence-blind renderer consumers (codex-session-restart, close-guard family, terminal-keydown-fit) compile unchanged; degraded reads now keep the agent name, so they no longer treat a blackout as an idle shell — conservative direction
daemon adapter / terminal-host inspectProcess unchanged — daemon-backed panes still publish no evidence (sibling site, deliberately out of scope, same as the sweep recorded it)
pre-#16926 wire peers optional field ignored; legacy values byte-identical

Ablation (re-measured at head e3bdedfc8b)

Suite: 5 files, 25 tests, all green at head —
src/main/providers/agent-foreground-process-snapshot-availability.test.ts,
src/main/providers/local-pty-process-evidence.test.ts,
src/main/providers/local-pty-provider-inspect-process-evidence.test.ts,
src/renderer/src/runtime/runtime-terminal-inspection-evidence-passthrough.test.ts,
tests/e2e/local-completion-evidence/local-inspection-unverifiable-completion.unit.test.ts.

Each production hunk reverted individually, tree restored between runs.

Hunk Red
POSIX cached-table pane-availability check 2 (availability unit pin + e2e false-completion)
degraded-scan unverifiable evidence 3
thrown-inspection unverifiable evidence 1
win32 job short-circuit observed evidence 1
inspectProcess method 8
children distress-coupling branch 5
observed-non-shell override branch 2

Three of these numbers moved since the table was first written, all upward: the degraded-scan
row said 2 and reddens 3; the inspectProcess row said 5 and reddens 8; the
distress-coupling row said 4 and reddens 5. The suite grew between the first measurement
and head — local-pty-provider-inspect-process-evidence.test.ts and the passthrough test came
later — so these are the same gates measured against more tests, not stronger gates.

Failing-first (measured at head a7ce56571e)

Every production file this PR changes reverted to #16926's live head 91f761a706, all tests kept,
then the PR's own 7 changed test files run: 10 failed across 4 of the 7. Baseline at head,
same 7 files: 69 passed, 0 failed. Tree byte-verified mutated before each run and restored
--hard after, serially.

The reproduction quoted above is one of those 10 — the ablated tree emits that
terminalIdleConfirmed: true assertion verbatim, not a paraphrase of it.

Notes

  • No new subprocess spawns; no node:child_process imports added; both only-shrinks ratchets and all baselines untouched (config/ diff is empty).
  • Perf: one extra O(n) pass over the already-parsed cached table per scan; one fewer async hop in local inspection; distress backoff reduces poll pressure. $perf skill is disable-model-invocation for workers, so this was reviewed by hand.
  • Residual (stated, not fixed here): daemon-hosted inspection (terminal-host.inspectProcess) is the remaining evidence-less local leg; the hook-lane stub inspectProcess in agent-hook-completion-notifications.ts predates this PR.

Author X handle: @BrennanKB5

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Verified push: this PR's reviewed head is exactly 7702a7de16582145a8d0b5b13ccb2ba54d8f363a (confirmed via git ls-remote origin brennanb2025/local-inspection-unverifiable-r1 → 7702a7de16582145a8d0b5b13ccb2ba54d8f363a). Stacked on #16926 base 291040402098adb1ef200ee2e05456e688f4d2cb; the branch diff vs that base contains only the local-inspection hunks described above.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Independent adversarial review — head 7702a7de16582145a8d0b5b13ccb2ba54d8f363a (stack base 291040402098adb1ef200ee2e05456e688f4d2cb)

Verdict: MERGE-READY (after #16926, with manual retarget). Every load-bearing claim re-verified independently; no P0/P1. Notes below are non-blocking.

Claims re-verified (not taken from the PR body)

  • Site real at main 4f14d6d757 and NOT closed by Keep relay completion evidence live/unverifiable/exited, never coerced #16926. The null reads as an exit collapse is at main's local-pty-provider.ts:1419. The pre-fix repro was re-run on the stack base 2910404020 — which already contains Keep relay completion evidence live/unverifiable/exited, never coerced #16926's evidence-aware monitor — and it fired dispatchCompletion("codex", { source: 'process-exit', terminalIdleConfirmed: true, quietedHookDone: false }) for a live agent, through the real LocalPtyProvider + real completion coordinator with only ps and node-pty mocked. 3 tests red on base (false completion, availability pin, missing evidence); the real-exit and shell-row-lost tests pass on base, so the repro isolates the defect.
  • 7-hunk ablation re-run independently: 2 / 2 / 1 / 1 / 5 / 4 / 2 — matches the PR table exactly; every production hunk is individually load-bearing. Notable: with only the stable-cache hunks ablated, the e2e stays green because the availability guard masks it (and vice versa) — the unit pins are what make each hunk individually red, which is exactly why they exist.
  • Legacy fields byte-identical — verified mechanically, not by reading. A scratch differential harness ran 8 scenarios (healthy, degraded-table ±cache, ps-throw ±cache, real exit, child-only table, reaped pty) twice each from identical pre-state: once through the pre-evidence derivation (getForegroundProcess + hasChildProcesses) and once through inspectProcess. The legacy pair byte-matched in all 8. Scope caveat, correctly disclosed in the PR: the cached-table availability hunk deliberately changes legacy-visible behavior in one class of case (a table that never contained the pane used to clear the identity and flap to the shell; it now holds the cached agent) — that is the fix's conservative direction, not a parity break of the evidence plumbing. Ablations 2/3/4/6/7 (evidence-only hunks) left every legacy-field assertion green.
  • node-pty title-fallback rule verified in dependency source (unixTerminal get process): darwin returns the spawned file for a kernel_task native read, other POSIX returns pty.process(...) || this._file — so "title == shell" under scan distress genuinely observes nothing. The distress-coupling is correctly load-bearing.
  • CI 29/29 required, 0 failures — confirmed via checks API (29 pass, 11 skipped, none failing).

Attacks on the new distinctions

  • (a) Scan "available" but incomplete. Constructible: a well-formed ps table that retains the shell row (or one descendant row) while omitting the live agent's row reads as available: true, and children evidence then claims exited beyond what was observed. But a false completion additionally requires the node-pty title read to degrade to the shell simultaneously, on two consecutive polls — and execFile timeout/maxBuffer truncations reject (→ unverifiable), so a silently partial-yet-parsable table is essentially a pid-enumeration race. This residual is inherent to trusting any completed scan, is strictly narrower than pre-fix (where the same table also wiped the identity cache immediately), and matches the fresh path's historical trust model. Residual risk, not a defect.
  • (b) Stale positive table. Yes, a cached table that did contain the pane stays authoritative for its TTL — but the TTL is 500ms and the active cadence's minimum inter-poll gap is ~675ms, so two completion strikes cannot ride one snapshot on the cadence path. (A pending-title inspection interleaved within 500ms could theoretically share a snapshot with a cadence strike; that property is pre-existing and untouched by this PR.) Bounded, pre-existing, conservative-enough.
  • (c) win32. confirmed/unproven require a non-null job read that includes the shell pid (readWindowsPtyJobProcessIds returns null otherwise; null → unavailable/unsupported, which falls through to the scan). A degraded job read therefore cannot produce the observed short-circuit — and the short-circuit names a recognized agent, so the monitor treats it as live, never as exit. The win32 scan leg refuses tables that omit the pane root (queryWindowsPaneProcessInventory → null → available: false) — stricter than the new POSIX check. A job exited verdict only deletes the cache; the exit conclusion still requires an available scan. No confident-exit-from-degraded-read route found on Windows.
  • (d) Any remaining live-agent→positive-exit route? The monitor needs foreground observed + unrecognized + children exited, twice. Local observed arises from: reaped pty (positive — and foreign ids can't reach it: inspectPtyProviderProcess gates on hasPty === false → terminal_gone → unavailable, and the daemon router's adapterForInspection throws when no adapter owns the id), win32 job confirm (recognized agent → live), or an available scan (attack (a) above). The one real remaining route is the daemon terminal-host leg (terminal-host.ts:217 publishes no evidence; the pre-v27 client-side composition in daemon-pty-process-inspection.ts likewise), which is the default macOS path — acknowledged in the PR as the sibling site under separate remediation. Within this PR's scope (daemon-off, degraded-daemon fallback, router-local sessions, the runtime inspectTerminalProcess path over a local controller), no route survives.

Stack correctness (merge-order answer for the maintainer)

Consumer list (derived independently; all compile unchanged)

Consumer Behaves wrongly?
Completion monitor (agent-completion-process-monitor.ts:78) No — the fix's consumer; unverifiable → re-arm + backoff
LocalPtyProvider.confirmForegroundProcess / fresh path No — fresh gate unchanged (new check is trivially satisfied when the fresh shell-row check passes)
Daemon tracker scheduleRefresh (foreground-process-tracker.ts:139) No — drops available: false resolutions, so it now holds identity on never-contained tables (conservative); genuine exits still retire because the surviving shell row makes the table available
Daemon tracker fresh confirm (:277) No — fresh path unchanged
Runtime inspectTerminalProcess (orca-runtime.ts:22477) No — prefers controller inspectProcess, wire type already carries the optional field
degraded-daemon-pty-provider.ts:191 No — gains evidence for local-owned ids (this is part of the fix's reach)
Daemon router / terminal-host / pre-v27 adapter composition Unchanged — still evidence-less (sibling site, out of scope)
Evidence-blind renderer consumers (codex-session-restart.ts:97, pane-serializer-settle.ts:154, agent-ready-wait.ts:95, paste/followup gating) No — steadier identity during blackouts is the conservative direction for all of them (restart eligibility additionally re-confirms with a fresh availability-strict scan)
Pre-evidence wire peers / old daemons No — optional field ignored; legacy bytes proven identical

Non-blocking notes (P2)

  1. classifyLocalPtyChildProcesses's observed-non-shell override intentionally publishes hasChildProcesses: false with children evidence live — legacy parity requires it, and the code comment says so, but it means the local leg cannot use the shared buildPtyProcessInspectionWireResult (which would force hasChildProcesses: true for live). Fine as-is; worth remembering when the daemon leg adopts the contract.
  2. POSIX cached-path availability accepts a child-only table (shell row lost) as an observation while the win32 inventory requires the root row. The asymmetry is justified (a descendant row is pane evidence, and the stricter form broke a legitimate existing behavior), but the divergence deserves the one-line comment it already has — no action.
  3. The e2e and provider-evidence suites duplicate ~100 lines of vi.mock boilerplate; per-file vi.mock hoisting makes this hard to share. Not worth restructuring.

Test-to-prod ratio (768:149): thoroughness, not redundancy — the ablation matrix shows the unit pins and the e2e catch different reverts (the stable-cache fallback masks several hunks from the e2e), so the layers are each load-bearing. This is what the fix should look like written from scratch, given the legacy-parity constraint.

Perf reviewed by hand ($perf skill is disable-model-invocation for workers): one extra O(n) pass over already-parsed rows per cached scan, one fewer async hop in inspection, no new forks/timers/listeners, and degraded reads now engage the monitor's backoff (net fewer polls under load).

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Stack refresh + review

Refresh (the stack was stale)

This branch did not contain its own base. It has been rebased onto #16926's current head and force-pushed.

before after
#16955 head 7702a7de16 a8c720296e
built on (#16926 head) 291040402098 (merge-base) 3ca44ad9b5

The two commits it was missing — 7f002039b8 (require a positively matched exited verdict before completion dispatch) and 3ca44ad9b5 (validate evidence field types, not just verdicts) — are now in the tree. The rebase was conflict-free: the file sets are disjoint. CI is green on the new head (28 success / 11 skipped / 0 failures).

Two notes for whoever picks the stack up next:

Do #16926's gates still fire under this change?

A green composed tree proves nothing on its own, so I built the composed tree locally (#16926 + #16955 + #17003), reverted each gate individually, and checked that a test actually goes red.

Gate reverted Tests red
Out-of-vocabulary guard (foreground !== 'observed' || children outside live/exited) 0
Positive-exited requirement (children !== 'exited') 0
Both of the above together 2
observed + non-string processName type validation 1
Non-string unverifiable reason fallback 1

The two monitor hunks are mutually redundant — each alone catches the out-of-contract verdict, so neither is independently pinned and reverting either one on its own stays green. The pair is covered; the individual arms are not. That is a coverage gap in #16926's test, not a defect here, and it means a future edit could silently delete one arm. Worth an independent pin in #16926.

The two type-validation hunks are each independently pinned.

Answering the composition questions directly: this PR's evidence satisfies #16926's type validation (every verdict it emits is in-contract, with string reasons and string | null process names), and an unverifiable verdict correctly fails the positive-exited gate on both the foreground and children legs.

Per-hunk ablation of this PR

Each production hunk reverted individually on the refreshed tree; every one is pinned.

Hunk Tests red
Pane-membership availability check 2
Degraded scan → unverifiable 2
Thrown inspection → unverifiable 1
inspectProcess method 5
Children distress-coupling 4
Observed non-shell override 2
PTY title-read failure → unverifiable 1

Can a degraded local read still be published as an exit?

In the agent-completion path, no. Every return site in observeForegroundProcess now carries a verdict, the monitor guards unavailable before reading evidence, its catch re-arms rather than completing, and the reader degrades malformed payloads to unverifiable.

Outside it, yes — and that is worth stating plainly. readPtyProcessInspectionEvidence is read by exactly one consumer, the completion monitor. The other eight consumers of inspectRuntimeTerminalProcess still read the collapsed legacy fields. Most are safe because they are positive gates that fall conservative on a degraded read (agent-followup-delivery, codex-session-restart, agent-ready-wait), and running-terminal-close-guard fails open by a documented deliberate choice.

The one that does not is workspace cleanup:

workspace-cleanup-local-evidence.ts:172-178 (probeTerminalLiveness) reads pty:hasChildProcesses and pty:getForegroundProcess as standalone RPCs. LocalPtyProvider.hasChildProcesses still ends in catch { return false }, and getForegroundProcess still collapses to ?? null — both below the IPC boundary. So the probe's own catch → 'unknown' arm is unreachable for local panes: a degraded read arrives as a clean false + null, reads as 'idle', and drops the running-terminal blocker in workspace-cleanup-candidate-enrichment.ts:241-246, making a worktree with a live agent eligible for cleanup.

This is pre-existing, is not introduced or worsened here, and is genuinely outside this PR's scope (it does not go through inspectProcess at all). Flagging it rather than expanding this PR — it wants the evidence contract extended to the standalone probe RPCs, which is its own change.

On the retained ?? null

The cached ?? null foreground read is not gone — it is deliberately retained, and that is correct: the legacy fields must keep their exact pre-evidence collapse for wire compatibility. What changed is that it now travels beside an unverifiable verdict, so evidence-aware readers cannot read it as an exit. Its comment still asserted the old hazard ("null reads as an exit"), which now contradicts the code and invites someone to "fix" the legacy collapse and break that parity; I corrected the comment (a8c720296e) and changed nothing else.

I also checked whether inspectProcess should reuse the shared buildPtyProcessInspectionWireResult. It should not: that helper derives hasChildProcesses from children.verdict === 'live', which would flip the legacy field to true in the observed-non-shell-override branch. Hand-building it preserves byte-identical legacy output, verified branch-by-branch against the pre-change hasChildProcesses.

Verification

pnpm tc exit 0 on both the refreshed branch and the composed tree. Changed-code quality gate: 0 new findings across all three lanes (code quality, type-aware, React Doctor). oxlint and React Doctor: 0 diagnostics. No node:child_process imports; no ratchet, allowlist, or baseline touched. Parent suites run in full: src/renderer/src/components/terminal-pane/ 3893 passed, src/shared/ 6128 passed, src/main/providers/ 783 passed.

No Electron UI validation: this change has no renderer surface, and the behaviour it fixes (suppressing a false completion under a degraded ps read) is not reachable through CDP. CI's native-smoke on macOS, Linux and Windows covers app boot. I did not validate on a Windows host directly, so the win32 job-object arms are covered by tests and CI only.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Follow-up: how far each half of this change actually reaches

A second review pass turned up something worth stating explicitly, because the two halves of this PR have very different reach. Both claims below I verified in the tree.

The one-line guard has broad reach — including daemon-hosted panes. The new pane-membership check in agent-foreground-process.ts:176-179 lives in shared code. src/main/daemon/pty-subprocess/foreground-process-tracker.ts:139 calls the same resolveAgentForegroundProcessWithAvailability, and its :146 if (args.isDead() || !available) now short-circuits before the unconditional retireStaleForegroundIdentity() at :191. So a daemon-hosted local pane whose cached ps table lost the pane's subtree previously retired the agent identity and published the shell name; it now holds. That path is fixed by this PR too.

The evidence-publishing half does not reach the default local pane. daemon-init.ts:950 calls setLocalPtyProvider(routedAdapter) on successful daemon adoption, so getProviderForPty returns the daemon adapter for all non-SSH ids. LocalPtyProvider.inspectProcess is therefore reached only on daemon-init failure, the degraded/new-pty fallback, headless orcad, and tests. terminal-host.inspectProcess still publishes no evidence — which is #17003's job, and the PR body already scopes it out.

Worth noting because the PR's "when you'd hit this" framing reads as though the whole change covers local terminals generally. The behavioural fix does; the evidence contract does not, until #17003 lands.

Two findings that belong to the base, not to this PR

A degraded read now silently drops a pending-title completion. agent-completion-pending-title.ts:95-107: finishInspection dispatches only when succeeded && recognized && hasAgentEvidence(), and clears only when !succeeded. An unverifiable foreground makes the monitor return false with inspectionSucceeded === true, so it hits neither arm — the pending title survives, scheduleExpiry() runs, and it expires into onExpired: () => {} (agent-completion-coordinator.ts:159). The result is a missed "agent done" notification.

This is a false negative, never a false completion, so it is strictly the safe direction. But it is entirely renderer-side logic in the base branch — this PR touches no renderer file, it only newly exposes local panes to a path that already applies to relay/SSH panes, where the contract's own doc calls "could not ask" a normal steady state. Recommend raising it against #16926 rather than holding this PR. Nothing covers it today.

Two smaller consequences of the same shape, both also safe-direction: a degraded pane no longer resets consecutiveInspectionErrors, so it backs off to the 10s poll tier and post-recovery completion latency grows; and a degraded read no longer runs handleRecognizedProcess, the only writer of state.lastForegroundAgent, so identity can no longer bootstrap from the node-pty title on that pane.

One test-hygiene note

tests/e2e/local-completion-evidence/local-inspection-unverifiable-completion.unit.test.ts is the genuine regression test here — real provider, real resolver, real ps parser, real coordinator, and it fails on the pre-fix tree by dispatching a false completion. Its strength comes precisely from the resolver being real.

But it hoists a resolveAgentForegroundProcessMock and passes it to applyLocalPtyProviderMockDefaults, while never vi.mock-ing agent-foreground-process. The wiring is inert, and it reads as though the resolver is mocked when it is not. If someone later adds that vi.mock "to fix a flake", they would replace the real resolver and silently gut the only behavioural test in the PR. Worth deleting the inert wiring, or adding a line saying the resolver is deliberately real.

For contrast, local-pty-provider-inspect-process-evidence.test.ts mocks ./agent-foreground-process wholesale and injects the available flag — the exact thing the bug was about — so it is a shape test rather than a regression test. That is a reasonable split, just worth being explicit about which is which.

@brennanb2025
brennanb2025 force-pushed the brennanb2025/relay-completion-unverifiable-r1 branch from 3ca44ad to 66abb42 Compare August 28, 2026 13:00
@brennanb2025
brennanb2025 force-pushed the brennanb2025/local-inspection-unverifiable-r1 branch from a8c7202 to 82e2fde Compare August 28, 2026 13:20
A degraded local foreground read (failed or pane-less ps table, thrown
scan) used to collapse into the same payload as an observed idle shell,
and the agent-completion monitor read it as exit evidence. The local
provider now implements inspectProcess with per-probe
live/unverifiable/exited processEvidence (same contract as the relay
leg), keeps legacy fields byte-identical, and the POSIX resolver stops
claiming availability for cached tables that never contained the pane.
…nd read

The comment described the pre-evidence hazard it no longer causes: the catch
now publishes an `unverifiable` verdict, so the retained `?? null` legacy name
(kept byte-identical for pre-evidence wire peers) can no longer read as an
exit. Left as-is it invites a future reader to "fix" the legacy collapse and
break that parity.
@brennanb2025
brennanb2025 force-pushed the brennanb2025/local-inspection-unverifiable-r1 branch from 82e2fde to abb7f33 Compare August 28, 2026 14:04
…usal arms

A gate ablation found the `unavailable` arm of the completion monitor free
while its structurally identical out-of-contract twin was pinned. After an
`unavailable` sample the pending exit could stop being discarded and nothing
would notice: a pending exit would survive the gap and be confirmed by the next
positive sample, so the two "consecutive" samples that dispatch a completion
would be separated by a read that observed nothing. `unavailable` is strictly
less evidence than an out-of-contract verdict, so if either arm deserves the
re-arm it is this one. Its backoff charge was free for the same reason and is
pinned here too, or an unreachable host gets polled at the active tier forever.

Also pinned, each red with that arm reverted alone: the exit-1-is-not-absence
timed-out check on both pgrep and ps, the ps spawn-failure staying
unverifiable, `processName: null` from a completed scan reading as positive
absence, an unowned pty reading as positive absence, and a pty replaced
mid-scan staying unverifiable.

`!result.signal` in subprocessRanAndMatchedNothing is left unpinned on
purpose: Node reports `code` and `signal` mutually exclusively, so
`code === 1` with a signal is not an input production emits, and a test for it
would assert an unreachable branch.
… depends on

Two cross-PR hazards found against #17024, both closed on the side that owns
the code they depend on.

1. #17024 moves `RuntimeTerminalProcessInspection` into a new leaf module while
   this branch adds `processEvidence` to it in the old one. The merge conflicts,
   and the natural "keep ours — the type moved" resolution drops the field. It
   is optional and every reader guards it, so nothing at the call sites changes:
   `readPtyProcessInspectionEvidence` then promotes a host that could not answer
   to `observed` + `exited`, positive exit evidence from a read that observed
   nothing. The new test reads the field through the declared type, so the drop
   fails the typecheck at a named site, and asserts the real reader's output
   both with the evidence and without it.

2. `inspectPtyProviderProcess` falls back to composing `getForegroundProcess` +
   `hasChildProcesses` for a provider that has no `inspectProcess` of its own.
   Both coerce a degraded read to null/false with no way to say "could not ask",
   which is the idle a workspace-cleanup row gets swept up on. Pinned with the
   real LocalPtyProvider and no double: a degraded scan must reach the caller as
   `unverifiable` on both probes, and the same sample read through the legacy
   pair alone is shown reading as `exited`.

Both go red with their arm reverted alone and stay green under the others.
@greptile-apps

greptile-apps Bot commented Aug 28, 2026 •

Copy link
Copy Markdown

Greptile Summary

The PR makes degraded local PTY process inspection explicitly unverifiable rather than treating probe failure as process exit.

  • Adds foreground and child-process evidence to LocalPtyProvider.inspectProcess.
  • Preserves legacy process-name and child-boolean values for evidence-blind consumers.
  • Marks incomplete POSIX snapshots, failed probes, and PTY replacement during inspection as unverifiable.
  • Adds unit and integration coverage for local-to-renderer evidence propagation and completion suppression.

Confidence Score: 5/5

The PR appears safe to merge because no blocking failure remains.

No blocking failure remains.

Important Files Changed

Filename Overview
src/main/providers/agent-foreground-process.ts Distinguishes cached POSIX snapshots that contain no pane-related process rows from authoritative scans.
src/main/providers/local-pty-foreground-inspection.ts Carries observed versus unverifiable foreground evidence while preserving the stable legacy process name.
src/main/providers/local-pty-process-evidence.ts Defines local title-read and child-process evidence classification without coercing failed reads into exit evidence.
src/main/providers/local-pty-provider.ts Adds provider-level process inspection that publishes foreground and child evidence alongside legacy fields.
tests/e2e/local-completion-evidence/local-inspection-unverifiable-completion.unit.test.ts Exercises the local inspection-to-completion path and verifies degraded observations do not trigger completion.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[LocalPtyProvider.inspectProcess] --> B[Observe foreground process]
  B --> C{Foreground scan available?}
  C -->|No| D[Foreground evidence: unverifiable]
  C -->|Yes| E[Foreground evidence: observed]
  D --> F[Read PTY title and classify children]
  E --> F
  F --> G{Title and scan provide positive exit evidence?}
  G -->|No| H[Children evidence: live or unverifiable]
  G -->|Yes| I[Children evidence: exited]
  H --> J[Completion monitor re-arms]
  I --> K[Completion monitor confirms exit]
Loading

Reviews (5): Last reviewed commit: "Merge commit '91f761a706a2a0c65b985ea290..." | Re-trigger Greptile

brennanb2025 added a commit that referenced this pull request Aug 29, 2026
`native-smoke (windows-latest)` fails ~4.5% of runs on
`preserves a multiline argument through the compiled remote launcher`
with "Test timed out in 15000ms" — on unrelated PRs, for reasons that
have nothing to do with them. Across 176 sampled attempts it is the only
red that job produced, and it hit seven different PRs in two days:
#16900, #16904, #16915, #16955 (twice), #16979, #17014, #17085.

The test is six process creations: powershell.exe forks csc.exe, then
the freshly compiled orca.exe forks node.exe, twice. Hosted Windows
runners periodically slow process creation down, and this test amplifies
that far harder than anything else in the job. Comparing the 80 attempts
where it ran under 3s against the 12 where it ran over 12s, its own
median goes 2198ms -> 15917ms (7.2x) while the same file's
powershell-only test moves 556 -> 686ms (1.2x), the cmd.exe and Git Bash
process tests in the neighbouring file move 1.4x, and the other 35 files
put together move 1.5x.

Measured across those 176 attempts: 1881ms to 35438ms, p50 4264ms,
correlation +0.881 with the job's total Vitest duration. 8 of 176 (4.5%)
exceeded the 15s cap; 2 of 176 (1.1%) also exceeded the shared 30s
testTimeout, so deleting the override and inheriting the config is not
enough on its own. 60s clears all 176 with 1.7x headroom on the worst.

This is slow, not hung. Every body here is synchronous spawnSync, so
Vitest cannot interrupt one — the timer fires only after the body
returns and the reported duration is real elapsed time. That is why a
failure reads `× ... 22464ms` under `Test timed out in 15000ms`. The
work finished; the stopwatch was short. Seven reruns at one identical
head measured 2053 / 4680 / 5551 / 8732 / 13506 / 14868 / 21937ms — the
last of those would have been red on code that had not changed.

The 15s came from #8897, which raised this test off Vitest's built-in 5s
default because the job then ran bare `pnpm vitest run`. #8909 landed
3h27m later and pointed the job at config/vitest.config.ts, which is the
real fix for that. The constant stayed behind and has been the binding
budget ever since.
brennanb2025 added a commit that referenced this pull request Aug 30, 2026
`native-smoke (windows-latest)` fails ~4.5% of runs on
`preserves a multiline argument through the compiled remote launcher`
with "Test timed out in 15000ms" — on unrelated PRs, for reasons that
have nothing to do with them. Across 176 sampled attempts it is the only
red that job produced, and it hit seven different PRs in two days:
#16900, #16904, #16915, #16955 (twice), #16979, #17014, #17085.

The test is six process creations: powershell.exe forks csc.exe, then
the freshly compiled orca.exe forks node.exe, twice. Hosted Windows
runners periodically slow process creation down, and this test amplifies
that far harder than anything else in the job. Comparing the 80 attempts
where it ran under 3s against the 12 where it ran over 12s, its own
median goes 2198ms -> 15917ms (7.2x) while the same file's
powershell-only test moves 556 -> 686ms (1.2x), the cmd.exe and Git Bash
process tests in the neighbouring file move 1.4x, and the other 35 files
put together move 1.5x.

Measured across those 176 attempts: 1881ms to 35438ms, p50 4264ms,
correlation +0.881 with the job's total Vitest duration. 8 of 176 (4.5%)
exceeded the 15s cap; 2 of 176 (1.1%) also exceeded the shared 30s
testTimeout, so deleting the override and inheriting the config is not
enough on its own. 60s clears all 176 with 1.7x headroom on the worst.

This is slow, not hung. Every body here is synchronous spawnSync, so
Vitest cannot interrupt one — the timer fires only after the body
returns and the reported duration is real elapsed time. That is why a
failure reads `× ... 22464ms` under `Test timed out in 15000ms`. The
work finished; the stopwatch was short. Seven reruns at one identical
head measured 2053 / 4680 / 5551 / 8732 / 13506 / 14868 / 21937ms — the
last of those would have been red on code that had not changed.

The 15s came from #8897, which raised this test off Vitest's built-in 5s
default because the job then ran bare `pnpm vitest run`. #8909 landed
3h27m later and pointed the job at config/vitest.config.ts, which is the
real fix for that. The constant stayed behind and has been the binding
budget ever since.
Merge Sim and others added 2 commits August 29, 2026 21:57
… observation onto the split modules

main (#17206) cut local-pty-provider.ts from 1584 to 194 lines, moving
getForegroundProcess into local-pty-foreground-inspection.ts. This branch had
rewritten that same method into an observing form, so neither merge side was
resolvable on its own.

Ported rather than resolved:

- local-pty-foreground-inspection.ts now exports observeLocalPtyForegroundProcess
  returning LocalForegroundObservation. getLocalPtyForegroundProcess stays as the
  collapsing wrapper, so every existing caller keeps the exact legacy value.
- inspectProcess moves onto LocalPtyProvider and consumes the observation, which
  keeps the evidence type in local-pty-process-evidence.ts and out of the
  inspection module's import cycle.

The verdict vocabulary crosses the new module boundary unchanged: foreground
reads answer observed / unverifiable, children answer live / unverifiable /
exited, and a degraded or thrown read stays unverifiable rather than collapsing
into an exit.
nwparker pushed a commit that referenced this pull request Aug 31, 2026
`native-smoke (windows-latest)` fails ~4.5% of runs on
`preserves a multiline argument through the compiled remote launcher`
with "Test timed out in 15000ms" — on unrelated PRs, for reasons that
have nothing to do with them. Across 176 sampled attempts it is the only
red that job produced, and it hit seven different PRs in two days:
#16900, #16904, #16915, #16955 (twice), #16979, #17014, #17085.

The test is six process creations: powershell.exe forks csc.exe, then
the freshly compiled orca.exe forks node.exe, twice. Hosted Windows
runners periodically slow process creation down, and this test amplifies
that far harder than anything else in the job. Comparing the 80 attempts
where it ran under 3s against the 12 where it ran over 12s, its own
median goes 2198ms -> 15917ms (7.2x) while the same file's
powershell-only test moves 556 -> 686ms (1.2x), the cmd.exe and Git Bash
process tests in the neighbouring file move 1.4x, and the other 35 files
put together move 1.5x.

Measured across those 176 attempts: 1881ms to 35438ms, p50 4264ms,
correlation +0.881 with the job's total Vitest duration. 8 of 176 (4.5%)
exceeded the 15s cap; 2 of 176 (1.1%) also exceeded the shared 30s
testTimeout, so deleting the override and inheriting the config is not
enough on its own. 60s clears all 176 with 1.7x headroom on the worst.

This is slow, not hung. Every body here is synchronous spawnSync, so
Vitest cannot interrupt one — the timer fires only after the body
returns and the reported duration is real elapsed time. That is why a
failure reads `× ... 22464ms` under `Test timed out in 15000ms`. The
work finished; the stopwatch was short. Seven reruns at one identical
head measured 2053 / 4680 / 5551 / 8732 / 13506 / 14868 / 21937ms — the
last of those would have been red on code that had not changed.

The 15s came from #8897, which raised this test off Vitest's built-in 5s
default because the job then ran bare `pnpm vitest run`. #8909 landed
3h27m later and pointed the job at config/vitest.config.ts, which is the
real fix for that. The constant stayed behind and has been the binding
budget ever since.
nwparker added a commit that referenced this pull request Aug 31, 2026
* fix(ssh): fence stale kills and retired pane replay

* fix(ssh): support cancellable interactive authentication

* fix(ssh): await remote catalog before snapshot adoption

* fix(pty): contain Windows ConPTY input failures

* fix(power): avoid redundant macOS display blocking

* perf(editor): narrow markdown override subscriptions

* fix(quick-open): close directory handles after reads

* refactor(linux): remove unused proc socket scanner

* fix(usage): apply flat Sonnet 4.6 pricing

* ci: prime Node next native test cache

* docs(skills): resolve snapshot cleanup data path

* fix(ssh): recover install locks after host reboot

* test(ssh): recognize boot-aware install locks

* test(ssh): prove previous-boot lock recovery live

* test(wire): pin pre-metadata release coverage

* fix(terminal): preserve remote tab ownership through recovery races

* test(runtime): fence replaced terminal handles in agent guard

* fix(ssh): preserve remote snapshot authority across polls

* fix(pty): contain late ConPTY output EPIPE

* test(pty): register Windows exit watcher before kill

* fix: close SSH and tab readiness race gaps

* fix(tabs): retain headless order and placeholder titles

* fix(build): avoid parallel electron-vite config race

* test(windows): avoid MSYS temp path rewriting

* test(windows): avoid killing exited PTY

* fix(pty): avoid late ConPTY input teardown race

* fix(terminal): sync reconnect error ownership after commit

* fix(runtime): use canonical worktree identity comparison

* test(ssh): assert complete cold-hydration baseline

* test(windows): invoke quoted retention fixture via PowerShell

* test(windows): read ConPTY grid through mode con

* fix(terminal): publish PTY replacements atomically

* fix(terminal): infer stale identity on reattach

* fix(terminal): fence stale pane PTY callbacks

* fix(terminal): fence stale pane binds after rebind

* fix(terminal): reject stale pane transport callbacks

* fix(terminal): fence mirrored reattach spawn callbacks

* fix(terminal): replace stale pane PTYs on remount

* fix(ci): size the Windows launcher-compile test budget from measurement

`native-smoke (windows-latest)` fails ~4.5% of runs on
`preserves a multiline argument through the compiled remote launcher`
with "Test timed out in 15000ms" — on unrelated PRs, for reasons that
have nothing to do with them. Across 176 sampled attempts it is the only
red that job produced, and it hit seven different PRs in two days:
#16900, #16904, #16915, #16955 (twice), #16979, #17014, #17085.

The test is six process creations: powershell.exe forks csc.exe, then
the freshly compiled orca.exe forks node.exe, twice. Hosted Windows
runners periodically slow process creation down, and this test amplifies
that far harder than anything else in the job. Comparing the 80 attempts
where it ran under 3s against the 12 where it ran over 12s, its own
median goes 2198ms -> 15917ms (7.2x) while the same file's
powershell-only test moves 556 -> 686ms (1.2x), the cmd.exe and Git Bash
process tests in the neighbouring file move 1.4x, and the other 35 files
put together move 1.5x.

Measured across those 176 attempts: 1881ms to 35438ms, p50 4264ms,
correlation +0.881 with the job's total Vitest duration. 8 of 176 (4.5%)
exceeded the 15s cap; 2 of 176 (1.1%) also exceeded the shared 30s
testTimeout, so deleting the override and inheriting the config is not
enough on its own. 60s clears all 176 with 1.7x headroom on the worst.

This is slow, not hung. Every body here is synchronous spawnSync, so
Vitest cannot interrupt one — the timer fires only after the body
returns and the reported duration is real elapsed time. That is why a
failure reads `× ... 22464ms` under `Test timed out in 15000ms`. The
work finished; the stopwatch was short. Seven reruns at one identical
head measured 2053 / 4680 / 5551 / 8732 / 13506 / 14868 / 21937ms — the
last of those would have been red on code that had not changed.

The 15s came from #8897, which raised this test off Vitest's built-in 5s
default because the job then ran bare `pnpm vitest run`. #8909 landed
3h27m later and pointed the job at config/vitest.config.ts, which is the
real fix for that. The constant stayed behind and has been the binding
budget ever since.

* fix(terminal): fence stale remount reattach ownership

* fix(terminal): reconcile mounted pane identity after replacement

* fix(terminal): fence stale reattach fallback ownership

* fix(terminal): fence deferred SSH reattach ownership

* fix(terminal): fence stale split pane ownership callbacks

* fix(terminal): keep stale spawns from consuming startup

---------

Co-authored-by: Brennan Benson <[email protected]>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
* fix(ssh): fence stale kills and retired pane replay

* fix(ssh): support cancellable interactive authentication

* fix(ssh): await remote catalog before snapshot adoption

* fix(pty): contain Windows ConPTY input failures

* fix(power): avoid redundant macOS display blocking

* perf(editor): narrow markdown override subscriptions

* fix(quick-open): close directory handles after reads

* refactor(linux): remove unused proc socket scanner

* fix(usage): apply flat Sonnet 4.6 pricing

* ci: prime Node next native test cache

* docs(skills): resolve snapshot cleanup data path

* fix(ssh): recover install locks after host reboot

* test(ssh): recognize boot-aware install locks

* test(ssh): prove previous-boot lock recovery live

* test(wire): pin pre-metadata release coverage

* fix(terminal): preserve remote tab ownership through recovery races

* test(runtime): fence replaced terminal handles in agent guard

* fix(ssh): preserve remote snapshot authority across polls

* fix(pty): contain late ConPTY output EPIPE

* test(pty): register Windows exit watcher before kill

* fix: close SSH and tab readiness race gaps

* fix(tabs): retain headless order and placeholder titles

* fix(build): avoid parallel electron-vite config race

* test(windows): avoid MSYS temp path rewriting

* test(windows): avoid killing exited PTY

* fix(pty): avoid late ConPTY input teardown race

* fix(terminal): sync reconnect error ownership after commit

* fix(runtime): use canonical worktree identity comparison

* test(ssh): assert complete cold-hydration baseline

* test(windows): invoke quoted retention fixture via PowerShell

* test(windows): read ConPTY grid through mode con

* fix(terminal): publish PTY replacements atomically

* fix(terminal): infer stale identity on reattach

* fix(terminal): fence stale pane PTY callbacks

* fix(terminal): fence stale pane binds after rebind

* fix(terminal): reject stale pane transport callbacks

* fix(terminal): fence mirrored reattach spawn callbacks

* fix(terminal): replace stale pane PTYs on remount

* fix(ci): size the Windows launcher-compile test budget from measurement

`native-smoke (windows-latest)` fails ~4.5% of runs on
`preserves a multiline argument through the compiled remote launcher`
with "Test timed out in 15000ms" — on unrelated PRs, for reasons that
have nothing to do with them. Across 176 sampled attempts it is the only
red that job produced, and it hit seven different PRs in two days:
stablyai#16900, stablyai#16904, stablyai#16915, stablyai#16955 (twice), stablyai#16979, stablyai#17014, stablyai#17085.

The test is six process creations: powershell.exe forks csc.exe, then
the freshly compiled orca.exe forks node.exe, twice. Hosted Windows
runners periodically slow process creation down, and this test amplifies
that far harder than anything else in the job. Comparing the 80 attempts
where it ran under 3s against the 12 where it ran over 12s, its own
median goes 2198ms -> 15917ms (7.2x) while the same file's
powershell-only test moves 556 -> 686ms (1.2x), the cmd.exe and Git Bash
process tests in the neighbouring file move 1.4x, and the other 35 files
put together move 1.5x.

Measured across those 176 attempts: 1881ms to 35438ms, p50 4264ms,
correlation +0.881 with the job's total Vitest duration. 8 of 176 (4.5%)
exceeded the 15s cap; 2 of 176 (1.1%) also exceeded the shared 30s
testTimeout, so deleting the override and inheriting the config is not
enough on its own. 60s clears all 176 with 1.7x headroom on the worst.

This is slow, not hung. Every body here is synchronous spawnSync, so
Vitest cannot interrupt one — the timer fires only after the body
returns and the reported duration is real elapsed time. That is why a
failure reads `× ... 22464ms` under `Test timed out in 15000ms`. The
work finished; the stopwatch was short. Seven reruns at one identical
head measured 2053 / 4680 / 5551 / 8732 / 13506 / 14868 / 21937ms — the
last of those would have been red on code that had not changed.

The 15s came from stablyai#8897, which raised this test off Vitest's built-in 5s
default because the job then ran bare `pnpm vitest run`. stablyai#8909 landed
3h27m later and pointed the job at config/vitest.config.ts, which is the
real fix for that. The constant stayed behind and has been the binding
budget ever since.

* fix(terminal): fence stale remount reattach ownership

* fix(terminal): reconcile mounted pane identity after replacement

* fix(terminal): fence stale reattach fallback ownership

* fix(terminal): fence deferred SSH reattach ownership

* fix(terminal): fence stale split pane ownership callbacks

* fix(terminal): keep stale spawns from consuming startup

---------

Co-authored-by: Brennan Benson <[email protected]>
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Closing as superseded: a merged PR already covers this change. Main local inspection returns childProcessEvidence 'unverifiable' on degraded or replaced reads (src/main/providers/local-pty-provider.ts:162,177) via #20756 (3ec6193). Base #16926 closed unmerged; relay files deleted by

(Stale-PR cleanup 2026-10-20, approved by Brennan. Reopen if something here is still missing on main.)

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