A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Reconcile delegated replies missed during a plugin restart
klarkxyc903b64e3a45
diff --git a/docs/plans/2026-10-16-bot-handoffs.md b/docs/plans/2026-10-16-bot-handoffs.mdindex 97997e75..4e6f9950 100644--- a/docs/plans/2026-10-16-bot-handoffs.md+++ b/docs/plans/2026-10-16-bot-handoffs.md@@ -111,3 +111,4 @@ Bot 之间派活原来按数量拦,不看对方的状态:- 2026-10-16:定下(#262)。- 2026-10-16:Bot 的形象动画表示「在等别的 Bot」(#262)。+- 2026-10-23:DS Bot 重启时,DSH 还在跑而 DS Bot 没看见的那个回合,按会话的持久记录(DSH 的 `session/event` 记录)结算一次:回合写出了答案就把答案交给等它的 Bot(不重发原来的请求);回合停了就说停了;回合被切断就照旧把活捡起来接着做;读不出结果就明说结果未知(写明会话,不当成成功或失败,也不重发请求)。等待关系因此不会一直挂着(#483)。diff --git a/ds-bot/src/host/resume.js b/ds-bot/src/host/resume.jsindex 27e52740..01ede55e 100644--- a/ds-bot/src/host/resume.js+++ b/ds-bot/src/host/resume.js@@ -4,11 +4,18 @@// ever run either again, and whoever waited for them was not told. DS Bot notes each// running Bot turn and each message it delivers until a turn takes it up, in// inflight.json; what is still noted at the next start is picked up once.+//+// A turn that ends while DS Bot is not watching it (the plugin reloaded, DSH went on)+// is settled from the Session's durable log: an answer that was produced goes to the Bot+// that waits for it, and an outcome that cannot be read is said to be unknown. The+// request itself is never sent again there.import { randomUUID } from 'node:crypto'import { readFileSync } from 'node:fs'import { mkdir, writeFile } from 'node:fs/promises'import { join } from 'node:path'-import { SOURCE_KIND } from './constants.js'+import { HISTORY_TIMEOUT_MS, MESSAGE_INLINE_MAX, SOURCE_KIND } from './constants.js'+import { answerSender, failureLine, turnFailure } from './turns.js'+import { textOf } from './text.js'// Long enough for DSH to finish opening its workspaces after a start.export const RESUME_DELAY_MS = 3000@@ -22,6 +29,47 @@ export const resumeText = record => ['Check what is already done (files, commands, messages) before you repeat anything, then finish the task and give your reply.',].filter(Boolean).join(' ')+// The turns of a Session's durable log, each with the exchanges it took up, what it+// said and how it ended.+export function turnsOf(events) {+ const turns = []+ let current+ for (const event of events) {+ if (event.type === 'turn/start') {+ current = { turn: event.data?.turn, took: [], texts: [], reason: undefined }+ turns.push(current)+ continue+ }+ if (current === undefined) continue+ if (event.type === 'user/message') {+ const source = event.data?.source+ if (source?.exchangeId !== undefined) current.took.push(source)+ continue+ }+ if (event.type === 'assistant/message') {+ const text = textOf(event.data?.message?.content)+ if (text !== '') current.texts.push(text)+ continue+ }+ if (event.type === 'turn/end') current.reason = event.data?.reason+ }+ return turns+}++// The last turn that took up an exchange: what it said and how it ended.+export function turnOf(events, exchangeId) {+ const turns = turnsOf(events)+ for (let at = turns.length - 1; at >= 0; at -= 1) {+ if (turns[at].took.some(source => source.exchangeId === exchangeId)) return turns[at]+ }+ return undefined+}++// Whether a Session already holds the answer to an exchange.+export function answeredIn(events, exchangeId) {+ return events.some(event => event.type === 'user/message' && event.data?.source?.replyTo === exchangeId)+}+// The trigger fields a resumed turn needs to answer the same sender.const triggerOf = info => ({role: info.role,@@ -131,7 +179,9 @@ export function install(rt) {ctx.on('session/event', (session, event) => {const id = session?.idif (id === undefined) return- if ((event.type === 'turn/start' || event.type === 'turn/end') && firstTurn?.has(id) === false) firstTurn.set(id, event.type)+ if ((event.type === 'turn/start' || event.type === 'turn/end') && firstTurn?.has(id) === false) {+ firstTurn.set(id, { type: event.type, turn: event.data?.turn, reason: event.data?.reason })+ }if (event.type === 'user/message' && event.data?.source?.kind === SOURCE_KIND && event.data.source.exchangeId) {taken?.add(event.data.source.exchangeId)forgetQueued(event.data.source.exchangeId)@@ -211,6 +261,99 @@ export function install(rt) {}}+ // A Session's durable log, as DSH keeps it: what happened there, and what it said.+ // Undefined when this DSH cannot read it, or when the Session is gone.+ async function logOf(sessionId) {+ const inspect = ctx.sessionController?.inspect+ if (typeof inspect !== 'function') return undefined+ const seen = await inspect(sessionId, AbortSignal.timeout(HISTORY_TIMEOUT_MS)).catch(() => undefined)+ return Array.isArray(seen?.events) ? seen.events : undefined+ }++ // A turn that ended while DS Bot was not watching it: its answer may exist and never+ // have gone to the Bot that waits for it. The Session's durable log says what it did;+ // the work it was for is settled once, the way a finished turn settles it.+ async function reconcileEnded(sessionId, record, ended) {+ const trigger = record.trigger+ if (trigger === undefined) return+ if (trigger.role !== 'request' || trigger.audience === 'user') return+ const exchangeId = trigger.exchangeId+ const sender = trigger.senderSessionId+ if (exchangeId === undefined || sender === undefined || rt.botOf(sender) === undefined) return+ // The work it was for: gone when the answer already went up.+ const work = rt.state.works?.[exchangeId]+ if (work === undefined) return+ const name = rt.botOf(rt.selfOf(sessionId))?.name ?? 'The other Bot'+ const asker = rt.workAsker(exchangeId)+ if (asker === undefined) return+ // DSH stopped that turn as it shut down: it is picked up at the next start.+ if (ended.reason?.kind === 'aborted' && ended.reason.reason?.kind === 'disposed') {+ update(sessionId, () => record)+ return+ }+ const events = await logOf(sessionId)+ if (events === undefined) {+ // The record of that work cannot be read: whether it answered cannot be+ // established. The sender is told that, and the work is not run again.+ const why = 'the record of that work could not be read'+ const text = `${name} could not answer your message: ${why}, so what it did is unknown (its session is ${sessionId}). It may have done part of the work. Tell the user if it matters; do not run the work again without asking.`+ const room = rt.roomOf(rt.groupOwners.get(sessionId)?.roomId)+ rt.noteFailure?.({+ level: 'warn',+ source: 'turn',+ text: `the result of the work ${name} was given is unknown`,+ bot: name,+ where: room === undefined ? 'own chat' : `group "${room.name}"`,+ sessionId,+ })+ answerSender(rt, sessionId, asker, text)+ return+ }+ const turn = turnOf(events, exchangeId)+ // The request was never taken up: it is still waiting, and the delivery that is+ // waiting for it keeps what it had.+ if (turn === undefined) return+ const said = turn.texts.join('\n\n')+ // The answer went up in another run: the work closes with what it said, and+ // nothing is sent twice.+ const back = rt.roomOf(trigger.senderRoomId)?.sessions?.[sender]+ const sent = await logOf(back ?? rt.chatOf(sender))+ if (sent !== undefined && answeredIn(sent, exchangeId)) {+ rt.closeWork?.(exchangeId, name, rt.answerText(exchangeId, said, name))+ return+ }+ const reason = turn.reason+ // A turn that went on to a fresh part goes on there; it is not settled here.+ if (reason?.kind === 'blocked') return+ // The turn was cut off before it finished: the work is picked up again, as after+ // a restart that cut it off.+ if (reason === undefined || reason.kind === 'interrupted') {+ await resumeTurn(sessionId, record)+ return+ }+ if (reason.kind === 'error') {+ const failure = turnFailure(reason.error)+ answerSender(rt, sessionId, asker, `${name} could not answer your message: its model call failed (${failureLine(failure)}). Tell the user if it matters; do not retry right away.`)+ return+ }+ if (reason.kind === 'aborted') {+ // The turn was stopped before it could answer: the sender is told, as it is told+ // when DS Bot watches the turn end.+ answerSender(rt, sessionId, asker, `${name} was stopped before it could answer your message.`)+ return+ }+ // The turn ended with what it said: the answer goes up the way a finished turn's+ // does, with the results that came back for it and the text it held. A work that+ // still waits for what it handed on keeps its part until that comes back.+ if (rt.waitsWork(exchangeId)) {+ rt.holdWork(exchangeId, said)+ return+ }+ const text = rt.answerText(exchangeId, said, name)+ const long = text.length > MESSAGE_INLINE_MAX ? await rt.attachLong(text, `Answer from ${name}.txt`) : undefined+ answerSender(rt, sessionId, asker, text, long)+ }+async function resumeAll() {await rt.load()if (rt.readOnly() !== undefined) return@@ -222,7 +365,12 @@ export function install(rt) {const cut = []for (const [sessionId, record] of Object.entries(noted)) {const first = firstTurn.get(sessionId)- if (first === 'turn/end') continue+ if (first?.type === 'turn/end') {+ // The turn ended while DS Bot was not watching it: what it did is settled from+ // the Session's durable log.+ await reconcileEnded(sessionId, record, first).catch(error => rt.warn('ds-bot: settling the work of %s failed: %s', sessionId, error))+ continue+ }// Still running: noted again, as if it had started here.if (first === undefined && (await rt.resolveAgent(sessionId).catch(() => undefined))?.status === 'running') update(sessionId, () => record)else cut.push([sessionId, record])diff --git a/ds-bot/src/host/turns.js b/ds-bot/src/host/turns.jsindex a78b9637..331339fe 100644--- a/ds-bot/src/host/turns.js+++ b/ds-bot/src/host/turns.js@@ -22,6 +22,24 @@ export function turnFailure(error) {export const failureLine = failure => `${failure.code}${failure.status ? ` ${failure.status}` : ''}${failure.message ? `: ${failure.message.slice(0, 200)}` : ''}`+// The reply a sender waits for, sent the way a finished turn sends it: the work it was+// for closes, and the answer goes up to the Bot that asked. `id` is the Session the+// answer comes from; `source` is the trigger the turn answered.+export function answerSender(rt, id, source, text, long) {+ const back = rt.roomOf(source.senderRoomId)?.sessions?.[source.senderSessionId]+ const work = rt.closeWork?.(source.exchangeId, rt.botOf(rt.selfOf(id))?.name ?? 'The other Bot', text)+ void rt.deliver({+ fromId: rt.selfOf(id),+ toId: source.senderSessionId,+ ...(back ? { sessionId: back } : {}),+ text: long?.text ?? text,+ ...(long?.length === undefined ? {} : { files: long.files, length: long.length }),+ role: 'reply',+ replyTo: source.exchangeId,+ ...(work ? { work } : {}),+ }).catch(error => rt.warn('ds-bot: reply delivery failed: %s', error))+}+// A group's own Session never reaches a model, so the snapshot DSH prepared there// rides with the user's queued message to the members who answer it.export function attachReference(queued, source, text) {@@ -184,20 +202,7 @@ export function install(rt) {// reply in its Session there while it is still a member. A sender that asked for it// while working on another Bot's request goes on with that work when it reads it.// `long`: the text as attachLong sends it, when it went as a file.- const tellSender = (id, source, text, long) => {- const back = rt.roomOf(source.senderRoomId)?.sessions?.[source.senderSessionId]- const work = rt.closeWork?.(source.exchangeId, rt.botOf(rt.selfOf(id))?.name ?? 'The other Bot', text)- void rt.deliver({- fromId: rt.selfOf(id),- toId: source.senderSessionId,- ...(back ? { sessionId: back } : {}),- text: long?.text ?? text,- ...(long?.length === undefined ? {} : { files: long.files, length: long.length }),- role: 'reply',- replyTo: source.exchangeId,- ...(work ? { work } : {}),- }).catch(error => rt.warn('ds-bot: reply delivery failed: %s', error))- }+ const tellSender = (id, source, text, long) => answerSender(rt, id, source, text, long)// Runs before a deleted Bot leaves the team. Its Sessions stop with it, and the// turn/end that follows is no longer the team's, so their activity and turn records godiff --git a/ds-bot/test/follow-through.test.js b/ds-bot/test/follow-through.test.jsindex 8704795e..282547e5 100644--- a/ds-bot/test/follow-through.test.js+++ b/ds-bot/test/follow-through.test.js@@ -28,7 +28,9 @@ const seed = () => ({// Hosts by home: a home is removed only after its hosts stopped and their writes landed.const started = new Map()-async function start(home) {+// The durable logs DSH keeps, by Session: what a Session's turns did and said.+// `inspect` stands in for DSH reading that log, when a test cannot read it.+async function start(home, logs, inspect) {const ctx = fakeContext()const agents = new Map()const agentOf = (sessionId) => {@@ -43,7 +45,12 @@ async function start(home) {Object.assign(ctx, {llm: { listProviders: () => [], listModels: async () => [], resolveModelInfo: async () => ({}) },workspaceRegistry: { get: () => undefined, resolveByPath: async () => undefined, create: async path => ({ id: 'w1', path }), archiveSession: async () => {} },- sessionController: { create: async () => ({ sessionId: 's1' }), resolveAgent: async sessionId => ({ agent: agentOf(sessionId) }), selectModel: async () => {} },+ sessionController: {+ create: async () => ({ sessionId: 's1' }),+ resolveAgent: async sessionId => ({ agent: agentOf(sessionId) }),+ selectModel: async () => {},+ inspect: inspect ?? (async sessionId => ({ events: logs?.get(sessionId) ?? [] })),+ },sessionTitle: { rename: async () => {} },sessions: { flush: async () => {} },})@@ -66,9 +73,9 @@ async function start(home) {return host}-const freshHome = (t) => {+const freshHome = (t, state = seed()) => {const home = mkdtempSync(join(tmpdir(), 'ds-bot-follow-'))- writeFileSync(join(home, 'state.json'), JSON.stringify(seed()))+ writeFileSync(join(home, 'state.json'), JSON.stringify(state))t.after(async () => {await Promise.all((started.get(home) ?? []).map(host => host.stop()))started.delete(home)@@ -76,6 +83,16 @@ const freshHome = (t) => {})return home}+const stateOf = home => JSON.parse(readFileSync(join(home, 'state.json'), 'utf8'))+// The team file is written in the background, and Windows may hold it busy for a+// moment: the retry waits on the clock, which the tests mock.+const settleState = async (t, home, check) => {+ for (let at = 0; at < 100 && !check(); at += 1) {+ t.mock.timers.tick(100)+ await new Promise(resolve => setImmediate(resolve))+ }+ assert.ok(check(), 'condition not reached')+}const settle = async (check) => {const until = Date.now() + 3000while (!check() && Date.now() < until) await new Promise(resolve => setImmediate(resolve))@@ -195,6 +212,203 @@ test('when only DS Bot restarts, a turn still running or finished meanwhile is nassert.deepEqual([third.agentOf('b').calls[0].source.exchangeId, third.agentOf('a').calls.length], ['x1', 0])})+// Chief asks Writer for the plan; Writer's turn takes it up and the work waits.+const askWriter = async (host, home) => {+ await host.tool('message_bot', { to: 'Writer', message: 'Draft the plan' }, 'a')+ const request = host.agentOf('b').calls[0]+ run(host, 'b', 1, request)+ await settle(() => inflight(home).b?.trigger?.exchangeId === request.source.exchangeId)+ return request+}++// The durable log of Writer's Session: the turn that took the request up, and what it said.+const writerLog = (request, said, reason = { kind: 'completed' }) => [+ { type: 'turn/start', seq: 1, data: { turn: 1 } },+ { type: 'user/message', seq: 2, data: { source: request.source, content: request.content } },+ ...(said === undefined ? [] : [{ type: 'assistant/message', seq: 3, data: { turn: 1, message: { content: [{ type: 'text', text: said }] } } }]),+ { type: 'turn/end', seq: 4, data: { turn: 1, reason } },+]++test('an answer a turn produced while DS Bot was not watching goes to the Bot that waits for it, once', async (t) => {+ t.mock.timers.enable({ apis: ['setTimeout'] })+ const home = freshHome(t)+ const logs = new Map()+ const first = await start(home, logs)+ const request = await askWriter(first, home)+ const exchangeId = request.source.exchangeId+ // Writer answers, and DS Bot restarts before it sees the end of that turn.+ logs.set('b', writerLog(request, 'The plan is ready.'))+ await first.stop()++ const second = await start(home, logs)+ second.emit('b', 'turn/end', { turn: 1, reason: { kind: 'completed' } })+ t.mock.timers.tick(3000)+ await settle(() => second.agentOf('a').calls.length === 1)+ const reply = second.agentOf('a').calls[0]+ assert.deepEqual([reply.source.role, reply.source.replyTo], ['reply', exchangeId])+ assert.match(text(reply), /The plan is ready\./)+ // The work is settled, and the request is not run again.+ await settleState(t, home, () => stateOf(home).works?.[exchangeId] === undefined)+ assert.equal(second.agentOf('b').calls.length, 0)++ // Chief reads the answer; another restart finds nothing left to settle.+ second.emit('a', 'user/message', { content: reply.content, source: reply.source })+ await settleState(t, home, () => Object.keys(notes(home).queued ?? {}).length === 0)+ await second.stop()+ const third = await start(home, logs)+ t.mock.timers.tick(3000)+ await new Promise(resolve => setImmediate(resolve))+ assert.deepEqual([third.agentOf('a').calls.length, third.agentOf('b').calls.length], [0, 0])+})++test('a turn whose record cannot be read says the result is unknown, and is not run again', async (t) => {+ t.mock.timers.enable({ apis: ['setTimeout'] })+ const home = freshHome(t)+ const logs = new Map()+ const first = await start(home, logs)+ const request = await askWriter(first, home)+ const exchangeId = request.source.exchangeId+ logs.set('b', writerLog(request, 'The plan is ready.'))+ await first.stop()++ // DSH cannot read that Session's record: whether the turn answered cannot be+ // established, so the sender is told that, and the work is not run again.+ const unreadable = async () => { throw new Error('session not found') }+ const second = await start(home, logs, unreadable)+ second.emit('b', 'turn/end', { turn: 1, reason: { kind: 'completed' } })+ t.mock.timers.tick(3000)+ await settle(() => second.agentOf('a').calls.length === 1)+ const reply = second.agentOf('a').calls[0]+ assert.deepEqual([reply.source.role, reply.source.replyTo], ['reply', exchangeId])+ assert.match(text(reply), /what it did is unknown/)+ // The work is settled, and the request is not run again.+ await settleState(t, home, () => stateOf(home).works?.[exchangeId] === undefined)+ assert.equal(second.agentOf('b').calls.length, 0)++ // Another restart finds nothing left to settle: nothing is said or run twice.+ second.emit('a', 'user/message', { content: reply.content, source: reply.source })+ await settleState(t, home, () => Object.keys(notes(home).queued ?? {}).length === 0)+ await second.stop()+ const third = await start(home, logs)+ t.mock.timers.tick(3000)+ await new Promise(resolve => setImmediate(resolve))+ assert.deepEqual([third.agentOf('a').calls.length, third.agentOf('b').calls.length], [0, 0])+})++test('a turn that ended without saying anything says it finished', async (t) => {+ t.mock.timers.enable({ apis: ['setTimeout'] })+ const home = freshHome(t)+ const logs = new Map()+ const first = await start(home, logs)+ const request = await askWriter(first, home)+ const exchangeId = request.source.exchangeId+ logs.set('b', writerLog(request, undefined))+ await first.stop()++ const second = await start(home, logs)+ second.emit('b', 'turn/end', { turn: 1, reason: { kind: 'completed' } })+ t.mock.timers.tick(3000)+ await settle(() => second.agentOf('a').calls.length === 1)+ const reply = second.agentOf('a').calls[0]+ assert.deepEqual([reply.source.role, reply.source.replyTo], ['reply', exchangeId])+ assert.match(text(reply), /Writer finished without a reply\./)+ // The work is settled, and the request is not run again.+ await settleState(t, home, () => stateOf(home).works?.[exchangeId] === undefined)+ assert.equal(second.agentOf('b').calls.length, 0)+})++test('a turn that ended on the token limit gives what it said', async (t) => {+ t.mock.timers.enable({ apis: ['setTimeout'] })+ const home = freshHome(t)+ const logs = new Map()+ const first = await start(home, logs)+ const request = await askWriter(first, home)+ const exchangeId = request.source.exchangeId+ logs.set('b', writerLog(request, 'The plan is ready, up to the limit.', { kind: 'max-tokens' }))+ await first.stop()++ const second = await start(home, logs)+ second.emit('b', 'turn/end', { turn: 1, reason: { kind: 'max-tokens' } })+ t.mock.timers.tick(3000)+ await settle(() => second.agentOf('a').calls.length === 1)+ const reply = second.agentOf('a').calls[0]+ assert.deepEqual([reply.source.role, reply.source.replyTo], ['reply', exchangeId])+ assert.match(text(reply), /The plan is ready, up to the limit\./)+ // The work is settled, and the request is not run again.+ await settleState(t, home, () => stateOf(home).works?.[exchangeId] === undefined)+ assert.equal(second.agentOf('b').calls.length, 0)+})++test('the answer that goes up keeps what came back for the work', async (t) => {+ t.mock.timers.enable({ apis: ['setTimeout'] })+ const state = seed()+ // Writer handed the plan on; what came back for it is kept with the work.+ state.works = { x1: { from: 'a', to: 'b', open: [], results: [{ id: 'y1', name: 'Reviewer', text: 'The numbers check out.' }], at: 1 } }+ const home = freshHome(t, state)+ const logs = new Map()+ const first = await start(home, logs)+ const request = { content: [{ type: 'text', text: '[Message from Chief]\nDraft the plan' }], source: { kind: 'bot', form: 'relay', role: 'request', exchangeId: 'x1', senderName: 'Chief', senderSessionId: 'a', hop: 0 } }+ run(first, 'b', 1, request)+ await settle(() => inflight(home).b?.trigger?.exchangeId === 'x1')+ logs.set('b', writerLog(request, 'The plan is ready.'))+ await first.stop()++ const second = await start(home, logs)+ second.emit('b', 'turn/end', { turn: 1, reason: { kind: 'completed' } })+ t.mock.timers.tick(3000)+ await settle(() => second.agentOf('a').calls.length === 1)+ const reply = text(second.agentOf('a').calls[0])+ assert.match(reply, /The plan is ready\./)+ assert.match(reply, /Reviewer:\nThe numbers check out\./)+ // The work is settled, and the request is not run again.+ await settleState(t, home, () => stateOf(home).works?.x1 === undefined)+ assert.equal(second.agentOf('b').calls.length, 0)+})++test('an answer that already went up is not sent again', async (t) => {+ t.mock.timers.enable({ apis: ['setTimeout'] })+ const home = freshHome(t)+ const logs = new Map()+ const first = await start(home, logs)+ const request = await askWriter(first, home)+ const exchangeId = request.source.exchangeId+ logs.set('b', writerLog(request, 'The plan is ready.'))+ // Chief already has the answer: another run delivered it.+ logs.set('a', [{ type: 'user/message', seq: 1, data: { source: { kind: 'bot', role: 'reply', replyTo: exchangeId, senderSessionId: 'b' }, content: [{ type: 'text', text: '[Reply from Writer]\nThe plan is ready.' }] } }])+ await first.stop()++ const second = await start(home, logs)+ second.emit('b', 'turn/end', { turn: 1, reason: { kind: 'completed' } })+ t.mock.timers.tick(3000)+ await settleState(t, home, () => stateOf(home).works?.[exchangeId] === undefined)+ assert.deepEqual([second.agentOf('a').calls.length, second.agentOf('b').calls.length], [0, 0])+})++test('a work that still waits for what it handed on holds its text, and is not settled', async (t) => {+ t.mock.timers.enable({ apis: ['setTimeout'] })+ const state = seed()+ state.works = { x1: { from: 'a', to: 'b', open: ['y1'], results: [], at: 1 } }+ const home = freshHome(t, state)+ const logs = new Map()+ const first = await start(home, logs)+ const request = { content: [{ type: 'text', text: '[Message from Chief]\nDraft the plan' }], source: { kind: 'bot', form: 'relay', role: 'request', exchangeId: 'x1', senderName: 'Chief', senderSessionId: 'a', hop: 0 } }+ run(first, 'b', 1, request)+ await settle(() => inflight(home).b?.trigger?.exchangeId === 'x1')+ logs.set('b', writerLog(request, 'The plan is ready.'))+ await first.stop()++ const second = await start(home, logs)+ second.emit('b', 'turn/end', { turn: 1, reason: { kind: 'completed' } })+ t.mock.timers.tick(3000)+ await new Promise(resolve => setImmediate(resolve))+ // The work waits for what Writer handed on: nothing is sent, and it stays open.+ assert.deepEqual([second.agentOf('a').calls.length, second.agentOf('b').calls.length], [0, 0])+ // What the turn said is held for it, until what it handed on comes back.+ await settleState(t, home, () => stateOf(home).works.x1.held !== undefined)+ assert.equal(stateOf(home).works.x1.held, 'The plan is ready.')+ assert.deepEqual(stateOf(home).works.x1.open, ['y1'])+})+test('a finished turn leaves nothing to pick up', async (t) => {t.mock.timers.enable({ apis: ['setTimeout'] })const home = freshHome(t)