Skip to content

fix(session): recover concatenated session index records#2074

Draft
shizhigu wants to merge 2 commits into
MoonshotAI:mainfrom
shizhigu:agent/fix-corrupt-session-index
Draft

fix(session): recover concatenated session index records#2074
shizhigu wants to merge 2 commits into
MoonshotAI:mainfrom
shizhigu:agent/fix-corrupt-session-index

Conversation

@shizhigu

@shizhigu shizhigu commented Jul 22, 2026

Copy link
Copy Markdown

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]
Loading

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

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

@changeset-bot

changeset-bot Bot commented Jul 22, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8770228

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

@shizhigu
shizhigu force-pushed the agent/fix-corrupt-session-index branch from 490fb8d to 8770228 Compare July 22, 2026 21:10
@shizhigu
shizhigu marked this pull request as ready for review July 22, 2026 21:30
@shizhigu
shizhigu marked this pull request as draft July 22, 2026 22:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant