diff --git a/plugins/minimax-ai/minimax-bot/.minimax-plugin/plugin.json b/plugins/minimax-ai/minimax-bot/.minimax-plugin/plugin.json index 3fdf839a..6fc01b30 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.41", + "version": "0.7.45", "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 88ab2502..3f1190c5 100644 --- a/plugins/minimax-ai/minimax-bot/README.md +++ b/plugins/minimax-ai/minimax-bot/README.md @@ -171,6 +171,12 @@ The hand-over between two Bots of a group carried the tail of the previous reply - 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.45 A refused schedule delete leaves the schedule where it was + +- Deleting a scheduled task removed it from memory before the write. If the write failed, the caller saw the failure, but the schedule was already gone from memory; the next unrelated save then wrote that absence to disk, and the task disappeared for good. +- The delete now puts back only the schedule it removed when the write fails. It does not restore the old array, so another change made while the write was in flight is kept. The state is broadcast again after the rollback, and a later save or restart still finds the schedule. +- The successful path is unchanged: the schedule is removed, the write lands, and the page hears the change. + ## 0.7.10 Optional group notes - 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. diff --git a/plugins/minimax-ai/minimax-bot/miniapp/node/mcp.mjs b/plugins/minimax-ai/minimax-bot/miniapp/node/mcp.mjs index 816891ef..f550e284 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.41' }, + serverInfo: { name: 'minimax-bot', version: '0.7.45' }, instructions: t('mcp.instructions'), }; break; diff --git a/plugins/minimax-ai/minimax-bot/miniapp/node/team.mjs b/plugins/minimax-ai/minimax-bot/miniapp/node/team.mjs index 7869b822..74348cb1 100644 --- a/plugins/minimax-ai/minimax-bot/miniapp/node/team.mjs +++ b/plugins/minimax-ai/minimax-bot/miniapp/node/team.mjs @@ -681,9 +681,25 @@ export class Team { } async deleteSchedule(id) { - this.store.state.schedules = this.store.state.schedules.filter((s) => s.id !== id); - await this.store.save(); - this.changed(); + const list = this.store.state.schedules; + const index = list.findIndex((schedule) => schedule.id === id); + if (index < 0) return; + const schedule = list[index]; + this.store.state.schedules = list.filter((item) => item.id !== id); + try { + await this.store.save(); + } catch (error) { + // The user was told the delete failed, so the schedule has to still be there. Put back + // only this schedule: another caller may have changed the list while the write was in + // flight, and restoring the old array would throw that change away. + const current = this.store.state.schedules; + if (!current.some((item) => item.id === id)) { + current.splice(Math.min(index, current.length), 0, schedule); + } + throw error; + } finally { + this.changed(); + } } // ---------------------------------------------------------------- read models diff --git a/plugins/minimax-ai/minimax-bot/package.json b/plugins/minimax-ai/minimax-bot/package.json index 27a00780..d273d38a 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.41", + "version": "0.7.45", "private": true, "type": "module", "mcode": { diff --git a/plugins/minimax-ai/minimax-bot/tests/storage-reliability.test.mjs b/plugins/minimax-ai/minimax-bot/tests/storage-reliability.test.mjs index cd06ac84..90aa2964 100644 --- a/plugins/minimax-ai/minimax-bot/tests/storage-reliability.test.mjs +++ b/plugins/minimax-ai/minimax-bot/tests/storage-reliability.test.mjs @@ -1,6 +1,6 @@ import assert from 'node:assert/strict'; import { test } from 'node:test'; -import { appendFile, mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises'; +import { appendFile, mkdir, mkdtemp, readFile, rename, rm, writeFile } from 'node:fs/promises'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; import { Store } from '../miniapp/node/store.mjs'; @@ -171,6 +171,64 @@ test('a schedule update that cannot be saved keeps the values the user was shown const current = store.state.schedules.find((item) => item.id === schedule.id); assert.equal(current.prompt, 'Original prompt'); }); + +test('a schedule delete that cannot be saved keeps the schedule in memory and on disk', async (t) => { + const { dir, store } = await fixture(t); + const { Team } = await import('../miniapp/node/team.mjs'); + const team = new Team({ store, memory: undefined, engine: { cancelBot() {}, cancelChat() {} }, broadcast() {} }); + const bot = store.state.bots[0]; + const schedule = await team.saveSchedule({ botId: bot.id, prompt: 'Keep me', kind: 'daily', time: '09:00' }); + await store.writeChain; + + const statePath = join(dir, 'state.json'); + const savedPath = join(dir, 'state.saved.json'); + await rename(statePath, savedPath); + await mkdir(statePath); // real EISDIR at rename(tmp, statePath) + await assert.rejects(team.deleteSchedule(schedule.id)); + + // The delete was refused, so the schedule must still be in memory and in the copy that is + // still on disk. A later unrelated save must not publish the refused delete. + assert.equal(store.state.schedules.some((item) => item.id === schedule.id), true); + const onDisk = JSON.parse(await readFile(savedPath, 'utf8')); + assert.equal(onDisk.schedules.some((item) => item.id === schedule.id), true); + + await rm(statePath, { recursive: true }); + await rename(savedPath, statePath); + await store.save(); + const reloaded = new Store(dir); + await reloaded.init(); + assert.equal(reloaded.state.schedules.some((item) => item.id === schedule.id), true); +}); + +test('a refused schedule delete does not undo another change made while the save was in flight', async (t) => { + const { store } = await fixture(t); + const { Team } = await import('../miniapp/node/team.mjs'); + const team = new Team({ store, memory: undefined, engine: { cancelBot() {}, cancelChat() {} }, broadcast() {} }); + const bot = store.state.bots[0]; + const schedule = await team.saveSchedule({ botId: bot.id, prompt: 'Delete me', kind: 'daily', time: '09:00' }); + await store.writeChain; + + const realSave = store.save.bind(store); + let rejectSave; + let saveStarted; + const started = new Promise((resolve) => { saveStarted = resolve; }); + store.save = () => { + saveStarted(); + return new Promise((resolve, reject) => { rejectSave = reject; }); + }; + const deleting = team.deleteSchedule(schedule.id); + await started; + const other = { ...schedule, id: 'sch_other', prompt: 'Added while the delete was waiting' }; + store.state.schedules.push(other); + rejectSave(Object.assign(new Error('storage unavailable'), { code: 'EIO' })); + await assert.rejects(deleting); + store.save = realSave; + + assert.equal(store.state.schedules.some((item) => item.id === schedule.id), true, + 'the refused delete is rolled back'); + assert.equal(store.state.schedules.some((item) => item.id === other.id), true, + 'the other change is kept'); +}); test('legacy sequence migration preserves text/tool order and stable cursors across restarts', async (t) => { const { dir, store, chat } = await fixture(t); const parts = [{ type: 'text', text: 'The current conclusion: ' }, { type: 'tool', name: 'build', state: 'ok' }, { type: 'text', text: 'The current conclusion: publish after the build passes.' }];