Skip to content

Commit c8fe487

Browse files
committed
fix(minimax-bot): 排队中的后台任务能停掉了
后台任务面板对 queued 也画停止按钮,但 stopHelper 只 abort helperRuns 里的 run 对象,而 run 要等 runHelper 启动时才注册。所以在排队窗口里按停止, stopHelper 走 !run 分支返回 stopped:false,不报错、不改状态、不留标记; save 完成后 runHelper 照常启动,任务跑完并把状态写成 done。 改成 stopHelper 找不到 run 时,若 helper 还是 queued 就标成 stopped、写 endedAt、存盘、广播;runHelper 开头加守卫,status 已是 stopped 就直接返回。 同一脚本对照:基线后台回合跑 2 次、状态 done;改完 0 次、状态 stopped。 新测试在 0.7.28 上红、在切片上绿。全量 414 条通过。
1 parent 28d4388 commit c8fe487

6 files changed

Lines changed: 68 additions & 5 deletions

File tree

‎plugins/minimax-ai/minimax-bot/.minimax-plugin/plugin.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"schemaVersion": 1,
33
"name": "minimax-bot",
44
"displayName": "MiniMax Bot",
5-
"version": "0.7.31",
5+
"version": "0.7.33",
66
"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.",
77
"author": "MiniMax Code",
88
"icon": "icon.png",

‎plugins/minimax-ai/minimax-bot/README.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ The hand-over between two Bots of a group carried the tail of the previous reply
111111
- 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.
112112
- A request whose reply had already started is unchanged, and a request this page has just sent never offers to resume itself.
113113

114+
## 0.7.33 Stopping a queued background task actually stops it
115+
116+
- 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.
117+
- 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.
118+
- A task that had already started is unchanged: it is stopped by aborting its run, as before.
119+
114120
## 0.7.10 Optional group notes
115121

116122
- 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.

‎plugins/minimax-ai/minimax-bot/miniapp/node/engine.mjs‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1797,6 +1797,9 @@ export class Engine {
17971797
}
17981798

17991799
async runHelper(helper) {
1800+
// The stop button can be pressed while the helper is still `queued` and no run exists yet; that
1801+
// path marks the helper stopped instead of aborting a controller. Nothing to do here then.
1802+
if (helper.status === 'stopped') return;
18001803
const controller = new AbortController();
18011804
const run = { controller };
18021805
const approvals = new Set();
@@ -2000,9 +2003,21 @@ export class Engine {
20002003
const helper = (this.store.state.helpers ?? []).find((h) => h.id === String(id ?? ''));
20012004
if (!helper) throw new EngineError('not_found', t('err.helperMissing', { id: String(id ?? '') }));
20022005
if (caller && !caller.isMain && helper.botId !== caller.id) throw new EngineError('forbidden', t('err.helperNotYours'));
2006+
const who = caller ? caller.name : 'user';
20032007
const run = this.helperRuns.get(helper.id);
2004-
if (!run || !HELPER_ACTIVE.has(helper.status)) return { stopped: false, status: helper.status };
2005-
run.stoppedBy = caller ? caller.name : 'user';
2008+
if (!run) {
2009+
// A helper is in the list before `runHelper` registers a run for it, and the page offers the
2010+
// stop button for `queued` too. Without this the request is answered `stopped: false` and the
2011+
// job starts anyway: mark it so `runHelper` sees it and leaves it alone.
2012+
if (helper.status !== 'queued') return { stopped: false, status: helper.status };
2013+
helper.status = 'stopped';
2014+
helper.endedAt = Date.now();
2015+
void this.store.save().catch((error) => this.logger.warn('minimax_bot.helper_stop_save_failed', { helperId: helper.id, code: error?.code ?? 'unknown' }));
2016+
this.broadcastHelpers();
2017+
return { stopped: true, status: 'stopped' };
2018+
}
2019+
if (!HELPER_ACTIVE.has(helper.status)) return { stopped: false, status: helper.status };
2020+
run.stoppedBy = who;
20062021
run.controller.abort();
20072022
return { stopped: true, status: 'stopped' };
20082023
}

‎plugins/minimax-ai/minimax-bot/miniapp/node/mcp.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ export function createMcpHandler({ team, engine }) {
662662
result = {
663663
protocolVersion: PROTOCOL_VERSIONS.includes(requested) ? requested : PROTOCOL_VERSIONS[0],
664664
capabilities: { tools: { listChanged: false } },
665-
serverInfo: { name: 'minimax-bot', version: '0.7.31' },
665+
serverInfo: { name: 'minimax-bot', version: '0.7.33' },
666666
instructions: t('mcp.instructions'),
667667
};
668668
break;

‎plugins/minimax-ai/minimax-bot/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "minimax-bot",
3-
"version": "0.7.31",
3+
"version": "0.7.33",
44
"private": true,
55
"type": "module",
66
"mcode": {

‎plugins/minimax-ai/minimax-bot/tests/engine-reliability.test.mjs‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,3 +1319,45 @@ test('a resume that loses the race to a same-id retry does not send the request
13191319
engine.dispose();
13201320
await store.writeChain;
13211321
});
1322+
1323+
test('stopping a helper while its admission is still being saved stops it for good', async (t) => {
1324+
const { store, engine } = await fixture(t);
1325+
const bot = store.state.bots[0];
1326+
const chatId = `bot:${bot.id}`;
1327+
const finish = deferred();
1328+
const saveEntered = deferred();
1329+
const finishSave = deferred();
1330+
t.after(() => { finish.resolve(); finishSave.resolve(); });
1331+
let runs = 0;
1332+
engine.agent = { async run(input, options) {
1333+
const ids = started(input, options, 'source');
1334+
runs += 1;
1335+
await finish.promise;
1336+
return { ...ids, status: 'finished', text: 'Done' };
1337+
} };
1338+
const source = engine.runBotTurn({ bot, chatId, text: 'Start background work', kind: 'private' });
1339+
await until(() => runs === 1);
1340+
1341+
// Hold the save that admits the helper, so the stop lands while it is still `queued` and no run
1342+
// exists yet. That is the window the page's stop button can be pressed in.
1343+
const save = store.save.bind(store);
1344+
store.save = async () => {
1345+
if (store.state.helpers.some((helper) => helper.status === 'queued')) { saveEntered.resolve(); await finishSave.promise; }
1346+
return save();
1347+
};
1348+
const starting = engine.startHelper(bot, { task: 'A new task' });
1349+
await saveEntered.promise;
1350+
const queued = store.state.helpers.find((helper) => helper.status === 'queued');
1351+
assert.equal(engine.helperRuns.size, 0);
1352+
const stopped = engine.stopHelper(null, queued.id);
1353+
assert.equal(stopped.stopped, true);
1354+
finishSave.resolve();
1355+
await starting;
1356+
1357+
// The helper must stay stopped and must never start a background turn.
1358+
finish.resolve();
1359+
await source;
1360+
await new Promise((resolve) => setTimeout(resolve, 60));
1361+
assert.equal(store.state.helpers.find((helper) => helper.id === queued.id).status, 'stopped');
1362+
assert.equal(runs, 1);
1363+
});

0 commit comments

Comments
 (0)