Repository navigation
fix(cleanup): stop reading an unreachable terminal as an idle one - #17024
brennanb2025 wants to merge 18 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (8)
Included review availability: Your plan provides up to 10 included reviews per hour; 2 remain after this review. 📝 WalkthroughWalkthroughThe change moves runtime terminal inspection into a store-free module. Local terminals use Merge Risk: ⚪ Minimal · up to 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)
✅ Passed checks (4 passed)
Full details: Description checkExplanation 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.
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Review — two commits pushed, head
|
… 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.
4490961 to
c72d2cc
Compare
…025/probe-liveness-coercion-r1
Greptile SummaryThis PR makes workspace cleanup treat unreachable or unverified terminal inspection as unknown rather than idle.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains.
|
| 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]
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.
…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.
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,
applyWorkspaceCleanupPolicyclassified it
ready/selectedByDefault, and the final confirm-remove screenshowed 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 rowkeeps 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
probeTerminalLivenessread two standalone RPCs whose degraded answers areflattened below the IPC boundary, so nothing reached the caller to reject:
src/main/ipc/pty/ipc/inspect.ts:139-141,:149-151(hasPtyProviderForInspectionfalse →return false/return null;src/main/ipc/pty/provider/registry.ts:49-50states the intent as "should read as idle")false/nullsrc/main/daemon/daemon-pty-process-inspection.ts:58-59swallows the request and returnsnull;:22deriveshasChildProcessesfrom thatnullfalse/nullremote:runtime PTY idremote:prefix (pty:hasPtyat:112-119andpty:inspectProcessat:157-165both do), so the id falls through to the local provider, which has never heard of itfalse/nullIn every one of those,
probeTerminalLivenessfell into!hasChildProcesses && !processName → continueand returnedidle.pty:inspectProcessalready 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 daemonadapter even documents the distinction at
daemon-pty-process-inspection.ts:32-33— itsinspectProcessdeliberatelyrequests 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 existinginspectRuntimeTerminalProcess,which also routes
remote:panes to their owning runtime) and adds theunavailablearm. 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 backto their pre-change source (
570cb71cbb^) and the current tests are run againstthem:
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
hasChildProcessestofalseandgetForegroundProcesstonull—exactly what main returns for a degraded read — while only
inspectProcesscarries
unavailableor 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:
2c68f20d6dinspectRuntimeTerminalProcessfrom@/runtime/runtime-terminal-inspectionagainsrc/renderer/src/store/slices/fail to load —createWorkspaceCleanupSlice is not a function, the store↔runtime import cycleThat 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 theircounts and semantics:
workspace-cleanup-scan-progress.test.ts— probe-count / ordering contractsworkspace-cleanup-enrichment-performance.test.ts— concurrency-peak contractsworkspace-cleanup-removal-preflight.test.ts— the two "agent stillforegrounded" protections; their doubles now also answer
inspectProcessThe new test additionally asserts
hasChildProcessesandgetForegroundProcessare 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
blockersarray.probeTerminalLivenessread onlyinspection.unavailable. Butunavailableis set only for ahandle we could not route to —
terminal_gone, aremote:id, an unregistered provider. A host thatdid 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, theshell name) and
hasChildProcesses: false, with the real verdict in the new optionalprocessEvidence. 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
processEvidenceobserve unchanged host content"). This PR was the clientthat 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:
They are the four the round-4 gate reddens on its own (G4 below). After:
Tests 28 passed (28)across the three guard files.probeTerminalLivenessnow routes the answer throughreadPtyProcessInspectionEvidence.Old hosts keep their old meaning — the reader falls back to
{ foreground: observed(legacy), children: hasChildProcesses ? live : exited }when the field isabsent, 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.queryWorkspaceCleanupCandidates(...).selectableIdentities— the listtoggleSelectAllwrites intoselectedIdsverbatim[]for the unverifiable row,[identity]for an observed-idle one.selectableIdentities∩canQueueWorkspaceCleanupCandidate— whatselectedCandidatesreduces to, and whatdeleteDisabled: selectedCount === 0gates onWorkspaceCleanupConfirmRemoverendered into a DOM, asserting ontextContentTerminal liveness unknown.One deliberate escape hatch, stated plainly:
terminal-liveness-unknownis not inWORKSPACE_CLEANUP_QUEUE_BLOCKERS, so a row the user ticks by hand still removes. That is theround-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
processEvidencewhen the host published it. A host that publishes nonewas read back through the reader's legacy fallback, which restates its two values as an
observation. A retained pre-v27 daemon publishes
zsh+falseboth when the pane reallysits 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 isstill fine: that can only add a blocker.
The confirm-time preflight learned the same thing:
terminal-liveness-unknownjoins thereconfirm 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
2c68f20d6dThree 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.
terminal-liveness-unknowninWORKSPACE_CLEANUP_BULK_SELECT_EXCLUSIONSprobeTerminalLivenessreadsinspectRuntimeTerminalProcess(restore thePromise.all([hasChildProcesses, getForegroundProcess])pair)inspection.unavailable === true → unverifiablearmprocessEvidenceread (round 4), replaced by the legacy interpretationterminal-liveness-unknownon'unverifiable'!hasPublishedPtyProcessInspectionEvidence(inspection) && children.verdict !== 'live'terminal-liveness-unknownin the preflight'sWORKSPACE_CLEANUP_RECONFIRM_BLOCKERSprocessEvidencedeclared onRuntimeTerminalProcessInspectionnpx tsc -p config/tsconfig.tc.web.json --noEmit→ 18 errors, incl.TS2339atruntime-terminal-process-inspection-evidence-contract.test.ts:29G3 reddens nothing on its own, and stays anyway
Deleting the
unavailablearm leaves the three guard files at 28/28 green, and alsoleaves 4241 tests across 469 files green (
src/renderer/src/store/slices/+src/renderer/src/components/workspace-cleanup/+src/renderer/src/runtime/). Thistable 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:
unavailable: truepublishes noprocessEvidence—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, andsrc/main/daemon/daemon-pty-process-inspection.ts:28. SohasPublishedPtyProcessInspectionEvidenceis false for all four and G6 sees the shape.hasChildProcesses: false, so the reader's legacy fallback giveschildren: 'exited', G6'schildren.verdict !== 'live'half holds, and the row isunverifiablewith or without G3.daemon-pty-process-inspection.ts:28— carrieshasChildProcesses: true, which reads back aschildren: 'live'. It therefore skips G6,falls through both idle gates with no process name, and returns
running— a harderblocker 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
unavailablealsopublishes 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
(
Terminal.tsx:560,pane-agent-identity.ts:156). ChangingPromise<boolean>to an evidence shape touches the preload contract and theweb/mobile shims; out of scope for this fix.
Terminal.tsx:560is the onethat matters most: it is the window-close guard, so a degraded read resolves
falseand the window closes with no "processes are running" warning. Samecoercion class, smaller blast radius — a lost warning, not a deleted
workspace.
pty:hasChildProcesses/pty:getForegroundProcessdo not guard theremote:prefix the waypty:hasPtyandpty:inspectProcessdo, so theystill answer about a
remote:id from the local provider's table.WorkspaceCleanupCandidate.tierand.selectedByDefaultare computed butnever read by any renderer code (
applyWorkspaceCleanupPolicyis their onlywriter). 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 ontier.src/shared/pty-liveness-verdict.tsdeclaresPtyLivenessVerdictand calls itself "the one vocabulary Orca uses to talkabout whether a PTY is live", while
#16926addsPtyChildProcessesEvidenceas a parallel
live/exited/unverifiableunion. Reported, not touched.What I did NOT verify
reproduce the degraded read against a real disconnected SSH host, a killed
daemon, or a paired runtime environment.
0 new finding(s) across 55 changed file(s)for code quality, type-aware code quality, and React Doctor. It has tobe invoked as
node config/scripts/check-changed-code-quality.mjs; thepnpm runwrapper crashes parsing oxlint JSON because this machine's pnpmengine warning (node 26 vs the wanted 24) lands on stdout.
store/slices+components/workspace-cleanup+runtime(468 files, 4231tests) and
main/providers+main/daemon+main/ipc/pty(228 files, 2500tests, 8 skipped).
pnpm tcexit 0.git diff --checkclean.child-process-import-boundaryand the max-lines ratchet both pass; noallowlist or baseline was edited.