The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): keep a draft's preview tabs in the draft until its first send
teknium14fc8c909cb45
diff --git a/apps/desktop/src/app/session/hooks/use-session-actions/index.ts b/apps/desktop/src/app/session/hooks/use-session-actions/index.tsindex 321632ff3d3..308a6f58975 100644--- a/apps/desktop/src/app/session/hooks/use-session-actions/index.ts+++ b/apps/desktop/src/app/session/hooks/use-session-actions/index.ts@@ -49,7 +49,7 @@ import { $gatewaySwitching } from '@/store/gateway-switch'import { clearSessionGoal } from '@/store/goals'import { $pinnedSessionIds } from '@/store/layout'import { clearNotifications, notify, notifyError } from '@/store/notifications'-import { prunePreviewTabsForSession } from '@/store/preview'+import { adoptDraftPreviewTabs, prunePreviewTabsForSession } from '@/store/preview'import {$activeGatewayProfile,$gatewaySwapTarget,@@ -112,6 +112,7 @@ import {setYoloActive} from '@/store/session'import { clearSessionControl } from '@/store/session-control'+import { $focusedStoredSessionId } from '@/store/session-focus'import { isSessionOwnerResolutionError } from '@/store/session-owner-resolution'import {beginSessionMutation,@@ -128,7 +129,6 @@ import {type SessionProfileRoute} from '@/store/session-request-router'import {- $focusedStoredSessionId,$sessionTiles,closeSessionTile,dropSessionState,@@ -923,6 +923,8 @@ export function useSessionActions({// Anything still parked under the pre-session draft bucket belongs// to this chat now (#114122); the composer moves it on scope swap.announceNewSessionDraftKey(stored)+ // The draft's preview tabs follow it the same way (#73890).+ adoptDraftPreviewTabs(stored)createOverrides?.onComposerScopeAssigned?.(stored)// Hold creatingSessionRef until the route lands on `stored` (release// effect above). setTimeout(0) raced use-route-resume back onto thediff --git a/apps/desktop/src/store/preview.test.ts b/apps/desktop/src/store/preview.test.tsindex b2e8021898c..110b17ae6f6 100644--- a/apps/desktop/src/store/preview.test.ts+++ b/apps/desktop/src/store/preview.test.ts@@ -11,6 +11,7 @@ import {$previewTabs,$previewTarget,$visiblePreviewTabs,+ adoptDraftPreviewTabs,beginPreviewServerRestart,closeAgentPreview,closeBrowserPreviewMatchingLiveUrl,@@ -478,14 +479,36 @@ describe('preview session scoping (#73890)', () => {expect(paths($previewTabs.get())).toEqual(['/work/a.html'])})- it('adopts ownerless draft tabs when a session appears', () => {+ it('keeps a draft tabs in the draft until that draft itself gets its stored id', () => {openPreview(fileTarget('/work/draft.html'))- expect($previewTabs.get()[0]?.sessionId).toBeUndefined()+ newBrowserTab()+ expect($previewTabs.get().map(tab => tab.sessionId)).toEqual([undefined, undefined])++ // Focus moving elsewhere — an existing session clicked in the sidebar, or+ // a side tile — must not take the draft's tabs with it.+ $selectedStoredSessionId.set('existing-x')+ expect($visiblePreviewTabs.get()).toHaveLength(0)++ const previousTree = $layoutTree.get()++ try {+ $layoutTree.set(group(['workspace', 'session-tile:tile-t'], { active: 'session-tile:tile-t', id: 'grp-draft' }))+ noteActiveTreeGroup('grp-draft')+ expect($visiblePreviewTabs.get()).toHaveLength(0)+ } finally {+ noteActiveTreeGroup(null)+ $layoutTree.set(previousTree)+ }++ $selectedStoredSessionId.set(null)+ expect(paths($visiblePreviewTabs.get())).toEqual(['/work/draft.html', 'about:blank'])+ // The draft's first send assigns its stored id: now the tabs are its own.+ adoptDraftPreviewTabs('sess-new')$selectedStoredSessionId.set('sess-new')- expect($previewTabs.get()[0]?.sessionId).toBe('sess-new')- expect(paths($visiblePreviewTabs.get())).toEqual(['/work/draft.html'])+ expect($previewTabs.get().map(tab => tab.sessionId)).toEqual(['sess-new', 'sess-new'])+ expect(paths($visiblePreviewTabs.get())).toEqual(['/work/draft.html', 'about:blank'])})it('owns a strip "+" Browser by the focused session, never adopting it elsewhere', () => {diff --git a/apps/desktop/src/store/preview.ts b/apps/desktop/src/store/preview.tsindex 7114f2bb459..ba48f094c5f 100644--- a/apps/desktop/src/store/preview.ts+++ b/apps/desktop/src/store/preview.ts@@ -473,21 +473,20 @@ export function preferredVisibleTabId(): RightRailTabId | null {return isVisible(remembered) ? remembered! : (visible[0]?.id ?? null)}-// A fresh draft has no session yet, so tabs opened there are ownerless — adopt-// them into the session the moment one exists, or the drawer would silently-// lose them at first send. Every other open is stamped with its owner, so-// only a draft's tabs can be ownerless here.-$focusedStoredSessionId.listen(sessionId => {- if (sessionId == null) {- return- }-+/** A fresh draft has no session yet, so tabs opened there are ownerless (the+ * drawer of every draft shows them). Called where the draft's first send+ * assigns its stored id — beside the composer draft's own hand-over — so the+ * tabs follow it into the conversation. Never on a focus change: clicking an+ * existing session or a side tile must leave the draft's tabs in the draft. */+export function adoptDraftPreviewTabs(storedSessionId: string): void {const tabs = $previewTabs.get()if (tabs.some(tab => tab.sessionId == null && !tab.pinned)) {- $previewTabs.set(tabs.map(tab => (tab.sessionId == null && !tab.pinned ? { ...tab, sessionId } : tab)))+ $previewTabs.set(+ tabs.map(tab => (tab.sessionId == null && !tab.pinned ? { ...tab, sessionId: storedSessionId } : tab))+ )}-})+}/** The tab the rail actually shows. A stale or missing selection falls back to* the first tab, so the strip, `⌘W`, and the pane never disagree about which