perf(host): reopen recent transcripts from what the host held
Merged
CH
4d ago+570+570+012345678901234567890123456789-56-56-01234567890123456789
Performance rollout, 90/10 follow-up: reopening an agent transcript you saw recently draws at once from what the host already read, then catches up from its cursor.
What changed
packages/host/src/transcript-held.ts(new): an LRU of the newest window of the lastHELD_TRANSCRIPTS = 8followed transcripts,HELD_BYTES = 4 MBin total (1 MB max per entry, which is dropped rather than cut, since cutting the oldest end would break itsbefore). It lives in an EffectRefin the host process only, keyed byTranscriptKeyand account id. Asking for or writing an entry under a different account drops every entry held for any other account.followTranscript: takes a per-transcriptTranscriptMemory. When it holds a window, it tells that window first (newest: true, held: true), before the seal or any read, and then reads forward withmessagesNowfrom the held cursor once the subscription stands. Every page it tells is joined into the held window withapplyMessagesPage, so the window keeps the forward cursor and the newest page'sbefore. If the first read from a held cursor fails with anything but not-found, the follow drops the entry and falls back tomessagesNewest, the same way a fresh open does. That failure is never told to the window. A not-found from the seal or a read drops the entry too.- Composer:
reset(sign-out) clears everything held, and a successful archive drops the agent's own transcript and its workers'. - Wire:
codingAgentTranscriptPageSchemagets an optionalheld: true. This is a host→window flag only, with no server change. - Panel: both transcript spans now carry
transcript.cache_hit(1 or 0), sotranscript.first_paintstays honest on cache hits.
Tests (fake client, TestClock)
- A re-follow is told the held window before any client call, then makes exactly one
messagesNowfrom the held cursor. A message written while away arrives. - A held message older than the cursor that is rewritten while away arrives on the forward read (
seq > S or revision > R), and the next held window carries the rewrite in place. - A refused held cursor falls back to newest, and the refusal is never told.
- Sign-out, an account switch, and an archive each clear what was held.
- The LRU evicts the least recently used entry past 8.
- Panel: a held first page draws at once, and
first_paintgetscache_hit: 1. - One existing assertion changed: after a seal that went unanswered, following again opens on the held window instead of reading the newest page a second time.
Out of scope: caching the task document or agent list (Owen's PR), and server changes.
Made with Luke