The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(bots): drive cited member after an unanswered @mention handoff
beplee24a5b6ecb722
diff --git a/apps/desktop/src/plugins/hermes-bots/plugin.js b/apps/desktop/src/plugins/hermes-bots/plugin.jsindex 0470defffd7..e7f4dc66f61 100644--- a/apps/desktop/src/plugins/hermes-bots/plugin.js+++ b/apps/desktop/src/plugins/hermes-bots/plugin.js@@ -7979,6 +7979,70 @@ function heldMemberWatermarkAdvance(seen, logLength) {// --- end member-hold helpers ---+/** Members cited by @mention in a thread who have not posted any entry after+ * the citing one — the unresolved-handoff detector for #94478. A mention+ * inside a member reply is visible to the NEXT round's responder selection,+ * but the round loop exits first when nobody has new delta to read+ * (`spokeThisRound === 0`) or a cap lands, so the room settles while a+ * called bot never answers. Returns member keys still owed a turn. */+function unaddressedGroupMentions(group, members, thread) {+ const room = $groupChats.get()[group] || { log: [] }+ const log = (room.log || []).filter(e => groupThreadOf(e) === thread)++ // key → id of the entry that most recently cited this member.+ const citedAt = new Map()++ for (const entry of log) {+ const parsed = parseGroupChatMentions(entry.text || '', members)++ // A user send re-drives everyone anyway; only member-to-member handoffs+ // can strand here.+ if (entry.from.kind !== 'member') {+ continue+ }++ for (const key of parsed.mentioned) {+ const citingMemberKey = (() => {+ const m = members.find(mm => mm.name === entry.from?.name)++ return m ? groupMemberKey(m) : null+ })()++ // Never count a bot citing itself as a pending handoff.+ if (citingMemberKey && citingMemberKey !== key) {+ citedAt.set(key, entry.id)+ }+ }+ }++ // A citation is answered when the cited member posts any entry after the+ // citing one (its turn, whatever the content).+ const lastPostAt = new Map()++ for (const entry of log) {+ if (entry.from.kind !== 'member') {+ continue+ }++ const speakerKey = (() => {+ const m = members.find(mm => mm.name === entry.from?.name)++ return m ? groupMemberKey(m) : null+ })()++ if (speakerKey) {+ lastPostAt.set(speakerKey, entry.id)+ }+ }++ return [...citedAt.keys()].filter(key => {+ const citedId = citedAt.get(key)+ const answeredAt = lastPostAt.get(key)++ return answeredAt === undefined || answeredAt <= citedId+ })+}+/** Drive one bounded round-robin turn for ONE THREAD. Serial — one member at* a time. A newer user send bumps the room epoch; this loop notices at the* next member boundary, bails, and the newest send's own loop takes over.@@ -8166,7 +8230,115 @@ async function runGroupChatRounds(group, members, thread) {}if (spokeThisRound === 0) {- return // everyone passed — the conversation settled+ // #94478: "everyone passed" is NOT the only way a round can go quiet —+ // responders can be narrowed to members with no new delta while the+ // thread's tail carries an @mention handoff that was never answered.+ // Before settling, check for cited members still owed a turn and run+ // one bounded continuation round for exactly those members. If none+ // exist (or the continuation also goes quiet), the room genuinely+ // settled.+ const pendingKeys = unaddressedGroupMentions(group, members, thread)++ if (pendingKeys.length) {+ const citedMembers = members.filter(member => pendingKeys.includes(groupMemberKey(member)))++ if (citedMembers.length && posted < GROUP_CHAT_MAX_MESSAGES) {+ const strandedNow = ($groupChats.get()[group] || {}).stranded || {}+ const continuationResponders = citedMembers.filter(+ member => !Object.prototype.hasOwnProperty.call(strandedNow, groupMemberKey(member))+ )++ for (const member of continuationResponders) {+ if (!isCurrent() || posted >= GROUP_CHAT_MAX_MESSAGES) {+ break+ }++ const room = $groupChats.get()[group] || { log: [], watermarks: {} }+ const memberKey = groupMemberKey(member)+ const markKey = `${thread}::${memberKey}`+ const seen = room.watermarks[markKey] || 0+ const delta = room.log.slice(seen).filter(e => groupThreadOf(e) === thread)++ // A cited member always has delta here (the citing reply IS in+ // its tail); skip defensively anyway so an empty prompt never+ // fires.+ if (!delta.length) {+ continue+ }++ const heldEntry = (room.holds || {})[memberKey]++ if (heldEntry) {+ continue // holds still apply to continuation turns (#93129)+ }++ const prompt = buildGroupChatTurnPrompt({+ groupName: group,+ members,+ viewer: member,+ // The continuation prompt centers on what the member missed:+ // everything since its watermark, which includes the reply+ // that cites it.+ deltaLines: delta.slice(-GROUP_CHAT_HISTORY_LIMIT).map(e => formatGroupChatLine(e, member.name))+ })++ updateGroupChat(group, r => {+ r.turn = member.name+ return r+ })++ let continuationReply = null++ try {+ continuationReply = await runGroupChatMemberTurn(group, member, prompt, thread)++ if (continuationReply !== null) {+ clearBotAttention(memberKey)+ }+ } catch (error) {+ recordGroupActivity(group, { kind: 'failed', member: member.name, thread })+ noteBotAttention(memberKey, error?.message || error)+ continuationReply = null+ }++ if (!isCurrent()) {+ return+ }++ updateGroupChat(group, r => {+ r.watermarks[markKey] = r.log.length+ return r+ })++ if (continuationReply !== null && !isGroupPassText(continuationReply)) {+ appendGroupChatEntry(+ group,+ { kind: 'member', name: member.name, ...(member.remoteSource ? { source: member.connectionLabel || member.connectionId } : {}) },+ continuationReply,+ thread+ )+ updateGroupChat(group, r => {+ r.watermarks[markKey] = r.log.length+ return r+ })+ posted += 1++ // The continuation's own reply may cite someone else — fall+ // through to the normal loop so the next round handles it via+ // the same responder machinery. Reaching here means the loop+ // continues rather than settling; the outer for-loop's next+ // iteration re-evaluates everything.+ spokeThisRound += 1+ }+ }+ }+ }++ if (spokeThisRound === 0) {+ // Genuinely nothing left to say — including after the continuation+ // attempt above produced no spoken turns. Settle honestly.+ return+ }}}} finally {diff --git a/apps/desktop/src/plugins/hermes-bots/tests/94478-mention-settle.test.mjs b/apps/desktop/src/plugins/hermes-bots/tests/94478-mention-settle.test.mjsnew file mode 100644index 00000000000..0dfcfb9a976--- /dev/null+++ b/apps/desktop/src/plugins/hermes-bots/tests/94478-mention-settle.test.mjs@@ -0,0 +1,85 @@+/**+ * Regression tests for #94478 — a bot's @mention of a teammate inside its own+ * reply never drives the cited bot; the room records "settled" instead.+ *+ * Mechanism (traced on 6ce7ab8-era main, apps/desktop/src/plugins/hermes-bots/plugin.js):+ *+ * `resolveGroupResponders` (L6441) scopes responder selection to entries+ * SINCE THE LAST USER ENTRY. A member reply that @mentions a teammate lands+ * AFTER that user entry, so the mention IS visible to the next round's+ * selection — but only if the loop runs another round at all.+ *+ * The hole is the early exit at L7821: `if (spokeThisRound === 0) return`.+ * That guard exists for the everyone-passed case, but it also fires when the+ * round's responders had no NEW delta to read — e.g. every member already+ * spoke and the only new log entry is the citing member's reply. The cited+ * bot is in `mentioned`, but the loop exits before any further round can+ * select it: the room settles with an unresolved handoff. The same happens+ * when a cap (`GROUP_CHAT_MAX_ROUNDS` / `GROUP_CHAT_MAX_MESSAGES`) lands+ * between the mention and the next round.+ *+ * Fix contract:+ * 1. When a round produces zero spoken turns but the thread's tail contains+ * an @mention of a member who has NOT yet answered it, drive one+ * continuation round for exactly those cited members (still bounded by+ * the GROUP_CHAT_MAX_* caps) instead of settling silently.+ * 2. If settling must happen anyway (cap exhausted), record an activity+ * entry naming the unaddressed handoff so the room does not LOOK+ * finished while a called bot never answered.+ */+import assert from 'node:assert/strict'+import test from 'node:test'++// Mirror of resolveGroupResponders' scoping rule (plugin.js L6441): mentions+// are collected from entries after the last user entry.+function mentionedSinceLastUser(log, parseMentions) {+ let sinceLastUser = []++ for (let i = log.length - 1; i >= 0; i--) {+ if (log[i].from.kind === 'user') {+ sinceLastUser = log.slice(i)+ break+ }+ }++ const mentioned = new Set()++ for (const entry of sinceLastUser) {+ for (const name of parseMentions(entry.text)) {+ mentioned.add(name)+ }+ }++ return mentioned+}++test('#94478: detects an unanswered member mention in the post-user tail', () => {+ // Room state from the issue: user asks, member radar replies citing @hermes.+ const log = [+ { id: 1, from: { kind: 'user' }, text: 'kick this off' },+ { id: 2, from: { kind: 'member', name: 'radar' }, text: 'done — @hermes please review' }+ ]++ const mentioned = mentionedSinceLastUser(log, text => (text.includes('@hermes') ? ['hermes'] : []))++ // Pre-fix, the loop exits via `spokeThisRound === 0` / cap exhaustion before+ // any round can act on this mention. The fix's detector must find it so a+ // continuation round can be driven for exactly [hermes].+ assert.ok(mentioned.has('hermes'), 'cited member must be detected as pending')+})++test('#94478: does not flag a handoff the cited member already answered', () => {+ const log = [+ { id: 1, from: { kind: 'user' }, text: 'kick this off' },+ { id: 2, from: { kind: 'member', name: 'radar' }, text: 'done — @hermes please review' },+ { id: 3, from: { kind: 'member', name: 'hermes' }, text: 'reviewed, all good' }+ ]++ // hermes has a member entry AFTER the mentioning one — handoff resolved.+ // The fix's detector must not re-drive an answered mention (that would loop).+ const mentionIdx = log.findIndex(e => e.id === 2)+ const answer = [...log].reverse().find(e => e.from.kind === 'member' && e.from.name === 'hermes')+ const answerIdx = log.findIndex(e => answer && e.id === answer.id)++ assert.ok(answerIdx > mentionIdx, 'answer must postdate the mention')+})