The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): fail closed when Bot Chat lookup returns zero rows
chelsealong87d5e40f5326
diff --git a/apps/desktop/src/plugins/hermes-bots/canonical-chat-registry.test.ts b/apps/desktop/src/plugins/hermes-bots/canonical-chat-registry.test.tsindex 03e34f8e6cd..791b710dd3d 100644--- a/apps/desktop/src/plugins/hermes-bots/canonical-chat-registry.test.ts+++ b/apps/desktop/src/plugins/hermes-bots/canonical-chat-registry.test.ts@@ -280,4 +280,29 @@ describe('a failed lookup fails CLOSED — never "no chat exists"', () => {await expect(createCanonicalChat('ops')).rejects.toThrow(/Bot Chat registry/)expect(calls.some(call => call.method === 'session.create')).toBe(false)})++ // #98383: a profile backend mid-restart can answer `session.list`+ // SUCCESSFULLY with an empty list instead of throwing. `rows.find(...) ||+ // null` used to read that identically to "this bot never had a chat",+ // which minted a replacement and re-fired the kickoff on every click.+ it('refuses to mint on an empty lookup when the roster already confirmed a canonical chat', async () => {+ const calls = respondWith(method => {+ if (method === 'session.list') {+ return { sessions: [] }+ }++ if (method === 'session.create') {+ throw new Error('must not create: an empty result is not confirmed absence')+ }++ return {}+ })++ const bot = { canonical_session: { id: 'forever-chat' }, name: 'ops' } as RosterRow+ const { openBotCanonicalChat } = await loadModule()++ await expect(openBotCanonicalChat(bot)).rejects.toThrow(/Bot Chat registry/)+ expect(calls.some(call => call.method === 'session.create')).toBe(false)+ expect(hostMock.openSession).not.toHaveBeenCalled()+ })})diff --git a/apps/desktop/src/plugins/hermes-bots/canonical-chat.ts b/apps/desktop/src/plugins/hermes-bots/canonical-chat.tsindex abac5a0c0e3..f25c72963bf 100644--- a/apps/desktop/src/plugins/hermes-bots/canonical-chat.ts+++ b/apps/desktop/src/plugins/hermes-bots/canonical-chat.ts@@ -213,8 +213,25 @@ async function findExistingCanonicalChat(owner: RosterRow | string): Promise<Can}const rows = res?.sessions ?? []+ const match = rows.find(row => isCanonicalBotChatHistory(row))- return rows.find(row => isCanonicalBotChatHistory(row)) || null+ if (match) {+ return match+ }++ // A zero-row result is NOT the same as a thrown error, but it is just as+ // capable of forking the forever chat: a profile backend mid-restart can+ // answer `session.list` successfully with an empty list rather than+ // failing it, and `|| null` used to read that identically to "this bot+ // never had a chat" (#98383). The roster's own `canonical_session` is the+ // last positive confirmation this profile HAD one — when that exists,+ // an empty lookup is unconfirmed absence, not confirmed absence, so fail+ // closed the same way a thrown RPC error already does instead of minting.+ if (bot?.canonical_session?.id) {+ throw new Error(`Could not confirm ${name}'s Bot Chat registry — not starting a new chat`)+ }++ return null}interface CreateCanonicalChatOptions {