Skip to content

fix(session): skip corrupt lines in load_transcript instead of crashing#1744

Merged
teknium1 merged 1 commit intomainfrom
hermes/hermes-8058968e
Mar 17, 2026
Merged

fix(session): skip corrupt lines in load_transcript instead of crashing#1744
teknium1 merged 1 commit intomainfrom
hermes/hermes-8058968e

Conversation

@teknium1
Copy link
Contributor

Summary

Salvaged from PR #1193 by @alireza78a.

load_transcript() had no error handling around json.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.loads raises JSONDecodeError and the entire transcript fails to load — the user sees blank context with no history.

Changes

  • Wrap json.loads(line) in a try/except json.JSONDecodeError block
  • Skip the corrupt line and log a logger.warning with the session ID and truncated line content (first 120 chars) for debugging visibility
  • The rest of the history loads normally

Tests

3 new tests in TestLoadTranscriptCorruptLines:

  • test_corrupt_line_skipped — truncated JSON mid-line is skipped, valid lines before and after load fine
  • test_all_lines_corrupt_returns_empty — file with only corrupt lines returns empty list (no crash)
  • test_valid_transcript_unaffected — normal transcripts still load correctly

All 5231 tests pass.

Closes #1193

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
@teknium1 teknium1 merged commit 7021910 into main Mar 17, 2026
1 check passed
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.

1 participant