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 e00960de2f2a..3c1bd45e0758 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 @@ -6,6 +6,7 @@ import { afterEach, describe, expect, it, vi } from 'vitest' import { getSessionMessages, type SessionInfo } from '@/hermes' import { createClientSessionState } from '@/lib/chat-runtime' import { $activeGatewayProfile, $newChatProfile } from '@/store/profile' +import { $projectScope, $projectTree, ALL_PROJECTS } from '@/store/projects' import { $activeSessionId, $currentCwd, @@ -113,6 +114,8 @@ describe('createBackendSessionForSend profile routing', () => { cleanup() $newChatProfile.set(null) $activeGatewayProfile.set('default') + $projectScope.set(ALL_PROJECTS) + $projectTree.set([]) $currentCwd.set('') vi.restoreAllMocks() }) @@ -161,6 +164,24 @@ describe('createBackendSessionForSend profile routing', () => { expect(params).toMatchObject({ cwd: '/remote/worktree' }) }) + + it('falls back to the entered project cwd when the current cwd is blank', async () => { + const params = await createWith(() => { + $projectTree.set([ + { + id: 'p_app', + label: 'App', + path: '/repo/app', + repos: [{ groups: [], id: '/repo/app', label: 'app', path: '/repo/app', sessionCount: 0 }], + sessionCount: 0 + } + ]) + $projectScope.set('p_app') + $currentCwd.set('') + }) + + expect(params).toMatchObject({ cwd: '/repo/app' }) + }) }) // ── Resume failure recovery (the "stuck loading session window" bug) ────────── 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 2b51f002e4b8..ae68e7d83ce9 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 @@ -38,8 +38,7 @@ import { setSessionStartedAt, setSessionsTotal, setTurnStartedAt, - setYoloActive, - workspaceCwdForNewSession + setYoloActive } from '@/store/session' import { broadcastSessionsChanged } from '@/store/session-sync' import { isWatchWindow } from '@/store/windows' @@ -163,7 +162,7 @@ export function useSessionActions({ // a backend resolves its own launch profile to None (_profile_home). const newChatProfile = $newChatProfile.get() ?? normalizeProfileKey($activeGatewayProfile.get()) await ensureGatewayProfile(newChatProfile) - const cwd = $currentCwd.get().trim() || workspaceCwdForNewSession() + const cwd = $currentCwd.get().trim() || resolveNewSessionCwd() // The composer's model/effort/fast is sticky UI state ($currentModel, // $currentProvider, $currentReasoningEffort, $currentFastMode). Ship it // with every session.create so the new chat opens on whatever the picker