diff --git a/desktop/src/stores/chatStore.test.ts b/desktop/src/stores/chatStore.test.ts index 17f1ba71..ff780feb 100644 --- a/desktop/src/stores/chatStore.test.ts +++ b/desktop/src/stores/chatStore.test.ts @@ -215,6 +215,40 @@ describe('chatStore history mapping', () => { }) }) + it('does not prewarm an existing transcript when opening it for history review', () => { + sessionStoreSnapshot.sessions = [{ + id: TEST_SESSION_ID, + title: 'Existing transcript', + createdAt: '2026-06-20T10:00:00.000Z', + modifiedAt: '2026-06-20T10:30:00.000Z', + messageCount: 4, + projectPath: '/workspace/project', + workDir: '/workspace/project', + workDirExists: true, + }] + + useChatStore.getState().connectToSession(TEST_SESSION_ID) + + expect(sendMock).not.toHaveBeenCalledWith(TEST_SESSION_ID, { type: 'prewarm_session' }) + }) + + it('still prewarms empty placeholder sessions so new chats start quickly', () => { + sessionStoreSnapshot.sessions = [{ + id: TEST_SESSION_ID, + title: 'New Session', + createdAt: '2026-06-20T10:00:00.000Z', + modifiedAt: '2026-06-20T10:00:00.000Z', + messageCount: 0, + projectPath: '/workspace/project', + workDir: '/workspace/project', + workDirExists: true, + }] + + useChatStore.getState().connectToSession(TEST_SESSION_ID) + + expect(sendMock).toHaveBeenCalledWith(TEST_SESSION_ID, { type: 'prewarm_session' }) + }) + it('preserves thinking blocks when restoring transcript history', () => { const messages: MessageEntry[] = [ { diff --git a/desktop/src/stores/chatStore.ts b/desktop/src/stores/chatStore.ts index 07c28a5c..a6247145 100644 --- a/desktop/src/stores/chatStore.ts +++ b/desktop/src/stores/chatStore.ts @@ -892,6 +892,11 @@ async function fetchAndMapSessionHistory(sessionId: string) { const historyLoadsInFlight = new Map>() +function shouldPrewarmSession(sessionId: string): boolean { + const knownSession = useSessionStore.getState().sessions.find((session) => session.id === sessionId) + return !knownSession || knownSession.messageCount === 0 +} + export const useChatStore = create((set, get) => ({ sessions: {}, @@ -938,7 +943,11 @@ export const useChatStore = create((set, get) => ({ if (runtimeSelection) { wsManager.send(sessionId, { type: 'set_runtime_config', ...runtimeSelection }) } - if (!sessionId.startsWith('__') && !useTeamStore.getState().getMemberBySessionId(sessionId)) { + if ( + !sessionId.startsWith('__') && + !useTeamStore.getState().getMemberBySessionId(sessionId) && + shouldPrewarmSession(sessionId) + ) { wsManager.send(sessionId, { type: 'prewarm_session' }) }