Skip to content

fix: tolerate invalid UTF-8 in session transcript reads (#1518) - #1568

Open
doge-th wants to merge 1 commit into
anthropics:mainfrom
doge-th:fix/1518-invalid-utf8-transcripts
Open

doge-th wants to merge 1 commit into
anthropics:mainfrom
doge-th:fix/1518-invalid-utf8-transcripts

Conversation

@doge-th

@doge-th doge-th commented Nov 21, 2026

Copy link
Copy Markdown

Summary

Fixes #1518.

_try_read_session_file reads session transcripts with strict UTF-8 but catches only OSError. UnicodeDecodeError inherits from ValueError, so a single invalid byte in a stored .jsonl file escaped get_session_messages as an uncaught exception instead of degrading to [] the way missing/unreadable files do. The subagent-messages transcript read had the same gap; the .meta.json sidecar reader already handles it via its existing ValueError catch.

Changes

  • _try_read_session_file: catch (OSError, UnicodeDecodeError) → None
  • get_subagent_messages transcript read: catch (OSError, UnicodeDecodeError) → []

Tests

  • New TestInvalidUtf8Transcripts regression tests for both paths (fixtures write raw invalid-UTF-8 bytes into the transcript files).
  • Verified the tests fail on unpatched main (both raise UnicodeDecodeError) and pass with the fix.
  • Full suite: 1757 passed, 6 skipped. ruff and mypy clean.

Related

Sibling of #1521 (same file-robustness family; fixed in #1566).

)

_try_read_session_file and the get_subagent_messages transcript read
caught only OSError, so a single invalid byte in a stored JSONL file
escaped as UnicodeDecodeError from get_session_messages /
get_subagent_messages instead of degrading to [] / None the way missing
or unreadable files do. Catch UnicodeDecodeError alongside OSError at
both sites; the .meta.json sidecar reader already handled it via its
existing ValueError catch.

This branch has not been deployed

No deployments
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.

Invalid UTF-8 in a session file escapes get_session_messages as UnicodeDecodeError

1 participant