Skip to content

A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.

Sync thinking levels to existing group Sessions on restart

Fei24111b3f8ccad241
diff --git a/ds-bot/src/host/models.js b/ds-bot/src/host/models.js
index ac06f9f3..b236d1cd 100644
--- a/ds-bot/src/host/models.js
+++ b/ds-bot/src/host/models.js
@@ -137,6 +137,9 @@ export function install(rt) {
// it. Selections run one at a time and wait for the write-back: profile writes land in
// submission order, so the next one reads the user's default, not a Bot's.
let selecting = Promise.resolve()
+ // Recheck group Sessions after every restart: Bot-level applied fields cannot
+ // prove that an older group Session received the member's thinking level.
+ const sessionSelections = new Map()
function selectSessionModel(sessionId, { provider, model, reasoningEffort }) {
const run = selecting.then(async () => {
const defaults = ctx.get?.('agentDefaultModel')
@@ -149,6 +152,7 @@ export function install(rt) {
if (before?.provider && before?.model && !sameSelection(before, saved)) {
await defaults.saveSelection(before).catch(error => rt.warn('ds-bot: the default model was not restored: %s', error))
}
+ sessionSelections.set(sessionId, { provider, model, reasoningEffort })
return result
})
selecting = run.catch(() => {})
@@ -163,13 +167,16 @@ export function install(rt) {
const ref = await desiredModel(bot)
if (ref === undefined) return ref
const effort = await desiredEffort(bot, ref)
- if (!force && bot.appliedModel === ref && (bot.appliedEffort ?? undefined) === effort) return ref
+ const ownChanged = force || bot.appliedModel !== ref || (bot.appliedEffort ?? undefined) !== effort
const route = { ...splitRef(ref), ...(effort === undefined ? {} : { reasoningEffort: effort }) }
- await selectSessionModel(rt.chatOf(bot.id), route)
+ if (ownChanged) await selectSessionModel(rt.chatOf(bot.id), route)
for (const sessionId of rt.groupSessionsOf(bot.id)) {
+ const applied = sessionSelections.get(sessionId)
+ if (!force && applied !== undefined && sameSelection(applied, route)) continue
await selectSessionModel(sessionId, route)
.catch(error => rt.warn('ds-bot: model for %s in a group not applied: %s', bot.name, error))
}
+ if (!ownChanged) return ref
bot.appliedModel = ref
if (effort === undefined) delete bot.appliedEffort
else bot.appliedEffort = effort
diff --git a/ds-bot/test/group-work.test.js b/ds-bot/test/group-work.test.js
index e10a705f..4eb2118f 100644
--- a/ds-bot/test/group-work.test.js
+++ b/ds-bot/test/group-work.test.js
@@ -173,6 +173,22 @@ test('message_bot from a group to one of its members calls it there, as "@Name"
assert.deepEqual([host.agentOf('b').calls, host.agentOf('gc').calls], [[], []])
})
+test('a group Session made before the member\'s level applied gets it on the next sync', async (t) => {
+ const llm = {
+ listProviders: () => [{ id: 'deepseek', name: 'DeepSeek' }],
+ listModels: async () => [{ id: 'v4-flash', name: 'v4-flash', inputModalities: ['text'] }],
+ resolveModelInfo: async () => ({ reasoning: { efforts: [{ id: 'low', name: 'Low' }, { id: 'high', name: 'High' }], defaultEffort: 'high' } }),
+ }
+ // Saved state from before the fix: 'gb' already exists and the Bot-level record
+ // already says applied — the bot-wide check would never revisit the group Session.
+ const host = await start(t, { members: ['a', 'b'], sessions: { a: 'ga', b: 'gb' } }, undefined, undefined,
+ { b: { model: 'deepseek/v4-flash', effort: 'low', appliedModel: 'deepseek/v4-flash', appliedEffort: 'low' } }, llm)
+ await host.call('state', {})
+ // The group Session gets the member's level once; the own chat is not re-selected.
+ await settle(() => host.selected.length === 1)
+ assert.deepEqual(host.selected, [{ sessionId: 'gb', provider: 'deepseek', model: 'v4-flash', reasoningEffort: 'low' }])
+})
+
test('a member\'s group Session runs on the member\'s model and thinking level', async (t) => {
const llm = {
listProviders: () => [{ id: 'deepseek', name: 'DeepSeek' }],
diff --git a/ds-bot/test/models.test.js b/ds-bot/test/models.test.js
index 248b3b6f..b97e5566 100644
--- a/ds-bot/test/models.test.js
+++ b/ds-bot/test/models.test.js
@@ -144,6 +144,53 @@ test('a Bot model applies its thinking level, and only re-selects on a change',
assert.equal(bot.appliedEffort, undefined)
})
+test('group selections sync per Session even when the Bot-level fields already match', async () => {
+ const { rt, selected } = bench({ reasoning: { 'deepseek/v4-flash': { reasoning: { efforts: [{ id: 'low' }, { id: 'high' }], defaultEffort: 'high' } } } })
+ const bot = { id: 'b1', model: 'deepseek/v4-flash', effort: 'low', appliedModel: 'deepseek/v4-flash', appliedEffort: 'low' }
+ const groups = ['g1', 'g2']
+ rt.groupSessionsOf = () => groups
+ const select = rt.ctx.sessionController.selectModel
+ rt.ctx.sessionController.selectModel = async (request) => {
+ await select(request)
+ return { selected: { provider: request.provider, model: request.model, reasoningEffort: request.reasoningEffort ?? 'high' } }
+ }
+ await rt.applyModel(bot)
+ assert.deepEqual(selected, ['g1:deepseek/v4-flash:low', 'g2:deepseek/v4-flash:low'])
+ await rt.applyModel(bot)
+ assert.equal(selected.length, 2)
+ groups.push('g3')
+ await rt.applyModel(bot)
+ assert.deepEqual(selected.slice(2), ['g3:deepseek/v4-flash:low'])
+
+ delete bot.effort
+ await rt.applyModel(bot)
+ assert.deepEqual(selected.slice(3), ['b1:deepseek/v4-flash', 'g1:deepseek/v4-flash', 'g2:deepseek/v4-flash', 'g3:deepseek/v4-flash'])
+ // The provider's resolved default is not an explicit Bot choice to reapply.
+ await rt.applyModel(bot)
+ assert.equal(selected.length, 7)
+ await rt.applyModel(bot, { force: true })
+ assert.equal(selected.length, 11)
+})
+
+test('a failed group selection is retried without reselecting the own chat or successful groups', async () => {
+ const { rt, selected } = bench()
+ const bot = { id: 'b1', model: 'deepseek/v4-flash', appliedModel: 'deepseek/v4-flash' }
+ rt.groupSessionsOf = () => ['g1', 'g2']
+ const select = rt.ctx.sessionController.selectModel
+ let failed = false
+ rt.ctx.sessionController.selectModel = async (request) => {
+ if (request.sessionId === 'g2' && !failed) {
+ failed = true
+ throw new Error('Session unavailable')
+ }
+ return select(request)
+ }
+ await rt.applyModel(bot)
+ assert.deepEqual(selected, ['g1:deepseek/v4-flash'])
+ await rt.applyModel(bot)
+ assert.deepEqual(selected, ['g1:deepseek/v4-flash', 'g2:deepseek/v4-flash'])
+})
+
test('resolveEffort takes an id or a name, and refuses what the model has not', async () => {
const { rt } = bench({ reasoning: {
'deepseek/v4-flash': { reasoning: { efforts: [{ id: 'off', name: 'Off' }, { id: 'high', name: 'High' }] } },