[PR #13032] fix(core): tolerate corrupted JSON in session storage #14485

Open
opened 2026-02-16 18:19:16 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/13032

State: open
Merged: No


Fixes #7607

When a crash or OOM occurs mid-write, session part files can be left truncated or empty (0 bytes). This causes SyntaxError: Unexpected end of JSON input which breaks the entire session.

Changes:

  • Storage.withErrorHandling now converts SyntaxError to NotFoundError (matching the existing ENOENT pattern)
  • MessageV2.parts() gracefully skips corrupted part entries instead of crashing
  • MessageV2.stream() gracefully skips corrupted messages instead of crashing

How I verified:

  • Truncated a session part file to 0 bytes on a live server
  • Confirmed the SyntaxError: Unexpected end of JSON input in journalctl
  • Applied the fix, restarted — session opened normally, only the corrupted part was skipped
  • All 13 existing message-v2.test.ts tests pass
  • Typecheck passes
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/13032 **State:** open **Merged:** No --- Fixes #7607 When a crash or OOM occurs mid-write, session part files can be left truncated or empty (0 bytes). This causes `SyntaxError: Unexpected end of JSON input` which breaks the entire session. **Changes:** - `Storage.withErrorHandling` now converts `SyntaxError` to `NotFoundError` (matching the existing `ENOENT` pattern) - `MessageV2.parts()` gracefully skips corrupted part entries instead of crashing - `MessageV2.stream()` gracefully skips corrupted messages instead of crashing **How I verified:** - Truncated a session part file to 0 bytes on a live server - Confirmed the `SyntaxError: Unexpected end of JSON input` in journalctl - Applied the fix, restarted — session opened normally, only the corrupted part was skipped - All 13 existing `message-v2.test.ts` tests pass - Typecheck passes
yindo added the pull-request label 2026-02-16 18:19:16 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#14485