From a4092cd2d282f6bd717010dd7f04b3d4366933bb Mon Sep 17 00:00:00 2001 From: chelsealong Date: Mon, 24 Aug 2026 02:29:39 +0000 Subject: [PATCH] fix(desktop): open a branched session in the main workspace, not just a tile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit forkBranch ended by opening the branch as a session-tile and leaving the primary selection on the parent (#69750). In the default layout there is no visible tile pane, so branching only added a sidebar row with no feedback in the main area — and openSessionTile no-ops when the target is already the selected session, the common case of branching the chat you're viewing. Load the branch as the primary session via resumeSession instead, which reuses the runtime already warm-cached by forkBranch's ensureSessionState/updateSessionState calls, so it doesn't cost an extra resume RPC. Fixes #93444 --- .../hooks/use-session-actions.test.tsx | 24 ++++++++++++++----- .../hooks/use-session-actions/index.ts | 16 +++++-------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/apps/desktop/src/app/session/hooks/use-session-actions.test.tsx b/apps/desktop/src/app/session/hooks/use-session-actions.test.tsx index c0b0ec6359..093ef8feeb 100644 --- a/apps/desktop/src/app/session/hooks/use-session-actions.test.tsx +++ b/apps/desktop/src/app/session/hooks/use-session-actions.test.tsx @@ -1402,12 +1402,23 @@ describe('branchStoredSession desktop source tagging', () => { vi.restoreAllMocks() }) - it('opens the branch as a new tab and leaves the parent chat selected', async () => { + it('opens the branch as the primary session in the main workspace (#93444)', async () => { const requestGateway = vi.fn(async (method: string) => { if (method === 'session.create') { return { session_id: 'branch-runtime', stored_session_id: 'branch-stored' } as never } + if (method === 'session.resume') { + return { + info: {}, + message_count: 0, + messages: [], + resumed: 'branch-stored', + session_id: 'branch-runtime', + session_key: 'branch-stored' + } as never + } + return {} as never }) @@ -1432,11 +1443,12 @@ describe('branchStoredSession desktop source tagging', () => { await expect(branchStoredSession!('stored-parent')).resolves.toBe(true) - // The branch opened as its own tab... - expect($sessionTiles.get().some(tile => tile.storedSessionId === 'branch-stored')).toBe(true) - // ...without stealing the primary selection or navigating away from the parent. - expect($selectedStoredSessionId.get()).toBe('stored-parent') - expect(navigate).not.toHaveBeenCalledWith(sessionRoute('branch-stored')) + // The branch becomes the primary session — this is what routes the main + // workspace area to it, not just a new sidebar row. + expect($selectedStoredSessionId.get()).toBe('branch-stored') + // It must not ALSO exist as a tile: a session is either the main thread or + // a tile, never both (resumeSession closes any tile with the same id). + expect($sessionTiles.get().some(tile => tile.storedSessionId === 'branch-stored')).toBe(false) }) it('tags desktop branch sessions as desktop sessions', async () => { 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.ts index 540058dc53..5001c3f6d3 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 @@ -1649,8 +1649,6 @@ export function useSessionActions({ routedSessionId ) - // The branch opens as its own tile in the parent's worktree, not as the - // primary session — keep its runtime out of the main composer atoms. const runtimeInfo = applyRuntimeInfo(branched.info, { foreground: false }) patchSessionWorkspace(routedSessionId, runtimeInfo?.cwd) @@ -1658,13 +1656,11 @@ export function useSessionActions({ updateSessionState(branched.session_id, state => ({ ...state, ...runtimeInfo }), routedSessionId) } - // Open the branch as its own tab and switch to it, leaving the parent - // chat exactly where it is. Prime the tile with the create runtime so it - // skips a redundant resume. Do NOT select it as the primary session - // first — openSessionTile no-ops when the id is already primary. - openSessionTile(routedSessionId, 'center') - patchSessionTile(routedSessionId, { runtimeId: branched.session_id }) - revealTreePane(`session-tile:${routedSessionId}`) + // Load the branch as the primary session so it opens in the main + // workspace, not just a sidebar row. resumeSession reuses the runtime + // warm-cached above (ensureSessionState/updateSessionState) instead of + // an extra resume RPC. + await resumeSession(routedSessionId) broadcastSessionsChanged() return true @@ -1678,7 +1674,7 @@ export function useSessionActions({ }, 0) } }, - [copy, creatingSessionRef, ensureSessionState, requestGateway, updateSessionState] + [copy, creatingSessionRef, ensureSessionState, requestGateway, resumeSession, updateSessionState] ) // Branch the open chat — optionally from a specific message — off its live transcript.