A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Wait for the task move before stopping an earlier part
Fei2411b6a9a285d93e
diff --git a/ds-bot/src/host/parts.js b/ds-bot/src/host/parts.jsindex e456f305..9905360d 100644--- a/ds-bot/src/host/parts.js+++ b/ds-bot/src/host/parts.js@@ -788,6 +788,9 @@ export function install(rt) {if (currentOf(owner) !== sessionId) {await forward(owner, held)for (const message of held) agent.inbox.remove(message.id)+ // An interrupted switch may not have finished moving the tasks over; stop+ // the earlier part only after they sit on the part that replaced it.+ await rt.moveSchedules?.(sessionId, currentOf(owner))await ctx.workspaceRegistry.archiveSession(sessionId, { stopActivity: true }).catch(error => rt.warn('ds-bot: earlier part %s not archived: %s', sessionId, error))} else {@@ -876,6 +879,9 @@ export function install(rt) {}if (job.moved) {rt.renewMemory(agent.id)+ // The task move started inside the switch; stopping the earlier part while it+ // still runs would drop the tasks it has not copied yet.+ await job.movedSchedulesawait ctx.workspaceRegistry.archiveSession(agent.id, { stopActivity: true }).catch(error => rt.warn('ds-bot: earlier part %s not archived: %s', agent.id, error))}@@ -977,7 +983,7 @@ export function install(rt) {const now = await freshRoute(bot, session)if (now !== undefined && (now.ref !== picked?.ref || now.effort !== picked?.effort)) await selectRoute(bot, freshId, now)if (job.failed !== undefined) rescued.set(freshId, job.bare ? 'bare' : 'carried')- void rt.moveSchedules(agent.id, freshId)+ job.movedSchedules = rt.moveSchedules(agent.id, freshId)job.moved = trueconst resume = job.resume || job.overflow// Then what the old part held: the stopped turn's input, then whatever waited. Itdiff --git a/ds-bot/test/switch-keeps-input.test.js b/ds-bot/test/switch-keeps-input.test.jsindex 344feedb..6ac7b639 100644--- a/ds-bot/test/switch-keeps-input.test.js+++ b/ds-bot/test/switch-keeps-input.test.js@@ -329,6 +329,26 @@ test('a marked part that stayed current is woken for its kept input, once, in orassert.deepEqual(second.state().switching, {})})+// #571: archiving with stopActivity drops the tasks the earlier part still owns, so+// the archive waits for the task move the switch started.+test('an earlier part is stopped only after its tasks moved to the fresh part', async (t) => {+ const host = await start({ services })+ t.after(host.stop)+ const order = []+ let release+ const moved = new Promise(resolve => { release = resolve })+ host.rt.moveSchedules = async (from, to) => { order.push(['move', from, to]); await moved }+ const archive = host.ctx.workspaceRegistry.archiveSession+ host.ctx.workspaceRegistry.archiveSession = async (id, options) => { order.push(['archive', id]); return archive(id, options) }+ await moveWriter(host, [])+ await until(() => order.length >= 1)+ await settle()+ assert.deepEqual(order, [['move', 'b', 's1']])+ release()+ await until(() => order.some(([kind]) => kind === 'archive'))+ assert.deepEqual(order, [['move', 'b', 's1'], ['archive', 'b']])+})+test('unmarked earlier parts are never resolved by the restart pass', async (t) => {const host = await start({ services })await moveWriter(host, [])