Repository navigation
perf(kbrain): 启动时不再重传已迁移的旧会话,存在性确认改为一次列表 - #959
Merged
xiaozhou26 merged 1 commit intoOct 10, 2026
Merged
Conversation
迁移过旧会话后,每次启动仍要在启动画面停 35–55 秒:29 个已迁移的会话被整份重传(约 125 MB),72 个已缓存的会话逐个按 id 查询确认存在(约 24 秒)。 - 文件回滚记录为 partial 的结果也进缓存。partial 由 K-brain 完全根据请求内容算出,内容不变结果不变;指纹覆盖回滚导出,内容变了会重新导入。unresolved 仍每次重试。手动「导入旧版对话」仍会重传 partial 的会话。 - 存在性确认改为一次分页列出会话(迁移的两个来源共用)。列表里没有、或者列表请求失败时,仍按 id 确认,只有真正的 404 才会重新导入。 - 测试:partial 结果在下次启动不再上传,手动导入和内容变化后会重新上传,unresolved 每次重试;列表命中时不再逐个查询。 Closes Stack-Cairn#958
StackCairn
marked this pull request as draft
October 10, 2026 13:48
Contributor
|
PR governance checks passed. Awaiting human review. |
AlphaCatMeow
marked this pull request as ready for review
October 10, 2026 13:54
xiaozhou26
approved these changes
Oct 10, 2026
xiaozhou26
left a comment
Contributor
There was a problem hiding this comment.
复核通过:部分 checkpoint 结果按完整内容指纹缓存,显式手动导入仍重试;共享分页列表仅作为正向存在性确认,列表缺失/失败仍按 ID 确认,只有真实 404 才允许补传。18 个迁移测试通过;与 #957 联合测试 GUI 3038 passed / 1 skipped,WebUI 770 passed,三端类型检查通过。浏览器验证两条 partial 会话首次上传两次,第二次启动只列表一次且不上传/不逐会话 GET,手动导入重新上传,partial 仍保留 incomplete 状态;分页、并发列表共享、404 和 503 分支也验证通过。与 K-brain #25 无依赖,兼容当前 beta.5 后端。
This was referenced Oct 11, 2026
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.
Closes #958
问题
迁移过旧会话之后,每次启动桌面端仍要在启动画面停 35–55 秒。本机实测每次启动:
GET /v1/sessions/:id确认还在,合计约 24 秒。原因
available/not_found的结果。回滚记录为partial的会话每次启动都会重传。但partial是 K-brain 完全根据请求内容算出来的(缺少的 blob、无效的记录行、目录标记、找不到对应消息的回合),内容不变,结果就不变。改动
isStableMigrationResult把partial也视为稳定结果,可以缓存。unresolved仍然每次重试(当时可能还读不到回滚导出)。retryKnownFailures)不复用缓存里的partial结果,仍会重传。createSessionExistenceCheck:先分页列一次会话,用列表回答存在性;旧版会话和 Pi 会话两个来源共用这一次列表。列表里没有这个会话,或者列表请求失败,就按 id 确认,只有真正的 404 才会重新导入。验证
pnpm typecheck通过;test/providers下 238 个测试全部通过。新增测试:
partial结果在下次启动不再上传;手动导入、内容变化后会重新上传;unresolved每次都重试。这个测试在撤掉修复后会失败。原有测试"只在 404 时修复、尊重后端删除"的断言不变。测试桩加了一个空的会话列表,让这些断言继续落在按 id 查询的那条路径上。
本地调试客户端(K-brain 用最新源码编译)重载页面:
说明
剩下的 16 秒里,约 6 秒花在会话列表接口上(K-brain 列会话时同样要读所有会话文件),约 5.7 秒花在读取本地旧版历史的分页上。前者要改 K-brain 的会话存储,不在本 PR 范围内。
截图
本 PR 只改了迁移逻辑,没有界面变化。下图是用 Chrome DevTools 网络记录量出的前后对比(数据图,不是界面截图):