fix(core): recover sessions with a corrupt or missing metadata line#27912
Draft
i-anubhav-anand wants to merge 2 commits into
Draft
fix(core): recover sessions with a corrupt or missing metadata line#27912i-anubhav-anand wants to merge 2 commits into
i-anubhav-anand wants to merge 2 commits into
Conversation
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
|
📊 PR Size: size/M
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
sessionIdis recovered, so the loader returnsnulland 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
projectHashoptional for loading); together they make session loading resilient to missing/corrupt metadata.Testing
null. Verified it fails before this change and passes after.npx vitest run src/services/chatRecordingService.test.ts→ 52 passed.eslint(touched files) andnpm run typecheck(packages/core) clean.