Session corrupt: seed assistant/message at index 4002 has invalid settlement fields #8084
Replies: 5 comments 2 replies
|
我对着 packages/core/session/src/index.ts 核实了一下,能确认根因,虽然帮不了你恢复这一条已经写坏的记录。 turn/step/stream 这三个字段(也就是报错里说的 settlement fields)有一个专门的校验函数 assertAssistantSettlementShape,要求 turn、step 是非负安全整数,stream 是数组。但这个校验之前只挂在 seed/load 那条路径上,也就是 Session.fromRestore、从存储读回会话的时候才会跑。真正写入用的 Session.append,只调用了 validateSessionEventData 和 surfaceManager.validateNext,两个都不检查这三个字段。 结果就是:只要有任何写入方(插件、provider 适配器等)append 了一条 turn/step/stream 缺失或者格式不对的 assistant/message 或 assistant/attempt,写入当时完全不会报错,等到下次这个会话要从磁盘读回来,才会在 seed assistant/message at index N has invalid settlement fields 这里被拒收,整个会话读不出来,但已经没法知道到底是哪一次写入造成的了。你这条会话第 4002 条assistant/message,大概率就是这样被某次写入弄坏的,不是存储层数据损坏,是写入路径当时没挡住。 我把这个校验补到 append() 里了,位置和最近另一个类似问题(消息缺 id/role)的修法完全一致,推到了 fork 上: https://github.com/Mide69/deepseek-harness/tree/fix/append-validates-assistant-settlement-shape 加了回归测试,复用现有 seed/load 那边的畸形数据 fixture,对 append() 跑一遍同样的拒绝断言;跑过 packages/core/session、packages/core/agent-loop、packages/core/agent、packages/api/session-controller、packages/subagent 的完整测试套件和仓库自己的 typecheck、lint,都通过。 这个修法能防止以后再出现同类问题,但没法修复你现在这条已经损坏的会话,那条记录已经是坏的了。要拿回历史内容的话,目前只能自己写个小工具,把会话文件按事件一条条读出来(不要用 Node 自带的 JSON 解析整份读,读到第 4002 条就会因为这个校验失败而整体失败),跳过或者修补 seq 4002 那一条的 turn/step/stream 字段后再继续读后面的事件。 |
|
Reproduced this on the installed runtime ( The gate is
One bad row refuses the whole session, which is the message in your report. To see it on your own log without building anything, feed the decoded events in as the seed: const { Session } = await import("<...>/@deepseek-ai/dsh-session/lib/index.js");
Session.fromRestore(header.id, events, header, 0, "detached", []);As-is it constructs. Delete one On the repair question I agree with @Mide69 — What is available offline is a sharper diagnosis than the loader's: the official message names the type and the index but not which member tripped, and the row is identifiable from the file alone: I added exactly that to dsh-session-surgeon this round ( |
|
Follow-up on the root cause you asked about — "是否与 subagent / 工具调用相关" — because I can now rule out the official writer, which narrows it a lot. The official agent loop cannot produce this row. get stream() {
return [...this.accumulator.snapshot()];
}That is always an array — possibly empty, never And a v0/v1/v2 log cannot produce this message either. v0→v1 does emit Put together: the row came from something other than the official agent loop — a plugin or provider adapter calling I also checked that our own tool is not a candidate, since it rewrites these files: across 5 real v4 logs, all 925 None of that recovers the row, and I agree with @Mide69 that it cannot be repaired: |
|
两位把根因挖透了,补上你没被回答的那半——这条坏记录怎么修。坏的是一行(v2 起每行一个事件),
两个后续提醒:
(会话日志的行级手术是我熟的路子——备份插件的 doctor 平时干的就是这类活。) |
|
@xiaoyuyu6420 — you are right and I was wrong, so let me correct my own follow-up above rather than leave it standing. I said the row could not be repaired. It can. Your step 3 is the part that decided it:
Measured, not read: Your step 3's other half I would sharpen, though. Copying One trap in your step 5 worth knowing, since you validate with the host's checker: So: thank you — this was a real correction, not a nitpick, and it is now shipped. |
Uh oh!
There was an error while loading. Please reload this page.
Hi,我遇到一个会话历史加载失败的问题,报错如下:
历史加载失败:stored session "session-c72030f6-638b-4c63-bc35-43cb29336def" is corrupt: seed assistant/message at index 4002 has invalid settlement fields(gateway/internal)
基本信息:
Session ID:session-c72030f6-638b-4c63-bc35-43cb29336def
报错类型:gateway/internal
失败位置:assistant/message at index 4002
失败原因:invalid settlement fields
问题描述:
该会话在加载历史记录时直接失败,整个会话无法继续使用,历史记录全部无法读取。推测是第 4002 条 assistant 消息的 settlement 字段在写入时中途失败/不完整,或存储层数据损坏。
影响:
会话无法打开,历史内容全部丢失。
已尝试:
重启 / 重新加载会话,无效
报错稳定复现,指向同一条消息
请求:
帮忙清理或修复该会话的损坏记录
排查 settlement 字段写入失败的根因,确认是否与 subagent / 工具调用相关,避免其他会话出现同类问题
谢谢!
All reactions