From 688286772acbf11fc3f8e6ccfcdc7d8a28c45b32 Mon Sep 17 00:00:00 2001 From: Apageoflove Date: Mon, 16 Nov 2026 01:35:39 -0500 Subject: [PATCH 1/3] =?UTF-8?q?fix(minimax-bot):=20=E9=87=8D=E5=90=AF?= =?UTF-8?q?=E5=90=8E=E5=B7=B2=E6=94=B6=E4=B8=8B=E7=9A=84=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E8=BF=98=E8=83=BD=E5=86=8D=E5=8F=91=E5=87=BA=E5=8E=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 宿主在没有页面可见时可以停掉插件的 Node 进程,不通知也不回调。一条已经收下、 还没产出回复的请求,重启后被 store 映射回 pending,而 pending 的含义是内存里 那个队列会负责发它——队列已经跟进程一起没了。续跑只认 held,页面按钮也只对 held 画,手动调 resume-pending 回 busy,这条请求就再也发不出去。 resumeHeld 放宽到也收这种 pending,判据用重试路径本来就在用的那条:没有任何 回复引用它,也没有落盘的助手占位,说明它从没到过宿主。队列里还活着的请求被 this.has() 排除,不会重复派发。页面在同样条件下画出本来就有的 Continue with follow-ups,并用 dispatchRevision 区分刚发出的新消息,避免它给自己画按钮。 不自动重放:进程停之前那一回合可能已经跑过工具,再发一次由用户决定。 store 的状态映射未改动,客户端按 clientMessageId 重试的路径保持原样。 两条新测试在未改的上游上红、在本切片上绿。全量 415 条通过(0.7.28 基线 411, 加上 #135 的两条和本切片的兩条)。 --- .../minimax-bot/.minimax-plugin/plugin.json | 2 +- plugins/minimax-ai/minimax-bot/README.md | 6 +++ .../minimax-bot/miniapp/client/app.js | 9 ++++- .../minimax-bot/miniapp/node/mcp.mjs | 2 +- .../minimax-bot/miniapp/node/user-inbox.mjs | 10 ++++- plugins/minimax-ai/minimax-bot/package.json | 2 +- .../tests/client-reliability.test.mjs | 16 ++++++++ .../tests/engine-reliability.test.mjs | 38 +++++++++++++++++++ 8 files changed, 80 insertions(+), 5 deletions(-) diff --git a/plugins/minimax-ai/minimax-bot/.minimax-plugin/plugin.json b/plugins/minimax-ai/minimax-bot/.minimax-plugin/plugin.json index b6cfa02e..27ecf749 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.30", + "version": "0.7.31", "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 98632125..5e74fbf3 100644 --- a/plugins/minimax-ai/minimax-bot/README.md +++ b/plugins/minimax-ai/minimax-bot/README.md @@ -105,6 +105,12 @@ The hand-over between two Bots of a group carried the tail of the previous reply - 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.31 A request the plugin already accepted is still sendable after a restart + +- MiniMax Code may stop the plugin's Node process while no page is visible, and it does so without a callback. A request that was already accepted and had produced no reply used to come back as waiting for a queue that no longer existed: it stayed in the chat with no answer, the page offered no way to send it again, and the resume route refused it. The request was unreachable for good. +- 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. +- A request whose reply had already started is unchanged, and a request this page has just sent never offers to resume itself. + ## 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/client/app.js b/plugins/minimax-ai/minimax-bot/miniapp/client/app.js index 35518904..9f033724 100644 --- a/plugins/minimax-ai/minimax-bot/miniapp/client/app.js +++ b/plugins/minimax-ai/minimax-bot/miniapp/client/app.js @@ -792,7 +792,14 @@ function userDelivery(message) { const status = message.dispatchState; if (!status || status === 'processing' || status === 'delivered') return null; const key = `${message.chatId}:${message.id}`; - const button = status === 'held' ? h('button', { + // A restart leaves an accepted request pending with no queue left to send it and nothing running. + // Offer the same resume on the proof the server uses: nothing was ever written back for it. + // dispatchRevision is only written when a delivery state changes, so a request this page just + // sent has none yet and never offers to resume itself. + const stranded = status === 'pending' && message.dispatchRevision > 0 && !state.busy.has(message.chatId) + && !(state.messages.get(message.chatId) ?? []).some( + (item) => item.sourceMessageId === message.id || item.sourceMessageIds?.includes(message.id)); + const button = status === 'held' || stranded ? h('button', { type: 'button', class: 'btn sm', disabled: deliveryActions.has(key), onclick: async (event) => { if (deliveryActions.has(key)) return; diff --git a/plugins/minimax-ai/minimax-bot/miniapp/node/mcp.mjs b/plugins/minimax-ai/minimax-bot/miniapp/node/mcp.mjs index 768cfd99..aa693a48 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.30' }, + serverInfo: { name: 'minimax-bot', version: '0.7.31' }, instructions: t('mcp.instructions'), }; break; diff --git a/plugins/minimax-ai/minimax-bot/miniapp/node/user-inbox.mjs b/plugins/minimax-ai/minimax-bot/miniapp/node/user-inbox.mjs index 61706491..f25f44be 100644 --- a/plugins/minimax-ai/minimax-bot/miniapp/node/user-inbox.mjs +++ b/plugins/minimax-ai/minimax-bot/miniapp/node/user-inbox.mjs @@ -149,7 +149,15 @@ export class UserInbox { async resumeHeld(chatId) { // Only resend supplements that never started; an uncertain original request is never replayed. const history = await this.engine.store.getMessages(chatId); - const held = history.filter((message) => message.role === 'user' && message.dispatchState === 'held' && !this.has(message.id)); + const held = history.filter((message) => { + if (message.role !== 'user' || this.has(message.id)) return false; + if (message.dispatchState === 'held') return true; + // A restart leaves an accepted request `pending` with the queue that owned it gone. It is + // recoverable on the same proof the retry path uses: no reply and no durable assistant + // placeholder means the request never reached the Host. + return message.dispatchState === 'pending' + && !history.some((item) => item.sourceMessageId === message.id || item.sourceMessageIds?.includes(message.id)); + }); if (!held.length || this.busy(chatId) || [...this.engine.tickets].some((ticket) => ticket.chatId === chatId)) { throw new this.ErrorType('busy', t('err.messageAlreadyProcessing')); } diff --git a/plugins/minimax-ai/minimax-bot/package.json b/plugins/minimax-ai/minimax-bot/package.json index aa7d48cd..1b8fad54 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.30", + "version": "0.7.31", "private": true, "type": "module", "mcode": { diff --git a/plugins/minimax-ai/minimax-bot/tests/client-reliability.test.mjs b/plugins/minimax-ai/minimax-bot/tests/client-reliability.test.mjs index 4063caa4..f909b383 100644 --- a/plugins/minimax-ai/minimax-bot/tests/client-reliability.test.mjs +++ b/plugins/minimax-ai/minimax-bot/tests/client-reliability.test.mjs @@ -570,6 +570,22 @@ test('held supplements require an explicit continuation and a failed action leav assert.equal(calls.filter((call) => call.path.endsWith('/resume-pending')).length, 1); }); +test('a request stranded by a restart offers to send it again, and one this page just sent does not', async () => { + // dispatchRevision is written when a delivery state changes, so a recovered request has one and + // a request the composer just created does not. + const stranded = message('msg_stranded', 'Ship the hotfix', { role: 'user', dispatchState: 'pending', dispatchRevision: 1 }); + await reset([stranded]); + const button = document.querySelector('.message-delivery button'); + assert.equal(button.textContent, 'Continue with follow-ups'); + route = ({ path }) => path.endsWith('/resume-pending') ? response({ ok: true }) : undefined; + button.click(); await settle(); + assert.equal(calls.filter((call) => call.path.endsWith('/resume-pending')).length, 1); + + const fresh = message('msg_fresh', 'Just typed', { role: 'user', dispatchState: 'pending' }); + await reset([fresh]); + assert.equal(document.querySelector('.message-delivery button'), null); +}); + test('a delayed send receipt cannot restore an obsolete pending state after the live processing event', async () => { await reset(); const user = message('msg_receipt', 'Request', { role: 'user', dispatchState: 'pending', dispatchRevision: 0 }); diff --git a/plugins/minimax-ai/minimax-bot/tests/engine-reliability.test.mjs b/plugins/minimax-ai/minimax-bot/tests/engine-reliability.test.mjs index 4de0eb3d..9f2e312f 100644 --- a/plugins/minimax-ai/minimax-bot/tests/engine-reliability.test.mjs +++ b/plugins/minimax-ai/minimax-bot/tests/engine-reliability.test.mjs @@ -648,6 +648,44 @@ test('an interrupted associated assistant is reported as uncertain, and legacy m await restored.writeChain; }); +test('a request whose queue died with the process is still sendable from the page', async (t) => { + const { dir, store, memory, engine } = await fixture(t); + const bot = store.state.bots[0]; + const chatId = `bot:${bot.id}`; + // The process died after the inbox marked the batch processing and before any reply existed. + const user = await store.appendMessage(chatId, { + role: 'user', text: 'Ship the hotfix', clientMessageId: 'orphan-1', + clientMessageHash: engine.userMessageFingerprint('Ship the hotfix', []), dispatchState: 'processing', + }); + await store.writeChain; + + const restored = new Store(dir); + await restored.init(); + let runs = 0; + const reopened = new Engine({ store: restored, memory, logger: { warn() {} }, broadcast() {}, retryDelaysMs: [], agent: { + async run(input, options) { runs += 1; return { ...started(input, options, 'resumed'), status: 'finished', text: 'Shipped' }; }, + } }); + reopened.startScheduler(); + reopened.tasks.start(); + + // The load-time mapping keeps `pending`, which the client retry path needs. The queue that owned + // it is gone, so the resume route has to recognise it too or the request is stranded for good. + const afterRestart = (await restored.getMessages(chatId)).find((message) => message.id === user.id); + assert.equal(afterRestart.dispatchState, 'pending'); + await until(() => idle(reopened)); + // Nothing replays it on its own: the turn may already have run tools before the process died. + assert.equal(runs, 0); + + await reopened.inbox.resume(chatId); + await until(() => idle(reopened)); + assert.equal(runs, 1); + const messages = await restored.getMessages(chatId); + assert.equal(messages.find((message) => message.id === user.id).dispatchState, 'delivered'); + assert.equal(messages.filter((message) => message.sourceMessageId === user.id).length, 1); + reopened.dispose(); + await restored.writeChain; +}); + test('repeated pending submissions do not duplicate queued turns or revive a deliberately cancelled queue', async (t) => { const { store, engine } = await fixture(t); const bot = store.state.bots[0]; From 26f8e7ae24fdf09024857065afc9d56e8dc36c95 Mon Sep 17 00:00:00 2001 From: Apageoflove Date: Tue, 17 Nov 2026 20:11:18 -0500 Subject: [PATCH 2/3] =?UTF-8?q?fix(minimax-bot):=20=E6=81=A2=E5=A4=8D?= =?UTF-8?q?=E4=B8=8E=E5=90=8C=20ID=20=E9=87=8D=E8=AF=95=E5=B9=B6=E5=8F=91?= =?UTF-8?q?=E6=97=B6=E4=B8=8D=E5=86=8D=E6=89=A7=E8=A1=8C=E4=B8=A4=E6=AC=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 维护者指出 resumeHeld 通过 has() 之后还有一次异步写盘,随后直接入队, 没有再次检查;这期间同一 clientMessageId 的发送重试可能已把消息入队并 开始执行,于是同一请求跑两遍、回两条。 两处收口: - updateMessages 增加可选的条件谓词 when,只更新仍处于调用方观察到 的状态里的消息。resumeHeld 用它把选择限定在 held/pending,重试已经 改成 processing 或 delivered 的消息不会被它改写。 - enqueue 开头按 message.id 去重,一条消息只进队列一次。 页面与服务端的恢复条件也对齐了。服务端本来就不看 dispatchRevision, 页面却要求它 > 0,所以「消息已落盘、进程在标记 processing 前退出」留下的 pending(没有 dispatchRevision)服务端能恢复而页面没有按钮。现在页面改 用一个本会话已发送 id 的集合来区分「刚由输入框发出」与「重启留下的」, 两端都接受没有 dispatchRevision 的 pending。 两条新测试:一条卡住 resume 的写盘、让同 id 重试先跑,断言只有 1 次 Agent 调用和 1 条回复;一条走真实发送路径,断言刚发出的消息不画续跑按钮。 前者在 c43eeaf 上红、在本次提交上绿。全量 416 条通过。 --- .../minimax-bot/miniapp/client/app.js | 16 ++++--- .../minimax-bot/miniapp/node/store.mjs | 9 ++-- .../minimax-bot/miniapp/node/user-inbox.mjs | 15 +++++-- .../tests/client-reliability.test.mjs | 13 ++++-- .../tests/engine-reliability.test.mjs | 44 +++++++++++++++++++ 5 files changed, 82 insertions(+), 15 deletions(-) diff --git a/plugins/minimax-ai/minimax-bot/miniapp/client/app.js b/plugins/minimax-ai/minimax-bot/miniapp/client/app.js index 9f033724..fa936b59 100644 --- a/plugins/minimax-ai/minimax-bot/miniapp/client/app.js +++ b/plugins/minimax-ai/minimax-bot/miniapp/client/app.js @@ -248,6 +248,9 @@ function rowMenu(event, chatId) { const ui = {}; const drafts = new Map(); const submissions = new Map(); +// Message ids this page sent in this session. A request the composer just created is `pending` with +// no reply, exactly like one a restart stranded, and only this set tells them apart. +const sentHere = new Set(); let mounted = ''; let mountRevision = 0; let revealRevision = 0; @@ -793,10 +796,10 @@ function userDelivery(message) { if (!status || status === 'processing' || status === 'delivered') return null; const key = `${message.chatId}:${message.id}`; // A restart leaves an accepted request pending with no queue left to send it and nothing running. - // Offer the same resume on the proof the server uses: nothing was ever written back for it. - // dispatchRevision is only written when a delivery state changes, so a request this page just - // sent has none yet and never offers to resume itself. - const stranded = status === 'pending' && message.dispatchRevision > 0 && !state.busy.has(message.chatId) + // Offer the same resume on the proof the server uses: nothing was ever written back for it. The + // server does not look at `dispatchRevision` either — a request that reached the disk and then + // lost the process before any state change is recoverable too, and it carries no revision. + const stranded = status === 'pending' && !sentHere.has(message.id) && !state.busy.has(message.chatId) && !(state.messages.get(message.chatId) ?? []).some( (item) => item.sourceMessageId === message.id || item.sourceMessageIds?.includes(message.id)); const button = status === 'held' || stranded ? h('button', { @@ -1439,7 +1442,10 @@ async function submit() { const stillHere = () => mounted === chatId && ui.input; try { const result = await api('POST', `/api/chats/${chatId}/messages`, { ...body, clientMessageId: submission.clientMessageId }); - if (result.message?.id && result.message.chatId === chatId) upsertMessage(cacheMessage(result.message)); + if (result.message?.id && result.message.chatId === chatId) { + sentHere.add(result.message.id); + upsertMessage(cacheMessage(result.message)); + } submissions.delete(chatId); // A file added while the POST was pending belongs to the next send. const sentKeys = new Set(ready.map((file) => file.key)); diff --git a/plugins/minimax-ai/minimax-bot/miniapp/node/store.mjs b/plugins/minimax-ai/minimax-bot/miniapp/node/store.mjs index 1c93afbd..7eae5c30 100644 --- a/plugins/minimax-ai/minimax-bot/miniapp/node/store.mjs +++ b/plugins/minimax-ai/minimax-bot/miniapp/node/store.mjs @@ -574,15 +574,18 @@ export class Store { } /** Commit one inbox batch atomically, preserving streaming message object identity. */ - async updateMessages(chatId, messageIds, patch) { + async updateMessages(chatId, messageIds, patch, options = {}) { await this.getMessages(chatId); const ids = new Set(messageIds); return this.enqueue(async () => { const list = this.messageCache.get(chatId) ?? []; - const selected = list.filter((message) => ids.has(message.id)); + // `when` keeps the selection to messages still in the state the caller reached them in: a + // resume that read `held` must not overwrite a state another path wrote while it waited. + const selected = list.filter((message) => ids.has(message.id) && (!options.when || options.when(message))); + const touched = new Set(selected.map((message) => message.id)); const patches = new Map(selected.map((message) => [message.id, Object.hasOwn(patch, 'dispatchState') ? { ...patch, dispatchRevision: (message.dispatchRevision ?? 0) + 1 } : patch])); - await writeJsonAtomic(this.messagePath(chatId), list.map((message) => ids.has(message.id) ? { ...message, ...patches.get(message.id) } : message)); + await writeJsonAtomic(this.messagePath(chatId), list.map((message) => touched.has(message.id) ? { ...message, ...patches.get(message.id) } : message)); for (const message of selected) Object.assign(message, patches.get(message.id)); return selected; }); diff --git a/plugins/minimax-ai/minimax-bot/miniapp/node/user-inbox.mjs b/plugins/minimax-ai/minimax-bot/miniapp/node/user-inbox.mjs index f25f44be..e1ec8f1b 100644 --- a/plugins/minimax-ai/minimax-bot/miniapp/node/user-inbox.mjs +++ b/plugins/minimax-ai/minimax-bot/miniapp/node/user-inbox.mjs @@ -29,6 +29,10 @@ export class UserInbox { } enqueue(chatId, message, bot, group) { + // One message joins the queue once. The resume route computes its list before an awaited write, + // so a retry carrying the same clientMessageId can enqueue the message first; without this the + // same request runs twice and answers twice. + if (this.has(message.id)) return; const queued = [...this.batches].filter((batch) => batch.chatId === chatId && !batch.started && !batch.cancelled); // Append only to the tail so a smaller message cannot overtake an overflow batch. // Supplements arriving during cancellation join this same continuation. @@ -166,12 +170,17 @@ export class UserInbox { if (!bot && !group) throw new this.ErrorType('not_found', t('err.chatMissing')); const uncertainIds = history.filter((message) => message.role === 'user' && message.dispatchState === 'uncertain').map((message) => message.id); await this.engine.store.updateMessages(chatId, uncertainIds, { continuationAcknowledged: true }); - const messages = await this.engine.store.updateMessages(chatId, held.map((message) => message.id), { dispatchState: 'pending' }); + const heldIds = new Set(held.map((message) => message.id)); + // Re-check inside the write: a retry carrying the same clientMessageId can enqueue the message + // while this call waits for the disk, and a message that moved on must not be sent a second + // time. Only the state this call actually reached is still recoverable. + const messages = await this.engine.store.updateMessages(chatId, [...heldIds], { dispatchState: 'pending' }, + { when: (message) => heldIds.has(message.id) && (message.dispatchState === 'held' || message.dispatchState === 'pending') }); for (const message of messages) { + if (this.has(message.id)) continue; this.engine.broadcast({ type: 'message.upsert', chatId, message }); this.enqueue(chatId, message, bot, group); - } - return { ok: true }; + } return { ok: true }; } cancel(chatId, { persist = true } = {}) { diff --git a/plugins/minimax-ai/minimax-bot/tests/client-reliability.test.mjs b/plugins/minimax-ai/minimax-bot/tests/client-reliability.test.mjs index f909b383..4f1550e4 100644 --- a/plugins/minimax-ai/minimax-bot/tests/client-reliability.test.mjs +++ b/plugins/minimax-ai/minimax-bot/tests/client-reliability.test.mjs @@ -571,9 +571,9 @@ test('held supplements require an explicit continuation and a failed action leav }); test('a request stranded by a restart offers to send it again, and one this page just sent does not', async () => { - // dispatchRevision is written when a delivery state changes, so a recovered request has one and - // a request the composer just created does not. - const stranded = message('msg_stranded', 'Ship the hotfix', { role: 'user', dispatchState: 'pending', dispatchRevision: 1 }); + // A request that reached the disk and then lost the process before any state change carries no + // dispatchRevision; it is still recoverable, and the server says so too. + const stranded = message('msg_stranded', 'Ship the hotfix', { role: 'user', dispatchState: 'pending' }); await reset([stranded]); const button = document.querySelector('.message-delivery button'); assert.equal(button.textContent, 'Continue with follow-ups'); @@ -581,8 +581,13 @@ test('a request stranded by a restart offers to send it again, and one this page button.click(); await settle(); assert.equal(calls.filter((call) => call.path.endsWith('/resume-pending')).length, 1); + // A request this page just sent is pending with no reply too; it must not offer to resume itself. + await reset(); const fresh = message('msg_fresh', 'Just typed', { role: 'user', dispatchState: 'pending' }); - await reset([fresh]); + route = ({ path, options }) => path.endsWith('/messages') && options.method === 'POST' + ? response({ message: fresh }) : undefined; + type('Just typed'); enter(); await settle(); + assert.equal(document.querySelector('.message-delivery button'), null); assert.equal(document.querySelector('.message-delivery button'), null); }); diff --git a/plugins/minimax-ai/minimax-bot/tests/engine-reliability.test.mjs b/plugins/minimax-ai/minimax-bot/tests/engine-reliability.test.mjs index 9f2e312f..37a22584 100644 --- a/plugins/minimax-ai/minimax-bot/tests/engine-reliability.test.mjs +++ b/plugins/minimax-ai/minimax-bot/tests/engine-reliability.test.mjs @@ -1275,3 +1275,47 @@ test('sending after Stop does not restore an explicitly cancelled request that n assert.equal(original.dispatchState, 'cancelled'); assert.equal(replacement.dispatchState, 'delivered'); }); + +test('a resume that loses the race to a same-id retry does not send the request twice', async (t) => { + const { dir, store, memory, engine } = await fixture(t); + const bot = store.state.bots[0]; + const chatId = `bot:${bot.id}`; + const text = 'Ship the hotfix'; + // A request the restart left pending, with no reply. + const user = await store.appendMessage(chatId, { + role: 'user', text, clientMessageId: 'race-1', + clientMessageHash: engine.userMessageFingerprint(text, []), dispatchState: 'pending', + }); + await store.writeChain; + + let runs = 0; + engine.agent = { async run(input, options) { + runs += 1; + return { ...started(input, options, 'reply'), status: 'finished', text: 'Reply' }; + } }; + + // Hold the resume's write, so the retry gets in first. + let release; + const gate = new Promise((resolve) => { release = resolve; }); + const realUpdate = store.updateMessages.bind(store); + let held = false; + store.updateMessages = async (id, ids, patch, options) => { + if (!held && patch?.dispatchState === 'pending') { held = true; await gate; } + return realUpdate(id, ids, patch, options); + }; + + const resuming = engine.inbox.resume(chatId).catch((error) => error); + await new Promise((resolve) => setTimeout(resolve, 30)); + await engine.sendUserMessage(chatId, text, [], 'race-1').catch(() => {}); + await new Promise((resolve) => setTimeout(resolve, 60)); + release(); + await resuming; + await until(() => idle(engine)); + + // One request, one turn, one reply that answers it. + assert.equal(runs, 1); + const messages = await store.getMessages(chatId); + assert.equal(messages.filter((message) => message.role === 'bot' && message.sourceMessageId === user.id).length, 1); + engine.dispose(); + await store.writeChain; +}); From 5973b073443bae6e1399d630b31f6631f5a33e91 Mon Sep 17 00:00:00 2001 From: Apageoflove Date: Wed, 18 Nov 2026 04:17:51 -0500 Subject: [PATCH 3/3] =?UTF-8?q?fix(minimax-bot):=20busy=20=E5=8F=98?= =?UTF-8?q?=E5=8C=96=E6=97=B6=E7=BB=AD=E8=B7=91=E6=8C=89=E9=92=AE=E7=AB=8B?= =?UTF-8?q?=E5=8D=B3=E8=B7=9F=E7=9D=80=E5=8F=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 维护者在复审里提的非阻断项:SSE 的 chat.busy 先于发送回执到达,或页面 挂载后才收到 busy 事件时,续跑按钮会留到下一次消息事件才消失。 两处补齐。chat.busy 处理里重渲染当前会话的消息流,因为投递行的内容取决于 这条会话忙不忙,而事件本身不带消息。messageView 的签名加上 state.busy, 否则 reconcile 认为节点没变、不会重建按钮。 新测试:一条 pending 消息本来有按钮,收到 busy 后消失,收到空闲后又回来。 --- plugins/minimax-ai/minimax-bot/miniapp/client/app.js | 8 +++++++- .../minimax-bot/tests/client-reliability.test.mjs | 11 +++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/plugins/minimax-ai/minimax-bot/miniapp/client/app.js b/plugins/minimax-ai/minimax-bot/miniapp/client/app.js index fa936b59..75f2d0e2 100644 --- a/plugins/minimax-ai/minimax-bot/miniapp/client/app.js +++ b/plugins/minimax-ai/minimax-bot/miniapp/client/app.js @@ -698,7 +698,9 @@ function presentationKey() { function messageView(message, prev, presentation) { return { key: message.id, - signature: JSON.stringify([message, prev?.ts, presentation, deliveryActions.has(`${message.chatId}:${message.id}`)]), + // `busy` decides whether the delivery line offers a resume, and the message itself does not + // carry it: without it here a busy event would leave the button in place. + signature: JSON.stringify([message, prev?.ts, presentation, deliveryActions.has(`${message.chatId}:${message.id}`), state.busy.has(message.chatId)]), create: () => renderItem(message, prev), update: (node) => renderItem(message, prev, node), }; @@ -1651,6 +1653,10 @@ function handleEvent(event) { if (mounted) { renderPill(); syncSend(); + // The delivery line depends on whether this chat is busy, and the event that flips it does + // not carry a message: re-render the feed so a resume button disappears the moment the chat + // starts answering, or comes back when it stops. + if (mounted === event.chatId) renderFeed(state.messages.get(event.chatId) ?? [], false); } if (state.drawer.open && state.drawer.view === 'overview') nav.renderDrawer(); break; diff --git a/plugins/minimax-ai/minimax-bot/tests/client-reliability.test.mjs b/plugins/minimax-ai/minimax-bot/tests/client-reliability.test.mjs index 4f1550e4..3f410e9e 100644 --- a/plugins/minimax-ai/minimax-bot/tests/client-reliability.test.mjs +++ b/plugins/minimax-ai/minimax-bot/tests/client-reliability.test.mjs @@ -581,6 +581,17 @@ test('a request stranded by a restart offers to send it again, and one this page button.click(); await settle(); assert.equal(calls.filter((call) => call.path.endsWith('/resume-pending')).length, 1); + // The busy event carries no message, but it changes whether this line offers a resume. + const late = message('msg_late', 'Held back', { role: 'user', dispatchState: 'pending' }); + await reset([late]); + assert.notEqual(document.querySelector('.message-delivery button'), null); + emit({ type: 'chat.busy', chatId: late.chatId, busy: true, turns: [] }); + await settle(); + assert.equal(document.querySelector('.message-delivery button'), null); + emit({ type: 'chat.busy', chatId: late.chatId, busy: false, turns: [] }); + await settle(); + assert.notEqual(document.querySelector('.message-delivery button'), null); + // A request this page just sent is pending with no reply too; it must not offer to resume itself. await reset(); const fresh = message('msg_fresh', 'Just typed', { role: 'user', dispatchState: 'pending' });