diff --git a/desktop/src/stores/chatStore.test.ts b/desktop/src/stores/chatStore.test.ts index fd92413b..eacd03ed 100644 --- a/desktop/src/stores/chatStore.test.ts +++ b/desktop/src/stores/chatStore.test.ts @@ -287,6 +287,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 642969c7..0fced879 100644 --- a/desktop/src/stores/chatStore.ts +++ b/desktop/src/stores/chatStore.ts @@ -902,6 +902,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: {}, @@ -948,7 +953,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' }) }