Repository navigation
Load each long transcript's older history in the background - #37
Merged
Merged
Conversation
10 tasks
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.
On a long-running session antfarm only read the last 16 MB of the transcript, so the swimlanes started partway through, call counts and files touched undercounted, and results whose call sat before the cut were dropped. Even inside the tail, each agent kept only its last 500 activity entries, which is where the "older calls not kept" marker came from. On this machine the Greatsword transcript is 487 MB, and main shows about 1,100 of its 9,100 calls.
Attach still reads the tail first, so live state shows up as fast as before. Then a background thread reads each cut transcript backward from its boundary to the first line, main transcripts and sub-agents alike, and turns each chunk into compact call records: id, tool, summary, start, end, status, and the byte offsets of the call and result lines. The engine merges those in front of what the tail read, and never runs old lines through the live reducer, so status, names, and context fill are untouched. The same compact store also takes calls as they age out of the 500-entry activity list, so nothing is cut any more. Inputs and results aren't kept for older calls. The call screen reads them back from the transcript by offset, and it now shows the result for every call, which it never did before.
Acceptance criteria
watch's settle step used to wait for snapshots to go quiet, which backfill progress would have stretched to its 5 s cap; it now waits for events to go quiet, and backfill emits none. Measured on this machine with release builds, three runs each, time to the firstwatch --jsonsnapshot: main 1.3 to 2.5 s, branch 0.6 to 2.5 s, branch with--no-backfill1.2 to 2.4 s. All of it is settle time, and the spread is noise from the live sessions.Session.historyisloading {read, total}while backfill runs, thencomplete, andtruncated_beforeclears. The TUI and app swimlanes show "loading older history 34%" where "older calls not kept" used to be. Tests:progress_shows_while_backfill_readsincrates/antfarm-core/tests/backfill.rsanda_tail_orphan_is_paired_with_its_backfilled_callinreduce.rs.backfill_matches_reading_every_transcript_wholeattaches to the scrubbedreal/small-sessionfixture with a 32 KB tail and 8 KB chunks, then compares every agent's call count, every call's id, tool, start, end, status, and summary in order, and the files touched list with line counts against a run that reads every file whole. On real data, Greatsword's root shows 8,587 calls, which matches a grep of distincttool_useids in the transcript.call_detail_reads_an_older_calls_input_and_result_from_the_transcriptinview.rschecks that both are masked. By hand: in the TUI I opened an AskUserQuestion call from mid-October on Greatsword, weeks before the tail, and saw its full input and answer.a_transcript_that_moves_during_backfill_is_followedrenames the project folder mid-backfill; counts still match the whole read. Jobs open their file at attach, which this test caught: a queued sub-agent job used to lose its file after a move.a_transcript_replaced_during_backfill_has_no_duplicate_callsreplaces the main transcript mid-backfill and checks that ids are unique and that what the cancelled job merged was taken back out of the store and the call count. Unit testa_batch_from_a_stale_job_is_dropped.watch --jsonmarks history and emits an event. Each session in a snapshot carrieshistory, and the stream carries ahistory_completeevent (backfill_matches_reading_every_transcript_wholechecks the event). On this machine backfill of the 487 MB file finishes insidewatch's settle window, because most of its bytes areapi-request-bloblines skipped by type, so the first snapshot already sayscompleteand the event comes beforewatchsubscribes. That followswatch's existing rule that history up to now is in the first snapshot.--no-backfill, global.lsanddoctornever backfill. Test:the_flag_off_leaves_history_partial./usr/bin/time -l antfarm watch --json --sessionon the 487 MB session: 71 MB. The whole machine (7 sessions, 10,188 calls): 73 MB, against 51 to 57 MB on main or with backfill off. Recorded in DESIGN.md section 5.Checked by hand
check-ui) at 1440, 1000, and 960 wide, dark and light: a result in the Output tab, a 400-line result scrolls inside the tab with no horizontal overflow and the "cut at 20,000 characters" note at the end, an error result uses the theme's error color, and the swimlane loading note fits on one line at 960 and ends 16 px from the edge. That check also turned up a missing space before the session screen's active-time label ("3h36m· partial history"); the old "· last 500 calls" label had the same bug, and it's fixed.live-reproon Claude Code 2.1.325 with Haiku: Bash calls, a background Agent, and an AskUserQuestion wait. Main and the branch showed the same status sequence (idle, thinking, working, thinking, idle, thinking, waiting on a question, thinking, idle), the same event counts, and 7 calls, which matches the transcript (5 main, 2 sub-agent).Not checked
pnpm tauri dev); only the mock.cost-stateline. Backfilled background Bash calls don't carry their background run, so their output tail isn't offered.Related: #36 (forked skills not linked to their Skill call) was found along the way and isn't part of this.
Closes #13