fix(history): count compressed rollouts, read each file once, degrade an unreadable parent

Codex's local_thread_store_compression rewrites cold rollouts to
*.jsonl.zst, which the store scan skipped without a trace. Each one is now
counted in compressedFiles (complete: false), skipped only when its plain
.jsonl sibling exists, as Codex's own discovery does, and a lookup that
misses names the compressed file whose name carries the wanted id. A
Zstandard file given to --file, or sitting in the store under a .jsonl
name, is recognised by its magic number.

Each selected rollout is parsed once into every view later needed of it,
so a legacy copy's boundary proof reuses the parent's own read instead of
charging it to --scan-bytes a second time (and counting its malformed or
inherited records twice).

A parent read that fails for any reason other than a budget now leaves
the boundary unproven (cut at the last candidate, unverifiedPrefixes,
complete: false) instead of failing a child whose own file is intact. A
budget error still fails the read.

--max-bytes is validated before the first file is read, next to the
other budgets, and every budget flag accepts plain decimal integers only.
This commit is contained in:
Aamer Akhter committed 2026-10-25 09:08:54 -04:00
1 parent 44fa2d4757
commit 17b2edce22
9 files changed
+346 -56

No files matched your search

+18 -4
View File
@@ -27,8 +27,18 @@ import {
HISTORY_MAX_OUTPUT_BYTES,
HISTORY_MAX_SCAN_BYTES,
readLocalHistory,
validateOutputBytes,
} from './local-history.js';
/**
* A budget flag's value as a number. Only plain decimal digits count, so `0x10`,
* `1e3` and ` 5 ` are refused rather than read as 16, 1000 and 5; anything else
* becomes NaN, which the reader's range check rejects with the flag's name.
*/
function budgetFlag(value: string | boolean | undefined): number {
return typeof value === 'string' && /^\d+$/.test(value) ? Number(value) : NaN;
}
export function registerHistoryCommands(program: Command): Command {
const history = program
.command('history')
@@ -74,6 +84,10 @@ export function registerHistoryCommands(program: Command): Command {
if (options.json && options.format === 'text' && command.getOptionValueSource('format') === 'cli')
throw new Error('--json conflicts with --format text; pass one of them');
const format = options.format;
// Every flag is checked before the first file is read: --max-bytes would otherwise
// only be judged after the whole store had been scanned.
const maxBytes = budgetFlag(options.maxBytes);
validateOutputBytes(maxBytes);
const result = await readLocalHistory({
file: options.file as string | undefined,
sessionId: options.sessionId as string | undefined,
@@ -82,11 +96,11 @@ export function registerHistoryCommands(program: Command): Command {
topic: options.topic as string | undefined,
after: options.after as string | undefined,
before: options.before as string | undefined,
scanBytes: Number(options.scanBytes),
metadataBytes: Number(options.metadataBytes),
maxEntries: Number(options.maxEntries),
scanBytes: budgetFlag(options.scanBytes),
metadataBytes: budgetFlag(options.metadataBytes),
maxEntries: budgetFlag(options.maxEntries),
});
program.configureOutput().writeOut?.(`${formatLocalHistory(result, format, Number(options.maxBytes))}\n`);
program.configureOutput().writeOut?.(`${formatLocalHistory(result, format, maxBytes)}\n`);
} catch (error) {
program.error(error instanceof Error ? error.message : String(error), { exitCode: 1, code: 'history.read' });
}