Repository navigation
Conversation
The two message-page helpers sliced with the raw offset when a positive limit was given: messages[offset : offset + limit] with a negative offset returned an empty/wrong page, while the no-limit branch treated the same offset as absent. get_session_messages(sid, limit=5, offset=-1) on a 10-message session returned []. Mirror _apply_sort_limit_offset's guards in _entries_to_session_messages and _entries_to_subagent_messages, which the SessionStore path already follows: non-positive offsets are treated as absent and a positive limit takes the first entries after the offset. Fixes anthropics#1519
_try_read_session_file and the subagent transcript read caught only OSError, but UnicodeDecodeError is a ValueError subclass, so a single invalid byte in a transcript escaped get_session_messages as an uncaught exception instead of degrading to [] like a missing or unreadable file. Catch ValueError at both sites, matching _read_agent_metadata_sidecar; _read_session_lite already tolerates undecodable bytes via errors="replace". Fixes anthropics#1518
This branch has not been deployed
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
Fixes #1518.
_try_read_session_fileand the subagent transcript read inget_subagent_messagesdecode with strict UTF-8 but catch onlyOSError.UnicodeDecodeErrorinherits fromValueError, so a single invalid byte in a transcript escapedget_session_messagesas an uncaught exception instead of degrading to[]the way missing or unreadable files do.Both sites now catch
(OSError, ValueError)and return their empty fallback — matching_read_agent_metadata_sidecar(which already catchesValueError);_read_session_litetolerates undecodable bytes viaerrors="replace".Test plan
TestGetSessionMessages::test_undecodable_transcript_degrades_to_empty: a transcript with invalid UTF-8 followed by a valid JSONL line returns[]fromget_session_messages, and a corrupt subagent transcript returns[]fromget_subagent_messagesinstead of raising.mainwithUnicodeDecodeErrorand passes with the fix.pytest tests/: 1756 passed, 6 skipped (this branch).ruff check,mypy src/ scripts/clean.