Repository navigation
fix(minimax-bot): 写盘失败不再把进程带走 - #142
Merged
MyPrototypeWhat merged 1 commit intoNov 20, 2026
Merged
Conversation
Apageoflove
force-pushed
the
fix/minimax-bot-unhandled-saves
branch
from
November 19, 2026 02:25
ef36f97 to
3da17b1
Compare
两处 fire-and-forget 的写没有 catch。一是回合开始时记 session id 的 void this.store.setSession(...),它上面一行 tasks.save() 是 catch 了的; 二是 startScheduler 里 setInterval(() => void this.tickSchedules(), 30_000), tickSchedules 内部有 await this.store.save()。 宿主 host-runner.js 把 unhandledRejection 转成 fail(error),也就是整个 Mini App 进程失败退出。磁盘坏一次,正在跑的回合和其他 Bot 的任务全断; 定时任务那条每 30 秒重试,会反复触发。 两处都改成记一条 warn 日志带错误码,照抄旁边已写好的 catch。定时任务的 catch 放在 tick 闭包里,定时器和启动时那一次共用。 两条新测试在 0.7.28 上红、在切片上绿。全量 415 条通过。
Apageoflove
force-pushed
the
fix/minimax-bot-unhandled-saves
branch
from
November 20, 2026 01:11
3da17b1 to
556b074
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
有两处写盘失败会把整个插件进程带走。
第一处是回合开始时记 session id。engine.mjs 里那一行是 void this.store.setSession(...),void 掉又没有 catch。它上面一行 tasks.save() 是 .catch 了的,同一处两条并发写,一条防了、一条漏了。
第二处更严重,是定时任务的扫描。startScheduler 用 setInterval(() => void this.tickSchedules(), 30_000) 每 30 秒跑一次,而 tickSchedules 内部有 await this.store.save(),也没有 catch。
这两个漏所在的地方都不安静。宿主在 host-runner.js 里注册了 unhandledRejection,收到就把整个 Mini App 进程判失败。所以磁盘坏一次,正在跑的回合、其他 Bot 手里的任务全断;定时任务那条更糟,它每 30 秒重试一次,磁盘一直是坏的就会反复触发。
复现是拿真实 engine 跑的。把 state.json 的位置换成一个目录让写入失败,然后挂一个 unhandledRejection 监听数次数:
两条都在 0.7.28 上复现出来。加上 catch 之后再跑,两次都是 0,日志里分别出现 minimax_bot.session_save_failed 和 minimax_bot.schedule_tick_failed。
改法就是照抄旁边已经写好的那个 .catch:记一条 warn 日志带错误码,不用把错误往上抛,因为这两个写都不是用户当次请求的一部分,失败了这一轮照常跑完。定时任务那边把 catch 放在 tick 闭包里,setInterval 和启动时那一次调用共用。
测试加在 engine-reliability 里两条,都挂 process.on('unhandledRejection') 计数。一条走完整回合,断言没有 rejection、日志里有 session_save_failed;一条挂一条已经到点的定时任务,走 startScheduler,断言没有 rejection、日志里有 schedule_tick_failed。两条在 0.7.28 上都红,在切片上绿。全量 415 条过。
版本号到 0.7.31。0.7.29 和 0.7.30 被另外两条还开着的 PR 占着。
顺手看了同类的其他 void 调用。task-dispatcher 里那三处是安全的,deliver 内部自己有 try/catch,另一处 save 后面跟了 .catch。runBotTurn 在引擎里也接了 catch。剩下没细查的是 tickSchedules 之外还有没有别的周期任务用了同样的写法,这个得把定时器和 setInterval 全过一遍才知道。
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.