The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): own a project-cwd tile by the project's profile (#124265, salvage #124296)
teknium1f8deae40fd9c
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.tsxindex 69d735e47a1..8d2dc587638 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@@ -5305,6 +5305,46 @@ describe('openNewSessionTile workspace target', () => {undefined)})++ // #124265: the project "+" while a chat is occupied (and project-row drags)+ // stack a tile with the project's cwd instead of running the fresh-draft+ // pin. The tile must still be owned by the profile the project tree is+ // rendered under, not by a stale new-chat pin left from a profile pick.+ it('owns a project-cwd tile by the project profile over a stale new-chat pin', async () => {+ const storedSessionId = 'stored-project-tile-work'+ setConnection({ mode: 'local' } as never)+ $profiles.set([{ name: 'default' }, { name: 'work' }] as never)+ $activeGatewayProfile.set('work')+ $newChatProfile.set('default')++ let createParams: Record<string, unknown> | undefined++ const requestGateway = vi.fn(async (method: string, params?: Record<string, unknown>) => {+ if (method === 'session.create') {+ createParams = params++ return {+ info: { cwd: '/repo/work', model: 'test-model', tools: {}, skills: {} },+ session_id: RUNTIME_SESSION_ID,+ stored_session_id: storedSessionId+ } as never+ }++ throw new Error(`Unexpected ambient RPC: ${method}`)+ })++ let handle: HarnessHandle | null = null+ render(<Harness onReady={value => (handle = value)} requestGateway={requestGateway} />)+ await waitFor(() => expect(handle).not.toBeNull())++ await act(async () => {+ await handle!.openNewSessionTile('center', { cwd: '/repo/work', listed: false })+ })++ expect(createParams).toMatchObject({ cwd: '/repo/work', profile: 'work' })+ expect($sessionTiles.get()).toContainEqual(expect.objectContaining({ ownerProfile: 'work', storedSessionId }))+ expect(knownOwnerForSession(storedSessionId)).toBe('work')+ })})describe('openNewSessionTile unlisted owner (#102792)', () => {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.tsindex 3c8294a8465..dec91021f21 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@@ -61,7 +61,7 @@ import {resolveNewChatOwnerRoute} from '@/store/profile'import { $projectScope } from '@/store/project-scope'-import { resolveNewSessionCwd } from '@/store/projects'+import { projectProfile, resolveNewSessionCwd } from '@/store/projects'import { clearAllPrompts, receiveApprovalRequest, replayPendingApproval } from '@/store/prompts'import { clearStoredTranscriptReadOnly, markStoredTranscriptReadOnly } from '@/store/read-only-transcript'import {@@ -878,6 +878,15 @@ export function useSessionActions({const listed = options?.listed ?? truetry {+ // A tile anchored at a project path belongs to the profile the project+ // tree is rendered under — the same owner the fresh-draft "+" pins+ // (#79005). The occupied-chat "+" and project-row drags reach this+ // path instead, where a stale $newChatProfile pin would otherwise win+ // and land the session in the wrong profile (#124265). All-profiles+ // view has no owner and keeps the ordinary fallback.+ const optionProfile =+ options?.profile ?? (typeof options?.cwd === 'string' ? (projectProfile() ?? undefined) : undefined)+// Fresh tile → the caller's workspace when one was named (the sidebar// "+" on a project/worktree lane), explicit null means Home/detached,// else the resolved new-session cwd (project scope → configured default).@@ -885,9 +894,7 @@ export function useSessionActions({// to fall through into the last project folder while main chat was// occupied (openTab path for "New session in Home").const explicitTarget =- options?.profile !== undefined ||- options?.cwd !== undefined ||- options?.workspaceScope?.ownerRoute !== undefined+ optionProfile !== undefined || options?.cwd !== undefined || options?.workspaceScope?.ownerRoute !== undefinedconst defaultTarget = options?.route === undefined && !explicitTarget ? defaultNewSessionTarget() : null@@ -895,16 +902,14 @@ export function useSessionActions({options?.route !== undefined? options.route: (options?.workspaceScope?.ownerRoute ??- (defaultTarget ? defaultTarget.route : resolveNewChatOwnerRoute(options?.profile)))+ (defaultTarget ? defaultTarget.route : resolveNewChatOwnerRoute(optionProfile)))// A named local profile uses the legacy profile-only transport (no// connectionId). Tab-strip "+" omits `options.profile`; the draft or// active profile is still the owner. Unique non-default local roster// names stay authoritative; default/remote/duplicate stay unresolved.const requestedProfile = normalizeProfileKey(- typeof options?.profile === 'string' && options.profile- ? options.profile- : defaultTarget?.profile || $newChatProfile.get() || $activeGatewayProfile.get()+ optionProfile || defaultTarget?.profile || $newChatProfile.get() || $activeGatewayProfile.get())const legacyOwnerProfile =