Skip to content

fix: close mirrored editor tabs on the host so they stop reopening - #5975

Merged
Jinwoo-H merged 3 commits into
stablyai:mainfrom
gsxdsm:gsxdsm/fix-files-not-closing
Jun 22, 2026
Merged

Jinwoo-H merged 3 commits into
stablyai:mainfrom
gsxdsm:gsxdsm/fix-files-not-closing

Conversation

@gsxdsm

@gsxdsm gsxdsm commented Jun 21, 2026 •

Copy link
Copy Markdown
Contributor

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 is mirroredFromRuntimeSession and a web runtime session is active, it fires session.tabs.close for 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:closeSessionTab handler: a companion-driven editor close now routes through closeFile (which clears openFiles) instead of closeUnifiedTab (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 through closeFile directly and would have stayed broken. One chokepoint covers every surface, including future ones, and removes the duplication.

Tests

  • closeFile routes 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 → still closeUnifiedTab (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.


Open in Stage

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]>
@ghost

ghost commented Jun 21, 2026 •

Copy link
Copy Markdown

Ready to review this PR? Stage has broken it down into 4 individual chapters for you:

Title
1 Fix linting and formatting in tests
2 Implement host notification for mirrored editor closes
3 Integrate host notification into editor store
4 Route companion-driven closes through editor store
Open in Stage

Chapters generated by Stage for commit 4516b58 on Jun 22, 2026 9:37pm UTC.

@coderabbitai

coderabbitai Bot commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

A new module close-mirrored-editor-tab.ts exports MirroredEditorCloseState and notifyHostOfMirroredEditorClose, which checks whether a given file id corresponds to a mirrored editor tab in an active web runtime session and, if so, calls closeWebRuntimeSessionTab with the host tab id and environment id. The closeFile action in the editor store now calls this helper before applying state mutations. In useIpcEvents.ts, the onCloseSessionTab IPC handler's close callback was updated to branch on the session tab's contentType: editor tabs now route through closeFile (which triggers host notification), while other tab types continue to use closeUnifiedTab.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description covers the issue, solution, and testing, but is missing required template sections: Screenshots, Testing checklist completion, AI Review Report, and Security Audit. Add the missing sections from the template: Screenshots (or 'No visual change'), completed Testing checklist with results, AI Review Report covering cross-platform compatibility, and Security Audit summary.
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. 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: fixing reopening mirrored editor tabs by closing them on the host.
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.

✏️ 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@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

🧹 Nitpick comments (1)
src/renderer/src/hooks/useIpcEvents.test.ts (1)

2063-2118: ⚡ Quick win

Consider 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 to closeUnifiedTab(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

📥 Commits

Reviewing files that changed from the base of the PR and between 3117ebc and c1ae200.

📒 Files selected for processing (6)
  • src/renderer/src/hooks/useIpcEvents.test.ts
  • src/renderer/src/hooks/useIpcEvents.ts
  • src/renderer/src/runtime/close-mirrored-editor-tab.test.ts
  • src/renderer/src/runtime/close-mirrored-editor-tab.ts
  • src/renderer/src/store/slices/editor.test.ts
  • src/renderer/src/store/slices/editor.ts

Comment on lines +44 to +48
void closeWebRuntimeSessionTab({
worktreeId,
tabId: unifiedTab.id,
environmentId: runtimeEnvironmentId
})

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.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

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)

@coderabbitai

coderabbitai Bot commented Jun 21, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: eea00c00-ee16-462d-87d0-fccaee100123

📥 Commits

Reviewing files that changed from the base of the PR and between 89c3f31 and 4516b58.

📒 Files selected for processing (2)
  • src/renderer/src/runtime/close-mirrored-editor-tab.test.ts
  • src/renderer/src/runtime/close-mirrored-editor-tab.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/renderer/src/runtime/close-mirrored-editor-tab.test.ts
  • src/renderer/src/runtime/close-mirrored-editor-tab.ts

📝 Walkthrough

Walkthrough

Adds a new notifyHostOfMirroredEditorClose helper in close-mirrored-editor-tab.ts that checks whether a closing file is a mirrored editor tab from an active runtime session and, if so, calls closeWebRuntimeSessionTab on the host's unified editor tab. This function is imported and called within closeFile in the editor slice before the store mutation. Tests for the helper cover mirrored routing, non-mirrored, and no-active-session cases. The useIpcEvents test suite is extended with a CloseSessionTabListener mechanism and two new tests verifying that companion-closed editor tabs route through closeFile while non-editor tabs route through closeUnifiedTab. Two unrelated test files receive cosmetic assertion reformatting.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The description covers what/why, the fix approach, rationale for centralization, and tests, but is missing Screenshots section and incomplete AI Review Report and Security Audit sections. Add Screenshots section (or note 'No visual change'), complete AI Review Report with cross-platform checks, and provide Security Audit summary as required by the template.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely summarizes the main change: fixing mirrored editor tabs reopening on the host.
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.

✏️ 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

…closing

# Conflicts:
#	src/renderer/src/hooks/useIpcEvents.ts

@Jinwoo-H Jinwoo-H 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.

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

@Jinwoo-H
Jinwoo-H merged commit b58478e into stablyai:main Jun 22, 2026
2 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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]>
@gsxdsm
gsxdsm deleted the gsxdsm/fix-files-not-closing branch October 31, 2026 17:59
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.

2 participants