Repository navigation
fix(runtime): hold four more host reads through an unverifiable probe - #20095
Conversation
There was a problem hiding this comment.
Important
The web-tabs fix drops the disconnected guard its sibling mirror code keeps, so a blocked/retired host now holds its active session.tabs.subscribe instead of tearing it down — the inverse of the bug being fixed (see inline).
Reviewed changes
runtime-environment-subscription-selection.ts—getRuntimeClientEventEnvironmentIdsandgetReachableRuntimeEnvironmentIdsnow derive membership from the sharedisConnectedRuntimeHostState(runtimeHostConnectionStateForEntry(...))verdict via a file-localisRuntimeHostStillInContact, so an unverifiable-but-ready host stays in both sets.runtime-environment-ssh-selectors.ts—isEnvironmentReachablecomposes the same verdict, keeping mirrored SSH rows for a ready host whose probe went unverifiable.landing-preflight-runtime.ts— reachability now derives from the shared verdict instead ofstatus === null.use-web-session-tabs-sync.ts—activeWorktreeRuntimeIdreadslastVerifiedRuntimeStatus(entry)?.runtimeIdinstead ofentry.status?.runtimeId.- Three new test files covering held-through-blip and still-drops transport-down / retired / no-entry cases for the verdict-based sites, and hold-vs-restart for the web-tabs site.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
| const environmentId = getExplicitRuntimeEnvironmentIdForWorktree(state, state.activeWorktreeId) | ||
| return environmentId | ||
| ? (state.runtimeStatusByEnvironmentId.get(environmentId)?.status?.runtimeId ?? null) | ||
| ? (lastVerifiedRuntimeStatus(state.runtimeStatusByEnvironmentId.get(environmentId)) |
There was a problem hiding this comment.
lastVerifiedRuntimeStatus drops the disconnected guard the sibling mirror code keeps (lib/runtime-session-mirror-targets.ts:55). A blocked or retired host retains its last snapshot.status, so this returns the stale runtimeId and keeps the active session.tabs.subscribe alive for a host that is gone — the inverse of the bug this PR fixes, where the old entry.status?.runtimeId read (nulled on any non-verified probe) tore it down.
Technical details
# web-tabs site loses the disconnected guard
## Affected sites
- src/renderer/src/runtime/web-session-tabs-sync/use-web-session-tabs-sync.ts:45 — reads `lastVerifiedRuntimeStatus(entry)?.runtimeId` with no `disconnected` verdict guard.
- src/renderer/src/lib/runtime-session-mirror-targets.ts:55 — the #20085 sibling, which correctly guards with `isDisconnectedRuntimeHostState(runtimeHostConnectionStateForEntry(entry))` before reading the same helper.
## Why it regresses
- `runtimeHostConnectionStateForEntry` maps `retired` and `verification === 'blocked'` to `'disconnected'` (runtime-host-connection-state.ts:123), which the four verdict-based sites in this PR drop correctly.
- `lastVerifiedRuntimeStatus` = `snapshot.status ?? status ?? null` with no retired/blocked guard. `RuntimeHostStatusOwner.dispose()` and `authenticationRejected()` both merge patches that keep `snapshot.status` (the last verified identity), so a previously-verified host that becomes `blocked`/`retired` still yields a non-null `runtimeId`.
- Result: `activeWorktreeRuntimeId` stays `'runtime-a'`, so the effect does not tear down `installActiveSessionTabsSubscription`; the stale tab mirror persists and the subscribe errors are only logged (active-session-subscription.ts:236-238, 274-278), never uninstalled.
## Required outcome
- A `blocked`/`retired` host must tear down the active session-tabs subscription exactly as the old `entry.status?.runtimeId` read did, while an `unverifiable`-but-ready host (and `reconnecting`/`checking`) keeps it.
## Suggested approach
- Mirror the sibling: derive the verdict, return `null` when `isDisconnectedRuntimeHostState(runtimeHostConnectionStateForEntry(entry))`, and only then read `lastVerifiedRuntimeStatus(entry)?.runtimeId`. This keeps `runtime-unavailable`, `reconnecting`, and `checking` holding, while `blocked`/`retired` (→ `disconnected`) drop.
- Add a `blocked`/`retired` case to `web-session-tabs-sync-unverifiable-host.test.tsx` asserting the subscription is unsubscribed/not re-held, since the current mutation table omits it.d6e2033 to
ef82ede
Compare
1292d5b to
ae5e9f7
Compare
Two derivations read the same host state and reached opposite verdicts, and the destructive one won. When a status probe came back unverifiable over a still-ready transport, runtimeHostConnectionStateForEntry called the host 'runtime-unavailable' (connected) while getReachableRuntimeSessionMirrorTargets dropped it, tearing down and cold-rebuilding the session-tab mirror while the host's flows were still delivering. The root cause is that applyRuntimeHostStatusSnapshot nulls entry.status for any non-verified probe while the snapshot retains the runtime identity. The connection-state reader consults the snapshot; the mirror-target reader did not. Give both readers one answer: - lastVerifiedRuntimeStatus() in shared/runtime-host-status.ts is now the single definition of "the last identity the host answered with". runtime-status.ts already had this inline as previousVerifiedStatus and now calls it. - The mirror-target reader asks the shared connection verdict instead of entry.status, gated on isDisconnectedRuntimeHostState -- only the one exit verdict earns a destructive read, per docs/reference/ssh-execution-boundary.md. 'checking' and 'reconnecting' are unverifiable, not evidence of an exit. Holding the target through the outage would strand the mirror on its own: the subscription is installed by the effect in use-web-session-tabs-sync.ts keyed on useRuntimeSessionMirrorEnvironmentKey(), a stream 'end' frame is dropped without resubscribing, and the parking layer retries only a rejected subscribe call. The teardown was the recovery. So regaining contact now advances the connection epoch, giving recovery its own "the host is back" trigger rather than leaving the mirror to be restored as a side effect of having been destroyed. The connection epoch is not the runtime session: a same-runtime return fires no restart hook, no provider session bump, and no toast.
Siblings of the session-mirror defect fixed in #20085. runtime-status-snapshot nulls `entry.status` for any non-verified probe while the snapshot retains the host's identity, so a host with a ready transport that is still delivering reads as gone to anything gating on `entry.status != null`. - client-event subscription selection dropped the stream for such a host, and its disconnect edge bumped the SSH generation, rebuilding even the active host's subscription - the web client's active session-tabs stream tore down and cold-rebuilt, twice per blip - landing preflight discarded its whole result - runtime-aware SSH selectors blanked mirrored target rows Each now reads the shared verdict, isConnectedRuntimeHostState of runtimeHostConnectionStateForEntry, or lastVerifiedRuntimeStatus where the read is host identity rather than reachability. No new predicate: every "genuinely gone" case is byte-identical, so nothing gains a retry loop.
ef82ede to
e7046b1
Compare
ae5e9f7 to
e17ac8e
Compare
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (14)
📝 WalkthroughWalkthroughThe change adds a shared helper for retrieving the last verified runtime status. Runtime reachability now uses shared host connection verdicts across preflight, subscriptions, SSH selectors, and mirror target selection. Session tab synchronization preserves the last verified runtime identity during unverifiable probes. Connection generation now advances when contact returns after an outage. New tests cover ready transports, disconnected transports, retired hosts, checking states, remote-control closure, reconnection, and runtime replacement. ✨ Finishing Touches📝 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 |
…stablyai#20095) * fix(runtime): hold the session mirror through an unverifiable probe Two derivations read the same host state and reached opposite verdicts, and the destructive one won. When a status probe came back unverifiable over a still-ready transport, runtimeHostConnectionStateForEntry called the host 'runtime-unavailable' (connected) while getReachableRuntimeSessionMirrorTargets dropped it, tearing down and cold-rebuilding the session-tab mirror while the host's flows were still delivering. The root cause is that applyRuntimeHostStatusSnapshot nulls entry.status for any non-verified probe while the snapshot retains the runtime identity. The connection-state reader consults the snapshot; the mirror-target reader did not. Give both readers one answer: - lastVerifiedRuntimeStatus() in shared/runtime-host-status.ts is now the single definition of "the last identity the host answered with". runtime-status.ts already had this inline as previousVerifiedStatus and now calls it. - The mirror-target reader asks the shared connection verdict instead of entry.status, gated on isDisconnectedRuntimeHostState -- only the one exit verdict earns a destructive read, per docs/reference/ssh-execution-boundary.md. 'checking' and 'reconnecting' are unverifiable, not evidence of an exit. Holding the target through the outage would strand the mirror on its own: the subscription is installed by the effect in use-web-session-tabs-sync.ts keyed on useRuntimeSessionMirrorEnvironmentKey(), a stream 'end' frame is dropped without resubscribing, and the parking layer retries only a rejected subscribe call. The teardown was the recovery. So regaining contact now advances the connection epoch, giving recovery its own "the host is back" trigger rather than leaving the mirror to be restored as a side effect of having been destroyed. The connection epoch is not the runtime session: a same-runtime return fires no restart hook, no provider session bump, and no toast. * test(runtime): drop the redundant status casts the new casting gate rejects * fix(runtime): hold four more host reads through an unverifiable probe Siblings of the session-mirror defect fixed in stablyai#20085. runtime-status-snapshot nulls `entry.status` for any non-verified probe while the snapshot retains the host's identity, so a host with a ready transport that is still delivering reads as gone to anything gating on `entry.status != null`. - client-event subscription selection dropped the stream for such a host, and its disconnect edge bumped the SSH generation, rebuilding even the active host's subscription - the web client's active session-tabs stream tore down and cold-rebuilt, twice per blip - landing preflight discarded its whole result - runtime-aware SSH selectors blanked mirrored target rows Each now reads the shared verdict, isConnectedRuntimeHostState of runtimeHostConnectionStateForEntry, or lastVerifiedRuntimeStatus where the read is host identity rather than reachability. No new predicate: every "genuinely gone" case is byte-identical, so nothing gains a retry loop. * test(runtime): build real host statuses instead of casting partials

Stacked on #20085 — it introduces
lastVerifiedRuntimeStatus(), which this branch imports. Rebase ontomainonce #20085 lands.runtime-status-snapshot.ts:29nullsentry.statusfor any non-verifiedprobe, while the snapshot separately retains the host's runtime identity. A host that is genuinely reachable — transportready, flows still delivering — therefore hasentry.status === nullwhenever its last probe was merely unverifiable. Every reader gating onentry.status != nullmisreads that live host as gone. #20085 fixed one instance; these are its siblings.Governing rule:
docs/reference/ssh-execution-boundary.md— verdicts arelive/unverifiable/exited, no synonyms, and loss of contact is never evidence of process death.The two findings that matter most
The client-event stream case is the worst of the family, because the failure is self-concealing. The stream is closed deliberately by the subscription reconciler, so the gap-replay path that normally recovers a dropped stream never runs — there is no gap to detect. The user loses worktree-appearance,
sshStateChanged,automationsChangedand Linear events from a host whose terminals keep streaming the whole time, with nothing anywhere indicating why. It recovers only if a later probe happens to verify.The wrong-explanation cases are worse than the silent ones, not better.
client-creation-action-policy.tshides "New browser tab" on the paired-web surface with the reason "this web client's paired runtime does not support browser streaming", andassertRuntimeManagedBrowserCreationAvailablethrows the same text mid-action — for a host that is merely unprobed and fully capable. That sends the next person to debug a capability negotiation that is not the problem. A reviewer will instinctively rank these below the destructive ones; they should not be. (Not fixed here — see Left alone.)Fixed
Five call sites across four files, each with a failing test written first.
hooks/ipc-events/runtime-environment-subscription-selection.tsisRuntimeHostStillInContact, shared by both selectorsstore/slices/runtime-environment-ssh-selectors.tsisEnvironmentReachable-> same compositioncomponents/landing-preflight-runtime.tsruntime/web-session-tabs-sync/use-web-session-tabs-sync.ts?.status?.runtimeId->lastVerifiedRuntimeStatus(entry)?.runtimeIdNo new predicate. The reachability sites compose two primitives that already exist and are already the shared vocabulary —
isConnectedRuntimeHostState(runtimeHostConnectionStateForEntry(entry)). The web-tabs site is not a reachability read at all: it wants the last identity the host answered with, which is exactly whatlastVerifiedRuntimeStatus()is for.User-facing consequence of each
getRuntimeClientEventEnvironmentIdsruntime-client-events-sync.ts:138-144unsubscribes its client-event stream. See above.getReachableRuntimeEnvironmentIdsmarkEnvironmentSshStateStale-> advances the SSH generation, which is a component ofbuildRuntimeClientEventEnvironmentKey. So even the active host — otherwise pinned into the desired set unconditionally — gets its subscription torn down and cold-rebuilt. Spurious project refresh on recovery.use-web-session-tabs-sync.ts:42activeWorktreeRuntimeIdflips tonull; it is an effect dep, soinstallActiveSessionTabsSubscriptiontears down and cold-rebuilds. The paired web client's active tab list reloads through a fresh snapshot round-trip — twice per blip, out and back.landing-preflight-runtime.ts:22invalidatePreflightStatus()wipespreflightStatusto null and drops the visibility/focus listeners. The landing page's integration banner vanishes until a probe verifies again.runtime-environment-ssh-selectors.ts:15selectRuntimeAwareSshStatus/Errorreturnnull— mirrored SSH target rows blank out while their sessions are live. Conservative: hides, tears nothing down.Mutation table — the four verdict-based sites
checkingconnectedworkspace-window-closedruntime-unavailablereconnectingcheckingdisconnecteddisconnecteddisconnected(fall-through gap)runtime-unavailableconnected/disconnectedOne intended cell flips. Every "genuinely gone" cell is byte-identical, so no host gains a permanent retry loop — that was the trap in the obvious fix (see Got wrong).
Mutation table —
use-web-session-tabs-syncruntime-aruntime-aruntime-aruntime-anull-> tears downruntime-a, heldruntime-b(host restart)runtime-b, restartsruntime-b, restartsnullnullBoth directions asserted, so the test distinguishes "held through a blip" from "never restarts".
Full inventory
Every reader of the nulled field, classified. The three sites originally handed over are marked with an asterisk.
Destructive — tears state down on a live host. All four fixed here:
runtime-environment-subscription-selection.ts:24* and:36,use-web-session-tabs-sync.ts:42,landing-preflight-runtime.ts:22.Conservative — under-reports, hides something.
runtime-environment-ssh-selectors.ts:15* — fixed.selectRuntimeAwareSshTargetRemovedreturnsfalse, which was already safe.browser-pane/restored-client-hosted-recovery-window.ts:42* — the 45s clock never starts, and a mid-wait blip restarts it (the effect cleanup clears the timer). A restored client-hosted page spins indefinitely instead of offering the unavailable/reopen notice. Not fixed — see below.settings/runtime-server-row.tsx:62,67— the Settings host row flips to'error'. The same component computesconnectionStatethrough the snapshot-aware path, so the two disagree within one component.client-creation-action-policy.ts:72,98— the wrong-explanation case described above.Capability / metadata reads that go null by accident. Same root cause, different shape: these read host identity (
capabilities,hostPlatform,pairedDeviceId), which never changes without the host answering, so they should all readlastVerifiedRuntimeStatus()and can never legitimately go null on a blip.client-creation-action-policy.ts:72,98(wrong-reason hide + throw);web-runtime-browser-creation-context.ts:78,90andworkspace-browser-tab-open.ts:52(browser creation loses the host's capability set and device scope mid-blip);terminal-input-host-platform.ts:75,98(host platform falls back, so keybinding/path behaviour silently switches platform under the user).paired-runtime-parking-capabilities.ts:37feedscanWatcherCoverParkedTerminalTab, andpty-connection/paired-parked-terminal-restore.ts:17feedsdeferred-session-reattach-choice.ts:96. Both plausibly affect whether a paired terminal parks or reattaches, but the reattach decision tree there has several interacting branches and the user-facing outcome could not be proven without more work than the evidence justified. Flagged, not claimed.sidebar/workspace-creator-visibility.ts:19, which falls back toenvironment.pairedDeviceIdfrom the environment record.Not this bug — already correct.
SshStatusSegment.tsx:116,NoticeHostGlyph.tsx:40,use-worktree-card-foundation.ts:191,RepositoryHostSetupsSection.tsx:230all route throughruntimeHostConnectionStateForEntry.shared/execution-host-registry.ts:162-166doesstatus ?? snapshot?.statusplus snapshot-aware health — a third inline implementation of the concept, but a correct one.Beyond the three sites originally handed over
Two findings nobody had flagged:
use-web-session-tabs-sync.ts:42is the web twin of fix(runtime): hold the session mirror through an unverifiable probe #20085 — the same defect, the same consequence, on the paired-web path instead of the desktop path. Fixed here.runtime-status-snapshot.ts:29usesverification === 'verified' && !snapshot.retiredand mergesremoteControlinto the status.runtime-status-refresh.ts:25uses onlyverification === 'verified'and does neither. A retired host therefore publishes a non-nullentry.statusthrough the manual-refresh path andnullthrough the event path. Not touched — it is writer-side, adjacent to fix(runtime): hold the session mirror through an unverifiable probe #20085's territory.Left alone, deliberately
runtimeHostConnectionStateForEntryfall-through gap.transport: 'connecting'with a failed probe yieldsdisconnected; the right mapping under the boundary rule ischecking. Reported, not fixed: five sites in this PR now route through that function, and so does fix(runtime): hold the session mirror through an unverifiable probe #20085. Changing it flipsisDisconnectedRuntimeHostStatetofalsefor a connecting host, which changes fix(runtime): hold the session mirror through an unverifiable probe #20085's mirror-retention decision inside its own file. That is its author's call. (isConnectedRuntimeHostStatestaysfalseeither way, so nothing in this PR moves.)runtime-server-row.tsx— a product decision. "Show error when the probe failed" is defensible; that one component derivesconnectionStatesnapshot-aware andstatusnot is the actual inconsistency, and picking the winner is a design call.restored-client-hosted-recovery-window.ts— correct under the rule, but fixing it changes when a user-facing notice appears. Notice timing is a product decision.runtime-status-refresh.ts.Got wrong, and how it was caught
lastVerifiedRuntimeStatus(entry) != nullwas the first choice at the subscription site. Walking the mutation table before writing code showed that keeps a genuinely-down host (transport: 'disconnected') desired forever, adding a permanent 30s-cap subscribe retry loop against a dead host. Switched toisConnectedRuntimeHostState, which leaves every disconnected cell untouched.:20-22. TracingmarkEnvironmentSshStateStale-> SSH generation ->buildRuntimeClientEventEnvironmentKeyshowed the active host's subscription is rebuilt too.Verification
Each gate was proven able to fail before its silence was trusted: a deliberate
TS2322in a touched file produced errors fromconfig/tsconfig.tc.web.json(clean after revert); an unusedvarmadeoxlintexit 1 (these files exit 0); the three new tests failed 3/3, 1/2 and 1/2 respectively before the fixes, with their negative controls passing throughout.Full renderer suite after the fixes: 3723 files / 31189 tests passed, 2+6 skipped, zero
FAILlines in the grepped log.tsconfig.tc.web.jsonandtsconfig.node.jsonboth clean.oxfmtapplied.