From e0a999aa8a22ce24caa5f9748116daec32779ad7 Mon Sep 17 00:00:00 2001 From: Brooklyn Nicholson Date: Wed, 3 Jun 2026 00:25:19 -0500 Subject: [PATCH] fix(desktop): label in-flight new chats with the first message The send path created the optimistic sidebar row with a null preview, so a new chat read "Untitled session" until its turn persisted and auto-title ran. With concurrent new chats now preserved across refreshes, several "Untitled session" rows could show at once. Seed the optimistic preview with the user's first message (the branch path already does this) so each in-flight row is labeled immediately. The server's own preview/title supersedes it once the turn persists. --- apps/desktop/src/app/session/hooks/use-prompt-actions.ts | 4 ++-- apps/desktop/src/app/session/hooks/use-session-actions.ts | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions.ts b/apps/desktop/src/app/session/hooks/use-prompt-actions.ts index 62d685fc7..e1e13b9d4 100644 --- a/apps/desktop/src/app/session/hooks/use-prompt-actions.ts +++ b/apps/desktop/src/app/session/hooks/use-prompt-actions.ts @@ -65,7 +65,7 @@ interface PromptActionsOptions { activeSessionIdRef: MutableRefObject busyRef: MutableRefObject branchCurrentSession: () => Promise - createBackendSessionForSend: () => Promise + createBackendSessionForSend: (preview?: string | null) => Promise handleSkinCommand: (arg: string) => string requestGateway: (method: string, params?: Record) => Promise selectedStoredSessionIdRef: MutableRefObject @@ -296,7 +296,7 @@ export function usePromptActions({ if (!sessionId) { try { - sessionId = await createBackendSessionForSend() + sessionId = await createBackendSessionForSend(visibleText) } catch (err) { dropOptimistic(null) releaseBusy() diff --git a/apps/desktop/src/app/session/hooks/use-session-actions.ts b/apps/desktop/src/app/session/hooks/use-session-actions.ts index 7b301f7f3..a07bfdb64 100644 --- a/apps/desktop/src/app/session/hooks/use-session-actions.ts +++ b/apps/desktop/src/app/session/hooks/use-session-actions.ts @@ -303,7 +303,7 @@ export function useSessionActions({ [activeSessionIdRef, busyRef, navigate, selectedStoredSessionIdRef] ) - const createBackendSessionForSend = useCallback(async (): Promise => { + const createBackendSessionForSend = useCallback(async (preview: string | null = null): Promise => { const startingActiveSessionId = activeSessionIdRef.current const startingStoredSessionId = selectedStoredSessionIdRef.current const startingRouteToken = getRouteToken() @@ -330,7 +330,11 @@ export function useSessionActions({ ensureSessionState(created.session_id, stored) if (stored) { - upsertOptimisticSession(created, stored) + // Seed the sidebar preview with the user's first message so the row + // reads meaningfully while the turn is in flight, instead of flashing + // "Untitled session" until the turn persists and auto-title runs. The + // server later returns its own preview/title and supersedes this. + upsertOptimisticSession(created, stored, null, preview?.trim() || null) navigate(sessionRoute(stored), { replace: true }) }