A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Show a failed group delivery and replace a group Session that cannot open
Fei2411933f75598cdb
diff --git a/ds-bot/client.js b/ds-bot/client.jsindex 9b5e894a..278e7433 100644--- a/ds-bot/client.js+++ b/ds-bot/client.js@@ -810,6 +810,7 @@ var ZH = {"The model took too long to answer": "模型响应超时","Could not reach the model service": "连不上模型服务","Its group conversation could not open": "它的群聊会话打不开",+ "Its group conversation could not open, so it starts a new one next time": "它的群聊会话打不开,下次会换一个新的",// The composer's +"Add files": "添加文件","Reference a chat": "引用对话",@@ -1041,7 +1042,8 @@ var FAILURES = {SERVER: "The model service failed",TIMEOUT: "The model took too long to answer",TRANSPORT: "Could not reach the model service",- SESSION: "Its group conversation could not open"+ SESSION: "Its group conversation could not open",+ SESSION_RESET: "Its group conversation could not open, so it starts a new one next time"};function failureLabel(code, message) {if (FAILURES[code]) return t(FAILURES[code]);diff --git a/ds-bot/src/client/diagnostics.js b/ds-bot/src/client/diagnostics.jsindex ae38c4dc..31258896 100644--- a/ds-bot/src/client/diagnostics.js+++ b/ds-bot/src/client/diagnostics.js@@ -59,6 +59,7 @@ const FAILURES = {TIMEOUT: 'The model took too long to answer',TRANSPORT: 'Could not reach the model service',SESSION: 'Its group conversation could not open',+ SESSION_RESET: 'Its group conversation could not open, so it starts a new one next time',}export function failureLabel(code, message) {diff --git a/ds-bot/src/client/i18n.js b/ds-bot/src/client/i18n.jsindex 83b39980..97e1d1e2 100644--- a/ds-bot/src/client/i18n.js+++ b/ds-bot/src/client/i18n.js@@ -760,6 +760,7 @@ const ZH = {'The model took too long to answer': '模型响应超时','Could not reach the model service': '连不上模型服务','Its group conversation could not open': '它的群聊会话打不开',+ 'Its group conversation could not open, so it starts a new one next time': '它的群聊会话打不开,下次会换一个新的',// The composer's +'Add files': '添加文件','Reference a chat': '引用对话',diff --git a/ds-bot/src/host/delivery.js b/ds-bot/src/host/delivery.jsindex 5b20edcb..b547c688 100644--- a/ds-bot/src/host/delivery.js+++ b/ds-bot/src/host/delivery.js@@ -8,7 +8,7 @@ export function install(rt) {const resolveAgent = async (sessionId) => {const resolved = await ctx.sessionController.resolveAgent(sessionId)- if ('error' in resolved) throw new Error(resolved.error?.message ?? 'Session unavailable')+ if ('error' in resolved) throw Object.assign(new Error(resolved.error?.message ?? 'Session unavailable'), { code: resolved.error?.code })rt.hideBotUnusedTools(resolved.agent)return resolved.agent}diff --git a/ds-bot/src/host/groups.js b/ds-bot/src/host/groups.jsindex 9f636fd5..b23ebb82 100644--- a/ds-bot/src/host/groups.js+++ b/ds-bot/src/host/groups.js@@ -111,6 +111,10 @@ const roomKickoff = language => `The user just created this group and has not wrconst ROOM_READ_MAX = 30+// DSH cannot open the Session at all: it is gone, or its stored log is corrupt. DSH+// reports a corrupt log only in the message of a generic failure.+const lostSession = error => error?.code === 'session/not-found' || /\bis corrupt\b|\bcorrupt session log\b/i.test(String(error?.message ?? ''))+export function install(rt) {const { ctx } = rt@@ -237,7 +241,14 @@ export function install(rt) {else if (busy) rt.roomWaiters.get(exchangeId)?.resolve({ working: true })} catch (error) {rt.warn('ds-bot: group delivery to %s failed: %s', member.name, error)- rt.roomWaiters.get(exchangeId)?.resolve(null)+ // A delivery that failed is not a pass: the round shows it. Nothing here can+ // repair a lost Session, so the member's next turn in the group starts a new one.+ const lost = lostSession(error)+ if (lost && room.sessions?.[member.id] === sessionId) {+ rt.retireGroupSession(room, member.id)+ void rt.save().catch(() => {})+ }+ rt.roomWaiters.get(exchangeId)?.fail({ code: lost ? 'SESSION_RESET' : 'SESSION', message: String(error?.message ?? error).slice(0, 300) })}const reply = await done// A turn that ended leaves nothing for a stop to cancel.diff --git a/ds-bot/src/host/store.js b/ds-bot/src/host/store.jsindex 580ce7ab..6b27fa8f 100644--- a/ds-bot/src/host/store.js+++ b/ds-bot/src/host/store.js@@ -333,6 +333,16 @@ export function install(rt) {// that no longer has it.void ctx.workspaceRegistry.archiveSession(sessionId, { stopActivity: true }).catch(() => {})}+ // A group Session DSH can no longer open is set aside; the member's earlier parts in+ // the group stay, and its next turn there starts a new Session.+ const retireGroupSession = (room, botId) => {+ const sessionId = room.sessions?.[botId]+ if (sessionId === undefined) return+ delete room.sessions[botId]+ groupOwners.delete(sessionId)+ rt.cancelApprovals?.(sessionId)+ void ctx.workspaceRegistry.archiveSession(sessionId, { stopActivity: true }).catch(() => {})+ }const findBot = (ref) => {if (ref === undefined) return undefinedif (state.bots[ref]) return state.bots[ref]@@ -352,6 +362,6 @@ export function install(rt) {state, load, save, refresh, readOnly,botOf, roomOf, isMain, chatOf, selfOf, isBotSession,chatOwners, groupOwners, pastOwners,- groupSessionsOf, dropGroupSession, findBot, findRooms, isAdminOf,+ groupSessionsOf, dropGroupSession, retireGroupSession, findBot, findRooms, isAdminOf,})}diff --git a/ds-bot/test/rounds.test.js b/ds-bot/test/rounds.test.jsindex 495826dc..a2099e9d 100644--- a/ds-bot/test/rounds.test.js+++ b/ds-bot/test/rounds.test.js@@ -347,3 +347,79 @@ test('a message sent between rounds still opens a full round', async (t) => {const result = JSON.parse(await running)assert.deepEqual(result.replies.map(reply => reply.name ?? 'User'), ['Chief', 'Writer'])})++// 公开#163: a member's group Session whose stored log is corrupt could not be resumed;+// the round counted the member as passed, showed nothing, and tried the same Session+// again every round.+test('a member whose group Session cannot be opened shows a failure, and its next turn there starts a new Session', async (t) => {+ const { call, emit, userMessage, relay, answer, stop, sent, ctx, rt } = start()+ t.after(stop)+ const room = await team(call, sent)+ const chief = (await call('state', {})).value.mainBotId++ await emit(room.id, userMessage('Report in'))+ let running = relay(room.id, 'r1')+ const first = await turnFor(sent)+ await answer(first.sessionId, first.message.source.exchangeId, 'Chief here.', 1)+ const second = await turnFor(sent, first)+ await answer(second.sessionId, second.message.source.exchangeId, 'Writer here.', 2)+ await running+ const broken = rt.roomOf(room.id).sessions[chief]+ assert.equal(first.sessionId, broken)++ const resolve = ctx.sessionController.resolveAgent+ ctx.sessionController.resolveAgent = async sessionId => (sessionId === broken+ ? { error: { code: 'gateway/internal', message: `resume failed for session "${sessionId}": SessionQueryError: stored session "${sessionId}" is corrupt: released v2 row has seq gap (expected 20, got 16)` } }+ : resolve(sessionId))+ t.mock.method(rt, 'warn', () => {})+ sent.length = 0+ await emit(room.id, userMessage('Again'))+ running = relay(room.id, 'r2')+ const writerTurn = await turnFor(sent)+ assert.equal(writerTurn.sessionId, second.sessionId)+ await answer(writerTurn.sessionId, writerTurn.message.source.exchangeId, 'Still here.', 3)+ const result = JSON.parse(await running)+ const failed = result.replies.filter(reply => reply.kind === 'failed')+ assert.deepEqual(failed.map(reply => [reply.name, reply.code]), [['Chief', 'SESSION_RESET']])+ assert.equal(result.passed.includes('Chief'), false)+ assert.equal(rt.roomOf(room.id).sessions[chief], undefined)++ sent.length = 0+ await emit(room.id, userMessage('Once more'))+ running = relay(room.id, 'r3')+ const fresh = await turnFor(sent)+ assert.notEqual(fresh.sessionId, broken)+ assert.equal(rt.roomOf(room.id).sessions[chief], fresh.sessionId)+ await answer(fresh.sessionId, fresh.message.source.exchangeId, 'Back.', 1)+ const again = await turnFor(sent, fresh)+ await answer(again.sessionId, again.message.source.exchangeId, 'Here.', 4)+ assert.deepEqual(JSON.parse(await running).replies.map(reply => reply.name ?? 'User'), ['Chief', 'Writer'])+})++test('a delivery that fails for another reason shows a failure and keeps the Session', async (t) => {+ const { call, emit, userMessage, relay, answer, stop, sent, ctx, rt } = start()+ t.after(stop)+ const room = await team(call, sent)+ const chief = (await call('state', {})).value.mainBotId+ await emit(room.id, userMessage('Report in'))+ let running = relay(room.id, 'r1')+ const first = await turnFor(sent)+ await answer(first.sessionId, first.message.source.exchangeId, 'Chief here.', 1)+ const second = await turnFor(sent, first)+ await answer(second.sessionId, second.message.source.exchangeId, 'Writer here.', 2)+ await running++ const resolve = ctx.sessionController.resolveAgent+ ctx.sessionController.resolveAgent = async sessionId => (sessionId === first.sessionId+ ? { error: { code: 'session/writer-held', message: 'another process holds this Session' } }+ : resolve(sessionId))+ t.mock.method(rt, 'warn', () => {})+ sent.length = 0+ await emit(room.id, userMessage('Again'))+ running = relay(room.id, 'r2')+ const writerTurn = await turnFor(sent)+ await answer(writerTurn.sessionId, writerTurn.message.source.exchangeId, 'Still here.', 3)+ const result = JSON.parse(await running)+ assert.deepEqual(result.replies.filter(reply => reply.kind === 'failed').map(reply => [reply.name, reply.code]), [['Chief', 'SESSION']])+ assert.equal(rt.roomOf(room.id).sessions[chief], first.sessionId)+})