A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Scope the steer-cut switch guard and drop the interrupted draft on recovery
Fei24115254b2b7b233
diff --git a/ds-bot/src/host/resume.js b/ds-bot/src/host/resume.jsindex 80c153ba..ce2d3246 100644--- a/ds-bot/src/host/resume.js+++ b/ds-bot/src/host/resume.js@@ -41,6 +41,10 @@ export function turnsOf(events) {continue}if (current === undefined) continue+ if (event.type === 'step/start') {+ current.stepFrom = current.texts.length+ continue+ }if (event.type === 'user/message') {const source = event.data?.sourceif (source?.exchangeId !== undefined) current.took.push(source)@@ -68,12 +72,17 @@ export function turnOf(events, exchangeId) {if (!turns[at].took.some(source => source.exchangeId === exchangeId)) continuelet found = turns[at]let next = at + 1+ // A steer cut lands inside a step's model call, so the cut turn's last step left+ // an interrupted draft: texts before the last step/start stay, the rest is a+ // fragment the continuation replaces.+ const finished = turn => turn.texts.slice(0, turn.stepFrom ?? turn.texts.length)while (steerCut(found) && next < turns.length) {const follow = turns[next]- found = { ...follow, took: [...found.took, ...follow.took], texts: [...found.texts, ...follow.texts] }+ const kept = finished(found)+ found = { ...follow, took: [...found.took, ...follow.took], texts: [...kept, ...follow.texts], stepFrom: kept.length + (follow.stepFrom ?? follow.texts.length) }next += 1}- return steerCut(found) ? { ...found, reason: undefined } : found+ return steerCut(found) ? { ...found, texts: finished(found), reason: undefined } : found}return undefined}diff --git a/ds-bot/src/host/steer.js b/ds-bot/src/host/steer.jsindex 17d75d41..31668e98 100644--- a/ds-bot/src/host/steer.js+++ b/ds-bot/src/host/steer.js@@ -42,7 +42,7 @@ export function install(rt) {const entry = rt.live.get(id)const agent = liveAgent(id)if (!privateOf(id) || rt.readOnly?.() !== undefined || entry === undefined || agent === undefined) return- if ([...(rt.switchJobs?.() ?? [])].some(job => job?.botId === rt.chatOwners.get(id))) return+ if ([...(rt.switchJobs?.() ?? [])].some(job => job?.botId === rt.chatOwners.get(id) && job.roomId === undefined)) returnconst track = stateOf(id)if (track.phase !== 'model' || track.cutting) returnif (entry.turn === undefined || (entry.calls?.size ?? 0) > 0 || agent.status !== 'running') returndiff --git a/ds-bot/test/steer.test.js b/ds-bot/test/steer.test.jsindex c59bf6de..8142a554 100644--- a/ds-bot/test/steer.test.js+++ b/ds-bot/test/steer.test.js@@ -421,6 +421,10 @@ test('steer cut: a running part switch blocks the cut', async () => {agent.inbox.nextStep.push(steer)await emit(dm, 'agent/inbox/spliced', { target: 'next-step', inserted: [steer] })assert.equal(calls.find(c => c[0] === 'cancel'), undefined)+ // A group part switch of the same Bot carries a roomId and must not block this cut.+ rt.switchJobs = () => new Map([['job', { botId: rt.chatOwners.get(dm), roomId: 'r1' }]]).values()+ await emit(dm, 'agent/inbox/spliced', { target: 'next-step', inserted: [steer] })+ assert.deepEqual(calls.find(c => c[0] === 'cancel')?.[1], { kind: 'hook', reason: STEER_CUT })rt.switchJobs = originalawait stop()})@@ -480,9 +484,10 @@ test('steer resume: turnOf follows a steer cut to its continuation', async () =>const ended = reason => ({ type: 'turn/end', data: { reason } })const cut = { kind: 'aborted', reason: { kind: 'hook', reason: STEER_CUT } }- // A cut turn whose continuation answered: the continuation's reason and the texts merged.+ // A cut turn whose continuation answered: the continuation's reason and the texts+ // merged, with the cut step's interrupted draft dropped.const follow = turnOf([- ...turn(1, [took('x1'), said('a'), ended(cut)]),+ ...turn(1, [took('x1'), said('a'), { type: 'step/start', data: { turn: 1, step: 2 } }, said('p'), ended(cut)]),...turn(2, [said('b'), ended({ kind: 'completed' })]),], 'x1')assert.deepEqual(follow?.reason, { kind: 'completed' })