A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Stop a deleted Bot or group chat's scheduled tasks
Fei24112ceba39a8092
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 685ad0a3..9d84242b 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -18,6 +18,7 @@ All notable changes to DS Bot are listed here. The format follows [Keep a Change- In a group chat, a conversation referenced in a message reached none of the members, and a reference whose title started with a member's name called that member. Now the members who answer the message get the referenced conversation.- In a group chat, typing `@` and a Bot's name and pressing Enter inserted a conversation reference instead of the Bot's name.+- Deleting a Bot or group chat also removes its scheduled tasks. Before, armed tasks stayed active and kept running the deleted Session; the archive that would have stopped them was refused and the failure was silent.- A long conversation's fresh part keeps the Bot's model and thinking level. Before, the new part fell back to the default model.- A provider adapter that cannot measure tokens no longer fails every turn. The context size is estimated instead, with one warning in the log.diff --git a/ds-bot/src/host/roster.js b/ds-bot/src/host/roster.jsindex 36500d76..f20788b1 100644--- a/ds-bot/src/host/roster.js+++ b/ds-bot/src/host/roster.js@@ -329,7 +329,10 @@ export function install(rt) {delete state.rooms[id]rt.roomInbox.delete(id)await rt.save()- await ctx.workspaceRegistry.archiveSession(id).catch(() => {})+ // Armed scheduled tasks refuse a plain archive and would keep delivering into+ // the deleted group; the session-stop that stopActivity runs removes them.+ await ctx.workspaceRegistry.archiveSession(id, { stopActivity: true })+ .catch(error => rt.warn('ds-bot: group chat %s not archived: %s', room.name, error))}// The first Main Bot is the sidebar tile. `replace` gives a Main Bot's place to@@ -364,13 +367,14 @@ export function install(rt) {}async function deleteBot(id) {- if (rt.botOf(id) === undefined) throw new Error('Unknown Bot')+ const bot = rt.botOf(id)+ if (bot === undefined) throw new Error('Unknown Bot')if (rt.isMain(id)) throw new Error('A Main Bot cannot be deleted; remove its Main Bot role first')// Before the Bot and its group Sessions leave the state, which the archive reads.const archived = rt.archiveBotMemory(id)const current = rt.chatOf(id)// Questions and exchange turns are kept per Session, so every part of the chat is cleared.- const parts = new Set([id, current, ...(rt.botOf(id).segments ?? []).map(segment => segment.sessionId)])+ const parts = new Set([id, current, ...(bot.segments ?? []).map(segment => segment.sessionId)])delete state.bots[id]for (const part of parts) {delete state.questions[part]@@ -388,7 +392,9 @@ export function install(rt) {await rt.forgetBotSecrets(id)await archivedawait rt.save()- await ctx.workspaceRegistry.archiveSession(current).catch(() => {})+ // Same as deleteRoom: stopActivity removes the Session's armed scheduled tasks.+ await ctx.workspaceRegistry.archiveSession(current, { stopActivity: true })+ .catch(error => rt.warn('ds-bot: Bot %s not archived: %s', bot.name, error))}async function bootstrap() {diff --git a/ds-bot/test/roster.test.js b/ds-bot/test/roster.test.jsindex 89cd9d88..b8011ba2 100644--- a/ds-bot/test/roster.test.js+++ b/ds-bot/test/roster.test.js@@ -3,18 +3,22 @@ import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'import { tmpdir } from 'node:os'import { join } from 'node:path'import { test } from 'node:test'+import { format } from 'node:util'import { apply } from '../index.js'import { fakeContext } from './fake-ctx.js'// Enough of the dsh services for the roster to make Sessions; kickoff messages are dropped.-function start(team, { models = [], reasoning = {} } = {}) {+function start(team, { models = [], reasoning = {}, archiveError } = {}) {const home = mkdtempSync(join(tmpdir(), 'ds-bot-roster-'))if (team !== undefined) writeFileSync(join(home, 'state.json'), JSON.stringify(team))const ctx = fakeContext()const workspaces = new Map()const sent = []const selected = []+ const archived = []+ const warnings = []let sessions = 0+ ctx.logger.warn = (...args) => warnings.push(format(...args))Object.assign(ctx, {llm: {listProviders: () => (models.length > 0 ? [{ id: 'deepseek', name: 'DeepSeek' }] : []),@@ -29,7 +33,10 @@ function start(team, { models = [], reasoning = {} } = {}) {workspaces.set(workspace.id, workspace)return workspace},- archiveSession: async () => {},+ archiveSession: async (sessionId, options) => {+ if (archiveError !== undefined) throw archiveError+ archived.push([sessionId, options])+ },},sessionController: {create: async () => ({ sessionId: `s${++sessions}` }),@@ -54,7 +61,7 @@ function start(team, { models = [], reasoning = {} } = {}) {ctx.dispose()rmSync(home, { recursive: true, force: true })}- return { call, stop, home, sent, selected, ctx }+ return { call, stop, home, sent, selected, ctx, archived, warnings }}const settle = () => new Promise(resolve => setTimeout(resolve, 20))@@ -266,6 +273,33 @@ test('set-main keeps one Main Bot and replaces only a Main Bot', async (t) => {assert.deepEqual((await call('state', {})).value.mainBotIds, [chief])})+test('deleting a Bot or group chat stops its Session, so its tasks are removed', async (t) => {+ const { call, stop, archived } = start(undefined, { models: ['deepseek-v4-flash'] })+ t.after(stop)+ const chief = (await call('state', {})).value.mainBotId+ const writer = (await call('create-bot', { name: 'Writer' })).value+ const room = (await call('create-room', { members: [chief, writer.id], admin: writer.id })).value+ archived.length = 0+ assert.equal((await call('delete-bot', { id: writer.id })).ok, true)+ assert.equal((await call('delete-room', { id: room.id })).ok, true)+ // `stopActivity` lets DSH's session-stop hook drop the Session's armed+ // scheduled tasks; without it the archive is refused and they keep+ // delivering into the deleted Session.+ assert.deepEqual(archived, [+ [writer.id, { stopActivity: true }],+ [room.id, { stopActivity: true }],+ ])+})++test('an archive failure on delete is warned instead of passing silently', async (t) => {+ const { call, stop, warnings } = start(undefined, { models: ['deepseek-v4-flash'], archiveError: new Error('archive refused') })+ t.after(stop)+ const writer = (await call('create-bot', { name: 'Writer' })).value+ assert.equal((await call('delete-bot', { id: writer.id })).ok, true)+ await settle()+ assert.equal(warnings.filter(text => text.includes('not archived')).length, 1)+})+test('a hidden Bot made Main Bot shows again, and a replaced Chief drops its held greeting', async (t) => {const { call, stop, sent } = start(undefined, { models: ['deepseek-v4-flash'] })t.after(stop)