refactor: consolidate transcript file reads from 3x to 1x per session#16
Merged
Conversation
Each session refresh was opening, reading, and parsing the same transcript JSONL file three times (status, prompt, output). Introduce TranscriptSnapshot to read the file once and extract all data from the in-memory buffer. Existing standalone functions remain as thin wrappers for backward compatibility (daemon uses detect_session_status alone).
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
TranscriptSnapshotto read JSONL file once and extract status, prompt, and output from in-memory buffertranscript/info.rsas orchestration layer between parser and state modules to avoid circular dependenciesdetect_session_status,get_last_user_prompt,get_last_assistant_text) remain as thin wrappers for backward compatibilityMotivation
Each call to
detect_session_info()was opening/reading/parsing the same transcript file 3 times:detect_session_status()→read_lines_from_end(path, 20)get_last_user_prompt()→read_lines_from_end(path, 30)get_last_assistant_text()→read_lines_from_end(path, 30)With N sessions, this meant 3N file opens per refresh cycle. Now it's 1N.
Test plan
read_transcript_infovs individual functions)make allpasses (fmt + clippy -D warnings + test)daemon/watcher.rsunaffected (usesdetect_session_status(path)standalone)