From 083b6553da9766ff12c8103a59474ada3f6a3ead Mon Sep 17 00:00:00 2001 From: Apageoflove Date: Mon, 16 Nov 2026 03:20:34 -0500 Subject: [PATCH 1/2] =?UTF-8?q?fix(minimax-bot):=20=E6=96=B0=E5=BB=BA?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E6=97=B6=E4=B8=8D=E5=86=8D=E7=95=99=E4=B8=8B?= =?UTF-8?q?=E5=B9=BD=E7=81=B5=E5=AF=B9=E8=B1=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 建 Bot、建群、建定时任务都是先改内存里的 state 再 await save()。save 抛错 时新对象已经在内存里,接口回 500,用户以为没建成,可它还在;之后任何一次 无关保存都会把它写进 state.json,重启后仍留在队伍里。 updateBot 的注释里已经写明这条原则(a rejected request must leave no trace), startHelper 也有同样的回滚,只有这三个 create 路径没做。 save 失败时把状态退回去:createBot / createGroup 摘掉刚 push 的对象后重新 抛错;saveSchedule 新建就摘掉,更新就把改之前的字段值盖回去。 两条新测试在 0.7.28 上红、在切片上绿。全量 415 条通过。 --- .../minimax-bot/.minimax-plugin/plugin.json | 2 +- plugins/minimax-ai/minimax-bot/README.md | 5 ++ .../minimax-bot/miniapp/node/mcp.mjs | 2 +- .../minimax-bot/miniapp/node/team.mjs | 30 ++++++++++-- plugins/minimax-ai/minimax-bot/package.json | 2 +- .../tests/storage-reliability.test.mjs | 46 +++++++++++++++++++ 6 files changed, 81 insertions(+), 6 deletions(-) diff --git a/plugins/minimax-ai/minimax-bot/.minimax-plugin/plugin.json b/plugins/minimax-ai/minimax-bot/.minimax-plugin/plugin.json index e08811fe..b6cfa02e 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.28", + "version": "0.7.30", "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 fd2d8c50..98632125 100644 --- a/plugins/minimax-ai/minimax-bot/README.md +++ b/plugins/minimax-ai/minimax-bot/README.md @@ -100,6 +100,11 @@ The hand-over between two Bots of a group carried the tail of the previous reply - **Start new chat**, deleting a Bot and deleting a group all empty the transcript and then write the state that forgets the chat. When that state write failed, the empty transcript was already on disk: the request reported a failure, the chat was still listed, and its history was gone for good. - The state is now written first, and the in-memory session entry is dropped only after that write succeeded. A failure leaves the chat, its messages and its session cursor as they were, so the same action can simply be tried again. +## 0.7.30 A create that fails does not leave the thing behind + +- Creating a Bot, a group or a scheduled task writes into the live state and then saves it. When that save failed, the new object stayed in memory: the request reported a failure while the Bot, group or task was already there, and the next unrelated save — changing a setting, any other write — published it to disk. After a restart the thing the user was told had failed was in the team. +- A failed save now puts the state back: a new object is removed and a changed schedule returns to the values still on disk, so a refusal leaves nothing for a later save to publish. This is the rule `updateBot` already followed; the three create paths now do the same. + ## 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 74d9def9..768cfd99 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.28' }, + serverInfo: { name: 'minimax-bot', version: '0.7.30' }, 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 48e51eb6..c933d592 100644 --- a/plugins/minimax-ai/minimax-bot/miniapp/node/team.mjs +++ b/plugins/minimax-ai/minimax-bot/miniapp/node/team.mjs @@ -180,7 +180,15 @@ export class Team { if (avatar) bot.avatar = await this.saveAvatar(avatar); this.store.state.bots.push(bot); this.store.bumpRoster(); - await this.store.save(); + try { + await this.store.save(); + } catch (error) { + // Same rule as updateBot: a rejected request leaves no trace. Without this the Bot stays in + // memory after a failed save, and the next unrelated save publishes what the user was told + // had failed. + this.store.state.bots = this.store.state.bots.filter((item) => item.id !== bot.id); + throw error; + } this.changed(); return bot; } @@ -379,7 +387,14 @@ export class Team { }; this.store.state.groups.push(group); this.store.bumpRoster(); - await this.store.save(); + try { + await this.store.save(); + } catch (error) { + // A rejected request leaves no trace: a group kept in memory after a failed save would be + // published by the next unrelated save, under a name the user was told was refused. + this.store.state.groups = this.store.state.groups.filter((item) => item.id !== group.id); + throw error; + } const welcome = await this.store.appendMessage(`group:${group.id}`, { role: 'system', key: 'notice.groupCreated', @@ -595,6 +610,9 @@ export class Team { } if (kind === 'once' && !runAt) throw new EngineError('invalid', t('err.scheduleInMinutes')); const schedule = existing ?? { id: newId('sch'), createdAt: Date.now() }; + // The previous values, so a failed save can put the object back: a schedule left in memory + // would be published by the next unrelated save, at a time the user was told was refused. + const before = existing ? { ...existing } : undefined; if (!existing) list.push(schedule); Object.assign(schedule, { name: String(input.name ?? '').trim().slice(0, 40) || prompt.slice(0, 20), @@ -607,7 +625,13 @@ export class Team { enabled: input.enabled !== false, }); schedule.nextRunAt = nextRun(schedule, Date.now()); - await this.store.save(); + try { + await this.store.save(); + } catch (error) { + if (before) Object.assign(schedule, before); + else this.store.state.schedules = this.store.state.schedules.filter((item) => item.id !== schedule.id); + throw error; + } this.changed(); return schedule; } diff --git a/plugins/minimax-ai/minimax-bot/package.json b/plugins/minimax-ai/minimax-bot/package.json index 8035a030..aa7d48cd 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.28", + "version": "0.7.30", "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 6363b979..691ee5a0 100644 --- a/plugins/minimax-ai/minimax-bot/tests/storage-reliability.test.mjs +++ b/plugins/minimax-ai/minimax-bot/tests/storage-reliability.test.mjs @@ -125,6 +125,52 @@ test('a session created while another chat is being deleted survives in memory a assert.equal(restored.getSession(other, bot.id)?.sessionId, 'session-other'); }); +test('a create that cannot be saved leaves nothing behind for a later save to publish', async (t) => { + const { dir, store, chat } = 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]; + + // A directory where state.json belongs makes every save in this test fail. + const statePath = join(dir, 'state.json'); + await rm(statePath, { force: true }); + await mkdir(statePath, { recursive: true }); + + // Every create refuses, and the refusal has to be complete: a Bot or group left in memory would + // be published by the next unrelated save, after the user was told it had failed. + await assert.rejects(team.createBot(null, { name: 'Ghost Bot', instructions: 'x' })); + assert.equal(store.state.bots.some((item) => item.name === 'Ghost Bot'), false); + await assert.rejects(team.createGroup(null, { name: 'Ghost Group', members: [bot.id] })); + assert.equal(store.state.groups.some((item) => item.name === 'Ghost Group'), false); + await assert.rejects(team.saveSchedule({ botId: bot.id, prompt: 'Ghost Schedule', kind: 'daily', time: '09:00' })); + assert.equal(store.state.schedules.some((item) => item.prompt === 'Ghost Schedule'), false); + + // Storage recovers and something unrelated writes the state: the refused objects must stay gone. + await rm(statePath, { recursive: true, force: true }); + await store.save(); + const onDisk = JSON.parse(await readFile(statePath, 'utf8')); + assert.equal(onDisk.bots.some((item) => item.name === 'Ghost Bot'), false); + assert.equal(onDisk.groups.some((item) => item.name === 'Ghost Group'), false); + assert.equal(onDisk.schedules.some((item) => item.prompt === 'Ghost Schedule'), false); +}); + +test('a schedule update that cannot be saved keeps the values the user was shown', 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: 'Original prompt', kind: 'daily', time: '09:00' }); + await store.writeChain; + + const statePath = join(dir, 'state.json'); + await rm(statePath, { force: true }); + await mkdir(statePath, { recursive: true }); + await assert.rejects(team.saveSchedule({ id: schedule.id, botId: bot.id, prompt: 'Refused prompt', kind: 'daily', time: '09:00' })); + + // The in-memory object must go back to what is still on disk, not keep the refused values. + const current = store.state.schedules.find((item) => item.id === schedule.id); + assert.equal(current.prompt, 'Original prompt'); +}); 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.' }]; From 53cc49b6a17db5672d96a07d27d6b697db64c310 Mon Sep 17 00:00:00 2001 From: Apageoflove Date: Tue, 17 Nov 2026 20:19:20 -0500 Subject: [PATCH 2/2] =?UTF-8?q?fix(minimax-bot):=20=E6=97=A5=E7=A8=8B?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=A4=B1=E8=B4=A5=E4=B8=8D=E5=86=8D=E5=9B=9E?= =?UTF-8?q?=E6=BB=9A=E6=8E=89=E5=88=AB=E4=BA=BA=E5=B7=B2=E6=88=90=E5=8A=9F?= =?UTF-8?q?=E7=9A=84=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 维护者指出 083b655 的回滚会覆盖并发成功的修改:同一日程初始 A,B 的保存 被挂起,期间 C 成功,再让 B 以 EIO 失败,结果内存和磁盘都回到 A,C 丢了。 原因是 B 在共享对象上原地改、失败时用 Object.assign 把整个旧值盖回去, 而 C 改的正是同一个对象。 改成 draft 写法,与 updateBot 一致:新的值建成一个独立对象放进列表,save 成功才返回;失败时只在列表里还找得到这个对象时把它换回原对象,别的调用方 已经换掉的就不动。 新测试照维护者的场景:卡住 B 的保存、让 C 成功、再让 B 失败,断言最终是 C。 这条在 083b655 上红、在本次提交上绿。全量 416 条通过。 --- .../minimax-bot/miniapp/node/team.mjs | 31 ++++++++++------ .../tests/storage-reliability.test.mjs | 37 +++++++++++++++++++ 2 files changed, 57 insertions(+), 11 deletions(-) diff --git a/plugins/minimax-ai/minimax-bot/miniapp/node/team.mjs b/plugins/minimax-ai/minimax-bot/miniapp/node/team.mjs index c933d592..d9b212ef 100644 --- a/plugins/minimax-ai/minimax-bot/miniapp/node/team.mjs +++ b/plugins/minimax-ai/minimax-bot/miniapp/node/team.mjs @@ -610,11 +610,11 @@ export class Team { } if (kind === 'once' && !runAt) throw new EngineError('invalid', t('err.scheduleInMinutes')); const schedule = existing ?? { id: newId('sch'), createdAt: Date.now() }; - // The previous values, so a failed save can put the object back: a schedule left in memory - // would be published by the next unrelated save, at a time the user was told was refused. - const before = existing ? { ...existing } : undefined; - if (!existing) list.push(schedule); - Object.assign(schedule, { + // Build the next value beside the live object and publish it only once the save went through. + // Editing in place and restoring on failure would also undo an update another caller completed + // while this save was in flight: it wrote into the same object this call is holding. + const next = { + ...schedule, name: String(input.name ?? '').trim().slice(0, 40) || prompt.slice(0, 20), botId: bot.id, prompt: prompt.slice(0, 4000), @@ -623,17 +623,26 @@ export class Team { everyMinutes, runAt: kind === 'once' ? runAt : undefined, enabled: input.enabled !== false, - }); - schedule.nextRunAt = nextRun(schedule, Date.now()); + }; + next.nextRunAt = nextRun(next, Date.now()); + if (!existing) list.push(next); + else list[list.indexOf(schedule)] = next; try { await this.store.save(); + return next; } catch (error) { - if (before) Object.assign(schedule, before); - else this.store.state.schedules = this.store.state.schedules.filter((item) => item.id !== schedule.id); + // Put the list back the way it was; a concurrent caller that got here first keeps its value. + if (!existing) { + const at = list.indexOf(next); + if (at !== -1) list.splice(at, 1); + } else { + const at = list.indexOf(next); + if (at !== -1) list[at] = schedule; + } throw error; + } finally { + this.changed(); } - this.changed(); - return schedule; } /** 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 691ee5a0..cd06ac84 100644 --- a/plugins/minimax-ai/minimax-bot/tests/storage-reliability.test.mjs +++ b/plugins/minimax-ai/minimax-bot/tests/storage-reliability.test.mjs @@ -295,3 +295,40 @@ test('delivery transitions commit a complete batch or leave every message unchan assert.deepEqual(saved.map((message) => message.dispatchState), ['delivered', 'delivered']); assert.deepEqual(saved.map((message) => message.dispatchRevision), [1, 1]); }); + +test('a refused schedule update does not undo an update that succeeded while it was saving', 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: 'A', kind: 'daily', time: '09:00' }); + await store.writeChain; + + // B starts saving and is held; C then saves successfully; B finally fails. + let releaseB; + const heldB = new Promise((resolve) => { releaseB = resolve; }); + const realSave = store.save.bind(store); + let holding = true; + store.save = async () => { + if (holding && store.state.schedules.some((item) => item.prompt === 'B')) { holding = false; await heldB; } + return realSave(); + }; + const b = team.saveSchedule({ id: schedule.id, botId: bot.id, prompt: 'B', kind: 'daily', time: '09:00' }); + await new Promise((resolve) => setTimeout(resolve, 20)); + const c = await team.saveSchedule({ id: schedule.id, botId: bot.id, prompt: 'C', kind: 'daily', time: '09:00' }); + assert.equal(store.state.schedules.find((item) => item.id === schedule.id).prompt, 'C'); + + // Make B's write fail, then let it go. + const statePath = join(dir, 'state.json'); + await rm(statePath, { force: true }); + await mkdir(statePath, { recursive: true }); + releaseB(); + await assert.rejects(b); + store.save = realSave; + + // B's refusal must not roll the shared object back past C's success. + const current = store.state.schedules.find((item) => item.id === schedule.id); + assert.equal(current.prompt, 'C'); + assert.equal(store.state.schedules.length, 1); + assert.equal(c.prompt, 'C'); +});