diff --git a/plugins/minimax-ai/minimax-bot/.minimax-plugin/plugin.json b/plugins/minimax-ai/minimax-bot/.minimax-plugin/plugin.json index 370cee81..3fdf839a 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.41", "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..88ab2502 100644 --- a/plugins/minimax-ai/minimax-bot/README.md +++ b/plugins/minimax-ai/minimax-bot/README.md @@ -165,6 +165,11 @@ The hand-over between two Bots of a group carried the tail of the previous reply - 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". - A null is now read as what it is — a field that was left out — so the default applies, the same as when the field is absent. A value that is there but is not one of the allowed ones is still refused, and so is the text "null". +## 0.7.41 A finished background job is not left reading as running + +- A background job publishes its status to the page through one broadcast, and that broadcast came after the write that closed the job out. A write that fails there — no space, a read-only disk — skipped the broadcast, so the page kept the last status it had been told, which is `running`. The job is already final in memory, and it never runs again, so nothing else would ever correct the row: the spinner stayed for good, and the only thing left to do was restart. +- The status is now published before that write, and the write's failure is logged instead of ending the turn. The report that posts the job's outcome into its chat had the same shape and is fixed the same way, so a disk that fails once no longer costs the page the job's ending or the chat its note. +- What is on disk is unchanged: the write still happens before the report, and the status it writes is the same one. Only the order of that one broadcast and the handling of a failed write changed. ## 0.7.10 Optional group notes diff --git a/plugins/minimax-ai/minimax-bot/miniapp/node/engine.mjs b/plugins/minimax-ai/minimax-bot/miniapp/node/engine.mjs index 33ffe93b..4ba1e30b 100644 --- a/plugins/minimax-ai/minimax-bot/miniapp/node/engine.mjs +++ b/plugins/minimax-ai/minimax-bot/miniapp/node/engine.mjs @@ -1981,8 +1981,16 @@ export class Engine { } if (this.disposed) return; this.trimHelpers(); - await this.store.save(); + // Tell the page the job is over before the write, not after it. The status is already final + // in memory, and a write that fails is no reason to leave the row reading "running" for good: + // the job never runs again, so nothing else would ever correct it. The write itself still + // has to happen before the report goes out, and a failure still has to be reported. this.broadcastHelpers(); + try { + await this.store.save(); + } catch (error) { + this.logger.warn('minimax_bot.helper_final_save_failed', { helperId: helper.id, code: error?.code ?? 'unknown' }); + } await this.deliverHelperReport(helper, run.stoppedBy); } @@ -2005,8 +2013,14 @@ export class Engine { this.broadcast({ type: 'message.upsert', chatId, message: note }); this.broadcastSummary(chatId); helper.resultMessageId = note.id; - await this.store.save(); + // Same reason as the status broadcast above: the note is already in the chat and the status + // is already final, so a write that fails must not keep the page from hearing either. this.broadcastHelpers(); + try { + await this.store.save(); + } catch (error) { + this.logger.warn('minimax_bot.helper_report_save_failed', { helperId: helper.id, code: error?.code ?? 'unknown' }); + } if (helper.parentTaskId) { await this.tasks.receiveDependency(helper.parentTaskId, helper.id, this.tasks.helperReport(helper)); return; @@ -2022,8 +2036,15 @@ export class Engine { const result = await this.runBotTurn({ bot, chatId, text, kind: group ? 'group' : 'helper' }); if (result.messageId) { helper.resultMessageId = result.messageId; - await this.store.save(); + // The page has to hear that the job is over before the write, not after it: the status is + // already final in memory, and a write that fails is no reason to leave the row reading + // "running" for good. The write itself still has to happen, and its failure is reported. this.broadcastHelpers(); + try { + await this.store.save(); + } catch (error) { + this.logger.warn('minimax_bot.helper_report_save_failed', { helperId: helper.id, code: error?.code ?? 'unknown' }); + } } // In a group the relay is a normal member turn: hand off to whoever it @mentions. if (!group || result.status !== 'done' || result.pendingQuestion || PASS_RE.test(result.text)) return; diff --git a/plugins/minimax-ai/minimax-bot/miniapp/node/mcp.mjs b/plugins/minimax-ai/minimax-bot/miniapp/node/mcp.mjs index a6473f79..816891ef 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.41' }, instructions: t('mcp.instructions'), }; break; diff --git a/plugins/minimax-ai/minimax-bot/package.json b/plugins/minimax-ai/minimax-bot/package.json index e799ef2e..27a00780 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.41", "private": true, "type": "module", "mcode": { diff --git a/plugins/minimax-ai/minimax-bot/tests/helper-usage.test.mjs b/plugins/minimax-ai/minimax-bot/tests/helper-usage.test.mjs index e317f323..eb603cb1 100644 --- a/plugins/minimax-ai/minimax-bot/tests/helper-usage.test.mjs +++ b/plugins/minimax-ai/minimax-bot/tests/helper-usage.test.mjs @@ -262,3 +262,64 @@ test('a job stopped and then killed still leaves its turn in the ledger', async assert.equal(background.status, 'aborted'); assert.equal(background.turnId, store.state.helpers[0].id); }); + +test('a background job whose closing write fails still stops reading as running', async (t) => { + const { store, engine } = await fixture(t); + const bot = { id: 'bot_a', name: 'Alice', role: 'Writer' }; + store.state.bots = [bot]; + const chatId = `bot:${bot.id}`; + const helperDone = deferred(); + const seen = []; + const calls = []; + engine.agent = { async run(input, options) { + calls.push(input.text); + const ids = { sessionId: `session-${calls.length}`, turnId: `turn-${calls.length}` }; + options.onEvent({ type: 'turn.started', ...ids }); + if (input.text.startsWith(HELPER_PROMPT)) { + await helperDone.promise; + return { ...ids, status: 'finished', text: 'BACKGROUND_ANSWER' }; + } + if (input.text.endsWith('START_BACKGROUND')) { + await engine.startHelper(bot, { task: 'Look this up' }); + return { ...ids, status: 'finished', text: 'Started' }; + } + return { ...ids, status: 'finished', text: 'Relay' }; + } }; + // The panel is told the job's status through these broadcasts, and nothing else updates it. + const realBroadcastHelpers = engine.broadcastHelpers.bind(engine); + engine.broadcastHelpers = (...args) => { + realBroadcastHelpers(...args); + seen.push(...(store.state.helpers ?? []).map((helper) => helper.status)); + }; + + await engine.runBotTurn({ bot, chatId, text: 'START_BACKGROUND', kind: 'private' }); + await until(() => store.state.helpers[0]?.status === 'running'); + // The job finishes, and the writes that close it out fail. Only those fail: the ones before + // them still have to land, or the job never reaches its final state at all and the test + // would be measuring something else. + const realSave = store.save.bind(store); + const saves = { total: 0, failed: 0 }; + store.save = async (...args) => { + saves.total += 1; + const settled = (store.state.helpers ?? []).some((helper) => helper.status === 'done' || helper.status === 'stopped'); + if (settled) { + saves.failed += 1; + throw Object.assign(new Error('no space left'), { code: 'ENOSPC' }); + } + return realSave(...args); + }; + helperDone.resolve(); + + // The closing write has to be reached, or none of this says anything: the job's own turn + // (calls[1]) and the relay turn that follows it (calls[2]) are both before it. + await until(() => store.state.helpers[0]?.status === 'done'); + await until(() => calls.length >= 3, 'the relay turn ran'); + await until(() => saves.failed >= 1, 'the closing write failed'); + + assert.equal(store.state.helpers[0].status, 'done'); + assert.ok(seen.includes('done'), `the page was never told the job finished: saw ${seen.join(',')}`); + // The relay turn is the third one: the user's, the job's own, and the one that hands the + // report over. The write under test is the one after it. + assert.ok(calls.length >= 3, `the relay turn never ran: saw ${calls.length} calls`); + assert.ok(saves.failed >= 1, 'the closing write was never attempted'); +});