Repository navigation
fix: close mirrored editor tabs on the host so they stop reopening - #5975
Conversation
On web and mobile companions, editor file tabs are mirrored from the host's runtime-session snapshot, which the host derives from its authoritative `openFiles`. Closing a mirrored tab only removed it locally, so the next snapshot re-mirrored the still-open host file and the tab immediately reopened. Route the close to the host from the single chokepoint every editor close funnels through (`store.closeFile`): when the file is mirrored and a web runtime session is active, send `session.tabs.close` for the host tab id. The RPC's recorded close-intent suppresses re-mirroring until the host snapshot catches up, so the local removal is not undone. No-op for the host's own (non-mirrored) files. Also fix the desktop `ui:closeSessionTab` handler so a companion-driven editor close goes through `closeFile` (clears `openFiles`) instead of `closeUnifiedTab` (tab strip only), which had the same re-mirror bug for mobile-originated closes. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Ready to review this PR? Stage has broken it down into 4 individual chapters for you: Chapters generated by Stage for commit 4516b58 on Jun 22, 2026 9:37pm UTC. |
📝 WalkthroughWalkthroughA new module 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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: 1
🧹 Nitpick comments (1)
src/renderer/src/hooks/useIpcEvents.test.ts (1)
2063-2118: ⚡ Quick winConsider adding a test for the missing-tab edge case.
The tests cover the main branching paths (editor vs. non-editor), but don't verify what happens when the tab ID is not found in
unifiedTabsByWorktree. Based on the implementation, it should fall back tocloseUnifiedTab(tabId).🧪 Suggested test case
+ it('falls back to closeUnifiedTab when session tab is not found', async () => { + const closeSessionTabListenerRef: { current: CloseSessionTabListener | null } = { + current: null + } + const closeFile = vi.fn() + const closeUnifiedTab = vi.fn() + + await useIpcEventsForCloseRouting({ + closeSessionTabListenerRef, + getState: () => ({ + closeFile, + closeUnifiedTab, + browserTabsByWorktree: {}, + unifiedTabsByWorktree: { + 'wt-1': [] // Empty - tab not found + } + }) + }) + + closeSessionTabListenerRef.current?.({ tabId: 'missing-tab', worktreeId: 'wt-1' }) + + expect(closeUnifiedTab).toHaveBeenCalledWith('missing-tab') + expect(closeFile).not.toHaveBeenCalled() + })
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 81d512e8-8c3d-4fb5-97c8-59c44f65cb82
📒 Files selected for processing (6)
src/renderer/src/hooks/useIpcEvents.test.tssrc/renderer/src/hooks/useIpcEvents.tssrc/renderer/src/runtime/close-mirrored-editor-tab.test.tssrc/renderer/src/runtime/close-mirrored-editor-tab.tssrc/renderer/src/store/slices/editor.test.tssrc/renderer/src/store/slices/editor.ts
| void closeWebRuntimeSessionTab({ | ||
| worktreeId, | ||
| tabId: unifiedTab.id, | ||
| environmentId: runtimeEnvironmentId | ||
| }) |
There was a problem hiding this comment.
Catch host-close RPC failures to avoid unhandled rejections.
This fire-and-forget async call can reject and bubble as an unhandled promise rejection on transport/RPC failure.
Suggested fix
- void closeWebRuntimeSessionTab({
- worktreeId,
- tabId: unifiedTab.id,
- environmentId: runtimeEnvironmentId
- })
+ void closeWebRuntimeSessionTab({
+ worktreeId,
+ tabId: unifiedTab.id,
+ environmentId: runtimeEnvironmentId
+ }).catch(() => undefined)|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughAdds a new 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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 |
…closing # Conflicts: # src/renderer/src/hooks/useIpcEvents.ts
Jinwoo-H
left a comment
There was a problem hiding this comment.
Thanks. I reviewed and fixed one remaining mirrored-editor close path.
- Resolved the conflict with current main.
- Added host-close notification for mirrored editors removed by close-all, which previously bypassed closeFile and could still reappear from the next host snapshot.
- Cleaned up mirrored editor tab-order entries by host tab id as well as file id.
- Confirmed the SSH remote-workspace path does not appear to mirror editor openFiles separately; this fix applies to the runtime-session mirrored editor path.
Validation:
- pnpm typecheck
- pnpm lint
- affected Vitest suites: 220 tests passed
- Electron dev validation of the live renderer close paths
Co-authored-by: Orca <[email protected]>
…tablyai#5975) * fix: close mirrored editor tabs on the host so they stop reopening On web and mobile companions, editor file tabs are mirrored from the host's runtime-session snapshot, which the host derives from its authoritative `openFiles`. Closing a mirrored tab only removed it locally, so the next snapshot re-mirrored the still-open host file and the tab immediately reopened. Route the close to the host from the single chokepoint every editor close funnels through (`store.closeFile`): when the file is mirrored and a web runtime session is active, send `session.tabs.close` for the host tab id. The RPC's recorded close-intent suppresses re-mirroring until the host snapshot catches up, so the local removal is not undone. No-op for the host's own (non-mirrored) files. Also fix the desktop `ui:closeSessionTab` handler so a companion-driven editor close goes through `closeFile` (clears `openFiles`) instead of `closeUnifiedTab` (tab strip only), which had the same re-mirror bug for mobile-originated closes. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * Fix mirrored editor close import cycle Co-authored-by: Orca <[email protected]> --------- Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]> Co-authored-by: Jinwoo-H <[email protected]> Co-authored-by: Orca <[email protected]>
What & why
On web and mobile companions, some editor file tabs reopened the instant you closed them.
Companions don't own their editor tabs — they mirror them from the host's runtime-session snapshot, which the host builds from its authoritative
openFiles. Closing a mirrored tab only removed it on the companion, so the next snapshot re-mirrored the file (still open on the host) and the tab popped right back. Locally-opened files closed fine, which is why it was "some" tabs.The fix
Tell the host to close its own copy. The close is centralized at the single chokepoint every editor close funnels through —
store.closeFile(tab strips, bulk close-others/to-right, save/discard, the floating panel). When the file ismirroredFromRuntimeSessionand a web runtime session is active, it firessession.tabs.closefor the host tab id, then proceeds with the normal local removal. The RPC records a close-intent that suppresses re-mirroring until the host snapshot catches up, so the local removal isn't undone and there's no flicker. It's a no-op for the host's own (non-mirrored) files, so desktop behavior is unchanged.Also fixes the desktop
ui:closeSessionTabhandler: a companion-driven editor close now routes throughcloseFile(which clearsopenFiles) instead ofcloseUnifiedTab(tab strip only) — the same re-mirror bug, hit by mobile-originated closes.Why centralize (vs. patching each close site)
An earlier draft guarded individual call sites in
Terminal.tsx, but that's the legacy fallback titlebar — the primary tab-group UI (useTabGroupWorkspaceModel), the dirty save/discard handlers, and the floating panel all close throughcloseFiledirectly and would have stayed broken. One chokepoint covers every surface, including future ones, and removes the duplication.Tests
closeFileroutes through the host-mirror notifier and still removes the file locally (locks the chokepoint).notifyHostOfMirroredEditorClose: fires with the host tab id; no-ops for non-mirrored files and inactive sessions.ui:closeSessionTab: editor close →closeFile; non-editor close → stillcloseUnifiedTab(keeps the editor-only routing scoped).Notes
No demo embedded — reproducing requires a live host + web/mobile companion runtime session, which isn't capturable here. Renderer typecheck, oxlint, and the affected vitest suites pass.