A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Keep member calls queued; drain steered posts in the running round
Fei2411f37d712010dd
diff --git a/ds-bot/src/host/groups.js b/ds-bot/src/host/groups.jsindex ab6a44cb..6f8f5307 100644--- a/ds-bot/src/host/groups.js+++ b/ds-bot/src/host/groups.js@@ -326,10 +326,7 @@ export function install(rt) {signal.addEventListener('abort', () => finish(null), { once: true })})try {- // A member mid-turn would only read a queued post after that work: steer the- // call in, so a correction reaches it at the turn's next step instead of- // landing in its inbox once the crossing has already deepened.- await rt.deliver({ fromId: undefined, toId: member.id, sessionId, role: 'room', roomId: room.id, exchangeId, note, text, files, steer: busy, ...(by ? { askedBy: by } : {}) })+ await rt.deliver({ fromId: undefined, toId: member.id, sessionId, role: 'room', roomId: room.id, exchangeId, note, text, files, ...(by ? { askedBy: by } : {}) })// Still held by an earlier request: this turn cannot start until the user answers.if (rt.waitsForApproval?.(sessionId)) rt.roomWaiters.get(exchangeId)?.approval()// Still at earlier work: the call waits in its inbox and is answered after that.@@ -450,12 +447,29 @@ export function install(rt) {void rt.save().catch(() => {})}+ // A member's post steered into the group Session's running turn lands in the+ // room inbox mid-round: the relay took its snapshot at entry, so the post picks+ // its speakers here, in the round it corrected, instead of losing its relay.+ function drainRoomPosts(room, round, index) {+ const queued = rt.roomInbox.get(room.id) ?? []+ const posts = queued.filter(post => post.botId !== undefined)+ if (posts.length === 0) return+ rt.roomInbox.set(room.id, queued.filter(post => post.botId === undefined))+ for (const post of posts) {+ // The post wrote itself into the log already; it still needs its speakers and,+ // when it asked for one, its report at the end of the round it joined.+ callMembers(round, index - 1, openingSpeakers(room, post), `${post.name ?? 'a member'} posted to the group`, post.botId, 'bot')+ if (post.reportBack === true) (round.postBacks ??= []).push(post)+ }+ }+async function runRound(room, round, signal, agent) {// The inbox check keeps a message sent during the last speaker's turn inside// this round: it drains at the loop's head even once the slots ran out.- for (let index = 0; index < round.slots.length || waitingLines(agent).length > 0; index += 1) {+ for (let index = 0; index < round.slots.length || waitingLines(agent).length > 0 || (rt.roomInbox.get(room.id) ?? []).length > 0; index += 1) {if (signal.aborted) breakdrainRoomInbox(room, round, index, agent)+ drainRoomPosts(room, round, index)if (index >= round.slots.length) breakconst slot = round.slots[index]const member = rt.botOf(slot.id)diff --git a/ds-bot/test/group-work.test.js b/ds-bot/test/group-work.test.jsindex 334e710b..5550d5b8 100644--- a/ds-bot/test/group-work.test.js+++ b/ds-bot/test/group-work.test.js@@ -431,19 +431,21 @@ const busyRound = async (t, room, services) => {return { host, first }}-test('a group call into a busy member steers it, and a post into a busy group steers', async (t) => {+test('a post steered into a busy group Session picks its speakers inside the running round', async (t) => {const { host, first } = await busyRound(t)- await host.tool('post_to_group', { group: 'Ops', message: '@Writer 看一下文档' }, 'a')+ await host.tool('post_to_group', { group: 'Ops', message: '@Tester 看一下文档' }, 'a')const post = host.takePost()- // Writer (gb) is mid-turn: the call cuts in at its next step rather than queueing- // for a turn of its own after the work.- const second = host.round('c2', post)- await settle(() => host.agentOf('gb').calls.length === 2)- assert.equal(host.agentOf('gb').kinds.at(-1), 'steer')+ // The steered post lands as a user/message inside the running turn: it queues+ // into the room inbox, and the running round drains it for its speakers.+ host.emit('r1', 'user/message', post)host.finish('gb', '整理好了。')- await settle(() => first() !== undefined && second() !== undefined)+ await settle(() => host.agentOf('gc').calls.length === 1)+ assert.equal(host.begin('gc').source.askedBy, 'a')+ host.finish('gc', '看过了。')+ await settle(() => first() !== undefined)+ assert.ok(first().replies.some(reply => reply.botId === 'c'))- // A busy group Session hears a member's post at its next step the same way.+ // The group Session itself hears the post at its next step while it works.host.emit('r1', 'turn/start', { turn: 9 })await host.tool('post_to_group', { group: 'Ops', message: '暂停一下' }, 'a')assert.equal(host.agentOf('r1').kinds.at(-1), 'steer')