From 307ed068434b17e2a6e55b44733d8395ddb9be15 Mon Sep 17 00:00:00 2001 From: Evander Date: Mon, 30 Nov 2026 23:19:36 -0500 Subject: [PATCH] =?UTF-8?q?fix(minimax-bot):=20=E5=8F=96=E6=B6=88=E7=88=B6?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E6=97=B6=E5=85=B3=E9=97=AD=E5=AD=90=E6=89=B9?= =?UTF-8?q?=E6=AC=A1=EF=BC=8C=E4=B8=8D=E5=86=8D=E6=B0=B8=E4=B9=85=E6=B3=84?= =?UTF-8?q?=E6=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../minimax-bot/.minimax-plugin/plugin.json | 2 +- plugins/minimax-ai/minimax-bot/README.md | 7 + .../minimax-bot/miniapp/node/mcp.mjs | 2 +- .../miniapp/node/task-dispatcher.mjs | 9 ++ plugins/minimax-ai/minimax-bot/package.json | 2 +- .../tests/cancel-child-batch.test.mjs | 147 ++++++++++++++++++ 6 files changed, 166 insertions(+), 3 deletions(-) create mode 100644 plugins/minimax-ai/minimax-bot/tests/cancel-child-batch.test.mjs diff --git a/plugins/minimax-ai/minimax-bot/.minimax-plugin/plugin.json b/plugins/minimax-ai/minimax-bot/.minimax-plugin/plugin.json index 370cee81..b054eaff 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.40", + "version": "0.7.44", "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 651f680a..e00efb21 100644 --- a/plugins/minimax-ai/minimax-bot/README.md +++ b/plugins/minimax-ai/minimax-bot/README.md @@ -161,6 +161,13 @@ The hand-over between two Bots of a group carried the tail of the previous reply - `` reached the next Bot whole: the closing tag of the block the plugin writes around the context. The words around it were kept, as they are for every other spelling. - The text is now walked by code point, so a character outside the Basic Multilingual Plane is read as the one character it is. The tag characters are named as well, because some of the slots in that block are not assigned in every Unicode version and are therefore not caught by the general categories. +## 0.7.44 A cancelled child batch closes instead of staying pending for good + +- A parent task may wait for a child batch. Cancelling the parent cancels the child's tasks, but the child batch itself was left with its notification still `pending`. A pending batch counts as active, so it was never trimmed: every cancelled delegation left another live batch in the state file, and a lookup answered `pending` for work that was already over. +- The parent's dependency on the child stayed pending too, and that is a second reason the batch could never be trimmed: the parent was cancelled and would never consume it. +- Cancelling a dependency now closes the child batch through the same delivery path that marks a batch whose parent was cancelled as `posted`, and marks the dependency as consumed. The batch stops being active, the normal trim can archive it, and a lookup no longer contradicts itself. +- Forty cancelled delegations used to leave seventy live batches, forty of them stuck in `pending`; after the fix the same probe leaves thirty live batches, none stuck, and the child lookup says `posted` with `complete: true`. + ## 0.7.40 A value that is not there is left out, not refused - The reply mode of a group and the kind of a scheduled task are checked against the values the catalogue offers, so a value that is not one of them is refused instead of quietly becoming another one. A value that is not there at all was refused too, when it arrived as null: many models write an optional field they did not fill in as null, and the call failed with "reply_mode must be one of: admin, all". diff --git a/plugins/minimax-ai/minimax-bot/miniapp/node/mcp.mjs b/plugins/minimax-ai/minimax-bot/miniapp/node/mcp.mjs index a6473f79..3383bbee 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.40' }, + serverInfo: { name: 'minimax-bot', version: '0.7.44' }, instructions: t('mcp.instructions'), }; break; diff --git a/plugins/minimax-ai/minimax-bot/miniapp/node/task-dispatcher.mjs b/plugins/minimax-ai/minimax-bot/miniapp/node/task-dispatcher.mjs index c6970ea3..e307c86a 100644 --- a/plugins/minimax-ai/minimax-bot/miniapp/node/task-dispatcher.mjs +++ b/plugins/minimax-ai/minimax-bot/miniapp/node/task-dispatcher.mjs @@ -263,7 +263,16 @@ export class TaskDispatcher { const batch = this.batches.find((item) => item.id === dependency.id); this.deliveryControllers.get(dependency.id)?.abort(); for (const child of batch?.tasks ?? []) this.cancelTask(child); + // The child batch has to close with the cancel. Its tasks are settled now, and a batch + // whose notification is still pending counts as active, so it is never trimmed and it + // stays in the state file for good. The delivery closes it — that is the branch that + // marks a batch whose parent was cancelled as posted. + if (batch) void this.deliver(batch); } + // The dependency is answered by the cancel, so it is no longer owed. A dependency that + // stays pending keeps its batch active for good: the parent was cancelled and will never + // consume it, and a batch whose parent still owes it is never trimmed. + dependency.consumed = true; } } diff --git a/plugins/minimax-ai/minimax-bot/package.json b/plugins/minimax-ai/minimax-bot/package.json index e799ef2e..dcfc7d45 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.40", + "version": "0.7.44", "private": true, "type": "module", "mcode": { diff --git a/plugins/minimax-ai/minimax-bot/tests/cancel-child-batch.test.mjs b/plugins/minimax-ai/minimax-bot/tests/cancel-child-batch.test.mjs new file mode 100644 index 00000000..4f1a8b38 --- /dev/null +++ b/plugins/minimax-ai/minimax-bot/tests/cancel-child-batch.test.mjs @@ -0,0 +1,147 @@ +// A batch whose parent was cancelled has to close with the cancel. +// +// The parent task waits for a child batch. Cancelling the parent cancels the child's tasks too, +// but the child batch itself has to be closed by the same cancel: a batch whose notification is +// still "pending" counts as active, so it is never trimmed and it stays in the state file for +// good — one more live batch for every cancelled delegation, and a lookup that answers +// "pending" for work that is over. +import assert from "node:assert/strict"; +import { test } from "node:test"; +import { mkdtemp, rm } from "node:fs/promises"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import { Store } from "../miniapp/node/store.mjs"; +import { MemoryStore } from "../miniapp/node/memory.mjs"; +import { Engine } from "../miniapp/node/engine.mjs"; +import { setLocale } from "../miniapp/node/i18n.mjs"; + +async function until(predicate, label = "condition") { + for (let i = 0; i < 800; i += 1) { + if (await predicate()) return; + await new Promise((resolve) => setTimeout(resolve, 5)); + } + throw new Error(`Timed out waiting for ${label}`); +} + +const idle = (engine) => + !engine.tasks.runs.size && + !engine.tasks.deliveries.size && + !engine.tickets.size; + +async function fixture(t) { + const dir = await mkdtemp(join(tmpdir(), "bot-cancel-child-")); + const store = new Store(dir); + await store.init(); + const memory = new MemoryStore(dir); + await memory.init(); + setLocale("en"); + const a = { id: "bot_a", name: "Alice", isMain: true }; + const b = { id: "bot_b", name: "Bob" }; + store.state.bots = [a, b]; + store.state.groups = []; + await store.save(); + const engine = new Engine({ + store, + memory, + logger: { warn() {} }, + broadcast() {}, + retryDelaysMs: [], + }); + t.after(async () => { + engine.dispose(); + await until(() => idle(engine)).catch(() => {}); + await store.writeChain; + await rm(dir, { recursive: true, force: true }); + }); + return { dir, store, memory, engine, a, b }; +} + +/** + * A parent task that is waiting for a child batch. + * + * The parent is a task of its own, handed to Alice; Alice's turn then hands a second task to Bob, + * and that second batch is the parent's dependency. Bob's chat is kept busy so the child stays + * queued and the parent stays waiting for it. + */ +async function parentWaitingForChild(engine, a, b) { + let releaseBusy; + const busy = new Promise((resolve) => { releaseBusy = resolve; }); + engine.agent = { + async run(input, options) { + const ids = { sessionId: `session-${engine.tasks.runs.size + 1}`, turnId: "turn" }; + options.onEvent({ type: "turn.started", ...ids }); + if (input.text.includes("OCCUPY")) { + await busy; + return { ...ids, status: "finished", text: "free" }; + } + if (input.text.includes("DELEGATE")) { + await engine.tasks.dispatch( + a, + { request_id: "child-1", tasks: [{ to: b.id, message: "child work" }] }, + { turn: engine.bindCallerTurn(a.id) }, + ); + return { ...ids, status: "finished", text: "dispatched" }; + } + return { ...ids, status: "finished", text: "child reply" }; + }, + }; + void engine.runBotTurn({ bot: b, chatId: `bot:${b.id}`, kind: "private", text: "OCCUPY the chat" }); + await until(() => engine.isBusy(`bot:${b.id}`), "Bob's chat is busy"); + + await engine.tasks.dispatch( + undefined, + { request_id: "parent-1", tasks: [{ to: a.id, message: "DELEGATE child-1" }] }, + { turn: { chatId: `bot:${a.id}` } }, + ); + await until( + () => engine.tasks.tasks.some((task) => task.status === "waiting_for_tasks"), + "the parent is waiting for its child", + ); + const parent = engine.tasks.tasks.find((task) => task.status === "waiting_for_tasks"); + const child = engine.tasks.batches.find((batch) => batch.id === parent.dependencies[0].id); + await until(() => child !== undefined, "the child batch"); + return { child, parent, releaseBusy }; +} + +test("a child batch closes with its parent's cancel instead of staying pending for good", async (t) => { + const { engine, a, b } = await fixture(t); + const { child, parent } = await parentWaitingForChild(engine, a, b); + + await engine.tasks.cancel(undefined, { task_id: parent.id }); + await until(() => child.notification !== "pending", "the child batch closed"); + + assert.notEqual(child.notification, "pending", "the child batch is not left pending"); + assert.equal(child.tasks.every((task) => task.status === "cancelled" || task.status === "done"), true, + "the child's tasks are settled"); + + // A pending batch is an active one, and an active batch is never trimmed. + assert.equal(engine.tasks.batchActive(child), false, "the child batch is no longer active"); +}); + +test("a cancelled child batch is answered as finished, not as pending", async (t) => { + const { engine, a, b } = await fixture(t); + const { child, parent } = await parentWaitingForChild(engine, a, b); + + await engine.tasks.cancel(undefined, { task_id: parent.id }); + await until(() => child.notification !== "pending", "the child batch closed"); + + const view = await engine.tasks.get(undefined, { batch_id: child.id }); + const batch = view.tasks?.length ? view : { tasks: view?.tasks ?? [], notification: view?.notification }; + assert.notEqual(batch.notification, "pending", "the lookup does not say pending"); + assert.equal(batch.complete, true, "the lookup says the work is over"); +}); + +test("cancelling a parent leaves no batch behind that nothing will ever close", async (t) => { + const { engine, store, a, b } = await fixture(t); + const { child, parent } = await parentWaitingForChild(engine, a, b); + + await engine.tasks.cancel(undefined, { task_id: parent.id }); + await until(() => child.notification !== "pending", "the child batch closed"); + await engine.tasks.save(); + + // Every batch that is in the state file but not settled has to be one that can still move. + const stuck = (store.state.taskBatches ?? []).filter( + (batch) => batch.notification === "pending" && batch.tasks?.every((task) => task.status !== "queued" && task.status !== "running"), + ); + assert.deepEqual(stuck.map((batch) => batch.id), [], "no batch is left pending with nothing to do"); +});