diff --git a/plugins/minimax-ai/minimax-bot/.minimax-plugin/plugin.json b/plugins/minimax-ai/minimax-bot/.minimax-plugin/plugin.json index 5bae125d..37445d15 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.36", + "version": "0.7.38", "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 e7f6907d..d182ea62 100644 --- a/plugins/minimax-ai/minimax-bot/README.md +++ b/plugins/minimax-ai/minimax-bot/README.md @@ -139,6 +139,15 @@ The hand-over between two Bots of a group carried the tail of the previous reply - The report a finished task batch hands back was trimmed to 4,000 characters per task without saying so. The task record already carries a marker when it had to shorten a result itself, and the report did not consult it, so a reader had no way to tell "this is the whole answer" from "this is the first part of it". - A result that was cut now ends with the same truncation mark the rest of the plugin uses. A result that fits is unchanged, and the full text is still read back with `get_tasks`. +## 0.7.38 The page tells the user when a chat is stuck and when a job was stopped + +- A turn whose outcome cannot be confirmed — the process stopped while it was running, or the Host took it and never said — leaves the request marked as unknown. Every later message of that chat waits for it, on purpose: a correction must not act on a state nobody can vouch for. +- But the way out was not reachable. The page draws its continuation button on a held message and on a request a restart left stranded; a message with an unknown outcome got no button, and the continuation route answered `busy` when the chat held nothing but that one message. So a chat with a single unknown outcome had no way out at all: the user could not confirm it, could not send it again under the same id, and every new request joined the queue behind it. Restarting did not help, because the state is on disk — and a restart in the middle of a turn is what produces it. +- A message with an unknown outcome now carries the same button, and the continuation route accepts a chat that holds nothing but such a message. Confirming it does not send that turn again: the request stays marked as unknown, and the chat goes on. The requests that were waiting behind it are sent. +- The stop button of a background job had the same trouble from the other side. It asked the Host to end the turn, but the job kept the `running` state until that turn actually came back. The Host ends a turn between its steps, so a job inside a long tool call kept reading as running for a while — and to a user pressing the button, nothing had happened at all. The only thing left to try was quitting the whole app. +- The job is marked stopped the moment the stop is asked for, so the page stops reading it as running. The turn still winds down in the background; what changes is that the page tells the truth about it. The abort still goes to the same turn, and a job that was already stopped or already finished is left alone. +- Nothing else moves: a request with an unknown outcome is still never replayed on its own, and the order of the messages around it is unchanged. + ## 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/client/app.js b/plugins/minimax-ai/minimax-bot/miniapp/client/app.js index 75f2d0e2..4d02ae5f 100644 --- a/plugins/minimax-ai/minimax-bot/miniapp/client/app.js +++ b/plugins/minimax-ai/minimax-bot/miniapp/client/app.js @@ -804,7 +804,10 @@ function userDelivery(message) { const stranded = status === 'pending' && !sentHere.has(message.id) && !state.busy.has(message.chatId) && !(state.messages.get(message.chatId) ?? []).some( (item) => item.sourceMessageId === message.id || item.sourceMessageIds?.includes(message.id)); - const button = status === 'held' || stranded ? h('button', { + // A turn whose outcome is unknown holds every later message of the chat. The page has to offer + // the way out on the message that carries that state: asking from anywhere else would not show + // the user where the chat is stuck. + const button = status === 'held' || status === 'uncertain' || stranded ? h('button', { type: 'button', class: 'btn sm', disabled: deliveryActions.has(key), onclick: async (event) => { if (deliveryActions.has(key)) return; diff --git a/plugins/minimax-ai/minimax-bot/miniapp/node/engine.mjs b/plugins/minimax-ai/minimax-bot/miniapp/node/engine.mjs index 0e2168fc..33ffe93b 100644 --- a/plugins/minimax-ai/minimax-bot/miniapp/node/engine.mjs +++ b/plugins/minimax-ai/minimax-bot/miniapp/node/engine.mjs @@ -2051,6 +2051,13 @@ export class Engine { } if (!HELPER_ACTIVE.has(helper.status)) return { stopped: false, status: helper.status }; run.stoppedBy = who; + // The Host ends a turn between its steps, so a run that is inside a long tool call keeps + // going for a while after the abort. The job is not working any more, and the page has to + // say so at once: a stop button that leaves the row reading "running" looks like it did + // nothing, and the only thing left to try is quitting the whole app. + helper.status = 'stopped'; + void this.store.save().catch((error) => this.logger.warn('minimax_bot.helper_stop_save_failed', { helperId: helper.id, code: error?.code ?? 'unknown' })); + this.broadcastHelpers(); 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 8a836bdd..d4fd1987 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.36' }, + serverInfo: { name: 'minimax-bot', version: '0.7.38' }, instructions: t('mcp.instructions'), }; break; diff --git a/plugins/minimax-ai/minimax-bot/miniapp/node/user-inbox.mjs b/plugins/minimax-ai/minimax-bot/miniapp/node/user-inbox.mjs index e1ec8f1b..a7da9b6e 100644 --- a/plugins/minimax-ai/minimax-bot/miniapp/node/user-inbox.mjs +++ b/plugins/minimax-ai/minimax-bot/miniapp/node/user-inbox.mjs @@ -162,13 +162,19 @@ export class UserInbox { return message.dispatchState === 'pending' && !history.some((item) => item.sourceMessageId === message.id || item.sourceMessageIds?.includes(message.id)); }); - if (!held.length || this.busy(chatId) || [...this.engine.tickets].some((ticket) => ticket.chatId === chatId)) { + // A turn whose outcome is unknown holds every later message of the chat, so a chat that has + // one is stuck until the user says what to do with it. Asking is the only way out, so the + // asking must work even when there is nothing to send again: the unknown turn is confirmed + // as seen, and the chat goes on. + const uncertainIds = history.filter((message) => message.role === 'user' && message.dispatchState === 'uncertain').map((message) => message.id); + if ((!held.length && !uncertainIds.length) || this.busy(chatId) || [...this.engine.tickets].some((ticket) => ticket.chatId === chatId)) { throw new this.ErrorType('busy', t('err.messageAlreadyProcessing')); } const bot = chatId.startsWith('bot:') ? this.engine.store.getBot(chatId.slice(4)) : undefined; const group = chatId.startsWith('group:') ? this.engine.store.getGroup(chatId.slice(6)) : undefined; if (!bot && !group) throw new this.ErrorType('not_found', t('err.chatMissing')); - const uncertainIds = history.filter((message) => message.role === 'user' && message.dispatchState === 'uncertain').map((message) => message.id); + // Confirming the unknown turn is not replaying it: it is the user saying they have seen it. + // The turn itself is never sent again. await this.engine.store.updateMessages(chatId, uncertainIds, { continuationAcknowledged: true }); const heldIds = new Set(held.map((message) => message.id)); // Re-check inside the write: a retry carrying the same clientMessageId can enqueue the message diff --git a/plugins/minimax-ai/minimax-bot/package.json b/plugins/minimax-ai/minimax-bot/package.json index a297a586..e0d76793 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.36", + "version": "0.7.38", "private": true, "type": "module", "mcode": { diff --git a/plugins/minimax-ai/minimax-bot/tests/client-reliability.test.mjs b/plugins/minimax-ai/minimax-bot/tests/client-reliability.test.mjs index 3f410e9e..7ec54e8f 100644 --- a/plugins/minimax-ai/minimax-bot/tests/client-reliability.test.mjs +++ b/plugins/minimax-ai/minimax-bot/tests/client-reliability.test.mjs @@ -844,4 +844,16 @@ test('the background task strip keeps the official one line rows and folds a lon emit({ type: 'helpers.changed', helpers }); await settle(); assert.match(strip.querySelector('.helper-more').textContent, /4 more tasks/, 'the queue starts folded again'); -}); \ No newline at end of file +}); +test('an unknown outcome offers the way out, so the chat is not stuck for good', async () => { + // A turn whose outcome is unknown holds every later message of the chat. The page has to + // offer the way out on the message that carries that state. + const unknown = message('msg_unknown', 'Possibly already executed', { role: 'user', dispatchState: 'uncertain' }); + await reset([unknown]); + assert.match(document.querySelector('.message-delivery').textContent, /Outcome unknown/); + const button = document.querySelector('.message-delivery button'); + assert.notEqual(button, null, 'the message that holds the chat offers the continuation'); + route = ({ path }) => path.endsWith('/resume-pending') ? response({ ok: true }) : undefined; + button.click(); await settle(); + assert.equal(calls.filter((call) => call.path.endsWith('/resume-pending')).length, 1); +}); 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 a00d8bc4..29aa9dda 100644 --- a/plugins/minimax-ai/minimax-bot/tests/engine-reliability.test.mjs +++ b/plugins/minimax-ai/minimax-bot/tests/engine-reliability.test.mjs @@ -1493,3 +1493,95 @@ test('a pass by the last speaker does not overwrite what an earlier one said', a const messages = await store.getMessages(chatId); assert.equal(messages.filter((message) => message.status === 'pass').length, 1); }); + +test('a chat with one unknown outcome can be let go, so it is not stuck for good', async (t) => { + const { store, engine } = await fixture(t); + const bot = store.state.bots[0]; + const chatId = `bot:${bot.id}`; + // A turn that was cut off leaves its request uncertain: the outcome cannot be known, and the + // request is never replayed on its own. Every later message of the chat waits for it. + await store.appendMessage(chatId, { role: 'user', text: 'Possibly already executed', dispatchState: 'uncertain' }); + await store.writeChain; + + let runs = 0; + engine.agent = { async run(input, options) { + runs += 1; + return { ...started(input, options, 'after-unknown'), status: 'finished', text: 'Done' }; + } }; + + // The user says they have seen it: the chat goes on. The unknown turn itself is not sent again. + const resumed = await engine.inbox.resumeHeld(chatId); + assert.deepEqual(resumed, { ok: true }); + const history = await store.getMessages(chatId); + assert.equal(history.find((m) => m.text === 'Possibly already executed').continuationAcknowledged, true); + + // And a later request is no longer held back by it. + await engine.sendUserMessage(chatId, 'A new request', [], 'after-unknown-1'); + await until(() => idle(engine)); + assert.equal(runs, 1, 'the new request runs'); + const after = await store.getMessages(chatId); + assert.equal(after.find((m) => m.text === 'A new request').dispatchState, 'delivered'); +}); + +test('an unknown outcome does not stop a later request from running once it is acknowledged', async (t) => { + const { store, engine } = await fixture(t); + const bot = store.state.bots[0]; + const chatId = `bot:${bot.id}`; + await store.appendMessage(chatId, { role: 'user', text: 'Possibly already executed', dispatchState: 'uncertain' }); + await store.writeChain; + + let runs = 0; + engine.agent = { async run(input, options) { + runs += 1; + return { ...started(input, options, 'held-then-asked'), status: 'finished', text: 'Done' }; + } }; + + // A request that arrives while the outcome is unknown waits for it. + await engine.sendUserMessage(chatId, 'A correction', [], 'held-1'); + await until(() => idle(engine)); + assert.equal(runs, 0, 'the correction waits for the unknown outcome'); + assert.equal((await store.getMessages(chatId)).find((m) => m.text === 'A correction').dispatchState, 'held'); + + // Asking lets the chat go: the unknown outcome is confirmed as seen and the waiting request + // is sent. + await engine.inbox.resumeHeld(chatId); + await until(() => idle(engine)); + assert.equal(runs, 1, 'the waiting request is sent'); + const after = await store.getMessages(chatId); + assert.equal(after.find((m) => m.text === 'A correction').dispatchState, 'delivered'); +}); + +test('a running helper shows as stopped the moment the stop is asked for', async (t) => { + const { store, engine } = await fixture(t); + const bot = store.state.bots[0]; + const chatId = `bot:${bot.id}`; + const finish = deferred(); + let insideHelper = false; + engine.agent = { async run(input, options) { + const ids = started(input, options, 'helper-session'); + if (input.text.startsWith('')) { + insideHelper = true; + // The run is inside a tool call that does not come back on its own. + await finish.promise; + return { ...ids, status: 'finished', text: 'Done' }; + } + await engine.startHelper(bot, { task: 'Watch the automation' }); + return { ...ids, status: 'finished', text: 'Started' }; + } }; + const source = engine.runBotTurn({ bot, chatId, text: 'Watch the automation for me', kind: 'private' }); + await until(() => insideHelper); + const helper = store.state.helpers.find((item) => item.status === 'running'); + assert.ok(helper, 'the helper is running'); + + const stopped = engine.stopHelper(null, helper.id); + assert.equal(stopped.stopped, true); + + // The Host ends a turn between its steps, so the run is still winding down. The page must + // not keep reading "running": a stop button that changes nothing looks like it did nothing. + assert.equal(store.state.helpers.find((item) => item.id === helper.id).status, 'stopped'); + + finish.resolve(); + await source; + await new Promise((resolve) => setTimeout(resolve, 60)); + assert.equal(store.state.helpers.find((item) => item.id === helper.id).status, 'stopped'); +});