kimi-code icon indicating copy to clipboard operation
kimi-code copied to clipboard

[Bug] session_index.jsonl loses newline between entries, causing session.not_found on resume

Open SunshineR04 opened this issue 4 months ago • 1 comments

Bug Report

Summary

session_index.jsonl can end up with two JSON objects concatenated on the same line (missing newline separator), which causes kimi --session <id> to fail with [session.not_found] even when the session directory exists and is intact.

Environment

  • kimi-code version: v0.27.0
  • Platform: Windows x64
  • Node version: v24.15.0

Steps to Reproduce

  1. Create multiple sessions in the same working directory over several kimi-code launches.
  2. At some point, the index write loses the newline separator between two entries.
  3. Attempt to resume the earlier session by ID: kimi --session <id>.
  4. Error: Failed to resume session <id>: [session.not_found]

Root Cause

session_index.jsonl had two JSON objects on the same line without a newline separator.

When the CLI reads the index line-by-line, the first line fails to parse, so the session entry becomes unreadable.

Workaround

Manually split the concatenated entry onto its own line in ~/.kimi-code/session_index.jsonl.

Notes

  • The session directory is fully intact: state.json, wire.jsonl (~878KB), agents/main/ all present and valid.
  • This appears to be a bug in the index append/write logic where the newline separator is occasionally lost.

SunshineR04 avatar Jul 19 '26 15:07 SunshineR04

I opened draft PR #2074 with a read-only recovery path. It keeps the normal single-record parse, recovers adjacent complete JSON containers in both readers of the shared index, preserves only the complete prefix before truncation or garbage, and never resynchronizes past an untrusted byte. It does not rewrite the index or change the writers; I have not reproduced the write-side trigger. Does that recovery boundary fit the intended direction?

shizhigu avatar Jul 22 '26 17:07 shizhigu