Repository navigation
[bug] 离线补标题写坏会话日志的三个变体,以及一条被漏掉的校验:session/title.messageSeqs 引用了非用户消息
#10440
Replies: 2 comments
|
I read the reader at The invariant your scripts break that your report does not name
// session-format-v3-to-v4/src/relationships.ts:353-354
if (event.type === 'session/title'
&& (references.length === 0) !== (record(data['source'], 'title source')['kind'] === 'user')) {
throw new SessionFormatError('session/title messageSeqs must be empty exactly for a user title')
}Not "a user title may cite messages" — a user title must have an empty
So the offline retitle recipe is one line, and it is the one you already had in variant A: { title, messageSeqs: [], source: { kind: 'user' } }That is the only pinning form. If you do want a title that cites, it cannot be What a citable ref must actually beYour filter kept every
Why the layers come in that order (and why "report all at once" is not an error-text change)They are sequential by construction, and each one runs at a different stage of the decode:
So the read path can never list all findings in one message: layer 3 needs 1 and 2 to have produced an array. A one-pass report is a property of an offline tool, not of the reader — which is the strongest argument for your validator, and worth saying plainly rather than as a request to improve the message. One diagnostic wart while you are documenting this: when the bad row has no On "skip duplicate rows instead of refusing" (your point 2)There is a
Your variant-B repair is right, and it is permanent
That also answers your docs request precisely: layer 1 is documented, at The part that makes a third-party validator drift — and the actual missing APIYou offered to publish the validator, so this matters: you cannot reuse the app's own codecs today.
That is why every offline tool in this space is a reimplementation, and why yours reproduced two invariants and missed a third. The minimal ask is not On the restart being mandatoryThe persistence backend revalidates by file revision before it serves a memoized parse ( Where I landYour tool is worth publishing, and the four rules above change what it has to check. If the maintainers do not pick up the exported-validator ask, I am happy to put together a standalone verifier package that walks the same three layers read-only (frame → rows → relationships), reports every finding in one run rather than one per restart, and never rewrites a log — a repair mode is a separate, opt-in decision I would keep out of the same tool. Say the word and I will post it as its own package; the report format and the layer boundaries would follow the code above, not a summary of it. |
|
先把你这三个变体逐条对着发布包量了一遍,结论是:三个里有两个我们之前判死了,现在都能修,第三个本来就能修。 一、变体 B(12/13 的那个):可修,而且损失为零你贴的 现在改成先拆再判:第一行当表头,剩下的行喂给同一个 scanner(排在后续帧的内容之前),健康码 实测(真实 326 事件 v4 会话,整份压成一帧):
首行解不出表头的情形照旧只报 二、变体 C:两条规则,不是一条你在 #10440 里引的是「必须指向真实存在、且更早的人类 user/message」,少了一半(
所以「人类」= 修复只做确定的事:用户标题的引用清空(它本来就该是空的),指向不了真人消息的引用逐条丢掉、保留其余。非用户标题若一条合法引用都不剩,我们只报告 —— 它究竟来自哪些消息,工件里没有答案,编不出来。实测:上面表格里前三种拒读形状,修完都被同一条折叠接受;后两种剩下的仍然拒,我们的判定与它一致。 三、变体 A:本来就能修,但边界要说清seq 撞车我们一直有路径(
你提醒的「不能靠跳过重复行做读端容错」我完全同意,而且理由和你一样:同号两行内容不同,跳过就会错位。我们做的不是跳过,是截到一个自洽的边界,代价写在 四、你那条 UX 建议,我们这侧已经是的读取端只报最外层那一层,是因为加载是 fail-fast。离线工具没有这个限制: 工具在 |
Uh oh!
There was an error while loading. Please reload this page.
现象
Web GUI 打开会话时报「历史加载失败」,前后踩了三个不同的校验点:
环境
@deepseek-ai/dsh0.2.1-rc.2(桌面版 44.7.0,Windows 11)@deepseek-ai/dsh-session-persistence-jsonl,产物session.v4.jsonl.zstd(多帧 zstd,帧 1 = 表头行)重要区别:这不是运行时中断导致的
翻了下 #255 / #333 / #420 / #496 / #1497 这一族报告,根因都是运行时路径:回合中断 → 合成收尾事件(
interrupted-turn-closers)与续跑 append 抢同一个 seq 区间;或者两个进程各持一个内存游标同时写。我这个案例的触发源完全不同:离线工具直接改写日志文件。
背景:社区装的
dsh-session-title-pattern只对之后的新消息生效,存量会话要离线补标题。我写了个脚本,按官方格式解压全部帧 → 追加一条session/title事件(source.kind: "user",这样不会被插件重算覆盖)→ 按「帧 1 = 表头、帧 2 = 正文」重新压回。第一版脚本里三个错误,正好对应上面三条报错:
变体 A:seq 撞车(1 例)
脚本在判断「已有同格式标题就跳过」时,
last.seq是从过滤掉空行后的数组取的,而写回时用的是另一份行数组——两份数组在末尾空行处理上不一致,导致算出的lastSeq比实际小 1,追加事件和最后一条真实事件撞号。变体 B:帧边界错乱(12 例)
脚本某次重构后,把「帧 1 单独放表头」这一步漏了,直接整体
zstdCompressSync。内容一条没丢、JSON 全部合法、seq 0..1784 完全连续,但读取端在解压后第一件事就是断言首帧恰好一行:这条校验很严:它不看内容对不对,只看帧边界。
变体 C:
session/title.messageSeqs引用非法(1 例,社区未覆盖)修完 B 之后,同一个会话又报了第三个错。查出来是这样:
13 条引用里只有 3 条(8、48、554)是真实存在的
user/message,其余 10 条 seq 指向的全是step/start事件:来源是另一个版本的补标题脚本——它想「让标题关联到产生它的那批消息」,于是按「离标题事件最近的若干事件」去凑 messageSeqs,压根没过滤事件类型。校验器要求每条 messageSeqs 都必须指向真实存在、且更早的、人类 user/message 事件,于是整份日志被拒。
关键观察:三层校验,报错只显示最外层那个
这是最容易误判的地方。DSH 加载会话日志要顺序过三道关:
first frame is not exactly one header lineevent.seq === events.lengthinvalid committed event at line N: released v2 row N has seq gap (...)session/title的messageSeqs全部指向真实 user/messagesession/title messageSeqs must cite distinct earlier human user/message events修好一层,下一次打开才会暴露下一层。 我在变体 B 上就是这样被误导的:修完帧边界以为完事了,重启后又冒出 messageSeqs 的错,一度以为没修好。如果第一轮报错里就能看到「这份日志一共有几处问题、分别在哪一层」,用户能少走两趟重启。
顺带一提:重启是必须的。主机进程在启动时就会把「这份会话已损坏」的结论缓存住,之后即使磁盘文件已经修好,不重启应用也不会重新读取——点窗口 × 只是缩到托盘,进程还活着。
修复方法(全部已验证,数据零丢失)
原则:只删/改不合法的那几行或那几个字段,绝不重编号、绝不动正文。
session/title事件(另有一条更新的标题事件已生效),重压messageSeqs过滤到只保留真实 user/message 的 seq[8,48,554],其余字段原样压缩写回统一用
ZSTD_c_checksumFlag: 1,确保产物与官方写入器逐字节同构。全量扫描 317 个会话的最终状态:317/317 通过。
建议
1. 写端(治本)
变体 A/B/C 都是我自己的工具写坏的,官方写入器不受影响——但社区那一族报告说明,只要能离线改写日志,就会有人写坏。建议:
dsh session repair/dsh session retitle),把「解析全部帧 → 校验 → 重新分帧」这条链路收进官方实现,避免每个人各写一份、各错一遍。messageSeqs只能引用真实 user/message。2. 读端(应急)
社区在 #496 / #1497 已经提过:
seq < expected的重复行可以跳过而不是整体拒读,这能覆盖「数据没丢、只是重复」的绝大多数场景。我这次遇到的 A 变体(同号但内容不同)和 C 变体(引用非法)都不属于「重复行」,跳过的策略不适用——所以:3. 这三条不变量可以做成校验工具
我按上面三层写了个只读体检脚本,
node validate.mjs --all一次扫完整个会话库,退出码非零就说明有坏的。如果维护者觉得有用,我可以整理成 PR 或独立 npm 包。(脚本目前只在我本机,需要的话我贴出来。)日志本身包含私人对话内容,不便公开贴出。如果需要具体的行级证据(脱敏后的 seq/类型/时间表)、或者需要一份最小可复现的损坏样本,我可以私下提供。
All reactions