Repository navigation
fix(kbrain): 旧会话迁移失败时给出可见清单,启动不再反复上传注定失败的会话 - #951
Merged
xiaozhou26 merged 2 commits intoOct 10, 2026
Merged
xiaozhou26 merged 2 commits into
xiaozhou26 merged 2 commits into
Conversation
此前迁移失败只有一行 `Legacy history migration incomplete`,原因被透传成 `Failed to fetch`;而且每次启动都会把失败的会话整份重传。实测本机 15 个会话的 迁移请求体在 5.3–29.7 MB 之间,全部超过 K-brain 的 4 MB 上限,每次启动多上传 约 216 MB,启动界面要停留约 48 秒(根因见 Stack-Cairn/K-brain#20)。 - 新增 `lib/kbrain/historyMigrationFailures.ts`:把失败分为过大、冲突、 被拒、暂时性四类,按「会话 id + 迁移指纹」持久化记录。 - `historyMigration.ts`:发送前计算请求体大小;连接被断开且请求体超过 4 MB 判定为过大。只有导入 POST 的失败才参与判定,前置的存在性检查失败一律按暂时性处理。 启动时跳过内容未变、且确定会再次失败的会话;手动「导入旧版对话」仍会全部重试。 导入成功后清除对应记录。 - 设置页「旧版对话迁移」列出失败会话:标题、短 id、大小,以及按类别给出的原因和处理建议。 - 主界面新增提示条,可以跳转到详情;关闭前会弹框确认,关闭后不再提示,此操作不可撤销。 - 新增单测,覆盖分类、记录合并、关闭,以及「启动跳过、手动重试、成功后清除」的完整流程。 Closes Stack-Cairn#947
Contributor
This was referenced Oct 10, 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 #947
问题
旧会话迁移失败时,控制台只打一行
Legacy history migration incomplete Array(16),原因显示成Failed to fetch,用户在界面上看不到哪些会话没迁移、为什么失败。失败的会话每次启动都会整份重传。本机实测:15 个会话的迁移请求体在 5.3–29.7 MB 之间,都超过了 K-brain 的 4 MB 请求体上限(根因见 Stack-Cairn/K-brain#20)。K-brain 读到一半直接断开连接,所以浏览器只看到
Failed to fetch。每次启动因此多传约 216 MB,启动画面要停约 48 秒。改动
lib/kbrain/historyMigrationFailures.ts:historyMigration.ts:retryKnownFailures选项。手动「导入旧版对话」会打开它,全部重试;导入成功后清掉对应记录。main.tsx:控制台只报本次新出现的失败,跳过的不再重复刷屏。test/providers/kbrain-history-migration-failures.test.mjs,6 条用例,其中一条覆盖完整流程:启动跳过 → 手动重试 → 成功后清除记录。验证
pnpm typecheck通过;迁移相关单测(新增 6 条加原有的)共 16 条全部通过。首次启动记下 16 条失败,其中 15 条过大、1 条冲突。
第二次启动和修复前对比:
提示条、详情清单、关闭确认都已人工验收。
剩下的 26 MB 来自已经迁移成功、但文件回滚记录不完整的会话。它们没进缓存,所以每次启动还会重发。这是现有逻辑,不在本 PR 范围内。
截图
主界面提示条:
设置页失败清单(会话标题已替换为占位文字):
说明
这些会话本身还是迁移不进去,要等 K-brain 支持更大或分批的导入(Stack-Cairn/K-brain#20)。本 PR 只处理前端:失败可见、不再反复上传、用户可以选择忽略。