fix(session): skip corrupt lines in load_transcript instead of crashing#1744
Merged
fix(session): skip corrupt lines in load_transcript instead of crashing#1744
Conversation
Wrap json.loads() in load_transcript() with try/except JSONDecodeError so that partial JSONL lines (from mid-write crashes like OOM/SIGKILL) are skipped with a warning instead of crashing the entire transcript load. The rest of the history loads fine. Adds a logger.warning with the session ID and truncated corrupt line content for debugging visibility. Salvaged from PR #1193 by alireza78a. Closes #1193
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
Salvaged from PR #1193 by @alireza78a.
load_transcript()had no error handling aroundjson.loads(). If the gateway is killed mid-write (OOM, SIGKILL, power loss), the last line of the JSONL transcript file can end up partial/truncated. On the next session load,json.loadsraisesJSONDecodeErrorand the entire transcript fails to load — the user sees blank context with no history.Changes
json.loads(line)in atry/except json.JSONDecodeErrorblocklogger.warningwith the session ID and truncated line content (first 120 chars) for debugging visibilityTests
3 new tests in
TestLoadTranscriptCorruptLines:test_corrupt_line_skipped— truncated JSON mid-line is skipped, valid lines before and after load finetest_all_lines_corrupt_returns_empty— file with only corrupt lines returns empty list (no crash)test_valid_transcript_unaffected— normal transcripts still load correctlyAll 5231 tests pass.
Closes #1193