perf(continuity): stream first user prompt instead of parsing the whole transcript#63
Merged
alexgreensh merged 1 commit intoJun 16, 2026
Conversation
…le transcript Why: firstUserPromptFromSession() resolved the first user message by calling loadMessagesFromSessionFile(), which reads AND JSON-parses every line of the session transcript. It only needs the first user message (which sits near the top of the file), and it runs on the cross-session continuity path that can fire on several early session:patch events before the first user prompt has landed on disk -- so each of those calls re-parsed an ever-growing transcript. What: replace that call with a streaming reader (firstUserPromptFromSessionFile) that reads the file in 64KB chunks and stops at the first non-empty user message. A StringDecoder buffers partial multi-byte UTF-8 sequences across chunk boundaries so text is never corrupted mid-character. The line-level parse (userTextFromJsonlLine) mirrors loadMessagesFromSessionFile's content handling (plain string or array of text blocks), so behavior is unchanged. loadMessagesFromSessionFile is still imported -- it remains in use elsewhere. How: verified equivalent to the previous implementation across 6 cases (assistant-first ordering, array-block content, tool_result-only user turns, no-user files, a multi-byte char forced onto a chunk boundary, and a 5000-line file where it early-exits). tsc build green; dist rebuilt.
Owner
|
Merged in v5.11.13. Streaming the first prompt instead of parsing the whole transcript is a clean win, and the UTF-8 chunk-boundary handling checks out. Thanks! |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Why
firstUserPromptFromSessionresolved the first user message by callingloadMessagesFromSessionFile, which reads and JSON-parses every line of the session transcript. It only needs the first user message (which sits near the top of the file), and it runs on the cross-session continuity path that can fire on several earlysession:patchevents before the first user prompt has landed on disk — so each of those calls re-parsed an ever-growing transcript.What
Replace that call with a streaming reader (
firstUserPromptFromSessionFile) that reads the file in 64 KB chunks and stops at the first non-empty user message:StringDecoderbuffers partial multi-byte UTF-8 sequences across chunk boundaries, so text is never corrupted mid-character.userTextFromJsonlLine) mirrorsloadMessagesFromSessionFile's content handling (plain string or array of text blocks), so behavior is unchanged.loadMessagesFromSessionFileremains imported — it is still used elsewhere.How (verified)
Verified equivalent to the previous implementation across 6 cases: assistant-first ordering, array-block content, tool_result-only user turns, no-user files, a multi-byte char forced onto a chunk boundary, and a 5000-line file where it early-exits.
tscbuild is green; committeddist/rebuilt.