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

fix(session): recover concatenated session index records

Open shizhigu opened this issue 4 months ago • 1 comments

Related Issue

Resolve #1925

Problem

If two session_index.jsonl records lose their newline separator, the reader drops both as invalid JSON. The session directory remains intact, but resume returns session.not_found.

The writer-side trigger is still unknown, so this change is limited to read-time recovery.

What changed

  • Keep JSON.parse as the single-record fast path. On failure, scan adjacent JSON containers with correct nesting, string, and escape handling.
  • Apply complete records in file order through the existing path checks. Stop at malformed data, then continue with the next physical line.
  • Put the v2 compatibility reader behind a private App-scoped Store. Workspace services consume validated entries and no longer know about bytes or JSONL framing.
flowchart LR
  I[session_index.jsonl] --> V1[v1 SessionStore reader]
  I --> S[v2 legacy-index Store]
  S --> W[Workspace services]

Here A and B are complete records:

Input Recovered
A\nB A, B
AB A, B
A + truncated B A
A + garbage + B A

Recovery does not rewrite the index.

Validation

  • v1: 31 focused and 3,983 full-suite tests passed.
  • v2: 33 focused and 3,960 full-suite tests passed, including a 150,000-record line.
  • Public SDK resume regression: 8 passed, 1 todo. Full node-sdk suite: 231 passed, 1 todo.
  • Three package typechecks, v2 domain lint, type-aware lint, klient smoke, changeset status, and git diff --check passed.

The original Windows writer-side trigger was not reproduced. Tests use the missing-separator shape from the issue.

Checklist

  • [x] I have read the CONTRIBUTING document.
  • [x] I have linked a related issue, or explained the problem above.
  • [x] I have added tests that prove my feature works.
  • [x] Ran gen-changesets skill, or this PR needs no changeset.
  • [x] Ran gen-docs skill, or this PR needs no doc update.

shizhigu avatar Jul 22 '26 17:07 shizhigu

🦋 Changeset detected

Latest commit: 8770228819b7cad8aa3d0095fdbb3389ee1a0cf0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

changeset-bot[bot] avatar Jul 22 '26 17:07 changeset-bot[bot]