Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

A turn written just after a transcript rewrite reaches clients again: the re-attach starts live where the rewrite was found (#1064)

Deed50d3adbb6f8
diff --git a/cli/src/core/engines/liveSessions.lifecycle.spec.ts b/cli/src/core/engines/liveSessions.lifecycle.spec.ts
index 4faa31ae0..44640d32c 100644
--- a/cli/src/core/engines/liveSessions.lifecycle.spec.ts
+++ b/cli/src/core/engines/liveSessions.lifecycle.spec.ts
@@ -117,6 +117,22 @@ describe('live session lifecycle', () => {
expect(p.transport.pull).toHaveBeenCalledTimes(3)
})
+ it('says a rewrite once through the default logger, and the re-attach names the stream whose read found it', async () => {
+ vi.useFakeTimers()
+ const say = vi.spyOn(console, 'log').mockImplementation(() => {})
+ vi.spyOn(console, 'warn').mockImplementation(() => {})
+ const p = setup(true), s = p.session()
+ const original = await p.attach(s)
+ p.transport.pull.mockRejectedValue(new EngineLiveError('ENGINE_TRANSCRIPT_CHANGED'))
+ await expect(p.live.pollSession(s.sessionId)).rejects.toMatchObject({ code: 'ENGINE_TRANSCRIPT_CHANGED' })
+ await vi.advanceTimersByTimeAsync(1_000)
+ expect(say.mock.calls.filter(([line]) => String(line).includes('transcript rewritten in place'))).toHaveLength(1)
+ expect(p.deps.reattach).toHaveBeenCalledWith(s)
+ p.transport.pull.mockImplementation(async ask => reply(ask))
+ const replacement = await p.prepare(s)
+ expect(replacement.state.ask).toMatchObject({ rewritten: true, rewrittenFrom: original.state.ask.token })
+ })
+
it('coalesces concurrent drains and remembers file changes arriving during a read', async () => {
vi.useFakeTimers()
const p = setup(), s = p.session(); await p.attach(s)
diff --git a/cli/src/core/engines/liveSessions.spec.ts b/cli/src/core/engines/liveSessions.spec.ts
index 03e2044ad..838799f9c 100644
--- a/cli/src/core/engines/liveSessions.spec.ts
+++ b/cli/src/core/engines/liveSessions.spec.ts
@@ -234,6 +234,32 @@ describe('core engine stream authority', () => {
expect(t.live.tails(t.session.sessionId, t.file)).toBe(false)
})
+ it('delivers a turn written after the rewrite was found, before the re-attach, as fresh, not history', async () => {
+ // e2e/bounded.e2e.ts since #1019: the re-attach comes a second after the rewrite is found, and the turn
+ // the agent ran in that second was folded into history, so no client ever saw it start or end.
+ const t = await setup(prompt('a much longer original turn'))
+ const original = await t.attach()
+ await writeFile(t.file, prompt('history') + done)
+ await expect(t.live.pollSession(t.session.sessionId)).rejects.toThrow('ENGINE_TRANSCRIPT_CHANGED')
+ await appendFile(t.file, prompt('fresh') + done)
+ // Core pulls with the old cursor until it re-attaches; each pull finds the change again.
+ await expect(t.live.pollSession(t.session.sessionId)).rejects.toThrow('ENGINE_TRANSCRIPT_CHANGED')
+ const said = t.log.mock.calls.filter(([line]) => String(line).includes('transcript rewritten in place — attaching it again'))
+ expect(said).toEqual([[`[engine] ${t.session.sessionId} transcript rewritten in place — attaching it again from where it was rewritten`]])
+ const hold = await t.live.hold(t.session.sessionId, t.file)
+ const replacement = await t.prepare()
+ expect(replacement.state.ask).toMatchObject({ rewritten: true, rewrittenFrom: original.state.ask.token })
+ expect(t.live.install(replacement)).toBe(true)
+ hold!.release()
+ await t.live.pollSession(t.session.sessionId)
+ const turns = t.frames.flatMap(frame => frame.events.filter(event => event.type.startsWith('turn_'))
+ .map(event => [event.type, (event.payload as { userMessage?: string } | undefined)?.userMessage ?? null, frame.replay]))
+ expect(turns).toEqual([
+ ['turn_started', 'history', true], ['turn_ended', null, true],
+ ['turn_started', 'fresh', false], ['turn_ended', null, false],
+ ])
+ })
+
it('activates a replacement under a hold and replays its history before delivering a fresh turn', async () => {
const t = await setup(prompt('a much longer original turn'))
await t.attach()
diff --git a/cli/src/core/engines/liveSessions.ts b/cli/src/core/engines/liveSessions.ts
index 8e7ef6d63..74e74e417 100644
--- a/cli/src/core/engines/liveSessions.ts
+++ b/cli/src/core/engines/liveSessions.ts
@@ -91,7 +91,8 @@ export function createLiveSessions(deps: LiveSessionDeps) {
engine: session.engine, transcriptPath: session.transcriptPath, cwd: session.cwd, model: session.model,
cliVersion: session.cliVersion, codexHome: session.codexHome }, cursor: null, fromStart: live,
replay: false, liveStart: live, ...(end === undefined ? {} : { end }),
- ...(tails.get(session.sessionId)?.rewritten ? { rewritten: true } : {}) },
+ // The stream still installed is the one whose read found the rewrite: its worker knows where.
+ ...(tails.get(session.sessionId)?.rewritten ? { rewritten: true, rewrittenFrom: states.get(session.sessionId)?.ask.token } : {}) },
handle: {
engine: session.engine,
// Handles escape prepare only after the worker has supplied a validated cursor.
@@ -146,6 +147,8 @@ export function createLiveSessions(deps: LiveSessionDeps) {
catch (error) {
if (error instanceof EngineLiveError && error.code === 'ENGINE_TRANSCRIPT_CHANGED') {
// No cursor from the changed file is accepted. Re-attach under a hold and a new identity.
+ // Said once per rewrite, as the legacy tailer says it (core/transcripts/ingest.ts).
+ if (!tail.rewritten) (deps.log ?? console.log)(`[engine] ${id} transcript rewritten in place — attaching it again from where it was rewritten`)
tail.rewritten = true
const session = deps.bySession(id)
if (session) retry(session)
diff --git a/cli/src/engines/worker/liveProtocol.ts b/cli/src/engines/worker/liveProtocol.ts
index 3946ab872..2fdc7d5e8 100644
--- a/cli/src/engines/worker/liveProtocol.ts
+++ b/cli/src/engines/worker/liveProtocol.ts
@@ -128,5 +128,9 @@ export interface LivePull {
liveStart?: boolean
/** Rebuild after replacement/truncation; stream a small rewritten file as history after activation. */
rewritten?: boolean
+ /** The stream whose read found the file rewritten. Its records up to where that read found them are
+ * history and the rest are live, as the legacy tailer placed the boundary when it noticed the rewrite.
+ * A worker that never saw that read, or a file changed again since, hydrates as `rewritten` alone. */
+ rewrittenFrom?: string
end?: number
}
diff --git a/cli/src/engines/worker/liveRequests.spec.ts b/cli/src/engines/worker/liveRequests.spec.ts
index f1f8f6934..d187877b6 100644
--- a/cli/src/engines/worker/liveRequests.spec.ts
+++ b/cli/src/engines/worker/liveRequests.spec.ts
@@ -166,6 +166,68 @@ describe('engine live checkpoints', () => {
expect(rest.cursor.historyUntil).toBeUndefined()
})
+ describe('a re-attach after a rewrite: history up to where the read found it, live after', () => {
+ /** Attach, rewrite the file shorter, and let the old cursor's read find it; then `after` happens. */
+ const rewritten = async (engine: 'claude' | 'codex', after: (t: Awaited<ReturnType<typeof setup>>) => Promise<void>) => {
+ const t = await setup(engine, prompt(engine, 'a much longer original turn') + done(engine))
+ await t.page()
+ await writeFile(t.file, prompt(engine, 'history') + done(engine))
+ expect(await t.send()).toMatchObject({ error: 'ENGINE_TRANSCRIPT_CHANGED' })
+ await after(t)
+ t.payload.token = 'next'
+ t.payload.cursor = null
+ const ask = { rewritten: true, rewrittenFrom: 'binding' }
+ // Activation first, with nothing in it; then the pages, until one has nothing more.
+ expect((await t.page(ask)).frames).toEqual([])
+ const turns: Array<[string, string | null, boolean]> = []
+ for (let page = await t.page(ask); page.frames.length; page = await t.page(ask)) {
+ for (const frame of page.frames) for (const event of frame.events) {
+ if (event.type.startsWith('turn_')) turns.push([event.type, (event.payload as { userMessage?: string } | undefined)?.userMessage ?? null, frame.replay])
+ }
+ }
+ return turns
+ }
+
+ it.each(['claude', 'codex'] as const)('%s: a turn appended before the re-attach is live, however often the old cursor finds the change', async engine => {
+ const turns = await rewritten(engine, async t => {
+ await appendFile(t.file, prompt(engine, 'fresh') + done(engine))
+ expect(await t.send()).toMatchObject({ error: 'ENGINE_TRANSCRIPT_CHANGED' })
+ })
+ expect(turns).toEqual([
+ ['turn_started', 'history', true], ['turn_ended', null, true],
+ ['turn_started', 'fresh', false], ['turn_ended', null, false],
+ ])
+ })
+
+ it('a file rewritten again before the re-attach moves the boundary to where that was found', async () => {
+ const turns = await rewritten('claude', async t => {
+ await writeFile(t.file, prompt('claude', 'rewritten again') + done('claude'))
+ expect(await t.send()).toMatchObject({ error: 'ENGINE_TRANSCRIPT_CHANGED' })
+ await appendFile(t.file, prompt('claude', 'fresh') + done('claude'))
+ })
+ expect(turns).toEqual([
+ ['turn_started', 'rewritten again', true], ['turn_ended', null, true],
+ ['turn_started', 'fresh', false], ['turn_ended', null, false],
+ ])
+ })
+
+ it('a worker that never saw the read, or whose token core forgot, keeps everything on disk as history', async () => {
+ for (const lose of ['restart', 'forget'] as const) {
+ const turns = await rewritten('claude', async t => {
+ await appendFile(t.file, prompt('claude', 'fresh') + done('claude'))
+ if (lose === 'restart') t.restart()
+ else expect(await t.send(LIVE_FORGET)).toMatchObject({ forgotten: true })
+ })
+ expect(turns.map(([, , replay]) => replay), lose).toEqual([true, true, true, true])
+ }
+ })
+
+ it('refuses a rewrittenFrom that is not a token', async () => {
+ const t = await setup('claude', prompt('claude', 'one'))
+ expect(await t.send(LIVE_PREPARE, { rewritten: true, rewrittenFrom: 7 })).toMatchObject({ error: 'ENGINE_INVALID_REQUEST' })
+ })
+ })
+
it('accepts complete attach records without a trailing newline and finishes after trailing blank bytes', async () => {
const t = await setup('claude', prompt('claude', 'attached').trimEnd())
expect((await t.page()).prepared).toBe(true)
diff --git a/cli/src/engines/worker/liveRequests.ts b/cli/src/engines/worker/liveRequests.ts
index 451b765fb..d0a11713b 100644
--- a/cli/src/engines/worker/liveRequests.ts
+++ b/cli/src/engines/worker/liveRequests.ts
@@ -40,10 +40,12 @@ function pullOf(payload: Record<string, unknown>, engine: ReaderEngine): LivePul
if (!session || !label(payload.token) || (payload.cursor !== null && !liveCursor(payload.cursor))
|| typeof payload.fromStart !== 'boolean' || typeof payload.replay !== 'boolean'
|| (payload.end !== undefined && !position(payload.end)) || (payload.liveStart !== undefined && typeof payload.liveStart !== 'boolean')
- || (payload.rewritten !== undefined && typeof payload.rewritten !== 'boolean')) return null
+ || (payload.rewritten !== undefined && typeof payload.rewritten !== 'boolean')
+ || (payload.rewrittenFrom !== undefined && !label(payload.rewrittenFrom))) return null
return { token: payload.token, session, cursor: payload.cursor, fromStart: payload.fromStart,
replay: payload.replay, ...(payload.liveStart === undefined ? {} : { liveStart: payload.liveStart }),
...(payload.rewritten === undefined ? {} : { rewritten: payload.rewritten }),
+ ...(payload.rewrittenFrom === undefined ? {} : { rewrittenFrom: payload.rewrittenFrom }),
...(payload.end === undefined ? {} : { end: payload.end }) }
}
@@ -84,10 +86,12 @@ export function engineLiveRequests(engine: ReaderEngine, deps: LiveRequestDeps =
return record(value) ? runtime.decode(value) : null
} : undefined)
})().catch((error) => { streams = null; throw error })
- const forget = async (token: string): Promise<void> => {
+ // `release` only when core forgets the token: a failed read or an evicted reply drops the stream's
+ // state, which a cursor rebuilds, but not where that stream found its file rewritten.
+ const forget = async (token: string, release = false): Promise<void> => {
const old = replies.get(token)
if (old) { bytes -= old.bytes.length; replies.delete(token); parts.delete(old.id) }
- if (streams) (await streams).forget(token)
+ if (streams) (await streams).forget(token, release)
}
const failure = (error: string) => ({ version: LIVE_VERSION, error,
retryable: error !== 'ENGINE_INVALID_REQUEST' && error !== 'ENGINE_REPLY_TOO_LARGE' })
@@ -108,7 +112,7 @@ export function engineLiveRequests(engine: ReaderEngine, deps: LiveRequestDeps =
}
if (!label(payload.token)) return failure('ENGINE_INVALID_REQUEST')
if (pending >= LIVE_IN_FLIGHT) return failure('ENGINE_BUSY')
- if (type === LIVE_FORGET) { await forget(payload.token); return { version: LIVE_VERSION, forgotten: true } }
+ if (type === LIVE_FORGET) { await forget(payload.token, true); return { version: LIVE_VERSION, forgotten: true } }
const ask = pullOf(payload, engine)
if (!ask || (type === LIVE_PREPARE && ask.cursor !== null) || (type === LIVE_READ && ask.cursor === null)
|| (type === LIVE_CLOSE && (!ask.cursor || typeof payload.identity !== 'string'
diff --git a/cli/src/engines/worker/liveStreams.rewrite.spec.ts b/cli/src/engines/worker/liveStreams.rewrite.spec.ts
new file mode 100644
index 000000000..8459d6a9a
--- /dev/null
+++ b/cli/src/engines/worker/liveStreams.rewrite.spec.ts
@@ -0,0 +1,53 @@
+import { appendFile, mkdtemp, rm, writeFile } from 'node:fs/promises'
+import { tmpdir } from 'node:os'
+import { join } from 'node:path'
+import { afterEach, expect, it, vi } from 'vitest'
+import type { LivePage, LiveSession } from './liveProtocol.js'
+import { LIVE_PREPARE, LIVE_READ } from './liveProtocol.js'
+import { engineLiveRequests } from './liveRequests.js'
+
+// A rewritten file past the history limit hydrates silently from the boundary instead of replaying. The
+// limit is 32 MiB; here it is a few records, so the large path runs on a small file.
+vi.mock('./liveProtocol.js', async (original) => ({ ...await original<typeof import('./liveProtocol.js')>(), LIVE_HISTORY_BYTES: 64 }))
+
+const dirs: string[] = []
+const who = { owner: true, local: true }
+const prompt = (engine: string, text: string) => JSON.stringify(engine === 'claude'
+ ? { type: 'user', message: { role: 'user', content: text } }
+ : { type: 'event_msg', payload: { type: 'user_message', message: text } }) + '\n'
+const done = (engine: string) => JSON.stringify(engine === 'claude'
+ ? { type: 'assistant', message: { role: 'assistant', content: [{ type: 'text', text: 'done' }], stop_reason: 'end_turn' } }
+ : { type: 'event_msg', payload: { type: 'task_complete', last_agent_message: 'done' } }) + '\n'
+afterEach(async () => { await Promise.all(dirs.splice(0).map(dir => rm(dir, { recursive: true, force: true }))) })
+
+it.each(['claude', 'codex'] as const)('%s: a large rewritten file hydrates up to where the read found the rewrite, and a turn appended since is live', async engine => {
+ const dir = await mkdtemp(join(tmpdir(), 'engine-rewrite-')); dirs.push(dir)
+ const file = join(dir, 'transcript.jsonl')
+ await writeFile(file, prompt(engine, `original ${'x'.repeat(400)}`) + done(engine))
+ const session: LiveSession = { agentId: 'agent', sessionId: 'session', engine, transcriptPath: file, cwd: dir, model: null, cliVersion: null, codexHome: dir }
+ const worker = engineLiveRequests(engine)
+ const ask = { version: 1, token: 'binding', session, cursor: null as LivePage['cursor'] | null, fromStart: false, replay: false }
+ const page = async (extra: Record<string, unknown> = {}): Promise<LivePage> => {
+ const reply = await worker[ask.cursor ? LIVE_READ : LIVE_PREPARE]({ ...ask, ...extra }, who) as { answer: LivePage }
+ expect(reply.answer).toBeDefined()
+ ask.cursor = reply.answer.cursor
+ return reply.answer
+ }
+ await page()
+ await writeFile(file, prompt(engine, `history ${'y'.repeat(200)}`) + done(engine))
+ expect(await worker[LIVE_READ](ask, who)).toMatchObject({ error: 'ENGINE_TRANSCRIPT_CHANGED' })
+ await appendFile(file, prompt(engine, 'fresh') + done(engine))
+
+ ask.token = 'next'
+ ask.cursor = null
+ const turns: Array<[string, boolean]> = []
+ let prepared = false
+ for (let next = await page({ rewritten: true, rewrittenFrom: 'binding' }); ; next = await page({ rewritten: true, rewrittenFrom: 'binding' })) {
+ expect(next.cursor.historyUntil).toBeUndefined()
+ for (const frame of next.frames) for (const event of frame.events) if (event.type.startsWith('turn_')) turns.push([event.type, frame.replay])
+ if (prepared && !next.frames.length) break
+ prepared ||= next.prepared === true
+ }
+ // The history is folded silently; what was appended after the rewrite was found arrives as it would live.
+ expect(turns).toEqual([['turn_started', false], ['turn_ended', false]])
+})
diff --git a/cli/src/engines/worker/liveStreams.ts b/cli/src/engines/worker/liveStreams.ts
index f664832ce..653096116 100644
--- a/cli/src/engines/worker/liveStreams.ts
+++ b/cli/src/engines/worker/liveStreams.ts
@@ -6,7 +6,8 @@ import { isWholeRecord, locateAttachSpan, type AttachSpan } from '../../lib/atta
import type { RuntimeField, RuntimeRecord } from '../facets/runtime.js'
import { streamRecords } from '../../lib/transcriptTail.js'
import { sameStamp, stampAt } from './liveFiles.js'
-import { LIVE_HISTORY_BYTES, LIVE_PAGE_BYTES, type LiveCursor, type LiveFrame, type LivePage, type LiveSession, type LivePull } from './liveProtocol.js'
+import { LIVE_CACHE_SESSIONS, LIVE_HISTORY_BYTES, LIVE_PAGE_BYTES, type LiveCursor, type LiveFrame, type LivePage, type LiveSession,
+ type LivePull, type LiveStamp } from './liveProtocol.js'
interface Stream {
session: LiveSession
@@ -20,6 +21,9 @@ interface Stream {
activation: { end: number; history: boolean } | null
}
+/** Where a read found its file rewritten: the length then, and the bytes and file identity there. */
+interface Rewrite { offset: number; device: number; inode: number; stamp: LiveStamp | null }
+
const emptySpan = (): AttachSpan => ({ end: 0, turnFrom: 0, profileFrom: 0, head: null, seeds: [] })
const sameCursor = (a: LiveCursor | null, b: LiveCursor | null): boolean => JSON.stringify(a) === JSON.stringify(b)
const binding = (s: LiveSession): string => JSON.stringify([s.agentId, s.sessionId, s.engine, s.transcriptPath, s.codexHome])
@@ -27,6 +31,14 @@ function changed(): never { throw new Error('ENGINE_TRANSCRIPT_CHANGED') }
export class LiveStreams {
private readonly streams = new Map<string, Stream>()
+ /**
+ * Where each stream's read found its file rewritten, by the stream's token, until core forgets that token.
+ * Core re-attaches a second later (core/engines/liveSessions.ts `retry`), and the file's end by then is
+ * not where it was rewritten: the turn an agent ran in that second was folded into history and never
+ * reached a client as a turn (e2e/bounded.e2e.ts, broken by #1019, found 2026-10-08). The legacy tailer
+ * put the boundary where it noticed the rewrite (watcher.ts), and the re-attach puts it here.
+ */
+ private readonly rewrites = new Map<string, Rewrite>()
constructor(private readonly adapter: EngineLive, private readonly fields: (session: LiveSession, raw: string) => readonly RuntimeField[],
private readonly runtime?: (raw: string) => RuntimeRecord | null) {}
@@ -34,7 +46,51 @@ export class LiveStreams {
return this.runtime ? { ...frame, runtime: this.runtime(frame.raw) } : frame
}
- forget(token: string): void { this.streams.delete(token) }
+ forget(token: string, release = false): void {
+ this.streams.delete(token)
+ if (release) this.rewrites.delete(token)
+ }
+
+ /** The file as it is at `offset` now, or null when it cannot be read there. */
+ private async at(file: string, offset: number): Promise<Rewrite | null> {
+ try {
+ const { dev, ino } = await stat(file)
+ return { offset, device: dev, inode: ino, stamp: await stampAt(file, offset) }
+ } catch { return null }
+ }
+
+ /** Whether the file has only grown since `rewrite` was noted: same file, same bytes at its boundary. */
+ private async unchangedSince(file: string, rewrite: Rewrite): Promise<boolean> {
+ const now = await this.at(file, rewrite.offset)
+ return !!now && now.device === rewrite.device && now.inode === rewrite.inode && sameStamp(rewrite.stamp, now.stamp)
+ }
+
+ /**
+ * Note where a read with a cursor found the file rewritten. Core keeps pulling with that cursor until
+ * it re-attaches, and each pull finds the change again: the first one's boundary stands while the file
+ * has only grown since, so the records appended after the rewrite stay live.
+ */
+ private async noteRewrite(ask: LivePull): Promise<void> {
+ const file = ask.session.transcriptPath
+ if (!file) return
+ const known = this.rewrites.get(ask.token)
+ if (known && await this.unchangedSince(file, known)) return
+ let size: number
+ try { size = (await stat(file)).size } catch { this.rewrites.delete(ask.token); return }
+ const rewrite = await this.at(file, size)
+ this.rewrites.delete(ask.token)
+ if (!rewrite) return
+ this.rewrites.set(ask.token, rewrite)
+ // Bounded like the replies: one per stream core still holds, and core holds at most this many.
+ if (this.rewrites.size > LIVE_CACHE_SESSIONS) this.rewrites.delete(this.rewrites.keys().next().value!)
+ }
+
+ /** Where a re-attach's history ends: where `rewrittenFrom`'s read found the rewrite, while that still holds. */
+ private async rewriteBoundary(ask: LivePull): Promise<number | undefined> {
+ const file = ask.session.transcriptPath
+ const rewrite = ask.rewrittenFrom === undefined ? undefined : this.rewrites.get(ask.rewrittenFrom)
+ return file && rewrite && await this.unchangedSince(file, rewrite) ? rewrite.offset : undefined
+ }
private ingest(stream: Stream, token: string, raw: string, offset: number): ReturnType<LiveParser['ingest']> {
const before = stream.parser.snapshot().identity
@@ -57,10 +113,12 @@ export class LiveStreams {
turn: { ...parser.snapshot(), identity: `${ask.token}:empty` }, closed: false,
cursor: null, lastStarted: null, head: true, activation: null }
const file = ask.session.transcriptPath
+ const boundary = !ask.cursor && ask.rewritten ? await this.rewriteBoundary(ask) : undefined
if (!ask.cursor && (ask.liveStart || ask.rewritten)) {
let end = 0
try { if (file) end = (await stat(file)).size }
catch (error) { if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error }
+ if (boundary !== undefined) end = boundary
if (ask.liveStart || end <= LIVE_HISTORY_BYTES) {
stream.activation = { end, history: !!ask.rewritten }
return stream
@@ -69,7 +127,7 @@ export class LiveStreams {
if (!file) return stream
const cursor = ask.cursor
if (cursor && !sameStamp(cursor.stamp, await stampAt(file, cursor.offset))) changed()
- const end = cursor ? cursor.origin : ask.rewritten ? undefined : ask.end
+ const end = cursor ? cursor.origin : ask.rewritten ? boundary : ask.end
const rules = this.adapter.attachRules!((line) => this.fields(ask.session, line))
try {
stream.span = await locateAttachSpan(file, rules, { end, fromStart: ask.fromStart })
@@ -109,6 +167,13 @@ export class LiveStreams {
}
async pull(ask: LivePull): Promise<LivePage> {
+ try { return await this.read(ask) } catch (error) {
+ if (ask.cursor && error instanceof Error && error.message === 'ENGINE_TRANSCRIPT_CHANGED') await this.noteRewrite(ask)
+ throw error
+ }
+ }
+
+ private async read(ask: LivePull): Promise<LivePage> {
const stream = await this.get(ask)
const file = ask.session.transcriptPath
if (!ask.cursor && stream.activation) {
diff --git a/docs/design/2026-10-07-engine-streams.md b/docs/design/2026-10-07-engine-streams.md
index ae6f32336..0723fd308 100644
--- a/docs/design/2026-10-07-engine-streams.md
+++ b/docs/design/2026-10-07-engine-streams.md
@@ -62,7 +62,12 @@ their current tailers and parsers.
the page and schedules a held re-attach. Files up to 32 MiB activate a fresh
parser and replay existing records as history in bounded pages; subsequent
appends are live. The history boundary survives worker restart. Larger files
- hydrate from their new end. A trusted explicit tail move hydrates at the new
+ hydrate up to that boundary. The boundary is where the read that found the
+ change saw the file end (the worker keeps it by that stream's token until core
+ forgets the token, and drops it if the file changes again), not where the file
+ ends when core re-attaches a second later: a turn written in between is live,
+ as it was under the legacy tailer. A worker restarted in between keeps
+ everything on disk as history. A trusted explicit tail move hydrates at the new
offset without replay. This is not a checksum of every byte in the transcript.
## Availability and compatibility