Repository navigation
refactor(core): codex decoder with explicit serializable state, cost leaves the decoder (phase 4) - #823
Merged
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.