Skip to content

The agent that grows with you

fix(bot-mode): durable disband memory is keyed by roomId only, so a same-name recreate is never deleted

teknium1b81e8ddf8b5b
diff --git a/apps/desktop/src/plugins/hermes-bots/group-chat.test.ts b/apps/desktop/src/plugins/hermes-bots/group-chat.test.ts
index ff65992c92f..8a664a6620d 100644
--- a/apps/desktop/src/plugins/hermes-bots/group-chat.test.ts
+++ b/apps/desktop/src/plugins/hermes-bots/group-chat.test.ts
@@ -1221,4 +1221,39 @@ describe('sync worker', () => {
// The read-back merge did not resurrect the room locally either.
expect('Build' in room.chat.$groupChats.get()).toBe(false)
})
+
+ // Durable memory is keyed by roomId only: a name key would delete a fresh
+ // same-name room (syncRevision 0) on every pull after the sync window, and
+ // an older persisted `name:` entry must be dropped on hydrate for the same
+ // reason.
+ it('a same-name room recreated after the disband sync window survives a pull that lacks it', async () => {
+ const room = await loadRoom()
+ const view = await import('./group-chat-view')
+
+ room.chat.hydrateGroupChatTombstones({ 'id:room-9': 2, 'name:Core': 7 })
+ expect(room.chat.groupChatTombstoneMemory()).toEqual({ 'id:room-9': 2 })
+
+ // Legacy name-keyed room (no roomId), already published.
+ room.chat.$groupChats.set({
+ Core: {
+ log: [{ at: 1, from: { kind: 'user', name: 'You' }, id: 'c1', text: 'old', thread: 't' }],
+ sessions: {},
+ syncRevision: 3,
+ watermarks: {}
+ }
+ } as unknown as Record<string, GroupChat>)
+ await view.disbandGroupChat('Core', [])
+ await drain(() => room.gateway.rpcFor('profiles.configure').length < 1, 50)
+ expect('name:Core' in room.chat.groupChatTombstoneMemory()).toBe(false)
+
+ // Sync window over; user recreates the name. Nothing published yet.
+ room.chat.updateGroupChat('Core', current => ({ ...current, roomId: room.chat.mintGroupRoomId() }), { sync: false })
+ room.chat.appendGroupChatEntry('Core', { kind: 'user', name: 'You' }, 'fresh start', 't2')
+
+ room.gateway.uiMeta['hermes-bots-groups'] = { deleted: {}, rooms: {}, updatedAt: 5, version: 3 }
+ room.gateway.uiMetaRevisions['hermes-bots-groups'] = 9
+ await room.chat.pullGroupChatServerState()
+
+ expect(room.chat.$groupChats.get().Core?.log.map(entry => entry.text)).toEqual(['fresh start'])
+ })
})
diff --git a/apps/desktop/src/plugins/hermes-bots/group-chat.ts b/apps/desktop/src/plugins/hermes-bots/group-chat.ts
index 5272087db92..8269ca0c78d 100644
--- a/apps/desktop/src/plugins/hermes-bots/group-chat.ts
+++ b/apps/desktop/src/plugins/hermes-bots/group-chat.ts
@@ -108,11 +108,19 @@ export function groupChatTombstoneMemory(): Record<string, number> {
return { ...groupChatTombstones }
}
-/** Remember a disband durably, keyed by the room's durable key so a same-name
- * recreate with a fresh roomId is never blocked. Revision = the room's last
- * known sync revision + 1, the ordering the live tombstone merge applies. */
+/** Remember a disband durably — ONLY by roomId. A name key would outlive the
+ * room: a same-name recreate starts at syncRevision 0 and the memory is
+ * applied on every pull with `deletedRevision >= syncRevision`, so the
+ * fresh room would be deleted forever. Legacy name-only rooms keep the
+ * job-scoped tombstone of the pending sync (the pre-#105275 behaviour).
+ * Revision = the room's last known sync revision + 1, the ordering the
+ * live tombstone merge applies. */
export function rememberGroupChatTombstone(name: string, roomId?: null | string, syncRevision?: number) {
- const key = typeof roomId === 'string' && roomId ? `id:${roomId}` : `name:${name}`
+ if (typeof roomId !== 'string' || !roomId) {
+ return Promise.resolve()
+ }
+
+ const key = `id:${roomId}`
groupChatTombstones[key] = Math.max(Number(groupChatTombstones[key] || 0), Math.max(0, Number(syncRevision || 0)) + 1)
for (const stale of Object.keys(groupChatTombstones)
@@ -140,7 +148,9 @@ export function hydrateGroupChatTombstones(value: unknown) {
}
for (const [key, revision] of Object.entries(value as Record<string, unknown>)) {
- if (key.startsWith('id:') || key.startsWith('name:')) {
+ // Older builds persisted `name:` keys too; they are exactly the memory
+ // that blocks a same-name recreate, so they are dropped on hydrate.
+ if (key.startsWith('id:')) {
groupChatTombstones[key] = Math.max(0, Number(revision || 0))
}
}
diff --git a/apps/desktop/src/plugins/hermes-bots/plugin.tsx b/apps/desktop/src/plugins/hermes-bots/plugin.tsx
index 59f99bc8d05..772e19ccf9c 100644
--- a/apps/desktop/src/plugins/hermes-bots/plugin.tsx
+++ b/apps/desktop/src/plugins/hermes-bots/plugin.tsx
@@ -233,11 +233,15 @@ export default {
// Hydrate persisted group-chat room logs (epoch/running are runtime-only
// and always reset — a loop can't survive a window reload anyway).
+ // Disband memory must be in place before the first gateway pull merges
+ // a mirror that may still project a disbanded room (#105275) — the pull
+ // below awaits this, otherwise the first pull resurrects the room until
+ // the next one re-tombstones it.
+ let tombstonesHydrated: Promise<void> = Promise.resolve()
+
try {
- // Disband memory must be in place before the first gateway pull merges
- // a mirror that may still project a disbanded room (#105275).
// @ts-expect-error TODO(bot-mode-types): PluginStorage.get requires a fallback argument.
- Promise.resolve(ctx.storage?.get?.('group-chat-tombstones'))
+ tombstonesHydrated = Promise.resolve(ctx.storage?.get?.('group-chat-tombstones'))
.then(value => hydrateGroupChatTombstones(value))
.catch(() => undefined)
} catch {
@@ -320,6 +324,7 @@ export default {
// Receive before publish. A fresh Desktop with no local room cache
// must hydrate the gateway projection instead of merely avoiding an
// empty overwrite and then rendering an empty conversation.
+ await tombstonesHydrated
await pullGroupChatServerState().catch(() => false)
scheduleGroupChatServerSync($groupChats.get())
})