perf(host): reopen recent transcripts from what the host held

Merged
CH
4d ago
+570-56

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 last HELD_TRANSCRIPTS = 8 followed transcripts, HELD_BYTES = 4 MB in total (1 MB max per entry, which is dropped rather than cut, since cutting the oldest end would break its before). It lives in an Effect Ref in the host process only, keyed by TranscriptKey and account id. Asking for or writing an entry under a different account drops every entry held for any other account.
  • followTranscript: takes a per-transcript TranscriptMemory. When it holds a window, it tells that window first (newest: true, held: true), before the seal or any read, and then reads forward with messagesNow from the held cursor once the subscription stands. Every page it tells is joined into the held window with applyMessagesPage, so the window keeps the forward cursor and the newest page's before. If the first read from a held cursor fails with anything but not-found, the follow drops the entry and falls back to messagesNewest, 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: codingAgentTranscriptPageSchema gets an optional held: true. This is a host→window flag only, with no server change.
  • Panel: both transcript spans now carry transcript.cache_hit (1 or 0), so transcript.first_paint stays honest on cache hits.

Tests (fake client, TestClock)

  • A re-follow is told the held window before any client call, then makes exactly one messagesNow from 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_paint gets cache_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


Devin Review