From 293bfe795d35cc0e9f05f57aa291abf428e87e2e Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Sat, 24 Oct 2026 14:55:44 -0700 Subject: [PATCH] fix(browser): closing a host page retires a window-saved tab whose ids differ (STA-11998) (#33266) --- .../runtime/serve-browser-tab-layout.test.ts | 26 +++++++++++++++++++ src/main/runtime/serve-browser-tab-layout.ts | 8 +++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/main/runtime/serve-browser-tab-layout.test.ts b/src/main/runtime/serve-browser-tab-layout.test.ts index d76eec740f5..7612e6088dd 100644 --- a/src/main/runtime/serve-browser-tab-layout.test.ts +++ b/src/main/runtime/serve-browser-tab-layout.test.ts @@ -118,6 +118,32 @@ describe('a browser tab a host with no window saves', () => { expect(saved.browserPagesByWorkspace?.['page-1']).toBeUndefined() }) + it('leaves no trace once closed when a window saved it under its own tab ids (STA-11998)', () => { + const session = opened(sessionWithTerminal()) + const browserTab = session.browserTabsByWorktree![WT]![0]! + const unifiedTab = session.unifiedTabs![WT]!.find((tab) => tab.id === 'page-1')! + const group = session.tabGroups![WT]![0]! + const windowSaved: WorkspaceSessionState = { + ...session, + browserTabsByWorktree: { [WT]: [{ ...browserTab, id: 'browser-tab-1' }] }, + browserPagesByWorkspace: { 'browser-tab-1': session.browserPagesByWorkspace!['page-1']! }, + unifiedTabs: { + [WT]: session.unifiedTabs![WT]!.map((tab) => + tab === unifiedTab ? { ...tab, id: 'unified-1', entityId: 'browser-tab-1' } : tab + ) + }, + tabGroups: { + [WT]: [{ ...group, tabOrder: ['term-1', 'unified-1'], activeTabId: 'unified-1' }] + } + } + + const saved = withClosedServeBrowserTab(HOST, windowSaved, WT, 'page-1')! + + expect(saved.unifiedTabs?.[WT]?.map((tab) => tab.id)).toEqual(['term-1']) + expect(saved.browserTabsByWorktree?.[WT] ?? []).toEqual([]) + expect(findSavedBrowserPage(saved, WT, 'page-1')).toBeNull() + }) + it('updates only the page of a window-saved tab that is not its active one', () => { const session = opened(sessionWithTerminal()) const windowSaved: WorkspaceSessionState = { diff --git a/src/main/runtime/serve-browser-tab-layout.ts b/src/main/runtime/serve-browser-tab-layout.ts index 3e7aac27ada..ce0cad19cf1 100644 --- a/src/main/runtime/serve-browser-tab-layout.ts +++ b/src/main/runtime/serve-browser-tab-layout.ts @@ -189,7 +189,13 @@ export function withClosedServeBrowserTab( const loaded = loadWorkspaceLayout(hostId, session, nameBasedLoadContext()) const applied = applyLayoutCommand( loaded.layout, - { type: 'closeTabs', workspace: worktreeId, tabIds: [saved.tabId], force: true }, + { + type: 'closeTabs', + workspace: worktreeId, + // Why (STA-11998): closeTabs takes the tab-bar id, which a window-saved tab keeps apart. + tabIds: [savedBrowserTabEntryId(session, worktreeId, saved.tabId)], + force: true + }, { mintId: randomUUID, mintLeafId: randomUUID, now: Date.now } ) if (!applied.ok) {