perf(agent-worker): settling a turn reads only that turn's transcript rows
What
Each agent-session turn downloaded the session's whole transcript (every page) up to four times: twice in runTurn, once in settleTurn, and once to read a failed turn's last error. A Dev's main session never ends, so every one of those reads grew with the Dev's whole history.
SessionStore.transcript(afterSeq?)starts its paging atafterSeq.turnRows(store, turnId)gets the turn's start row with the existingtranscriptStep(?stepKey=) query and reads only the rows after it. It replacesturnStartIndex,turnStartOf,entriesOfTurnandtailEntries.runTurn's second read (after it appends the run marker) fetches only the new rows.
The one full read that restores pdev's session file stays.
Why it keeps behaviour
Transcript seq is INTEGER PRIMARY KEY AUTOINCREMENT in the session's Durable Object, so "rows after the start row in the full list" is "rows with seq above the start row's seq". A turn with no start row still gives no entries and no start time.
Tests
- New
settleTurntest "reads only the rows of its own turn": two turns, then settle the second; the store sees one read, from the second turn's start. It fails onmain(the read is from 0). - The in-memory store now honours
afterSeq, so the existingrunTurntests cover the incremental read. bun testinapps/agent-worker20/20,bun run typecheckandbiome checkclean.
Summary by cubic
Makes turn settling read only the current turn's transcript rows instead of the session's whole history, so reads no longer grow with a Dev's lifetime.
Each turn previously downloaded the entire transcript up to four times: twice in runTurn, once in settleTurn, and once to read a failed turn's last error. settleTurn and the error read now find the turn's start row via the existing transcriptStep query and fetch only the rows after it; runTurn's post-marker read fetches only new rows.
SessionStore.transcript(afterSeq?)now starts paging atafterSeq.- The new
turnRows(store, turnId)helper replacesturnStartIndex,turnStartOf,entriesOfTurn, andtailEntries. - Behavior is unchanged because transcript
seqis an autoincrement key: rows after the start row are rows with a higherseq, and a turn with no start row still yields no entries and no start time. - The one full read that restores pdev's session file stays.