A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Stop only real subagents and test the rest of the stop path
AdamPlatin123ca1fcc9454d7
diff --git a/ds-bot/src/host/turns.js b/ds-bot/src/host/turns.jsindex ac4e19a4..6e347d88 100644--- a/ds-bot/src/host/turns.js+++ b/ds-bot/src/host/turns.js@@ -223,7 +223,9 @@ export function install(rt) {const map = subagentsByParent.get(sessionId)const childIds = [...(map?.keys() ?? [])]for (const agent of ctx.get?.('agents')?.list?.() ?? []) {- if (agent?.session?.header?.parentSession === sessionId && typeof agent.id === 'string' && !childIds.includes(agent.id)) {+ const header = agent?.session?.header+ // A fork names its parent too, but it is the user's own Session, not work to stop.+ if (header?.parentSession === sessionId && header.origin === 'subagent' && typeof agent.id === 'string' && !childIds.includes(agent.id)) {childIds.push(agent.id)}}diff --git a/ds-bot/test/group-goal.test.js b/ds-bot/test/group-goal.test.jsindex 9b3ab745..1b0a4ce7 100644--- a/ds-bot/test/group-goal.test.js+++ b/ds-bot/test/group-goal.test.js@@ -559,7 +559,8 @@ for (const [endpoint, body] of [['stop-room-work', { roomId: 'r1' }], ['stop-memhost.emit('gb', 'turn/start', { turn: 1 })host.agentOf('gb').cancel = () => { throw new Error('cancel failed') }assert.equal((await host.call(endpoint, body)).ok, false)- await settle(() => goal(host).idle === true)+ const { rooms } = (await host.call('state', {})).value+ assert.equal(rooms.find(room => room.id === 'r1').goal.idle, true)})}diff --git a/ds-bot/test/group-work.test.js b/ds-bot/test/group-work.test.jsindex ff71f945..3c21ff94 100644--- a/ds-bot/test/group-work.test.js+++ b/ds-bot/test/group-work.test.js@@ -1035,17 +1035,56 @@ test('a member that cannot be stopped leaves the others stopped and reports theassert.equal(host.takePost().source.stopped, true)})-test('a subagent whose interrupt throws does not stop the member from being stopped', async (t) => {+test('a round that cannot be stopped leaves the members stopped and reports the failure', async (t) => {+ const host = await start(t)+ const stop = new AbortController()+ host.emit('gb', 'turn/start', { turn: 1 })+ host.emit('r1', 'user/message', host.say('@Chief 看看进度'))+ const relay = host.tool('group_relay', {}, 'r1', { callId: 'c1', signal: stop.signal })+ try {+ await settle(() => host.agentOf('ga').calls.length === 1)+ host.begin('ga')+ host.agentOf('r1').cancel = () => { throw new Error('round cancel failed') }+ const stopped = await host.call('stop-room-work', { roomId: 'r1' })+ assert.equal(stopped.ok, false)+ assert.match(stopped.error.message, /round cancel failed/)+ for (const id of ['ga', 'gb']) assert.deepEqual(host.agentOf(id).cancelled, [{ kind: 'user' }], id)+ } finally {+ stop.abort()+ host.emit('ga', 'turn/end', { turn: 1, reason: { kind: 'aborted' } })+ await relay+ }+})++test('a subagent whose interrupt throws is still cancelled, and so is the member', async (t) => {+ const cancelled = []const host = await start(t, undefined, {subagents: { interrupt: () => { throw new Error('belongs to another parent') } },+ agents: { list: () => [], get: id => (id === 'sub-1' ? { cancel: reason => cancelled.push(reason) } : undefined) },})host.emit('gb', 'turn/start', { turn: 1 })host.emit('gb', 'subagent/catalog', { childId: 'sub-1', label: 'Long run', mode: 'continuable' })const stopped = await host.call('stop-room-work', { roomId: 'r1' })assert.deepEqual([stopped.ok, stopped.value], [true, true])+ assert.deepEqual(cancelled, [{ kind: 'user' }])assert.deepEqual(host.agentOf('gb').cancelled, [{ kind: 'user' }])})+test('stopping a member stops its subagents and leaves Sessions forked from it alone', async (t) => {+ const interrupted = []+ const cancelled = []+ const live = (id, header) => ({ id, session: { header: { parentSession: 'gb', ...header } }, cancel: () => cancelled.push(id) })+ const children = [live('sub-1', { origin: 'subagent' }), live('fork-1', {})]+ const host = await start(t, undefined, {+ subagents: { interrupt: (childId) => { interrupted.push(childId) } },+ agents: { list: () => children, get: id => children.find(child => child.id === id) },+ })+ host.emit('gb', 'turn/start', { turn: 1 })+ assert.equal((await host.call('stop-room-work', { roomId: 'r1' })).value, true)+ assert.deepEqual(interrupted, ['sub-1'])+ assert.deepEqual(cancelled, ['sub-1'])+})+// An unhandled rejection here would end the Host.test('a stopped round warns when a member turn cannot be stopped', async (t) => {const host = await start(t)@@ -1620,9 +1659,7 @@ test('a group member with a running DSH subagent stays working and stop-room-wor// User clicks "Stop all" in the group: it interrupts sub-1 and logs Writer as stopped.const stopped = await host.call('stop-room-work', { roomId: 'r1' })assert.deepEqual([stopped.ok, stopped.value], [true, true])- assert.equal(interrupted.length, 1)- assert.equal(interrupted[0].childId, 'sub-1')- assert.equal(interrupted[0].opts.parentSessionId, 'gb')+ assert.deepEqual(interrupted, [{ childId: 'sub-1', opts: { kind: 'user', parentSessionId: 'gb' } }])assert.deepEqual((await host.call('state', {})).value.work.rooms.r1, undefined)// Clear the stopped event post from r1's inbox.