Skip to content

fix(runtime): hold parking and transport reads through an unverifiable probe - #20096

Merged
nwparker merged 3 commits into
mainfrom
nwparker/status-writer-one-nulling-rule
Sep 17, 2026
Merged

nwparker merged 3 commits into
mainfrom
nwparker/status-writer-one-nulling-rule

Conversation

@nwparker

@nwparker nwparker commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​240 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​239
Prod 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​98 $\color{#cf222e}{\Huge{\mathbf{−}}}$​41 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​57

Stacked on #20095. Closes the last three sites in the status-verdict family where a non-verified probe was read as evidence the host is gone.

Governing rule: docs/reference/ssh-execution-boundary.md — verdicts are live / unverifiable / exited, no synonyms, and loss of contact is never evidence of process death. Reuses lastVerifiedRuntimeStatus() from #20085; no new predicates.


1. Writer divergence — real as duplication, unreachable as a behaviour split

runtime-status-refresh.ts:25 and runtime-status-snapshot.ts:27 both implemented the "null the status unless verified" rule, and only the latter guarded on !snapshot.retired / merged remoteControl. The reported consequence — a retired host publishing a non-null entry.status through the manual-refresh path — does not reproduce, for two independent reasons:

  1. retired: true implies verification: 'blocked', permanently. retired is set in exactly one place, RuntimeHostStatusOwner.dispose() (src/shared/runtime-host-status-owner.ts:182), together with verification: 'blocked'. dispose() sets this.disposed, and every mutator (activate, acceptVerified, refresh, connectionChanged, authenticationRejected, startRequest, verify) early-returns on disposed, so no later update() can reach the snapshot. verification === 'verified' && !retired is therefore equivalent to verification === 'verified'. The owner is the only producer — both getStatusSnapshots paths (runtime-environment-connectivity-handlers.ts:64, web-runtime-session.ts:46) just read owner snapshots.
  2. The refresh path's computed status was never used. Its caller (runtime-status.ts:297) branched if (entry.snapshot) { applyRuntimeHostStatusSnapshot(entry.snapshot); return } — discarding the entry and re-deriving through the other rule. The duplicate was dead code.

So there is no user-visible split today. The duplication is still the defect this area keeps producing, so the dead copy is removed rather than left to drift: refreshRuntimeEnvironmentStatus now takes an explicit applySnapshot callback and hands the snapshot straight to applyRuntimeHostStatusSnapshot, leaving one implementation of the nulling rule.

Mutation table: none. Behaviour-identical by construction — the removed expression's value was already discarded by the only caller.

2. Paired-parking capability reads — real, and one is destructive

Both sites read entry.status?.capabilities, so a nulled status reads as "this host cannot park".

paired-parked-terminal-restore.ts → deferred-session-reattach-choice.ts:96 — destructive. Path proven: reaching line 96 requires isRemoteRuntimePtyId(candidateReattachSessionId). When canRestorePairedParkedTerminal returns false, pairedParkedReattachSessionId is null; runtimeHostPtyWakeHint (line 66) and the third disjunct (line 103) both require !isRemoteRuntimePtyId(candidate), so both are false too — deferredReattachSessionId is null. With hasSleepingAgentSession true, detachedLivePtyId and detachedRemoteLeafPtyId are both null (lines 48, 56) and eagerLivePtyId requires a non-remote id, so control reaches the final else and calls startFreshColdRestoreAgentResume.

A parked paired terminal that should have reattached instead cold-restores a fresh session, because its host failed one status probe. This is reachable exactly when it matters: panes remount on reconnect while the status probe is still in flight.

paired-runtime-parking-capabilities.ts → canWatcherCoverParkedTerminalTab — real but conservative. A false negative propagates through isParkRestorableTerminalPty to parkedTabIds.delete(...) (terminal-cold-park-withheld-tabs.ts:47) and immediateTabIds.add(...) (terminal-cold-activation.ts:127): a tab that should have parked stays mounted. No output is lost — the gate only ever fails toward mounting, and the pane owns the bytes. The cost is churn: every paired terminal tab in the workspace unparks and remounts on each transient probe failure, then re-parks on recovery.

Both now read lastVerifiedRuntimeStatus. A capability is a fact about the host's build, not about current reachability.

entry.status snapshot.status before after
advertises capability — capable capable
null advertises capability not capable capable
null null not capable not capable
null no snapshot not capable not capable

3. Transport fall-through — real, and inverted

runtimeHostConnectionStateForEntry's snapshot branch handled transport: 'disconnected' and 'ready'; 'connecting' and 'unknown' fell through to runtimeHostConnectionState, which was called without transportStatus and so defaulted it to 'disconnected'.

Reachable, and the verdict is inverted: a host whose transport is disconnected returns 'reconnecting', while a host actively connecting returned 'disconnected' — the destructive verdict, the only one isDisconnectedRuntimeHostState accepts and the one that earns the red glyph.

The producing sequence is ordinary reconnect. connectionChanged('connecting') with a previous transport of 'ready' sets verification: 'unavailable' (runtime-host-status-owner.ts:145-151). On the desktop path the caller passes diagnostics, whose remoteControl.state steers the result before the default applies. web-runtime-client.ts:58 passes no diagnostics, so remoteControl stays undefined and the default lands — the web client painted a reconnecting host as disconnected.

Fixed by passing the snapshot's own transport instead of letting it default. 'disconnected' already returned above, so 'ready' is the only connected transport remaining.

UI effect: runtimeStatusForOverall maps 'checking' to connecting and 'disconnected' to disconnected, and isDisconnectedRuntimeHostState is true only for 'disconnected'. The status bar and Settings > Available Hosts move that host from the red disconnected glyph to the connecting state for the duration of the handshake. That is the correct reading: the transport is being established, which is unverifiable, not exited.

Mutation table (entry.status null, no remoteControl — transportStatus only feeds the !status branch, so every case with a non-null status is unchanged):

snapshot.transport verification before after
disconnected any non-blocked reconnecting reconnecting
ready unavailable runtime-unavailable runtime-unavailable
ready checking checking checking
connecting checking checking checking
unknown checking checking checking
connecting unavailable disconnected checking
unknown unavailable disconnected disconnected (corrected in the follow-up below)
any blocked disconnected disconnected
any, retired — disconnected disconnected
connecting unavailable, remoteControl: closed disconnected disconnected

Verification

Each gate was proven able to fail before its pass was believed.

  • Tests bind to the fixes. Reverting the three source files and re-running produced exactly 4 failures, all expected: connecting/unavailable and unknown/unavailable returning 'disconnected' instead of 'checking', plus both capability reads. 26 other tests in those files still passed, so the suites are not merely tautological.
  • Typecheck tsc -p config/tsconfig.tc.web.json, config/tsconfig.node.json, config/tsconfig.tc.cli.json — all empty logs. Proven failable: a deliberate type error in runtime-host-connection-state.ts reported TS2322 at the right line.
  • Tests vitest run --config config/vitest.config.ts over src/renderer/src/runtime/, src/renderer/src/lib/, src/renderer/src/store/slices/, the parking suites and pty-connection/ — 733 + 329 + 6 + 8 files, 0 failures. Logs grepped for FAIL rather than trusting the exit code.
  • Lint oxlint over the four touched directories, exit 0. Proven failable: an unused variable reported no-unused-vars.

The 'ready' + 'checking' row was wrong in my first draft of the verdict table — I had expected runtime-unavailable, but the verification === 'checking' && !status guard answers first. The enumerated table caught it; the code was right and the expectation was wrong.


Follow-up commit: fix(runtime): keep a revoked host out of the parking promise

Two defects found by adversarial review after the sections above were written. Both are fixed in the second commit on this branch.

A. The capability reads had no trust gate, and one direction is destructive

Section 2 above is right that a capability is a fact about the host's build. It is not right that the fact survives every verdict. blocked and retired stop all retries permanently (runtime-host-status-owner.ts:93, 187, 237), and snapshot.status is never cleared (:221 is its only writer), so both sites kept advertising TERMINAL_PAIRED_PARKING_RUNTIME_CAPABILITY for a host that can never honour a restore.

That inverts the safe direction for the parking site. selectPairedRuntimeParkingEnvironmentIds → isParkRestorableTerminalPty → selectColdParkedTerminalTabs cold-unmounts the pane, and remote-runtime bytes never transit main, so the client's xterm buffer is its only copy of the scrollback. Trading it for a host-side restore that cannot happen is the lossy direction, not the conservative one. On main those tabs stayed mounted.

Fix: isRuntimeHostContactRevoked in src/shared/runtime-host-status.ts names the one terminal verdict — retired, or refused — once. Both parking sites gate on it before reading lastVerifiedRuntimeStatus, and runtimeHostConnectionStateForEntry now reads the same predicate instead of its own inline copy, so there is a single definition rather than two derivations free to drift.

Known limit, stated plainly: verification: 'blocked' is broader than "the host refused us". isRuntimeHostStatusBlocked also covers invalid_argument, invalid_runtime_response, method_not_found and unsupported_method, and the owner maps any client-side TypeError/SyntaxError to invalid_runtime_response. So a host whose status method is merely broken is treated as revoked here too. That is the same breadth runtimeHostConnectionStateForEntry has always had, and it is strictly narrower than main, which drops the capability on every non-verified verification. Splitting "refused" from "status method broken" belongs at the owner, in its own PR.

B. transport: 'unknown' is not a handshake in progress

The mutation table above claimed unknown + unavailable should read checking. That was wrong, and the row is corrected.

transport: 'unknown' is the owner's constructor default (runtime-host-status-owner.ts:51), and connectionChanged is only ever called from a shared-control connection's diagnostics handler (runtime-environment-request-connections.ts:229). That connection is created only after a verified probe (runtime-environment-status-owner.ts:69). So for a host that never answers — a paired laptop that is switched off — unknown is not a transient handshake state; it is where the transport stays.

Reading it as checking withdrew the user's only affordance: runtimeActionLabel('checking') returns null, so the row offered neither Connect nor Disconnect, and runtimeStatusForOverall('checking') held the whole status-bar segment in a connecting state. The hint now applies only to transport: 'connecting', which really is a handshake in flight; unknown keeps the previous default and the row stays actionable.

Verification of the follow-up

Six new assertions, each mutation-checked: reverting the specific fix produced 6 failed | 29 passed (35), restoring it 35 passed (35). No survivors. Broader runs on the rebased branch: src/renderer/src/components/terminal-pane 453 passed (453) / 4360 passed (4360); src/renderer/src/runtime + src/renderer/src/store/slices 522 passed (522) / 4772 passed (4772); status-bar, sidebar host options and RepositoryHostSetupsSection 56 passed (56) / 397 passed (397). pnpm tc exit 0 with zero error TS; check:code-quality:changed against this PR's base exit 0.

@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

  • Transport verdict fall-through — runtimeHostConnectionStateForEntry now feeds the snapshot's own transport into transportStatus (ready → connected, connecting/unknown → checking) instead of letting it default to disconnected, so a host still establishing contact reads checking rather than the destructive disconnected verdict. I re-ran the fall-through against runtimeHostConnectionState and the enumerated table is accurate, including the remoteControl: closed and retired/blocked short-circuits.
  • Parking capability reads — both paired-parking readers now go through lastVerifiedRuntimeStatus, so an unverifiable probe no longer unpacks a parked terminal or cold-restores a fresh session via deferred-session-reattach-choice.ts:96.
  • Single nulling rule — refreshRuntimeEnvironmentStatus takes an explicit applySnapshot callback, deleting the dead verification === 'verified' duplicate that its only caller already discarded. Behavior-identical, and the dead-code claim checks out against runtime-host-status-owner.ts (dispose sets retired alongside verification: 'blocked').
  • Tests — the enumerated verdict table and the unverifiable-probe parking cases bind to the fixes and fail against the pre-fix sources (the two connecting/unknown + unavailable rows and both status: null + snapshot capability reads).

One non-blocking note for awareness, not a change request: the parking reads don't exclude retired the way the transport verdict does, so a disposed host's retained snapshot.status still reads as "capable" via lastVerifiedRuntimeStatus. That's harmless in practice — retired environment ids are deleted from runtimeStatusByEnvironmentId on the next catalog update — and consistent with "a capability is a fact about the host's build", but it's the one asymmetry between the two reads worth having consciously accepted.

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

@nwparker
nwparker force-pushed the nwparker/status-reads-hold-unverifiable-host branch from 1292d5b to ae5e9f7 Compare September 17, 2026 06:57
@nwparker
nwparker force-pushed the nwparker/status-writer-one-nulling-rule branch from 323fa13 to 5b1df3f Compare September 17, 2026 06:58

@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 narrowed transport hint re-exposes a case the previous commit had fixed: a host that has already answered a status probe can keep transport: 'unknown' for the whole session and, after one failed probe, now reads disconnected, dropping the session mirror and blanking its SSH rows. Evidence and a proposed discrimination are inline.

Reviewed changes

Since the prior pullfrog review (323fa135), commit 5b1df3f:

  • Added isRuntimeHostContactRevoked to runtime-host-status.ts and gated both paired-parking reads and the connection-state derivation on it, resolving the retired/blocked asymmetry the prior review flagged.
  • Narrowed the transport fall-through to connecting → 'checking', deliberately leaving unknown at the default 'disconnected', with an affordance test asserting a never-contacted host stays Connect-able.
  • Extended paired-parking-unverifiable-host.test.ts with blocked/retired refusal cases for both parking reads.

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

Comment on lines +142 to +147
// Why only 'connecting': a transport mid-handshake fell through to the default and
// reported a host still establishing contact as down. 'unknown' keeps that default on
// purpose — it means no transport was ever attempted, which for an unreachable paired
// host is the permanent state, and 'checking' there withdraws its Connect action and
// pins the status bar to "connecting" forever.
...(snapshot?.transport === 'connecting' ? { transportStatus: 'checking' as const } : {}),

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.

transport: 'unknown' is not exclusive to a host that was never contacted: the desktop status owner leaves it at 'unknown' whenever shared control is absent (runtime-environment-status-owner.ts calls transport.pause() for a capability-absent host, a no-op with no connection) or the read is passive, and complete() retains snapshot.status across a later failed probe. That entry — status: null, snapshot: { status: <verified>, verification: 'unavailable', transport: 'unknown' } — reads disconnected here, so getReachableRuntimeSessionMirrorTargets drops a target whose retained runtimeId is non-null and runtime-environment-ssh-selectors.ts blanks its rows: loss of contact read as exit. The never-contacted host this is fixing has snapshot.status === null; discriminating on that keeps the Connect affordance and holds a previously-answered host as unverifiable.

Technical details
# `unknown` transport with a retained verified status must not read `disconnected`

## Affected sites
- `src/renderer/src/runtime/runtime-host-connection-state.ts:147` — the hint is passed only for `'connecting'`; with `'unknown'` the fall-through defaults `transportStatus` to `'disconnected'`.
- `src/renderer/src/runtime/runtime-host-connection-state.test.ts:281` — the new row asserts `disconnected`; the comment at :279-280 encodes the premise ("no transport was ever attempted") the code below refutes.
- `src/renderer/src/lib/runtime-session-mirror-targets.ts:55` — `isDisconnectedRuntimeHostState(...)` short-circuits before the retained `runtimeId` at :58 is read.
- `src/renderer/src/store/slices/runtime-environment-ssh-selectors.ts:22-24` — `isConnectedRuntimeHostState` false, so mirrored SSH rows/errors are withheld.

## Why `unknown` is reachable for a host that already answered
- The owner initializes `transport: 'unknown'` (`src/shared/runtime-host-status-owner.ts:44-52`) and only `connectionChanged` writes it (`:133-159`); no production caller passes `'unknown'`.
- The desktop owner calls `transport.establish()` only when the host advertises `REMOTE_RUNTIME_SHARED_CONTROL_CAPABILITY` (`src/main/ipc/runtime-environment-status-owner.ts:56-72`); otherwise `transport.pause()`, a no-op when no connection exists (`src/main/ipc/runtime-environment-request-connections.ts:182-184`). A reachable `capabilities: []` host therefore keeps `'unknown'` indefinitely (`runtime-environment-status-recovery.test.ts:47-70` verifies one successfully).
- `complete()` retains `snapshot.status` on a failed probe (`runtime-host-status-owner.ts:223-229`), and the store nulls only `entry.status` (`src/renderer/src/store/slices/runtime-status-snapshot.ts:27`).
- `runtimeHostConnectionStateForEntry` passes `entry.status` (not `snapshot.status`) into `runtimeHostConnectionState` (`:141`), so the retained verified status is invisible to the transport branch.

## Required outcome
- A host with a retained verified status must read as unverifiable (`checking`), not `disconnected`, when its transport is `'unknown'` and its latest probe failed. The never-contacted case (`snapshot.status === null`) may keep returning `disconnected` so the row keeps its Connect action.

## Suggested approach (optional)
- Discriminate on the retained status at `:147`, e.g. treat `transport === 'connecting' || (transport === 'unknown' && snapshot.status != null)` as `'checking'`, or derive the hint from `lastVerifiedRuntimeStatus(entry)`.
- Add a row for `unknown` + `unavailable` with a non-null `snapshot.status`; the new `snapshotWith` helper only builds `status: null`, so this case is uncovered.

## Open questions for the human (optional)
- Is a capability-absent (or passive-only) host expected to keep its session mirror / SSH rows? If not, this destructive read may be intended; if yes, the retained-status case needs the hold.

@nwparker
nwparker force-pushed the nwparker/status-reads-hold-unverifiable-host branch from ae5e9f7 to e17ac8e Compare September 17, 2026 07:23
@nwparker
nwparker force-pushed the nwparker/status-writer-one-nulling-rule branch from 5b1df3f to 9b44476 Compare September 17, 2026 07:23
@nwparker
nwparker changed the base branch from nwparker/status-reads-hold-unverifiable-host to main September 17, 2026 09:02
…e probe

Three remaining sites where a non-verified status probe was read as evidence the
host is gone, per docs/reference/ssh-execution-boundary.md.

- runtime-status-refresh published its own copy of the "null the status unless
  verified" rule, then handed the snapshot to applyRuntimeHostStatusSnapshot,
  which re-derived it. The copy was dead but free to drift; the snapshot branch
  now calls applyRuntimeHostStatusSnapshot directly, leaving one implementation.
- The paired-parking capability reads treated a nulled status as "host cannot
  park", so a transient probe failure unparked live paired terminals and dropped
  a parked session's reattach in favour of a fresh cold restore. Both now read
  lastVerifiedRuntimeStatus; a capability is a fact about the host's build.
- runtimeHostConnectionStateForEntry handled transport 'disconnected' and 'ready'
  and let 'connecting'/'unknown' fall through to the default 'disconnected' —
  reporting a host mid-handshake as down, a worse verdict than an actually
  disconnected transport gets. It now passes the snapshot's transport through.
Holding a capability through an unverifiable probe is right; holding it through
the host's own refusal is not. `blocked` (auth rejected, protocol mismatch) stops
every retry for good, and parking trades the client's only copy of the scrollback
for a host-side restore that can then never happen -- the destructive direction.
`isRuntimeHostContactRevoked` names that one terminal verdict once, and the
connection-state derivation now reads it too so there is a single definition.

Also narrows the transport hint to 'connecting'. 'unknown' means no transport was
ever attempted, which is the permanent state of an unreachable paired host: as
'checking' its row lost its Connect action and the status bar read "connecting"
for the whole session.
@nwparker
nwparker force-pushed the nwparker/status-writer-one-nulling-rule branch from 9b44476 to 6caf692 Compare September 17, 2026 09:07
@nwparker
nwparker merged commit 851befa into main Sep 17, 2026
3 of 4 checks passed
ivanvykopal pushed a commit to ivanvykopal/orca that referenced this pull request Sep 20, 2026
…e probe (stablyai#20096)

* fix(runtime): hold parking and transport reads through an unverifiable probe

Three remaining sites where a non-verified status probe was read as evidence the
host is gone, per docs/reference/ssh-execution-boundary.md.

- runtime-status-refresh published its own copy of the "null the status unless
  verified" rule, then handed the snapshot to applyRuntimeHostStatusSnapshot,
  which re-derived it. The copy was dead but free to drift; the snapshot branch
  now calls applyRuntimeHostStatusSnapshot directly, leaving one implementation.
- The paired-parking capability reads treated a nulled status as "host cannot
  park", so a transient probe failure unparked live paired terminals and dropped
  a parked session's reattach in favour of a fresh cold restore. Both now read
  lastVerifiedRuntimeStatus; a capability is a fact about the host's build.
- runtimeHostConnectionStateForEntry handled transport 'disconnected' and 'ready'
  and let 'connecting'/'unknown' fall through to the default 'disconnected' —
  reporting a host mid-handshake as down, a worse verdict than an actually
  disconnected transport gets. It now passes the snapshot's transport through.

* fix(runtime): keep a revoked host out of the parking promise

Holding a capability through an unverifiable probe is right; holding it through
the host's own refusal is not. `blocked` (auth rejected, protocol mismatch) stops
every retry for good, and parking trades the client's only copy of the scrollback
for a host-side restore that can then never happen -- the destructive direction.
`isRuntimeHostContactRevoked` names that one terminal verdict once, and the
connection-state derivation now reads it too so there is a single definition.

Also narrows the transport hint to 'connecting'. 'unknown' means no transport was
ever attempted, which is the permanent state of an unreachable paired host: as
'checking' its row lost its Connect action and the status bar read "connecting"
for the whole session.

* test(runtime): pin the parking gate against over-firing on a flap
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