diff --git a/plugins/minimax-ai/minimax-bot/.minimax-plugin/plugin.json b/plugins/minimax-ai/minimax-bot/.minimax-plugin/plugin.json index 27ecf749..7e5cc956 100644 --- a/plugins/minimax-ai/minimax-bot/.minimax-plugin/plugin.json +++ b/plugins/minimax-ai/minimax-bot/.minimax-plugin/plugin.json @@ -2,7 +2,7 @@ "schemaVersion": 1, "name": "minimax-bot", "displayName": "MiniMax Bot", - "version": "0.7.31", + "version": "0.7.32", "description": "Turn MiniMax Code into an always-on team of Bots. A Chief Bot helps you build the team; in group chats the admin answers and @mentions hand work to other members. Every Bot has its own octopus avatar and memory, with scheduled tasks and usage stats.", "author": "MiniMax Code", "icon": "icon.png", diff --git a/plugins/minimax-ai/minimax-bot/README.md b/plugins/minimax-ai/minimax-bot/README.md index 5e74fbf3..dcaf8d60 100644 --- a/plugins/minimax-ai/minimax-bot/README.md +++ b/plugins/minimax-ai/minimax-bot/README.md @@ -111,6 +111,11 @@ The hand-over between two Bots of a group carried the tail of the previous reply - The page now offers the same **Continue with follow-ups** button for it, and the resume route accepts it, so the request can be sent again. Nothing is replayed on its own: the turn may already have run tools before the process stopped, so sending it again stays the user's decision. - A request whose reply had already started is unchanged, and a request this page has just sent never offers to resume itself. +## 0.7.32 A failed write is reported instead of taking the process down + +- Two writes the plugin fires and forgets had nothing to catch their failure: the session id recorded when a turn starts, and the scheduled-task scan that runs every 30 seconds. A failed write there became an unhandled rejection, and the Host fails the whole Mini App process on one of those — so a disk that would not take a write took every running turn with it, and the scheduled task kept retrying every 30 seconds. +- Both now report the failure through the plugin log, the way the task save next to one of them already did. The turn carries on, and the scan keeps running. + ## 0.7.10 Optional group notes - A group can keep a note of what it said. After every round the group records the closing lines of the replies, and every Bot of the group gets that record in its standing brief. diff --git a/plugins/minimax-ai/minimax-bot/miniapp/node/engine.mjs b/plugins/minimax-ai/minimax-bot/miniapp/node/engine.mjs index c4f8261f..f5d28487 100644 --- a/plugins/minimax-ai/minimax-bot/miniapp/node/engine.mjs +++ b/plugins/minimax-ai/minimax-bot/miniapp/node/engine.mjs @@ -644,7 +644,8 @@ export class Engine { task.sessionId = event.sessionId; void this.tasks.save().catch((error) => this.logger.warn('minimax_bot.task_save_failed', { taskId: task.id, code: error?.code ?? 'unknown' })); } - void this.store.setSession(chatId, bot.id, { sessionId: event.sessionId }); + void this.store.setSession(chatId, bot.id, { sessionId: event.sessionId }) + .catch((error) => this.logger.warn('minimax_bot.session_save_failed', { chatId, code: error?.code ?? 'unknown' })); flush(true); break; case 'text.delta': @@ -1624,9 +1625,12 @@ export class Engine { // ------------------------------------------------------------------ schedules startScheduler() { - this.scheduleTimer = setInterval(() => void this.tickSchedules(), 30_000); + // A failed save inside the tick must not become an unhandled rejection: the Host turns one of + // those into a failed Mini App process, so a bad disk would take every running turn with it. + const tick = () => this.tickSchedules().catch((error) => this.logger.warn('minimax_bot.schedule_tick_failed', { code: error?.code ?? 'unknown' })); + this.scheduleTimer = setInterval(() => void tick(), 30_000); this.scheduleTimer.unref?.(); - void this.tickSchedules(); + void tick(); } async tickSchedules() { diff --git a/plugins/minimax-ai/minimax-bot/miniapp/node/mcp.mjs b/plugins/minimax-ai/minimax-bot/miniapp/node/mcp.mjs index aa693a48..f6c660f0 100644 --- a/plugins/minimax-ai/minimax-bot/miniapp/node/mcp.mjs +++ b/plugins/minimax-ai/minimax-bot/miniapp/node/mcp.mjs @@ -662,7 +662,7 @@ export function createMcpHandler({ team, engine }) { result = { protocolVersion: PROTOCOL_VERSIONS.includes(requested) ? requested : PROTOCOL_VERSIONS[0], capabilities: { tools: { listChanged: false } }, - serverInfo: { name: 'minimax-bot', version: '0.7.31' }, + serverInfo: { name: 'minimax-bot', version: '0.7.32' }, instructions: t('mcp.instructions'), }; break; diff --git a/plugins/minimax-ai/minimax-bot/package.json b/plugins/minimax-ai/minimax-bot/package.json index 1b8fad54..acc9773b 100644 --- a/plugins/minimax-ai/minimax-bot/package.json +++ b/plugins/minimax-ai/minimax-bot/package.json @@ -1,6 +1,6 @@ { "name": "minimax-bot", - "version": "0.7.31", + "version": "0.7.32", "private": true, "type": "module", "mcode": { diff --git a/plugins/minimax-ai/minimax-bot/tests/engine-reliability.test.mjs b/plugins/minimax-ai/minimax-bot/tests/engine-reliability.test.mjs index 37a22584..629d583e 100644 --- a/plugins/minimax-ai/minimax-bot/tests/engine-reliability.test.mjs +++ b/plugins/minimax-ai/minimax-bot/tests/engine-reliability.test.mjs @@ -1,6 +1,6 @@ import assert from 'node:assert/strict'; import { test } from 'node:test'; -import { mkdtemp, rm } from 'node:fs/promises'; +import { mkdir, mkdtemp, rm } from 'node:fs/promises'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; import { spawnSync } from 'node:child_process'; @@ -1319,3 +1319,69 @@ test('a resume that loses the race to a same-id retry does not send the request engine.dispose(); await store.writeChain; }); + +test('a failed session write during a turn is reported, not thrown as an unhandled rejection', async (t) => { + const { dir, store, memory } = await fixture(t); + const bot = store.state.bots[0]; + const chatId = `bot:${bot.id}`; + const rejected = []; + const onRejection = (error) => rejected.push(error); + process.on('unhandledRejection', onRejection); + t.after(() => process.removeListener('unhandledRejection', onRejection)); + + const logged = []; + const engine = new Engine({ store, memory, broadcast() {}, retryDelaysMs: [], logger: { warn: (key) => logged.push(key) }, agent: { + async run(input, options) { + options.onEvent({ type: 'turn.started', sessionId: 'host-session', turnId: 'turn-1' }); + return { sessionId: 'host-session', turnId: 'turn-1', status: 'finished', text: 'Done' }; + }, + } }); + // Every state write fails from here on. + const statePath = join(dir, 'state.json'); + await rm(statePath, { force: true }); + await mkdir(statePath, { recursive: true }); + + await engine.sendUserMessage(chatId, 'Ship the hotfix', [], 'session-write').catch(() => {}); + await until(() => idle(engine)); + await new Promise((resolve) => setTimeout(resolve, 50)); + + // The Host fails the whole Mini App process on an unhandled rejection, so this one has to be caught. + assert.deepEqual(rejected.map((error) => error?.code ?? 'unknown'), []); + assert.ok(logged.includes('minimax_bot.session_save_failed'), `logged: ${logged.join(',')}`); + engine.dispose(); + await store.writeChain.catch(() => {}); +}); + +test('a failed save in the schedule tick is reported, not thrown as an unhandled rejection', async (t) => { + const { dir, store, memory } = await fixture(t); + const bot = store.state.bots[0]; + const rejected = []; + const onRejection = (error) => rejected.push(error); + process.on('unhandledRejection', onRejection); + t.after(() => process.removeListener('unhandledRejection', onRejection)); + + // A schedule that is already due, so one tick touches it. + store.state.schedules.push({ + id: 'sch_due', createdAt: Date.now(), name: 'Due', botId: bot.id, prompt: 'Ping', + kind: 'interval', time: '09:00', everyMinutes: 60, enabled: true, nextRunAt: Date.now() - 1000, + }); + await store.save(); + + const logged = []; + const engine = new Engine({ store, memory, logger: { warn: (key) => logged.push(key) }, broadcast() {}, retryDelaysMs: [], agent: { + async run() { return { sessionId: 's', turnId: 'turn-2', status: 'finished', text: 'ok' }; }, + } }); + const statePath = join(dir, 'state.json'); + await rm(statePath, { force: true }); + await mkdir(statePath, { recursive: true }); + + // The scheduler fires the tick without awaiting it, so a rejection would surface as an unhandled + // rejection unless the engine catches it. + engine.startScheduler(); + await new Promise((resolve) => setTimeout(resolve, 80)); + + assert.deepEqual(rejected.map((error) => error?.code ?? 'unknown'), []); + assert.ok(logged.includes('minimax_bot.schedule_tick_failed'), `logged: ${logged.join(',')}`); + engine.dispose(); + await store.writeChain.catch(() => {}); +});