Skip to content

Commit 1ddf35f

Browse files
committed
Merge origin/main into minimax-bot PR #148
2 parents d352150 + 0e8c24a commit 1ddf35f

4 files changed

Lines changed: 66 additions & 3 deletions

File tree

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@ The hand-over between two Bots of a group carried the tail of the previous reply
116116
- 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.
117117
- 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.
118118

119+
## 0.7.33 Stopping a queued background task actually stops it
120+
121+
- 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.
122+
- 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.
123+
- A task that had already started is unchanged: it is stopped by aborting its run, as before.
124+
119125
## 0.7.35 An uploaded file whose name carries `..` can be attached
120126

121127
- An upload kept the file name as given apart from a few forbidden characters, so a name containing `..` reached the stored id. The attachment reader refuses any id with `..` in it, and the file could never be attached again — the upload looked fine and the message that tried to use it failed.

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

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

18031803
async runHelper(helper) {
1804+
// The stop button can be pressed while the helper is still `queued` and no run exists yet; that
1805+
// path marks the helper stopped instead of aborting a controller. Nothing to do here then.
1806+
if (helper.status === 'stopped') return;
18041807
const controller = new AbortController();
18051808
const run = { controller };
18061809
const approvals = new Set();
@@ -2004,9 +2007,21 @@ export class Engine {
20042007
const helper = (this.store.state.helpers ?? []).find((h) => h.id === String(id ?? ''));
20052008
if (!helper) throw new EngineError('not_found', t('err.helperMissing', { id: String(id ?? '') }));
20062009
if (caller && !caller.isMain && helper.botId !== caller.id) throw new EngineError('forbidden', t('err.helperNotYours'));
2010+
const who = caller ? caller.name : 'user';
20072011
const run = this.helperRuns.get(helper.id);
2008-
if (!run || !HELPER_ACTIVE.has(helper.status)) return { stopped: false, status: helper.status };
2009-
run.stoppedBy = caller ? caller.name : 'user';
2012+
if (!run) {
2013+
// A helper is in the list before `runHelper` registers a run for it, and the page offers the
2014+
// stop button for `queued` too. Without this the request is answered `stopped: false` and the
2015+
// job starts anyway: mark it so `runHelper` sees it and leaves it alone.
2016+
if (helper.status !== 'queued') return { stopped: false, status: helper.status };
2017+
helper.status = 'stopped';
2018+
helper.endedAt = Date.now();
2019+
void this.store.save().catch((error) => this.logger.warn('minimax_bot.helper_stop_save_failed', { helperId: helper.id, code: error?.code ?? 'unknown' }));
2020+
this.broadcastHelpers();
2021+
return { stopped: true, status: 'stopped' };
2022+
}
2023+
if (!HELPER_ACTIVE.has(helper.status)) return { stopped: false, status: helper.status };
2024+
run.stoppedBy = who;
20102025
run.controller.abort();
20112026
return { stopped: true, status: 'stopped' };
20122027
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ function safeUploadName(raw) {
9797
const base = String(raw ?? '').split(/[\\/]/).pop() ?? '';
9898
// `..` reaches the stored id, and the attachment reader refuses any id carrying it, so the file
9999
// could never be attached again. Cut by code point so a character such as an emoji is not left
100-
// half-written, but stay inside the id's own byte-length budget.
100+
// half-written, while keeping the name within 140 UTF-16 code units.
101101
const points = [...base.replace(/[\u0000-\u001f\u007f<>:"|?*]/g, '_').replace(/\.{2,}/g, '_').replace(/^\.+/, '').trim()];
102102
let clean = '';
103103
for (const point of points) {

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,3 +1385,45 @@ test('a failed save in the schedule tick is reported, not thrown as an unhandled
13851385
engine.dispose();
13861386
await store.writeChain.catch(() => {});
13871387
});
1388+
1389+
test('stopping a helper while its admission is still being saved stops it for good', async (t) => {
1390+
const { store, engine } = await fixture(t);
1391+
const bot = store.state.bots[0];
1392+
const chatId = `bot:${bot.id}`;
1393+
const finish = deferred();
1394+
const saveEntered = deferred();
1395+
const finishSave = deferred();
1396+
t.after(() => { finish.resolve(); finishSave.resolve(); });
1397+
let runs = 0;
1398+
engine.agent = { async run(input, options) {
1399+
const ids = started(input, options, 'source');
1400+
runs += 1;
1401+
await finish.promise;
1402+
return { ...ids, status: 'finished', text: 'Done' };
1403+
} };
1404+
const source = engine.runBotTurn({ bot, chatId, text: 'Start background work', kind: 'private' });
1405+
await until(() => runs === 1);
1406+
1407+
// Hold the save that admits the helper, so the stop lands while it is still `queued` and no run
1408+
// exists yet. That is the window the page's stop button can be pressed in.
1409+
const save = store.save.bind(store);
1410+
store.save = async () => {
1411+
if (store.state.helpers.some((helper) => helper.status === 'queued')) { saveEntered.resolve(); await finishSave.promise; }
1412+
return save();
1413+
};
1414+
const starting = engine.startHelper(bot, { task: 'A new task' });
1415+
await saveEntered.promise;
1416+
const queued = store.state.helpers.find((helper) => helper.status === 'queued');
1417+
assert.equal(engine.helperRuns.size, 0);
1418+
const stopped = engine.stopHelper(null, queued.id);
1419+
assert.equal(stopped.stopped, true);
1420+
finishSave.resolve();
1421+
await starting;
1422+
1423+
// The helper must stay stopped and must never start a background turn.
1424+
finish.resolve();
1425+
await source;
1426+
await new Promise((resolve) => setTimeout(resolve, 60));
1427+
assert.equal(store.state.helpers.find((helper) => helper.id === queued.id).status, 'stopped');
1428+
assert.equal(runs, 1);
1429+
});

0 commit comments

Comments
 (0)