The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): resolve a cold focused tile's cwd beyond the recents page (#76535)
Austin Pickettff7b9d1a2c85
diff --git a/apps/desktop/src/store/session-states.test.ts b/apps/desktop/src/store/session-states.test.tsindex a80792302a6..5608b37844e 100644--- a/apps/desktop/src/store/session-states.test.ts+++ b/apps/desktop/src/store/session-states.test.ts@@ -13,6 +13,7 @@ import {import { $connectionsRegistry } from '@/store/connection-registry-state'import { setPrimaryGateway, setPrimaryGatewayConnection } from '@/store/gateway'import { $activeGatewayProfile } from '@/store/profile'+import { $projectTree } from '@/store/projects'import {$activeSessionId,$connection,@@ -20,7 +21,8 @@ import {$workspaceCwdOwner,setCurrentCwd,setSessionOwnerHint,- setSessions+ setSessions,+ setUnlistedSessionOwnerRows} from '@/store/session'import { $focusedStoredSessionId } from '@/store/session-focus'import type { SessionProfileRoute } from '@/store/session-request-router'@@ -1180,6 +1182,11 @@ describe('$focusedStoredSessionId in Bot Mode (#96062)', () => {$layoutTree.set(null)$selectedStoredSessionId.set(null)setWorkspaceScope('sessions')+ // The cwd-ladder tests below load rows into slices the describe never+ // touched before; leave every store as empty as they found it.+ setSessions([])+ setUnlistedSessionOwnerRows([])+ $projectTree.set([])})it('a Bots-pane click keeps the main-zone bot tile focused instead of collapsing to a null selection edge', () => {@@ -1274,6 +1281,100 @@ describe('$focusedStoredSessionId in Bot Mode (#96062)', () => {expect($focusedStoredSessionId.get()).toBe('primary-1')expect($focusedWorkspaceCwd.get()).toBe('/repo-primary-project')})++ it('resolves a cold focused tile cwd from the unlisted owner rows, not only the paginated recents page (#76535)', () => {+ // A cold restored tile outside the recents page and project preview caps+ // has no $sessions row; a resume-time by-id resolve parked its row on the+ // unlisted-owner atom, which $focusedWorkspaceCwd never searched — so+ // Files showed "No project open" for a valid tile whose cwd was known.+ $selectedStoredSessionId.set('primary-1')+ setSessions([{ cwd: '/repo-primary', id: 'primary-1' } as never])+ setUnlistedSessionOwnerRows([{ cwd: '/repo-cold', id: 'cold-4' } as never])+ $sessionTiles.set([{ storedSessionId: 'cold-4', workspaceMode: 'sessions' } as never])+ $sessionStates.set({})+ $layoutTree.set(+ split('row', [+ group(['files'], { active: 'files', id: 'grp-files' }),+ group(['workspace', tilePane('cold-4')], { active: tilePane('cold-4'), id: 'grp-main' })+ ])+ )+ noteActiveTreeGroup('grp-files')++ expect($focusedStoredSessionId.get()).toBe('cold-4')+ expect($focusedWorkspaceCwd.get()).toBe('/repo-cold')+ })++ it('resolves a cold focused tile cwd from the project tree lanes (#76535)', () => {+ // Same class, second cache: a session opened as a tab from a project+ // group lives only in the (capped) tree rows until new activity lands it+ // in recents. tileStoredRow already resolves titles this way; cwd must+ // agree.+ $selectedStoredSessionId.set('primary-1')+ setSessions([{ cwd: '/repo-primary', id: 'primary-1' } as never])+ $projectTree.set([+ {+ id: 'proj',+ label: 'proj',+ path: null,+ repos: [+ {+ id: 'repo',+ label: 'repo',+ path: null,+ groups: [{ id: 'lane', label: 'lane', path: null, sessions: [{ cwd: '/repo-tree', id: 'tree-5' } as never] }],+ sessionCount: 1+ }+ ],+ sessionCount: 1+ } as never+ ])+ $sessionTiles.set([{ storedSessionId: 'tree-5', workspaceMode: 'sessions' } as never])+ $sessionStates.set({})+ $layoutTree.set(+ split('row', [+ group(['files'], { active: 'files', id: 'grp-files' }),+ group(['workspace', tilePane('tree-5')], { active: tilePane('tree-5'), id: 'grp-main' })+ ])+ )+ noteActiveTreeGroup('grp-files')++ expect($focusedStoredSessionId.get()).toBe('tree-5')+ expect($focusedWorkspaceCwd.get()).toBe('/repo-tree')+ })++ it('widens the primary historical fallback the same way — a selected session outside recents resolves from the tree (#76535)', () => {+ // The sibling path of the same defect: the primary branch's historical+ // fallback (no owner-gated currentCwd, no live slice) scanned recents+ // only. The focused-session row ladder must agree for both branches.+ $selectedStoredSessionId.set('deep-primary')+ setCurrentCwd('')+ $sessionTiles.set([])+ $sessionStates.set({})+ $projectTree.set([+ {+ id: 'proj',+ label: 'proj',+ path: null,+ repos: [+ {+ id: 'repo',+ label: 'repo',+ path: null,+ groups: [+ { id: 'lane', label: 'lane', path: null, sessions: [{ cwd: '/repo-deep-primary', id: 'deep-primary' } as never] }+ ],+ sessionCount: 1+ }+ ],+ sessionCount: 1+ } as never+ ])+ $layoutTree.set(split('row', [group(['workspace'], { active: 'workspace', id: 'grp-main' })]))+ noteActiveTreeGroup('grp-main')++ expect($focusedStoredSessionId.get()).toBe('deep-primary')+ expect($focusedWorkspaceCwd.get()).toBe('/repo-deep-primary')+ })})describe('focusedSessionNeedsRoute', () => {diff --git a/apps/desktop/src/store/session-states.ts b/apps/desktop/src/store/session-states.tsindex 1c5b76d3525..4b3b960226c 100644--- a/apps/desktop/src/store/session-states.ts+++ b/apps/desktop/src/store/session-states.ts@@ -54,14 +54,18 @@ import {import { forgetPendingRuntimeTabs } from './preview-ownership'import { dropPreviewArtifactsForProfile, migratePreviewArtifactsForProfile } from './preview-status'import { $activeGatewayProfile, normalizeProfileKey } from './profile'+import { $projectTree } from './projects'import { clearAllProviderWaits, clearSessionProviderWait } from './provider-wait'import {$activeSessionId,$connection,+ $cronSessions,$currentCwd,$lastReadAtBySessionId,+ $messagingSessions,$selectedStoredSessionId,$sessions,+ $unlistedSessionOwnerRows,$workspaceCwdOwner,clearReadBaseline,getSessionOwnerHint,@@ -3095,10 +3099,42 @@ export const $focusedSessionState = computed([$focusedRuntimeId, $sessionStates]runtimeId ? states[runtimeId] : undefined)+/** The best cached row for a stored session id, across every slice the sidebar+ * has loaded (#76535): the owner-lookup rows (recents + cron + messaging ++ * unlisted-draft/hidden stubs) and the project tree (a tile's session is+ * often older than the paginated recents page, so the tree is the only+ * loaded copy). Never a by-id fetch — a computed must stay synchronous. */+function focusedSessionRow(storedSessionId: string): SessionInfo | undefined {+ return (+ ownerLookupSessionRows().find(s => sessionMatchesStoredId(s, storedSessionId)) ??+ $projectTree+ .get()+ .flatMap(project => [+ ...(project.previewSessions ?? []),+ ...project.repos.flatMap(repo => repo.groups.flatMap(group => group.sessions))+ ])+ .find(s => sessionMatchesStoredId(s, storedSessionId))+ )+}+/** The workspace CWD of the currently focused session (the focused tile's cwd,* else the primary session's confirmed workspace cwd, with fallback to historical session cwd). */export const $focusedWorkspaceCwd = computed(- [$focusedStoredSessionId, $selectedStoredSessionId, $focusedSessionState, $sessions, $currentCwd, $workspaceCwdOwner],+ [+ $focusedStoredSessionId,+ $selectedStoredSessionId,+ $focusedSessionState,+ $sessions,+ $currentCwd,+ $workspaceCwdOwner,+ $unlistedSessionOwnerRows,+ $projectTree,+ // focusedSessionRow reads the cron/messaging slices through the owner+ // lookup; listing them keeps a cron/messaging row landing reactive without+ // reading them eagerly in the computed body.+ $cronSessions,+ $messagingSessions+ ],(focusedStoredId,selectedStoredId,@@ -3113,6 +3149,7 @@ export const $focusedWorkspaceCwd = computed(const tileCwd = (focusedSessionState?.cwd ||sessions.find(s => sessionMatchesStoredId(s, focusedStoredId))?.cwd ||+ focusedSessionRow(focusedStoredId)?.cwd ||'').trim()@@ -3129,6 +3166,7 @@ export const $focusedWorkspaceCwd = computed(const fallbackCwd = (focusedSessionState?.cwd ||sessions.find(s => sessionMatchesStoredId(s, selectedStoredId))?.cwd ||+ focusedSessionRow(selectedStoredId)?.cwd ||'').trim()