Skip to content

fix(core): recover sessions with a corrupt or missing metadata line#27912

Draft
i-anubhav-anand wants to merge 2 commits into
google-gemini:mainfrom
i-anubhav-anand:fix/27276-corrupt-metadata-recovery
Draft

fix(core): recover sessions with a corrupt or missing metadata line#27912
i-anubhav-anand wants to merge 2 commits into
google-gemini:mainfrom
i-anubhav-anand:fix/27276-corrupt-metadata-recovery

Conversation

@i-anubhav-anand

Copy link
Copy Markdown

Draft — builds on #27904. This branch is stacked on the #27275 fix, so the diff currently includes that change too. Please review/merge #27904 first; I'll rebase this onto main (leaving only the recovery logic) and mark it ready once #27904 lands.

Summary

Fixes #27276.

The JSONL reader swallows per-line parse errors — including on the first metadata/identity line. If that line is truncated or malformed, no sessionId is recovered, so the loader returns null and discards every valid message record that followed. A whole conversation silently disappears from the session list because of one unreadable line.

Fix

When no session identity was recovered but valid message records exist, derive a stable session id from the file name (path.basename(filePath, '.jsonl')) instead of giving up. The conversation stays listable and resumable. If there are no recoverable records either, the legacy fallback path is preserved.

This complements #27275/#27904 (which makes projectHash optional for loading); together they make session loading resilient to missing/corrupt metadata.

Testing

  • Added a regression test: a session file with a truncated first metadata line plus a valid message line now loads (id derived from the file name) instead of returning null. Verified it fails before this change and passes after.
  • npx vitest run src/services/chatRecordingService.test.ts → 52 passed.
  • eslint (touched files) and npm run typecheck (packages/core) clean.

The session loader treated a record as valid only when both `sessionId`
and `projectHash` were present. When `projectHash` was absent it fell back
to the legacy parser, which reads the whole file with a single
`JSON.parse` — guaranteed to throw on multi-line JSONL — so the loader
returned null and a real session with messages became invisible to
list/resume.

Identify the metadata/identity line by `sessionId` alone and treat
`projectHash` as optional metadata (defaulted when absent), so a session
is no longer hidden because one metadata field is missing.

Fixes google-gemini#27275
The JSONL reader swallows per-line parse errors, including on the first
metadata/identity line. If that line is truncated or malformed, no
sessionId is recovered and the loader returns null — discarding every
valid message record that followed, so a whole conversation silently
disappears from the session list.

When no session identity was recovered but valid message records exist,
derive a stable session id from the file name instead of giving up, so
the conversation stays listable and resumable.

Fixes google-gemini#27276
@github-actions github-actions Bot added the size/m A medium sized PR label Jun 14, 2026
@github-actions

Copy link
Copy Markdown

📊 PR Size: size/M

  • Lines changed: 93
  • Additions: +85
  • Deletions: -8
  • Files changed: 3

@gemini-cli gemini-cli Bot added priority/p2 Important but can be addressed in a future release. area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality labels Jun 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality priority/p2 Important but can be addressed in a future release. size/m A medium sized PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Corrupted metadata line can hide the whole session

1 participant