Skip to content

fix(relay): observe Windows PTY child processes instead of answering false - #18591

Merged
nwparker merged 3 commits into
mainfrom
nwparker/relay-windows-child-process-evidence
Sep 4, 2026
Merged

nwparker merged 3 commits into
mainfrom
nwparker/relay-windows-child-process-evidence

Conversation

@nwparker

@nwparker nwparker commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​453 $\color{#cf222e}{\Huge{\mathbf{−}}}$​9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​444
Prod 18 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​212 $\color{#cf222e}{\Huge{\mathbf{−}}}$​82 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​130

What

processHasChildren returned a hardcoded false on Windows. A hardcoded negative is
indistinguishable from a measurement, and every close guard reads it as "nothing is running in this
pane" — so an SSH-to-Windows tab running a build closed with no prompt.

Windows has no ps, but it has a process table, and the pane walk over it already existed for the
foreground reader (queryWindowsPaneProcessInventory). This wires that up, and reports
unverifiable only where the host genuinely could not look.

Measured, on a real Windows SSH host

awin (Windows 11 26200, OpenSSH 10.0p2, DefaultShell=cmd.exe), macOS client, live PING.EXE
running under the pane's cmd.exe. openclaw (Ubuntu) is the control, same harness.

Before:

awin      IDLE           getForegroundProcess="xterm-256color"  hasChildProcesses=false
awin      CHILD-RUNNING  getForegroundProcess="xterm-256color"  hasChildProcesses=false   <-- wrong
openclaw  IDLE           getForegroundProcess="/bin/bash"       hasChildProcesses=false
openclaw  CHILD-RUNNING  getForegroundProcess="sleep"           hasChildProcesses=true

The child was real, and a plain ppid walk finds it:

PID=23536 PPID=13052 NAME=PING.EXE  CL=ping -n 40 127.0.0.1
PID=13052 PPID=16312 NAME=cmd.exe   (16312 = the relay's node)

After, same host, same harness:

awin  IDLE           DECIDE  childProcessEvidence="no-children"    hasChildProcesses=false
awin  CHILD-RUNNING  DECIDE  childProcessEvidence="children"       hasChildProcesses=true
awin  CHILD-RUNNING  POLL    childProcessEvidence="unverifiable"   hasChildProcesses=false
awin  legacy pty.hasChildProcesses: false -> true

Linux control is byte-identical to before on both the boolean and the poll:

openclaw  IDLE           POLL/DECIDE  childProcessEvidence="no-children"  hasChildProcesses=false
openclaw  CHILD-RUNNING  POLL/DECIDE  childProcessEvidence="children"     hasChildProcesses=true

Why a new member rather than fixing the boolean's meaning

hasChildProcesses cannot hold the third answer, and it is read two incompatible ways:

  • running-terminal-close-guard.ts, use-terminal-pane-close-actions.ts — true means "busy, do
    not close"; the safe mapping for unverifiable is true.
  • agent-ready-wait.ts:105, agent-followup-delivery.ts:58 — true means "the agent has taken
    over the PTY, safe to type user text into it"; the safe mapping for unverifiable is false.

No single mapping is safe for both, so unverifiable keeps spelling itself false on the boolean
and the verdict moves to a new optional childProcessEvidence. Same shape as SshRemotePtyLeaseState
lacking an unverifiable member being root cause in #18006.

Cost

pty.inspectProcess is the polled path (750ms/2000ms per tracked pane). A relay host has no
@vscode/windows-process-tree, so its table read falls back to the CIM scan, self-documented at
windows-process-table-cim-scan.ts as 1.36s and 4.8MiB per scan against a 3s limit. Polling that
would reinstate the fork storm the shared table exists to prevent (#15209, #15036). So the scan is
opt-in: callers whose answer decides something once and destructively pass scanChildProcesses, and
a poll gets the honest unverifiable instead of a fabricated negative. This is the same poll/decide
split processHasChildren's own fresh option already documents.

On Windows the read deliberately ignores fresh: the CIM scan's own 1.36s runtime is longer than
the 500ms TTL a fresh read would refresh, so a "fresh" answer is not meaningfully fresher while N
sequential ones are an N x 1.36s stall.

Wire compatibility

Per docs/reference/remote-wire-compatibility.md:

  • Rule 1 (safe) — scanChildProcesses is a new optional request member. An older relay ignores
    it and answers as it always did, so a new client against an old host degrades to today's behavior.
  • Rule 1 (safe) — childProcessEvidence is a new optional response member. Old clients ignore
    it; inspectionReportsRunningWork falls back to the boolean when it is absent, so an old host
    decides exactly as it does today.
  • Rule 3 (stated deliberately) — the value of the existing hasChildProcesses boolean changes
    on Windows hosts, from unconditionally false to a real answer, and that reaches old clients with
    no wire change. This is the fix. The direction is safe for the close guards (they start prompting
    correctly). I checked the two consumers that read true as "safe to type": both are additionally
    gated on a foreground that Windows never satisfies (isAgentForegroundWrapperProcess /
    isExpectedAgentProcess against xterm-256color), so neither can be newly triggered by this.

No new stream opcode, so no capability negotiation is required.

Why inspectionReportsRunningWork disappeared in the rebase

Rebasing onto main landed probePtyRunningWork, which already speaks the live / unverifiable /
exited vocabulary and exists so the tab-close and window-close guards cannot drift. That is a
better home for this than the close guard, so the child-process verdict moved into it and the
helper this PR originally added was deleted rather than kept alongside it. One predicate, not
two. The pane-close path was a third caller asking the same question through its own direct
inspect, so it now goes through the same probe.

The seam, stated plainly because it is the part worth preserving: this makes the measurement
honest and leaves every caller's policy alone.
The tab-close guard still fails open on
unverifiable — that is main's deliberate choice ("a close button that silently does nothing is
worse than closing a busy tab"), not something this PR changes. All this does is stop a host that
could not look from being recorded as a host that looked and found nothing.

Not fixed here

foregroundProcess / listProcesses.title still report the TERM string xterm-256color on Windows
relays, because node-pty's WindowsTerminal.process getter returns opt.name || env.TERM and the
relay passes it through raw. The desktop already guards this literal in two places
(local-pty-launch-helpers.ts:81, daemon/pty-subprocess/foreground-fallback-process.ts:5); the
relay has no counterpart. Consequence: probeTerminalLiveness still reports every Windows SSH
terminal as running, so workspace cleanup stays inert there. Separate change — it alters agent
identity detection, which is a different blast radius from the close guards.

Revert-tested

Every new test was checked by deleting the fix it covers and confirming it fails:

revert failing tests
Windows branch back to return 'no-children' 3 of 4 in pty-shell-utils.test.ts; 3 of 4 in pty-handler-windows-child-process-evidence.test.ts
only the ESRCH discriminator (isProcessAlive -> always unverifiable) does not read a missing shell as unverifiable when the kernel says it is gone
inspectionReportsRunningWork back to boolean-only prompts when the host could not observe the pane, rather than reading it as idle

One pre-existing test encoded the defect and is replaced: spawns nothing on Windows, where the answer was always false.

Checks

pnpm tc clean. oxlint clean. check:code-quality:changed 0 findings. check:max-lines-ratchet
OK — pty-shell-utils.ts crossed 300 lines, so the child-process question was extracted to
pty-child-process-inspection.ts rather than suppressed. Full src/main suite: 3086 files / 31209
tests passed. src/relay + src/shared + terminal renderer suites: 636 files / 6125 tests passed.

@coderabbitai

coderabbitai Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

PTY inspection now accepts and forwards scanChildProcesses. Relay inspection reports children, no-children, or unverifiable evidence while retaining the legacy boolean. Runtime probes use this evidence to classify running work. Terminal close actions use the shared probe and update confirmation behavior. Tests cover option forwarding, relay process inspection, compatibility behavior, and close decisions.

Merge Risk: 🟡 Moderate · up to 346f2

If child-process inspection fails, closing a terminal pane can bypass confirmation despite active work. This should be corrected before merge.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 55.56% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 18 functions across 27 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely identifies the main change: Windows relay PTY child-process observation replaces the incorrect hardcoded false result.
Description check ✅ Passed The description provides a detailed explanation of the problem, implementation, rationale, compatibility impact, testing, platform coverage, and performance considerations. It does not include the req…
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.
  • 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/renderer/src/runtime/runtime-terminal-inspection.ts (1)

170-172: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Propagate scanChildProcesses through the environment inspection RPC.

guardRunningTerminalClose requests { scanChildProcesses: true }, but the environment path sends only expectedIncarnationId. The RPC schema and handler also drop this option before pty.inspectProcess. On Windows, the relay then returns childProcessEvidence: 'unverifiable', which inspectionReportsRunningWork treats as running work. An idle remote Windows pane can therefore show a close confirmation. Forward the option through the schema, handler, runtime method, and renderer payload.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: a0822d15-7fc0-4138-bed0-72c786920f03

📥 Commits

Reviewing files that changed from the base of the PR and between b378101 and baeb0a4.

📒 Files selected for processing (18)
  • src/main/ipc/pty/ipc/inspect.ts
  • src/main/providers/pty-process-inspection.ts
  • src/main/providers/ssh-pty-provider-rpc-operations.ts
  • src/main/providers/ssh-pty-provider.ts
  • src/preload/api/pty-api.ts
  • src/preload/api/pty-bridge-stream-and-serialization.ts
  • src/relay/pty-child-process-inspection.ts
  • src/relay/pty-handler-spawn-admission.test.ts
  • src/relay/pty-handler-test-harness.ts
  • src/relay/pty-handler-windows-child-process-evidence.test.ts
  • src/relay/pty-handler.ts
  • src/relay/pty-shell-utils.test.ts
  • src/relay/pty-shell-utils.ts
  • src/renderer/src/components/terminal-pane/use-terminal-pane-close-actions.ts
  • src/renderer/src/components/terminal/running-terminal-close-guard.test.ts
  • src/renderer/src/components/terminal/running-terminal-close-guard.ts
  • src/renderer/src/runtime/runtime-terminal-inspection.ts
  • src/shared/terminal-process-inspection.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.

Important

The Boolean-flip safety argument in the PR description is correct for agent-followup-delivery.ts but does not hold for agent-ready-wait.ts: that consumer's child-process readiness branch is gated on !isShellProcess(foreground), and xterm-256color is not a shell, so the gate is open on Windows.

Reviewed changes

  • New PtyChildProcessVerdict — 'children' | 'no-children' | 'unverifiable' carried on a new optional childProcessEvidence response member, with hasChildProcesses preserved as childProcessEvidence === 'children'.
  • scanChildProcesses opt-in — the polled inspectProcess path returns honest unverifiable on Windows instead of fabricating false; close/cleanup callers pass scanChildProcesses: true to pay for the CIM-backed table read.
  • inspectPtyChildProcesses / processHasChildren extracted to src/relay/pty-child-process-inspection.ts, wiring queryWindowsPaneProcessInventory for Windows and the shared TTL snapshot for POSIX.
  • Close guards (running-terminal-close-guard.ts, use-terminal-pane-close-actions.ts) now request the scan and read via inspectionReportsRunningWork, which maps unverifiable to "prompt".

⚠️ agent-ready-wait.ts is not actually protected by the foreground gate the PR claims

The PR description states both "safe to type" consumers are "additionally gated on a foreground that Windows never satisfies (isAgentForegroundWrapperProcess / isExpectedAgentProcess against xterm-256color)". That is true for agent-followup-delivery.ts (its branch requires isAgentForegroundWrapperProcess(foreground), which is false for xterm-256color), but not for agent-ready-wait.ts.

waitForAgentReady has two separate hasChildProcesses-free and hasChildProcesses-consuming branches:

  • agent-ready-wait.ts:96 (foreground-match) is gated on isExpectedAgentProcess(foreground, …) — genuinely protected.
  • agent-ready-wait.ts:104-107 (child-process) is gated on !isShellProcess(foreground) — not protected. isShellProcess (shell-process-detection.ts:4) does not classify xterm-256color as a shell, so on a Windows relay — where foregroundProcess is always the TERM string xterm-256color — !isShellProcess is true and the branch is open.

Consequently, now that hasChildProcesses flips from hardcoded false to a real true on Windows, waitForAgentReady can return ready: true, reason: 'child-process' on a Windows SSH host whenever any non-shell child is running — git, ls, a build — not just the launched agent. That is precisely the "weakest signal" this branch documents itself as avoiding on POSIX (where foreground stays the shell until the agent takes over, so the gate blocks). On Windows the gate never blocks. The agent-paste-draft.ts fallback (agent-paste-draft.ts:119-120) reaches this path when the bracketed-paste readiness sequence never arrives, so drafts can be pasted into a pane whose agent has not yet taken over.

Technical details
# agent-ready-wait child-process branch is unguarded on Windows relays

## Affected sites
- src/renderer/src/lib/agent-ready-wait.ts:104-107 — `child-process` readiness reason gated only on `!isShellProcess(foreground)`; `isShellProcess('xterm-256color')` is `false`.
- src/shared/shell-process-detection.ts:4-23 — `SHELL_NAMES` omits the TERM string Windows relays publish as `foregroundProcess`.
- src/renderer/src/lib/agent-paste-draft.ts:119-120 — fallback that consumes the premature `ready` result.
- src/relay/pty-handler.ts:2741 — the boolean this PR makes `true` on Windows.

## Required outcome
- Either gate the `child-process` reason against the Windows TERM string (so a bare `xterm-256color` foreground cannot satisfy readiness), or confirm with evidence that `waitForAgentReady` is unreachable on Windows relays and document that boundary. The PR description's stated rationale must match the actual gate.

## Open questions for the human
- Does agent launch on a Windows SSH relay actually reach `agent-paste-draft.ts`'s `waitForAgentReady` fallback today? If yes, is the desired Windows behavior "paste once any child is running" (in which case document it as intentional, not as gated)?

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

@nwparker

nwparker commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Thanks — the outside-diff-range finding on runtime-terminal-inspection.ts:170-172 is correct and is fixed in 81b40ca.

scanChildProcesses now goes through all four layers: renderer payload → TerminalInspectProcess schema → method handler → inspectTerminalProcess / RuntimePtyController signatures. The schema is a dedicated TerminalHandle.extend(...) rather than a field on TerminalHandle itself, so clearBuffer / agentStatus / isRunningAgent keep refusing an option they have no use for.

Two refinements to the diagnosis, both of which changed how I tested it.

The silent strip is not the bug. Zod stripping undeclared keys is what makes "a new optional member is safe to send to an old host" true, which docs/reference/remote-wire-compatibility.md depends on. Making the schema .strict() would turn graceful degradation into an error. The actual defect is narrower: the schema and its own caller drifted inside one version. So the tests pin the registered method, not the schema — terminal-inspect-process-params.test.ts resolves terminal.inspectProcess out of TERMINAL_QUERY_METHODS, parses through its real params, and calls its real handler. Pointing the method back at TerminalHandle compiles, parses, and drops the option; only that test sees it.

The reachable blast radius is narrower than "an idle remote Windows pane." LocalPtyProvider has no inspectProcess at all, so an environment host serving local Windows panes takes the getForegroundProcess + hasChildProcesses fallback and never emits childProcessEvidence — inspectionReportsRunningWork then falls back to the boolean, i.e. unchanged behavior. The unverifiable you describe requires the environment host to route that pane through an SSH relay (the nested runtime-over-SSH case). Still a real defect and still worth fixing; I mention it because it is why I could not reproduce it end-to-end on hardware, and I would rather say that than imply I had.

Revert-tested per layer (delete the fix, confirm the test fails):

revert fails
renderer forward removed forwards scanChildProcesses to the PTY owning environment, …alongside the incarnation fence
method params back to TerminalHandle carries scanChildProcesses from the wire into the runtime call, …alongside the incarnation fence
handler spread removed same two
runtime/controller signatures pnpm tc

Verified on real hardware — the user-visible contract this PR exists for, on a Windows SSH host (awin, Windows 11 26200, DefaultShell=cmd.exe) with a Linux control, driving the actual inspectionReportsRunningWork predicate against real relay payloads:

[awin]      IDLE evidence="no-children" hasChildProcesses=false -> CLOSES SILENTLY
[awin]      BUSY evidence="children"    hasChildProcesses=true  -> PROMPTS
[openclaw]  IDLE evidence="no-children" hasChildProcesses=false -> CLOSES SILENTLY
[openclaw]  BUSY evidence="children"    hasChildProcesses=true  -> PROMPTS

BUSY is a live PING.EXE under the pane's cmd.exe, which before this PR reported hasChildProcesses: false.

pnpm tc, oxlint, and check:code-quality:changed (0 findings) are clean; 4518 test files / 45523 tests pass across src/main, src/relay, src/shared, and the touched renderer trees.

I also audited every terminal.* runtime RPC for keys the renderer sends that the schema does not declare — none. That check does not cover this bug's class (an option dropped before it becomes a payload key at all), so it is not evidence that the path is clear; for that I checked runtime-terminal-inspection.ts by hand. inspectRuntimeTerminalProcess was its only dual-path function carrying an options object; the two send helpers take no options, and confirmRuntimeTerminalForegroundProcess returns null on the environment path deliberately and documents why.

…false

`processHasChildren` returned a hardcoded `false` on Windows, and a hardcoded
negative is indistinguishable from a measurement. Every close guard reads it as
"nothing is running in this pane", so an SSH-to-Windows tab running a build
closed with no prompt. Measured on a real Windows SSH host: a live `PING.EXE`
under the pane's `cmd.exe` still reported `hasChildProcesses: false`, while the
identical harness on Linux reported `sleep` / `true`.

Windows has no `ps`, but it does have a process table, and the pane walk over it
already existed for the foreground reader. The answer now comes from
`queryWindowsPaneProcessInventory`; a table it could not read reports
`unverifiable` rather than a fabricated negative.

`hasChildProcesses` is a boolean, which cannot hold the third answer, and it is
read both as "busy, do not close" and as "the agent took the PTY, safe to type
into" — so no single mapping of `unverifiable` is safe for both. The verdict
moves to a new optional `childProcessEvidence` member that the close paths read;
the boolean keeps its exact meaning for every client that cannot.

Cost: `pty.inspectProcess` is the polled path and a relay host has no
`@vscode/windows-process-tree`, so its table read falls back to the 1.36s CIM
scan. Polling that would reinstate the fork storm the shared table exists to
prevent, so only a caller whose answer decides something asks for the scan.
…ection RPC

`guardRunningTerminalClose` asks the host to pay for a real child-process read,
but the environment path dropped the option before it reached the wire: the
renderer sent only `expectedIncarnationId`, and the RPC schema — the shared
`TerminalHandle` — silently stripped anything else. A host routing that pane
through an SSH relay then declined to scan and answered `unverifiable`, which
`inspectionReportsRunningWork` reads as running work. The result was a close
confirmation on an idle pane, which is the nag this PR exists to avoid.

Forwarded through all four layers: renderer payload, RPC schema, method handler,
and the runtime/controller signatures. The schema is a dedicated extension rather
than a field on `TerminalHandle`, so `clearBuffer`/`agentStatus`/`isRunningAgent`
keep refusing an option they have no use for.

The silent strip is not itself the defect — it is what makes a new optional member
safe to send to an old host, per docs/reference/remote-wire-compatibility.md. The
defect was the schema and its caller drifting inside one version, so the tests pin
the registered method rather than the schema alone: pointing it back at
`TerminalHandle` compiles, parses, and drops the option.

Found by review on #18591.
…ocess answer

Rebasing onto main landed `probePtyRunningWork`, which is a better home for this
than the close guard: it already speaks `live` / `unverifiable` / `exited`, and it
exists so the tab-close and window-close guards cannot drift. The child-process
verdict belongs there, not in a parallel predicate beside it.

So the mapping moves into the probe and `inspectionReportsRunningWork` is deleted
rather than kept alongside. The probe now asks for the scan, and a host that could
not observe the pane reports `unverifiable` instead of collapsing onto `exited` --
which is what `hasChildProcesses: false` meant on every Windows relay.

The pane-close path is routed through the same probe for the same reason; it was
the third caller asking this question through a direct inspect of its own.
@nwparker
nwparker force-pushed the nwparker/relay-windows-child-process-evidence branch from 39effba to 346f279 Compare September 4, 2026 08:29

@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

  • Forwarded scanChildProcesses through the environment inspection RPC — inspectRuntimeTerminalProcess now includes the flag in the terminal.inspectProcess RPC params; a new TerminalInspectProcess schema (extending TerminalHandle) declares it, and the handler rebuilds the options object so the option survives to runtime.inspectTerminalProcess.
  • Widened the runtime controller contract — RuntimePtyController.inspectProcess and the runtime inspectTerminalProcess method now carry scanChildProcesses, completing the renderer → runtime → provider → relay chain for remote environment panes.
  • Added regression tests — a new terminal-inspect-process-params.test.ts pins the registered schema/handler (so a schema swap back to TerminalHandle can't silently strip the option), plus renderer forwarding tests for the flag alone, alongside the incarnation fence, and its omission on a bare poll.

Prior agent-ready-wait concern re-examined — it does not fire on Windows. waitForAgentReady and agent-followup-delivery both call inspectRuntimeTerminalProcess without scanChildProcesses, so a Windows relay answers unverifiable and the compatibility boolean stays false (pty-handler.ts maps unverifiable → false). The child-process / wrapper branches therefore cannot newly trigger. The close guards — the only callers passing scanChildProcesses: true — read true as "busy, do not close", which is the intended safe mapping. The poll/decide split makes the boolean flip safe for both reader directions.

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

@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: a2e68f55-b95d-4816-aed2-13671baeb42a

📥 Commits

Reviewing files that changed from the base of the PR and between 81b40ca4c0df5785a59f7af89dfe8778eec7d614 and 346f279.

📒 Files selected for processing (6)
  • src/renderer/src/components/terminal-pane/use-terminal-pane-close-actions.ts
  • src/renderer/src/components/terminal/pty-running-work-probe-child-evidence.test.ts
  • src/renderer/src/components/terminal/pty-running-work-probe.ts
  • src/renderer/src/components/terminal/running-terminal-close-guard.test.ts
  • src/renderer/src/components/terminal/terminal-close-confirm-keyboard-vs-mouse.test.ts
  • src/shared/terminal-process-inspection.ts

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

decide(() => {
if (
!process.hasChildProcesses ||
probes[0]?.verdict !== 'live' ||

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.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Do not close an unverifiable pane without confirmation.

'unverifiable' !== 'live' is true. A failed host observation therefore calls executeClosePane without prompting. This can close a pane that still has running work.

Close without confirmation only when the verdict is exited. Preserve the explicit skip setting.

Proposed fix
-              probes[0]?.verdict !== 'live' ||
+              probes[0]?.verdict === 'exited' ||
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
probes[0]?.verdict !== 'live' ||
probes[0]?.verdict === 'exited' ||

@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.

Important

The close guards now silently close a pane the host could not observe, regressing the fail-safe the PR documents.

Reviewed changes

  • Consolidated the "is work running" decision into probePtyRunningWork — the probe now passes scanChildProcesses: true and maps childProcessEvidence: 'unverifiable' to a distinct unverifiable verdict with reason host_child_processes_unobserved, instead of collapsing it into the boolean.
  • Routed the pane close path through the shared probe (use-terminal-pane-close-actions.ts), and deleted inspectionReportsRunningWork from src/shared/terminal-process-inspection.ts.
  • Added probe-level tests and updated the keyboard-vs-mouse source assertion to probePtyRunningWork.

⚠️ Close guards now close on host_child_processes_unobserved instead of prompting

The PR body states that for running-terminal-close-guard.ts and use-terminal-pane-close-actions.ts, the safe mapping of unverifiable is "busy, do not close". inspectionReportsRunningWork implemented exactly that: client-only unverifiable → false (fail open on transport loss), host-side unverifiable → true (prompt). This commit deletes inspectionReportsRunningWork and replaces both consumers with a verdict === 'live' filter that treats an answered unverifiable identically to exited — closing without a prompt.

On a Windows SSH relay whose CIM process-table read fails but whose shell is still alive, childProcessEvidence is unverifiable, so a pane running a build now closes with no confirmation. That is the exact hazard the three-valued verdict was introduced to prevent, and the guard-level test that pinned the old behavior (prompts when the host could not observe the pane, rather than reading it as idle) was removed in this commit, replaced by probe tests that assert only the verdict mapping, not the close decision.

The timedOut branch does not cover this: timedOut is only set when the probe's deadline fires before the host answers, whereas host_child_processes_unobserved is an answered verdict.

Technical details
# Close guards must prompt on host-side unverifiable

## Affected sites
- `src/renderer/src/components/terminal-pane/use-terminal-pane-close-actions.ts:109` — `probes[0]?.verdict !== 'live'` closes on `unverifiable` too.
- `src/renderer/src/components/terminal/running-terminal-close-guard.ts:129` — `probe.verdict === 'live'` filter drops `unverifiable` from `busyPtyIds`, so `busyPtyIds.length === 0` → `closeNow()`.
- `src/renderer/src/components/terminal/pty-running-work-probe.ts:72-76` — correctly emits `verdict: 'unverifiable'`, reason `host_child_processes_unobserved`; the probe is not the defect, its consumers are.

## Required outcome
- A close decision where the host answered `childProcessEvidence: 'unverifiable'` (i.e. `verdict === 'unverifiable'` with `reason === 'host_child_processes_unobserved'`) must prompt, not close.
- A client-only `unverifiable` (transport loss, `old_host`, `terminal_gone`) may still fail open (close), matching the pre-existing #10142 rationale.

## Suggested approach (optional)
- In both consumers, distinguish the two unverifiable kinds by `reason === 'host_child_processes_unobserved'` (or, in `window-close-running-work.ts`'s style, `probe.remote && probe.verdict === 'unverifiable'`) and treat that as busy, while keeping client-only unverifiable as fail-open.

## Open questions for the human (optional)
- Should the guard mirror `window-close-running-work.ts`'s remote/local asymmetry, or prompt on any answered host-side unverifiable regardless of `probe.remote`?

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

decide(() => {
if (
!process.hasChildProcesses ||
probes[0]?.verdict !== 'live' ||

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.

probes[0]?.verdict !== 'live' closes on unverifiable as well as exited. On a Windows SSH relay whose CIM process-table read fails but whose shell is alive, childProcessEvidence is unverifiable, so this silently closes a pane that may be running a build — the exact fail-safe the PR documents for close guards. Treat verdict === 'unverifiable' (reason host_child_processes_unobserved) as busy/prompt, while keeping client-only unverifiable as fail-open. The tab guard (running-terminal-close-guard.ts:129) has the same verdict === 'live' filter.

@nwparker
nwparker merged commit 637dc30 into main Sep 4, 2026
29 of 31 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…false (stablyai#18591)

* fix(relay): observe Windows PTY child processes instead of answering false

`processHasChildren` returned a hardcoded `false` on Windows, and a hardcoded
negative is indistinguishable from a measurement. Every close guard reads it as
"nothing is running in this pane", so an SSH-to-Windows tab running a build
closed with no prompt. Measured on a real Windows SSH host: a live `PING.EXE`
under the pane's `cmd.exe` still reported `hasChildProcesses: false`, while the
identical harness on Linux reported `sleep` / `true`.

Windows has no `ps`, but it does have a process table, and the pane walk over it
already existed for the foreground reader. The answer now comes from
`queryWindowsPaneProcessInventory`; a table it could not read reports
`unverifiable` rather than a fabricated negative.

`hasChildProcesses` is a boolean, which cannot hold the third answer, and it is
read both as "busy, do not close" and as "the agent took the PTY, safe to type
into" — so no single mapping of `unverifiable` is safe for both. The verdict
moves to a new optional `childProcessEvidence` member that the close paths read;
the boolean keeps its exact meaning for every client that cannot.

Cost: `pty.inspectProcess` is the polled path and a relay host has no
`@vscode/windows-process-tree`, so its table read falls back to the 1.36s CIM
scan. Polling that would reinstate the fork storm the shared table exists to
prevent, so only a caller whose answer decides something asks for the scan.

* fix(runtime): forward scanChildProcesses through the environment inspection RPC

`guardRunningTerminalClose` asks the host to pay for a real child-process read,
but the environment path dropped the option before it reached the wire: the
renderer sent only `expectedIncarnationId`, and the RPC schema — the shared
`TerminalHandle` — silently stripped anything else. A host routing that pane
through an SSH relay then declined to scan and answered `unverifiable`, which
`inspectionReportsRunningWork` reads as running work. The result was a close
confirmation on an idle pane, which is the nag this PR exists to avoid.

Forwarded through all four layers: renderer payload, RPC schema, method handler,
and the runtime/controller signatures. The schema is a dedicated extension rather
than a field on `TerminalHandle`, so `clearBuffer`/`agentStatus`/`isRunningAgent`
keep refusing an option they have no use for.

The silent strip is not itself the defect — it is what makes a new optional member
safe to send to an old host, per docs/reference/remote-wire-compatibility.md. The
defect was the schema and its caller drifting inside one version, so the tests pin
the registered method rather than the schema alone: pointing it back at
`TerminalHandle` compiles, parses, and drops the option.

Found by review on stablyai#18591.

* fix(terminal): teach the shared running-work probe the third child-process answer

Rebasing onto main landed `probePtyRunningWork`, which is a better home for this
than the close guard: it already speaks `live` / `unverifiable` / `exited`, and it
exists so the tab-close and window-close guards cannot drift. The child-process
verdict belongs there, not in a parallel predicate beside it.

So the mapping moves into the probe and `inspectionReportsRunningWork` is deleted
rather than kept alongside. The probe now asks for the scan, and a host that could
not observe the pane reports `unverifiable` instead of collapsing onto `exited` --
which is what `hasChildProcesses: false` meant on every Windows relay.

The pane-close path is routed through the same probe for the same reason; it was
the third caller asking this question through a direct inspect of its own.
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