Repository navigation
fix(runtime): an outage is not a handle-gap verdict - #20059
Conversation
There was a problem hiding this comment.
ℹ️ No critical issues — the guard is correct and its own test is falsifiable; one test-coverage gap on the
reconnectingbranch and one dependency observation below.
Reviewed changes
- Outage guard —
host-mirror-handle-gap-wait.tsaddsenvironmentContactIsLost(disconnectedorreconnecting) and skips recording an expired handle-gap verdict when the environment is out of contact, so a deadline expiring mid-outage no longer authorizes a resume the host is still running. - Resume test —
host-mirror-handle-gap-resume.test.tsaddsdoes not turn an outage into a verdict when the environment dropped mid-parkplus two store-seeding helpers; it is falsifiable (forcingenvironmentContactIsLostto returnfalsekills exactly this test). - Dependency-visible (#19873 / #19647) —
runtimeHostConnectionStateForEntry+isDisconnectedRuntimeHostStateland here as visible dependencies;NoticeHostGlyph/use-worktree-card-foundationstop dimming unprobed hosts; the status-recheck ladder re-probes null verdicts and preserves live verdicts across unverifiable probes.
ℹ️ "Not-probed ≠ disconnected" is fixed on only one of the two derivations (belongs to #19873)
NoticeHostGlyph and use-worktree-card-foundation now read an unprobed host as checking, but the shared buildExecutionHostRegistry (src/shared/execution-host-registry.ts, runtimeHealth) still returns 'disconnected' for !status. The registry feeds the sidebar host options, HostSectionHeader, composer targets, and task-page hosts, so those still dim an unprobed host while the worktree card does not. The divergence is introduced by #19873 (visible here as a dependency), not by this PR's commit — flagging so it stays tracked, not as a merge-blocker.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
| const connectionState = runtimeHostConnectionStateForEntry( | ||
| useAppStore.getState().runtimeStatusByEnvironmentId.get(environmentId) | ||
| ) | ||
| return isDisconnectedRuntimeHostState(connectionState) || connectionState === 'reconnecting' |
There was a problem hiding this comment.
The || connectionState === 'reconnecting' clause is untested. The new resume case drives disconnected via { status: null }, but after #19647 the outage-over-a-live-mirror state is reconnecting (live status preserved, remoteControl refreshed to reconnecting); and { status: null } drops the environment from getReachableRuntimeSessionMirrorTargets, which retracts the row and releases the waiter before this deadline path can run. Removing the clause would leave the suite green while regressing the primary production path.
Technical details
# Cover the reconnecting branch of the outage guard
## Affected sites
- src/renderer/src/lib/host-mirror-handle-gap-wait.ts:174 — `|| connectionState === 'reconnecting'` has no integration coverage.
- src/renderer/src/lib/host-mirror-handle-gap-resume.test.ts:143 — helper only seeds `{ status: null }` (→ `disconnected`).
## Required outcome
- A test that seeds a LIVE status whose `remoteControl.state === 'reconnecting'` and asserts the handle-gap wait skips the verdict (pane stays parked, no resume claim), mirroring the existing `does not turn an outage into a verdict` case.
## Open questions
- Is `{ status: null }` (→ `disconnected`) actually reachable at the deadline in production, or always preempted by row retraction via `getReachableRuntimeSessionMirrorTargets`? If preempted, the existing test pins a branch the guard never sees while the reachable `reconnecting`/`closed` branches go unpinned.1200ad2 to
cb29f42
Compare
1a6b4ce to
ef969b8
Compare
There was a problem hiding this comment.
Reviewed changes
- Writer-guard comment restated —
runtime-status.tsrewords the #19647 guard comment into #20003's vocabulary; the guard line itself is unchanged. Accurate: a null, snapshot-less entry only comes fromrefreshRuntimeEnvironmentStatus's throw branch, andRuntimeHostStatusOwner.completepreservessnapshot.statuson failure while patching onlycheckedAt/verification. - E2E gate demoted to diagnostic —
paired-remote-terminal-tab-switch-reconnect.spec.tsreplacesexpect(flapped.sawNullStatus).toBe(false)with a logged diagnostic. Correct: post-#20003,applyRuntimeHostStatusSnapshotderivesentry.statusfromverification === 'verified', so an outage nullsentry.statusby design while the live verdict lives insnapshot.status; the survivinggenerationAfterRecovery === generationBeforeFlapandfinalObservation.mountedgates still fail on the unfixed writer.
ℹ️ No new issues in this incremental delta. The prior review's
reconnectingcoverage gap inhost-mirror-handle-gap-resume.test.tsis not addressed by these commits, so this is a non-approving delta review.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
cb29f42 to
e652df2
Compare
📝 WalkthroughWalkthroughThe change adds bounded waiting for host-mirror PTY handles before sleeping-agent resume. It records generation- and binding-specific expiry verdicts, drains waiters on handles or row removal, and cleans up verdicts during environment teardown. Replay failures no longer interrupt sibling waiters. Runtime status refreshes preserve established live status after failed probes. Tests cover renderer behavior, runtime hydration, SSH resume handling, paired reconnects, and sidebar connectivity states. Priority: ➖ Normal Merge Risk: 🟡 Moderate · up to The main reconnect regression may remain undetected because its test does not prove the fault occurred. Strengthen these assertions before merging; also move sidebar screenshots after UI assertions. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 2📝 Generate docstrings 💡
🛠️ Fix failing CI checks 💡
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 |
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: efedb06d-76b6-419a-81fe-3464b3ce6257
📒 Files selected for processing (21)
src/renderer/src/lib/host-mirror-handle-gap-drain.test.tssrc/renderer/src/lib/host-mirror-handle-gap-landed-handle.test.tssrc/renderer/src/lib/host-mirror-handle-gap-replay-containment.test.tssrc/renderer/src/lib/host-mirror-handle-gap-resume.test.tssrc/renderer/src/lib/host-mirror-handle-gap-subscription-lifetime.test.tssrc/renderer/src/lib/host-mirror-handle-gap-teardown.test.tssrc/renderer/src/lib/host-mirror-handle-gap-verdict-union.test.tssrc/renderer/src/lib/host-mirror-handle-gap-wait.tssrc/renderer/src/lib/host-mirrored-pane-liveness.tssrc/renderer/src/lib/resume-sleeping-agent-session-provider-claim.test.tssrc/renderer/src/lib/resume-sleeping-agent-session.tssrc/renderer/src/lib/sleeping-agent-pane-ownership.tssrc/renderer/src/lib/ssh-failed-target-sleeping-agent-resume.test.tssrc/renderer/src/runtime/host-session-mirror-hydration-drain.test.tssrc/renderer/src/runtime/host-session-mirror-hydration.tssrc/renderer/src/runtime/web-session-tabs-sync/tracking-lifecycle.tssrc/renderer/src/store/slices/runtime-status.test.tssrc/renderer/src/store/slices/runtime-status.tstests/e2e/helpers/runtime-endpoint-link-fault.tstests/e2e/paired-remote-terminal-tab-switch-reconnect.spec.tstests/e2e/sidebar-runtime-host-disconnected-glyph.spec.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.
| console.log( | ||
| `[tab-switch-repro] dials at the hop: accepted=${link.acceptedConnectionCount()} stalled=${link.stalledConnectionCount()}` | ||
| ) | ||
|
|
||
| // ---- Arm B2: the reporter's "reconnecting" state. Sever the established flows | ||
| // once while new dials still hang, so the shared-control socket enters | ||
| // `reconnecting` and the status recheck ladder arms. What the store does with | ||
| // the resulting failed status.get is the writer under test: a live verdict must | ||
| // not become `status: null` because the client could not ask. | ||
| const generationBeforeFlap = ( | ||
| await observePane(client.page, target.webTabId, client.environmentId, 0) | ||
| ).connectionGeneration | ||
| const dropped = link.dropEstablished() |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
sed -n '390,535p' tests/e2e/paired-remote-terminal-tab-switch-reconnect.spec.tsRepository: stablyai/orca
Length of output: 7952
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- candidate symbols ---'
rg -n "function (recordRevealTimeline|observePane)|const (recordRevealTimeline|observePane)|recordRevealTimeline|observePane|class .*Link|stalledConnectionCount|dropEstablished|connectionGeneration|acceptedConnectionCount" tests/e2e src | head -n 240
printf '%s\n' '--- file outline ---'
ast-grep outline tests/e2e/paired-remote-terminal-tab-switch-reconnect.spec.ts
printf '%s\n' '--- file size ---'
wc -l tests/e2e/paired-remote-terminal-tab-switch-reconnect.spec.tsRepository: stablyai/orca
Length of output: 30266
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- pane and timeline helpers ---'
sed -n '220,330p' tests/e2e/paired-remote-terminal-tab-switch-reconnect.spec.ts
printf '%s\n' '--- fault link helper ---'
sed -n '1,145p' tests/e2e/helpers/runtime-endpoint-link-fault.ts
printf '%s\n' '--- test setup and Arm A assertions ---'
sed -n '1,220p' tests/e2e/paired-remote-terminal-tab-switch-reconnect.spec.ts
sed -n '330,430p' tests/e2e/paired-remote-terminal-tab-switch-reconnect.spec.tsRepository: stablyai/orca
Length of output: 20316
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- runtime status generation definitions and updates ---'
rg -n -C 4 "runtimeStatusByEnvironmentId|connectionGeneration" src/renderer/src/store src/renderer/src/hooks | head -n 320
printf '%s\n' '--- pane parking/disconnect references ---'
rg -n -C 4 "transportUnsubscribe|unsubscribe.*transport|cold.?park|park.*pane|runtimeStatusByEnvironmentId.*delete|delete.*runtimeStatusByEnvironmentId" src/renderer/src tests/e2e/helpers tests/e2e/paired-remote-terminal-tab-switch-reconnect.spec.ts | head -n 320Repository: stablyai/orca
Length of output: 50369
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- runtime-related source files ---'
rg --files src/renderer/src | rg 'runtime-status|runtime-environment|ipc-events.*runtime|agent-status'
printf '%s\n' '--- exact runtime status writers ---'
rg -n -C 6 "setRuntimeStatus|runtimeStatusByEnvironmentId:|runtimeStatusByEnvironmentId\\.set|runtimeStatusByEnvironmentId\\.delete|connectionGeneration.*status|status.*connectionGeneration" src/renderer/src --glob '!*.test.*' --glob '!*.test.tsx' | head -n 260Repository: stablyai/orca
Length of output: 35990
🏁 Script executed:
#!/bin/bash
set -e
sed -n '150,275p' src/renderer/src/store/slices/runtime-status.ts
printf '%s\n' '--- callers of status cleanup and disconnect ---'
rg -n -C 5 "clearRuntimeEnvironmentStatus|removeRuntimeEnvironmentStatus|dropRuntimeEnvironmentStatus|retainRuntimeEnvironmentStatuses|setRuntimeEnvironmentStatus\\(" src/renderer/src --glob '!*.test.*' --glob '!*.test.tsx' | head -n 260Repository: stablyai/orca
Length of output: 11475
Assert that Arm B2 enters the intended fault state.
recordRevealTimeline can stop immediately because the parked pane already contains READY. It does not prove that a stalled dial occurred. The test only logs stalledConnectionCount() and the result of dropEstablished(). The generation comparison also accepts two null values because observePane maps a missing generation to null.
Add assertions for the stalled dial, dropped established flow, and baseline generation.
Proposed assertions
+ await expect
+ .poll(() => link.stalledConnectionCount(), {
+ timeout: 30_000,
+ message: 'Arm B precondition: a replacement dial must stall at the link'
+ })
+ .toBeGreaterThan(0)
+
const generationBeforeFlap = (
await observePane(client.page, target.webTabId, client.environmentId, 0)
).connectionGeneration
+ expect(generationBeforeFlap).not.toBeNull()
const dropped = link.dropEstablished()
+ expect(
+ dropped,
+ 'Arm B2 precondition: an established flow must be dropped'
+ ).toBeGreaterThan(0)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| console.log( | |
| `[tab-switch-repro] dials at the hop: accepted=${link.acceptedConnectionCount()} stalled=${link.stalledConnectionCount()}` | |
| ) | |
| // ---- Arm B2: the reporter's "reconnecting" state. Sever the established flows | |
| // once while new dials still hang, so the shared-control socket enters | |
| // `reconnecting` and the status recheck ladder arms. What the store does with | |
| // the resulting failed status.get is the writer under test: a live verdict must | |
| // not become `status: null` because the client could not ask. | |
| const generationBeforeFlap = ( | |
| await observePane(client.page, target.webTabId, client.environmentId, 0) | |
| ).connectionGeneration | |
| const dropped = link.dropEstablished() | |
| console.log( | |
| `[tab-switch-repro] dials at the hop: accepted=${link.acceptedConnectionCount()} stalled=${link.stalledConnectionCount()}` | |
| ) | |
| // ---- Arm B2: the reporter's "reconnecting" state. Sever the established flows | |
| // once while new dials still hang, so the shared-control socket enters | |
| // `reconnecting` and the status recheck ladder arms. What the store does with | |
| // the resulting failed status.get is the writer under test: a live verdict must | |
| // not become `status: null` because the client could not ask. | |
| await expect | |
| .poll(() => link.stalledConnectionCount(), { | |
| timeout: 30_000, | |
| message: 'Arm B precondition: a replacement dial must stall at the link' | |
| }) | |
| .toBeGreaterThan(0) | |
| const generationBeforeFlap = ( | |
| await observePane(client.page, target.webTabId, client.environmentId, 0) | |
| ).connectionGeneration | |
| expect(generationBeforeFlap).not.toBeNull() | |
| const dropped = link.dropEstablished() | |
| expect( | |
| dropped, | |
| 'Arm B2 precondition: an established flow must be dropped' | |
| ).toBeGreaterThan(0) |
| await expect(card).toBeVisible() | ||
|
|
||
| // Captured before the assertions so a regression run still yields the evidence image. | ||
| await captureCard(card, testInfo, 'runtime-host-glyph-before-probe.png') |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
sed -n '60,125p' tests/e2e/sidebar-runtime-host-disconnected-glyph.spec.tsRepository: stablyai/orca
Length of output: 2794
🏁 Script executed:
sed -n '1,75p' tests/e2e/sidebar-runtime-host-disconnected-glyph.spec.tsRepository: stablyai/orca
Length of output: 2836
Capture screenshots after the expected glyph appears.
seedRuntimeHost updates the store inside page.evaluate and returns without waiting for React to commit the DOM. Each captureCard call invokes Locator.screenshot before the corresponding glyph and opacity assertions. The screenshot can therefore show stale state while the later auto-waiting assertions pass.
Move each captureCard call after its glyph and opacity assertions.
…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.
…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.
…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.
…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
…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.
The per-pane handle-gap wait releases at a 15s deadline and records that expiry as a verdict, which authorises the sleeping-agent resume. The connection generation was the only thing voiding that verdict, and a plain disconnect never advances it — runtime-status.ts advances on the reconnect, under a new runtime id. So a network drop mid-turn expired the wait with a generation that still matched, and the replay forked a second `--resume` onto the transcript the host was still writing: #19735 through the disconnect door. Suppress the verdict while the client positively knows it is out of contact, reusing the shared runtime-host connection derivation. The waiter still releases and re-parks, so contact returning gets a full fresh budget and the pane is still decided on real silence. Not redundant with the landed-handle drain that follows this commit, nor with the read-time pane identity from adv2-skew (cdafc90). Mutation on the composed tree gives three disjoint kills: dropping this guard fails only "does not turn an outage into a verdict"; dropping the landed-handle drain fails only the two landed-handle cases; forcing this guard always-true fails 16 across every suite. Three guards, three holes.
51ebc04 to
aef5ced
Compare
…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
… either The contact check at the deadline is a snapshot of now. An outage that began and ended inside one wait, on the same runtime, leaves contact restored and the generation untouched, so the deadline recorded a verdict after milliseconds of real contact. Capture hostContactEpoch at park time and refuse the verdict when it moved; the waiter still releases and re-parks for a fresh budget. Also pins the transport-down snapshot shape (reads 'reconnecting'), which is what main's status channel actually publishes for a dropped link and was the one arm of the guard no test exercised.

ELI5
You are working in a workspace that lives on a remote Orca host. An agent is running there. Your network blips for a few seconds. When it comes back, Orca opens a second terminal tab beside the agent's tab that says
session restored— a second copy of the same agent, resumed onto the same conversation the first one is still writing to.That happens because a 15-second timer, which exists to ask "did the host tell us about this terminal yet?", was treated as if it had received an answer when in fact the question could not be delivered. Silence during an outage is not "no". This change makes the timer tell those two apart: if the connection was down at any point while it was waiting, it reports nothing and simply waits again.
What Changed
Before. Open a remote workspace (or wake it) while an agent there has a saved session. Orca briefly holds off on auto-resuming that agent, waiting up to 15 s for the host to publish the terminal's handle. If the network drops during those 15 s — a laptop lid, a Wi-Fi hop, a VPN renegotiation — the wait expires having heard nothing, and Orca reads that silence as "the host has no such terminal" and launches
--resumein a new tab. The user sees a duplicate tab beside the agent that is still running (the same symptom as #19735, reached through a disconnect instead of a first-frame race). Both terminals now write into one transcript.After. The same drop produces no second tab. The wait still ends on schedule so nothing is held indefinitely, but it records no answer; the pane parks again and gets a full fresh 15 s once contact is back. If the host really has nothing for that pane, the next full budget of connected silence decides, exactly as before.
Mechanism. Two files,
src/renderer/src/lib/host-mirror-handle-gap-wait.tsand its test.The deadline callback previously recorded a verdict whenever the connection generation still matched. It now records one only when all three hold:
disconnectedorreconnectingfrom the sharedruntimeHostConnectionStateForEntryderivation);runtime-status.tsbumps when the host answers again after a loss of contact on the same runtime, which by design does not move the generation. It catches an outage that began and ended inside the 15 s — at the deadline contact is back, the generation is untouched, and check 2 alone would have passed.When any of the three fails the waiter releases without a verdict and the replayed sweep re-parks it. Nothing else changes: the read side (
hasHostMirrorHandleWaitExpired), the four drains, and teardown are untouched.Why
docs/reference/ssh-execution-boundary.mdis the contract: the only verdicts arelive/unverifiable/exited, loss of contact is never evidence ofexited, and the safe direction is to leak rather than kill. Silence measured across an outage isunverifiable. Recording it as a verdict is the destructive reading, and the destruction is concrete: a duplicated agent writing into a live transcript.Alternatives considered:
runtime-status.tsadvances it on the reconnect, and only when the runtime id changed ([Bug] Orca has to reconnect every time I switch tabs #19647 made same-runtime flaps deliberately not move it, because the mirror is keyed on it).isConnectedRuntimeHostState. That reads a never-probed host (checking) as out of contact, so a fresh pairing whose first probe is in flight would never decide. Mutating the guard to that shape turns seven existing tests red. The guard is narrowed to the two states an outage actually produces.Linked Issue
Related: #19735 (same user-visible duplicate
session restoredtab; this is the disconnect path to it). No dedicated issue exists for the outage path.Visual Proof
N/A — no UI change. The visible effect is the absence of a second
session restoredtab after a network blip on a remote workspace; the behaviour is pinned by the timed tests below.Testing
Tested on macOS against the renderer test suite; the code is platform-independent (pure store/timer logic) and only runs for remote (paired-runtime) workspaces.
pnpm teston the nine handle-gap / resume / connection-state / runtime-status suites — 136 passed.pnpm tc:web— clean.pnpm run check:code-quality:changed— 0 findings.main(7063c2cbdd3): swapping onlyhost-mirror-handle-gap-wait.tsback to main's version fails exactly one test,does not turn an outage into a verdict when the environment dropped mid-park(resume fires during the outage); the other 12 pass either way and serve as the shape control.!isConnectedRuntimeHostState) → 7 tests go red, including the "contact returns → next budget decides" half;reconnectingarm →does not turn a transport-down snapshot into a verdict eithergoes red (this is the shape main's status channel actually publishes for a dropped link; it was untested before this revision);does not record a verdict when contact was lost and regained inside the budgetgoes red.Three new tests in
host-mirror-handle-gap-resume.test.ts, each asserting both halves: no resume during/after the outage, and a resume once a full budget of connected silence has elapsed — so a fix that merely holds forever cannot pass them.Review
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
unverifiable.runtime-unavailablestate (transport up, status probe failed) is deliberately not treated as an outage: the mirror rows arrive over the same transport, so silence there is host evidence.findUnhydratedHostMirrorForPaneinhost-mirrored-pane-liveness.ts, which feeds the sleeping-agent resume sweep. Nothing else reads it.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)