Skip to content

Read only the transcript lines Claude Code has finished writing - #3700

Merged
max-sixty merged 2 commits into
mainfrom
journey-transcript-partial-line
Oct 23, 2026
Merged

max-sixty merged 2 commits into
mainfrom
journey-transcript-partial-line

Conversation

@max-sixty

@max-sixty max-sixty commented Oct 23, 2026 •

Copy link
Copy Markdown
Owner

The Claude Code journey reads the session's transcript while Claude Code is still writing it, between steps and as it breaks a reply down. When the read caught a record half-written, the last line didn't parse, and the journey failed with a JSONDecodeError even though the session itself was fine. That happened twice in one batch of #46 benchmark runs.

native_records now decodes only the bytes up to the last newline, leaving out the record that isn't finished. Those bytes can end inside a character, so it splits before decoding. The next read picks the record up once Claude Code finishes writing it. The transcript test now ends its file in a half-written record cut inside a two-byte character. It fails without the fix and passes with it.

This is the transcript-read fix from Max's decision #46 on the overnight report. The #46 experiment itself stays unmerged on opening-progress-experiment.

This was written by Claude Code on behalf of max-sixty

The Claude Code journey reads the session's transcript while Claude Code
is still writing it, and a half-written last line failed the journey
with a JSONDecodeError. native_records now leaves out a last line with
no newline yet; the next read picks it up once it is complete.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A partial UTF-8 character at the end of the transcript still makes this reader fail: read_text() raises UnicodeDecodeError before the unfinished line can be discarded. I reproduced this with one complete JSON line followed by an unfinished record ending in the first byte of a two-byte character. Split the bytes at the last newline before decoding the complete records.

Comment thread dev/leaf_dev/journey_claude_code.py Resolved
A partial UTF-8 character at the end of the transcript failed the read
before the unfinished line could be left out.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit be0044f into main Oct 23, 2026
3 checks passed
@max-sixty
max-sixty deleted the journey-transcript-partial-line branch October 23, 2026 06:46
max-sixty added a commit that referenced this pull request Oct 23, 2026
The Claude Code journey's transcript reads still failed with
`JSONDecodeError: Unterminated string`, after #3700. The cause was not a
half-written last line, as #3700 assumed. Claude Code writes U+2028 and
U+2029 raw inside JSON strings, which JSON allows, and both readers
split the transcript with `splitlines()`, which breaks a line at those
characters. A transcript kept from a failed run held one U+2028 and one
U+2029: 113 newlines, but 115 lines to `splitlines()`.

Both readers now share `reply_phases.transcript_records`:

- `journey_claude_code.native_records` reads the journey's session.
- `claude_code_transcript` reads a session for `leaf-dev
response-times`.

It splits only at the newline Claude Code writes after each record, and
keeps #3700's rule of leaving out a record still being written. The
transcript test now holds a raw U+2028 inside a string. It fails without
the fix and passes with it.

This follows up #3700, the transcript-read fix from Max's decision #46
on the overnight report. `leaf.event_log.jsonl_line` already escapes
these characters in the page log for the same reason.

> _This was written by Claude Code on behalf of max-sixty_

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
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.

2 participants