diff --git a/plugins/minimax-ai/minimax-bot/.minimax-plugin/plugin.json b/plugins/minimax-ai/minimax-bot/.minimax-plugin/plugin.json index 7e5cc956..12fa8746 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.32", + "version": "0.7.33", "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 dcaf8d60..c2fbd553 100644 --- a/plugins/minimax-ai/minimax-bot/README.md +++ b/plugins/minimax-ai/minimax-bot/README.md @@ -116,6 +116,12 @@ The hand-over between two Bots of a group carried the tail of the previous reply - 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.33 Stopping a queued background task actually stops it + +- The Stop button is offered for a background task that is still queued, but the request only found a run to abort once that task had started: pressed before then, it answered `stopped: false`, left the task queued, and the task started anyway. A queued task could not be stopped at all. +- Stopping before the run exists now marks the task stopped and saves that, and a task already marked stopped no longer starts a background turn. +- A task that had already started is unchanged: it is stopped by aborting its run, as before. + ## 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 f5d28487..8a1ead05 100644 --- a/plugins/minimax-ai/minimax-bot/miniapp/node/engine.mjs +++ b/plugins/minimax-ai/minimax-bot/miniapp/node/engine.mjs @@ -1801,6 +1801,9 @@ export class Engine { } async runHelper(helper) { + // The stop button can be pressed while the helper is still `queued` and no run exists yet; that + // path marks the helper stopped instead of aborting a controller. Nothing to do here then. + if (helper.status === 'stopped') return; const controller = new AbortController(); const run = { controller }; const approvals = new Set(); @@ -2004,9 +2007,21 @@ export class Engine { const helper = (this.store.state.helpers ?? []).find((h) => h.id === String(id ?? '')); if (!helper) throw new EngineError('not_found', t('err.helperMissing', { id: String(id ?? '') })); if (caller && !caller.isMain && helper.botId !== caller.id) throw new EngineError('forbidden', t('err.helperNotYours')); + const who = caller ? caller.name : 'user'; const run = this.helperRuns.get(helper.id); - if (!run || !HELPER_ACTIVE.has(helper.status)) return { stopped: false, status: helper.status }; - run.stoppedBy = caller ? caller.name : 'user'; + if (!run) { + // A helper is in the list before `runHelper` registers a run for it, and the page offers the + // stop button for `queued` too. Without this the request is answered `stopped: false` and the + // job starts anyway: mark it so `runHelper` sees it and leaves it alone. + if (helper.status !== 'queued') return { stopped: false, status: helper.status }; + helper.status = 'stopped'; + helper.endedAt = Date.now(); + void this.store.save().catch((error) => this.logger.warn('minimax_bot.helper_stop_save_failed', { helperId: helper.id, code: error?.code ?? 'unknown' })); + this.broadcastHelpers(); + return { stopped: true, status: 'stopped' }; + } + if (!HELPER_ACTIVE.has(helper.status)) return { stopped: false, status: helper.status }; + run.stoppedBy = who; run.controller.abort(); return { stopped: true, status: 'stopped' }; } diff --git a/plugins/minimax-ai/minimax-bot/miniapp/node/mcp.mjs b/plugins/minimax-ai/minimax-bot/miniapp/node/mcp.mjs index f6c660f0..83610206 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.32' }, + serverInfo: { name: 'minimax-bot', version: '0.7.33' }, instructions: t('mcp.instructions'), }; break; diff --git a/plugins/minimax-ai/minimax-bot/package.json b/plugins/minimax-ai/minimax-bot/package.json index acc9773b..a4548754 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.32", + "version": "0.7.33", "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 629d583e..1fafd72d 100644 --- a/plugins/minimax-ai/minimax-bot/tests/engine-reliability.test.mjs +++ b/plugins/minimax-ai/minimax-bot/tests/engine-reliability.test.mjs @@ -1385,3 +1385,45 @@ test('a failed save in the schedule tick is reported, not thrown as an unhandled engine.dispose(); await store.writeChain.catch(() => {}); }); + +test('stopping a helper while its admission is still being saved stops it for good', async (t) => { + const { store, engine } = await fixture(t); + const bot = store.state.bots[0]; + const chatId = `bot:${bot.id}`; + const finish = deferred(); + const saveEntered = deferred(); + const finishSave = deferred(); + t.after(() => { finish.resolve(); finishSave.resolve(); }); + let runs = 0; + engine.agent = { async run(input, options) { + const ids = started(input, options, 'source'); + runs += 1; + await finish.promise; + return { ...ids, status: 'finished', text: 'Done' }; + } }; + const source = engine.runBotTurn({ bot, chatId, text: 'Start background work', kind: 'private' }); + await until(() => runs === 1); + + // Hold the save that admits the helper, so the stop lands while it is still `queued` and no run + // exists yet. That is the window the page's stop button can be pressed in. + const save = store.save.bind(store); + store.save = async () => { + if (store.state.helpers.some((helper) => helper.status === 'queued')) { saveEntered.resolve(); await finishSave.promise; } + return save(); + }; + const starting = engine.startHelper(bot, { task: 'A new task' }); + await saveEntered.promise; + const queued = store.state.helpers.find((helper) => helper.status === 'queued'); + assert.equal(engine.helperRuns.size, 0); + const stopped = engine.stopHelper(null, queued.id); + assert.equal(stopped.stopped, true); + finishSave.resolve(); + await starting; + + // The helper must stay stopped and must never start a background turn. + finish.resolve(); + await source; + await new Promise((resolve) => setTimeout(resolve, 60)); + assert.equal(store.state.helpers.find((helper) => helper.id === queued.id).status, 'stopped'); + assert.equal(runs, 1); +});