Repository navigation
fix(minimax-bot): 删会话失败时不再顺手把聊天记录清空 - #135
Open
Apageoflove wants to merge 1 commit into
Open
Apageoflove wants to merge 1 commit into
Apageoflove wants to merge 1 commit into
Conversation
删 Bot、删群、Start new chat 都走 deleteChat。它先清空这条会话的 message 文件,再写 state.json 把会话忘掉。第二步失败时第一步已经落盘,接口回 500、 会话仍在侧栏,点进去是空的,再点一次也救不回来。 顺序换过来:先写不带这条会话的 state,成功了再清消息文件,两个写仍在同一个 队列槽内。内存里的 sessions 条目也等写成功才提交,避免失败时内存领先磁盘、 被后续无关保存顺手落盘。 新测试把 state.json 换成目录让写失败,断言 message 文件里那条消息还在。 未改的上游上红、切片上绿。全量 412 条通过,上游基线 411 条。
Collaborator
|
感谢修复!看了 1d0ac9b,有一个问题需要改了再合: 会丢 session 的竞态。 建议改法:快照照常用来写盘,写成功后改用 另外两点不影响合并,供参考:
|
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.
删 Bot、删群、聊天里点 Start new chat,这三件事以前在写盘失败的时候会顺手把聊天记录毁掉。
它们走的是同一个 deleteChat。那里的顺序是先清空这条会话的 message 文件,再去写 state.json 把会话忘掉。第二步失败的时候第一步已经落到磁盘上了,所以接口回 500,用户看到失败,会话还留在侧栏里,点进去是空的。再点一次也救不回来,文件已经是空的了。
复现用真实路由跑的。先给两个会话各塞三条消息,把 state.json 的位置换成一个目录让写入失败,然后分别走 DELETE /api/bots 和 POST /api/chats/:id/reset。在当前上游 main 上跑出来是这样:
两个会话都还在,消息都是 0 条。同一份探针打到改过的代码上,最后两行变成 3 和 3。
改法就是把两个写的顺序换过来,先写那份不带这条会话的 state,成功了再清消息文件。两个写还在同一个队列槽里,没有别的写能插进来。失败时两边都没动,用户原样重试一次就行。
第一版我改得更随意些,先删内存里的 sessions 再写盘。reviewer 指出这样失败时内存已经跑到磁盘前面了,之后任何一次无关的保存都会把这个删除顺手落盘,会话游标就悄悄没了。现在改成先写一份去掉这条会话的快照,写成功才把它提交到内存。
测试加在 storage-reliability 里,把 state.json 换成目录让写失败,断言 message 文件里那条消息还在。这条在未改的上游上红,在切片上绿。全量 412 条过,上游基线 411 条。
没做断电和磁盘写满这类真实现场注入,失败都是靠把 state.json 的位置换成目录模拟的。deleteBot 里 memory.archive 和 store.save 的相对顺序没单独打探针,只读了代码确认它们在 deleteChat 之后。
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.