Skip to content

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

Steer group posts into running turns

Fei2411cc2f0f46f7f5
diff --git a/ds-bot/src/host/groups.js b/ds-bot/src/host/groups.js
index 223913d8..ab6a44cb 100644
--- a/ds-bot/src/host/groups.js
+++ b/ds-bot/src/host/groups.js
@@ -326,7 +326,10 @@ export function install(rt) {
signal.addEventListener('abort', () => finish(null), { once: true })
})
try {
- await rt.deliver({ fromId: undefined, toId: member.id, sessionId, role: 'room', roomId: room.id, exchangeId, note, text, files, ...(by ? { askedBy: by } : {}) })
+ // 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 } : {}) })
// 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.
@@ -793,7 +796,10 @@ export function install(rt) {
await rt.save()
}
const agent = await rt.resolveAgent(room.id)
- agent.followup(createUserMessage({
+ // Same rule as a member turn: a group Session at work hears a post at its next
+ // step, not after it — otherwise corrections only queue while it keeps going.
+ const post = rt.live.get(room.id)?.turn !== undefined ? 'steer' : 'followup'
+ agent[post](createUserMessage({
content: [{ type: 'text', text: `[Group post from ${sender.name}]\n${text}` }, ...files.map(attachment => ({ type: 'file', attachment }))],
source: { kind: SOURCE_KIND, form: 'relay', role: 'post', exchangeId: randomUUID(), senderName: sender.name, senderSessionId: sender.id, roomId: room.id, ...extra, ...(logged !== undefined ? { logged } : {}) },
}))
diff --git a/ds-bot/test/group-work.test.js b/ds-bot/test/group-work.test.js
index eea9c588..334e710b 100644
--- a/ds-bot/test/group-work.test.js
+++ b/ds-bot/test/group-work.test.js
@@ -45,8 +45,9 @@ async function start(t, room, services, extraRooms) {
return true
},
}
- const keep = (message) => { calls.push(message); held.push(message) }
- agents.set(sessionId, { session: { id: sessionId }, calls, cancelled, inbox, followup: keep, steer: keep, cancel(reason) { cancelled.push(reason) } })
+ const kinds = []
+ const keep = kind => (message) => { calls.push(message); held.push(message); kinds.push(kind) }
+ agents.set(sessionId, { session: { id: sessionId }, calls, cancelled, inbox, kinds, followup: keep('followup'), steer: keep('steer'), cancel(reason) { cancelled.push(reason) } })
}
return agents.get(sessionId)
}
@@ -430,6 +431,24 @@ 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) => {
+ const { host, first } = await busyRound(t)
+ await host.tool('post_to_group', { group: 'Ops', message: '@Writer 看一下文档' }, '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')
+ host.finish('gb', '整理好了。')
+ await settle(() => first() !== undefined && second() !== undefined)
+
+ // A busy group Session hears a member's post at its next step the same way.
+ 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')
+})
+
test('a post during a running round is in the log at once, once, and shows in the round', async (t) => {
const { host, first } = await busyRound(t)
await host.tool('post_to_group', { group: 'Ops', message: '@Tester 看一下文档' }, 'a')