Skip to content

fix(runtime): hold the session mirror through an unverifiable probe - #20085

Merged
nwparker merged 2 commits into
mainfrom
nwparker/mirror-holds-unverifiable-host
Sep 17, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/mirror-holds-unverifiable-host

Conversation

@nwparker

@nwparker nwparker commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​342 $\color{#cf222e}{\Huge{\mathbf{−}}}$​7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​335
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​44 $\color{#cf222e}{\Huge{\mathbf{−}}}$​7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​37

The defect

Two derivations read the same host state and reached opposite verdicts, and the destructive one won.

When a host's status probe comes back unverifiable over a transport that is still ready:

  • runtimeHostConnectionStateForEntry calls the entry runtime-unavailable — i.e. connected.
  • getReachableRuntimeSessionMirrorTargets called it gone, and dropped it.
verified snapshot -> mirror targets: [{ environmentId: 'env-a', runtimeId: 'rt-1' }]
snapshot(verification:'unavailable', transport:'ready')
  entry: { status: null, snapshot.status: { runtimeId: 'rt-1' } }
  mirror targets: []

User impact: the session-tab mirror for that host was torn down and cold-rebuilt while the host's flows were still delivering.

This is docs/reference/ssh-execution-boundary.md violated: the verdict vocabulary is live / unverifiable / exited with no synonyms, and loss of contact is never evidence of process death. An unverifiable probe was being treated as an exit verdict by one reader while another correctly treated it as still-connected.

Root cause

applyRuntimeHostStatusSnapshot (runtime-status-snapshot.ts:29) nulls entry.status for any non-verified probe:

status: snapshot.verification === 'verified' && !snapshot.retired ? snapshot.status : null

while snapshot.status retains the last verified runtime identity. runtimeHostConnectionStateForEntry consults the snapshot and gets the right answer. The mirror-target reader only read entry.status, so it saw null and concluded the host was gone.

One concept, two implementations. The fix is not to make the destructive reader less destructive — it is to make there be one answer.

Why the obvious fix alone would strand the mirror

Simply holding the target through the outage strands it, because today's teardown is what restores it. I verified each link rather than assuming:

  • The mirror subscription is installed by the effect at web-session-tabs-sync/use-web-session-tabs-sync.ts:78-91, whose only deps are [runtimeSessionMirrorEnvironmentKey, workspaceSessionReady] → installGlobalSessionTabsSubscriptions.
  • A stream { type: 'end' } frame is dropped without resubscribing (global-session-events.ts:85 falls through if (event.type !== 'snapshot' && event.type !== 'updated') return).
  • window-visibility-subscription-parking.ts retries only a rejected subscribe() call, never an ended stream.

So nothing but that effect re-running restores the mirror. The env leaving the key and re-entering it was the recovery.

The fix

Three files, no retry, no timer, no reconciliation sweep, no third predicate.

  1. shared/runtime-host-status.ts — lastVerifiedRuntimeStatus() becomes the single definition of "the last identity the host actually answered with". runtime-status.ts already had this inline as previousVerifiedStatus and now calls it, so there is one spelling instead of two.

  2. runtime-session-mirror-targets.ts — asks the shared connection verdict instead of entry.status, gated on isDisconnectedRuntimeHostState. That predicate is already documented in this repo as "Only this verdict earns the destructive glyph. 'checking' and 'reconnecting' are unverifiable, not down." Dropping a mirror is a destructive read, so it earns the same gate.

  3. runtime-status.ts — regaining contact advances the connection epoch, giving recovery its own trigger that means "the host is back," rather than restoring the mirror as a side effect of having destroyed it.

The connection epoch is not the runtime session: a same-runtime return fires no restart hook, no provider session bump, and no toast. The #19241 first-publication guard is preserved.

One thing I got wrong

I first gated on isConnectedRuntimeHostState. That was wrong — it would have newly dropped targets on checking, adding a teardown where main has none. Caught by enumerating every verdict against current behavior. isDisconnectedRuntimeHostState is monotone against main everywhere except a closed control channel, where dropping now matches every other host surface.

This is one instance of a family

A reviewer who thinks they are approving a single-site fix will under-weight this. The same root cause — reading entry.status != null as a reachability verdict — appears at other readers. Sites I confirmed directly:

  • store/slices/runtime-environment-ssh-selectors.ts:15
  • hooks/ipc-events/runtime-environment-subscription-selection.ts:24
  • components/browser-pane/restored-client-hosted-recovery-window.ts:42
  • components/landing-preflight-runtime.ts:26

A parallel audit reports at least eight sites, four of them destructive — client-event streams unsubscribed for a live host (with the gap-replay path skipped, because the stream was closed deliberately), an SSH-generation bump that cold-rebuilds the client-event subscription for even the active host, the active workspace's tab list cold-reloading twice per probe blip, and the landing integration banner vanishing until a probe re-verifies. I have not independently reproduced those four; they are flagged here so this PR is not read as the whole problem.

lastVerifiedRuntimeStatus() is the intended reuse point for those sites.

Verification

Reproduction test was written and confirmed failing on main at 94c2f96 before any source change.

Mutation testing — 9 mutations, 0 survivors. Each re-introduces the specific regression an assertion claims to catch:

# Mutation Killed by
M1 mirror: reachability back to entry.status !== null 4
M2 mirror: isConnected instead of !isDisconnected 10
M3 mirror: never drop on the exit verdict 3
M4 mirror: drop the missing-identity guard 2
M5 shared: identity stops surviving loss of contact 4
M6 status: connectionChanged back to main 2
M7 status: advance on every answer, not just regained contact 1
M8 status: drop the first-publication guard 1
M9 status: advance once per condition (double bump) 2

Gates, each proven able to fail before being believed:

  • tsc -p config/tsconfig.tc.web.json / .node / .cli — clean (it reported 4 real errors first; an empty log is the pass state).
  • oxlint — clean; proven non-silent with a duplicate-identifier canary that exited 1.
  • oxfmt --check — clean.
  • vitest run --config config/vitest.config.ts src/renderer/src src/shared on a clean checkout of this exact SHA: 4416 files / 38987 tests, 0 failures.

src/main shows 12 failures under full-suite load that are unrelated to this change (Electron, real-CLI, real-zsh, and timing/throughput measurements); a base-vs-branch comparison is in progress and will be reported in a comment.

Pre-existing gap, deliberately not folded in

runtimeHostConnectionStateForEntry's snapshot branch handles transport: 'disconnected' and 'ready' but not 'connecting' / 'unknown', which fall through to a 'disconnected' verdict. Same defect family, but both readers now agree there, and changing it moves the host-status UI — that needs its own evidence and its own PR.

One pre-existing test updated

runtime-status-snapshot.test.ts asserted the connection generation stays put across an outage. Its stated intent is "without manufacturing a session restart or toast"; that intent is preserved and strengthened (asserts same runtimeId, ensureBrowserClientHostForRestartedRuntime not called, no toast). Only the epoch assertion changed, because the connection epoch is a distinct concept from the runtime session.

@coderabbitai

coderabbitai Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 71c41cdf-0caa-4a10-893a-924f801a92c6

📥 Commits

Reviewing files that changed from the base of the PR and between ef82ede and e7046b1.

📒 Files selected for processing (7)
  • src/renderer/src/lib/runtime-session-mirror-targets.test.ts
  • src/renderer/src/lib/runtime-session-mirror-targets.ts
  • src/renderer/src/lib/runtime-session-mirror-unverifiable-host.test.ts
  • src/renderer/src/store/slices/runtime-status-reconnect-connection-generation.test.ts
  • src/renderer/src/store/slices/runtime-status-snapshot.test.ts
  • src/renderer/src/store/slices/runtime-status.ts
  • src/shared/runtime-host-status.ts

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


📝 Walkthrough

Walkthrough

The change adds lastVerifiedRuntimeStatus to preserve host-answered runtime status across unverifiable probes. Runtime status handling now advances connection generations when contact resumes. Mirror target selection uses the host connection verdict and verified runtime ID. Tests cover reconnection, runtime replacement, unverifiable states, blocked or retired hosts, closed channels, and complete runtime status fixtures.

Priority: ⬇️ Low

Merge Risk: 🟡 Moderate · up to e7046

Repositories can be missing after startup until a later refresh when a host begins with an unverifiable status. Fix the first-publication transition before merging.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description provides detailed defect, root-cause, fix, scope, and verification information. It does not follow the required template structure and omits several required sections, including Visual… Reorganize the content under all required template headings. Add an actual linked issue after Fixes #. Add N/A with a reason for Visual Proof if there is no visual or interaction change. Complete the Testing, Review, Agent skill upstrea…
Docstring Coverage ⚠️ Warning Docstring coverage is 23.08% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 13 functions across 7 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: preserving the session mirror during an unverifiable host probe.
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.
Full details: Description check

Explanation

The description provides detailed defect, root-cause, fix, scope, and verification information. It does not follow the required template structure and omits several required sections, including Visual Proof, Testing checkboxes, Review, Notes, and Checklist.

Resolution

Reorganize the content under all required template headings. Add an actual linked issue after Fixes #. Add N/A with a reason for Visual Proof if there is no visual or interaction change. Complete the Testing, Review, Agent skill upstream boundary, Notes, and Checklist sections. Keep the existing technical analysis and verification details.

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

@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

  • Mirror reachability now uses the shared verdict — getReachableRuntimeSessionMirrorTargets gates the destructive drop on isDisconnectedRuntimeHostState(runtimeHostConnectionStateForEntry(entry)) and reads the runtime id via lastVerifiedRuntimeStatus, so an unverifiable probe over a ready transport no longer reads as "gone".
  • lastVerifiedRuntimeStatus accessor — new shared helper in src/shared/runtime-host-status.ts that prefers snapshot.status (retained across a loss of contact) over entry.status; runtime-status.ts reuses it in place of its inline previousVerifiedStatus, collapsing one spelling into one.
  • Regaining contact is its own recovery trigger — setRuntimeEnvironmentStatus advances the connection epoch on reconnectedAfterLostContact (same-runtime return after a null-status entry), so the mirror's "host is back" signal no longer depends on teardown. Restart hook, provider session bump, and toast stay gated on the runtime session, preserving the #19241 first-publication guard.
  • Tests — a failing-first reproduction, reconnect-generation and mirror-target suites, and one pre-existing snapshot test updated to assert the epoch advances without manufacturing a restart or toast.

I verified the snapshot producer (shared/runtime-host-status-owner.ts) never nulls snapshot.status on failure, that reconnectedAfterLostContact fires in every outage shape (transport drop, probe timeout, and their recovery), that the mirror key depends on connectionGeneration, and that the changed tests pass with a clean tsc -p config/tsconfig.tc.web.json.

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

@nwparker
nwparker force-pushed the nwparker/mirror-holds-unverifiable-host branch from d6e2033 to ef82ede Compare September 17, 2026 06:57
nwparker added a commit that referenced this pull request Sep 17, 2026
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.
nwparker added a commit that referenced this pull request Sep 17, 2026
…ration

`connectionGeneration` carried two meanings and one reader was always wrong.
holding the session mirror through an outage leaves its subscriptions stranded
and that edge was the only thing left to revive them. But the same value is the
mirror's cache key -- use-runtime-session-mirror-environment-key.ts keys the
subscription effect on it, every published frame is stamped with it, and
web-session-terminal-retirement-proof-ledger.ts drops retained proofs when it
moves. So the bump #20085 needed as a resubscribe signal re-keyed and rebuilt
the mirror after any brief flap, which is the #19647 symptom #19873/#20059 fix.

Measured first: with the reconnect bump deleted, an ended stream followed by
recovery issues zero resubscribes, and the mirror's subscribe call registers no
`onClose`, so main's terminal close is dropped. #20085's claim is true -- the
subscription really is dead after recovery -- so the trigger has to exist. It
just must not be the cache key.

Give each meaning its own value:

- `connectionGeneration` returns to identity only: a new runtime session, a
  re-pair, an explicit clear. A same-runtime return no longer moves it, so no
  stamp, fence or retained proof is invalidated by a flap.
- `hostContactEpoch` counts "the host answered again after we lost contact". It
  lives on the store entry and is read only as a dependency of the two
  subscription effects in use-web-session-tabs-sync.ts -- never passed to an
  installer, never part of `environmentKey`, so it cannot become a stamp.

`useRuntimeSessionMirrorEnvironmentKey` becomes
`useRuntimeSessionMirrorEnvironmentKeys`, returning `environmentKey` (identity)
and `resubscribeSignal` (the epoch edge) from the one target scan, so the hot
ownership scan is not doubled.

Each direction is pinned by its own test: removing the resubscribe dependency
fails only 'reinstalls both session-tabs subscriptions when the host answers
again'; restoring the reconnect bump fails only the two key-stability tests.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 6a6b91c0-b944-4396-9298-83b5311e49ca

📥 Commits

Reviewing files that changed from the base of the PR and between d6e2033 and ef82ede.

📒 Files selected for processing (3)
  • src/renderer/src/lib/runtime-session-mirror-unverifiable-host.test.ts
  • src/renderer/src/store/slices/runtime-status-reconnect-connection-generation.test.ts
  • src/renderer/src/store/slices/runtime-status.ts

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

Comment on lines +209 to 210
previous !== undefined && (runtimeSessionStarted || reconnectedAfterLostContact)
const activeEnvironmentId = s.settings?.activeRuntimeEnvironmentId?.trim()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

sed -n '150,225p' src/renderer/src/store/slices/runtime-status.ts
sed -n '1,80p' src/shared/runtime-host-status.ts
sed -n '1,190p' src/renderer/src/store/slices/runtime-status-reconnect-connection-generation.test.ts
rg -n "setRuntimeEnvironmentStatus|applyRuntimeHostStatusSnapshot|runtimeSessionStarted|reconnectedAfterLostContact|entryForSnapshot" src/renderer/src/store src/shared

Repository: stablyai/orca

Length of output: 27848


🏁 Script executed:

sed -n '1,120p' src/renderer/src/store/slices/runtime-status-snapshot.ts
sed -n '1,150p' src/renderer/src/store/slices/runtime-status-snapshot.test.ts
sed -n '1,110p' src/renderer/src/store/slices/runtime-status-first-publication.test.ts
sed -n '225,245p' src/renderer/src/store/slices/runtime-status.ts

Repository: stablyai/orca

Length of output: 11111


🏁 Script executed:

rg -n -C 4 "verification:\s*'checking'|verification:\s*'unavailable'|verification:\s*'blocked'|RuntimeHostStatusSnapshot" src | head -240

Repository: stablyai/orca

Length of output: 21122


Exclude an initial unverified snapshot from connection changes.

applyRuntimeHostStatusSnapshot stores an initial checking snapshot with status === null. The first verified snapshot then sets both runtimeSessionStarted and reconnectedAfterLostContact to true. Because previous exists, this advances the generation even though no connection existed.

Preserve reconnects from direct status entries, which are valid transitions.

Proposed fix
       const connectionChanged =
-        previous !== undefined && (runtimeSessionStarted || reconnectedAfterLostContact)
+        previous !== undefined &&
+        (previous.snapshot === undefined || previousVerifiedStatus != null) &&
+        (runtimeSessionStarted || reconnectedAfterLostContact)

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.
@nwparker
nwparker force-pushed the nwparker/mirror-holds-unverifiable-host branch from ef82ede to e7046b1 Compare September 17, 2026 07:23
nwparker added a commit that referenced this pull request Sep 17, 2026
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.
nwparker added a commit that referenced this pull request Sep 17, 2026
…ration

`connectionGeneration` carried two meanings and one reader was always wrong.
holding the session mirror through an outage leaves its subscriptions stranded
and that edge was the only thing left to revive them. But the same value is the
mirror's cache key -- use-runtime-session-mirror-environment-key.ts keys the
subscription effect on it, every published frame is stamped with it, and
web-session-terminal-retirement-proof-ledger.ts drops retained proofs when it
moves. So the bump #20085 needed as a resubscribe signal re-keyed and rebuilt
the mirror after any brief flap, which is the #19647 symptom #19873/#20059 fix.

Measured first: with the reconnect bump deleted, an ended stream followed by
recovery issues zero resubscribes, and the mirror's subscribe call registers no
`onClose`, so main's terminal close is dropped. #20085's claim is true -- the
subscription really is dead after recovery -- so the trigger has to exist. It
just must not be the cache key.

Give each meaning its own value:

- `connectionGeneration` returns to identity only: a new runtime session, a
  re-pair, an explicit clear. A same-runtime return no longer moves it, so no
  stamp, fence or retained proof is invalidated by a flap.
- `hostContactEpoch` counts "the host answered again after we lost contact". It
  lives on the store entry and is read only as a dependency of the two
  subscription effects in use-web-session-tabs-sync.ts -- never passed to an
  installer, never part of `environmentKey`, so it cannot become a stamp.

`useRuntimeSessionMirrorEnvironmentKey` becomes
`useRuntimeSessionMirrorEnvironmentKeys`, returning `environmentKey` (identity)
and `resubscribeSignal` (the epoch edge) from the one target scan, so the hot
ownership scan is not doubled.

Each direction is pinned by its own test: removing the resubscribe dependency
fails only 'reinstalls both session-tabs subscriptions when the host answers
again'; restoring the reconnect bump fails only the two key-stability tests.
@nwparker
nwparker merged commit 67dda9a into main Sep 17, 2026
34 checks passed
nwparker added a commit that referenced this pull request Sep 17, 2026
…#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 #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
nwparker added a commit that referenced this pull request Sep 17, 2026
…ration

`connectionGeneration` carried two meanings and one reader was always wrong.
holding the session mirror through an outage leaves its subscriptions stranded
and that edge was the only thing left to revive them. But the same value is the
mirror's cache key -- use-runtime-session-mirror-environment-key.ts keys the
subscription effect on it, every published frame is stamped with it, and
web-session-terminal-retirement-proof-ledger.ts drops retained proofs when it
moves. So the bump #20085 needed as a resubscribe signal re-keyed and rebuilt
the mirror after any brief flap, which is the #19647 symptom #19873/#20059 fix.

Measured first: with the reconnect bump deleted, an ended stream followed by
recovery issues zero resubscribes, and the mirror's subscribe call registers no
`onClose`, so main's terminal close is dropped. #20085's claim is true -- the
subscription really is dead after recovery -- so the trigger has to exist. It
just must not be the cache key.

Give each meaning its own value:

- `connectionGeneration` returns to identity only: a new runtime session, a
  re-pair, an explicit clear. A same-runtime return no longer moves it, so no
  stamp, fence or retained proof is invalidated by a flap.
- `hostContactEpoch` counts "the host answered again after we lost contact". It
  lives on the store entry and is read only as a dependency of the two
  subscription effects in use-web-session-tabs-sync.ts -- never passed to an
  installer, never part of `environmentKey`, so it cannot become a stamp.

`useRuntimeSessionMirrorEnvironmentKey` becomes
`useRuntimeSessionMirrorEnvironmentKeys`, returning `environmentKey` (identity)
and `resubscribeSignal` (the epoch edge) from the one target scan, so the hot
ownership scan is not doubled.

Each direction is pinned by its own test: removing the resubscribe dependency
fails only 'reinstalls both session-tabs subscriptions when the host answers
again'; restoring the reconnect bump fails only the two key-stability tests.
nwparker added a commit that referenced this pull request Sep 17, 2026
…ration (#20359)

* fix(runtime): split the host-contact epoch out of the connection generation

`connectionGeneration` carried two meanings and one reader was always wrong.
holding the session mirror through an outage leaves its subscriptions stranded
and that edge was the only thing left to revive them. But the same value is the
mirror's cache key -- use-runtime-session-mirror-environment-key.ts keys the
subscription effect on it, every published frame is stamped with it, and
web-session-terminal-retirement-proof-ledger.ts drops retained proofs when it
moves. So the bump #20085 needed as a resubscribe signal re-keyed and rebuilt
the mirror after any brief flap, which is the #19647 symptom #19873/#20059 fix.

Measured first: with the reconnect bump deleted, an ended stream followed by
recovery issues zero resubscribes, and the mirror's subscribe call registers no
`onClose`, so main's terminal close is dropped. #20085's claim is true -- the
subscription really is dead after recovery -- so the trigger has to exist. It
just must not be the cache key.

Give each meaning its own value:

- `connectionGeneration` returns to identity only: a new runtime session, a
  re-pair, an explicit clear. A same-runtime return no longer moves it, so no
  stamp, fence or retained proof is invalidated by a flap.
- `hostContactEpoch` counts "the host answered again after we lost contact". It
  lives on the store entry and is read only as a dependency of the two
  subscription effects in use-web-session-tabs-sync.ts -- never passed to an
  installer, never part of `environmentKey`, so it cannot become a stamp.

`useRuntimeSessionMirrorEnvironmentKey` becomes
`useRuntimeSessionMirrorEnvironmentKeys`, returning `environmentKey` (identity)
and `resubscribeSignal` (the epoch edge) from the one target scan, so the hot
ownership scan is not doubled.

Each direction is pinned by its own test: removing the resubscribe dependency
fails only 'reinstalls both session-tabs subscriptions when the host answers
again'; restoring the reconnect bump fails only the two key-stability tests.

* test(runtime): pin the mirror hydration verdict across a host flap

The generation tests assert the key string; this asserts what the user feels.
The mirror's hydration verdict is stamped with the connection generation, so any
bump discards it and every mirrored pane re-parks -- the tab-list rebuild. Held
across an unverifiable probe, still discarded when the runtime id actually moved.

* test(runtime): build real host statuses instead of casting partials
nwparker added a commit that referenced this pull request Sep 17, 2026
…ration

`connectionGeneration` carried two meanings and one reader was always wrong.
holding the session mirror through an outage leaves its subscriptions stranded
and that edge was the only thing left to revive them. But the same value is the
mirror's cache key -- use-runtime-session-mirror-environment-key.ts keys the
subscription effect on it, every published frame is stamped with it, and
web-session-terminal-retirement-proof-ledger.ts drops retained proofs when it
moves. So the bump #20085 needed as a resubscribe signal re-keyed and rebuilt
the mirror after any brief flap, which is the #19647 symptom #19873/#20059 fix.

Measured first: with the reconnect bump deleted, an ended stream followed by
recovery issues zero resubscribes, and the mirror's subscribe call registers no
`onClose`, so main's terminal close is dropped. #20085's claim is true -- the
subscription really is dead after recovery -- so the trigger has to exist. It
just must not be the cache key.

Give each meaning its own value:

- `connectionGeneration` returns to identity only: a new runtime session, a
  re-pair, an explicit clear. A same-runtime return no longer moves it, so no
  stamp, fence or retained proof is invalidated by a flap.
- `hostContactEpoch` counts "the host answered again after we lost contact". It
  lives on the store entry and is read only as a dependency of the two
  subscription effects in use-web-session-tabs-sync.ts -- never passed to an
  installer, never part of `environmentKey`, so it cannot become a stamp.

`useRuntimeSessionMirrorEnvironmentKey` becomes
`useRuntimeSessionMirrorEnvironmentKeys`, returning `environmentKey` (identity)
and `resubscribeSignal` (the epoch edge) from the one target scan, so the hot
ownership scan is not doubled.

Each direction is pinned by its own test: removing the resubscribe dependency
fails only 'reinstalls both session-tabs subscriptions when the host answers
again'; restoring the reconnect bump fails only the two key-stability tests.
ivanvykopal pushed a commit to ivanvykopal/orca that referenced this pull request Sep 20, 2026
…tablyai#20085)

* 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
ivanvykopal pushed a commit to ivanvykopal/orca that referenced this pull request Sep 20, 2026
…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
ivanvykopal pushed a commit to ivanvykopal/orca that referenced this pull request Sep 20, 2026
…ration (stablyai#20359)

* fix(runtime): split the host-contact epoch out of the connection generation

`connectionGeneration` carried two meanings and one reader was always wrong.
holding the session mirror through an outage leaves its subscriptions stranded
and that edge was the only thing left to revive them. But the same value is the
mirror's cache key -- use-runtime-session-mirror-environment-key.ts keys the
subscription effect on it, every published frame is stamped with it, and
web-session-terminal-retirement-proof-ledger.ts drops retained proofs when it
moves. So the bump stablyai#20085 needed as a resubscribe signal re-keyed and rebuilt
the mirror after any brief flap, which is the stablyai#19647 symptom stablyai#19873/stablyai#20059 fix.

Measured first: with the reconnect bump deleted, an ended stream followed by
recovery issues zero resubscribes, and the mirror's subscribe call registers no
`onClose`, so main's terminal close is dropped. stablyai#20085's claim is true -- the
subscription really is dead after recovery -- so the trigger has to exist. It
just must not be the cache key.

Give each meaning its own value:

- `connectionGeneration` returns to identity only: a new runtime session, a
  re-pair, an explicit clear. A same-runtime return no longer moves it, so no
  stamp, fence or retained proof is invalidated by a flap.
- `hostContactEpoch` counts "the host answered again after we lost contact". It
  lives on the store entry and is read only as a dependency of the two
  subscription effects in use-web-session-tabs-sync.ts -- never passed to an
  installer, never part of `environmentKey`, so it cannot become a stamp.

`useRuntimeSessionMirrorEnvironmentKey` becomes
`useRuntimeSessionMirrorEnvironmentKeys`, returning `environmentKey` (identity)
and `resubscribeSignal` (the epoch edge) from the one target scan, so the hot
ownership scan is not doubled.

Each direction is pinned by its own test: removing the resubscribe dependency
fails only 'reinstalls both session-tabs subscriptions when the host answers
again'; restoring the reconnect bump fails only the two key-stability tests.

* test(runtime): pin the mirror hydration verdict across a host flap

The generation tests assert the key string; this asserts what the user feels.
The mirror's hydration verdict is stamped with the connection generation, so any
bump discards it and every mirrored pane re-parks -- the tab-list rebuild. Held
across an unverifiable probe, still discarded when the runtime id actually moved.

* test(runtime): build real host statuses instead of casting partials
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