Skip to content

fix(minimax-bot-team): write the state that forgets a chat before its transcript is cleared - #139

Merged
MyPrototypeWhat merged 1 commit into
MiniMax-AI:mainfrom
antianqi:feat/minimax-bot-team-1.0.1
Nov 16, 2026
Merged

MyPrototypeWhat merged 1 commit into
MiniMax-AI:mainfrom
antianqi:feat/minimax-bot-team-1.0.1

Conversation

@antianqi

@antianqi antianqi commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Addresses the minimax-bot-team half of #136 (point 1: chat messages are cleared even when saving state fails).

What was wrong

Store.deleteChat() cleared the transcript first and saved the state afterwards:

await this.enqueue(async () => {
  await this.writeMessages(chatId, []);
  this.messageCache.set(chatId, []);
  delete this.state.sessions[chatId];
});
await this.save();

When the state write failed, the transcript was already gone. The chat stayed in the
sidebar, but its messages were lost for good - nothing could get them back.

What changed

miniapp/node/store.mjs writes the state that no longer lists the chat first, and clears
the transcript only after that write succeeded:

await this.enqueue(async () => {
  const sessions = { ...this.state.sessions };
  delete sessions[chatId];
  await writeJsonAtomic(this.statePath, { ...this.state, sessions });
  delete this.state.sessions[chatId];
  await this.writeMessages(chatId, []);
  this.messageCache.set(chatId, []);
});

A failed state write now leaves both the chat and its messages exactly as they were,
and the caller can try again. This is the same order the official minimax-bot package
uses since #135.

The test

The package carries the test that covers it, so it can be run against the package
itself:

node --test plugins/antianqi/minimax-bot-team/tests/chat-delete-atomicity.test.mjs

It follows the steps of the report: it appends messages to an existing chat, replaces
state.json with a directory of the same name so every write to it fails (EISDIR,
the same injection), calls deleteChat, and then checks that

  • the messages are still on disk,
  • the live state still knows the chat,
  • after the state file is restored and a new Store is initialized, the chat and its
    messages are still there.

A second test checks that a delete that succeeds does clear the transcript and forget
the chat.

The test was falsified before it was shipped: with the old order put back into the
package it fails with the messages are still on disk (1 pass, 1 fail); with the fix
it passes 2/2.

Version

1.0.1 - the manifest, package.json, the plugin id module and both READMEs carry it.

Checks

  • node --test plugins/antianqi/minimax-bot-team/tests/chat-delete-atomicity.test.mjs - 2/2
  • npm run validate - this package: 0 errors, 1 warning (ENTRY_STDOUT in
    miniapp/node/memory-bridge.mjs, the helper's own output channel - unchanged from
    1.0.0)
  • npm run check - 92/92

The second point of #136 (mmx-octopus) is a different package and a different pull
request.


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

… transcript is cleared

This answers the first point of issue MiniMax-AI#136.

Deleting a chat cleared the transcript first and saved the state afterwards. When the
state write failed, the transcript was already gone: the chat stayed in the sidebar
and its messages were lost for good, with no way to get them back.

The state that no longer lists the chat now goes to disk first, and the transcript is
cleared only after that write succeeded. A failed write leaves the chat and its
messages exactly as they were, and the caller can simply try again - the same order
the official minimax-bot package uses since MiniMax-AI#135.

The test that covers it travels with the package, so it can be run against the package
itself:

    node --test plugins/antianqi/minimax-bot-team/tests/chat-delete-atomicity.test.mjs

It replaces state.json with a directory of the same name, so every write to it fails,
and then checks that the messages are still on disk, that the live state still knows
the chat, and that after the state file is put back and the store is restarted the
chat and its messages are still there. The second test checks that a delete that
succeeds does clear the transcript and forget the chat.

Checks: the test passes against the package (2/2), the upstream validator reports
0 errors and 1 warning for this package (ENTRY_STDOUT - the stdout in question is the
memory helper's own output channel), and npm run check passes 92/92.

Version 1.0.1.
@MyPrototypeWhat
MyPrototypeWhat merged commit 25449d0 into MiniMax-AI:main Nov 16, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants