Skip to content

The agent that grows with you

fix(desktop): staleness-probe the adopt-on-conflict canonical open

Brooklyn Nicholson8ab34a76d0f0
diff --git a/apps/desktop/src/plugins/hermes-bots/canonical-chat-adopt-on-conflict.test.ts b/apps/desktop/src/plugins/hermes-bots/canonical-chat-adopt-on-conflict.test.ts
index 0d2829bf655..fb60121058d 100644
--- a/apps/desktop/src/plugins/hermes-bots/canonical-chat-adopt-on-conflict.test.ts
+++ b/apps/desktop/src/plugins/hermes-bots/canonical-chat-adopt-on-conflict.test.ts
@@ -108,6 +108,39 @@ describe('a title-uniqueness rejection means someone else won the registry', ()
expect(events).not.toContain('open:stray-1')
})
+ it('adopts the winner but does not navigate once the user has clicked away', async () => {
+ // The conflict path is a full extra round-trip past the point every
+ // sibling open is staleness-probed at, so it is the likeliest of them all
+ // to land late. Identity must still resolve — only the workspace steal is
+ // what the probe prevents.
+ let lists = 0
+
+ respondWith(method => {
+ if (method === 'session.list') {
+ lists += 1
+
+ return lists === 1
+ ? { sessions: [] }
+ : { sessions: [{ id: 'winner-1', message_count: 3, resolved_id: 'winner-1', title: 'Bot Chat' }] }
+ }
+
+ if (method === 'session.create') {
+ return { session_id: 'rt-stray', stored_session_id: 'stray-1' }
+ }
+
+ if (method === 'session.title') {
+ throw new Error("Title 'Bot Chat' is already in use by session winner-1")
+ }
+
+ return {}
+ })
+
+ const { createCanonicalChat } = await loadModule()
+
+ expect(await createCanonicalChat('ops', { openingStillCurrent: () => false })).toBe('winner-1')
+ expect(events).not.toContain('open:winner-1')
+ })
+
it('keeps the compat path for a NON-conflict title failure (old gateways)', async () => {
respondWith(method => {
if (method === 'session.list') {
diff --git a/apps/desktop/src/plugins/hermes-bots/canonical-chat.ts b/apps/desktop/src/plugins/hermes-bots/canonical-chat.ts
index d6d58e65a2e..ffcaffb5907 100644
--- a/apps/desktop/src/plugins/hermes-bots/canonical-chat.ts
+++ b/apps/desktop/src/plugins/hermes-bots/canonical-chat.ts
@@ -340,7 +340,11 @@ export function createCanonicalChat(
const winner = await findExistingCanonicalChat(owner)
if (winner?.id) {
- if (typeof host.openSession === 'function') {
+ // Adopting the winner settles IDENTITY, which is always correct to
+ // return. Navigating to it is not: this path can land a full
+ // round-trip after the user clicked another bot, and every sibling
+ // open here is staleness-probed for exactly that reason.
+ if (typeof host.openSession === 'function' && canNavigate()) {
await openStoredBotChat(owner, winner.resolved_id || winner.id, winner)
}