Skip to content

Commit c43eeaf

Browse files
committed
fix(minimax-bot): 重启后已收下的请求还能再发出去
宿主在没有页面可见时可以停掉插件的 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 的两条和本切片的兩条)。
1 parent 0c20f90 commit c43eeaf

8 files changed

Lines changed: 80 additions & 5 deletions

File tree

‎plugins/minimax-ai/minimax-bot/.minimax-plugin/plugin.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"schemaVersion": 1,
33
"name": "minimax-bot",
44
"displayName": "MiniMax Bot",
5-
"version": "0.7.28",
5+
"version": "0.7.29",
66
"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.",
77
"author": "MiniMax Code",
88
"icon": "icon.png",

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

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

103+
## 0.7.29 A request the plugin already accepted is still sendable after a restart
104+
105+
- 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.
106+
- 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.
107+
- A request whose reply had already started is unchanged, and a request this page has just sent never offers to resume itself.
108+
103109
## 0.7.10 Optional group notes
104110

105111
- 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.

‎plugins/minimax-ai/minimax-bot/miniapp/client/app.js‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,14 @@ function userDelivery(message) {
792792
const status = message.dispatchState;
793793
if (!status || status === 'processing' || status === 'delivered') return null;
794794
const key = `${message.chatId}:${message.id}`;
795-
const button = status === 'held' ? h('button', {
795+
// A restart leaves an accepted request pending with no queue left to send it and nothing running.
796+
// Offer the same resume on the proof the server uses: nothing was ever written back for it.
797+
// dispatchRevision is only written when a delivery state changes, so a request this page just
798+
// sent has none yet and never offers to resume itself.
799+
const stranded = status === 'pending' && message.dispatchRevision > 0 && !state.busy.has(message.chatId)
800+
&& !(state.messages.get(message.chatId) ?? []).some(
801+
(item) => item.sourceMessageId === message.id || item.sourceMessageIds?.includes(message.id));
802+
const button = status === 'held' || stranded ? h('button', {
796803
type: 'button', class: 'btn sm', disabled: deliveryActions.has(key),
797804
onclick: async (event) => {
798805
if (deliveryActions.has(key)) return;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ export function createMcpHandler({ team, engine }) {
662662
result = {
663663
protocolVersion: PROTOCOL_VERSIONS.includes(requested) ? requested : PROTOCOL_VERSIONS[0],
664664
capabilities: { tools: { listChanged: false } },
665-
serverInfo: { name: 'minimax-bot', version: '0.7.28' },
665+
serverInfo: { name: 'minimax-bot', version: '0.7.29' },
666666
instructions: t('mcp.instructions'),
667667
};
668668
break;

‎plugins/minimax-ai/minimax-bot/miniapp/node/user-inbox.mjs‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,15 @@ export class UserInbox {
149149
async resumeHeld(chatId) {
150150
// Only resend supplements that never started; an uncertain original request is never replayed.
151151
const history = await this.engine.store.getMessages(chatId);
152-
const held = history.filter((message) => message.role === 'user' && message.dispatchState === 'held' && !this.has(message.id));
152+
const held = history.filter((message) => {
153+
if (message.role !== 'user' || this.has(message.id)) return false;
154+
if (message.dispatchState === 'held') return true;
155+
// A restart leaves an accepted request `pending` with the queue that owned it gone. It is
156+
// recoverable on the same proof the retry path uses: no reply and no durable assistant
157+
// placeholder means the request never reached the Host.
158+
return message.dispatchState === 'pending'
159+
&& !history.some((item) => item.sourceMessageId === message.id || item.sourceMessageIds?.includes(message.id));
160+
});
153161
if (!held.length || this.busy(chatId) || [...this.engine.tickets].some((ticket) => ticket.chatId === chatId)) {
154162
throw new this.ErrorType('busy', t('err.messageAlreadyProcessing'));
155163
}

‎plugins/minimax-ai/minimax-bot/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "minimax-bot",
3-
"version": "0.7.28",
3+
"version": "0.7.29",
44
"private": true,
55
"type": "module",
66
"mcode": {

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,22 @@ test('held supplements require an explicit continuation and a failed action leav
570570
assert.equal(calls.filter((call) => call.path.endsWith('/resume-pending')).length, 1);
571571
});
572572

573+
test('a request stranded by a restart offers to send it again, and one this page just sent does not', async () => {
574+
// dispatchRevision is written when a delivery state changes, so a recovered request has one and
575+
// a request the composer just created does not.
576+
const stranded = message('msg_stranded', 'Ship the hotfix', { role: 'user', dispatchState: 'pending', dispatchRevision: 1 });
577+
await reset([stranded]);
578+
const button = document.querySelector('.message-delivery button');
579+
assert.equal(button.textContent, 'Continue with follow-ups');
580+
route = ({ path }) => path.endsWith('/resume-pending') ? response({ ok: true }) : undefined;
581+
button.click(); await settle();
582+
assert.equal(calls.filter((call) => call.path.endsWith('/resume-pending')).length, 1);
583+
584+
const fresh = message('msg_fresh', 'Just typed', { role: 'user', dispatchState: 'pending' });
585+
await reset([fresh]);
586+
assert.equal(document.querySelector('.message-delivery button'), null);
587+
});
588+
573589
test('a delayed send receipt cannot restore an obsolete pending state after the live processing event', async () => {
574590
await reset();
575591
const user = message('msg_receipt', 'Request', { role: 'user', dispatchState: 'pending', dispatchRevision: 0 });

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,44 @@ test('an interrupted associated assistant is reported as uncertain, and legacy m
648648
await restored.writeChain;
649649
});
650650

651+
test('a request whose queue died with the process is still sendable from the page', async (t) => {
652+
const { dir, store, memory, engine } = await fixture(t);
653+
const bot = store.state.bots[0];
654+
const chatId = `bot:${bot.id}`;
655+
// The process died after the inbox marked the batch processing and before any reply existed.
656+
const user = await store.appendMessage(chatId, {
657+
role: 'user', text: 'Ship the hotfix', clientMessageId: 'orphan-1',
658+
clientMessageHash: engine.userMessageFingerprint('Ship the hotfix', []), dispatchState: 'processing',
659+
});
660+
await store.writeChain;
661+
662+
const restored = new Store(dir);
663+
await restored.init();
664+
let runs = 0;
665+
const reopened = new Engine({ store: restored, memory, logger: { warn() {} }, broadcast() {}, retryDelaysMs: [], agent: {
666+
async run(input, options) { runs += 1; return { ...started(input, options, 'resumed'), status: 'finished', text: 'Shipped' }; },
667+
} });
668+
reopened.startScheduler();
669+
reopened.tasks.start();
670+
671+
// The load-time mapping keeps `pending`, which the client retry path needs. The queue that owned
672+
// it is gone, so the resume route has to recognise it too or the request is stranded for good.
673+
const afterRestart = (await restored.getMessages(chatId)).find((message) => message.id === user.id);
674+
assert.equal(afterRestart.dispatchState, 'pending');
675+
await until(() => idle(reopened));
676+
// Nothing replays it on its own: the turn may already have run tools before the process died.
677+
assert.equal(runs, 0);
678+
679+
await reopened.inbox.resume(chatId);
680+
await until(() => idle(reopened));
681+
assert.equal(runs, 1);
682+
const messages = await restored.getMessages(chatId);
683+
assert.equal(messages.find((message) => message.id === user.id).dispatchState, 'delivered');
684+
assert.equal(messages.filter((message) => message.sourceMessageId === user.id).length, 1);
685+
reopened.dispose();
686+
await restored.writeChain;
687+
});
688+
651689
test('repeated pending submissions do not duplicate queued turns or revive a deliberately cancelled queue', async (t) => {
652690
const { store, engine } = await fixture(t);
653691
const bot = store.state.bots[0];

0 commit comments

Comments
 (0)