Skip to content

The agent that grows with you

fix(bot-mode): a same-name room recreated inside the disband sync window survives the read-back merge

teknium1e3a0a74b032f
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 f4ddb319888..ff65992c92f 100644
--- a/apps/desktop/src/plugins/hermes-bots/group-chat.test.ts
+++ b/apps/desktop/src/plugins/hermes-bots/group-chat.test.ts
@@ -1043,6 +1043,54 @@ describe('room identity', () => {
expect(merged.New.sessions?.research).toBe('sid-9')
expect(merged.Old).toBeUndefined()
})
+
+ it('keeps a same-name recreate that landed inside the disband sync window', async () => {
+ const { chat } = await loadRoom()
+
+ // Disband Core, recreate Core with a fresh roomId before the disband's
+ // job flushes. The read-back merge still carries deletedRooms:['Core']:
+ // it must hide the remote copy of the OLD room without dropping the
+ // live recreate, while a runtime-only tombstone under that name is gone.
+ const remote = {
+ rooms: {
+ 'id:old-room': {
+ log: [{ at: 1, from: { kind: 'user', name: 'You' }, text: 'old question', thread: 'thread-old' }],
+ name: 'Core',
+ revision: 2,
+ roomId: 'old-room'
+ }
+ },
+ version: 3
+ }
+
+ const recreate = {
+ log: [{ at: 5, from: { kind: 'member', name: 'research' }, text: '@user replacement needs you', thread: 'legacy' }],
+ roomId: 'new-room',
+ sessions: {},
+ tombstone: false,
+ watermarks: {}
+ }
+
+ const merged = chat.mergeRemoteGroupChatSnapshotIntoRooms(
+ remote as never,
+ { Core: recreate } as unknown as Record<string, GroupChat>,
+ { deletedRooms: ['Core'] }
+ )
+
+ expect(merged.Core).toEqual(recreate)
+
+ const swept = chat.mergeRemoteGroupChatSnapshotIntoRooms(
+ remote as never,
+ { Core: { epoch: 2, log: [], running: false, sessions: {}, tombstone: true, watermarks: {} } } as unknown as Record<
+ string,
+ GroupChat
+ >,
+ { deletedRooms: ['Core'] }
+ )
+
+ expect(swept.Core).toBeUndefined()
+ expect(chat.mergeRemoteGroupChatSnapshotIntoRooms(remote as never, {}, { deletedRooms: ['Core'] }).Core).toBeUndefined()
+ })
})
describe('sync worker', () => {
diff --git a/apps/desktop/src/plugins/hermes-bots/group-chat.ts b/apps/desktop/src/plugins/hermes-bots/group-chat.ts
index c00741bf339..5272087db92 100644
--- a/apps/desktop/src/plugins/hermes-bots/group-chat.ts
+++ b/apps/desktop/src/plugins/hermes-bots/group-chat.ts
@@ -681,6 +681,19 @@ export function mergeRemoteGroupChatSnapshotIntoRooms(
const preserved = new Set(preserveRooms)
const locallyDeleted = new Set(deletedRooms)
+ // deletedRooms names a pending local disband. It must hide the REMOTE copy
+ // of that room, but a live local record under the same name is newer than
+ // the disband (the disband itself leaves nothing, or only the flagged
+ // runtime tombstone, under that name): a same-name recreate that landed
+ // inside the sync window. Only the disbanded record itself may be dropped.
+ const dropLocallyDeleted = (name: null | string | undefined) => {
+ if (!name || (rooms[name] && !rooms[name].tombstone)) {
+ return
+ }
+
+ delete rooms[name]
+ }
+
// Local rooms indexed by durable identity so an id-keyed projection room
// finds its local twin even when the display name changed remotely.
const localByRoomId = new Map<string, string>()
@@ -716,11 +729,8 @@ export function mergeRemoteGroupChatSnapshotIntoRooms(
continue
}
- delete rooms[displayName]
-
- if (localName) {
- delete rooms[localName]
- }
+ dropLocallyDeleted(displayName)
+ dropLocallyDeleted(localName)
continue
}
@@ -848,7 +858,7 @@ export function mergeRemoteGroupChatSnapshotIntoRooms(
}
for (const name of locallyDeleted) {
- delete rooms[name]
+ dropLocallyDeleted(name)
}
return rooms