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.

Bound transcript reads for recaps and session discovery (#648)

Deec966e1ac0e10
diff --git a/cli/scripts/benchmark-codex-recap.mjs b/cli/scripts/benchmark-codex-recap.mjs
new file mode 100644
index 000000000..6bd18f0e1
--- /dev/null
+++ b/cli/scripts/benchmark-codex-recap.mjs
@@ -0,0 +1,90 @@
+import assert from 'node:assert/strict';
+import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, rmSync, openSync, closeSync, writeSync, symlinkSync, statSync } from 'node:fs';
+import { join } from 'node:path';
+import { createRequire } from 'node:module';
+import { pathToFileURL, fileURLToPath } from 'node:url';
+import { spawnSync } from 'node:child_process';
+import { createHash } from 'node:crypto';
+import { performance } from 'node:perf_hooks';
+// Usage: node scripts/benchmark-codex-recap.mjs /absolute/new/output-directory
+// Disposable files and child processes only; no live session or daemon is touched.
+const repo = fileURLToPath(new URL('../..', import.meta.url));
+const require = createRequire(join(repo, 'cli/package.json'));
+const digest = text => createHash('sha256').update(text).digest('hex');
+const args = process.argv.slice(2);
+if (args[0] === '--worker') {
+ const [_, out, mode, file, expected] = args;
+ const fixture = mkdtempSync(join(out, 'worker-'));
+ Object.assign(process.env, { ADAPTER_DATA_DIR: join(fixture,'data'), ADAPTER_RUNTIME_DIR: join(fixture,'runtime'),
+ ADAPTER_COMPUTER_ID_FILE: join(fixture,'computer-id'), ADAPTER_COMPUTER_ID: 'recap-benchmark', HARNESS_AUTH_DIR: join(fixture,'auth'),
+ DSH_DIR: join(fixture,'dsh'), ZDOTDIR: fixture, HARNESS_LESSONS_DIR: join(fixture,'lessons'), HARNESS_STORE_CATALOG_URL: 'http://127.0.0.1:9/catalog.json' });
+ try {
+ const module = await import(pathToFileURL(join(out,'reader.mjs')));
+ for (let i=0;i<40;i++) await module[mode](join(out,'warmup.jsonl'));
+ global.gc();
+ const before = process.memoryUsage(), cpu = process.cpuUsage(), start = performance.now();
+ const result = await module[mode](file);
+ const durationMs = performance.now()-start, cpuDelta=process.cpuUsage(cpu), after=process.memoryUsage(), usage=process.resourceUsage();
+ const output = JSON.stringify(result);
+ assert.equal(digest(output),expected);
+ process.stdout.write(JSON.stringify({mode,durationMs,cpuUs:cpuDelta.user+cpuDelta.system,before,after,maxRssKiB:usage.maxRSS,outputSha256:digest(output),outputBytes:Buffer.byteLength(output)})+'\n');
+ } finally { rmSync(fixture,{recursive:true,force:true}); }
+} else {
+ assert.equal(args.length,1,'Expected a new absolute output directory');
+ const out=args[0];
+ assert(out.startsWith('/'),'Output directory must be absolute');
+ mkdirSync(out);
+ symlinkSync(join(repo,'cli/node_modules'),join(out,'node_modules'),'dir');
+ const { build } = require('esbuild');
+ await build({stdin:{contents:`import {tailFile} from './lib/transcriptTail.ts'; import {lastCodexTurnText} from './engines/codex/normalizer.ts'; export {readLastCodexTurnText as candidate} from './engines/codex/lastTurn.ts'; export async function baseline(file){return lastCodexTurnText(await tailFile(file,Infinity));}`,resolveDir:join(repo,'cli/src'),sourcefile:'recap-benchmark.ts',loader:'ts'},outfile:join(out,'reader.mjs'),bundle:true,packages:'external',platform:'node',format:'esm',target:'node20',minify:true,logLevel:'silent'});
+ const event = payload=>JSON.stringify({type:'event_msg',payload})+'\n';
+ const prompt='Latest task 📘',answer='Verified final answer. '.repeat(400);
+ const tail=event({type:'user_message',message:prompt})+event({type:'agent_message',phase:'commentary',message:'Working on it.'})+JSON.stringify({type:'response_item',payload:{type:'function_call_output',output:'recent tool data '.repeat(500)}})+'\n'+event({type:'agent_message',phase:'final_answer',message:answer});
+ const expected=digest(JSON.stringify({userMessage:prompt,assistantText:answer}));
+ writeFileSync(join(out,'warmup.jsonl'),tail);
+ const record=Buffer.from(JSON.stringify({type:'response_item',payload:{type:'function_call_output',output:'older tool data '.repeat(4096)}})+'\n');
+ const rows=[];
+ const scenarios=[
+ {name:'short-latest-0MiB',sizeMiB:0,shape:'short'},
+ ...[1,64,512].map(sizeMiB=>({name:`short-latest-${sizeMiB}MiB`,sizeMiB,shape:'short'})),
+ {name:'long-latest-64MiB',sizeMiB:64,shape:'long'},
+ {name:'no-boundary-64MiB',sizeMiB:64,shape:'no-boundary'},
+ {name:'single-tool-64MiB',sizeMiB:64,shape:'single-tool'},
+ ];
+ for(const {name,sizeMiB,shape} of scenarios) {
+ const file=join(out,`${name}.jsonl`),fd=openSync(file,'wx',0o600);
+ try {
+ if(shape!=='no-boundary') writeSync(fd,event({type:'user_message',message:shape==='short'?'Earlier task':prompt}));
+ if(shape==='single-tool') {
+ writeSync(fd,'{"type":"response_item","payload":{"type":"function_call_output","output":"');
+ const chunk=Buffer.alloc(65536,120);
+ for(let written=0;written<sizeMiB*1048576;written+=chunk.length) writeSync(fd,chunk);
+ writeSync(fd,'"}}\n');
+ } else {
+ for(let written=0;written<sizeMiB*1048576;written+=record.length) writeSync(fd,record);
+ }
+ writeSync(fd,shape==='short'?tail:event({type:'agent_message',phase:'final_answer',message:answer}));
+ } finally { closeSync(fd); }
+ const fileBytes=statSync(file).size;
+ const expectedOutput=shape==='no-boundary'?digest(JSON.stringify({userMessage:'',assistantText:answer})):expected;
+ try {
+ for(let trial=0;trial<3;trial++) for(const mode of trial%2?['candidate','baseline']:['baseline','candidate']) {
+ const result=spawnSync(process.execPath,['--expose-gc',fileURLToPath(import.meta.url),'--worker',out,mode,file,expectedOutput],{cwd:out,encoding:'utf8',timeout:60000,maxBuffer:1024*1024});
+ if(result.status!==0) throw new Error(`${name}/${mode}: ${result.stderr}\n${result.stdout}`);
+ const row={name,sizeMiB,shape,fileBytes,trial,...JSON.parse(result.stdout.trim())};rows.push(row);
+ console.log(JSON.stringify({name,trial,mode,ms:row.durationMs,maxRssMiB:row.maxRssKiB/1024}));
+ }
+ } finally { rmSync(file); }
+ }
+ const median = ns=>{const a=ns.slice().sort((a,b)=>a-b);return a[Math.floor(a.length/2)]};
+ const summary=[];
+ for(const {name} of scenarios) for(const metric of ['durationMs','cpuUs','maxRssKiB']) {
+ const select=mode=>median(rows.filter(x=>x.name===name&&x.mode===mode).map(x=>x[metric]));
+ const baseline=select('baseline'),candidate=select('candidate');summary.push({name,metric,baseline,candidate,reductionPercent:(1-candidate/baseline)*100});
+ }
+ const sources=['src/lib/transcriptTail.ts','src/engines/codex/normalizer.ts','src/engines/codex/lastTurn.ts','src/cli.ts','package-lock.json'];
+ const sourceSha256=Object.fromEntries(sources.map(name=>[name,digest(readFileSync(join(repo,'cli',name)))]));
+ const result={sourceSha256,finishedAt:new Date().toISOString(),node:process.version,platform:process.platform,arch:process.arch,scope:'Full-history recap vs reverse suffix using the same final parser, minified bundle, real synthetic files, disposable processes. No live app changes. Explicit GC runs only in benchmark children before timing.',rows,summary};
+ writeFileSync(join(out,'results.json'),JSON.stringify(result,null,2)+'\n');
+ console.log(JSON.stringify({directory:out,summary},null,2));
+}
diff --git a/cli/scripts/benchmark-session-metadata.mjs b/cli/scripts/benchmark-session-metadata.mjs
new file mode 100644
index 000000000..70f5e9313
--- /dev/null
+++ b/cli/scripts/benchmark-session-metadata.mjs
@@ -0,0 +1,93 @@
+import assert from 'node:assert/strict';
+import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, rmSync, openSync, closeSync, writeSync, symlinkSync, statSync } from 'node:fs';
+import { basename, join } from 'node:path';
+import { createRequire } from 'node:module';
+import { pathToFileURL, fileURLToPath } from 'node:url';
+import { execFileSync, spawnSync } from 'node:child_process';
+import { createHash } from 'node:crypto';
+import { performance } from 'node:perf_hooks';
+import { constants } from 'node:buffer';
+
+// Usage: node cli/scripts/benchmark-session-metadata.mjs BASE_COMMIT /absolute/new/output-directory
+// Real disposable files; no live engine, daemon, session or account is used.
+const repo = fileURLToPath(new URL('../..', import.meta.url));
+const require = createRequire(join(repo, 'cli/package.json'));
+const digest = text => createHash('sha256').update(text).digest('hex');
+const args = process.argv.slice(2), cwd = '/fixture/metadata';
+const header = JSON.stringify({ type: 'session', cwd }) + '\n';
+if (args[0] === '--worker') {
+ const [_, out, mode, file, expectMissing] = args;
+ const fixture = mkdtempSync(join(out, 'worker-'));
+ const projects = join(fixture, 'projects');
+ mkdirSync(projects);
+ Object.assign(process.env, { CLAUDE_PROJECTS_DIR: projects,
+ ADAPTER_DATA_DIR: join(fixture, 'data'), ADAPTER_RUNTIME_DIR: join(fixture, 'runtime'),
+ ADAPTER_COMPUTER_ID_FILE: join(fixture, 'computer-id'), ADAPTER_COMPUTER_ID: 'metadata-benchmark', HARNESS_AUTH_DIR: join(fixture, 'auth'),
+ DSH_DIR: join(fixture, 'dsh'), ZDOTDIR: fixture, HARNESS_LESSONS_DIR: join(fixture, 'lessons'), HARNESS_STORE_CATALOG_URL: 'http://127.0.0.1:9/catalog.json' });
+ try {
+ const module = await import(pathToFileURL(join(out, `${mode}.mjs`)));
+ const path = join(projects, 'session-id.jsonl');
+ writeFileSync(path, header);
+ for (let i = 0; i < 40; i++) assert.equal((await module.findLiveSession('claude', cwd, 0))?.sessionId, 'session-id');
+ rmSync(path);
+ symlinkSync(file, path);
+ global.gc();
+ const before = process.memoryUsage(), cpu = process.cpuUsage(), start = performance.now();
+ const result = await module.findLiveSession('claude', cwd, 0);
+ const durationMs = performance.now() - start, cpuDelta = process.cpuUsage(cpu), after = process.memoryUsage(), usage = process.resourceUsage();
+ const identity = result ? { sessionId: result.sessionId, transcript: basename(result.transcriptPath) } : null;
+ assert.deepEqual(identity, expectMissing === 'true' ? null : { sessionId: 'session-id', transcript: 'session-id.jsonl' });
+ process.stdout.write(JSON.stringify({ mode, durationMs, cpuUs: cpuDelta.user + cpuDelta.system, before, after, maxRssKiB: usage.maxRSS, identity }) + '\n');
+ } finally { rmSync(fixture, { recursive: true, force: true }); }
+} else {
+ assert.equal(args.length, 2, 'Expected baseline commit and new absolute output directory');
+ const [base, out] = args;
+ assert(/^[a-f0-9]{7,40}$/.test(base));
+ assert(out.startsWith('/'));
+ mkdirSync(out);
+ symlinkSync(join(repo, 'cli/node_modules'), join(out, 'node_modules'), 'dir');
+ const oldSource = execFileSync('git', ['show', `${base}:cli/src/lib/sessionRepair.ts`], { cwd: repo, encoding: 'utf8' });
+ const { build } = require('esbuild');
+ for (const mode of ['baseline', 'candidate']) {
+ await build({ entryPoints: [join(repo, 'cli/src/lib/sessionRepair.ts')], outfile: join(out, `${mode}.mjs`), bundle: true,
+ packages: 'external', platform: 'node', format: 'esm', target: 'node20', minify: true, logLevel: 'silent',
+ plugins: mode === 'candidate' ? [] : [{ name: 'baseline', setup(build) {
+ build.onLoad({ filter: /[/\\]sessionRepair\.ts$/ }, () => ({ contents: oldSource, loader: 'ts', resolveDir: join(repo, 'cli/src/lib') }));
+ } }],
+ });
+ }
+ const record = Buffer.from((JSON.stringify({ type: 'tool_result', output: 'x'.repeat(65536) }) + '\n').repeat(16));
+ const rows = [], sizes = [0, 1, 64, 256, 513];
+ for (const sizeMiB of sizes) {
+ const file = join(out, `history-${sizeMiB}.jsonl`), fd = openSync(file, 'wx', 0o600);
+ try {
+ writeSync(fd, header);
+ for (let written = 0; written < sizeMiB * 1048576; written += record.length) writeSync(fd, record);
+ } finally { closeSync(fd); }
+ const fileBytes = statSync(file).size;
+ try {
+ for (let trial = 0; trial < 3; trial++) for (const mode of trial % 2 ? ['candidate', 'baseline'] : ['baseline', 'candidate']) {
+ // ASCII file > V8's string limit: the old full-file reader catches RangeError and loses the binding.
+ const expectMissing = mode === 'baseline' && fileBytes > constants.MAX_STRING_LENGTH;
+ const result = spawnSync(process.execPath, ['--expose-gc', fileURLToPath(import.meta.url), '--worker', out, mode, file, String(expectMissing)],
+ { cwd: out, encoding: 'utf8', timeout: 60000, maxBuffer: 1024 * 1024 });
+ if (result.status !== 0) throw new Error(`${sizeMiB}/${mode}: ${result.stderr}\n${result.stdout}`);
+ const row = { sizeMiB, fileBytes, trial, ...JSON.parse(result.stdout.trim()) }; rows.push(row);
+ console.log(JSON.stringify({ sizeMiB, trial, mode, ms: row.durationMs, maxRssMiB: row.maxRssKiB / 1024, found: row.identity !== null }));
+ }
+ } finally { rmSync(file); }
+ }
+ const median = values => values.slice().sort((a, b) => a - b)[Math.floor(values.length / 2)];
+ const summary = [];
+ for (const sizeMiB of sizes) for (const metric of ['durationMs', 'cpuUs', 'maxRssKiB']) {
+ const select = mode => median(rows.filter(x => x.sizeMiB === sizeMiB && x.mode === mode).map(x => x[metric]));
+ const baseline = select('baseline'), candidate = select('candidate');
+ summary.push({ sizeMiB, metric, baseline, candidate, reductionPercent: (1 - candidate / baseline) * 100 });
+ }
+ const result = { base, baselineSourceSha256: digest(oldSource), candidateSourceSha256: digest(readFileSync(join(repo, 'cli/src/lib/sessionRepair.ts'))),
+ dependencySha256: digest(readFileSync(join(repo, 'cli/package-lock.json'))), finishedAt: new Date().toISOString(),
+ node: process.version, platform: process.platform, arch: process.arch, maxStringLength: constants.MAX_STRING_LENGTH,
+ scope: 'One public findLiveSession directory scan of a synthetic Claude transcript, fresh minified workers. Peak RSS includes startup/warmup; explicit GC is only before timing in disposable children. No whole-app energy claim.', rows, summary };
+ writeFileSync(join(out, 'results.json'), JSON.stringify(result, null, 2) + '\n');
+ console.log(JSON.stringify({ directory: out, summary }, null, 2));
+}
diff --git a/cli/src/cli.ts b/cli/src/cli.ts
index 58791c547..96f93b89a 100644
--- a/cli/src/cli.ts
+++ b/cli/src/cli.ts
@@ -264,7 +264,8 @@ import { updateManagedTui } from './tui/manage.js'
import { startTuiUpdater } from './tui/update.js'
import { ensureHnLauncher, ensureLauncher, ensureManagedGrid, ensureManagedRuntime, startGridPinRecheck } from './lib/runtimeInstall.js'
import { readdir, stat } from 'fs/promises'
-import { CodexNormalizer, codexTaskError, lastCodexTurnText } from './engines/codex/normalizer.js'
+import { CodexNormalizer, codexTaskError } from './engines/codex/normalizer.js'
+import { readLastCodexTurnText } from './engines/codex/lastTurn.js'
import { TurnActivity, type ActivityFrame } from './lib/turnActivity.js'
import { CodexActivityReader, RuntimeActivityReader, activityRuntimeKey } from './lib/runtimeActivity.js'
import { codexSubagentResolverFor } from './engines/codex/subagent.js'
@@ -3091,8 +3092,8 @@ async function runForeground(session: AuthSession | null): Promise<void> {
if (s.engine === 'hermes') return lastHermesTurnText(await readHermesMessages(await hermesDbForSession(s), sessionId))
if (s.engine === 'devin') return lastDevinTurnText(await readDevinMessages(DEVIN_DB, sessionId))
if (!s.transcriptPath) return null
+ if (s.engine === 'codex') return readLastCodexTurnText(s.transcriptPath)
const lines = await tailFile(s.transcriptPath, Infinity)
- if (s.engine === 'codex') return lastCodexTurnText(lines)
if (s.engine === 'cursor') return lastCursorTurnText(lines)
if (s.engine === 'muse') return lastMuseTurnText(lines)
if (s.engine === 'amp') return lastAmpTurnText(lines)
diff --git a/cli/src/engines/codex/lastTurn.spec.ts b/cli/src/engines/codex/lastTurn.spec.ts
new file mode 100644
index 000000000..86d60b787
--- /dev/null
+++ b/cli/src/engines/codex/lastTurn.spec.ts
@@ -0,0 +1,119 @@
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'
+import { tmpdir } from 'node:os'
+import { join } from 'node:path'
+import { CodexNormalizer, lastCodexTurnText, selectCodexRecapLine } from './normalizer.js'
+import { readLastCodexTurnText } from './lastTurn.js'
+import { tailFile } from '../../lib/transcriptTail.js'
+import { CommanderMirror, type CommanderFrame } from '../../lib/commander.js'
+import { deriveTurnSummary } from '../../lib/summarize.js'
+
+const event = (payload: unknown) => JSON.stringify({ type: 'event_msg', payload })
+const ask = (message: string) => event({ type: 'user_message', message })
+const answer = (message: string, phase?: string) => event({ type: 'agent_message', message, ...(phase ? { phase } : {}) })
+const goal = JSON.stringify({ type: 'response_item', payload: { type: 'message', role: 'user', content: [{ type: 'input_text',
+ text: '<codex_internal_context source="goal"><objective>Keep going 📘</objective></codex_internal_context>' }] } })
+
+describe('Codex recap from the latest file turn', () => {
+ let directory: string, file: string
+ beforeEach(() => { directory = mkdtempSync(join(tmpdir(), 'codex-recap-')); file = join(directory, 'rollout.jsonl') })
+ afterEach(() => rmSync(directory, { recursive: true, force: true }))
+
+ const cases = [
+ [ask('old'), answer('old answer'), ask('latest'), answer('on it', 'commentary'), answer('done', 'final_answer')],
+ [ask('old'), answer('old answer'), goal, answer('working', 'commentary')],
+ [ask('old'), answer('old answer'), goal, answer('complete', 'final_answer')],
+ [ask('old'), answer('old answer'), ask('unfinished'), answer('working', 'commentary')],
+ [ask('prompt'), answer('answer'), ask(''), event({ type: 'user_message', message: null })],
+ [ask('prompt'), answer('unphased'), answer('working', 'commentary')],
+ [ask('prompt'), answer('first'), answer('second'), '{torn'],
+ [answer('no prompt')],
+ [event({ type: 'item_completed', item: { type: 'UserMessage', content: [{ type: 'Text', text: 'new format' }] } }),
+ event({ type: 'item_completed', item: { type: 'AgentMessage', phase: 'final_answer', content: [{ type: 'Text', text: 'done' }] } })],
+ [ask('prompt'), answer('first final', 'final_answer'), answer('second final', 'final_answer')],
+ [ask('prompt'), answer('answer'), 'null', '[]', '{}', '{invalid', event({ type: 'task_complete' })],
+ [ask('prompt'), answer('answer'), JSON.stringify({ type: 'response_item', payload: { type: 'message', role: 'user', content: [
+ { type: 'input_text', text: 'A regular response-item message does not reset the existing recap.' }] } })],
+ [ask('prompt'), answer('answer'), answer('', 'commentary'), event({ type: 'agent_message', phase: 'final_answer', message: null })],
+ [ask('prompt'), answer('answer'), answer('unknown phase', 'future_phase')],
+ [ask('prompt'), answer('answer'), JSON.stringify({ type: 'response_item', payload: { type: 'function_call_output', output: ask('embedded prompt') } })],
+ ]
+ it.each(cases.map((rows, i) => ({ i, rows })))('matches the full-history reader for case $i', async ({ rows }) => {
+ writeFileSync(file, rows.join('\n'))
+ expect(await readLastCodexTurnText(file)).toEqual(lastCodexTurnText(await tailFile(file, Infinity)))
+ })
+
+ it('ignores megabytes of old tool data while retaining a long latest prompt and answer exactly', async () => {
+ const prompt = 'é漢字📘'.repeat(20_000), text = 'answer 📘 '.repeat(15_000)
+ const rows = [ask('old'), JSON.stringify({ type: 'response_item', payload: { type: 'function_call_output', output: 'x'.repeat(2 * 1024 * 1024) } }),
+ answer('old answer'), ask(prompt), answer(text, 'final_answer')]
+ writeFileSync(file, rows.join('\n') + '\n')
+ expect(await readLastCodexTurnText(file)).toEqual({ userMessage: prompt, assistantText: text })
+ })
+
+ it('matches every growing prefix of mixed legacy, current, goal and malformed records', async () => {
+ const rows = cases.flat()
+ for (let end = 0; end <= rows.length; end++) {
+ const prefix = rows.slice(0, end)
+ writeFileSync(file, prefix.join('\n') + '\n')
+ expect(await readLastCodexTurnText(file), `prefix ${end}`).toEqual(lastCodexTurnText(prefix))
+ }
+ })
+
+ it('discards tool receipts from a long latest turn before the final parser sees them', async () => {
+ const rows = [ask('prompt'), JSON.stringify({ type: 'response_item', payload: { type: 'function_call_output', output: 'x'.repeat(2 * 1024 * 1024) } }),
+ event({ type: 'token_count', info: {} }), answer('working', 'commentary'), answer('done', 'final_answer')]
+ expect(rows.map(selectCodexRecapLine)).toEqual(['stop', 'skip', 'skip', 'keep', 'keep'])
+ writeFileSync(file, rows.join('\n'))
+ expect(await readLastCodexTurnText(file)).toEqual({ userMessage: 'prompt', assistantText: 'done' })
+ })
+
+ it('returns no recap for a missing file', async () => {
+ expect(await readLastCodexTurnText(file)).toBeNull()
+ })
+
+ it.each(['legacy', 'wrapped', 'goal'])('delivers and persists the %s file result through the normalizer and Commander', async (format) => {
+ const prompt = format === 'goal' ? '/goal Keep going 📘' : 'Latest prompt'
+ const user = format === 'goal' ? goal : format === 'legacy' ? ask(prompt)
+ : event({ type: 'item_completed', item: { type: 'UserMessage', content: [{ type: 'Text', text: prompt }] } })
+ const final = format === 'wrapped'
+ ? event({ type: 'item_completed', item: { type: 'AgentMessage', phase: 'final_answer', content: [{ type: 'Text', text: 'Latest answer.' }] } })
+ : answer('Latest answer.', 'final_answer')
+ const latest = [event({ type: 'task_started', turn_id: 'turn-latest' }), user, answer('Still working.', 'commentary'), final,
+ event({ type: 'task_complete', turn_id: 'turn-latest' })]
+ writeFileSync(file, [ask('old'), answer('Old answer.'), ...latest].join('\n'))
+ const device: CommanderFrame[] = [], web: Record<string, unknown>[] = []
+ const summarize = vi.fn(async (text: string, _signal?: AbortSignal, _prompt?: string) => deriveTurnSummary(text))
+ const options = { dataDir: directory, send: (frame: CommanderFrame) => device.push(frame),
+ sendWeb: (frame: Record<string, unknown>) => web.push(frame), hasDevice: () => true,
+ summarize, summarizeIsLocal: true, readLastTurn: () => readLastCodexTurnText(file) }
+ const mirror = new CommanderMirror(options)
+ try {
+ const normalizer = new CodexNormalizer('live')
+ mirror.ingest(latest.flatMap(line => normalizer.ingest(line)), 'session')
+ await vi.waitFor(() => expect(web.some(frame => frame.type === 'turn_summary')).toBe(true))
+ expect(summarize).toHaveBeenCalledExactlyOnceWith('Latest answer.', expect.any(AbortSignal), prompt, 'session', undefined)
+ expect(device.at(-1)?.payload).toMatchObject({ kind: 'summary', notification: { kind: 'done' } })
+ expect(mirror.recent('session')[0].fullText).toBe('Latest answer.')
+ await vi.waitFor(() => expect(new CommanderMirror(options).recent('session')[0]?.fullText).toBe('Latest answer.'))
+ } finally { mirror.deleteHistory('session') }
+ })
+
+ it('clears completion without sending a stale recap for an unfinished goal', async () => {
+ const latest = [event({ type: 'task_started', turn_id: 'unfinished' }), goal, answer('Still working.', 'commentary'),
+ event({ type: 'task_complete', turn_id: 'unfinished' })]
+ writeFileSync(file, [ask('old'), answer('Old answer.', 'final_answer'), ...latest].join('\n'))
+ const device: CommanderFrame[] = [], web: Record<string, unknown>[] = []
+ const summarize = vi.fn(async () => 'Must not appear')
+ const mirror = new CommanderMirror({ dataDir: directory, send: frame => device.push(frame), sendWeb: frame => web.push(frame),
+ hasDevice: () => true, summarize, readLastTurn: () => readLastCodexTurnText(file) })
+ try {
+ const normalizer = new CodexNormalizer('live')
+ mirror.ingest(latest.flatMap(line => normalizer.ingest(line)), 'session')
+ await vi.waitFor(() => expect(device.at(-1)?.payload.kind).toBe('done'))
+ expect(summarize).not.toHaveBeenCalled()
+ expect(web).toEqual([])
+ expect(mirror.recent('session')).toEqual([])
+ } finally { mirror.deleteHistory('session') }
+ })
+})
diff --git a/cli/src/engines/codex/lastTurn.ts b/cli/src/engines/codex/lastTurn.ts
new file mode 100644
index 000000000..7e6a041cd
--- /dev/null
+++ b/cli/src/engines/codex/lastTurn.ts
@@ -0,0 +1,9 @@
+import { tailFileUntil } from '../../lib/transcriptTail.js'
+import type { LastTurnText } from '../../lib/normalize.js'
+import { selectCodexRecapLine, lastCodexTurnText } from './normalizer.js'
+
+/** A recap needs the latest turn, not every earlier tool receipt and answer. Keep the existing
+ * normalizer authoritative, including goal continuations and both Codex message vocabularies. */
+export async function readLastCodexTurnText(filePath: string): Promise<LastTurnText | null> {
+ return lastCodexTurnText(await tailFileUntil(filePath, selectCodexRecapLine))
+}
diff --git a/cli/src/engines/codex/normalizer.ts b/cli/src/engines/codex/normalizer.ts
index 203bc9dcf..23fa376bd 100644
--- a/cli/src/engines/codex/normalizer.ts
+++ b/cli/src/engines/codex/normalizer.ts
@@ -573,6 +573,19 @@ export function codexMessagesToEvents(
return events
}
+/** Select only records that can affect lastCodexTurnText. Empty user messages do not reset a
+ * turn. Discard tool receipts while scanning so a long latest turn does not retain them all. */
+export function selectCodexRecapLine(line: string): 'keep' | 'skip' | 'stop' {
+ const raw = parse(line)
+ const item = raw && payload(raw)
+ if (!raw || !item) return 'skip'
+ if (raw.type === 'response_item' && string(item.type) === 'message') return goalObjective(item) ? 'stop' : 'skip'
+ if (raw.type !== 'event_msg') return 'skip'
+ const itemType = string(item.type)
+ if (USER_TURN_TYPES.has(itemType) && messageText(item)) return 'stop'
+ return AGENT_TEXT_TYPES.has(itemType) ? 'keep' : 'skip'
+}
+
export function lastCodexTurnText(rawLines: string[]): LastTurnText | null {
let userMessage = ''
let assistantText = ''
diff --git a/cli/src/lib/sessionRepair.metadata.spec.ts b/cli/src/lib/sessionRepair.metadata.spec.ts
new file mode 100644
index 000000000..2b3c7066c
--- /dev/null
+++ b/cli/src/lib/sessionRepair.metadata.spec.ts
@@ -0,0 +1,130 @@
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import { mkdirSync, mkdtempSync, rmSync, truncateSync, writeFileSync } from 'node:fs'
+import { constants } from 'node:buffer'
+import * as fs from 'fs/promises'
+import { join } from 'node:path'
+import { tmpdir } from 'node:os'
+import type { AgentEngine } from '../engines/types.js'
+
+vi.mock('fs/promises', async importOriginal => {
+ const actual = await importOriginal<typeof import('fs/promises')>()
+ return { ...actual, open: vi.fn(actual.open) }
+})
+
+const LIMIT = 256 * 1024
+const CWD = '/fixture/工作/📘'
+const META = JSON.stringify({ type: 'session', cwd: CWD })
+let directory: string
+beforeEach(() => { directory = mkdtempSync(join(tmpdir(), 'repair-meta-')) })
+afterEach(() => {
+ vi.restoreAllMocks()
+ vi.unstubAllEnvs()
+ vi.resetModules()
+ rmSync(directory, { recursive: true, force: true })
+})
+
+async function fixture(text: string, engine: AgentEngine = 'claude') {
+ const config: Record<string, [string, string[]]> = {
+ claude: ['CLAUDE_PROJECTS_DIR', []],
+ pi: ['PI_HOME', ['agent', 'sessions']],
+ commandcode: ['COMMANDCODE_HOME', ['projects']],
+ amp: ['AMP_SESSIONS_DIR', []],
+ }
+ const [variable, subdirectories] = config[engine]
+ vi.stubEnv(variable, directory)
+ const root = join(directory, ...subdirectories, 'project')
+ mkdirSync(root, { recursive: true })
+ const path = join(root, 'session-id.jsonl')
+ writeFileSync(path, text)
+ vi.resetModules()
+ const { findLiveSession } = await import('./sessionRepair.js')
+ const read = () => findLiveSession(engine, CWD, Date.now() - 1000)
+ return { path, read }
+}
+
+describe('bounded session metadata discovery', () => {
+ it.each(['claude', 'pi', 'commandcode', 'amp'] as const)('finds %s metadata without retaining a large history', async engine => {
+ const { path, read } = await fixture(META + '\n' + 'x'.repeat(4 * 1024 * 1024), engine)
+ await expect(read()).resolves.toEqual({ sessionId: 'session-id', transcriptPath: path })
+ })
+
+ it.each([19, 20])('keeps the 20-line limit with %i bookkeeping lines', async count => {
+ const { read } = await fixture(Array(count).fill('{}').join('\n') + '\n' + META + '\n')
+ if (count === 19) await expect(read()).resolves.toMatchObject({ sessionId: 'session-id' })
+ else await expect(read()).resolves.toBeNull()
+ })
+
+ it.each([0, 1])('keeps the UTF-16 character boundary with metadata ending %i characters after the limit', async overflow => {
+ // > 256 KiB of UTF-8 bytes before the cwd, but still within 256K JS characters.
+ const padding = JSON.stringify({ bookkeeping: '漢'.repeat(90_000) }) + '\n'
+ const text = padding + ' '.repeat(LIMIT - padding.length - META.length + overflow) + META + '\nmore history'
+ expect(Buffer.byteLength(text)).toBeGreaterThan(LIMIT)
+ const { read } = await fixture(text)
+ if (overflow === 0) await expect(read()).resolves.toMatchObject({ sessionId: 'session-id' })
+ else await expect(read()).resolves.toBeNull()
+ })
+
+ it('keeps the first declared directory authoritative', async () => {
+ const { read } = await fixture(JSON.stringify({ cwd: '/somewhere/else' }) + '\n' + META + '\n')
+ await expect(read()).resolves.toBeNull()
+ })
+
+ it('finds a valid header even when the file exceeds the maximum JS string length', async () => {
+ const { path, read } = await fixture(META + '\n')
+ // A sparse suffix exercises the real file-size limit without allocating 512 MiB in the test.
+ truncateSync(path, constants.MAX_STRING_LENGTH + 4096)
+ await expect(read()).resolves.toMatchObject({ sessionId: 'session-id' })
+ })
+
+ it('bounds the actual disk read even when the transcript is much larger', async () => {
+ const { path, read } = await fixture(META + '\n' + 'x'.repeat(4 * 1024 * 1024))
+ const actual = await vi.importActual<typeof import('fs/promises')>('fs/promises')
+ const handle = await actual.open(path, 'r')
+ const reads = vi.spyOn(handle, 'read')
+ vi.mocked(fs.open).mockResolvedValueOnce(handle)
+ try {
+ await expect(read()).resolves.toMatchObject({ sessionId: 'session-id' })
+ expect(reads).toHaveBeenCalledTimes(1)
+ expect(reads.mock.calls[0].slice(1)).toEqual([0, LIMIT * 4, 0])
+ expect(handle.fd).toBe(-1)
+ } finally { if (handle.fd !== -1) await handle.close() }
+ })
+
+ it('fills short file reads and closes the handle', async () => {
+ const { path, read } = await fixture(META + '\n')
+ const actual = await vi.importActual<typeof import('fs/promises')>('fs/promises')
+ const handle = await actual.open(path, 'r')
+ const originalRead = handle.read.bind(handle)
+ vi.spyOn(handle, 'read').mockImplementation(((buffer: Buffer, offset: number, length: number, position: number) =>
+ originalRead(buffer, offset, Math.min(length, 7), position)) as typeof handle.read)
+ vi.mocked(fs.open).mockResolvedValueOnce(handle)
+ try {
+ await expect(read()).resolves.toMatchObject({ sessionId: 'session-id' })
+ expect(handle.fd).toBe(-1)
+ } finally { if (handle.fd !== -1) await handle.close() }
+ })
+
+ it('returns no binding and closes the handle after a read error', async () => {
+ const { path, read } = await fixture(META + '\n')
+ const actual = await vi.importActual<typeof import('fs/promises')>('fs/promises')
+ const handle = await actual.open(path, 'r')
+ vi.spyOn(handle, 'read').mockRejectedValueOnce(new Error('fixture read failure'))
+ vi.mocked(fs.open).mockResolvedValueOnce(handle)
+ try {
+ await expect(read()).resolves.toBeNull()
+ expect(handle.fd).toBe(-1)
+ } finally { if (handle.fd !== -1) await handle.close() }
+ })
+
+ it('stops and closes the handle if the file reaches EOF before its stated size', async () => {
+ const { path, read } = await fixture(META + '\n')
+ const actual = await vi.importActual<typeof import('fs/promises')>('fs/promises')
+ const handle = await actual.open(path, 'r')
+ vi.spyOn(handle, 'read').mockResolvedValueOnce({ bytesRead: 0, buffer: Buffer.alloc(0) })
+ vi.mocked(fs.open).mockResolvedValueOnce(handle)
+ try {
+ await expect(read()).resolves.toBeNull()
+ expect(handle.fd).toBe(-1)
+ } finally { if (handle.fd !== -1) await handle.close() }
+ })
+})
diff --git a/cli/src/lib/sessionRepair.spec.ts b/cli/src/lib/sessionRepair.spec.ts
index 00f0f52d0..35ed366a3 100644
--- a/cli/src/lib/sessionRepair.spec.ts
+++ b/cli/src/lib/sessionRepair.spec.ts
@@ -411,7 +411,7 @@ describe('claudeContinuation', () => {
await expect(claudeContinuation(oldPath)).resolves.toEqual({ sessionId: newId, transcriptPath: background })
})
- it('follows a continuation whose first turn is past the bounded read', async () => {
+ it.each(['x', '漢', '📘'])('follows a continuation past the byte cap with %s bookkeeping', async (character) => {
// A rollover can open on a `file-history-snapshot` big enough to push the first turn out of the
// head this check reads. What it rules out is two short lines, so size alone answers for a file
// larger than the bound — the bound must never be the thing that refuses a real conversation.
@@ -421,11 +421,15 @@ describe('claudeContinuation', () => {
writeFileSync(oldPath, `${JSON.stringify({ type: 'continued-in', continuedInSessionId: newId })}\n`)
const nextPath = join(dir, `${newId}.jsonl`)
writeFileSync(nextPath, [
- JSON.stringify({ type: 'file-history-snapshot', sessionId: newId, blob: 'x'.repeat(300 * 1024) }),
+ JSON.stringify({ type: 'file-history-snapshot', sessionId: newId, blob: character.repeat(300 * 1024) }),
JSON.stringify({ type: 'user', sessionId: newId, message: { role: 'user', content: 'carry on' } }),
].join('\n') + '\n')
await expect(claudeContinuation(oldPath)).resolves.toEqual({ sessionId: newId, transcriptPath: nextPath })
+
+ // Small Unicode-only bookkeeping is still an empty background session, not a conversation.
+ writeFileSync(nextPath, JSON.stringify({ type: 'ai-title', title: character.repeat(12) }) + '\n')
+ await expect(claudeContinuation(oldPath)).resolves.toBeNull()
})
it('returns null for a missing file', async () => {
diff --git a/cli/src/lib/sessionRepair.ts b/cli/src/lib/sessionRepair.ts
index e5ac9a625..5af77bd3d 100644
--- a/cli/src/lib/sessionRepair.ts
+++ b/cli/src/lib/sessionRepair.ts
@@ -77,10 +77,14 @@ async function transcripts(root: string, depth = 0): Promise<TranscriptFile[]> {
* line one; scanning a few lines covers all three without knowing which is which.
*/
const CWD_SCAN_LINES = 20
+const CWD_SCAN_CHARS = 256 * 1024
async function readTranscriptMeta(path: string): Promise<TranscriptMeta | null> {
try {
- const head = (await readFile(path, 'utf-8')).slice(0, 256 * 1024)
+ // Preserve the existing UTF-16 character budget, including non-ASCII paths. Four
+ // UTF-8 bytes per code unit is sufficient even when the cutoff splits a surrogate
+ // pair; a byte budget equal to the character budget would silently shrink the scan.
+ const head = (await headBytes(path, CWD_SCAN_CHARS * 4)).toString('utf-8').slice(0, CWD_SCAN_CHARS)
for (const line of head.split('\n', CWD_SCAN_LINES)) {
if (!line.trim()) continue
let obj: Record<string, unknown>
@@ -411,14 +415,19 @@ const CLAUDE_CONTINUATION_TAIL_BYTES = 4 * 1024
* lines of the top — the records before it are bookkeeping (mode, file history, title, agent name). */
const CLAUDE_CONTINUATION_HEAD_BYTES = 256 * 1024
-async function headBytes(path: string, maxBytes: number): Promise<string> {
+async function headBytes(path: string, maxBytes: number): Promise<Buffer> {
const handle = await open(path, 'r')
try {
const length = Math.min((await handle.stat()).size, maxBytes)
- if (length <= 0) return ''
+ if (length <= 0) return Buffer.alloc(0)
const buffer = Buffer.alloc(length)
- await handle.read(buffer, 0, length, 0)
- return buffer.toString('utf-8')
+ let read = 0
+ while (read < length) {
+ const { bytesRead } = await handle.read(buffer, read, length - read, read)
+ if (!bytesRead) break
+ read += bytesRead
+ }
+ return buffer.subarray(0, read)
} finally {
await handle.close()
}
@@ -438,13 +447,13 @@ async function headBytes(path: string, maxBytes: number): Promise<string> {
* these two lines and no turn.
*/
async function hasConversationTurn(path: string): Promise<boolean> {
- let head: string
+ let head: Buffer
try {
head = await headBytes(path, CLAUDE_CONTINUATION_HEAD_BYTES)
} catch {
return false
}
- for (const line of head.split('\n')) {
+ for (const line of head.toString('utf-8').split('\n')) {
if (!line.trim() || (!line.includes('"user"') && !line.includes('"assistant"'))) continue
try {
const record = JSON.parse(line) as { type?: unknown }
@@ -454,6 +463,8 @@ async function hasConversationTurn(path: string): Promise<boolean> {
// Nothing in the head, but more file than we read: a continuation can open on a `file-history-snapshot`
// large enough to push the first turn past the bound, and the thing being ruled out is two short
// lines. Anything this size is a conversation, so the bound must never be what refuses one.
+ // Count the bytes read, not decoded UTF-16 characters: Unicode bookkeeping must not make
+ // a read that hit the byte cap look smaller and strand the real turn beyond it.
return head.length >= CLAUDE_CONTINUATION_HEAD_BYTES
}
diff --git a/cli/src/lib/transcriptTail.spec.ts b/cli/src/lib/transcriptTail.spec.ts
new file mode 100644
index 000000000..27fb0fec6
--- /dev/null
+++ b/cli/src/lib/transcriptTail.spec.ts
@@ -0,0 +1,86 @@
+import { afterEach, beforeEach, describe, expect, it } from 'vitest'
+import { appendFileSync, mkdtempSync, rmSync, truncateSync, writeFileSync } from 'node:fs'
+import { tmpdir } from 'node:os'
+import { join } from 'node:path'
+import { tailFile, tailFileUntil } from './transcriptTail.js'
+
+describe('backward transcript suffix', () => {
+ let directory: string, file: string
+ beforeEach(() => { directory = mkdtempSync(join(tmpdir(), 'recap-tail-')); file = join(directory, 'history.jsonl') })
+ afterEach(() => rmSync(directory, { recursive: true, force: true }))
+
+ it.each(['\n', '\r\n', '\r'])('matches full readline records with %j separators', async (separator) => {
+ const rows = ['older', ' ', 'boundary', 'é📘漢字'.repeat(25_000), '', 'answer', 'tail']
+ writeFileSync(file, rows.join(separator))
+ const full = await tailFile(file, Infinity)
+ expect(await tailFileUntil(file, (line) => line === 'boundary' ? 'stop' : 'keep')).toEqual(full.slice(full.indexOf('boundary')))
+ })
+
+ it.each([0, 1, 2, 3, 65_535, 65_536, 65_537])('preserves UTF-8 and a boundary across chunks with %i bytes of tail padding', async (padding) => {
+ const rows = ['older', 'boundary📘', 'é📘漢字'.repeat(18_000), 'x'.repeat(padding)]
+ writeFileSync(file, rows.join('\n') + '\n')
+ expect(await tailFileUntil(file, (line) => line === 'boundary📘' ? 'stop' : 'keep')).toEqual(rows.slice(1).filter(Boolean))
+ })
+
+ it('stops before reading older records once it finds the boundary', async () => {
+ writeFileSync(file, 'older'.repeat(100_000) + '\nboundary\nanswer\n')
+ const seen: string[] = []
+ expect(await tailFileUntil(file, (line) => { seen.push(line); return line === 'boundary' ? 'stop' : 'keep' })).toEqual(['boundary', 'answer'])
+ expect(seen).toEqual(['answer', 'boundary'])
+ })
+
+ it('returns the entire file when there is no boundary, including a final unterminated line', async () => {
+ writeFileSync(file, 'first\n\nsecond\nlast')
+ expect(await tailFileUntil(file, () => 'keep')).toEqual(await tailFile(file, Infinity))
+ })
+
+ it('drops skipped records and stops on a boundary even if all later records are skipped', async () => {
+ writeFileSync(file, 'older\nboundary\nignored\nanswer\nignored\n')
+ const select = (line: string) => line === 'boundary' ? 'stop' : line === 'ignored' ? 'skip' : 'keep'
+ expect(await tailFileUntil(file, select)).toEqual(['boundary', 'answer'])
+ writeFileSync(file, 'older\nboundary\nignored\n')
+ expect(await tailFileUntil(file, select)).toEqual(['boundary'])
+ expect(await tailFileUntil(file, () => 'skip')).toEqual([])
+ })
+
+ it.each([65_534, 65_535, 65_536])('preserves CRLF split around the chunk edge with %i trailing bytes', async (padding) => {
+ writeFileSync(file, 'older\r\nboundary\r\n' + 'x'.repeat(padding))
+ expect(await tailFileUntil(file, (line) => line === 'boundary' ? 'stop' : 'keep')).toEqual(['boundary', 'x'.repeat(padding)])
+ })
+
+ it('matches readline with mixed separators and empty records at both file edges', async () => {
+ writeFileSync(file, '\n\r\nfirst\rsecond\nthird\r\nfourth\r\n\n')
+ expect(await tailFileUntil(file, () => 'keep')).toEqual(await tailFile(file, Infinity))
+ })
+
+ it('handles an empty or missing transcript', async () => {
+ expect(await tailFileUntil(file, () => 'stop')).toEqual([])
+ writeFileSync(file, '')
+ expect(await tailFileUntil(file, () => 'stop')).toEqual([])
+ })
+
+ it('reads the opening snapshot when the file grows during the read', async () => {
+ writeFileSync(file, 'boundary\n' + 'middle'.repeat(30_000) + '\nanswer\n')
+ let appended = false
+ const result = await tailFileUntil(file, (line) => {
+ if (!appended) { appended = true; appendFileSync(file, 'later\n') }
+ return line === 'boundary' ? 'stop' : 'keep'
+ })
+ expect(result).toEqual(['boundary', 'middle'.repeat(30_000), 'answer'])
+ })
+
+ it('does not return a mixed result after truncation between chunks', async () => {
+ writeFileSync(file, 'boundary\n' + 'middle'.repeat(30_000) + '\nanswer\n')
+ let truncated = false
+ expect(await tailFileUntil(file, () => {
+ if (!truncated) { truncated = true; truncateSync(file, 0) }
+ return 'keep'
+ })).toEqual([])
+ })
+
+ it('returns no result when boundary parsing fails and allows a retry', async () => {
+ writeFileSync(file, 'boundary\nanswer\n')
+ expect(await tailFileUntil(file, () => { throw new Error('parse failed') })).toEqual([])
+ expect(await tailFileUntil(file, () => 'stop')).toEqual(['answer'])
+ })
+})
diff --git a/cli/src/lib/transcriptTail.ts b/cli/src/lib/transcriptTail.ts
index f803086ad..cfc17d740 100644
--- a/cli/src/lib/transcriptTail.ts
+++ b/cli/src/lib/transcriptTail.ts
@@ -2,6 +2,59 @@ import { open } from 'node:fs/promises'
import { createReadStream } from 'node:fs'
import { createInterface } from 'node:readline'
+/** Read selected JSONL records backward, then return them in chronological order.
+ * `stop` includes the boundary record; `skip` discards an irrelevant record immediately.
+ * Only complete records are decoded, so UTF-8 may cross any read boundary. The file length is
+ * captured at open: later appends belong to the next read. A missing boundary reads back to BOF. */
+export async function tailFileUntil(filePath: string, select: (line: string) => 'keep' | 'skip' | 'stop'): Promise<string[]> {
+ try {
+ const handle = await open(filePath, 'r')
+ try {
+ let position = (await handle.stat()).size
+ const lines: string[] = []
+ // Fragments of one record, newest first; never concatenate the whole conversation.
+ let fragments: Buffer[] = []
+ const take = (head: Buffer): boolean => {
+ const bytes = fragments.length ? Buffer.concat([head, ...fragments.reverse()]) : head
+ fragments = []
+ const line = bytes.toString('utf8')
+ if (!line.trim()) return false
+ const action = select(line)
+ if (action !== 'skip') lines.push(line)
+ return action === 'stop'
+ }
+ while (position > 0) {
+ const length = Math.min(position, 64 * 1024)
+ position -= length
+ const chunk = Buffer.allocUnsafe(length)
+ let read = 0
+ while (read < length) {
+ const { bytesRead } = await handle.read(chunk, read, length - read, position + read)
+ if (!bytesRead) return [] // Truncated during the read; don't recap a mixed snapshot.
+ read += bytesRead
+ }
+ let end = length
+ // Each native search advances independently: CR-free files must not rescan the
+ // remaining chunk for CR once per LF. No per-byte JavaScript loop is needed.
+ let lf = chunk.lastIndexOf(10), cr = chunk.lastIndexOf(13)
+ while (lf >= 0 || cr >= 0) {
+ const i = Math.max(lf, cr)
+ // Match readline's LF, CRLF and bare-CR handling. The empty CRLF half is ignored.
+ if (take(chunk.subarray(i + 1, end))) return lines.reverse()
+ end = i
+ if (lf === i) lf = i > 0 ? chunk.lastIndexOf(10, i - 1) : -1
+ if (cr === i) cr = i > 0 ? chunk.lastIndexOf(13, i - 1) : -1
+ }
+ if (end) fragments.push(chunk.subarray(0, end))
+ }
+ if (fragments.length) take(Buffer.alloc(0))
+ return lines.reverse()
+ } finally { await handle.close() }
+ } catch {
+ return []
+ }
+}
+
/** Return the last `n` non-empty raw lines of a specific transcript file. Prefer this over
* `tailLines` when the caller already holds a trusted, registered `transcriptPath` — it takes no
* request-controlled id, so there is no path to traverse. */
diff --git a/docs/performance/2026-10-02-codex-recap-tail.json b/docs/performance/2026-10-02-codex-recap-tail.json
new file mode 100644
index 000000000..ffe1e706c
--- /dev/null
+++ b/docs/performance/2026-10-02-codex-recap-tail.json
@@ -0,0 +1,1310 @@
+{
+ "sourceSha256": {
+ "src/lib/transcriptTail.ts": "99258f7cc587c27c848ad4834975977b8ce1b7fcd1e66726d9b7933e9a240a10",
+ "src/engines/codex/normalizer.ts": "6cdd6060b8f1eacb16576ef62156b2731af6043651c92cb0da084cc197672d15",
+ "src/engines/codex/lastTurn.ts": "325a5b029a216b08db84bf38abf56e354496d219bc6c7a1945685583af91191a",
+ "src/cli.ts": "f75c8547fc43a0be285f9d64c2c92320403f53289da3fd8049b356e82ee991a2",
+ "package-lock.json": "5c69dffb1423173dfab75c0aa493b5c601784ff3efd16b9bfbb41ef9ad1c4d2b"
+ },
+ "finishedAt": "2026-10-02T18:26:39.944Z",
+ "node": "v22.23.2",
+ "platform": "darwin",
+ "arch": "arm64",
+ "scope": "Full-history recap vs reverse suffix using the same final parser, minified bundle, real synthetic files, disposable processes. No live app changes. Explicit GC runs only in benchmark children before timing.",
+ "rows": [
+ {
+ "name": "short-latest-0MiB",
+ "sizeMiB": 0,
+ "shape": "short",
+ "fileBytes": 18139,
+ "trial": 0,
+ "mode": "baseline",
+ "durationMs": 0.329540999999999,
+ "cpuUs": 1119,
+ "before": {
+ "rss": 57901056,
+ "heapTotal": 10895360,
+ "heapUsed": 5011816,
+ "external": 3619499,
+ "arrayBuffers": 82162
+ },
+ "after": {
+ "rss": 57901056,
+ "heapTotal": 10895360,
+ "heapUsed": 5145616,
+ "external": 2426285,
+ "arrayBuffers": 231396
+ },
+ "maxRssKiB": 56544,
+ "outputSha256": "51f3cd84a14896c88222c8cbb65478a655d57cd657bdae6230ffb68ab372ad4f",
+ "outputBytes": 9253
+ },
+ {
+ "name": "short-latest-0MiB",
+ "sizeMiB": 0,
+ "shape": "short",
+ "fileBytes": 18139,
+ "trial": 0,
+ "mode": "candidate",
+ "durationMs": 0.20204100000000125,
+ "cpuUs": 914,
+ "before": {
+ "rss": 54525952,
+ "heapTotal": 9584640,
+ "heapUsed": 4774848,
+ "external": 2379288,
+ "arrayBuffers": 16619
+ },
+ "after": {
+ "rss": 54525952,
+ "heapTotal": 9584640,
+ "heapUsed": 4850656,
+ "external": 2230116,
+ "arrayBuffers": 35374
+ },
+ "maxRssKiB": 53248,
+ "outputSha256": "51f3cd84a14896c88222c8cbb65478a655d57cd657bdae6230ffb68ab372ad4f",
+ "outputBytes": 9253
+ },
+ {
+ "name": "short-latest-0MiB",
+ "sizeMiB": 0,
+ "shape": "short",
+ "fileBytes": 18139,
+ "trial": 1,
+ "mode": "candidate",
+ "durationMs": 0.2273750000000021,
+ "cpuUs": 884,
+ "before": {
+ "rss": 54575104,
+ "heapTotal": 9584640,
+ "heapUsed": 4774992,
+ "external": 2416006,
+ "arrayBuffers": 16619
+ },
+ "after": {
+ "rss": 54575104,
+ "heapTotal": 9584640,
+ "heapUsed": 4850800,
+ "external": 2230116,
+ "arrayBuffers": 35374
+ },
+ "maxRssKiB": 53296,
+ "outputSha256": "51f3cd84a14896c88222c8cbb65478a655d57cd657bdae6230ffb68ab372ad4f",
+ "outputBytes": 9253
+ },
+ {
+ "name": "short-latest-0MiB",
+ "sizeMiB": 0,
+ "shape": "short",
+ "fileBytes": 18139,
+ "trial": 1,
+ "mode": "baseline",
+ "durationMs": 0.30733299999999986,
+ "cpuUs": 1063,
+ "before": {
+ "rss": 57688064,
+ "heapTotal": 11157504,
+ "heapUsed": 5011816,
+ "external": 3852225,
+ "arrayBuffers": 82162
+ },
+ "after": {
+ "rss": 57720832,
+ "heapTotal": 11157504,
+ "heapUsed": 5145616,
+ "external": 2426285,
+ "arrayBuffers": 231396
+ },
+ "maxRssKiB": 56368,
+ "outputSha256": "51f3cd84a14896c88222c8cbb65478a655d57cd657bdae6230ffb68ab372ad4f",
+ "outputBytes": 9253
+ },
+ {
+ "name": "short-latest-0MiB",
+ "sizeMiB": 0,
+ "shape": "short",
+ "fileBytes": 18139,
+ "trial": 2,
+ "mode": "baseline",
+ "durationMs": 0.28591700000000486,
+ "cpuUs": 1057,
+ "before": {
+ "rss": 57524224,
+ "heapTotal": 10895360,
+ "heapUsed": 5011960,
+ "external": 3553963,
+ "arrayBuffers": 82162
+ },
+ "after": {
+ "rss": 57524224,
+ "heapTotal": 10895360,
+ "heapUsed": 5145760,
+ "external": 2426285,
+ "arrayBuffers": 231396
+ },
+ "maxRssKiB": 56176,
+ "outputSha256": "51f3cd84a14896c88222c8cbb65478a655d57cd657bdae6230ffb68ab372ad4f",
+ "outputBytes": 9253
+ },
+ {
+ "name": "short-latest-0MiB",
+ "sizeMiB": 0,
+ "shape": "short",
+ "fileBytes": 18139,
+ "trial": 2,
+ "mode": "candidate",
+ "durationMs": 0.18200000000000216,
+ "cpuUs": 834,
+ "before": {
+ "rss": 54591488,
+ "heapTotal": 9584640,
+ "heapUsed": 4774920,
+ "external": 2397347,
+ "arrayBuffers": 16619
+ },
+ "after": {
+ "rss": 54591488,
+ "heapTotal": 9584640,
+ "heapUsed": 4850728,
+ "external": 2230116,
+ "arrayBuffers": 35374
+ },
+ "maxRssKiB": 53312,
+ "outputSha256": "51f3cd84a14896c88222c8cbb65478a655d57cd657bdae6230ffb68ab372ad4f",
+ "outputBytes": 9253
+ },
+ {
+ "name": "short-latest-1MiB",
+ "sizeMiB": 1,
+ "shape": "short",
+ "fileBytes": 1067979,
+ "trial": 0,
+ "mode": "baseline",
+ "durationMs": 2.539999999999999,
+ "cpuUs": 3368,
+ "before": {
+ "rss": 57360384,
+ "heapTotal": 10895360,
+ "heapUsed": 5011816,
+ "external": 3852225,
+ "arrayBuffers": 82162
+ },
+ "after": {
+ "rss": 60375040,
+ "heapTotal": 16318464,
+ "heapUsed": 9650568,
+ "external": 2886301,
+ "arrayBuffers": 691412
+ },
+ "maxRssKiB": 58960,
+ "outputSha256": "51f3cd84a14896c88222c8cbb65478a655d57cd657bdae6230ffb68ab372ad4f",
+ "outputBytes": 9253
+ },
+ {
+ "name": "short-latest-1MiB",
+ "sizeMiB": 1,
+ "shape": "short",
+ "fileBytes": 1067979,
+ "trial": 0,
+ "mode": "candidate",
+ "durationMs": 0.2595409999999987,
+ "cpuUs": 947,
+ "before": {
+ "rss": 54525952,
+ "heapTotal": 9584640,
+ "heapUsed": 4774992,
+ "external": 2379288,
+ "arrayBuffers": 16619
+ },
+ "after": {
+ "rss": 54624256,
+ "heapTotal": 9584640,
+ "heapUsed": 4850800,
+ "external": 2277513,
+ "arrayBuffers": 82771
+ },
+ "maxRssKiB": 53344,
+ "outputSha256": "51f3cd84a14896c88222c8cbb65478a655d57cd657bdae6230ffb68ab372ad4f",
+ "outputBytes": 9253
+ },
+ {
+ "name": "short-latest-1MiB",
+ "sizeMiB": 1,
+ "shape": "short",
+ "fileBytes": 1067979,
+ "trial": 1,
+ "mode": "candidate",
+ "durationMs": 0.23929200000000606,
+ "cpuUs": 913,
+ "before": {
+ "rss": 54427648,
+ "heapTotal": 7487488,
+ "heapUsed": 4774848,
+ "external": 2416606,
+ "arrayBuffers": 16619
+ },
+ "after": {
+ "rss": 54542336,
+ "heapTotal": 7487488,
+ "heapUsed": 4850656,
+ "external": 2277513,
+ "arrayBuffers": 82771
+ },
+ "maxRssKiB": 53264,
+ "outputSha256": "51f3cd84a14896c88222c8cbb65478a655d57cd657bdae6230ffb68ab372ad4f",
+ "outputBytes": 9253
+ },
+ {
+ "name": "short-latest-1MiB",
+ "sizeMiB": 1,
+ "shape": "short",
+ "fileBytes": 1067979,
+ "trial": 1,
+ "mode": "baseline",
+ "durationMs": 2.4630829999999975,
+ "cpuUs": 3268,
+ "before": {
+ "rss": 57737216,
+ "heapTotal": 10633216,
+ "heapUsed": 5011816,
+ "external": 3619499,
+ "arrayBuffers": 82162
+ },
+ "after": {
+ "rss": 60801024,
+ "heapTotal": 16580608,
+ "heapUsed": 9524328,
+ "external": 2886301,
+ "arrayBuffers": 691412
+ },
+ "maxRssKiB": 59376,
+ "outputSha256": "51f3cd84a14896c88222c8cbb65478a655d57cd657bdae6230ffb68ab372ad4f",
+ "outputBytes": 9253
+ },
+ {
+ "name": "short-latest-1MiB",
+ "sizeMiB": 1,
+ "shape": "short",
+ "fileBytes": 1067979,
+ "trial": 2,
+ "mode": "baseline",
+ "durationMs": 2.507165999999998,
+ "cpuUs": 3364,
+ "before": {
+ "rss": 57933824,
+ "heapTotal": 10895360,
+ "heapUsed": 5011816,
+ "external": 3619499,
+ "arrayBuffers": 82162
+ },
+ "after": {
+ "rss": 60817408,
+ "heapTotal": 16318464,
+ "heapUsed": 9650568,
+ "external": 2886301,
+ "arrayBuffers": 691412
+ },
+ "maxRssKiB": 59392,
+ "outputSha256": "51f3cd84a14896c88222c8cbb65478a655d57cd657bdae6230ffb68ab372ad4f",
+ "outputBytes": 9253
+ },
+ {
+ "name": "short-latest-1MiB",
+ "sizeMiB": 1,
+ "shape": "short",
+ "fileBytes": 1067979,
+ "trial": 2,
+ "mode": "candidate",
+ "durationMs": 0.23049999999999926,
+ "cpuUs": 922,
+ "before": {
+ "rss": 54624256,
+ "heapTotal": 9584640,
+ "heapUsed": 4774848,
+ "external": 2397347,
+ "arrayBuffers": 16619
+ },
+ "after": {
+ "rss": 54706176,
+ "heapTotal": 9584640,
+ "heapUsed": 4850656,
+ "external": 2277513,
+ "arrayBuffers": 82771
+ },
+ "maxRssKiB": 53424,
+ "outputSha256": "51f3cd84a14896c88222c8cbb65478a655d57cd657bdae6230ffb68ab372ad4f",
+ "outputBytes": 9253
+ },
+ {
+ "name": "short-latest-64MiB",
+ "sizeMiB": 64,
+ "shape": "short",
+ "fileBytes": 67142284,
+ "trial": 0,
+ "mode": "baseline",
+ "durationMs": 125.65562499999999,
+ "cpuUs": 140340,
+ "before": {
+ "rss": 57212928,
+ "heapTotal": 10895360,
+ "heapUsed": 5011816,
+ "external": 3703094,
+ "arrayBuffers": 82162
+ },
+ "after": {
+ "rss": 203997184,
+ "heapTotal": 159858688,
+ "heapUsed": 113825272,
+ "external": 2801355,
+ "arrayBuffers": 606466
+ },
+ "maxRssKiB": 199216,
+ "outputSha256": "51f3cd84a14896c88222c8cbb65478a655d57cd657bdae6230ffb68ab372ad4f",
+ "outputBytes": 9253
+ },
+ {
+ "name": "short-latest-64MiB",
+ "sizeMiB": 64,
+ "shape": "short",
+ "fileBytes": 67142284,
+ "trial": 0,
+ "mode": "candidate",
+ "durationMs": 0.2577500000000015,
+ "cpuUs": 948,
+ "before": {
+ "rss": 54640640,
+ "heapTotal": 9584640,
+ "heapUsed": 4774920,
+ "external": 2416006,
+ "arrayBuffers": 16619
+ },
+ "after": {
+ "rss": 54755328,
+ "heapTotal": 9584640,
+ "heapUsed": 4850728,
+ "external": 2277513,
+ "arrayBuffers": 82771
+ },
+ "maxRssKiB": 53472,
+ "outputSha256": "51f3cd84a14896c88222c8cbb65478a655d57cd657bdae6230ffb68ab372ad4f",
+ "outputBytes": 9253
+ },
+ {
+ "name": "short-latest-64MiB",
+ "sizeMiB": 64,
+ "shape": "short",
+ "fileBytes": 67142284,
+ "trial": 1,
+ "mode": "candidate",
+ "durationMs": 0.23366700000000407,
+ "cpuUs": 897,
+ "before": {
+ "rss": 54591488,
+ "heapTotal": 9584640,
+ "heapUsed": 4775064,
+ "external": 2397347,
+ "arrayBuffers": 16619
+ },
+ "after": {
+ "rss": 54689792,
+ "heapTotal": 9584640,
+ "heapUsed": 4850872,
+ "external": 2277513,
+ "arrayBuffers": 82771
+ },
+ "maxRssKiB": 53408,
+ "outputSha256": "51f3cd84a14896c88222c8cbb65478a655d57cd657bdae6230ffb68ab372ad4f",
+ "outputBytes": 9253
+ },
+ {
+ "name": "short-latest-64MiB",
+ "sizeMiB": 64,
+ "shape": "short",
+ "fileBytes": 67142284,
+ "trial": 1,
+ "mode": "baseline",
+ "durationMs": 125.40645799999999,
+ "cpuUs": 139863,
+ "before": {
+ "rss": 57999360,
+ "heapTotal": 10895360,
+ "heapUsed": 5011888,
+ "external": 3553963,
+ "arrayBuffers": 82162
+ },
+ "after": {
+ "rss": 206110720,
+ "heapTotal": 161693696,
+ "heapUsed": 126653704,
+ "external": 2932427,
+ "arrayBuffers": 737538
+ },
+ "maxRssKiB": 201280,
+ "outputSha256": "51f3cd84a14896c88222c8cbb65478a655d57cd657bdae6230ffb68ab372ad4f",
+ "outputBytes": 9253
+ },
+ {
+ "name": "short-latest-64MiB",
+ "sizeMiB": 64,
+ "shape": "short",
+ "fileBytes": 67142284,
+ "trial": 2,
+ "mode": "baseline",
+ "durationMs": 132.27495800000003,
+ "cpuUs": 148822,
+ "before": {
+ "rss": 57671680,
+ "heapTotal": 11157504,
+ "heapUsed": 5011816,
+ "external": 3619499,
+ "arrayBuffers": 82162
+ },
+ "after": {
+ "rss": 207257600,
+ "heapTotal": 160645120,
+ "heapUsed": 113253328,
+ "external": 2997963,
+ "arrayBuffers": 803074
+ },
+ "maxRssKiB": 202400,
+ "outputSha256": "51f3cd84a14896c88222c8cbb65478a655d57cd657bdae6230ffb68ab372ad4f",
+ "outputBytes": 9253
+ },
+ {
+ "name": "short-latest-64MiB",
+ "sizeMiB": 64,
+ "shape": "short",
+ "fileBytes": 67142284,
+ "trial": 2,
+ "mode": "candidate",
+ "durationMs": 0.24570800000000048,
+ "cpuUs": 926,
+ "before": {
+ "rss": 54493184,
+ "heapTotal": 7487488,
+ "heapUsed": 4774920,
+ "external": 2416606,
+ "arrayBuffers": 16619
+ },
+ "after": {
+ "rss": 54575104,
+ "heapTotal": 7487488,
+ "heapUsed": 4850728,
+ "external": 2277513,
+ "arrayBuffers": 82771
+ },
+ "maxRssKiB": 53296,
+ "outputSha256": "51f3cd84a14896c88222c8cbb65478a655d57cd657bdae6230ffb68ab372ad4f",
+ "outputBytes": 9253
+ },
+ {
+ "name": "short-latest-512MiB",
+ "sizeMiB": 512,
+ "shape": "short",
+ "fileBytes": 536945684,
+ "trial": 0,
+ "mode": "baseline",
+ "durationMs": 985.470416,
+ "cpuUs": 1052050,
+ "before": {
+ "rss": 57327616,
+ "heapTotal": 10895360,
+ "heapUsed": 5011816,
+ "external": 3703094,
+ "arrayBuffers": 82162
+ },
+ "after": {
+ "rss": 954073088,
+ "heapTotal": 969768960,
+ "heapUsed": 819327424,
+ "external": 2473675,
+ "arrayBuffers": 278786
+ },
+ "maxRssKiB": 931712,
+ "outputSha256": "51f3cd84a14896c88222c8cbb65478a655d57cd657bdae6230ffb68ab372ad4f",
+ "outputBytes": 9253
+ },
+ {
+ "name": "short-latest-512MiB",
+ "sizeMiB": 512,
+ "shape": "short",
+ "fileBytes": 536945684,
+ "trial": 0,
+ "mode": "candidate",
+ "durationMs": 0.3023329999999973,
+ "cpuUs": 998,
+ "before": {
+ "rss": 54591488,
+ "heapTotal": 9584640,
+ "heapUsed": 4774920,
+ "external": 2416006,
+ "arrayBuffers": 16619
+ },
+ "after": {
+ "rss": 54706176,
+ "heapTotal": 9584640,
+ "heapUsed": 4850728,
+ "external": 2277513,
+ "arrayBuffers": 82771
+ },
+ "maxRssKiB": 53424,
+ "outputSha256": "51f3cd84a14896c88222c8cbb65478a655d57cd657bdae6230ffb68ab372ad4f",
+ "outputBytes": 9253
+ },
+ {
+ "name": "short-latest-512MiB",
+ "sizeMiB": 512,
+ "shape": "short",
+ "fileBytes": 536945684,
+ "trial": 1,
+ "mode": "candidate",
+ "durationMs": 0.26687500000000597,
+ "cpuUs": 973,
+ "before": {
+ "rss": 54444032,
+ "heapTotal": 7487488,
+ "heapUsed": 4774848,
+ "external": 2416606,
+ "arrayBuffers": 16619
+ },
+ "after": {
+ "rss": 54525952,
+ "heapTotal": 7487488,
+ "heapUsed": 4850656,
+ "external": 2277513,
+ "arrayBuffers": 82771
+ },
+ "maxRssKiB": 53248,
+ "outputSha256": "51f3cd84a14896c88222c8cbb65478a655d57cd657bdae6230ffb68ab372ad4f",
+ "outputBytes": 9253
+ },
+ {
+ "name": "short-latest-512MiB",
+ "sizeMiB": 512,
+ "shape": "short",
+ "fileBytes": 536945684,
+ "trial": 1,
+ "mode": "baseline",
+ "durationMs": 997.592833,
+ "cpuUs": 1065078,
+ "before": {
+ "rss": 57507840,
+ "heapTotal": 10895360,
+ "heapUsed": 5011816,
+ "external": 3703094,
+ "arrayBuffers": 82162
+ },
+ "after": {
+ "rss": 957005824,
+ "heapTotal": 971341824,
+ "heapUsed": 823073456,
+ "external": 2932427,
+ "arrayBuffers": 737538
+ },
+ "maxRssKiB": 934576,
+ "outputSha256": "51f3cd84a14896c88222c8cbb65478a655d57cd657bdae6230ffb68ab372ad4f",
+ "outputBytes": 9253
+ },
+ {
+ "name": "short-latest-512MiB",
+ "sizeMiB": 512,
+ "shape": "short",
+ "fileBytes": 536945684,
+ "trial": 2,
+ "mode": "baseline",
+ "durationMs": 1007.696667,
+ "cpuUs": 1076290,
+ "before": {
+ "rss": 57688064,
+ "heapTotal": 10895360,
+ "heapUsed": 5011816,
+ "external": 3703094,
+ "arrayBuffers": 82162
+ },
+ "after": {
+ "rss": 957218816,
+ "heapTotal": 970817536,
+ "heapUsed": 826746800,
+ "external": 2932427,
+ "arrayBuffers": 737538
+ },
+ "maxRssKiB": 934784,
+ "outputSha256": "51f3cd84a14896c88222c8cbb65478a655d57cd657bdae6230ffb68ab372ad4f",
+ "outputBytes": 9253
+ },
+ {
+ "name": "short-latest-512MiB",
+ "sizeMiB": 512,
+ "shape": "short",
+ "fileBytes": 536945684,
+ "trial": 2,
+ "mode": "candidate",
+ "durationMs": 0.2644170000000017,
+ "cpuUs": 955,
+ "before": {
+ "rss": 54509568,
+ "heapTotal": 9584640,
+ "heapUsed": 4774848,
+ "external": 2416006,
+ "arrayBuffers": 16619
+ },
+ "after": {
+ "rss": 54607872,
+ "heapTotal": 9584640,
+ "heapUsed": 4850656,
+ "external": 2277513,
+ "arrayBuffers": 82771
+ },
+ "maxRssKiB": 53328,
+ "outputSha256": "51f3cd84a14896c88222c8cbb65478a655d57cd657bdae6230ffb68ab372ad4f",
+ "outputBytes": 9253
+ },
+ {
+ "name": "long-latest-64MiB",
+ "sizeMiB": 64,
+ "shape": "long",
+ "fileBytes": 67133521,
+ "trial": 0,
+ "mode": "baseline",
+ "durationMs": 142.12095899999997,
+ "cpuUs": 153180,
+ "before": {
+ "rss": 57278464,
+ "heapTotal": 10895360,
+ "heapUsed": 5011816,
+ "external": 3703094,
+ "arrayBuffers": 82162
+ },
+ "after": {
+ "rss": 315195392,
+ "heapTotal": 264421376,
+ "heapUsed": 227096936,
+ "external": 2801355,
+ "arrayBuffers": 606466
+ },
+ "maxRssKiB": 307808,
+ "outputSha256": "51f3cd84a14896c88222c8cbb65478a655d57cd657bdae6230ffb68ab372ad4f",
+ "outputBytes": 9253
+ },
+ {
+ "name": "long-latest-64MiB",
+ "sizeMiB": 64,
+ "shape": "long",
+ "fileBytes": 67133521,
+ "trial": 0,
+ "mode": "candidate",
+ "durationMs": 91.190333,
+ "cpuUs": 94218,
+ "before": {
+ "rss": 54525952,
+ "heapTotal": 9584640,
+ "heapUsed": 4774848,
+ "external": 2397347,
+ "arrayBuffers": 16619
+ },
+ "after": {
+ "rss": 60047360,
+ "heapTotal": 9584640,
+ "heapUsed": 5278688,
+ "external": 2630084,
+ "arrayBuffers": 435342
+ },
+ "maxRssKiB": 58640,
+ "outputSha256": "51f3cd84a14896c88222c8cbb65478a655d57cd657bdae6230ffb68ab372ad4f",
+ "outputBytes": 9253
+ },
+ {
+ "name": "long-latest-64MiB",
+ "sizeMiB": 64,
+ "shape": "long",
+ "fileBytes": 67133521,
+ "trial": 1,
+ "mode": "candidate",
+ "durationMs": 90.67587499999999,
+ "cpuUs": 93789,
+ "before": {
+ "rss": 54525952,
+ "heapTotal": 9584640,
+ "heapUsed": 4774848,
+ "external": 2416006,
+ "arrayBuffers": 16619
+ },
+ "after": {
+ "rss": 60899328,
+ "heapTotal": 9584640,
+ "heapUsed": 5278688,
+ "external": 2630084,
+ "arrayBuffers": 435342
+ },
+ "maxRssKiB": 59472,
+ "outputSha256": "51f3cd84a14896c88222c8cbb65478a655d57cd657bdae6230ffb68ab372ad4f",
+ "outputBytes": 9253
+ },
+ {
+ "name": "long-latest-64MiB",
+ "sizeMiB": 64,
+ "shape": "long",
+ "fileBytes": 67133521,
+ "trial": 1,
+ "mode": "baseline",
+ "durationMs": 141.245708,
+ "cpuUs": 152611,
+ "before": {
+ "rss": 57720832,
+ "heapTotal": 11157504,
+ "heapUsed": 5011816,
+ "external": 3553963,
+ "arrayBuffers": 82162
+ },
+ "after": {
+ "rss": 315293696,
+ "heapTotal": 264159232,
+ "heapUsed": 226964136,
+ "external": 2735819,
+ "arrayBuffers": 540930
+ },
+ "maxRssKiB": 307904,
+ "outputSha256": "51f3cd84a14896c88222c8cbb65478a655d57cd657bdae6230ffb68ab372ad4f",
+ "outputBytes": 9253
+ },
+ {
+ "name": "long-latest-64MiB",
+ "sizeMiB": 64,
+ "shape": "long",
+ "fileBytes": 67133521,
+ "trial": 2,
+ "mode": "baseline",
+ "durationMs": 148.82025000000002,
+ "cpuUs": 162101,
+ "before": {
+ "rss": 57655296,
+ "heapTotal": 10895360,
+ "heapUsed": 5011888,
+ "external": 3619499,
+ "arrayBuffers": 82162
+ },
+ "after": {
+ "rss": 315490304,
+ "heapTotal": 264159232,
+ "heapUsed": 226831464,
+ "external": 2670283,
+ "arrayBuffers": 475394
+ },
+ "maxRssKiB": 308096,
+ "outputSha256": "51f3cd84a14896c88222c8cbb65478a655d57cd657bdae6230ffb68ab372ad4f",
+ "outputBytes": 9253
+ },
+ {
+ "name": "long-latest-64MiB",
+ "sizeMiB": 64,
+ "shape": "long",
+ "fileBytes": 67133521,
+ "trial": 2,
+ "mode": "candidate",
+ "durationMs": 96.22862500000001,
+ "cpuUs": 99586,
+ "before": {
+ "rss": 54509568,
+ "heapTotal": 9584640,
+ "heapUsed": 4774848,
+ "external": 2434665,
+ "arrayBuffers": 16619
+ },
+ "after": {
+ "rss": 59949056,
+ "heapTotal": 9584640,
+ "heapUsed": 5278688,
+ "external": 2630084,
+ "arrayBuffers": 435342
+ },
+ "maxRssKiB": 58544,
+ "outputSha256": "51f3cd84a14896c88222c8cbb65478a655d57cd657bdae6230ffb68ab372ad4f",
+ "outputBytes": 9253
+ },
+ {
+ "name": "no-boundary-64MiB",
+ "sizeMiB": 64,
+ "shape": "no-boundary",
+ "fileBytes": 67133437,
+ "trial": 0,
+ "mode": "baseline",
+ "durationMs": 131.07412499999998,
+ "cpuUs": 146552,
+ "before": {
+ "rss": 57180160,
+ "heapTotal": 10895360,
+ "heapUsed": 5011816,
+ "external": 3703094,
+ "arrayBuffers": 82162
+ },
+ "after": {
+ "rss": 204029952,
+ "heapTotal": 159825920,
+ "heapUsed": 113614488,
+ "external": 2866891,
+ "arrayBuffers": 672002
+ },
+ "maxRssKiB": 199248,
+ "outputSha256": "4aa56bbb821e549e2bf7d530c172bf4aaabf453a3f8b5c3ac677231caa84f0d4",
+ "outputBytes": 9237
+ },
+ {
+ "name": "no-boundary-64MiB",
+ "sizeMiB": 64,
+ "shape": "no-boundary",
+ "fileBytes": 67133437,
+ "trial": 0,
+ "mode": "candidate",
+ "durationMs": 92.832458,
+ "cpuUs": 96206,
+ "before": {
+ "rss": 54444032,
+ "heapTotal": 9584640,
+ "heapUsed": 4774848,
+ "external": 2416006,
+ "arrayBuffers": 16619
+ },
+ "after": {
+ "rss": 59621376,
+ "heapTotal": 9584640,
+ "heapUsed": 5276792,
+ "external": 2630000,
+ "arrayBuffers": 435258
+ },
+ "maxRssKiB": 58224,
+ "outputSha256": "4aa56bbb821e549e2bf7d530c172bf4aaabf453a3f8b5c3ac677231caa84f0d4",
+ "outputBytes": 9237
+ },
+ {
+ "name": "no-boundary-64MiB",
+ "sizeMiB": 64,
+ "shape": "no-boundary",
+ "fileBytes": 67133437,
+ "trial": 1,
+ "mode": "candidate",
+ "durationMs": 91.126417,
+ "cpuUs": 94342,
+ "before": {
+ "rss": 54591488,
+ "heapTotal": 9584640,
+ "heapUsed": 4774920,
+ "external": 2416006,
+ "arrayBuffers": 16619
+ },
+ "after": {
+ "rss": 60915712,
+ "heapTotal": 9584640,
+ "heapUsed": 5276864,
+ "external": 2630000,
+ "arrayBuffers": 435258
+ },
+ "maxRssKiB": 59488,
+ "outputSha256": "4aa56bbb821e549e2bf7d530c172bf4aaabf453a3f8b5c3ac677231caa84f0d4",
+ "outputBytes": 9237
+ },
+ {
+ "name": "no-boundary-64MiB",
+ "sizeMiB": 64,
+ "shape": "no-boundary",
+ "fileBytes": 67133437,
+ "trial": 1,
+ "mode": "baseline",
+ "durationMs": 127.054292,
+ "cpuUs": 140491,
+ "before": {
+ "rss": 57524224,
+ "heapTotal": 10895360,
+ "heapUsed": 5011816,
+ "external": 3619499,
+ "arrayBuffers": 82162
+ },
+ "after": {
+ "rss": 209715200,
+ "heapTotal": 161660928,
+ "heapUsed": 126434976,
+ "external": 2866891,
+ "arrayBuffers": 672002
+ },
+ "maxRssKiB": 204800,
+ "outputSha256": "4aa56bbb821e549e2bf7d530c172bf4aaabf453a3f8b5c3ac677231caa84f0d4",
+ "outputBytes": 9237
+ },
+ {
+ "name": "no-boundary-64MiB",
+ "sizeMiB": 64,
+ "shape": "no-boundary",
+ "fileBytes": 67133437,
+ "trial": 2,
+ "mode": "baseline",
+ "durationMs": 129.124666,
+ "cpuUs": 144577,
+ "before": {
+ "rss": 57819136,
+ "heapTotal": 10895360,
+ "heapUsed": 5011816,
+ "external": 3553963,
+ "arrayBuffers": 82162
+ },
+ "after": {
+ "rss": 203636736,
+ "heapTotal": 160874496,
+ "heapUsed": 126119376,
+ "external": 2997963,
+ "arrayBuffers": 803074
+ },
+ "maxRssKiB": 198864,
+ "outputSha256": "4aa56bbb821e549e2bf7d530c172bf4aaabf453a3f8b5c3ac677231caa84f0d4",
+ "outputBytes": 9237
+ },
+ {
+ "name": "no-boundary-64MiB",
+ "sizeMiB": 64,
+ "shape": "no-boundary",
+ "fileBytes": 67133437,
+ "trial": 2,
+ "mode": "candidate",
+ "durationMs": 96.62437500000001,
+ "cpuUs": 100099,
+ "before": {
+ "rss": 54509568,
+ "heapTotal": 9584640,
+ "heapUsed": 4774848,
+ "external": 2416006,
+ "arrayBuffers": 16619
+ },
+ "after": {
+ "rss": 59621376,
+ "heapTotal": 9584640,
+ "heapUsed": 5276792,
+ "external": 2630000,
+ "arrayBuffers": 435258
+ },
+ "maxRssKiB": 58224,
+ "outputSha256": "4aa56bbb821e549e2bf7d530c172bf4aaabf453a3f8b5c3ac677231caa84f0d4",
+ "outputBytes": 9237
+ },
+ {
+ "name": "single-tool-64MiB",
+ "sizeMiB": 64,
+ "shape": "single-tool",
+ "fileBytes": 67118319,
+ "trial": 0,
+ "mode": "baseline",
+ "durationMs": 145.09199999999998,
+ "cpuUs": 156300,
+ "before": {
+ "rss": 57753600,
+ "heapTotal": 11157504,
+ "heapUsed": 5011960,
+ "external": 3703094,
+ "arrayBuffers": 82162
+ },
+ "after": {
+ "rss": 367640576,
+ "heapTotal": 323829760,
+ "heapUsed": 268644272,
+ "external": 7529402,
+ "arrayBuffers": 278786
+ },
+ "maxRssKiB": 359024,
+ "outputSha256": "51f3cd84a14896c88222c8cbb65478a655d57cd657bdae6230ffb68ab372ad4f",
+ "outputBytes": 9253
+ },
+ {
+ "name": "single-tool-64MiB",
+ "sizeMiB": 64,
+ "shape": "single-tool",
+ "fileBytes": 67118319,
+ "trial": 0,
+ "mode": "candidate",
+ "durationMs": 105.097792,
+ "cpuUs": 110522,
+ "before": {
+ "rss": 54607872,
+ "heapTotal": 9584640,
+ "heapUsed": 4774920,
+ "external": 2416006,
+ "arrayBuffers": 16619
+ },
+ "after": {
+ "rss": 324665344,
+ "heapTotal": 144097280,
+ "heapUsed": 139245256,
+ "external": 136439238,
+ "arrayBuffers": 134244496
+ },
+ "maxRssKiB": 317056,
+ "outputSha256": "51f3cd84a14896c88222c8cbb65478a655d57cd657bdae6230ffb68ab372ad4f",
+ "outputBytes": 9253
+ },
+ {
+ "name": "single-tool-64MiB",
+ "sizeMiB": 64,
+ "shape": "single-tool",
+ "fileBytes": 67118319,
+ "trial": 1,
+ "mode": "candidate",
+ "durationMs": 103.12100000000001,
+ "cpuUs": 108714,
+ "before": {
+ "rss": 54394880,
+ "heapTotal": 9584640,
+ "heapUsed": 4774848,
+ "external": 2416006,
+ "arrayBuffers": 16619
+ },
+ "after": {
+ "rss": 257523712,
+ "heapTotal": 80904192,
+ "heapUsed": 72099880,
+ "external": 136438838,
+ "arrayBuffers": 134244096
+ },
+ "maxRssKiB": 317040,
+ "outputSha256": "51f3cd84a14896c88222c8cbb65478a655d57cd657bdae6230ffb68ab372ad4f",
+ "outputBytes": 9253
+ },
+ {
+ "name": "single-tool-64MiB",
+ "sizeMiB": 64,
+ "shape": "single-tool",
+ "fileBytes": 67118319,
+ "trial": 1,
+ "mode": "baseline",
+ "durationMs": 148.72125,
+ "cpuUs": 159386,
+ "before": {
+ "rss": 57917440,
+ "heapTotal": 10633216,
+ "heapUsed": 5011816,
+ "external": 3553963,
+ "arrayBuffers": 82162
+ },
+ "after": {
+ "rss": 367443968,
+ "heapTotal": 323829760,
+ "heapUsed": 268687880,
+ "external": 3325643,
+ "arrayBuffers": 1130754
+ },
+ "maxRssKiB": 358832,
+ "outputSha256": "51f3cd84a14896c88222c8cbb65478a655d57cd657bdae6230ffb68ab372ad4f",
+ "outputBytes": 9253
+ },
+ {
+ "name": "single-tool-64MiB",
+ "sizeMiB": 64,
+ "shape": "single-tool",
+ "fileBytes": 67118319,
+ "trial": 2,
+ "mode": "baseline",
+ "durationMs": 153.38987500000002,
+ "cpuUs": 165536,
+ "before": {
+ "rss": 57229312,
+ "heapTotal": 10895360,
+ "heapUsed": 5011816,
+ "external": 3703094,
+ "arrayBuffers": 82162
+ },
+ "after": {
+ "rss": 372178944,
+ "heapTotal": 324354048,
+ "heapUsed": 269109216,
+ "external": 7463866,
+ "arrayBuffers": 672002
+ },
+ "maxRssKiB": 363456,
+ "outputSha256": "51f3cd84a14896c88222c8cbb65478a655d57cd657bdae6230ffb68ab372ad4f",
+ "outputBytes": 9253
+ },
+ {
+ "name": "single-tool-64MiB",
+ "sizeMiB": 64,
+ "shape": "single-tool",
+ "fileBytes": 67118319,
+ "trial": 2,
+ "mode": "candidate",
+ "durationMs": 111.26875,
+ "cpuUs": 116643,
+ "before": {
+ "rss": 54525952,
+ "heapTotal": 9584640,
+ "heapUsed": 4774920,
+ "external": 2416006,
+ "arrayBuffers": 16619
+ },
+ "after": {
+ "rss": 324599808,
+ "heapTotal": 143835136,
+ "heapUsed": 139245256,
+ "external": 136439238,
+ "arrayBuffers": 134244496
+ },
+ "maxRssKiB": 316992,
+ "outputSha256": "51f3cd84a14896c88222c8cbb65478a655d57cd657bdae6230ffb68ab372ad4f",
+ "outputBytes": 9253
+ }
+ ],
+ "summary": [
+ {
+ "name": "short-latest-0MiB",
+ "metric": "durationMs",
+ "baseline": 0.30733299999999986,
+ "candidate": 0.20204100000000125,
+ "reductionPercent": 34.2599070064063
+ },
+ {
+ "name": "short-latest-0MiB",
+ "metric": "cpuUs",
+ "baseline": 1063,
+ "candidate": 884,
+ "reductionPercent": 16.839134524929445
+ },
+ {
+ "name": "short-latest-0MiB",
+ "metric": "maxRssKiB",
+ "baseline": 56368,
+ "candidate": 53296,
+ "reductionPercent": 5.44990065285268
+ },
+ {
+ "name": "short-latest-1MiB",
+ "metric": "durationMs",
+ "baseline": 2.507165999999998,
+ "candidate": 0.23929200000000606,
+ "reductionPercent": 90.45567784502478
+ },
+ {
+ "name": "short-latest-1MiB",
+ "metric": "cpuUs",
+ "baseline": 3364,
+ "candidate": 922,
+ "reductionPercent": 72.59215219976218
+ },
+ {
+ "name": "short-latest-1MiB",
+ "metric": "maxRssKiB",
+ "baseline": 59376,
+ "candidate": 53344,
+ "reductionPercent": 10.15898679601186
+ },
+ {
+ "name": "short-latest-64MiB",
+ "metric": "durationMs",
+ "baseline": 125.65562499999999,
+ "candidate": 0.24570800000000048,
+ "reductionPercent": 99.80445921143601
+ },
+ {
+ "name": "short-latest-64MiB",
+ "metric": "cpuUs",
+ "baseline": 140340,
+ "candidate": 926,
+ "reductionPercent": 99.34017386347442
+ },
+ {
+ "name": "short-latest-64MiB",
+ "metric": "maxRssKiB",
+ "baseline": 201280,
+ "candidate": 53408,
+ "reductionPercent": 73.46581875993641
+ },
+ {
+ "name": "short-latest-512MiB",
+ "metric": "durationMs",
+ "baseline": 997.592833,
+ "candidate": 0.26687500000000597,
+ "reductionPercent": 99.97324810371808
+ },
+ {
+ "name": "short-latest-512MiB",
+ "metric": "cpuUs",
+ "baseline": 1065078,
+ "candidate": 973,
+ "reductionPercent": 99.90864518842751
+ },
+ {
+ "name": "short-latest-512MiB",
+ "metric": "maxRssKiB",
+ "baseline": 934576,
+ "candidate": 53328,
+ "reductionPercent": 94.29388300148945
+ },
+ {
+ "name": "long-latest-64MiB",
+ "metric": "durationMs",
+ "baseline": 142.12095899999997,
+ "candidate": 91.190333,
+ "reductionPercent": 35.83611196994525
+ },
+ {
+ "name": "long-latest-64MiB",
+ "metric": "cpuUs",
+ "baseline": 153180,
+ "candidate": 94218,
+ "reductionPercent": 38.491970231100666
+ },
+ {
+ "name": "long-latest-64MiB",
+ "metric": "maxRssKiB",
+ "baseline": 307904,
+ "candidate": 58640,
+ "reductionPercent": 80.95510288921221
+ },
+ {
+ "name": "no-boundary-64MiB",
+ "metric": "durationMs",
+ "baseline": 129.124666,
+ "candidate": 92.832458,
+ "reductionPercent": 28.106332526738143
+ },
+ {
+ "name": "no-boundary-64MiB",
+ "metric": "cpuUs",
+ "baseline": 144577,
+ "candidate": 96206,
+ "reductionPercent": 33.45691223361945
+ },
+ {
+ "name": "no-boundary-64MiB",
+ "metric": "maxRssKiB",
+ "baseline": 199248,
+ "candidate": 58224,
+ "reductionPercent": 70.77812575283065
+ },
+ {
+ "name": "single-tool-64MiB",
+ "metric": "durationMs",
+ "baseline": 148.72125,
+ "candidate": 105.097792,
+ "reductionPercent": 29.33236373416711
+ },
+ {
+ "name": "single-tool-64MiB",
+ "metric": "cpuUs",
+ "baseline": 159386,
+ "candidate": 110522,
+ "reductionPercent": 30.657648726989827
+ },
+ {
+ "name": "single-tool-64MiB",
+ "metric": "maxRssKiB",
+ "baseline": 359024,
+ "candidate": 317040,
+ "reductionPercent": 11.69392575426712
+ }
+ ],
+ "baselineCommit": "5a0951b1c996b47ce1e819aa40429862d3581756",
+ "limitations": [
+ "Synthetic component benchmark, not whole-app energy or retained daemon memory.",
+ "Peak RSS includes worker startup and warmup; explicit GC only in disposable benchmark children before timing.",
+ "A single huge JSONL record still has to be decoded and parsed; it is not truncated.",
+ "Live daemon heap bursts were observed, but their causal attribution to recap reads remains unproven."
+ ],
+ "prototypeControl": {
+ "description": "Initial boundary-only prototype had a roughly 25% elapsed-time regression on a 64 MiB single-turn/no-boundary control. Final code uses native delimiter search and skips irrelevant records immediately; the checked-in benchmark includes both controls.",
+ "shipped": false
+ }
+}
diff --git a/docs/performance/2026-10-02-codex-recap-tail.md b/docs/performance/2026-10-02-codex-recap-tail.md
new file mode 100644
index 000000000..a7f5b678d
--- /dev/null
+++ b/docs/performance/2026-10-02-codex-recap-tail.md
@@ -0,0 +1,80 @@
+# Codex recap history reads — October 2, 2026
+
+Every Codex recap previously read the entire rollout into an array of strings and
+parsed it, even though only the latest turn contributes to the result. Long-lived
+sessions can accumulate hundreds of megabytes of old tool receipts. Repeating
+that work on completion causes avoidable I/O, parsing, allocations and collection.
+
+The recap now reads backward in 64 KiB chunks and stops at the latest nonempty
+user message or injected goal objective. It discards irrelevant records while
+scanning and sends the selected prompt/answer records, in chronological order,
+to the unchanged final-answer parser. Both Codex message vocabularies, phase
+handling, multiple final messages and unfinished goals retain their semantics.
+History pagination, conversation storage, other engines and session lifecycle
+are unchanged. No transcript is modified.
+
+The reader captures the initial file length, excludes later appends, assembles
+whole records before decoding UTF-8, and supports LF, CRLF and bare CR. A missing
+boundary scans to the beginning. Read failures return no recap; the configured
+reader remains authoritative, so live commentary cannot become a stale answer.
+
+## Measurements
+
+[Raw results](2026-10-02-codex-recap-tail.json) compare the former full-history
+reader with the candidate using the same final-answer parser, minified bundle,
+macOS ARM64 and managed Node 22.23.2. Each scenario has three paired trials in
+alternating order, using fresh child processes and real synthetic files. All
+42 output hashes match the expected complete prompt and final answer.
+
+| History shape | Median elapsed, before → after | Peak worker RSS, before → after |
+| --- | ---: | ---: |
+| Short latest turn, no older tool history | 0.307 → 0.202 ms | 55.0 → 52.0 MiB |
+| Short latest turn, 1 MiB older tool history | 2.507 → 0.239 ms | 58.0 → 52.1 MiB |
+| Short latest turn, 64 MiB older tool history | 125.656 → 0.246 ms | 196.6 → 52.2 MiB |
+| Short latest turn, 512 MiB older tool history | 997.593 → 0.267 ms | 912.7 → 52.1 MiB |
+| One latest turn containing 64 MiB of tool records | 142.121 → 91.190 ms | 300.7 → 57.3 MiB |
+| 64 MiB of tool records without a recognized prompt | 129.125 → 92.832 ms | 194.6 → 56.9 MiB |
+| One 64 MiB tool record in the latest turn | 148.721 → 105.098 ms | 350.6 → 309.6 MiB |
+
+The 512 MiB history case reduces elapsed time by **99.97%**, process CPU by
+**99.91%**, and peak worker RSS by **94.29%**. The latest-turn and no-boundary
+controls improve elapsed time by **35.84%** and **28.11%** respectively. An initial
+prototype was about 25% slower on those controls; the final code uses native
+delimiter searches and discards irrelevant records immediately instead of keeping
+and parsing them twice.
+
+Peak RSS includes process startup and warmup. Explicit GC runs only in disposable
+benchmark children before timing. Submillisecond measurements include file-cache,
+scheduling and runtime noise. These are component measurements, **not** retained
+daemon memory, whole-app energy savings or removal from macOS's energy list.
+A live daemon heap burst motivated investigation, but its causal attribution to
+this recap path remains unproven. A single huge JSONL record still requires memory
+to decode and parse; the reader does not truncate it to manufacture a lower result.
+
+Reproduce from the repository root with CLI dependencies installed:
+
+```sh
+node cli/scripts/benchmark-codex-recap.mjs /tmp/codex-recap-comparison-new
+```
+
+The output directory must be new. Workers have 60-second deadlines, use private
+fixture directories, and remove their large transcript fixtures. No app, daemon,
+engine, shared server or tmux session is restarted or changed.
+
+## Validation and delivery
+
+Validation covers real files, long Unicode records, separator/chunk boundaries,
+append/truncate handling, missing files, malformed records, goal continuations,
+phase rules, empty prompts and exact parity with the existing full-history parser.
+Integration cases drive the Codex normalizer and Commander through notifications
+and persisted recaps, including suppression of stale answers for unfinished goals.
+They use local summarization and do not start a live Codex process or contact a model.
+
+Typecheck and affected tests run locally. The full CLI CI scope, including its
+OS/Node matrix and release-bundle checks, is required before merge. Final counts,
+source identity, validation receipt, CI link and merge time are recorded on the PR.
+No desktop rendering code is changed; whole-app battery behavior remains unverified.
+
+The exact original request time is unavailable. Final benchmark finished at
+18:26:40 UTC; implementation, validation and merge timestamps are tracked separately
+in the PR. Publication is excluded under the user's weekend release hold.
diff --git a/docs/performance/2026-10-02-session-metadata-reads.json b/docs/performance/2026-10-02-session-metadata-reads.json
new file mode 100644
index 000000000..f4b73beff
--- /dev/null
+++ b/docs/performance/2026-10-02-session-metadata-reads.json
@@ -0,0 +1,937 @@
+{
+ "base": "4e4f8af23a0f294f4594fcbc0d176aceb4443bb8",
+ "baselineSourceSha256": "d8e219c7ce55d765c11ef2dd2ab4d4feb7c9e0fb737c7b847824502cf33cea0b",
+ "candidateSourceSha256": "08393985ae5ee5507b8496be90cd69d86bc8a076149a5b011543651051819f02",
+ "dependencySha256": "5c69dffb1423173dfab75c0aa493b5c601784ff3efd16b9bfbb41ef9ad1c4d2b",
+ "finishedAt": "2026-10-02T20:16:35.276Z",
+ "node": "v22.23.2",
+ "platform": "darwin",
+ "arch": "arm64",
+ "maxStringLength": 536870888,
+ "scope": "One public findLiveSession directory scan of a synthetic Claude transcript, fresh minified workers. Peak RSS includes startup/warmup; explicit GC is only before timing in disposable children. No whole-app energy claim.",
+ "rows": [
+ {
+ "sizeMiB": 0,
+ "fileBytes": 45,
+ "trial": 0,
+ "mode": "baseline",
+ "durationMs": 0.3135420000000053,
+ "cpuUs": 1389,
+ "before": {
+ "rss": 69550080,
+ "heapTotal": 18759680,
+ "heapUsed": 8995752,
+ "external": 2375369,
+ "arrayBuffers": 24815
+ },
+ "after": {
+ "rss": 69566464,
+ "heapTotal": 18759680,
+ "heapUsed": 9036656,
+ "external": 2338439,
+ "arrayBuffers": 26076
+ },
+ "maxRssKiB": 67936,
+ "identity": {
+ "sessionId": "session-id",
+ "transcript": "session-id.jsonl"
+ }
+ },
+ {
+ "sizeMiB": 0,
+ "fileBytes": 45,
+ "trial": 0,
+ "mode": "candidate",
+ "durationMs": 0.30058300000000315,
+ "cpuUs": 1431,
+ "before": {
+ "rss": 69386240,
+ "heapTotal": 19283968,
+ "heapUsed": 9001712,
+ "external": 2370389,
+ "arrayBuffers": 24815
+ },
+ "after": {
+ "rss": 69402624,
+ "heapTotal": 19283968,
+ "heapUsed": 9045384,
+ "external": 2338439,
+ "arrayBuffers": 26076
+ },
+ "maxRssKiB": 67776,
+ "identity": {
+ "sessionId": "session-id",
+ "transcript": "session-id.jsonl"
+ }
+ },
+ {
+ "sizeMiB": 0,
+ "fileBytes": 45,
+ "trial": 1,
+ "mode": "candidate",
+ "durationMs": 0.3286250000000024,
+ "cpuUs": 1353,
+ "before": {
+ "rss": 69140480,
+ "heapTotal": 19283968,
+ "heapUsed": 9001544,
+ "external": 2373279,
+ "arrayBuffers": 24815
+ },
+ "after": {
+ "rss": 69140480,
+ "heapTotal": 19283968,
+ "heapUsed": 9045192,
+ "external": 2338439,
+ "arrayBuffers": 26076
+ },
+ "maxRssKiB": 67520,
+ "identity": {
+ "sessionId": "session-id",
+ "transcript": "session-id.jsonl"
+ }
+ },
+ {
+ "sizeMiB": 0,
+ "fileBytes": 45,
+ "trial": 1,
+ "mode": "baseline",
+ "durationMs": 0.26950000000000074,
+ "cpuUs": 1369,
+ "before": {
+ "rss": 69189632,
+ "heapTotal": 18759680,
+ "heapUsed": 8996088,
+ "external": 2370389,
+ "arrayBuffers": 24815
+ },
+ "after": {
+ "rss": 69206016,
+ "heapTotal": 18759680,
+ "heapUsed": 9036992,
+ "external": 2338439,
+ "arrayBuffers": 26076
+ },
+ "maxRssKiB": 67584,
+ "identity": {
+ "sessionId": "session-id",
+ "transcript": "session-id.jsonl"
+ }
+ },
+ {
+ "sizeMiB": 0,
+ "fileBytes": 45,
+ "trial": 2,
+ "mode": "baseline",
+ "durationMs": 0.2601659999999981,
+ "cpuUs": 1358,
+ "before": {
+ "rss": 69386240,
+ "heapTotal": 18759680,
+ "heapUsed": 8995712,
+ "external": 2368299,
+ "arrayBuffers": 24815
+ },
+ "after": {
+ "rss": 69386240,
+ "heapTotal": 18759680,
+ "heapUsed": 9036616,
+ "external": 2338439,
+ "arrayBuffers": 26076
+ },
+ "maxRssKiB": 67760,
+ "identity": {
+ "sessionId": "session-id",
+ "transcript": "session-id.jsonl"
+ }
+ },
+ {
+ "sizeMiB": 0,
+ "fileBytes": 45,
+ "trial": 2,
+ "mode": "candidate",
+ "durationMs": 0.34312500000000057,
+ "cpuUs": 1496,
+ "before": {
+ "rss": 69451776,
+ "heapTotal": 19021824,
+ "heapUsed": 9001592,
+ "external": 2370589,
+ "arrayBuffers": 24815
+ },
+ "after": {
+ "rss": 69468160,
+ "heapTotal": 19021824,
+ "heapUsed": 9045264,
+ "external": 2338439,
+ "arrayBuffers": 26076
+ },
+ "maxRssKiB": 67840,
+ "identity": {
+ "sessionId": "session-id",
+ "transcript": "session-id.jsonl"
+ }
+ },
+ {
+ "sizeMiB": 1,
+ "fileBytes": 1049181,
+ "trial": 0,
+ "mode": "baseline",
+ "durationMs": 0.8055000000000021,
+ "cpuUs": 1922,
+ "before": {
+ "rss": 69353472,
+ "heapTotal": 19021824,
+ "heapUsed": 8996088,
+ "external": 2371234,
+ "arrayBuffers": 24815
+ },
+ "after": {
+ "rss": 72040448,
+ "heapTotal": 21168128,
+ "heapUsed": 11138464,
+ "external": 2863089,
+ "arrayBuffers": 550726
+ },
+ "maxRssKiB": 70352,
+ "identity": {
+ "sessionId": "session-id",
+ "transcript": "session-id.jsonl"
+ }
+ },
+ {
+ "sizeMiB": 1,
+ "fileBytes": 1049181,
+ "trial": 0,
+ "mode": "candidate",
+ "durationMs": 0.5145840000000064,
+ "cpuUs": 1581,
+ "before": {
+ "rss": 69402624,
+ "heapTotal": 18759680,
+ "heapUsed": 9003992,
+ "external": 2373924,
+ "arrayBuffers": 24815
+ },
+ "after": {
+ "rss": 70483968,
+ "heapTotal": 19824640,
+ "heapUsed": 10096400,
+ "external": 3386970,
+ "arrayBuffers": 1074607
+ },
+ "maxRssKiB": 68832,
+ "identity": {
+ "sessionId": "session-id",
+ "transcript": "session-id.jsonl"
+ }
+ },
+ {
+ "sizeMiB": 1,
+ "fileBytes": 1049181,
+ "trial": 1,
+ "mode": "candidate",
+ "durationMs": 0.5242080000000016,
+ "cpuUs": 1464,
+ "before": {
+ "rss": 69140480,
+ "heapTotal": 18759680,
+ "heapUsed": 9001752,
+ "external": 2369144,
+ "arrayBuffers": 24815
+ },
+ "after": {
+ "rss": 70221824,
+ "heapTotal": 19824640,
+ "heapUsed": 10094160,
+ "external": 3386970,
+ "arrayBuffers": 1074607
+ },
+ "maxRssKiB": 68576,
+ "identity": {
+ "sessionId": "session-id",
+ "transcript": "session-id.jsonl"
+ }
+ },
+ {
+ "sizeMiB": 1,
+ "fileBytes": 1049181,
+ "trial": 1,
+ "mode": "baseline",
+ "durationMs": 0.6777499999999961,
+ "cpuUs": 1857,
+ "before": {
+ "rss": 69189632,
+ "heapTotal": 18759680,
+ "heapUsed": 8996112,
+ "external": 2372879,
+ "arrayBuffers": 24815
+ },
+ "after": {
+ "rss": 71385088,
+ "heapTotal": 20905984,
+ "heapUsed": 11138488,
+ "external": 2863089,
+ "arrayBuffers": 550726
+ },
+ "maxRssKiB": 69712,
+ "identity": {
+ "sessionId": "session-id",
+ "transcript": "session-id.jsonl"
+ }
+ },
+ {
+ "sizeMiB": 1,
+ "fileBytes": 1049181,
+ "trial": 2,
+ "mode": "baseline",
+ "durationMs": 0.6039579999999987,
+ "cpuUs": 1667,
+ "before": {
+ "rss": 69386240,
+ "heapTotal": 18759680,
+ "heapUsed": 8995760,
+ "external": 2370789,
+ "arrayBuffers": 24815
+ },
+ "after": {
+ "rss": 71548928,
+ "heapTotal": 20905984,
+ "heapUsed": 11138136,
+ "external": 2863089,
+ "arrayBuffers": 550726
+ },
+ "maxRssKiB": 69872,
+ "identity": {
+ "sessionId": "session-id",
+ "transcript": "session-id.jsonl"
+ }
+ },
+ {
+ "sizeMiB": 1,
+ "fileBytes": 1049181,
+ "trial": 2,
+ "mode": "candidate",
+ "durationMs": 0.5035840000000036,
+ "cpuUs": 1520,
+ "before": {
+ "rss": 69337088,
+ "heapTotal": 19021824,
+ "heapUsed": 9001792,
+ "external": 2370789,
+ "arrayBuffers": 24815
+ },
+ "after": {
+ "rss": 70418432,
+ "heapTotal": 20086784,
+ "heapUsed": 10094200,
+ "external": 3386970,
+ "arrayBuffers": 1074607
+ },
+ "maxRssKiB": 68768,
+ "identity": {
+ "sessionId": "session-id",
+ "transcript": "session-id.jsonl"
+ }
+ },
+ {
+ "sizeMiB": 64,
+ "fileBytes": 67144749,
+ "trial": 0,
+ "mode": "baseline",
+ "durationMs": 23.107457999999994,
+ "cpuUs": 31749,
+ "before": {
+ "rss": 69025792,
+ "heapTotal": 19546112,
+ "heapUsed": 8997240,
+ "external": 2371234,
+ "arrayBuffers": 24815
+ },
+ "after": {
+ "rss": 207388672,
+ "heapTotal": 180289536,
+ "heapUsed": 143297504,
+ "external": 2866233,
+ "arrayBuffers": 551270
+ },
+ "maxRssKiB": 202528,
+ "identity": {
+ "sessionId": "session-id",
+ "transcript": "session-id.jsonl"
+ }
+ },
+ {
+ "sizeMiB": 64,
+ "fileBytes": 67144749,
+ "trial": 0,
+ "mode": "candidate",
+ "durationMs": 0.5281659999999988,
+ "cpuUs": 1639,
+ "before": {
+ "rss": 69124096,
+ "heapTotal": 18759680,
+ "heapUsed": 9001392,
+ "external": 2371634,
+ "arrayBuffers": 24815
+ },
+ "after": {
+ "rss": 70238208,
+ "heapTotal": 19824640,
+ "heapUsed": 10093800,
+ "external": 3386970,
+ "arrayBuffers": 1074607
+ },
+ "maxRssKiB": 68592,
+ "identity": {
+ "sessionId": "session-id",
+ "transcript": "session-id.jsonl"
+ }
+ },
+ {
+ "sizeMiB": 64,
+ "fileBytes": 67144749,
+ "trial": 1,
+ "mode": "candidate",
+ "durationMs": 0.539749999999998,
+ "cpuUs": 1703,
+ "before": {
+ "rss": 69173248,
+ "heapTotal": 19021824,
+ "heapUsed": 9001592,
+ "external": 2371834,
+ "arrayBuffers": 24815
+ },
+ "after": {
+ "rss": 71319552,
+ "heapTotal": 20086784,
+ "heapUsed": 10094000,
+ "external": 3386970,
+ "arrayBuffers": 1074607
+ },
+ "maxRssKiB": 69648,
+ "identity": {
+ "sessionId": "session-id",
+ "transcript": "session-id.jsonl"
+ }
+ },
+ {
+ "sizeMiB": 64,
+ "fileBytes": 67144749,
+ "trial": 1,
+ "mode": "baseline",
+ "durationMs": 22.373084,
+ "cpuUs": 30713,
+ "before": {
+ "rss": 69304320,
+ "heapTotal": 19021824,
+ "heapUsed": 8996016,
+ "external": 2373924,
+ "arrayBuffers": 24815
+ },
+ "after": {
+ "rss": 207962112,
+ "heapTotal": 180551680,
+ "heapUsed": 143296656,
+ "external": 2866233,
+ "arrayBuffers": 551470
+ },
+ "maxRssKiB": 203088,
+ "identity": {
+ "sessionId": "session-id",
+ "transcript": "session-id.jsonl"
+ }
+ },
+ {
+ "sizeMiB": 64,
+ "fileBytes": 67144749,
+ "trial": 2,
+ "mode": "baseline",
+ "durationMs": 21.617958,
+ "cpuUs": 29692,
+ "before": {
+ "rss": 69337088,
+ "heapTotal": 18759680,
+ "heapUsed": 8995824,
+ "external": 2370389,
+ "arrayBuffers": 24815
+ },
+ "after": {
+ "rss": 207519744,
+ "heapTotal": 180289536,
+ "heapUsed": 143296400,
+ "external": 2866233,
+ "arrayBuffers": 551270
+ },
+ "maxRssKiB": 202656,
+ "identity": {
+ "sessionId": "session-id",
+ "transcript": "session-id.jsonl"
+ }
+ },
+ {
+ "sizeMiB": 64,
+ "fileBytes": 67144749,
+ "trial": 2,
+ "mode": "candidate",
+ "durationMs": 0.5412910000000011,
+ "cpuUs": 1687,
+ "before": {
+ "rss": 69124096,
+ "heapTotal": 19021824,
+ "heapUsed": 9003264,
+ "external": 2374569,
+ "arrayBuffers": 24815
+ },
+ "after": {
+ "rss": 70221824,
+ "heapTotal": 20086784,
+ "heapUsed": 10095672,
+ "external": 3386970,
+ "arrayBuffers": 1074607
+ },
+ "maxRssKiB": 68576,
+ "identity": {
+ "sessionId": "session-id",
+ "transcript": "session-id.jsonl"
+ }
+ },
+ {
+ "sizeMiB": 256,
+ "fileBytes": 268578861,
+ "trial": 0,
+ "mode": "baseline",
+ "durationMs": 79.715084,
+ "cpuUs": 95639,
+ "before": {
+ "rss": 69435392,
+ "heapTotal": 19021824,
+ "heapUsed": 8996112,
+ "external": 2374124,
+ "arrayBuffers": 24815
+ },
+ "after": {
+ "rss": 616972288,
+ "heapTotal": 589774848,
+ "heapUsed": 546183056,
+ "external": 2866433,
+ "arrayBuffers": 551270
+ },
+ "maxRssKiB": 602512,
+ "identity": {
+ "sessionId": "session-id",
+ "transcript": "session-id.jsonl"
+ }
+ },
+ {
+ "sizeMiB": 256,
+ "fileBytes": 268578861,
+ "trial": 0,
+ "mode": "candidate",
+ "durationMs": 0.5679589999999948,
+ "cpuUs": 1721,
+ "before": {
+ "rss": 69304320,
+ "heapTotal": 19021824,
+ "heapUsed": 9001544,
+ "external": 2372034,
+ "arrayBuffers": 24815
+ },
+ "after": {
+ "rss": 70402048,
+ "heapTotal": 20086784,
+ "heapUsed": 10093952,
+ "external": 3386970,
+ "arrayBuffers": 1074607
+ },
+ "maxRssKiB": 68752,
+ "identity": {
+ "sessionId": "session-id",
+ "transcript": "session-id.jsonl"
+ }
+ },
+ {
+ "sizeMiB": 256,
+ "fileBytes": 268578861,
+ "trial": 1,
+ "mode": "candidate",
+ "durationMs": 0.5364579999999961,
+ "cpuUs": 1752,
+ "before": {
+ "rss": 69287936,
+ "heapTotal": 19283968,
+ "heapUsed": 9001592,
+ "external": 2374324,
+ "arrayBuffers": 24815
+ },
+ "after": {
+ "rss": 71417856,
+ "heapTotal": 20348928,
+ "heapUsed": 10093976,
+ "external": 3386970,
+ "arrayBuffers": 1074607
+ },
+ "maxRssKiB": 69744,
+ "identity": {
+ "sessionId": "session-id",
+ "transcript": "session-id.jsonl"
+ }
+ },
+ {
+ "sizeMiB": 256,
+ "fileBytes": 268578861,
+ "trial": 1,
+ "mode": "baseline",
+ "durationMs": 81.40379100000001,
+ "cpuUs": 97448,
+ "before": {
+ "rss": 69238784,
+ "heapTotal": 19283968,
+ "heapUsed": 8999800,
+ "external": 2371834,
+ "arrayBuffers": 24815
+ },
+ "after": {
+ "rss": 617349120,
+ "heapTotal": 590036992,
+ "heapUsed": 546187136,
+ "external": 2866433,
+ "arrayBuffers": 551470
+ },
+ "maxRssKiB": 602880,
+ "identity": {
+ "sessionId": "session-id",
+ "transcript": "session-id.jsonl"
+ }
+ },
+ {
+ "sizeMiB": 256,
+ "fileBytes": 268578861,
+ "trial": 2,
+ "mode": "baseline",
+ "durationMs": 82.36999999999999,
+ "cpuUs": 97428,
+ "before": {
+ "rss": 69238784,
+ "heapTotal": 19021824,
+ "heapUsed": 8995776,
+ "external": 2367699,
+ "arrayBuffers": 24815
+ },
+ "after": {
+ "rss": 616693760,
+ "heapTotal": 589774848,
+ "heapUsed": 546183312,
+ "external": 2868033,
+ "arrayBuffers": 551470
+ },
+ "maxRssKiB": 602240,
+ "identity": {
+ "sessionId": "session-id",
+ "transcript": "session-id.jsonl"
+ }
+ },
+ {
+ "sizeMiB": 256,
+ "fileBytes": 268578861,
+ "trial": 2,
+ "mode": "candidate",
+ "durationMs": 0.5414580000000058,
+ "cpuUs": 1569,
+ "before": {
+ "rss": 69107712,
+ "heapTotal": 18497536,
+ "heapUsed": 9001864,
+ "external": 2371834,
+ "arrayBuffers": 24815
+ },
+ "after": {
+ "rss": 70205440,
+ "heapTotal": 19562496,
+ "heapUsed": 10094272,
+ "external": 3386970,
+ "arrayBuffers": 1074607
+ },
+ "maxRssKiB": 68560,
+ "identity": {
+ "sessionId": "session-id",
+ "transcript": "session-id.jsonl"
+ }
+ },
+ {
+ "sizeMiB": 513,
+ "fileBytes": 538206813,
+ "trial": 0,
+ "mode": "baseline",
+ "durationMs": 116.986208,
+ "cpuUs": 134058,
+ "before": {
+ "rss": 69206016,
+ "heapTotal": 19283968,
+ "heapUsed": 8996864,
+ "external": 2374524,
+ "arrayBuffers": 24815
+ },
+ "after": {
+ "rss": 625049600,
+ "heapTotal": 597835776,
+ "heapUsed": 545948752,
+ "external": 2869433,
+ "arrayBuffers": 557070
+ },
+ "maxRssKiB": 610400,
+ "identity": null
+ },
+ {
+ "sizeMiB": 513,
+ "fileBytes": 538206813,
+ "trial": 0,
+ "mode": "candidate",
+ "durationMs": 0.5499590000000012,
+ "cpuUs": 1685,
+ "before": {
+ "rss": 69468160,
+ "heapTotal": 19283968,
+ "heapUsed": 9004120,
+ "external": 2375369,
+ "arrayBuffers": 24815
+ },
+ "after": {
+ "rss": 71401472,
+ "heapTotal": 20348928,
+ "heapUsed": 10096528,
+ "external": 3386970,
+ "arrayBuffers": 1074607
+ },
+ "maxRssKiB": 69728,
+ "identity": {
+ "sessionId": "session-id",
+ "transcript": "session-id.jsonl"
+ }
+ },
+ {
+ "sizeMiB": 513,
+ "fileBytes": 538206813,
+ "trial": 1,
+ "mode": "candidate",
+ "durationMs": 0.5763749999999987,
+ "cpuUs": 1587,
+ "before": {
+ "rss": 69419008,
+ "heapTotal": 18759680,
+ "heapUsed": 9001448,
+ "external": 2374324,
+ "arrayBuffers": 24815
+ },
+ "after": {
+ "rss": 71368704,
+ "heapTotal": 19824640,
+ "heapUsed": 10093856,
+ "external": 3386970,
+ "arrayBuffers": 1074607
+ },
+ "maxRssKiB": 69696,
+ "identity": {
+ "sessionId": "session-id",
+ "transcript": "session-id.jsonl"
+ }
+ },
+ {
+ "sizeMiB": 513,
+ "fileBytes": 538206813,
+ "trial": 1,
+ "mode": "baseline",
+ "durationMs": 120.73645899999998,
+ "cpuUs": 138632,
+ "before": {
+ "rss": 69451776,
+ "heapTotal": 19021824,
+ "heapUsed": 8995736,
+ "external": 2372034,
+ "arrayBuffers": 24815
+ },
+ "after": {
+ "rss": 625754112,
+ "heapTotal": 597835776,
+ "heapUsed": 545948976,
+ "external": 2869433,
+ "arrayBuffers": 557070
+ },
+ "maxRssKiB": 611088,
+ "identity": null
+ },
+ {
+ "sizeMiB": 513,
+ "fileBytes": 538206813,
+ "trial": 2,
+ "mode": "baseline",
+ "durationMs": 118.682,
+ "cpuUs": 136007,
+ "before": {
+ "rss": 69271552,
+ "heapTotal": 18759680,
+ "heapUsed": 8995752,
+ "external": 2369544,
+ "arrayBuffers": 24815
+ },
+ "after": {
+ "rss": 625049600,
+ "heapTotal": 597835776,
+ "heapUsed": 545925304,
+ "external": 2863233,
+ "arrayBuffers": 550870
+ },
+ "maxRssKiB": 610400,
+ "identity": null
+ },
+ {
+ "sizeMiB": 513,
+ "fileBytes": 538206813,
+ "trial": 2,
+ "mode": "candidate",
+ "durationMs": 0.5542500000000032,
+ "cpuUs": 1660,
+ "before": {
+ "rss": 69304320,
+ "heapTotal": 18759680,
+ "heapUsed": 9002688,
+ "external": 2369789,
+ "arrayBuffers": 24815
+ },
+ "after": {
+ "rss": 70402048,
+ "heapTotal": 19824640,
+ "heapUsed": 10095096,
+ "external": 3386970,
+ "arrayBuffers": 1074607
+ },
+ "maxRssKiB": 68752,
+ "identity": {
+ "sessionId": "session-id",
+ "transcript": "session-id.jsonl"
+ }
+ }
+ ],
+ "summary": [
+ {
+ "sizeMiB": 0,
+ "metric": "durationMs",
+ "baseline": 0.26950000000000074,
+ "candidate": 0.3286250000000024,
+ "reductionPercent": -21.93877551020462
+ },
+ {
+ "sizeMiB": 0,
+ "metric": "cpuUs",
+ "baseline": 1369,
+ "candidate": 1431,
+ "reductionPercent": -4.528853177501824
+ },
+ {
+ "sizeMiB": 0,
+ "metric": "maxRssKiB",
+ "baseline": 67760,
+ "candidate": 67776,
+ "reductionPercent": -0.0236127508854711
+ },
+ {
+ "sizeMiB": 1,
+ "metric": "durationMs",
+ "baseline": 0.6777499999999961,
+ "candidate": 0.5145840000000064,
+ "reductionPercent": 24.074658797490322
+ },
+ {
+ "sizeMiB": 1,
+ "metric": "cpuUs",
+ "baseline": 1857,
+ "candidate": 1520,
+ "reductionPercent": 18.147549811523966
+ },
+ {
+ "sizeMiB": 1,
+ "metric": "maxRssKiB",
+ "baseline": 69872,
+ "candidate": 68768,
+ "reductionPercent": 1.5800320586214833
+ },
+ {
+ "sizeMiB": 64,
+ "metric": "durationMs",
+ "baseline": 22.373084,
+ "candidate": 0.539749999999998,
+ "reductionPercent": 97.5875029119812
+ },
+ {
+ "sizeMiB": 64,
+ "metric": "cpuUs",
+ "baseline": 30713,
+ "candidate": 1687,
+ "reductionPercent": 94.50721192980171
+ },
+ {
+ "sizeMiB": 64,
+ "metric": "maxRssKiB",
+ "baseline": 202656,
+ "candidate": 68592,
+ "reductionPercent": 66.15348176219801
+ },
+ {
+ "sizeMiB": 256,
+ "metric": "durationMs",
+ "baseline": 81.40379100000001,
+ "candidate": 0.5414580000000058,
+ "reductionPercent": 99.33484915954344
+ },
+ {
+ "sizeMiB": 256,
+ "metric": "cpuUs",
+ "baseline": 97428,
+ "candidate": 1721,
+ "reductionPercent": 98.2335673523012
+ },
+ {
+ "sizeMiB": 256,
+ "metric": "maxRssKiB",
+ "baseline": 602512,
+ "candidate": 68752,
+ "reductionPercent": 88.58910693894893
+ },
+ {
+ "sizeMiB": 513,
+ "metric": "durationMs",
+ "baseline": 118.682,
+ "candidate": 0.5542500000000032,
+ "reductionPercent": 99.53299573650595
+ },
+ {
+ "sizeMiB": 513,
+ "metric": "cpuUs",
+ "baseline": 136007,
+ "candidate": 1660,
+ "reductionPercent": 98.7794745858669
+ },
+ {
+ "sizeMiB": 513,
+ "metric": "maxRssKiB",
+ "baseline": 610400,
+ "candidate": 69696,
+ "reductionPercent": 88.5819134993447
+ }
+ ],
+ "limitations": [
+ "Component scan benchmark, not whole-app energy or retained daemon memory.",
+ "The 513 MiB baseline returns null despite a valid header; its timing is a failed scan, not equivalent successful work.",
+ "Peak RSS includes worker startup/warmup; GC is explicit only before timing in disposable benchmark children.",
+ "Header-only elapsed time rose 59.1 microseconds (21.9%) and CPU 4.5%; no tiny-file improvement is claimed."
+ ],
+ "unicodeContinuationCorrection": {
+ "beforeProbe": "b1a87c9665537bd365e344518f540bf9577223ec",
+ "before": {
+ "ascii": true,
+ "bmp": false,
+ "emoji": false
+ },
+ "regressionTests": "sessionRepair.spec.ts parameterized ASCII/BMP/emoji continuation case, including small background-session rejection"
+ }
+}
diff --git a/docs/performance/2026-10-02-session-metadata-reads.md b/docs/performance/2026-10-02-session-metadata-reads.md
new file mode 100644
index 000000000..18336cc81
--- /dev/null
+++ b/docs/performance/2026-10-02-session-metadata-reads.md
@@ -0,0 +1,82 @@
+# Bounded session metadata reads — October 2, 2026
+
+Fallback discovery for Claude, Pi, Command Code and Amp used `readFile` on the
+entire transcript, then inspected only its first 256K JavaScript characters and
+20 lines. A long conversation therefore caused large allocations just to learn
+its directory. A sufficiently large file could also exceed V8's maximum string
+length and quietly return no matching session despite a valid opening header.
+
+Discovery now reuses the existing bounded header reader. Its 1 MiB byte cap is
+sufficient to preserve the old 256K UTF-16 character budget with any UTF-8 text,
+including a cutoff inside a surrogate pair. The 20-line limit, first declared
+directory, ambiguity rules, timestamps and session IDs are unchanged. The shared
+header helper now fills partial reads, stops at EOF and decodes only bytes read;
+its existing Claude-continuation caller retains its own 256 KiB limit.
+
+That caller also compared decoded character count against a byte limit. A real
+file probe found ASCII continuation headers worked while equally large BMP/emoji
+headers stranded the conversation. The helper now returns bytes, and each caller
+decodes them explicitly: continuation checks count bytes, while directory scanning
+keeps its existing character budget. Small background-only sessions remain rejected.
+
+## Measured result
+
+[Raw measurements](2026-10-02-session-metadata-reads.json) use the public
+`findLiveSession` path, one real synthetic transcript per scan, minified bundles,
+macOS ARM64 and Node 22.23.2. Three paired trials per size alternate order and run
+in fresh processes. The measurements used local commit `4e4f8af23a0f294f4594fcbc0d176aceb4443bb8`.
+Its `sessionRepair.ts` is byte-identical to published commit
+`5a0951b1c996b47ce1e819aa40429862d3581756`, used below for reproduction.
+
+| Transcript payload | Median elapsed, before → after | Peak worker RSS, before → after |
+| --- | ---: | ---: |
+| Header only | 0.270 → 0.329 ms | 66.17 → 66.19 MiB |
+| 1 MiB | 0.678 → 0.515 ms | 68.23 → 67.16 MiB |
+| 64 MiB | 22.373 → 0.540 ms | 197.91 → 66.98 MiB |
+| 256 MiB | 81.404 → 0.541 ms | 588.39 → 67.14 MiB |
+| 513 MiB | 118.682 → 0.554 ms | 596.09 → 68.06 MiB |
+
+For 256 MiB, elapsed time falls **99.33%**, CPU **98.23%**, and peak RSS **88.59%**.
+The header-only case is 59.1 microseconds slower (21.9%), with 4.5% higher measured
+CPU; no tiny-file speedup is claimed. Peak RSS includes process startup and warmup.
+Explicit GC runs only in disposable benchmark children before timing. These are
+component measurements, not whole-app energy savings or retained daemon memory.
+
+All 24 trials up to 256 MiB return the same session identity and transcript name.
+For 513 MiB, all three baseline trials return **null** while all three candidate
+trials find the valid session. That row compares a failed scan with a successful
+one, rather than equivalent useful work. The fixture exceeds this Node runtime's
+536,870,888-character maximum string length.
+
+Reproduce with CLI dependencies installed and a new output directory:
+
+```sh
+node cli/scripts/benchmark-session-metadata.mjs 5a0951b1c996b47ce1e819aa40429862d3581756 /tmp/session-metadata-comparison-new
+```
+
+Workers have 60-second deadlines and private data, runtime and authentication
+directories. Their synthetic files are removed after each size; no live session
+store is used or changed.
+
+## Validation and delivery
+
+178 affected tests and typecheck passed. The tests cover all four engine layouts, the exact line and Unicode
+character boundaries, the first declared directory, files beyond the JS string
+limit, bounded actual reads, partial reads, early EOF, read errors and handle
+cleanup. ASCII/BMP/emoji continuation checks include rejection of small background-only
+sessions. Existing discovery ambiguity, restart and Claude-continuation tests
+remain in scope. Typecheck and final counts are recorded on the eventual PR.
+
+Five native checks passed using tmux 3.7c, Claude 2.1.287 and Pi 0.85.1 with
+private tmux sockets and disposable engine profiles: lifecycle, Claude/Pi process
+discovery and removal, literal input, and the restart capability-probe race.
+Auto-updating and nonessential traffic were disabled. Fourteen matrix rows were
+skipped: affected Command Code/Amp binaries are unavailable, and other engine
+rows were outside this change's scope. No model prompt or paid request was sent.
+
+The exact original user-request timestamp is unavailable. Initial local checks
+completed around 19:44:50 UTC. The Unicode correction passed its final affected
+checks at 20:13:33 UTC; the final benchmark timestamp is in the raw result. Source
+identity, CI and merge evidence are tracked separately in the PR. The full CLI CI
+scope is required before merge. Publication and app/daemon updates are excluded by
+the user's weekend hold.