Skip to content

The agent that grows with you

test(bots): pin draft sweep age boundary

fangliquanflq8fca54f9f15c
diff --git a/apps/desktop/src/plugins/hermes-bots/plugin.js b/apps/desktop/src/plugins/hermes-bots/plugin.js
index 71a3e3f823d..da964d0606f 100644
--- a/apps/desktop/src/plugins/hermes-bots/plugin.js
+++ b/apps/desktop/src/plugins/hermes-bots/plugin.js
@@ -2121,13 +2121,15 @@ function isBotModeSweepCandidate(row, nowSeconds = Date.now() / 1000) {
* is never listed, so its sessions are never touched) and hide any VISIBLE
* row whose title is Bot Mode plumbing and whose creation grace period has
* elapsed. The grace period protects a new desktop draft while its first-turn
- * title is pending; missing or future timestamps fail closed. session.list
+ * title is pending; after five minutes an unchanged plumbing title is treated
+ * as Bot Mode-owned. session.list supplies epoch seconds; missing, malformed,
+ * millisecond, or future timestamps fail closed and stay visible. session.list
* without include_hidden returns only visible rows, which keeps the sweep
* naturally idempotent.
* Remote-source bots route to their own connection via requestForBot.
* Feature-detected + fire-and-forget: older gateways without per-profile
* session.list / session.set_hidden simply reject and the sweep no-ops. */
-async function sweepBotProfileSessions() {
+async function sweepBotProfileSessions(nowSeconds = Date.now() / 1000) {
const cached = $lastRoster.get()
let roster = Array.isArray(cached) && cached.length ? cached : null
@@ -2158,7 +2160,7 @@ async function sweepBotProfileSessions() {
await Promise.all(
rows
- .filter(row => isBotModeSweepCandidate(row))
+ .filter(row => isBotModeSweepCandidate(row, nowSeconds))
.map(row =>
Promise.resolve(
requestForBot(bot, 'session.set_hidden', { session_id: row.id, hidden: true, profile: name })
diff --git a/apps/desktop/src/plugins/hermes-bots/tests/hide-bot-chats.test.mjs b/apps/desktop/src/plugins/hermes-bots/tests/hide-bot-chats.test.mjs
index 6424f7e27ee..9e9dcb48aee 100644
--- a/apps/desktop/src/plugins/hermes-bots/tests/hide-bot-chats.test.mjs
+++ b/apps/desktop/src/plugins/hermes-bots/tests/hide-bot-chats.test.mjs
@@ -219,6 +219,7 @@ test('sweepBotProfileSessions hides Bot-Mode-titled rows per roster bot, and onl
const start = source.indexOf('function hideOwnedBotSessions()')
const end = source.indexOf('/** Fetch server-side avatars', start)
const calls = []
+ const nowSeconds = 1_000
const rowsByProfile = {
alpha: [
{ id: 'a-1', title: 'Bot Chat', started_at: 1 },
@@ -226,8 +227,9 @@ test('sweepBotProfileSessions hides Bot-Mode-titled rows per roster bot, and onl
{ id: 'a-3', title: 'Group: Core', started_at: 1 },
{ id: 'a-4', title: 'My real conversation', started_at: 1 },
{ id: 'a-5', title: 'Bot Chat notes', started_at: 1 }, // not an exact title — kept
- { id: 'a-6', title: 'Bot Chat', started_at: Date.now() / 1000 }, // live draft — kept
- { id: 'a-7', title: 'Agent Inbox' } // missing age metadata — kept fail-closed
+ { id: 'a-6', title: 'Bot Chat', started_at: nowSeconds - 299 }, // live draft — kept
+ { id: 'a-7', title: 'Agent Inbox' }, // missing age metadata — kept fail-closed
+ { id: 'a-8', title: 'Bot Chat', started_at: nowSeconds - 300 } // boundary reached — hidden
],
remy: [{ id: 'r-1', title: 'Agent Inbox', started_at: 1 }]
}
@@ -247,7 +249,7 @@ test('sweepBotProfileSessions hides Bot-Mode-titled rows per roster bot, and onl
}
const section = source.slice(start, end).concat('\nglobalThis.__h = { hideOwnedBotSessions, sweepBotProfileSessions };\n')
vm.runInNewContext(section, context, { filename: 's.js' })
- await context.__h.sweepBotProfileSessions()
+ await context.__h.sweepBotProfileSessions(nowSeconds)
const lists = calls.filter(c => c.method === 'session.list')
assert.deepEqual(lists.map(c => c.params.profile).sort(), ['alpha', 'remy'])
@@ -257,7 +259,7 @@ test('sweepBotProfileSessions hides Bot-Mode-titled rows per roster bot, and onl
const hidden = calls.filter(c => c.method === 'session.set_hidden')
assert.deepEqual(
hidden.map(c => c.params.session_id).sort(),
- ['a-1', 'a-2', 'a-3', 'r-1'],
+ ['a-1', 'a-2', 'a-3', 'a-8', 'r-1'],
'exact plumbing titles only — user-titled and brand-new rows stay visible'
)
assert.ok(hidden.every(c => c.params.hidden === true))