Skip to content

The agent that grows with you

fix(desktop): front main when a Bot roster click targets the chat it already holds

liuhao102499aa3ca0af9b
diff --git a/apps/desktop/src/app/open-session.test.ts b/apps/desktop/src/app/open-session.test.ts
index ba67af80e52..d0292c1df2d 100644
--- a/apps/desktop/src/app/open-session.test.ts
+++ b/apps/desktop/src/app/open-session.test.ts
@@ -1,6 +1,7 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'
const focusOpenSession = vi.fn()
+const frontMainIfSelected = vi.fn((storedSessionId: string) => false)
const openSessionTile = vi.fn()
const reuseBlankDraftTile = vi.fn()
const setSessionTileWorkspaceScope = vi.fn()
@@ -18,6 +19,7 @@ vi.mock('@/store/session-states', () => ({
!focused || (focused === 'main' && workspaceIsPage),
focusedSessionWorkspaceScope: () => focusedSessionWorkspaceScope(),
focusOpenSession: (...args: unknown[]) => focusOpenSession(...args),
+ frontMainIfSelected: (storedSessionId: string) => frontMainIfSelected(storedSessionId),
openSessionTile: (...args: unknown[]) => openSessionTile(...args),
reuseBlankDraftTile: (...args: unknown[]) => reuseBlankDraftTile(...args),
setSessionTileWorkspaceScope: (...args: unknown[]) => setSessionTileWorkspaceScope(...args)
@@ -68,6 +70,8 @@ describe('openSession', () => {
beforeEach(() => {
navigate.mockClear()
focusOpenSession.mockReset()
+ frontMainIfSelected.mockClear()
+ frontMainIfSelected.mockReturnValue(false)
openSessionTile.mockReset()
openSessionInNewWindow.mockReset()
canOpenSessionWindow.mockReturnValue(true)
@@ -107,6 +111,30 @@ describe('openSession', () => {
expect(navigate).toHaveBeenCalledWith('/c/s1')
})
+ it('in-place fronts main when a Bot-scoped open targets the chat main already holds', () => {
+ // #125899: the bot lost its tile (closing main promoted it into the
+ // workspace pane) and another bot's tab is active. focusOpenSession won't
+ // claim 'main' for a Bot scope, and the route already points at the chat
+ // so navigating changes nothing — only the explicit front makes the
+ // roster click visible.
+ const scope = { workspaceMode: 'bots' as const, workspaceOwnerKey: 'bot:local::emp' }
+ $selectedStoredSessionId.set('s1')
+ focusOpenSession.mockReturnValue(null)
+ frontMainIfSelected.mockReturnValue(true)
+
+ openSession('s1', navigate, 'in-place', scope)
+
+ expect(navigate).toHaveBeenCalledWith('/c/s1')
+ expect(frontMainIfSelected).toHaveBeenCalledWith('s1')
+ expect(openSessionTile).not.toHaveBeenCalled()
+ })
+
+ it('in-place skips the main front when focus already landed somewhere', () => {
+ focusOpenSession.mockReturnValue('tile')
+ openSession('s1', navigate)
+ expect(frontMainIfSelected).not.toHaveBeenCalled()
+ })
+
it('main routes to the workspace even when the session is already open as a tile', () => {
focusOpenSession.mockReturnValue('tile')
openSession('s1', navigate, 'main')
diff --git a/apps/desktop/src/app/open-session.ts b/apps/desktop/src/app/open-session.ts
index 9951a536f5c..6b3cc4d29f4 100644
--- a/apps/desktop/src/app/open-session.ts
+++ b/apps/desktop/src/app/open-session.ts
@@ -21,6 +21,7 @@ import {
focusedSessionNeedsRoute,
focusedSessionWorkspaceScope,
focusOpenSession,
+ frontMainIfSelected,
openSessionTile,
reuseBlankDraftTile,
setSessionTileWorkspaceScope
@@ -196,7 +197,20 @@ export function openSession(
// otherwise load it into main. From a full page (artifacts, skills, …) a
// `'main'` hit still has to route back: fronting the workspace tab alone
// leaves the page showing.
- if (focusedSessionNeedsRoute(focusOpenSession(storedSessionId, workspaceScope), $workspaceIsPage.get())) {
+ const focused = focusOpenSession(storedSessionId, workspaceScope)
+
+ if (focusedSessionNeedsRoute(focused, $workspaceIsPage.get())) {
navigate(sessionRoute(storedSessionId))
}
+
+ // The target may also be the chat MAIN already holds — a Bot Mode roster
+ // click whose owner lost its tile (closing main promoted a neighbour tile
+ // into the workspace pane). focusOpenSession declined the 'main' hit for the
+ // Bot scope because a Bot tab for the same stored id must stay mintable, and
+ // the navigate above changed nothing (the route already points there), so
+ // front the pane here — or a zone parked on another bot's tile leaves the
+ // click looking dead (#125899).
+ if (!focused) {
+ frontMainIfSelected(storedSessionId)
+ }
}
diff --git a/apps/desktop/src/store/session-states.test.ts b/apps/desktop/src/store/session-states.test.ts
index 051bad96afe..56d03d4eaff 100644
--- a/apps/desktop/src/store/session-states.test.ts
+++ b/apps/desktop/src/store/session-states.test.ts
@@ -35,6 +35,7 @@ import {
focusOpenSession,
focusWorkspaceOwnerSessionTile,
foregroundSessionScopes,
+ frontMainIfSelected,
isSessionRemote,
knownOwnerForSession,
markSelectionRestore,
@@ -555,6 +556,51 @@ describe('SessionTile workspace scope', () => {
})
})
+describe('frontMainIfSelected (#125899 — Bot row click while its chat sits in main)', () => {
+ const activePane = () => {
+ const tree = $layoutTree.get()
+
+ return tree?.type === 'group' ? tree.active : null
+ }
+
+ afterEach(() => {
+ $layoutTree.set(null)
+ $selectedStoredSessionId.set(null)
+ $sessionTiles.set([])
+ })
+
+ it('fronts the workspace pane over another bot tile when main holds the chat', () => {
+ // The promoted-into-main state: closing main dropped the bot tile and
+ // loaded its chat as the primary; the zone sits on another bot tile.
+ $selectedStoredSessionId.set('bot-chat')
+ $layoutTree.set(group(['workspace', tilePane('other-bot')], { active: tilePane('other-bot'), id: 'main' }))
+
+ expect(frontMainIfSelected('bot-chat')).toBe(true)
+ expect(activePane()).toBe('workspace')
+ })
+
+ it('matches a compression-lineage alias of the chat main holds', () => {
+ setSessions([{ _lineage_ids: ['seg-1', 'seg-2'], _lineage_root_id: 'seg-1', id: 'seg-2' } as never])
+ $selectedStoredSessionId.set('seg-2')
+ $layoutTree.set(group(['workspace'], { id: 'main' }))
+
+ expect(frontMainIfSelected('seg-1')).toBe(true)
+ setSessions([])
+ })
+
+ it('reports false and fronts nothing when main holds another chat', () => {
+ $selectedStoredSessionId.set('other-chat')
+ $layoutTree.set(group(['workspace', tilePane('other-bot')], { active: tilePane('other-bot'), id: 'main' }))
+
+ expect(frontMainIfSelected('bot-chat')).toBe(false)
+ expect(activePane()).toBe(tilePane('other-bot'))
+ })
+
+ it('reports false when main holds nothing', () => {
+ expect(frontMainIfSelected('bot-chat')).toBe(false)
+ })
+})
+
describe('focusWorkspaceOwnerSessionTile', () => {
const botA = { workspaceMode: 'bots' as const, workspaceOwnerKey: 'bot:a' }
const botB = { workspaceMode: 'bots' as const, workspaceOwnerKey: 'bot:b' }
diff --git a/apps/desktop/src/store/session-states.ts b/apps/desktop/src/store/session-states.ts
index a426c56ac69..2a4b8831498 100644
--- a/apps/desktop/src/store/session-states.ts
+++ b/apps/desktop/src/store/session-states.ts
@@ -2551,16 +2551,39 @@ export function focusOpenSession(
// Already the main session: front the workspace tab and drop tile focus so
// the readouts + sidebar highlight come home (a no-op when main is focused).
- if (workspaceScope.workspaceMode === 'sessions' && aliases.includes($selectedStoredSessionId.get() ?? '')) {
- revealTreePane('workspace')
- noteActiveTreeGroup(null)
-
+ // Bot scopes never claim main here — a Bot tab for the same stored id must
+ // stay mintable — they front through frontMainIfSelected at their own door.
+ if (workspaceScope.workspaceMode === 'sessions' && frontMainIfSelected(storedSessionId)) {
return 'main'
}
return null
}
+/** Front the workspace pane when `storedSessionId` names the chat MAIN already
+ * holds (through any compression-lineage alias). False when main holds
+ * another chat or nothing — the caller then owns the open.
+ *
+ * The door for a Bot Mode roster click whose owner lost its tile: closing the
+ * main tab promotes a neighbouring tile INTO the workspace pane (dropping its
+ * tile, close-tab.ts), so the canonical Bot Chat lives in main with no tile
+ * left. The route already points at that session, so navigating is a no-op,
+ * and focusOpenSession won't claim the 'main' hit for a Bot scope — a Bot tab
+ * for the same stored id must stay mintable. Without this front, a zone
+ * parked on another bot's tile left the row click looking dead (#125899). */
+export function frontMainIfSelected(storedSessionId: string): boolean {
+ const aliases = lineageAliases(storedSessionId, $sessions.get())
+
+ if (!aliases.includes($selectedStoredSessionId.get() ?? '')) {
+ return false
+ }
+
+ revealTreePane('workspace')
+ noteActiveTreeGroup(null)
+
+ return true
+}
+
/** Front the tab a Bot Mode owner already has open and report its stored id:
* the tile the zone last had active for `workspaceOwnerKey` (the same
* window-local memory the strip restores on a scope switch), else the most