Skip to content

fix(minimax-bot): 群纪要的三处收尾,与后台任务也计入用量台账 - #87

Merged
MyPrototypeWhat merged 1 commit into
MiniMax-AI:mainfrom
Apageoflove:fix/minimax-bot-note-and-usage
Oct 27, 2026
Merged

MyPrototypeWhat merged 1 commit into
MiniMax-AI:mainfrom
Apageoflove:fix/minimax-bot-note-and-usage

Conversation

@Apageoflove

@Apageoflove Apageoflove commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

上一条 PR(#80)合进去以后,评审里提的三点我都改了。其中一条是我自己写出来的问题:裁一条记录的时候,原来会一直裁到第一个空格,而中文没有空格,于是中文的记录可能只剩最后几个字。现在只在切口正好落在英文单词中间的时候,才把那半截词去掉,而且最多去掉 20 个字符——中文在两个汉字之间切开本来就是边界,一个字都不会丢。中文和中英混排的用例都补上了。

协议标记原来只认写死的那么几个,现在认的是任意一个 minimax-bot- 开头的标签:带空格、带属性、大小写不同,或者用了一个长得像短横的字符,都会被去掉。去掉的时候只动标签本身,前后的文字留着,中文的标点也不会被改写——这里没有对全文做 NFKC,因为那会把中文的逗号变成半角,改成只折叠那些可能冒充短横和 ASCII 字母的字符,一个字符对一个字符,位置才对得上。

面板提示里原来写死了 6 条 / 1200 字,现在这两个数由服务端随状态一起下发,面板照着写,限额变了提示也跟着变。

另外还发现一处:后台任务是模型实打实跑的一回合,同一个模型、同一套工具、同样花时间,但这一回合从来没进过用量台账——台账里只留着把报告转述回来的那一回合,面板上显示的回合数于是比模型实际跑的少,后台任务越多,差得越多。

改法是在 runHelper 里量自己这一回合的耗时、工具次数和产出,跑完照 Bot 那一回合的样子写一行台账,kind 记成 helper-run;失败的记成 error,被停掉或被中断的记成 aborted。面板那边不用动,它本来就是按台账行数统计的,以前只是少了这些行。

官方 README 自己写着 every Bot reply, scheduled task and background job is an Agent turn,台账漏掉的正是这一类回合,所以这条得补上。拿一条 6 环的后台任务链量了量,每一环都是后台任务跑完、Bot 复核的时候再起下一个:上游 0.7.11 那边模型实际调用 13 次,台账只有 7 行,差的 6 行全是后台任务自己那一回合;改完之后同一条链,台账 13 行。真模型上也量了一遍:让 Chief 起一个后台任务去查仓库,宿主日志里是 3 次模型调用(27 秒、103 秒、14 秒),台账同样 3 行,差 0;后台任务自己那回合的 103 秒和 13 次工具调用,都记在它自己那一行里。

新补的测试里,模型调用几次台账就得有几行;后台任务失败记成 error;被停掉的记成 aborted,而且它不会再转述,所以也就没有第三行;面板上回合那一栏要等于模型实际调用次数。这四条在没改过的上游代码上都是红的。

上游 npm run check 的两半都在本地跑了,scripts/validate.mjs 对本插件报 minimax-bot: OK 和 repository: OK,根目录 87/87 条测试;插件自带套件 266 过、0 挂,比上游 main 多 9 条——中文条目、中英混排、标记的几种写法、中文不被改写、面板照着服务端的数写各一条,加上上面那四条。

@Apageoflove

Copy link
Copy Markdown
Contributor Author

真模型那层刚在 mcode 上跑过一遍,没问题,结果补在正文里那段了。这次只跑了一个后台任务,多个后台任务串起来的情况未验证。

@MyPrototypeWhat MyPrototypeWhat left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at 9d2d5cd. This carries over the three fixes from #86 and adds metering for background jobs. Approving.

What I verified

  1. The three #86 fixes are unchanged. Compared with #86's head 7c2fd89, the only differences are in engine.mjs (the new metering), the README and the new tests/helper-usage.test.mjs. tailOf, the minimax-bot- tag matching, the server-provided noteLimits and their tests are byte-for-byte what I checked in #86.
  2. A background job's own turn is now written to the usage ledger once. runHelper appends one row with kind: 'helper-run' after the run settles, carrying the duration of the agent.run call, the number of tool.started events and the length of the reply text. Status maps as described: failed becomes error; stopped and interrupted (including a stop or a restart) become aborted; everything else, including blocked, is done.
  3. No double counting. Before this PR the job's own turn never reached the ledger; only the follow-up turn that relays the report to the Bot did (through runBotTurn, kind: 'helper'). That relay is a separate model turn and is still recorded once, as before. So one job now shows as two rows because the model really ran two turns. The helper-run row is written only when agent.run was actually called: a job stopped while still waiting for a slot writes nothing.
  4. The usage panel. The panel's totals, per-Bot and per-bucket counts don't filter by kind, so a helper-run row counts as one turn with its chars, tools and duration, and an error row counts in the error total, like any other turn. The per-chat summary uses helper.chatId, so the job is attributed to the chat that started it. The turn count goes up by exactly the number of background jobs that ran, which is the intent stated in the README.
  5. Scope. The new write goes to the existing usage.jsonl inside the Mini App's dataDir through the same queued recordUsage as every other turn, and the README's data section says so. No new files, permissions or network access.
  6. Version. 0.7.12 is consistent across plugin.json, package.json and the MCP serverInfo (main is at 0.7.11), and the 0.7.12 README section now also describes the background job metering.

Checks run

  • npx -y -p node@22 npm run check at 9d2d5cd: passes.
  • Plugin suite, run inside plugins/minimax-ai/minimax-bot with node --test tests/*.test.mjs (Node 22, jsdom and ajv installed locally): 266 tests, 262 pass, 4 fail. The same 4 tests fail on current main in the same environment (one reactions-on-final-bubble test and three emoji picker tests), so this PR didn't cause them. The new helper-usage tests and all the group note, relay guard and panel tests pass.

Optional

  • A job that ends blocked (it asked a question and was handed back to its Bot) is recorded as done. That matches how a normal turn with a pending question is treated, so it's fine. I'm only mentioning it in case you want a separate status later.
  • The panel doesn't distinguish a background job's turn from the turn that relays its report. If you want users to see where turns went, the kind is already in the ledger and could be broken out in the panel.
  • Still open from #86, and still fine as is: a tag with a zero-width character inside the name, or with more than 40 characters of attribute text, is not matched.

@MyPrototypeWhat
MyPrototypeWhat merged commit ff192f0 into MiniMax-AI:main Oct 27, 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