Repository navigation
fix(native-chat): close only the reopened chat when main closes its tab - #22922
Conversation
After /clear the current chat keeps the window tab id derived from its first session, so reopening that first session from history lands in a suffixed tab. Main closed chat tabs in the window by re-deriving that id from the session, which named the current chat instead of the reopened one: closing the reopened tab (on the desktop or from a phone) also closed the current chat and stopped its Claude. Main now sends its own tab id, as it already does for every other tab kind, and the window translates it through the host-to-window tab mapping it keeps for mirrored chat tabs. The same translation lets a host-directed focus reach the reopened tab. The close handoff marker is keyed on the id actually sent.
Review status: ready to merge (still in draft)Verdict: no changes needed. One review pass came back clean, and the head is still Does it fix the reported problem? Yes. Closing a chat reopened from Agent Session History, after Is the fix architecturally sound? The bug came from main rebuilding the window's tab id from the session id. After Regressions and performance: none found. Browser, editor and terminal ids aren't in the chat table, so they pass through unchanged. The pinned-tab guard now checks the tab actually being closed. The launch-cancellation path already sent main's id, and its marker now matches. Nothing sent to or from phones or paired clients changes. The added cost is one small in-memory lookup per close or focus message. Checked and not a problem:
Live Electron QA (background dev build, fresh profile per arm, verified which build was running)Before, on origin/main: the reopened tab next to the current chat. Before: after closing only the reopened tab, both chats are gone. The host tab list and the persisted After, on the PR head: the same starting state. After: only the reopened tab closed. The host and After: the current chat still answers (OMEGA). After: the current chat is restored after an app restart. Phone-style path (PR head): the current chat is active; a host-directed focus of the reopened tab brings it forward; a Found during review, not caused by this PR
|
|
Warning Review limit reachedNext included review available in 20 minutes. View limit detailsLimit details: You’ve used all 10 included reviews currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (10)
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.
✅ No new issues found.
Reviewed changes
- Main relays its own session-tab id —
orca-runtime-close-mobile-session-tab.ts:305sendstab.id(agent-session:<sessionId>) for agent-session closes, matching browser/editor and every other tab kind. - Window translates once on arrival — new
host-session-tab-target.tsplus the inverse lookupresolveLocalTabIdForHostSessionTabintracking-mappings.tsmap main's id to the mirrored local tab; both close handlers insession-tab-ipc-bridge.tsand the focus handler interminal-ui-routing-ipc-bridge.ts:150use it. - Retirement keyed on the host id —
structured-agent-session-tab-retirement.ts:30derivesagent-session:<sessionId>for the marker and RPC, and the now-unusedtabIdargument is removed. This is load-bearing: main echoes the host id, and the reentrant phone-close path needs the marker to match that echo. - Tests —
tests/e2e/structured-session-reopened-tab-close.unit.test.tsexercises the real main close/focus path against the real store, mirror, IPC bridges and retirement across four cases (suffix mirror, desktop close, phone close, host-directed focus).
I verified the new test passes on head, and that reverting main's relay to structuredAgentSessionTabId(tab.sessionId) fails the desktop and phone cases. pnpm tc, the changed-lines code-quality gate, and the surrounding suites (tab retirement, close-routing session tabs, close-request, structured-session restore, local structured-session sync, tab slices) all pass.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
Live Electron QA on a second Mac (M4 Air): passThe PR head
Desktop closeorigin/main: the reopened tab next to the current chat. origin/main: after closing only the reopened tab, both chats are gone. PR head: the same starting state. PR head: only the reopened tab closed. PR head: the current chat still answers (OMEGA). PR head: the current chat is restored after an app restart. Phone-style focus and closeorigin/main: current chat active; after the host-directed focus it is still on the current chat; after the close, both tabs are gone. PR head: current chat active; the focus brings the reopened tab forward; the close removes only that tab. |






















ELI5
After
/clearin a Claude chat, you can reopen the conversation from before the clear in its own tab from Agent Session History. Closing that reopened tab used to close your current chat too, and stop its Claude. Now it closes only the tab you closed.What Changed
Before: close the reopened tab (with its × on the desktop, or from a paired phone) and both chat tabs disappear. The current chat's Claude is stopped, the workspace drops to the empty landing screen, and after a restart neither chat comes back (the persisted visible-chat list is empty).
After: only the reopened tab closes. The current chat stays open, keeps answering, and still comes back after a restart.
Mechanism. After
/clear, the current chat keeps the window tab id that was derived from its first session (structured-agent-session-<S>). When that first session is reopened from history, the window has to give it a suffixed id (structured-agent-session-<S>:history-1) because the plain name is taken. When main closed a chat tab in the window, it rebuilt the window id from the session id (structuredAgentSessionTabId(S)), and that rebuilt id names the current chat, not the reopened one. The window closed the current chat, which retired its session on the host and emptied the persisted visible-chat list.agent-session:<S>) to the window, as it already did for browser, editor and every other tab kind (orca-runtime-close-mobile-session-tab.ts).hooks/ipc-events/host-session-tab-target.ts, readingtracking-mappings.ts). Both close handlers and the focus handler use the translated id for the pin check and the close or focus. An id with no mapping passes through unchanged, so browser and editor closes behave exactly as before.agent-session:<S>), because main now echoes that id back instead of a window id. The one existing caller that already used that form (suppressCancelledStructuredSessionTabs) now agrees with it, and the unusedtabIdargument is gone.session.tabs.activatewithnavigation: 'host'or'all') reach the reopened tab. Before, it found no window tab and did nothing.Why
The window tab id cannot be derived from the session id:
/clearkeeps the old id on a tab showing a new session, and a reopened session gets a suffix. The only fact that names the right window tab is the correspondence the window records when it applies the host's tab snapshot, so this change addresses the window through that record instead of adding another guard beside a rebuilt name. Main's own tab id is also what every other tab kind already sends.Deviations from the usual shape of this pattern, stated plainly:
Alternatives considered: matching the window tab by the session id it shows (its
entityId) would also have fixed the close, but it bakes the host id format into the window and bypasses the mapping that the rest of the mirror already uses. Keeping the derived id and adding a special case for suffixed tabs would leave the root cause (a derived name) in place.Not changed, follow-up: clicking a chat's completion notification focuses by the tab id taken from the chat's pane key. That id is also derived from the session, so after
/clearit can focus the current chat instead of a reopened one. It carries no host tab id, so this translation does not apply to it; it only affects focus and destroys nothing.Remote / version skew:
closeSessionTabandfocusEditorTabare messages from main to its own window in the same app, so both sides always ship together. No RPC parameters, stream frames or published snapshots change, so phones and paired clients see exactly what they did before. Headless and remote-server hosts have no window and are unaffected.Linked Issue
No filed issue; found while reviewing #22709 (no file overlap with it).
Visual Proof
Repro: open a Claude chat, send ZETA,
/clear, send ETA, then Agent Session History → ZETA row → Resume in Worktree. Close the reopened tab.Before (main): the reopened ZETA tab next to the current ETA chat
Before (main): after closing only the reopened tab, both chats are gone and the workspace is deselected
After: closing the reopened tab leaves the current ETA chat open
After: the current chat still answers (OMEGA) and survives an app restart
Phone-style close through the runtime (
session.tabs.closefor the reopened tab's host id), before vs after:Host-directed focus of the reopened tab (
session.tabs.activatewithnavigation: 'host') while the current chat is active, before (stays on the current chat) vs after (shows the reopened MU conversation):Testing
Live Electron QA on macOS: a background dev build with an isolated profile per arm, driven over CDP. Each arm started from a fresh profile set up the same way (chat flags on, one scratch repo, relaunched). Main's bundle was checked in each arm to confirm which code was running.
[], and the persisted visible-chat list goes to[]. With the fix, only the reopened tab closes, the host keeps the current session, the persisted list keeps it, the current chat answers a new message, and it is restored after a restart.navigation: 'caller'for tab activation, so today only a caller that explicitly asks for desktop navigation reaches this path.New test
tests/e2e/structured-session-reopened-tab-close.unit.test.tsruns the real main close/focus path (OrcaRuntimeService.closeMobileSessionTab/activateMobileSessionTab) against the real window store, snapshot mirror, IPC bridges and retirement code. Only the process boundary is stubbed. Its four cases: the mirror produces the suffixed tab; a desktop close; a phone close; a host-directed focus.[S, clear-X]on the host, the phone close removes the wrong tab, and the focus never reaches the reopened tab.Also run:
pnpm tc, oxlint on the changed files,pnpm run check:code-quality:changed, and the related vitest suites (session-tab close routing, mobile session tabs, local structured-session mirror, tab slices, IPC event bridges).Not caused by this PR: the
src/renderer/src/hooks/useIpcEvents-close-routing-*tests fail on a cleanorigin/main(acf8e67), without this change, withCannot find package '@/lib/parked-terminal-host-hydration'. The same tests passed on the earlier base 8009939.AI Disclosure
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
Security: no new surface. Cross-platform: no platform-specific code. SSH/remote: see "Remote / version skew" above. Mobile: phone closes of a reopened chat now close the right desktop tab; nothing a phone reads changes. Performance: one small map lookup per close or focus message.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)