Recover terminal chat when transcript files are replaced
An atomically replaced terminal transcript can have the same or a larger size than the old file. Agent Chat currently keeps the old byte offset: a same-size replacement is invisible, and a larger replacement can skip its first records. This leaves Cloud terminal chat stale even though the source file changed.
Track file device/inode identity and confirm the opened file's stats before using its offset. On replacement, reset byte and UTF-8 decoding state and read using the existing bounded initial window (8 MiB by default). Unchanged files retain the stat-only polling path.
A file reset also resets the transcript parser and replaces displayed history. Subscribed views receive an empty authoritative history before replacement events, so copied Codex history is shown once and removed content does not remain in the view. In-place truncation uses the same history reset; transcript path changes reuse the server's shared reset path. This covers atomic replacements and observed shrinkage; same-inode rewrites that grow between polls are outside this detection rule.
Validation
- From
agent-chat, the focused command isbun test test/transcript-replacement.test.ts. - First red regression:
e54f0021e0ed1259b68f8bf8ff9e7701ac731041— six failures, including a missed same-size replacement and skipped first records after a larger replacement. - History reconciliation regression:
4151a9da08f3e346ba874a87202c72c9ccd4e093— three failures, showing stale displayed content and duplicated copied Codex history after the reader resumed. - Green:
acd284567484b77fbaca6e78b6f4446da98cf72a— all 11 focused tests pass. Real file renames cover identical size/mtime, larger and empty replacements, split UTF-8 decoding, bounded replay, and continued appends. Both Claude and Codex attachment paths are exercised. The production server reset/event paths are driven through a subscribed socket fixture, verifying history-before-event ordering and reset generation metadata. bun run checkpassed TypeScript, 23 script suites, and 55 Bun tests across 14 files. Both production browser entrypoints bundled successfully;git diff --check 304d3468debbcc21d3c691392404f46607aba77d..HEADpassed. Bundle output stayed under the worktree's disposablescratch/build-check.- No live terminal agent or Cloud instance was used. The sparse checkout omits the root verifier, so verification used the affected package. No UI copy or localization keys changed.
Changelog
Fixed Cloud terminal chat missing replaced transcripts or duplicating copied history when following the replacement file.
Summary by cubic
Fixes Cloud terminal chat missing transcripts when the source file is atomically replaced, by tracking file identity (dev/ino) instead of relying on size/mtime alone.
- On replacement, reading restarts from the bounded initial window (
8 MiBby default) and UTF-8 decoding state is cleared. - Subscribed views receive an empty history before replacement events, so replayed events replace instead of duplicate the displayed history.
- Stops and disposal now fence in-flight reads by generation, so late filesystem results can’t deliver events, rename the view, or update status after a session is redirected or disposed.
- Same-inode truncation and transcript path changes reuse the same reset path.