fix(ledger): recover from corrupted JSON instead of crashing

ledger.load now catches JSONDecodeError/ValueError and falls back to
an empty ledger, matching the defensive pattern already used by
sigil.load. Prevents a truncated or manually corrupted ledger file
from permanently breaking build_context for that stream.

https://claude.ai/code/session_01K7BWJY2gUoJi6dq91Yc7nx
This commit is contained in:
Claude 2026-02-27 22:57:33 +00:00
parent 39a37331d7
commit 949aa5d9bd
No known key found for this signature in database

View File

@ -43,7 +43,12 @@ def load(stream_id: str) -> dict:
ledger["stream"] = stream_id
return ledger
with open(path, "r", encoding="utf-8") as f:
data = json.load(f)
try:
data = json.load(f)
except (json.JSONDecodeError, ValueError):
ledger = dict(_EMPTY_LEDGER)
ledger["stream"] = stream_id
return ledger
# Ensure all expected keys exist
for key, default in _EMPTY_LEDGER.items():
if key not in data: