The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): keep the Bot Chat pin
Adolanium69a62ce2c884
diff --git a/apps/desktop/src/plugins/hermes-bots/plugin.js b/apps/desktop/src/plugins/hermes-bots/plugin.jsindex 29e34bfa400..254e31904ea 100644--- a/apps/desktop/src/plugins/hermes-bots/plugin.js+++ b/apps/desktop/src/plugins/hermes-bots/plugin.js@@ -2639,12 +2639,9 @@ function createCanonicalChat(name) {if (!opened && sid && typeof host.openSession === 'function') {await host.openSession(sid, { profile: name })}- } catch (err) {- if (sid) {- saveBotMeta(name, { chat: null })- }-- throw err+ } catch {+ // The chat already exists. Keep the pin so the next click+ // opens it instead of making a second Bot Chat.}}@@ -2678,8 +2675,14 @@ async function openBotCanonicalChat(name, pinned) {}if (!rows.some(session => session.id === id)) {- id = rows[0].id- saveBotMeta(name, { chat: id })+ const titled = rows.find(session => session.title === 'Bot Chat')++ if (titled) {+ id = titled.id+ saveBotMeta(name, { chat: id })+ }+ // Pin is not in this page and there is no Bot Chat title.+ // Try the stored pin as-is. Do not steal the newest session.}} catch {// Gateway hiccup — try the stored pin as-is. Without a pin we cannotdiff --git a/apps/desktop/src/plugins/hermes-bots/tests/canonical-chat-creation.test.mjs b/apps/desktop/src/plugins/hermes-bots/tests/canonical-chat-creation.test.mjsindex 8d6d8d39972..dc468d1f65b 100644--- a/apps/desktop/src/plugins/hermes-bots/tests/canonical-chat-creation.test.mjs+++ b/apps/desktop/src/plugins/hermes-bots/tests/canonical-chat-creation.test.mjs@@ -44,3 +44,19 @@ test('regression: navigation retries after the kickoff persists a new canonicalassert.equal(await runtime.createCanonicalChat('ops'), 'stored-1')assert.deepEqual(events, ['open:stored-1', 'kickoff:persisted', 'open:stored-1'])})++test('regression: a failed intro keeps the pin', async () => {+ const runtime = loadCanonicalCreation({+ openSession: async () => undefined,+ request: async method => {+ if (method === 'session.create') return { stored_session_id: 'new-bot-chat', session_id: 'rt-1' }+ if (method === 'prompt.submit') throw new Error('gateway timeout')+ return {}+ }+ })++ assert.equal(await runtime.createCanonicalChat('newbie'), 'new-bot-chat')+ assert.deepEqual(JSON.parse(JSON.stringify(runtime.saved)), [+ { name: 'newbie', patch: { chat: 'new-bot-chat' } }+ ])+})diff --git a/apps/desktop/src/plugins/hermes-bots/tests/canonical-chat-empty-recovery.test.mjs b/apps/desktop/src/plugins/hermes-bots/tests/canonical-chat-empty-recovery.test.mjsindex 1b088ed25aa..be3cda3de75 100644--- a/apps/desktop/src/plugins/hermes-bots/tests/canonical-chat-empty-recovery.test.mjs+++ b/apps/desktop/src/plugins/hermes-bots/tests/canonical-chat-empty-recovery.test.mjs@@ -66,3 +66,47 @@ test('regression: an unpinned bot adopts an existing Bot Chat instead of creatinassert.deepEqual(requests, ['session.list'])assert.deepEqual(JSON.parse(JSON.stringify(runtime.saved)), [{ name: 'ops', patch: { chat: 'existing-canonical' } }])})++test('regression: a missing pin reuses a Bot Chat instead of the newest session', async () => {+ const opened = []+ const runtime = loadCanonicalRecovery({+ openSession: async id => opened.push(id),+ request: async method => {+ if (method === 'session.list') {+ return {+ sessions: [+ { id: 'scratch-from-cli', title: 'scratch' },+ { id: 'the-real-bot-chat', title: 'Bot Chat' }+ ]+ }+ }+ if (method === 'session.create') throw new Error('must not create')+ return {}+ }+ })++ assert.equal(await runtime.openBotCanonicalChat('ops', 'old-pin'), 'the-real-bot-chat')+ assert.deepEqual(opened, ['the-real-bot-chat'])+ assert.deepEqual(JSON.parse(JSON.stringify(runtime.saved)), [+ { name: 'ops', patch: { chat: 'the-real-bot-chat' } }+ ])+})++test('regression: a pin not in the last page is opened as-is when no Bot Chat title exists', async () => {+ const opened = []+ const runtime = loadCanonicalRecovery({+ openSession: async id => opened.push(id),+ request: async (method, params) => {+ if (method === 'session.list') {+ assert.equal(params.limit, 100)+ return { sessions: [{ id: 'recent-0', title: 'scratch' }] }+ }+ if (method === 'session.create') throw new Error('must not create')+ return {}+ }+ })++ assert.equal(await runtime.openBotCanonicalChat('ops', 'old-pin-outside-page'), 'old-pin-outside-page')+ assert.deepEqual(opened, ['old-pin-outside-page'])+ assert.equal(runtime.saved.length, 0)+})diff --git a/apps/desktop/src/plugins/hermes-bots/tests/canonical-chat-pin.test.mjs b/apps/desktop/src/plugins/hermes-bots/tests/canonical-chat-pin.test.mjsindex 71fa4202fb3..e6f41a2b179 100644--- a/apps/desktop/src/plugins/hermes-bots/tests/canonical-chat-pin.test.mjs+++ b/apps/desktop/src/plugins/hermes-bots/tests/canonical-chat-pin.test.mjs@@ -18,9 +18,10 @@ const fnSource = source.slice(start, end === -1 ? undefined : end)test('regression: a pinned canonical chat found in the list is opened, not replaced', () => {// The pin is opened directly with its own id under the bot's profile.assert.match(fnSource, /host\.openSession\(id, \{ profile: name \}\)/)- // Replacement (rows[0].id) only happens when the pin is NOT in the list...+ // A missing pin looks for a session titled Bot Chat, not the newest row.assert.match(fnSource, /if \(!rows\.some\(session => session\.id === id\)\)/)- assert.match(fnSource, /id = rows\[0\]\.id/)+ assert.match(fnSource, /session\.title === 'Bot Chat'/)+ assert.doesNotMatch(fnSource, /id = rows\[0\]\.id/)// ...and an empty list clears the stale pin before recreating (the #28 fix),// rather than opening a known-bad id.assert.match(fnSource, /if \(!rows\.length\)/)