Repository navigation
fix: fork_session drops transcript entries containing U+2028/U+2029/U+0085 - #1495
Open
Sathwik-giddi wants to merge 1 commit into
Open
Sathwik-giddi wants to merge 1 commit into
Sathwik-giddi wants to merge 1 commit into
Conversation
…0085 _parse_fork_transcript split the transcript with str.splitlines(), which also breaks on U+2028, U+2029 and U+0085 — characters Claude Code's JS JSON.stringify leaves unescaped inside strings. A single record holding one of them was cut into pieces that all failed json.loads and were silently skipped, so the entry disappeared from the fork and the next entry's parentUuid resolved to None, breaking the resumed chain. Split on "\n" only — the record separator the CLI actually writes — the same approach _parse_transcript_entries in sessions.py already uses. Fixes anthropics#1441
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.
Problem
_parse_fork_transcriptsplit the transcript withstr.splitlines(), which also breaks on U+2028 (LINE SEPARATOR), U+2029 (PARAGRAPH SEPARATOR) and U+0085 (NEL) — characters Claude Code's JSJSON.stringifyleaves unescaped inside strings (valid JSON). A single record holding one of them was cut into pieces that all failedjson.loadsand were silently skipped by theexcept: continuebranch. The entry disappeared from the fork and the next entry'sparentUuidresolved toNone, breaking the resumed chain — resuming the fork then loaded only the part after the break.Fix
Split on
"\n"only — the record separator the CLI actually writes — the same approach_parse_transcript_entriesinsessions.pyalready uses. Behavior for well-formed JSONL is unchanged; a comment documents whysplitlines()must not be reintroduced here.Testing
test_fork_preserves_entries_with_unicode_line_separatorswrites a 3-entry transcript (the middle one containing all three separator characters, unescaped as Claude Code writes it), forks it, and asserts all three messages survive with an intact parent chain. Red before the fix (fork contained['first', 'third']), green after.ruff check,ruff format,mypyclean.Fixes #1441