Merge pull request #58241 from tianma-if/codex/fix-desktop-project-session-cwd

fix(desktop): preserve project cwd for new sessions
This commit is contained in:
brooklyn! 2026-07-12 03:29:07 -05:00 committed by GitHub
commit 095b9eed38
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 3 deletions

View file

@ -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) ──────────

View file

@ -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