A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Merge remote-tracking branch 'origin/dev' into fix/571-archive-stop-activity
Fei2411cd764631b2b9
diff --cc ds-bot/src/host/schedules.jsindex d8ee9613,74b21318..62482fa7--- a/ds-bot/src/host/schedules.js+++ b/ds-bot/src/host/schedules.js@@@ -157,18 -150,20 +169,30 @@@ export function install(rt)for (const record of records) {const request = requestOf(record)if (request === null || (request.at !== undefined && Date.parse(request.at) <= Date.now())) continue+ let createdtry {- created = await service.create(toId, request)+ const key = keyOfRequest(request)+ const nth = (seen.get(key) ?? 0) + 1+ seen.set(key, nth)+ if (nth > (have.get(key) ?? 0)) {- await service.create(toId, request)++ created = await service.create(toId, request)+ have.set(key, (have.get(key) ?? 0) + 1)+ }- await service.delete({ sessionId: fromId, id: record.id })} catch (error) {rt.warn('ds-bot: task %s stayed with the earlier part: %s', record.title, error?.message ?? error)+ continue+ }+ const old = await remove(fromId, record.id)+ if (old.removed) continue+ // The earlier part still holds the task, so the fresh copy has to go: two armed- // copies of one task would fire twice.++ // copies of one task would fire twice. A satisfied copy is not ours to remove.++ if (created === undefined) {++ rt.warn('ds-bot: task %s stayed with the earlier part: %s', record.title, old.reason)++ continue+ }+ const fresh = await remove(toId, created.id)+ if (fresh.removed) rt.warn('ds-bot: task %s stayed with the earlier part: %s', record.title, old.reason)+ else rt.warn('ds-bot: task %s left in two parts: %s', record.title, fresh.reason)}}diff --cc ds-bot/test/schedules.test.jsindex a6eaf6aa,d2efe3e3..3324aa58--- a/ds-bot/test/schedules.test.js+++ b/ds-bot/test/schedules.test.js@@@ -29,18 -40,7 +40,8 @@@ function scheduleService({ broken = {}tasks,async create(sessionId, request) {const id = `schedule-${next++}`- const kind = { every_seconds: 'every' }[Object.keys(request).find(key => !['title', 'prompt'].includes(key))]- ?? Object.keys(request).find(key => !['title', 'prompt'].includes(key))- const record = {- id, kind, title: request.title, prompt: request.prompt,- timing: request[Object.keys(request).find(key => !['title', 'prompt'].includes(key))],- scheduledAt: request.at ?? '2030-01-01T01:00:00.000Z',- everySeconds: request.every_seconds,- time: request.daily?.time ?? request.weekly?.time,- timeZone: request.daily?.time_zone ?? request.weekly?.time_zone ?? request.cron?.time_zone,- weekdays: request.weekly?.weekdays,- expression: request.cron?.expression,- }+++ const record = stored(id, request)tasks.set(id, { sessionId, record })return record},@@@ -62,7 -65,7 +66,8 @@@ function setup(services = {})ctx.connection.fetch.register = (route) => { ctx.route = route; return register(route) }const rt = createRuntime(ctx, { home })const call = async (endpoint, payload) => (await ctx.route.fetch(new Request('http://localhost/api/bot', { method: 'POST', body: JSON.stringify({ endpoint, payload }) }))).json()- return { ctx, home, call, rt }+++ return { ctx, home, rt, call }}test('without the schedule service the page says so and creating is refused', async (t) => {@@@ -132,24 -135,59 +137,82 @@@ test('a due reminder reaches a group aassert.equal(reminderText('plain text'), 'plain text')})+++// #571: a restart pass re-runs the task move; a crash between create and delete must+// not leave a second copy of a recurring task on the fresh part.+test('a repeated task move copies each task only once', async (t) => {+ const schedule = scheduleService()+ const { ctx, home, rt } = setup({ schedule })+ t.after(async () => { await ctx.dispose(); rmSync(home, { recursive: true, force: true, maxRetries: 5 }) })+ await schedule.create('w2', { title: 'Ping', prompt: 'Check', every_seconds: 3600 })+ await schedule.create('w2', { title: 'Ping', prompt: 'Check', every_seconds: 3600 })++ const remove = schedule.delete+ schedule.delete = async () => { throw new Error('down') }+ await rt.moveSchedules('w2', 's9')+ const on = id => [...schedule.tasks.values()].filter(task => task.sessionId === id)+ assert.equal(on('s9').length, 2)+ assert.equal(on('w2').length, 2)++ schedule.delete = remove+ await rt.moveSchedules('w2', 's9')+ assert.equal(on('s9').length, 2)+ assert.equal(on('w2').length, 0)+})+++ // #511: a Bot's chat moves on to a fresh part, and its task moves with it. The+ // earlier part of a Bot's chat is 'w1' and the fresh one is 'w2'.+ async function moveSetup(broken = {}) {+ const schedule = scheduleService({ broken })+ const { ctx, home, rt } = setup({ schedule })+ await schedule.create('w1', { title: 'Standup', prompt: 'Where are we?', every_seconds: 3600 })+ const warnings = []+ rt.warn = (...args) => warnings.push(args)+ return { schedule, ctx, home, rt, warnings }+ }++ test('a task that moves goes to the fresh part alone', async (t) => {+ const { schedule, ctx, home, rt, warnings } = await moveSetup()+ t.after(async () => { await ctx.dispose(); rmSync(home, { recursive: true, force: true, maxRetries: 5 }) })+ await rt.moveSchedules('w1', 'w2')+ const armed = [...schedule.tasks.values()]+ assert.equal(armed.length, 1, JSON.stringify(armed))+ assert.equal(armed[0].sessionId, 'w2')+ assert.equal(armed[0].record.title, 'Standup')+ assert.deepEqual(warnings, [])+ })++ test('a task whose removal fails stays with the earlier part alone', async (t) => {+ const { schedule, ctx, home, rt, warnings } = await moveSetup({ w1: 'throw' })+ t.after(async () => { await ctx.dispose(); rmSync(home, { recursive: true, force: true, maxRetries: 5 }) })+ await rt.moveSchedules('w1', 'w2')+ const armed = [...schedule.tasks.values()]+ assert.equal(armed.length, 1, JSON.stringify(armed))+ assert.equal(armed[0].sessionId, 'w1')+ assert.equal(armed[0].record.title, 'Standup')+ assert.equal(warnings.length, 1)+ assert.match(warnings[0][0], /stayed with the earlier part/)+ })++ test('a task the service refuses to remove stays with the earlier part alone', async (t) => {+ const { schedule, ctx, home, rt, warnings } = await moveSetup({ w1: 'refuse' })+ t.after(async () => { await ctx.dispose(); rmSync(home, { recursive: true, force: true, maxRetries: 5 }) })+ await rt.moveSchedules('w1', 'w2')+ const armed = [...schedule.tasks.values()]+ assert.equal(armed.length, 1, JSON.stringify(armed))+ assert.equal(armed[0].sessionId, 'w1')+ assert.equal(armed[0].record.title, 'Standup')+ assert.equal(warnings.length, 1)+ assert.match(warnings[0][0], /stayed with the earlier part/)+ })++ test('a task that cannot be rolled back is reported as left in two parts', async (t) => {+ const { schedule, ctx, home, rt, warnings } = await moveSetup({ w1: 'throw', w2: 'throw' })+ t.after(async () => { await ctx.dispose(); rmSync(home, { recursive: true, force: true, maxRetries: 5 }) })+ await rt.moveSchedules('w1', 'w2')+ const armed = [...schedule.tasks.values()]+ assert.equal(armed.length, 2, JSON.stringify(armed))+ assert.deepEqual(armed.map(task => task.sessionId).sort(), ['w1', 'w2'])+ assert.equal(warnings.length, 1)+ assert.match(warnings[0][0], /left in two parts/)+ })