Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugins/minimax-ai/minimax-bot/.minimax-plugin/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 7 additions & 0 deletions plugins/minimax-ai/minimax-bot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,13 @@ The hand-over between two Bots of a group carried the tail of the previous reply
- `</minimax-bot` followed by U+E0020 and `-context>` 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".
Expand Down
2 changes: 1 addition & 1 deletion plugins/minimax-ai/minimax-bot/miniapp/node/mcp.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/minimax-ai/minimax-bot/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "minimax-bot",
"version": "0.7.40",
"version": "0.7.44",
"private": true,
"type": "module",
"mcode": {
Expand Down
147 changes: 147 additions & 0 deletions plugins/minimax-ai/minimax-bot/tests/cancel-child-batch.test.mjs
Original file line number Diff line number Diff line change
@@ -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");
});