Skip to content

refactor(core): codex decoder with explicit serializable state, cost leaves the decoder (phase 4) - #823

Merged
iamtoruk merged 1 commit into
feat/core-extractionfrom
phase4/codex-state
Jul 26, 2026
Merged

iamtoruk merged 1 commit into
feat/core-extractionfrom
phase4/codex-state

Conversation

@iamtoruk

Copy link
Copy Markdown
Member

Phase 4 of #809. Codex decode moves to packages/core/src/providers/codex with EXPLICIT plain-JSON state (every piece of implicit memory enumerated: cumulative/delta counters, fork cutoff + lineage, mid-turn accumulators, dedup keys). Signature invariant proven: two-pass decode with JSON-serialized state at EVERY split index deep-equals the cold pass, incl. mid-session and across forked-session boundaries; end-to-end CLI resume test writes the blob, appends, resumes from byteOffset+state. Bonus capability: codex now has incremental append parsing.

Cost leaves the decoder — both Phase-0 residual calculateCost sites retired (grep: zero call sites). CODEX_CACHE_VERSION 7→8, the one sanctioned bump: lossless (rollout files are durable), one-time re-derive == one normal cold run (~14s on a 4.2GB corpus).

Gates, independently re-verified in review: frozen-corpus parity (PRE self-consistent, then PRE≡POST at rel_tol 1e-9 for codex-only AND full payload, separate cache dirs, 51k calls/812 sessions); perf cold +1.4% / warm +0.4% (within ±5%); root suite green (the isolated 'failures' in review were a wrong-cwd invocation post-workspace-move — 5/5 green from packages/cli; residual full-suite timeouts are the documented tsx-spawn flake class); core 108 tests incl. codex smuggling cases; import-smoke covers the codex subpath; tsc clean.

Development note: the frozen-corpus parity gate caught a real bug mid-phase (session_meta in-place update vs reset — multi-meta rollout files would have double-counted) — fixed before commit.

Flag for Phase 9: packages/cli/dist does a bare runtime import of @codeburn/core (workspace-resolved). npm publish will require core published first or bundled via noExternal — tracked for the publish phase.

…leaves the decoder (phase 4)

Carve the Codex decoder into @codeburn/core/providers/codex as a pure function
over supplied rollout records with EXPLICIT, JSON-serializable state
(CodexDecodeState): the running cumulative token counters, fork-replay cutoff,
mid-turn accumulators, id/turn bookkeeping, and the cross-file dedup memory
(seenKeys). Decoding a corpus in one pass equals decoding it in any number of
passes when the state threads between them (the resume invariant).

Cost leaves the decoder: the rich calls are cost-free and the CLI prices them
through the established estimated-cost seam (costBasis: 'estimated'), retiring
both Phase-0 residual calculateCost sites. The CLI codex provider is now
discovery + file streaming + cache I/O + pricing.

codex-results cache bumped to v8 (one deliberate bump): it persists the decoder
end-state blob + a byte offset + host-priced calls, so a grown rollout resumes
from the stored state and decodes only the appended bytes. Lossless — rollout
files are durable, so the one-time re-derive rebuilds identical data.

Adds a codex path to the content-smuggling guardrail and the import-smoke
subpath set. Byte-parity verified against a frozen 826-file corpus (codex-only
and all-providers, rel_tol 1e-9); perf within ±1.5% cold / ±0.5% warm.
@iamtoruk
iamtoruk merged commit 99f7b25 into feat/core-extraction Jul 26, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant