diff --git a/apps/desktop/src/store/session-states.test.ts b/apps/desktop/src/store/session-states.test.ts index ad79f4756e..edde97bb2c 100644 --- a/apps/desktop/src/store/session-states.test.ts +++ b/apps/desktop/src/store/session-states.test.ts @@ -11,7 +11,7 @@ import { workspaceScopeKey } from '@/components/pane-shell/workspace-scope' import { $activeGatewayProfile } from '@/store/profile' -import { $activeSessionId, $connection, $selectedStoredSessionId, setSessions } from '@/store/session' +import { $activeSessionId, $connection, $selectedStoredSessionId, setSessionOwnerHint, setSessions } from '@/store/session' import type { SessionProfileRoute } from '@/store/session-request-router' import type { SessionTile } from '@/store/session-states' import type * as SessionStatesModule from '@/store/session-states' @@ -1269,6 +1269,26 @@ describe('knownOwnerForSession / requestForOwnedSession (#91684 client half)', ( expect(knownOwnerForSession('stored-2')).toBe('loki') }) + // A tile promoted into MAIN (⌘W on the workspace tab, its tab dragged out of + // main) loses its tile and its evicted mirror entry in the same tick, while + // the resume has already made its runtime the active one. The composer's + // control read for that runtime must still find the stored-id owner hint + // instead of failing closed with "Session controls unavailable" (#108369). + it('translates the active runtime through the selected stored id when no tile or mirror binds it', () => { + setSessionOwnerHint('stored-main', { connectionId: 'local', profile: 'alpha' }) + $sessionTiles.set([]) + $sessionStates.set({}) + $selectedStoredSessionId.set('stored-main') + $activeSessionId.set('rt-main') + + expect(knownOwnerForSession('rt-main')).toEqual({ connectionId: 'local', profile: 'alpha' }) + // Only MAIN's own runtime gets this rung: an unrelated runtime id stays unknown. + expect(knownOwnerForSession('rt-other')).toBeUndefined() + + $activeSessionId.set(null) + $selectedStoredSessionId.set(null) + }) + it('keeps a session row connection owner when profiles share the same name', () => { setSessions([{ connection_id: 'source-b', id: 'stored-shared', profile: 'default' } as never]) diff --git a/apps/desktop/src/store/session-states.ts b/apps/desktop/src/store/session-states.ts index 5fceec9b28..b663c9e6fa 100644 --- a/apps/desktop/src/store/session-states.ts +++ b/apps/desktop/src/store/session-states.ts @@ -1146,7 +1146,18 @@ export function storedSessionIdForRuntimeId(sessionId: string): null | string { // Without this rung such ids fell straight to the ambient socket. const mirrored = $sessionStates.get()[sessionId]?.storedSessionId?.trim() - return mirrored || null + if (mirrored) { + return mirrored + } + + // Main's own binding. A tile promoted into main (⌘W on the workspace tab, + // a tab dragged out of main) loses its tile AND its evicted mirror entry in + // the same tick, while the resume sets the runtime active before the view + // republishes the mirror. The composer's control read lands in that gap + // and, with nothing to translate, never reaches the stored-id hint. + const selected = $selectedStoredSessionId.get() + + return sessionId === $activeSessionId.get() && selected ? selected : null } const BOT_CHAT_SCOPE_KEY = 'hermes.desktop.botChatSessions.v1'