MoonshotAI / MoonshotAI/kimi-code
恢复会话失败:wire.jsonl 并发 append 产生撕裂行,单行损坏导致整个会话无法加载
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 7.5k
- Forks
- 1.2k
- Avg merge
- 11h 53m
- Merged PRs (30d)
- 350
Description
版本:kimi-code 0.38.0(Linux arm64)
现象:恢复会话(kimi -c / kimi -S <id>)时报错并直接退出:
failed to run prompt: append-log .../agents/main/wire.jsonl: corrupted line N
kimi web 加载同一会话时前端显示加载失败,后端报恢复失败。
根因(已在本地实锤):受损会话的 agents/main/wire.jsonl 第 N 行为撕裂写入——两条 task.terminated 记录被并发追加到同一行,前一条在 JSON 字符串中间被截断,后一条完整记录紧随其后;两条记录 taskId 相同、时间戳相同(毫秒级)。发生在恢复会话、对遗留 detached 后台任务做 reconcile 补写终止记录的时刻,疑似多个进程同时对该文件无锁 append。此后该会话所有加载尝试都在该行 fail-fast,会话永久无法恢复;手动移除该坏行后恢复即正常。
期望行为:
- 写入端:wire.jsonl 的 append 保证整行原子性(跨进程文件锁,或 O_APPEND 下单次 write 整行),reconcile 同一任务去重只写一次;
- 加载端:单行 JSON 损坏不应让整个会话无法恢复——建议跳过坏行并明确告警,或提供自动修复选项,而非直接退出。
相关 issue:#2159(state.json 损坏阻断恢复)、#2902(ENOSPC 致 append 失败崩溃),均不涉及并发撕裂写,本 issue 为不同成因。
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Trace the append-log path used when kimi -c or kimi -S reconciles detached tasks, then inspect the wire.jsonl loading path used by kimi web. Reproduce concurrent writes for the same task and timestamp, and verify that reconciliation does not tear lines or duplicate records. Done means a damaged line no longer prevents the whole session from loading, with an explicit warning or repair path.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- linux, typescript
- Domain
- backend, cli
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100