fix(desktop): a tab promoted into MAIN keeps its owner for session.control.read

KoNit-K's two commits stamp an owner on tab-strip `+` drafts at create
time, which clears the banner ON the draft tile. Promoting that draft into
main (⌘W on the workspace tab, or a tab dragged out of main) still raised
"Session controls unavailable": closeSessionTile drops the tile AND evicts
its $sessionStates mirror in one tick, resumeSession then makes the
runtime active before the view republishes, and the composer's control
read lands in that gap — storedSessionIdForRuntimeId had no tile, no
mirror, and so never reached the stored-id hint that was there all along.

Give the translation one more rung: the active runtime maps to the
selected stored id. Only main's own binding qualifies; unrelated runtime
ids stay unknown and keep failing closed.

Live (Electron + mock gateway, bot chat in main, `+` draft, close main's
tab so the draft promotes): main → banner; KoNit-K alone → banner on
promote; with this rung → no banner at any step, send works.

Invariant test red on main, green here.
This commit is contained in:
teknium1
2026-09-13 12:55:55 -07:00
committed by Teknium
parent 88a7e6f96a
commit 2292c64738
2 changed files with 33 additions and 2 deletions
+21 -1
View File
@@ -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])
+12 -1
View File
@@ -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'