Skip to content

The agent that grows with you

fix(bot-mode): disbanded group chat stays gone when a gateway mirror missed the tombstone

teknium10ee7854b6e70
diff --git a/apps/desktop/src/plugins/hermes-bots/group-chat-view.test.ts b/apps/desktop/src/plugins/hermes-bots/group-chat-view.test.ts
index 4c07972f242..c4d15d85491 100644
--- a/apps/desktop/src/plugins/hermes-bots/group-chat-view.test.ts
+++ b/apps/desktop/src/plugins/hermes-bots/group-chat-view.test.ts
@@ -288,4 +288,43 @@ describe('disband', () => {
expect(envelope.deleted?.['name:Gone']).toBeGreaterThan(0)
})
+
+ it('outlives a gateway mirror that missed the tombstone push (#105275)', async () => {
+ const room = await loadRoom()
+ room.chat.$groupChats.set({
+ Build: {
+ log: [{ at: 1, from: { kind: 'user', name: 'You' }, id: 'b1', text: 'go' }],
+ roomId: 'room-1',
+ syncRevision: 4,
+ watermarks: {}
+ }
+ } as unknown as Record<string, GroupChat>)
+
+ await room.view.disbandGroupChat('Build', [])
+
+ // The disband is remembered durably, not only in the in-flight sync job.
+ expect(room.gateway.storage.get('group-chat-tombstones')).toEqual({ 'id:room-1': 5 })
+
+ // A lagging mirror (its tombstone push failed) still projects the room
+ // with a higher CAS revision and no tombstone. Pulling it must not
+ // resurrect the room — and the durable room map must stay clean.
+ room.gateway.uiMeta['hermes-bots-groups'] = {
+ rooms: {
+ 'id:room-1': {
+ log: [{ at: 1, from: { kind: 'user', name: 'You' }, id: 'b1', text: 'go' }],
+ members: [],
+ name: 'Build',
+ revision: 9,
+ roomId: 'room-1'
+ }
+ },
+ updatedAt: 2,
+ version: 3
+ }
+
+ await room.chat.pullGroupChatServerState()
+
+ expect('Build' in room.chat.$groupChats.get()).toBe(false)
+ expect('Build' in durable(room)).toBe(false)
+ })
})
diff --git a/apps/desktop/src/plugins/hermes-bots/group-chat-view.tsx b/apps/desktop/src/plugins/hermes-bots/group-chat-view.tsx
index a64c9d3e823..fa4008aaa0b 100644
--- a/apps/desktop/src/plugins/hermes-bots/group-chat-view.tsx
+++ b/apps/desktop/src/plugins/hermes-bots/group-chat-view.tsx
@@ -64,6 +64,7 @@ import {
$groupClarify,
$groupNeedsYou,
groupThreadOf,
+ rememberGroupChatTombstone,
scheduleGroupChatServerSync,
setGroupChatImage,
updateGroupChat
@@ -155,6 +156,12 @@ export async function disbandGroupChat(group: string, members: RosterRow[]) {
delete all[group]
+ // Remember the disband durably BEFORE any remote write can stall: the
+ // pending sync job alone forgets it once the retry ladder gives up or the
+ // window closes, and a gateway mirror that missed the tombstone push would
+ // resurrect the room on every later pull (#105275).
+ await rememberGroupChatTombstone(group, prior.roomId, prior.syncRevision)
+
// Keep a runtime-only tombstone while a drive may still be mid-turn; it
// carries no log and is flagged so persistence and name-dedup skip it —
// updateGroupChat writes the WHOLE atom map, so an unflagged tombstone
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 3d81a91b85f..f4ddb319888 100644
--- a/apps/desktop/src/plugins/hermes-bots/group-chat.test.ts
+++ b/apps/desktop/src/plugins/hermes-bots/group-chat.test.ts
@@ -1132,4 +1132,45 @@ describe('sync worker', () => {
expect(configured.has('gw-a')).toBe(true)
expect(configured.has('gw-b')).toBe(true)
})
+
+ it('a remembered disband re-tombstones a mirror that still projects the room (#105275)', async () => {
+ const room = await loadRoom()
+ room.chat.hydrateGroupChatTombstones({ 'id:room-1': 5 })
+
+ // Mirror whose tombstone push was lost: full room, no `deleted` entry.
+ room.gateway.uiMeta['hermes-bots-groups'] = {
+ rooms: {
+ 'id:room-1': {
+ log: [{ at: 1, from: { kind: 'user', name: 'You' }, id: 'b1', text: 'go' }],
+ members: [],
+ name: 'Build',
+ revision: 9,
+ roomId: 'room-1'
+ }
+ },
+ updatedAt: 2,
+ version: 3
+ }
+ room.gateway.uiMetaRevisions['hermes-bots-groups'] = 9
+
+ // An unrelated room write is enough: the publish carries the memory.
+ room.chat.$groupChats.set({
+ Other: {
+ log: [{ at: 3, from: { kind: 'user', name: 'You' }, id: 'o1', text: 'hi' }],
+ roomId: 'room-2',
+ sessions: {},
+ syncRevision: 0,
+ watermarks: {}
+ }
+ } as unknown as Record<string, GroupChat>)
+ room.chat.scheduleGroupChatServerSync(room.chat.$groupChats.get(), { changedRooms: ['Other'] })
+ await drain(() => room.gateway.rpcFor('profiles.configure').length < 1, 50)
+
+ const mirror = published(room) as { deleted?: Record<string, number>; rooms: Record<string, unknown> }
+
+ expect('id:room-1' in mirror.rooms).toBe(false)
+ expect(mirror.deleted?.['id:room-1']).toBe(5)
+ // The read-back merge did not resurrect the room locally either.
+ expect('Build' in room.chat.$groupChats.get()).toBe(false)
+ })
})
diff --git a/apps/desktop/src/plugins/hermes-bots/group-chat.ts b/apps/desktop/src/plugins/hermes-bots/group-chat.ts
index 12f2bf108e9..c00741bf339 100644
--- a/apps/desktop/src/plugins/hermes-bots/group-chat.ts
+++ b/apps/desktop/src/plugins/hermes-bots/group-chat.ts
@@ -95,6 +95,57 @@ const groupChatSyncRetryTimers = new Map<string, ReturnType<typeof setTimeout>>(
const groupChatSyncRetryCounts = new Map<string, number>()
export let groupChatSyncDisposed = false
+// Durable disband memory in the mirror's own tombstone shape (room key ->
+// tombstone revision). A pending sync job forgets its deletedRooms once the
+// retry ladder gives up or the window closes, and "missing remote rooms are
+// not deletions" — so a gateway mirror that missed the tombstone push would
+// re-merge the room on every later pull. This map rides every publish and
+// every pull merge until the room is gone from every mirror (#105275).
+const groupChatTombstones: Record<string, number> = {}
+const GROUP_CHAT_TOMBSTONES_KEY = 'group-chat-tombstones'
+
+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. */
+export function rememberGroupChatTombstone(name: string, roomId?: null | string, syncRevision?: number) {
+ const key = typeof roomId === 'string' && roomId ? `id:${roomId}` : `name:${name}`
+ groupChatTombstones[key] = Math.max(Number(groupChatTombstones[key] || 0), Math.max(0, Number(syncRevision || 0)) + 1)
+
+ for (const stale of Object.keys(groupChatTombstones)
+ .sort((left, right) => groupChatTombstones[right] - groupChatTombstones[left])
+ .slice(64)) {
+ delete groupChatTombstones[stale]
+ }
+
+ try {
+ return Promise.resolve(getPluginCtx()?.storage?.set?.(GROUP_CHAT_TOMBSTONES_KEY, { ...groupChatTombstones })).catch(
+ () => undefined
+ )
+ } catch {
+ return Promise.resolve()
+ }
+}
+
+export function hydrateGroupChatTombstones(value: unknown) {
+ for (const key of Object.keys(groupChatTombstones)) {
+ delete groupChatTombstones[key]
+ }
+
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
+ return
+ }
+
+ for (const [key, revision] of Object.entries(value as Record<string, unknown>)) {
+ if (key.startsWith('id:') || key.startsWith('name:')) {
+ groupChatTombstones[key] = Math.max(0, Number(revision || 0))
+ }
+ }
+}
+
/** Cut one room body to a per-message budget and mark the cut (the sync
* projection and the per-turn delta window share the convention).
* Receivers used to see a silent mid-sentence slice with no signal that the
@@ -606,10 +657,23 @@ function groupChatSyncEnvelope(
export function mergeRemoteGroupChatSnapshotIntoRooms(
remote: GroupChatSyncSnapshot | null | undefined,
current: Record<string, GroupChat> = $groupChats.get(),
- { preserveRooms = [], deletedRooms = [] }: { deletedRooms?: string[]; preserveRooms?: string[] } = {}
+ {
+ preserveRooms = [],
+ deletedRooms = [],
+ tombstones = {}
+ }: { deletedRooms?: string[]; preserveRooms?: string[]; tombstones?: Record<string, number> } = {}
) {
const remoteNorm = normalizeGroupChatSyncSnapshot(remote)
+ // Remote tombstones plus this Desktop's durable disband memory: a mirror
+ // that missed the tombstone push still projects the room, and without the
+ // local memory it would resurrect here on every pull (#105275).
+ const deleted: Record<string, number> = { ...tombstones }
+
+ for (const [key, at] of Object.entries(remoteNorm.deleted || {})) {
+ deleted[key] = Math.max(Number(deleted[key] || 0), Math.max(0, Number(at || 0)))
+ }
+
const rooms: Record<string, GroupChat> = {
...(current || {})
}
@@ -746,7 +810,17 @@ export function mergeRemoteGroupChatSnapshotIntoRooms(
}
}
- for (const [key, deletedAt] of Object.entries(remoteNorm.deleted || {})) {
+ // Re-index by roomId: a resurrected projection room may have just landed
+ // under a roomId no local twin carried when the index was first built.
+ localByRoomId.clear()
+
+ for (const [name, room] of Object.entries(rooms)) {
+ if (typeof room?.roomId === 'string' && room.roomId) {
+ localByRoomId.set(room.roomId, name)
+ }
+ }
+
+ for (const [key, deletedAt] of Object.entries(deleted)) {
const deletedRoomId = key.startsWith('id:') ? key.slice(3) : null
const targetName =
@@ -929,7 +1003,8 @@ export async function pullGroupChatServerState(connectionId: string = groupChatS
const merged = mergeRemoteGroupChatSnapshotIntoRooms(remote, $groupChats.get(), {
preserveRooms: pending?.changedRooms || [],
- deletedRooms: pending?.deletedRooms || []
+ deletedRooms: pending?.deletedRooms || [],
+ tombstones: groupChatTombstones
})
$groupChats.set(merged)
@@ -1020,7 +1095,9 @@ async function flushGroupChatServerSync(connectionId?: string) {
try {
const remoteState = await groupChatRemoteSnapshot(job)
- const local = groupChatSyncSnapshot($groupChats.get())
+ // The local snapshot carries the durable disband memory, so every publish
+ // re-tombstones a mirror whose original tombstone push was lost.
+ const local = groupChatSyncSnapshot($groupChats.get(), groupChatTombstones)
const writeRevision = remoteState.revision + 1
const snapshot = mergeGroupChatSyncSnapshots(remoteState.snapshot, local, {
@@ -1042,7 +1119,8 @@ async function flushGroupChatServerSync(connectionId?: string) {
const mergedRooms = mergeRemoteGroupChatSnapshotIntoRooms(remoteState.snapshot, $groupChats.get(), {
preserveRooms: pending?.changedRooms || [],
- deletedRooms: pending?.deletedRooms || []
+ deletedRooms: pending?.deletedRooms || [],
+ tombstones: groupChatTombstones
})
$groupChats.set(mergedRooms)
@@ -1097,7 +1175,8 @@ async function flushGroupChatServerSync(connectionId?: string) {
const mergedRooms = mergeRemoteGroupChatSnapshotIntoRooms(confirmedState.snapshot, $groupChats.get(), {
preserveRooms: pending?.changedRooms || [],
- deletedRooms: pending?.deletedRooms || []
+ deletedRooms: pending?.deletedRooms || [],
+ tombstones: groupChatTombstones
})
$groupChats.set(mergedRooms)
@@ -1195,7 +1274,7 @@ export function scheduleGroupChatServerSync(
// debounce fires.
const activeId = String(groupChatSyncConnectionId() || '')
- const queueFor = (connectionId: string) => {
+ const queueFor = (connectionId: string, coalesced?: GroupChatSyncJob) => {
const id = String(connectionId || '')
const retryTimer = groupChatSyncRetryTimers.get(id)
@@ -1208,9 +1287,9 @@ export function scheduleGroupChatServerSync(
id,
mergeGroupChatSyncJobs(groupChatSyncPendingByConnection.get(id), {
connectionId: id,
- allowEmpty,
- changedRooms,
- deletedRooms
+ allowEmpty: Boolean(allowEmpty || coalesced?.allowEmpty),
+ changedRooms: [...new Set([...(coalesced?.changedRooms || []), ...changedRooms])],
+ deletedRooms: [...new Set([...(coalesced?.deletedRooms || []), ...deletedRooms])]
})
)
}
@@ -1220,9 +1299,15 @@ export function scheduleGroupChatServerSync(
groupChatSyncTimer = null
void groupChatSyncTargetConnections()
.then(targets => {
+ // An ordinary update inside the debounce window replaces the timer,
+ // so secondaries must inherit the active job's coalesced intent —
+ // a disband's deletedRooms included — or the tombstone lands on the
+ // active gateway only (#105275).
+ const coalesced = groupChatSyncPendingByConnection.get(activeId)
+
for (const target of targets) {
if (String(target || '') !== activeId) {
- queueFor(target)
+ queueFor(target, coalesced)
}
}
})
diff --git a/apps/desktop/src/plugins/hermes-bots/plugin.tsx b/apps/desktop/src/plugins/hermes-bots/plugin.tsx
index 28721700352..59f99bc8d05 100644
--- a/apps/desktop/src/plugins/hermes-bots/plugin.tsx
+++ b/apps/desktop/src/plugins/hermes-bots/plugin.tsx
@@ -49,6 +49,7 @@ import {
$groupChatWorkspace,
assignLegacyThreads,
handleSessionsGatewayTransition,
+ hydrateGroupChatTombstones,
pullGroupChatServerState,
scheduleGroupChatServerSync,
setGroupChatSyncDisposed,
@@ -232,6 +233,17 @@ 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).
+ 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'))
+ .then(value => hydrateGroupChatTombstones(value))
+ .catch(() => undefined)
+ } catch {
+ /* no storage — no remembered disbands this window */
+ }
+
try {
// @ts-expect-error TODO(bot-mode-types): PluginStorage.get requires a fallback argument.
Promise.resolve(ctx.storage?.get?.('group-chats'))
diff --git a/website/docs/user-guide/bot-mode.md b/website/docs/user-guide/bot-mode.md
index f571627e8c3..a1ec325b8bc 100644
--- a/website/docs/user-guide/bot-mode.md
+++ b/website/docs/user-guide/bot-mode.md
@@ -121,7 +121,7 @@ To edit an existing room as a unit, use **Manage members** — from the room hea
Each member's turn carries every room message since its own last turn — up to about 200 messages or 32,000 characters of transcript, whichever fills first — with a single oversized message cut to a marked 8,000-character excerpt (the room log stores the same excerpt) rather than crowding out the messages around it; when the window still overflows, the prompt names exactly how many earlier messages were left out.
-**Rooms follow your gateways, not one Desktop.** Each room's recent transcript, members, picture, and name are mirrored into the shared profile metadata of **every** gateway your Desktop is connected to, with per-gateway versioning so two Desktops writing at once merge instead of overwriting each other. Open Hermes Desktop on another machine against the same gateway (local network, Tailscale, anywhere) and the room appears with its history; gateway-only clients see it too. Rooms carry a durable internal identity, so renaming one changes just its display name everywhere, disbanding one removes it permanently on every client — even ones that were offline at the time — and recreating a same-name group starts a genuinely fresh room. If a gateway dies or is removed, nothing is lost: every connected Desktop keeps the full room locally and re-seeds any gateway it reconnects to. (The full orchestration log stays in each Desktop's local storage; the shared mirror is a bounded recent-history projection.)
+**Rooms follow your gateways, not one Desktop.** Each room's recent transcript, members, picture, and name are mirrored into the shared profile metadata of **every** gateway your Desktop is connected to, with per-gateway versioning so two Desktops writing at once merge instead of overwriting each other. Open Hermes Desktop on another machine against the same gateway (local network, Tailscale, anywhere) and the room appears with its history; gateway-only clients see it too. Rooms carry a durable internal identity, so renaming one changes just its display name everywhere, disbanding one removes it permanently on every client — even ones that were offline at the time; your Desktop remembers its own disbands, so a gateway whose copy missed the deletion cannot bring the room back — and recreating a same-name group starts a genuinely fresh room. If a gateway dies or is removed, nothing is lost: every connected Desktop keeps the full room locally and re-seeds any gateway it reconnects to. (The full orchestration log stays in each Desktop's local storage; the shared mirror is a bounded recent-history projection.)
A group's identity is editable, at creation and after: