Visitar URL original
fix: fork_session drops transcript entries containing U+2028/U+2029/U+0085 by Sathwik-giddi · Pull Request #1495 · anthropics/claude-agent-sdk-python · GitHub
Skip to content

fix: fork_session drops transcript entries containing U+2028/U+2029/U+0085 - #1495

Open
Sathwik-giddi wants to merge 1 commit into
anthropics:mainfrom
Sathwik-giddi:fix/fork-transcript-unicode-separators
Open

Sathwik-giddi wants to merge 1 commit into
anthropics:mainfrom
Sathwik-giddi:fix/fork-transcript-unicode-separators

Conversation

@Sathwik-giddi

Copy link
Copy Markdown

Problem

_parse_fork_transcript split the transcript with str.splitlines(), which also breaks on U+2028 (LINE SEPARATOR), U+2029 (PARAGRAPH SEPARATOR) and U+0085 (NEL) — characters Claude Code's JS JSON.stringify leaves unescaped inside strings (valid JSON). A single record holding one of them was cut into pieces that all failed json.loads and were silently skipped by the except: continue branch. The entry disappeared from the fork and the next entry's parentUuid resolved to None, 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_entries in sessions.py already uses. Behavior for well-formed JSONL is unchanged; a comment documents why splitlines() must not be reintroduced here.

Testing

  • New test_fork_preserves_entries_with_unicode_line_separators writes 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.
  • Full suite passes; ruff check, ruff format, mypy clean.

Fixes #1441

…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

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.

fork_session drops transcript entries containing U+2028/U+2029/U+0085 (str.splitlines), breaking the parentUuid chain

1 participant