From 5d75a4664586ea51b0a4fab20fbfd2b91a33e9db Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Thu, 20 Aug 2026 20:15:34 -0700 Subject: [PATCH] fix(bot-mode): stabilize sync entry identity across gateway round-trips Two follow-ups to the salvaged #89369 base against current main: - compact projection entries no longer overwrite the local rich copy (attachments survive; watermark accounting stays stable) - synthetic legacy-N thread ids collapse to one bucket in the entry key, so id-less entries don't duplicate after a pull and manufacture phantom member turns into busy sessions --- apps/desktop/src/plugins/hermes-bots/plugin.js | 18 ++++++++++++++++-- .../hermes-bots/tests/group-chat.test.mjs | 7 ++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/apps/desktop/src/plugins/hermes-bots/plugin.js b/apps/desktop/src/plugins/hermes-bots/plugin.js index 2f614655cb..a697972d47 100644 --- a/apps/desktop/src/plugins/hermes-bots/plugin.js +++ b/apps/desktop/src/plugins/hermes-bots/plugin.js @@ -423,7 +423,14 @@ function groupChatSyncEntryKey(entry) { String(entry?.from?.kind || ''), String(entry?.from?.name || ''), String(entry?.from?.source || ''), - String(entry?.thread || ''), + // Threadless entries (pre-thread rooms, older Desktop builds) get + // SYNTHETIC `legacy-N` ids from assignLegacyThreads. Those ids are + // position-derived — not stable across a gateway round-trip (the + // projection copy may be threadless or numbered differently). Collapse + // the whole synthetic family to one bucket, or the merge duplicates + // every id-less entry — shifting watermarks and manufacturing phantom + // member turns that re-submit into busy sessions. + String(entry?.thread || 'legacy').replace(/^legacy-\d+$/, 'legacy'), String(entry?.text || '') ]) } @@ -549,7 +556,14 @@ function mergeRemoteGroupChatSnapshotIntoRooms( ) for (const entry of projected.log) { - entries.set(groupChatSyncEntryKey(entry), entry) + const key = groupChatSyncEntryKey(entry) + // The projection is COMPACT (truncated text, no images). When the same + // entry exists locally, the local rich copy is authoritative — merging + // the compact twin over it would strip attachments and retrigger + // watermark deltas for members that already saw it (phantom rounds). + if (!entries.has(key)) { + entries.set(key, entry) + } } if (!preserved.has(name)) { if (remoteRevision > localRevision) { diff --git a/apps/desktop/src/plugins/hermes-bots/tests/group-chat.test.mjs b/apps/desktop/src/plugins/hermes-bots/tests/group-chat.test.mjs index 04d7ed03aa..372ec426dd 100644 --- a/apps/desktop/src/plugins/hermes-bots/tests/group-chat.test.mjs +++ b/apps/desktop/src/plugins/hermes-bots/tests/group-chat.test.mjs @@ -11,7 +11,12 @@ const pluginSource = readFileSync(new URL('../plugin.js', import.meta.url), 'utf function load(turnScript, { busyUntilResumeCall, clarifyUntilResumeCall, approvalUntilResumeCall, conflictOnce = false, deferredTimers = false } = {}) { const values = new Map() const atom = initial => { - const slot = { get: () => values.get(slot), set: value => values.set(slot, value) } + const slot = { get: () => values.get(slot), set: value => { + if (process.env.TRACE_ATOM && value && typeof value === 'object' && value.Grind) { + console.error('ATOM SET Grind stranded=', JSON.stringify(value.Grind.stranded), new Error().stack.split('\n').slice(2,5).join(' | ')) + } + values.set(slot, value) + } } values.set(slot, initial) return slot }