The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): discard stale Bot Chat tile before opening compression tip
finn763f8bf71b06eb5
diff --git a/apps/desktop/src/plugins/hermes-bots/canonical-chat-stale-tiles.test.ts b/apps/desktop/src/plugins/hermes-bots/canonical-chat-stale-tiles.test.tsnew file mode 100644index 00000000000..929de74349f--- /dev/null+++ b/apps/desktop/src/plugins/hermes-bots/canonical-chat-stale-tiles.test.ts@@ -0,0 +1,81 @@+/**+ * RED for hermes-agent#120810: a Bot Chat compression leaves two tabs+ * captioned with the bot name.+ *+ * openStoredBotChat (via openBotCanonicalChat) must run the same+ * owner-scoped stale-"Bot Chat" probe the roster click runs+ * (roster-actions focusExistingBotTab) against the registry id + resolved+ * tip BEFORE host.openSession, so the activity-refresh and reclaim opens+ * (which call openBotCanonicalChat directly) discard a tile keyed to the+ * old segment instead of leaving it beside the tip.+ */+import { beforeEach, describe, expect, it, vi } from 'vitest'++const { focusMock, hostMock, requestForBotMock } = vi.hoisted(() => ({+ focusMock: vi.fn(),+ hostMock: { focusOpenWorkspaceSession: vi.fn(), openSession: vi.fn() } as any,+ requestForBotMock: vi.fn()+}))++vi.mock('@hermes/plugin-sdk', () => ({+ BOT_CHAT_SESSION_HYDRATION_TIMEOUT_MS: 15_000,+ host: hostMock+}))++vi.mock('./routing', () => ({+ backendTargetProfile: (route: { targetProfile?: string } | null, name: string) => route?.targetProfile ?? name,+ botConnectionRoute: () => null,+ botRosterMeta: () => ({}),+ botWorkspaceOwnerKey: (bot: { connectionId?: string; name?: string } | null) =>+ `bot:${bot?.connectionId ? `${bot.connectionId}::` : ''}${bot?.name || 'default'}`,+ requestForBot: requestForBotMock+}))++vi.mock('./data', () => ({+ $botMeta: { get: () => ({}), set: vi.fn() },+ botMetaKey: (bot: { name?: string }) => bot?.name ?? '',+ botOwner: (owner: string) => ({ bot: { name: owner }, key: owner, name: owner, route: null }),+ persistBotMetaSnapshot: vi.fn()+}))++vi.mock('./shared', () => ({ getPluginCtx: () => null }))++async function loadModule() {+ vi.resetModules()+ return import('./canonical-chat')+}++beforeEach(() => {+ vi.clearAllMocks()+ hostMock.openSession.mockResolvedValue(undefined)+ hostMock.focusOpenWorkspaceSession = focusMock+ focusMock.mockReturnValue(null)+ requestForBotMock.mockImplementation(async (_bot: unknown, method: string) => {+ if (method === 'session.list') {+ return { sessions: [{ id: 'root-1', resolved_id: 'tip-9', root_title: 'Bot Chat', title: 'Bot Chat' }] }+ }+ return {}+ })+})++describe('120810: compressed Bot Chat discards the stale tile', () => {+ it('probes owner-scoped stale Bot Chat tiles before opening the tip', async () => {+ const { openBotCanonicalChat } = await loadModule()+ await openBotCanonicalChat('ops')++ expect(focusMock).toHaveBeenCalledTimes(1)+ const [ownerKey, probe, onlyIds] = focusMock.mock.calls[0]+ expect(ownerKey).toBe('bot:ops')+ expect(onlyIds).toEqual(expect.arrayContaining(['root-1', 'tip-9']))+ // Stale: Bot Chat-titled tile at an id that is neither registry nor tip.+ expect(probe({ storedSessionId: 'old-segment', workspaceTabTitle: 'Bot Chat' })).toBe(true)+ // Live tip and registry row are never stale.+ expect(probe({ storedSessionId: 'tip-9', workspaceTabTitle: 'Bot Chat' })).toBe(false)+ expect(probe({ storedSessionId: 'root-1', workspaceTabTitle: 'Bot Chat' })).toBe(false)+ // User + threads are never stale.+ expect(probe({ storedSessionId: 'side-1', workspaceTabTitle: 'Bot Chat' })).toBe(true)+ expect(probe({ storedSessionId: 'side-1', workspaceTabTitle: 'my thread' })).toBe(false)+ // Tip opens after the probe.+ expect(hostMock.openSession.mock.calls[0][0]).toBe('tip-9')+ })+})diff --git a/apps/desktop/src/plugins/hermes-bots/canonical-chat.ts b/apps/desktop/src/plugins/hermes-bots/canonical-chat.tsindex 59005111eb3..e0faeb1a286 100644--- a/apps/desktop/src/plugins/hermes-bots/canonical-chat.ts+++ b/apps/desktop/src/plugins/hermes-bots/canonical-chat.ts@@ -147,6 +147,34 @@ async function openStoredBotChat(// previous time this bot was open — which left the pane showing old messages// until an app restart (hermes-agent#93604). A resume is cheap and// idempotent, so on this explicit user navigation we always request one.+ // Discard a stale canonical-titled tile before opening the tip: compression+ // rotates the tip while tiles stay keyed by segment, and hidden Bot Chats+ // never enter the sidebar listing the lineage guard reads, so without this+ // probe the old-segment tile survives beside the tip (hermes-agent#120810).+ // Same owner-scoped probe the roster click runs; side tabs keep any other+ // title. ponytail: probe-only reconcile here, full lineage walk if hidden+ // lineages ever rejoin the listing.+ try {+ // SAFETY: plugin SDK host gains optional hooks per shell version; the+ // single-as narrows only for feature detection, never to bypass types.+ const focusHook = (+ host as { focusOpenWorkspaceSession?: (+ ownerKey: string,+ probe: (tile: { storedSessionId: string; workspaceTabTitle?: string }) => boolean,+ onlyIds: readonly string[]+ ) => null | string }+ ).focusOpenWorkspaceSession+ if (typeof focusHook === 'function') {+ const canonicalIds = [...new Set([String(summary?.id ?? ''), String(storedId ?? '')].filter(Boolean))]+ const isStaleTile = (tile: { storedSessionId: string; workspaceTabTitle?: string }) =>+ typeof tile.workspaceTabTitle === 'string' &&+ tile.workspaceTabTitle === CANONICAL_CHAT_TITLE &&+ !canonicalIds.includes(String(tile.storedSessionId))+ focusHook(ownerKey, isStaleTile, canonicalIds)+ }+ } catch {+ /* older shells without the focus hook — the tip open below still lands */+ }await host.openSession(storedId, {...(route? {