Skip to content

fix(cleanup): stop reading an unreachable terminal as an idle one - #17024

Open
brennanb2025 wants to merge 18 commits into
brennanb2025/coercion-daemon-inspect-r2from
brennanb2025/probe-liveness-coercion-r1
Open

brennanb2025 wants to merge 18 commits into
brennanb2025/coercion-daemon-inspect-r2from
brennanb2025/probe-liveness-coercion-r1

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​988 $\color{#cf222e}{\Huge{\mathbf{−}}}$​84 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​904
Prod 8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​181 $\color{#cf222e}{\Huge{\mathbf{−}}}$​80 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​101

Merge order: this PR lands after #16926 → #16955 → #17003

It is stacked on brennanb2025/coercion-daemon-inspect-r2 (#17003), and it cannot land before
that stack. pnpm tc says so out loud: the fix reads the host's processEvidence through
readPtyProcessInspectionEvidence, and src/shared/pty-process-inspection-evidence.ts does not
exist on main yet — it arrives with #16926. Building main + this PR fails to typecheck with
TS2307 in two production files, not just tests.

There is also a merge conflict waiting in runtime-terminal-inspection.ts, and one resolution
of it is silently destructive.
This PR moves RuntimeTerminalProcessInspection into the new leaf
module runtime-terminal-process-inspection.ts; #16955 adds a processEvidence field to that same
type in the old file. Resolving as "keep the moved type — the field was in the file that went away"
drops the field. The cost is not theoretical: without processEvidence, a terminal whose
liveness probe failed reads as an idle shell and becomes eligible for deletion. Carry
processEvidence across into the leaf module.
Two tests fail if you don't —
runtime-terminal-process-inspection-evidence-contract.test.ts (typecheck at a named site, and a
behaviour differential that names the cost) and #16955's
runtime-terminal-inspection-evidence-passthrough.test.ts.

ELI5

Before deleting an old workspace, Orca asks each of its terminals "is anything
running in you?" It asked that question through two channels that quietly turn
"I couldn't reach the host" into "no, nothing is running." So an agent that was
still working showed up as an idle, unblocked row — with no warning on the
confirmation screen.

This PR asks through the one channel that can say "I don't know," and treats
"I don't know" as a reason not to clean up.

User-facing before / after

Before: if the SSH host for a workspace's terminals was disconnected, or the
local terminal daemon's socket was dead, workspace cleanup read every terminal in
that workspace as an idle shell. The row lost its Running terminal process /
Terminal liveness unknown blocker entirely, applyWorkspaceCleanupPolicy
classified it ready / selectedByDefault, and the final confirm-remove screen
showed it as clean. Workspace cleanup could proceed against a worktree whose
agent was still running, and the user got no warning at all.

After: a read that cannot observe the process yields unverifiable, the row
keeps the Terminal liveness unknown blocker, and it is classified
protected / not selected by default. Unknown falls toward "do not clean up."

Where the coercion is

probeTerminalLiveness read two standalone RPCs whose degraded answers are
flattened below the IPC boundary, so nothing reached the caller to reject:

Degraded condition Coerced at Answer that reached the renderer
SSH provider not registered (host disconnected) src/main/ipc/pty/ipc/inspect.ts:139-141, :149-151 (hasPtyProviderForInspection false → return false / return null; src/main/ipc/pty/provider/registry.ts:49-50 states the intent as "should read as idle") false / null
Daemon-backed PTY, dead socket src/main/daemon/daemon-pty-process-inspection.ts:58-59 swallows the request and returns null; :22 derives hasChildProcesses from that null false / null
remote: runtime PTY id neither handler guards the remote: prefix (pty:hasPty at :112-119 and pty:inspectProcess at :157-165 both do), so the id falls through to the local provider, which has never heard of it false / null

In every one of those, probeTerminalLiveness fell into
!hasChildProcesses && !processName → continue and returned idle.

pty:inspectProcess already carries the evidence: the same conditions produce
{ unavailable: true } (inspect.ts:164,
src/main/providers/pty-process-inspection.ts:36-38) or a rejection. The daemon
adapter even documents the distinction at
daemon-pty-process-inspection.ts:32-33 — its inspectProcess deliberately
requests directly "so a dead socket still rejects rather than reading as an idle
foreground." The cleanup probe was the caller that never got the message.

The fix reads inspectProcess (via the existing inspectRuntimeTerminalProcess,
which also routes remote: panes to their owning runtime) and adds the
unavailable arm. It is also one IPC round trip per PTY instead of two.

Failing-first proof

Re-measured at head 2c68f20d6d. The two store files this PR changes are put back
to their pre-change source (570cb71cbb^) and the current tests are run against
them:

$ git checkout 570cb71cbb^ -- \
    src/renderer/src/store/slices/workspace-cleanup-local-evidence.ts \
    src/renderer/src/store/slices/workspace-cleanup-candidate-enrichment.ts
$ npx vitest run --config config/vitest.config.ts \
    src/renderer/src/store/slices/workspace-cleanup-terminal-liveness-coercion.test.ts

 Tests  9 failed | 4 passed (13)

Across all three guard files (28 tests): 18 failed | 10 passed. After the fix,
28 passed (28).

The 10 that pass on both are the preservation cases — idle shell still removable, live
agent still blocked, no-PTY workspace still removable, an observed-idle host still
offered to select-all — and they are there to stop the fix from becoming "always
unverifiable." They are pinned by ablation, not by failing first; the table below is
where they earn their place.

The test models a swallowing boundary, not a throwing controller: the double
resolves hasChildProcesses to false and getForegroundProcess to null —
exactly what main returns for a degraded read — while only inspectProcess
carries unavailable or rejects.

Ablation table

The per-hunk table this section used to carry was measured on the round-1..3 tree and
its numbers no longer describe head. It has been folded into the single re-measured
table below (Ablation — every gate, re-measured), which supersedes it. One row from
it survives because it is about module shape rather than a verdict, and it was
re-measured at head:

Hunk Ablation Result at 2c68f20d6d
inspection read lives in a store-free leaf module import inspectRuntimeTerminalProcess from @/runtime/runtime-terminal-inspection again 139 of 294 test files in src/renderer/src/store/slices/ fail to load — createWorkspaceCleanupSlice is not a function, the store↔runtime import cycle

That one is found by running the parent suite, not the guard files.

Test-double updates (not weakened assertions)

Three existing suites stubbed only the two coerced RPCs — a double that omits a
real field. They were retargeted at inspectProcess (the probe), keeping their
counts and semantics:

  • workspace-cleanup-scan-progress.test.ts — probe-count / ordering contracts
  • workspace-cleanup-enrichment-performance.test.ts — concurrency-peak contracts
  • workspace-cleanup-removal-preflight.test.ts — the two "agent still
    foregrounded" protections; their doubles now also answer inspectProcess

The new test additionally asserts hasChildProcesses and getForegroundProcess
are called zero times, so a regression back to the coerced pair is caught.

Round 4: the same defect, one layer up

Rounds 1-3 fixed the renderer composition. Round 4 found that on the composed tree
(#16926 → #16955 → #17003 + this PR) a degraded local probe still reached select-all as idle,
with an empty blockers array.

probeTerminalLiveness read only inspection.unavailable. But unavailable is set only for a
handle we could not route to — terminal_gone, a remote: id, an unregistered provider. A host that
did answer but whose probes failed publishes the stack's deliberate legacy collapse:
foregroundProcess = the provider's stable-cache value (for a pane that never ran an agent, the
shell name) and hasChildProcesses: false, with the real verdict in the new optional
processEvidence. That legacy half is byte-identical to an idle shell.

The collapse is not a bug in the stack — it is its stated wire contract
(buildPtyProcessInspectionWireResult: legacy fields "reproduce the pre-evidence behavior exactly
… so clients that predate processEvidence observe unchanged host content"). This PR was the client
that predated it. The one path where a wrong answer deletes a workspace was the last renderer
consumer still reading only the legacy fields.

Pre-fix, on the composed tree, the four round-4 cases fail:

FAIL … > reports unverifiable for a degraded local probe that looks like an idle shell
  AssertionError: expected 'idle' to be 'unverifiable'
FAIL … > withholds a degraded local probe from select-all
  AssertionError: expected [] to include 'terminal-liveness-unknown'
FAIL … > reports unverifiable for a relay host whose probes timed out
FAIL … > reports unverifiable when only the child probe failed

They are the four the round-4 gate reddens on its own (G4 below). After: Tests 28 passed (28) across the three guard files.

probeTerminalLiveness now routes the answer through readPtyProcessInspectionEvidence.
Old hosts keep their old meaning — the reader falls back to
{ foreground: observed(legacy), children: hasChildProcesses ? live : exited } when the field is
absent, so a pre-evidence daemon or relay reads exactly as before.

Every consumer of the blocker, checked separately

Rounds 2 and 3 each shipped a correct verdict that no consumer acted on, so each is now read on its
own through the reader the dialog really calls. Nothing asserts on tier / selectedByDefault.

Consumer Real reader exercised Withholds?
Bulk default (select-all) queryWorkspaceCleanupCandidates(...).selectableIdentities — the list toggleSelectAll writes into selectedIds verbatim Yes. [] for the unverifiable row, [identity] for an observed-idle one.
Remove button selectableIdentities ∩ canQueueWorkspaceCleanupCandidate — what selectedCandidates reduces to, and what deleteDisabled: selectedCount === 0 gates on Yes, transitively: nothing is selected after select-all, so the button is disabled.
Confirm screen status pill WorkspaceCleanupConfirmRemove rendered into a DOM, asserting on textContent Yes. The screen that authorizes the delete reads Terminal liveness unknown.

One deliberate escape hatch, stated plainly: terminal-liveness-unknown is not in
WORKSPACE_CLEANUP_QUEUE_BLOCKERS, so a row the user ticks by hand still removes. That is the
round-3 decision — withhold the bulk default without making an unverifiable workspace undeletable —
and the disclosure is real (the pill appears in the list and on the confirm screen), so it is an
informed per-row choice rather than a silent coercion. Making it a hard block is a one-line change
if that is preferred.

Round 5: a host that publishes no evidence cannot prove idle

Round 4 read processEvidence when the host published it. A host that publishes none
was read back through the reader's legacy fallback, which restates its two values as an
observation. A retained pre-v27 daemon publishes zsh + false both when the pane really
sits at an idle shell and when its foreground read fell back to the shell title, and it has
no field to tell the two apart. So on this path — the one that deletes a workspace — an
unpublished reading is unverifiable. Believing such a host when it reports live work is
still fine: that can only add a blocker.

The confirm-time preflight learned the same thing: terminal-liveness-unknown joins the
reconfirm blockers, so a row confirmed while its terminal read idle is not deleted on consent
the user gave against evidence the preflight no longer has.

Ablation — every gate, re-measured at 2c68f20d6d

Three guard files, 28 tests, all green at head:
workspace-cleanup-terminal-liveness-coercion.test.ts (13),
workspace-cleanup-legacy-host-liveness-evidence.test.ts (8),
workspace-cleanup-unverifiable-terminal-withholding.test.tsx (7).
Each gate reverted on its own, the tree restored between runs.

# Gate Reverted alone →
G1 terminal-liveness-unknown in WORKSPACE_CLEANUP_BULK_SELECT_EXCLUSIONS 6 failed / 22 passed
G2 probeTerminalLiveness reads inspectRuntimeTerminalProcess (restore the Promise.all([hasChildProcesses, getForegroundProcess]) pair) 11 failed / 17 passed
G3 the inspection.unavailable === true → unverifiable arm 0 failed / 28 passed. Reddens nothing alone — see below
G4 the processEvidence read (round 4), replaced by the legacy interpretation 7 failed / 21 passed
G5 enrichment pushes terminal-liveness-unknown on 'unverifiable' 8 failed / 20 passed
G6 the unpublished-evidence distrust arm (round 5): !hasPublishedPtyProcessInspectionEvidence(inspection) && children.verdict !== 'live' 4 failed / 24 passed
G7 terminal-liveness-unknown in the preflight's WORKSPACE_CLEANUP_RECONFIRM_BLOCKERS 1 failed / 27 passed
G8 processEvidence declared on RuntimeTerminalProcessInspection npx tsc -p config/tsconfig.tc.web.json --noEmit → 18 errors, incl. TS2339 at runtime-terminal-process-inspection-evidence-contract.test.ts:29

G3 reddens nothing on its own, and stays anyway

Deleting the unavailable arm leaves the three guard files at 28/28 green, and also
leaves 4241 tests across 469 files green (src/renderer/src/store/slices/ +
src/renderer/src/components/workspace-cleanup/ + src/renderer/src/runtime/). This
table used to claim 2 failed for it. That number was measured before the round-5 gate
existed; it is withdrawn.

It is not dead code — it is subsumed by G6, one gate later:

  • Every producer of unavailable: true publishes no processEvidence —
    src/main/ipc/pty/ipc/inspect.ts:164, src/main/providers/pty-process-inspection.ts:41,
    src/renderer/src/runtime/runtime-terminal-process-inspection.ts:62, and
    src/main/daemon/daemon-pty-process-inspection.ts:28. So
    hasPublishedPtyProcessInspectionEvidence is false for all four and G6 sees the shape.
  • Three of them also carry hasChildProcesses: false, so the reader's legacy fallback gives
    children: 'exited', G6's children.verdict !== 'live' half holds, and the row is
    unverifiable with or without G3.
  • The fourth — the pre-v27 daemon at daemon-pty-process-inspection.ts:28 — carries
    hasChildProcesses: true, which reads back as children: 'live'. It therefore skips G6,
    falls through both idle gates with no process name, and returns running — a harder
    blocker than unverifiable.

The arm is kept deliberately. It is the most direct statement of the rule ("a handle we
could not route to is not idle"), it does not depend on G6's fallback reasoning to be
correct, and it starts reddening again the moment any producer of unavailable also
publishes evidence. But no test fails without it today, and saying so is better than a
number that implies coverage this gate does not have.

Not fixed here, reported

  1. The standalone RPCs still coerce for their other callers
    (Terminal.tsx:560, pane-agent-identity.ts:156). Changing
    Promise<boolean> to an evidence shape touches the preload contract and the
    web/mobile shims; out of scope for this fix. Terminal.tsx:560 is the one
    that matters most: it is the window-close guard, so a degraded read resolves
    false and the window closes with no "processes are running" warning. Same
    coercion class, smaller blast radius — a lost warning, not a deleted
    workspace.
  2. pty:hasChildProcesses / pty:getForegroundProcess do not guard the
    remote: prefix
    the way pty:hasPty and pty:inspectProcess do, so they
    still answer about a remote: id from the local provider's table.
  3. WorkspaceCleanupCandidate.tier and .selectedByDefault are computed but
    never read
    by any renderer code (applyWorkspaceCleanupPolicy is their only
    writer). Pre-existing dead state; this PR routes the blocker to the live gates
    instead (WORKSPACE_CLEANUP_BULK_SELECT_EXCLUSIONS → isSelectable →
    selectableIdentities) and asserts on those, never on tier.
  4. Naming smell: src/shared/pty-liveness-verdict.ts declares
    PtyLivenessVerdict and calls itself "the one vocabulary Orca uses to talk
    about whether a PTY is live", while #16926 adds PtyChildProcessesEvidence
    as a parallel live/exited/unverifiable union. Reported, not touched.

What I did NOT verify

  • No Electron / packaged-app validation. This is unit-tested only; I did not
    reproduce the degraded read against a real disconnected SSH host, a killed
    daemon, or a paired runtime environment.
  • No Windows or Linux run. macOS only.
  • Changed-code quality gate ran clean — 0 new finding(s) across 55 changed file(s) for code quality, type-aware code quality, and React Doctor. It has to
    be invoked as node config/scripts/check-changed-code-quality.mjs; the
    pnpm run wrapper crashes parsing oxlint JSON because this machine's pnpm
    engine warning (node 26 vs the wanted 24) lands on stdout.
  • Full repo test suite not run. Green on the restacked branch:
    store/slices + components/workspace-cleanup + runtime (468 files, 4231
    tests) and main/providers + main/daemon + main/ipc/pty (228 files, 2500
    tests, 8 skipped). pnpm tc exit 0. git diff --check clean.
    child-process-import-boundary and the max-lines ratchet both pass; no
    allowlist or baseline was edited.

@coderabbitai

coderabbitai Bot commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f436c0f1-9cc3-45d9-a209-2a2dc2aa2ec7

📥 Commits

Reviewing files that changed from the base of the PR and between 94e7586 and dbb4d43.

📒 Files selected for processing (8)
  • src/renderer/src/runtime/runtime-terminal-inspection.ts
  • src/renderer/src/runtime/runtime-terminal-process-inspection.ts
  • src/renderer/src/store/slices/workspace-cleanup-candidate-enrichment.ts
  • src/renderer/src/store/slices/workspace-cleanup-enrichment-performance.test.ts
  • src/renderer/src/store/slices/workspace-cleanup-local-evidence.ts
  • src/renderer/src/store/slices/workspace-cleanup-removal-preflight.test.ts
  • src/renderer/src/store/slices/workspace-cleanup-scan-progress.test.ts
  • src/renderer/src/store/slices/workspace-cleanup-terminal-liveness-coercion.test.ts

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


📝 Walkthrough

Walkthrough

The change moves runtime terminal inspection into a store-free module. Local terminals use window.api.pty.inspectProcess, and remote terminals use runtime RPC inspection. Terminal-gone errors produce unavailable results. Workspace cleanup liveness now reports unverifiable for unavailable or failed inspections and blocks cleanup. Tests update PTY mocks to use inspectProcess and cover degraded, idle, running, failed, and terminal-free cases.

Merge Risk: ⚪ Minimal · up to dbb4d

The change prevents workspace cleanup from treating unreachable terminals as idle and keeps those workspaces protected by default. No actionable merge-blocking risk remains beyond normal checks and review.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 18.18% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 8 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly summarizes the main change: preventing unreachable terminals from being treated as idle during workspace cleanup.
Description check ✅ Passed The description is detailed and explains the problem, implementation, user-visible behavior, testing, limitations, and merge-order constraints. It does not provide a linked issue, explicit template he…
Full details: Description check

Explanation

The description is detailed and explains the problem, implementation, user-visible behavior, testing, limitations, and merge-order constraints. It does not provide a linked issue, explicit template headings for What Changed and Why, visual proof or an explicit N/A statement, or completed checklist items.

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

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review — two commits pushed, head 4490961bc1

Reviewed against current origin/main (94e7586665), which this branch was already rebased onto.

The read swap is right, and it is well pinned

Every degraded shape I could construct now resolves unverifiable, never idle. I confirmed the premise at the source: pty:hasChildProcesses and pty:getForegroundProcess short-circuit to false/null when hasPtyProviderForInspection is false — the registry comment states the intent as "should read as idle" — while pty:inspectProcess returns { unavailable: true } for the same conditions. Routing the probe through the evidence-carrying handler is the correct fix, and it is one IPC round trip per PTY instead of two.

Each gate is individually pinned. Ablating them one at a time: deleting the unavailable branch → 6 red; restoring the two coerced reads while keeping the unavailable gate → 9 red; deleting the catch assignment → 1 red; deleting the blockers.push arm → 4 red. No two gates go red only together.

But the blocker did not reach the destructive path

This is the substantive finding, and it is why I pushed a commit rather than just approving the diff.

terminal-liveness-unknown appears only in LEGACY_WORKSPACE_CLEANUP_HARD_BLOCKERS. That set is @deprecated and no renderer reads it. It is in neither WORKSPACE_CLEANUP_QUEUE_BLOCKERS nor WORKSPACE_CLEANUP_BULK_SELECT_EXCLUSIONS, the two sets the live UI actually consults. So the row kept its checkbox, was swept up by select-all, and passed the removal preflight.

The PR's strongest assertions — expect(candidate.tier).toBe('protected') and expect(candidate.selectedByDefault).toBe(false) — are on those same two @deprecated fields, which carry the comment "Current renderers ignore this legacy verdict". They passed against dead code, which made the suite read as though protection had been added when it had not.

Net: before these commits, an unreachable terminal stopped reading as idle but still permitted the deletion.

What I changed

b26c00d300 — add terminal-liveness-unknown to WORKSPACE_CLEANUP_BULK_SELECT_EXCLUSIONS, the set the dialog actually consults (buildWorkspaceCleanupFacets → isSelectable → selectableIdentities → select-all and its count). Select-all no longer sweeps a row we could not verify, while canQueueWorkspaceCleanupCandidate still returns true, so the workspace stays individually deletable and never becomes a dead end. I traced every consumer of that set: the only behavior delta is select-all membership. Ablated — removing the entry turns exactly 2 tests red.

Also repointed the assertions off the dead fields onto the real consumer, buildWorkspaceCleanupFacets(candidate).isSelectable plus canQueueWorkspaceCleanupCandidate.

4490961bc1 — the extracted store-free module imported its own return type back out of the store-coupled module it was split from. The value cycle was broken but the layering read backwards, and a later change turning that into a value import would silently reintroduce the store → runtime → store cycle the split exists to prevent. Type now lives in the leaf, re-exported so callers keep their import site.

Flagged, deliberately not changed

  • Conservatism ordering is now inverted. running-terminal — a confirmed running process — is still absent from both live sets, so it is still swept by select-all. As of this PR an unverifiable row is protected from the bulk default while a confirmed running one is not. Adding running-terminal too is a one-word change, but it alters behavior for a case this PR is not about, so it is your call rather than mine.
  • unavailable conflates two different facts. inspectPtyProviderProcess throws terminal_gone when provider.hasPty(id) === false, and LocalPtyProvider.hasPty is ptyProcesses.has(id) — an authoritative exited, which arrives wearing the same clothes as loss of contact. Per docs/reference/ssh-execution-boundary.md that is exited, not unverifiable. It runs in the conservative direction so it is not a safety problem, and it is largely unreachable in practice (workspace-terminal-hydration.ts:195 resets ptyIdsByTabId to [] for every tab, and terminal-pty-release.ts drops the id on exit), but splitting unavailable?: true into unavailable?: 'exited' | 'unverifiable' at the main boundary is the real end state. Separate PR — it touches the provider contract and crosses to paired clients.
  • Same bug class survives on two other destructive paths, both out of scope here: Terminal.tsx:555-566 gates the window-close confirmation on raw hasChildProcesses with no catch, and TerminalPane.tsx:1240 calls inspectRuntimeTerminalProcess but discards unavailable, disagreeing with its sibling running-terminal-close-guard.ts:138 which tests it explicitly.
  • Web clients now block nearly every row. web-terminal-api.ts:36-38 has inspectProcess reject outright, so every web-mirrored terminal becomes unverifiable. Semantically correct, but a blocker that appears on almost every row carries little information — worth a deliberate decision.
  • Serial per-PTY probe with a 15s remote timeout. probeTerminalLiveness awaits one PTY at a time; an unreachable remote runtime with N bound PTYs stalls that candidate for up to N × 15s. Local path is strictly cheaper than before.

Gates

pnpm tc exit 0 · oxlint clean · git diff --check clean · formatted with oxfmt on changed files only. Tests: 323/323 across 44 workspace-cleanup files, 1124/1124 across 145 runtime files, 42/42 across the four directly affected suites. Pre-fix differential reproduced: the PR's own test file is 4 failed / 3 passed against unmodified origin/main production code, 7/7 on this branch.

Not verified: no Electron/CDP run — the change is store-layer and staging a genuinely unreachable host in dev-mode CDP would not have produced real evidence. No Windows validation.

brennanb2025 added a commit that referenced this pull request Aug 28, 2026
… 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.
Workspace cleanup asked main two questions per terminal —
`pty:hasChildProcesses` and `pty:getForegroundProcess` — and both coerce a
degraded read to `false`/`null` before it crosses the IPC boundary. A
disconnected SSH provider short-circuits to those values, and the daemon
adapter catches its own dead-socket request and answers `null`. Nothing
throws, so `probeTerminalLiveness`'s `unknown` arm never ran for the case it
exists for, and a worktree whose agent was still working presented as an
idle, unblocked cleanup row.

Read `pty:inspectProcess` instead. It is the one inspection that carries
`unavailable` across the boundary, and it is a single round trip instead of
two. An `unavailable` answer, or a rejection, now yields `unverifiable` and
the `terminal-liveness-unknown` blocker — unknown falls toward "do not clean
up", which is the conservative arm here.

The inspection read moves to a store-free module so the cleanup store can
call it without a store->runtime import cycle; the type declaration stays put.
…d the bulk default

probeTerminalLiveness now reports 'unverifiable' for a degraded read, but the
blocker it pushed did not reach the destructive path: terminal-liveness-unknown
sits only in LEGACY_WORKSPACE_CLEANUP_HARD_BLOCKERS, which is @deprecated and
which no renderer reads. The row kept its checkbox, was swept up by select-all,
and passed the removal preflight -- so an unreachable terminal stopped reading as
idle but still permitted the deletion.

Add it to WORKSPACE_CLEANUP_BULK_SELECT_EXCLUSIONS, the set the dialog actually
consults via buildWorkspaceCleanupFacets -> selectableIdentities. Select-all no
longer sweeps a row we could not verify, while canQueueWorkspaceCleanupCandidate
still returns true so the workspace stays individually deletable rather than
becoming a dead end.

Also repoint the tests off tier/selectedByDefault, both @deprecated and unread,
onto the gates the renderer consults. Those assertions passed against dead code
and read as protection that did not exist.
…leaf module

The extracted store-free module imported its own return type back out of
runtime-terminal-inspection.ts, the store-coupled module it was split from. The
value cycle was broken but the layering read backwards, and a later change that
turned that type import into a value import would have silently reintroduced the
store->runtime->store cycle the split exists to prevent.

Define the type in the leaf and re-export it from the old module so the existing
callers keep their import site.
A host that answered but whose probes failed publishes the deliberate legacy
collapse (foregroundProcess = the stable-cache shell name, hasChildProcesses =
false) with the real verdict in processEvidence. That legacy half is
byte-identical to an idle shell, so cleanup dropped the blocker and select-all
swept the row. unavailable only ever covered a handle we could not route to.

Old hosts keep their old meaning: readPtyProcessInspectionEvidence falls back to
the legacy interpretation when the field is absent.
…ocker

Each consumer read on its own through the reader the dialog really calls -
select-all's selectableIdentities, the Remove button's queue filter, and the
confirm screen rendered into a DOM. Never tier/selectedByDefault; those are
@deprecated and no renderer reads them.

The new leaf-module test is also the merge-order guard: dropping processEvidence
from RuntimeTerminalProcessInspection is a typecheck failure at a named site, and
the behaviour half names the cost - the same degraded read becomes a deletable
idle shell without it.
@brennanb2025
brennanb2025 force-pushed the brennanb2025/probe-liveness-coercion-r1 branch from 4490961 to c72d2cc Compare August 28, 2026 15:39
@brennanb2025
brennanb2025 changed the base branch from main to brennanb2025/coercion-daemon-inspect-r2 August 28, 2026 15:39
@greptile-apps

greptile-apps Bot commented Aug 28, 2026 •

Copy link
Copy Markdown

Greptile Summary

This PR makes workspace cleanup treat unreachable or unverified terminal inspection as unknown rather than idle.

  • Reads the evidence-preserving process-inspection API across local and runtime terminals.
  • Excludes unverifiable workspaces from bulk selection while preserving explicit per-row removal.
  • Requires renewed confirmation when terminal evidence becomes unavailable during removal preflight.
  • Preserves legacy daemon compatibility and moves process inspection into a store-independent runtime module.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
src/renderer/src/store/slices/workspace-cleanup-local-evidence.ts Uses process-inspection evidence and fails closed when terminal liveness cannot be verified.
src/renderer/src/store/slices/workspace-cleanup-preflight-failures.ts Treats newly discovered unknown terminal liveness as a post-confirmation risk escalation.
src/shared/workspace-cleanup.ts Excludes unverifiable terminal rows from bulk selection while retaining deliberate manual removal.
src/shared/pty-process-inspection-evidence.ts Adds shared helpers for legacy inspection composition and identifying host-published evidence.
src/renderer/src/runtime/runtime-terminal-process-inspection.ts Extracts host-aware terminal inspection into a store-independent module and preserves evidence typing.
src/main/daemon/daemon-pty-process-inspection.ts Centralizes legacy daemon inspection composition without claiming evidence unavailable from older protocols.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Cleanup candidate with terminal] --> B[Inspect terminal process]
  B --> C{Published evidence?}
  C -->|Yes| D{Observed idle?}
  C -->|No| E{Legacy response reports live work?}
  D -->|Yes| F[Candidate remains selectable]
  D -->|No or unverifiable| G[Add terminal-liveness-unknown]
  E -->|Yes| H[Add running-terminal]
  E -->|No| G
  G --> I[Exclude from bulk selection]
  G --> J[Require renewed confirmation if discovered during preflight]
Loading

Reviews (12): Last reviewed commit: "Merge commit '003849ec9203c891499e872e35..." | Re-trigger Greptile

…e the delete

The post-confirmation preflight re-probes liveness and republishes
`terminal-liveness-unknown`, then nothing reads it: the queue gate gets only
`main-worktree`/`folder-repo`/`ssh-disconnected`, and the escalation gate only
`dirty-files`/`unpushed-commits`. A row confirmed while its terminal read idle
was therefore deleted even when the preflight could no longer verify it, and
the warning the confirm screen exists to show was never shown.

The blocker is a disclosure rather than a veto — it stays individually
selectable — so a fact that appears only after the authorizing screen has to
send the row back for review. Adding it to a separate reconfirm set keeps
CONCRETE_RISK_BLOCKERS meaning what its comment says. A row that already
carried the blocker at confirmation still deletes: the escalation only fires
when the blocker is new relative to the approved candidate.

Verified against the checks skipped by --no-verify (no node_modules in the
throwaway worktree): oxlint, oxfmt and all 42 workspace-cleanup suites were run
on byte-identical file contents in the stack tip's worktree.
brennanb2025 added a commit that referenced this pull request Aug 28, 2026
…fter confirm

The removal preflight rescans and re-enriches every confirmed row, so it
recomputes running-terminal, live-agent and terminal-liveness-unknown between
the confirmation and the delete. #17024 made terminal-liveness-unknown refuse
the delete; the two positive-liveness verdicts were still dropped on the floor
and the workspace was removed with no disclosure.

Add them to the set that invalidates a confirmation, and give each claim its
own message. Per docs/reference/ssh-execution-boundary.md, running-terminal and
live-agent are positive evidence something is alive, while
terminal-liveness-unknown is loss of contact -- different claims that must not
collapse into one string.

The messages state the verdict the preflight holds now. A verdict missing from
the approved snapshot need not have arisen after the confirmation -- that
snapshot may simply never have observed it -- so none of them claims it did.
…idle

A retained pre-v27 daemon (protocol 11-26) exposes only `getForegroundProcess`,
so `DaemonPtyProcessInspection.inspectProcess` composes the pair client-side and
publishes no `processEvidence`. Those daemons emit `zsh` + `hasChildProcesses:
false` both when the pane really sits at an idle shell and when their foreground
read fell back to the shell title, with no field to separate the two.
`readPtyProcessInspectionEvidence` restates that pair as an OBSERVATION for
hosts that predate the field -- the right reading for callers that act on
presence, and the wrong one on the path that deletes a workspace.

`probeTerminalLiveness` now refuses to conclude idle from a host that published
nothing. A positive live read stays believed: it can only add a blocker.

The legacy composition moves to `composeLegacyPtyProcessInspection` in the
shared evidence module so the producer and the reader that must distrust it live
in one file, and tests can drive the real producer.

This branch has not been deployed

No deployments
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