Stop disposed transcript reads from updating terminal chats

Merged
TE
2mo ago
+178-15

Closing or redirecting a terminal chat can leave a transcript read in flight. That read can still append old events, rename the view, or update status and attention after disposal. This change fences each read to its tail lifetime and guards callbacks against the active attachment. Restarting a tail begins a new read immediately and resumes at the last committed offset.

Depends on #16045; targets its branch so this PR contains only the disposal fix and regression.

Validation

From agent-chat, the same command bun run test/transcript-disposal.test.ts fails at 91892a70158bd258eb7ea6de2d52e884aa9eff93 with “a disposed transcript read must not emit late events” and passes at 3a5a306eac73cc2e5c56e2cfd13c7ccdf9205901.

The fixture uses real Claude/Codex transcript files and controlled intervals. It covers disposal during a pending read, redirecting a reused session, retained status callbacks, stopping partway through a multi-chunk file, immediate restart, polling while stopped, disposal inside an event batch, and timer cleanup.

On the final commit, bun run check passes TypeScript and the package tests (55 Bun tests across 14 files, plus 24 standalone assertion scripts). Both production browser entrypoints bundle successfully, and git diff --check acd284567484b77fbaca6e78b6f4446da98cf72a..HEAD passes. No live Cloud agent was exercised.

Changelog

Fixed: Closing or switching terminal chats no longer allows disposed transcript reads to update the view.


Summary by cubic

Stops disposed transcript reads from appending events, renaming views, or updating status after a terminal chat closes or redirects. In-flight reads are now fenced to the tail's current lifetime, and callbacks check the active attachment before running. Restarting a tail starts a fresh read at the last delivered offset, so restarts resume without duplicating rows.