Skip to content

fix(remote): send again a tab close the paired host never received - #29468

Merged
nwparker merged 6 commits into
mainfrom
nwparker/paired-close-replay
Oct 16, 2026
Merged

nwparker merged 6 commits into
mainfrom
nwparker/paired-close-replay

Conversation

@nwparker

@nwparker nwparker commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​301 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​299
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​281 $\color{#cf222e}{\Huge{\mathbf{−}}}$​8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​273

ELI5

If you close a tab that belongs to a paired Orca server while the connection drops, the close never reaches the server. When you reconnect, the server still has the tab, so it comes back. Now Orca remembers the close and sends it again once the server is reachable, so a tab you closed stays closed.

What Changed

  • Before: closing a host-owned tab (paired server, or the paired web client) did three things. It removed the local copy at once, recorded a short-lived "closing" marker, and sent session.tabs.close. If that call failed because the connection dropped or timed out (anything except a definitive tab_not_found), the marker was cleared and the close was forgotten. The host's first snapshot after reconnect re-added the tab. This is the third cause in STA-6224. The other two (fix(runtime): a terminal close commits in the session partition that holds the tab #27119 and fix(terminal): closing a tab is never a silent no-op #27132) are already on main.

  • After: a user close that fails without reaching the host now does two things:

    • It keeps the tab hidden: the marker is made durable instead of cleared.
    • It queues a replay. Any received host snapshot that states the worktree's contents and still lists the tab proves the host is reachable and still holds it, so the close is sent again. That check runs when the snapshot arrives, not when it's applied, because the reconnect snapshot is often unchanged and gets filtered before apply. A scheduled re-list covers an idle worktree that publishes nothing.

    The replay is pinned to the pairing it was made under, so a re-paired host never receives it. After three undelivered sends (or if the bounded queue evicts the entry) the tab is shown again, so a host that keeps failing can't hide a live tab forever.

  • Mechanism:

    • New src/renderer/src/runtime/web-session-close-replay.ts holds the replays.
    • web-runtime-session-tab-lifecycle.ts holds the close on an undelivered failure (a bare rejection, or runtime_unavailable / remote_runtime_unavailable / runtime_timeout / remote_runtime_timeout). It also exports replayWebSessionTabCloses.
    • web-session-tabs-sync/tracking.ts (recordReceivedWebSessionTabsSnapshot) makes replays due, after the existing retired-epoch and unpublished-snapshot guards. It also re-asserts the hide, because a subscription reinstall clears close intents.

Why

The execution host owns the tab, so the close has to reach it. Hiding the tab locally isn't enough. I considered three other approaches:

  • A timer-based retry. It can't know when the host is back.
  • Retrying inside the failing call. It would hold up the close UI.
  • Persisting a local tombstone that filters the host's snapshot forever. It would hide a tab the host legitimately still runs.

A snapshot is the one signal that proves both "reachable" and "still holds it". Lifecycle closes (cleanup or process exit) and structured refusals, such as a pairing conflict, keep the current clear-on-failure behavior, because those aren't the user's explicit intent or are a definitive answer.

Wire compatibility: nothing new on the wire. It resends the same session.tabs.close with reason: 'user', which every host already accepts. A second close of a tab the host already removed answers tab_not_found, which is already handled as "gone".

Limitation: replays live in memory, so a close made just before quitting the app while disconnected is still lost. Making it durable across restarts would mean persisting to main, which is a larger change.

Linked Issue

Linear STA-6224 (third cause). Related to #17767. I'm not closing that GitHub issue from here.

Visual Proof

N/A — this changes when an already-sent close is sent again after a reconnect. The tab bar looks the same; the closed tab just stays closed.

Testing

  • src/renderer/src/runtime/web-runtime-session-tab-activate-close.test.ts:

    • A user close whose RPC rejects keeps the tab hidden past the old TTL and queues a replay. The replay sends session.tabs.close again and settles.
    • A lifecycle close is not held.
    • The existing pairing-conflict test still clears.
  • src/renderer/src/runtime/web-session-close-replay.test.ts:

    • Due only when a snapshot lists the tab, and not twice while in flight.
    • Kept through a snapshot that omits the tab or can't state the worktree's contents.
    • Gives up after three tries.
    • Never replays to a re-paired host.
    • Evicted entries unhide their tab.
    • An in-flight close is re-hidden after a reinstall.
    • Receiving a host snapshot keeps the tab hidden and triggers the replay. This one fails on origin/main.
  • The lifecycle tests also cover the scheduled re-list after holding a close and after a failed replay, and refusing a replay after re-pairing.

  • web-session-tabs-sync.test.ts still passes. pnpm tc:web and pnpm run check:code-quality:changed pass.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

SSH/remote: this is the paired-host case. Losing contact is treated as "not delivered yet", never as "closed". Mobile: there's no change to the mobile app. The paired web client uses this same path and gets the fix.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

Closing a paired host's tab prunes the local mirror at once and asks the host
to close it. When the connection dropped mid-close the renderer cleared its
close intent, so the host's next snapshot after reconnect brought the tab
back. A user close that fails without reaching the host is now held: the tab
stays hidden, and the close is sent again when a snapshot proves the host is
reachable and still lists it, up to three times before the tab is shown.
@coderabbitai

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

User-initiated tab closes that cannot reach the host now retain durable close intents and enter a bounded replay queue. Qualifying snapshots trigger replay, while pairing-owner checks prevent closes from being sent for a different pairing. Failed attempts can be retried, and lifecycle closes are not queued by this handling.

Priority: ➖ Normal

Merge Risk: 🔵 Low · up to e79d3

A refused close may briefly hide the tab again and resend the request. If replay loading fails, a held tab can remain hidden until the app restarts. These bounded risks should be fixed or explicitly accepted before merging.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 47.06% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 17 functions across 5 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
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.
Title check Passed The title clearly and concisely describes the main change: retrying tab closes that the paired host did not receive.
Description check Passed The description is complete and aligned with the template. It explains the user impact, implementation, rationale, testing, limitations, and compatibility considerations. It also records that manual t…
  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

…pairing

Codex review: an unchanged reconnect snapshot is filtered before apply, so the
replay now fires when any snapshot is received; a replay is refused once the
environment is re-paired; replays survive a subscription reinstall and
re-assert their hide; giving up re-accepts the current snapshot so the tab
actually returns.
… unhide evicted ones

Codex review: an unpublished or retired-epoch frame could drop a pending
replay, and an evicted replay kept its tab hidden with nothing left to send.
…hide in-flight ones

Codex review: a real-epoch snapshot can omit tabs it is unsure of, so absence
no longer drops a held close; and a snapshot listing a tab whose close is in
flight re-asserts its hide after a subscription reinstall.
Codex review: subscriptions are change-driven, so an idle worktree might never
publish the snapshot that makes the next attempt due.
Codex review: an idle host may publish nothing after a held close, so the first
replay also needs a scheduled re-list.

@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: 2


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a0933787-ef38-4eaf-a5fe-92f0d47ca4f8
📥 Commits

Reviewing files that changed from the base of the PR and between a8f2c65 and e79d3c7.

📒 Files selected for processing: 5
  • src/renderer/src/runtime/web-runtime-session-tab-activate-close.test.ts
  • src/renderer/src/runtime/web-runtime-session-tab-lifecycle.ts
  • src/renderer/src/runtime/web-session-close-replay.test.ts
  • src/renderer/src/runtime/web-session-close-replay.ts
  • src/renderer/src/runtime/web-session-tabs-sync/tracking.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.

? { expectedPairingRevision: replay.owner.pairingRevision }
: {})
})
const settled = settleWebSessionCloseReplay(replay, outcome !== 'failed')

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 | 🟡 Minor | ⚡ Quick win

Treat a definitive refusal of a replayed close as settled, not as a retry.

closeWebRuntimeSessionTab returns 'failed' for two different cases:

  • The close did not reach the host (undelivered).
  • The host refused the close with a structured RuntimeRpcCallError code that is not in UNDELIVERED_CLOSE_CODES.

On a refusal, the inner catch takes the else branch at Line 324-331 and clears the close intents. The tab becomes visible again. Line 150 still passes delivered = false, so the replay stays in pendingReplays as 'retry'. The next snapshot that lists the tab then runs replayWebSessionClosesDueForSnapshot. That call hides the tab again and sends the close again. The tab flickers and the close is resent until the attempt limit is reached.

The comment at Line 93-94 says a structured refusal "is an answer." The replay path does not follow that contract.

The fix: return a distinct outcome for undelivered failures, or have the replay classify the error. Settle as delivered when the failure is a definitive refusal.

Proposed direction
-export type WebRuntimeSessionTabCloseOutcome = 'applied' | 'unknown-tab' | 'failed'
+export type WebRuntimeSessionTabCloseOutcome = 'applied' | 'unknown-tab' | 'failed' | 'undelivered'
...
-    return hostHasNoSuchTab ? 'unknown-tab' : 'failed'
+    if (hostHasNoSuchTab) return 'unknown-tab'
+    return isUndeliveredCloseFailure(error) ? 'undelivered' : 'failed'
...
-    const settled = settleWebSessionCloseReplay(replay, outcome !== 'failed')
+    const settled = settleWebSessionCloseReplay(replay, outcome !== 'undelivered')

If you add a new outcome value, check the existing callers that compare against 'failed'.

Comment on lines +140 to +154
)) {
for (const hostTabId of replay.hostTabIds) {
recordWebSessionCloseIntent(replay.owner, replay.worktreeId, hostTabId, Date.now())
makeWebSessionCloseIntentDurable(replay.owner, replay.worktreeId, hostTabId)
}
}
const due = takeDueWebSessionCloseReplays(owner, snapshot.worktree, presentHostTabIds)
if (due.length === 0) {
return
}
// Lazy: the lifecycle module reaches the store, which loads this module.
void import('./web-runtime-session-tab-lifecycle').then(({ replayWebSessionTabCloses }) =>
replayWebSessionTabCloses(environmentId, due)
)
}

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.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

sed -n '75,158p' src/renderer/src/runtime/web-session-close-replay.ts
sed -n '105,128p' src/renderer/src/runtime/web-session-tabs-sync/tracking.ts

Repository: stablyai/orca

Length of output: 4385


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- replay helper imports and callers ---'
rg -n -F --glob '*.ts' -e 'replayWebSessionTabCloses' -e 'replayWebSessionClosesDueForSnapshot' -e 'settleWebSessionCloseReplay' src/renderer/src
printf '%s\n' '--- lifecycle implementation ---'
rg -n -F --glob '*.ts' -- 'async function replayWebSessionTabCloses' 'function replayWebSessionTabCloses' 'export const replayWebSessionTabCloses' src/renderer/src
sed -n '1,260p' src/renderer/src/runtime/web-runtime-session-tab-lifecycle.ts
printf '%s\n' '--- replay module complete relevant range ---'
sed -n '1,180p' src/renderer/src/runtime/web-session-close-replay.ts

Repository: stablyai/orca

Length of output: 19772


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- close call error path ---'
sed -n '220,430p' src/renderer/src/runtime/web-runtime-session-tab-lifecycle.ts
printf '%s\n' '--- replay tests ---'
sed -n '1,190p' src/renderer/src/runtime/web-session-close-replay.test.ts
sed -n '600,750p' src/renderer/src/runtime/web-runtime-session-tab-activate-close.test.ts

Repository: stablyai/orca

Length of output: 16905


Handle lazy replay import failures.

When an authoritative snapshot lists a held tab, takeDueWebSessionCloseReplays marks the replay in flight before the lazy import runs. If that import rejects, no settlement runs. Later snapshots skip the replay because it remains in flight, while its close intent keeps the tab hidden. Add a rejection path that resets the replay and applies the same retry or give-up cleanup as the normal dispatch path.

@nwparker
nwparker merged commit eccbd17 into main Oct 16, 2026
42 of 44 checks passed
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