Skip to content

The agent that grows with you

fix(desktop): make member stop sticky — per-member hold until explicit resume (#93129)

kshitijk4poor0c474d782073
diff --git a/apps/desktop/src/plugins/hermes-bots/plugin.js b/apps/desktop/src/plugins/hermes-bots/plugin.js
index 6887f33fa4f..d36f2e69924 100644
--- a/apps/desktop/src/plugins/hermes-bots/plugin.js
+++ b/apps/desktop/src/plugins/hermes-bots/plugin.js
@@ -503,7 +503,8 @@ const GROUP_ACTIVITY_LABELS = {
failed: 'hit an error',
cancelled: 'turn interrupted by a newer message',
settled: 'turn settled',
- delivered: 'delivered a late reply'
+ delivered: 'delivered a late reply',
+ held: 'is held (stopped by you) — @mention it or say resume to release'
}
const GROUP_ACTIVITY_GLYPHS = {
@@ -515,7 +516,8 @@ const GROUP_ACTIVITY_GLYPHS = {
failed: 'error',
cancelled: 'close',
settled: 'check-all',
- delivered: 'mail-read'
+ delivered: 'mail-read',
+ held: 'debug-pause'
}
/** Text tone for an activity row: quiet for pass/cancel/settle, accent for
@@ -6313,6 +6315,10 @@ function updateGroupChat(group, mutate, { sync = true } = {}) {
// with the pre-turn message baseline. Survives reloads so finished
// work is still harvested after a window restart.
stranded: room.stranded || {},
+ // #93129: sticky per-member stop holds. Watermarks persist, so holds
+ // must too — otherwise a window restart silently releases a bot the
+ // user explicitly stopped.
+ holds: room.holds || {},
// Source-qualified member descriptors keep the room whole when the
// active connection changes and today's local members become remote.
members: Array.isArray(room.members) ? room.members : [],
@@ -7097,6 +7103,80 @@ function isDuplicateGroupAppend(lastEntry, from, text, thread, now = Date.now())
// --- end room-turn decision helpers ---
+// --- member-hold helpers (#93129) — pure, vm-sliced by tests ---
+
+/** #93129: classify a USER room message's effect on member holds. Only user
+ * sends ever reach this (bot replies are appended by the round loop, never
+ * through sendToGroupChat), so a bot saying "stopped working on it" can
+ * never set a hold. Conservative on purpose: any standalone stop/halt/pause
+ * word next to a mention holds those members — "don't stop @x" therefore
+ * also holds, which errs toward the bot staying quiet until re-addressed
+ * (a wrongly-held bot is one mention away from release; a wrongly-running
+ * one keeps doing work it was told to stop). A non-stop direct mention
+ * releases the mentioned members — the user addressing a bot directly
+ * overrides its hold. */
+function classifyGroupHoldDirective(text, mentionedKeys, everyone) {
+ const value = String(text || '')
+ const mentioned = [...(mentionedKeys || [])]
+ const stop = /\b(stop|halt|pause)\b/i.test(value)
+ const resume = /\b(resume|continue|go|proceed)\b/i.test(value)
+
+ if (stop) {
+ return { hold: mentioned, release: [], releaseAll: false }
+ }
+
+ if (resume) {
+ return { hold: [], release: mentioned, releaseAll: Boolean(everyone) }
+ }
+
+ return { hold: [], release: mentioned, releaseAll: false }
+}
+
+/** #93129: next holds map after one user message. Holds are keyed by
+ * memberKey at ROOM scope (not thread scope): every main-composer send
+ * mints a NEW thread, so a thread-scoped hold would never block the next
+ * send's turns and the stop would not stick. Returns the same object when
+ * nothing changed. */
+function applyGroupHoldDirective(holds, mentions, text, stamp) {
+ const prior = holds && typeof holds === 'object' ? holds : {}
+ const action = classifyGroupHoldDirective(text, mentions?.mentioned || [], Boolean(mentions?.everyone))
+
+ if (action.releaseAll) {
+ return Object.keys(prior).length ? {} : prior
+ }
+
+ let next = prior
+
+ for (const key of action.hold) {
+ if (next === prior) {
+ next = { ...prior }
+ }
+
+ next[key] = { at: stamp?.at || Date.now(), byMessageId: stamp?.byMessageId || null, thread: stamp?.thread || null }
+ }
+
+ for (const key of action.release) {
+ if (Object.prototype.hasOwnProperty.call(next, key)) {
+ if (next === prior) {
+ next = { ...prior }
+ }
+
+ delete next[key]
+ }
+ }
+
+ return next
+}
+
+/** #93129: a held member's skip must consume its delta exactly once —
+ * advance the watermark past the current log so the same entries never
+ * re-trigger the skip. Null = nothing to consume (no write, no spin). */
+function heldMemberWatermarkAdvance(seen, logLength) {
+ return logLength > (seen || 0) ? logLength : null
+}
+
+// --- end member-hold helpers ---
+
/** 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.
@@ -7159,6 +7239,35 @@ async function runGroupChatRounds(group, members, thread) {
continue
}
+ // #93129: a member the user told to stop is HELD — no turn until an
+ // explicit release (resume / @all resume / a direct non-stop
+ // mention). Consume the delta exactly once (watermark past the
+ // current log) so the same entries never re-trigger this skip, and
+ // surface WHY the bot is silent in the activity feed the first time.
+ const heldEntry = (room.holds || {})[memberKey]
+
+ if (heldEntry) {
+ const advance = heldMemberWatermarkAdvance(seen, room.log.length)
+
+ updateGroupChat(group, r => {
+ if (advance !== null) {
+ r.watermarks[markKey] = advance
+ }
+
+ if (r.holds?.[memberKey] && !r.holds[memberKey].noted) {
+ r.holds = { ...r.holds, [memberKey]: { ...r.holds[memberKey], noted: true } }
+ }
+
+ return r
+ })
+
+ if (!heldEntry.noted) {
+ recordGroupActivity(group, { kind: 'held', member: member.name, thread })
+ }
+
+ continue
+ }
+
const prompt = buildGroupChatTurnPrompt({
groupName: group,
members,
@@ -7320,13 +7429,23 @@ function sendToGroupChat(group, members, text, thread, images) {
room.members = durableGroupChatMembers(members)
return room
})
- appendGroupChatEntry(group, { kind: 'user', name: 'You' }, trimmed, target, attached)
+ const sent = appendGroupChatEntry(group, { kind: 'user', name: 'You' }, trimmed, target, attached)
const wasRunning = ($groupChats.get()[group] || {}).running === true
updateGroupChat(group, room => {
room.epoch = (room.epoch || 0) + 1
room.running = true
+ // #93129: user text is the ONLY input that changes member holds. An
+ // explicit "stop @member" sets a sticky hold; "@member resume" (or
+ // @all resume, or any direct non-stop mention of the held member)
+ // releases it. Bot replies never flow through this function.
+ room.holds = applyGroupHoldDirective(
+ room.holds,
+ parseGroupChatMentions(trimmed, members),
+ trimmed,
+ { at: sent?.at, byMessageId: sent?.id, thread: target }
+ )
return room
})
@@ -14177,6 +14296,10 @@ export default {
sessions: room.sessions && typeof room.sessions === 'object' ? room.sessions : {},
sessionOwners: room.sessionOwners && typeof room.sessionOwners === 'object' ? room.sessionOwners : {},
stranded: room.stranded && typeof room.stranded === 'object' ? room.stranded : {},
+ // #93129: rehydrate sticky stop holds with the same shape
+ // guard as the other maps — a held bot stays held across
+ // window restarts until explicitly released.
+ holds: room.holds && typeof room.holds === 'object' ? room.holds : {},
members: Array.isArray(room.members) ? room.members : [],
roomId: typeof room.roomId === 'string' && room.roomId ? room.roomId : null,
image: typeof room.image === 'string' && room.image ? room.image : null,
diff --git a/apps/desktop/src/plugins/hermes-bots/tests/group-member-hold.test.mjs b/apps/desktop/src/plugins/hermes-bots/tests/group-member-hold.test.mjs
new file mode 100644
index 00000000000..8216632bebb
--- /dev/null
+++ b/apps/desktop/src/plugins/hermes-bots/tests/group-member-hold.test.mjs
@@ -0,0 +1,114 @@
+import assert from 'node:assert/strict'
+import { readFileSync } from 'node:fs'
+import test from 'node:test'
+import vm from 'node:vm'
+
+// #93129: a bot told to stop must STAY stopped. The hold helpers are pure and
+// vm-sliced out of plugin.js exactly like group-turn-races.test.mjs does for
+// the #93127 helpers. NOTE: vm-realm arrays/objects fail strict deepEqual
+// against host literals (different realm prototypes) — normalize with spread
+// or JSON round-trip before comparing.
+
+const pluginSource = readFileSync(new URL('../plugin.js', import.meta.url), 'utf8')
+
+function loadHelpers() {
+ const start = pluginSource.indexOf('// --- member-hold helpers (#93129)')
+ const end = pluginSource.indexOf('// --- end member-hold helpers ---', start)
+ assert.notEqual(start, -1, 'plugin carries the member-hold helper block')
+ assert.notEqual(end, -1, 'member-hold helper block has a stable end marker')
+ const context = {}
+ vm.runInNewContext(
+ `${pluginSource.slice(start, end)}
+globalThis.classifyGroupHoldDirective = classifyGroupHoldDirective
+globalThis.applyGroupHoldDirective = applyGroupHoldDirective
+globalThis.heldMemberWatermarkAdvance = heldMemberWatermarkAdvance`,
+ context
+ )
+ return context
+}
+
+// ── stop detection ───────────────────────────────────────────────────────────
+
+test('explicit stop with a mention holds the mentioned member', () => {
+ const { classifyGroupHoldDirective } = loadHelpers()
+ for (const text of ['stop @impl', '@impl stop', '@impl please halt', 'pause @impl for now']) {
+ const action = classifyGroupHoldDirective(text, ['impl'], false)
+ assert.deepEqual([...action.hold], ['impl'], `"${text}" should hold`)
+ assert.deepEqual([...action.release], [])
+ }
+})
+
+test('stop word without any mention holds nobody', () => {
+ const { classifyGroupHoldDirective } = loadHelpers()
+ const action = classifyGroupHoldDirective('stop', [], false)
+ assert.deepEqual([...action.hold], [])
+})
+
+test('conservative choice: "don\'t stop @x" still holds (documented trade-off)', () => {
+ const { classifyGroupHoldDirective } = loadHelpers()
+ const action = classifyGroupHoldDirective("don't stop @impl", ['impl'], false)
+ assert.deepEqual([...action.hold], ['impl'])
+})
+
+test('"stopped" as part of another word does not trigger a hold', () => {
+ const { classifyGroupHoldDirective } = loadHelpers()
+ // \b(stop|halt|pause)\b — "stopped" is a different token
+ const action = classifyGroupHoldDirective('@impl unstoppable work ahead', ['impl'], false)
+ assert.deepEqual([...action.hold], [])
+ // a plain non-stop mention releases instead (direct address overrides hold)
+ assert.deepEqual([...action.release], ['impl'])
+})
+
+// ── hold lifecycle ───────────────────────────────────────────────────────────
+
+test('stop sets a hold; resume for the same member clears it', () => {
+ const { applyGroupHoldDirective } = loadHelpers()
+ const stamp = { at: 1000, byMessageId: 'm1', thread: 't1' }
+ const held = applyGroupHoldDirective({}, { mentioned: ['impl'], everyone: false }, 'stop @impl', stamp)
+ assert.ok(held.impl)
+ assert.equal(held.impl.at, 1000)
+ const released = applyGroupHoldDirective(held, { mentioned: ['impl'], everyone: false }, '@impl resume', stamp)
+ assert.equal(released.impl, undefined)
+})
+
+test('a direct non-stop mention of a held member releases the hold', () => {
+ const { applyGroupHoldDirective } = loadHelpers()
+ const held = { impl: { at: 1, byMessageId: null, thread: null } }
+ const next = applyGroupHoldDirective(held, { mentioned: ['impl'], everyone: false }, '@impl what is your status?', {})
+ assert.equal(next.impl, undefined)
+})
+
+test('@all resume releases every hold', () => {
+ const { applyGroupHoldDirective } = loadHelpers()
+ const held = { impl: { at: 1 }, docs: { at: 2 } }
+ const next = applyGroupHoldDirective(held, { mentioned: [], everyone: true }, '@all resume', {})
+ assert.deepEqual(JSON.parse(JSON.stringify(next)), {})
+})
+
+test('an unrelated room message leaves holds untouched (same object back)', () => {
+ const { applyGroupHoldDirective } = loadHelpers()
+ const held = { impl: { at: 1 } }
+ const next = applyGroupHoldDirective(held, { mentioned: [], everyone: false }, 'receipt round complete', {})
+ assert.equal(next, held)
+})
+
+test('holding one member does not disturb another\'s hold', () => {
+ const { applyGroupHoldDirective } = loadHelpers()
+ const held = { impl: { at: 1 } }
+ const next = applyGroupHoldDirective(held, { mentioned: ['docs'], everyone: false }, 'stop @docs', { at: 2 })
+ assert.ok(next.impl)
+ assert.ok(next.docs)
+})
+
+// ── skip must not spin ───────────────────────────────────────────────────────
+
+test('held skip consumes the delta exactly once', () => {
+ const { heldMemberWatermarkAdvance } = loadHelpers()
+ // fresh delta → advance to log length
+ assert.equal(heldMemberWatermarkAdvance(3, 7), 7)
+ // already consumed → no write, no spin
+ assert.equal(heldMemberWatermarkAdvance(7, 7), null)
+ assert.equal(heldMemberWatermarkAdvance(9, 7), null)
+ // unset watermark treated as 0
+ assert.equal(heldMemberWatermarkAdvance(undefined, 2), 2)
+})