Skip to content

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

Keep missed group lines unread

klarkxya11964f17626
diff --git a/ds-bot/src/host/groups.js b/ds-bot/src/host/groups.js
index 223913d8..4827a4fd 100644
--- a/ds-bot/src/host/groups.js
+++ b/ds-bot/src/host/groups.js
@@ -298,7 +298,9 @@ export function install(rt) {
const turn = { botId: member.id, sessionId, exchangeId }
const { started } = round
started.push(turn)
- room.seen[member.id] = room.seq
+ // The read position is the one of this turn's start, and moves only when the
+ // delivery lands: a delivery that failed leaves the member where it was.
+ const seenAt = room.seq
// Checked before the delivery, which may start the turn at once.
const busy = rt.live.get(sessionId)?.turn !== undefined
const done = new Promise((resolve) => {
@@ -327,6 +329,8 @@ export function install(rt) {
})
try {
await rt.deliver({ fromId: undefined, toId: member.id, sessionId, role: 'room', roomId: room.id, exchangeId, note, text, files, ...(by ? { askedBy: by } : {}) })
+ // The prompt reached the member: its read position moves on.
+ room.seen[member.id] = seenAt
// 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.
diff --git a/ds-bot/test/group-work.test.js b/ds-bot/test/group-work.test.js
index eea9c588..b20da70a 100644
--- a/ds-bot/test/group-work.test.js
+++ b/ds-bot/test/group-work.test.js
@@ -105,7 +105,7 @@ async function start(t, room, services, extraRooms) {
return { content: post.content, source: post.source }
}
await tool('list_bots', {}, 'a')
- return { home, agentOf, emit, tool, call, begin, finish, round, say, takePost }
+ return { home, ctx, agentOf, emit, tool, call, begin, finish, round, say, takePost }
}
const settle = async (check) => {
@@ -741,6 +741,46 @@ test('members still at work show in the team view and in the prompts of the othe
await settle(() => result() !== undefined)
})
+// #510: the member's read position moved before the delivery, so a delivery that
+// failed left the member past the round it missed, and that round never reached it.
+test('a member whose delivery failed sees the round it missed in its next prompt', async (t) => {
+ const host = await start(t)
+ // The delivery to Writer fails once; the Session is there, the message did not land.
+ let failed = false
+ host.ctx.sessions.flush = async (session) => {
+ if (session?.id === 'gb' && !failed) {
+ failed = true
+ throw new Error('the session log could not be written')
+ }
+ }
+ const first = host.round('c1', host.say('@Chief 安排一下文档'))
+ await settle(() => host.agentOf('ga').calls.length === 1)
+ host.begin('ga')
+ host.finish('ga', '@Writer 把文档整理好')
+ await settle(() => first() !== undefined)
+ assert.deepEqual(kinds(first()), [['message', 'Chief'], ['failed', 'Writer']])
+ // The failed delivery leaves the member where it was: it has read nothing yet.
+ assert.equal(JSON.parse(readFileSync(join(host.home, 'state.json'), 'utf8')).rooms.r1.seen.b, undefined)
+
+ // Its next prompt carries the round it missed.
+ const second = host.round('c2', host.say('@Writer 继续'))
+ await settle(() => host.agentOf('gb').calls.length === 2)
+ const prompt = text(host.agentOf('gb').calls[1])
+ assert.match(prompt, /User: @Chief 安排一下文档/)
+ assert.match(prompt, /Chief: @Writer 把文档整理好/)
+ assert.match(prompt, /User: @Writer 继续/)
+
+ // The delivery that lands moves the position on, so those lines are not shown again.
+ host.begin('gb')
+ host.finish('gb', '整理好了。')
+ await settle(() => second() !== undefined)
+ host.round('c3', host.say('@Writer 还有别的吗'))
+ await settle(() => host.agentOf('gb').calls.length === 3)
+ const later = text(host.agentOf('gb').calls[2])
+ assert.doesNotMatch(later, /@Chief 安排一下文档/)
+ assert.doesNotMatch(later, /@Writer 继续/)
+})
+
// A step that says something and calls a tool, as a model writes it while it works.
const step = (host, sessionId, said, callId, name = 'pwsh', args = '{}') => {
host.emit(sessionId, 'assistant/message', { message: { content: [{ type: 'text', text: said }, { type: 'tool-call', id: callId, name }] } })