Skip to content

The agent that grows with you

fix(desktop): preserve group turn reason codes

1052326311a8169f3e65c5
diff --git a/apps/desktop/src/plugins/hermes-bots/plugin.js b/apps/desktop/src/plugins/hermes-bots/plugin.js
index ce355f700a8..0470defffd7 100644
--- a/apps/desktop/src/plugins/hermes-bots/plugin.js
+++ b/apps/desktop/src/plugins/hermes-bots/plugin.js
@@ -8104,8 +8104,14 @@ async function runGroupChatRounds(group, members, thread) {
clearBotAttention(groupMemberKey(member))
}
} catch (error) {
- recordGroupActivity(group, { kind: 'failed', member: member.name, thread })
- noteBotAttention(groupMemberKey(member), error?.message || error)
+ const reason = String(error?.data?.reason || '').trim()
+ recordGroupActivity(group, {
+ kind: 'failed',
+ member: member.name,
+ thread,
+ ...(reason ? { reason } : {})
+ })
+ noteBotAttention(groupMemberKey(member), reason || error?.message || error)
reply = null // a failed turn is a pass, never a room error
}
diff --git a/apps/desktop/src/plugins/hermes-bots/tests/bot-attention-badge.test.mjs b/apps/desktop/src/plugins/hermes-bots/tests/bot-attention-badge.test.mjs
index 934eceecfff..71ec3e1be70 100644
--- a/apps/desktop/src/plugins/hermes-bots/tests/bot-attention-badge.test.mjs
+++ b/apps/desktop/src/plugins/hermes-bots/tests/bot-attention-badge.test.mjs
@@ -133,8 +133,11 @@ test('hooks: relay delivery and group member turns note/clear attention', () =>
assert.match(drain, /\.\.\.\(reason \? \{ reason \} : \{\}\)/)
// Group member turn boundary: failure notes under the member key; a real
- // reply clears it.
- assert.match(pluginSource, /noteBotAttention\(groupMemberKey\(member\), error\?\.message \|\| error\)/)
+ // reply clears it. Typed gateway reasons take precedence over text parsing.
+ assert.match(
+ pluginSource,
+ /noteBotAttention\(groupMemberKey\(member\), reason \|\| error\?\.message \|\| error\)/
+ )
assert.match(pluginSource, /clearBotAttention\(groupMemberKey\(member\)\)/)
})
diff --git a/apps/desktop/src/plugins/hermes-bots/tests/group-activity.test.mjs b/apps/desktop/src/plugins/hermes-bots/tests/group-activity.test.mjs
index 3027e4f8909..e46085be69d 100644
--- a/apps/desktop/src/plugins/hermes-bots/tests/group-activity.test.mjs
+++ b/apps/desktop/src/plugins/hermes-bots/tests/group-activity.test.mjs
@@ -104,7 +104,7 @@ function load(turnScript = () => '(pass)') {
.replace(/^import .* from 'react\/jsx-runtime'\r?\n/m, '')
.replace('export default {', 'globalThis.plugin = {')
.concat(
- '\nglobalThis.__ga = { sendToGroupChat, recordGroupActivity, currentGroupActivity, groupActivityLabel, updateGroupChat, $groupChats, $groupActivity, GROUP_ACTIVITY_LIMIT };\n'
+ '\nglobalThis.__ga = { sendToGroupChat, recordGroupActivity, currentGroupActivity, groupActivityLabel, updateGroupChat, $groupChats, $groupActivity, $botAttention, GROUP_ACTIVITY_LIMIT };\n'
)
vm.runInNewContext(source, context, { filename: 'plugin.js' })
const storageWrites = new Map()
@@ -164,6 +164,40 @@ test('a failed member turn records failed instead of a phantom reply', async ()
assert.equal(events.some(e => e.kind === 'failed' && e.member === 'builder'), true)
})
+test('a failed member turn preserves and prefers its typed reason', async () => {
+ const gc = load(profile => {
+ if (profile === 'builder') {
+ const error = new Error('generic gateway failure')
+ error.data = { reason: 'provider_auth_or_access' }
+ throw error
+ }
+ return '(pass)'
+ })
+
+ gc.sendToGroupChat('Typed failure', MEMBERS, 'anyone around?')
+ await drain(gc, 'Typed failure')
+
+ const failed = feed(gc, 'Typed failure').find(e => e.kind === 'failed' && e.member === 'builder')
+ assert.equal(failed.reason, 'provider_auth_or_access')
+ assert.equal(Object.values(gc.$botAttention.get())[0]?.reason, 'provider_auth_or_access')
+})
+
+test('an untyped failed member turn keeps the message-classification fallback', async () => {
+ const gc = load(profile => {
+ if (profile === 'builder') {
+ throw new Error('No LLM provider configured')
+ }
+ return '(pass)'
+ })
+
+ gc.sendToGroupChat('Untyped failure', MEMBERS, 'anyone around?')
+ await drain(gc, 'Untyped failure')
+
+ const failed = feed(gc, 'Untyped failure').find(e => e.kind === 'failed' && e.member === 'builder')
+ assert.equal(failed.reason, undefined)
+ assert.equal(Object.values(gc.$botAttention.get())[0]?.reason, 'missing_config')
+})
+
test('a newer send interrupts the previous run and records cancelled in the CURRENT epoch', async () => {
const gates = [null, null]
const gate = n => {