Codex real fork corpus: 5,427 replayed parent events across rewritten timestamps
Summary
This is a redacted real-world corpus report for the remaining cross-file work in #2037, not a separate root-cause claim.
A high-fanout Codex session produced dozens of child rollout files. The children replay parent token_count history with rewritten timestamps. In one verified parent/child pair, the child starts with 5,427 consecutive last_token_usage vectors that exactly match a contiguous section of the parent's immutable token stream. The copied prefix spans about 1.98 seconds in the child, so a same-second replay heuristic cannot remove it.
Environment
- macOS 26.2 (25C56), Apple Silicon
- Codex CLI 0.143.0
- CodexBar 0.42.0
- Local timezone: Asia/Shanghai
- Affected workload: Codex Ultra-style high-fanout subagents/forks
Redacted corpus shape
For one local day:
- 111 rollout JSONL files
- 22 root sessions
- 88 files with an explicit parent reference
- largest parent family: 46 child files
- second-largest parent family: 24 child files
For one sanitized parent/child pair:
parent token_count events: 12,273
child token_count events: 5,716
exact copied child-prefix events: 5,427
matched parent stream start index: 2,449
child replay duration: 1.983 seconds
The first and last matching vectors were compared using only the numeric fields in last_token_usage:
{
"input_tokens": 170483,
"cached_input_tokens": 167680,
"output_tokens": 244,
"reasoning_output_tokens": 87,
"total_tokens": 170727
}
{
"input_tokens": 54031,
"cached_input_tokens": 52992,
"output_tokens": 199,
"reasoning_output_tokens": 0,
"total_tokens": 54230
}
No prompt, response, account, session ID, filename, or local path was retained in this report.
Observed result
On this corpus, the released CodexBar scanner reported approximately:
Last 2 days: $7,634.61 / 21B tokens
The dollar value is included only as a symptom. I am not claiming a corrected bill amount here. The directly verified defect is that thousands of parent events appear again at the beginning of child files with rewritten timestamps.
Reproduction method
- Read only the first
session_metarecord from each rollout. - Map children to parents using
forked_from_idorsource.subagent.thread_spawn.parent_thread_id. - Read only
event_msg.payload.type == "token_count"records. - Normalize each event to its numeric
last_token_usagevector, excluding the envelope timestamp. - Compare the child prefix with contiguous sections of the referenced parent's immutable stream.
- The pair above produced an exact 5,427-event match before the child's new suffix began.
Expected behavior
- Copied parent history should have one owner across the fork family.
- A child should contribute only genuinely new usage after the copied prefix.
- If the parent is unavailable or ownership is ambiguous, the result should be marked incomplete/estimated rather than silently multiplying copied usage.
- Equal token vectors from distinct events must not be globally collapsed without provenance.
Relation to current main
I understand that #2082 adds bounded file-local containment and fixtures, while exact cross-file fork-family provenance remains open in #2037. This report is intended to provide the affected real-setup evidence requested there.
I can provide a generated numeric-only fixture derived from this pair, or run an instrumented CodexBar build against the frozen local corpus and return initial-scan plus cached repeat-scan summaries.
Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed July 16, 2026, 7:56 PM ET / 23:56 UTC.
Summary The copied-prefix fix is on current main, but the repository owner explicitly reopened this issue and requested a same-corpus strict-prefix rerun before closure. That measurement has not been posted, and the fix merged after the latest release, so this issue should remain open as a validation checkpoint.
Reproducibility: yes. at high confidence from source and corpus evidence: the numeric-only method deterministically identifies copied contiguous child prefixes, and the candidate fix has targeted regression coverage. A current-main rerun on the reporter’s exact corpus remains pending, so this is source-reproducible rather than independently reproduced here.
Root-cause cluster
Relationship: fixed_by_candidate
Canonical: https://github.com/steipete/codexbar/pull/2228
Summary: Merged PR 2228 is the candidate fix for this concrete copied-prefix corpus defect, while the broader fork-family ledger remains a distinct open investigation.
Members:
canonical: https://github.com/steipete/codexbar/pull/2228 - It merged the shape-aware copied-prefix subagent accounting implementation specifically intended to fix this issue.partial_overlap: https://github.com/steipete/codexbar/issues/2037 - It tracks the broader cross-file fork-family accounting problem and historical residuals that PR 2228 explicitly does not claim to complete.same_root_cause: https://github.com/steipete/codexbar/pull/2208 - Its blanket treatment of source.subagent lineage exposed the copied-prefix regression that PR 2228 refined into shape-aware accounting.adjacent_distinct: https://github.com/steipete/codexbar/pull/2118 - It fixes parent-cache invalidation needed by inherited-parent cases but does not itself classify copied-prefix rollouts.partial_overlap: https://github.com/steipete/codexbar/pull/2082 - It added file-local containment and fork fixtures while explicitly deferring exact cross-file provenance.- 1 more in the report.
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.
Next step Do not queue another fix PR: a merged candidate implementation already exists, and the remaining action is the explicitly requested real-corpus validation rather than new code.
Review details
Best possible solution:
Run current main against the same frozen corpus with isolated cold, warm, and forced scans; close this issue if the strict copied-prefix residual disappears or is conservatively classified, while leaving broader family-ledger gaps with https://github.com/steipete/CodexBar/issues/2037.
Do we have a high-confidence way to reproduce the issue?
Yes at high confidence from source and corpus evidence: the numeric-only method deterministically identifies copied contiguous child prefixes, and the candidate fix has targeted regression coverage. A current-main rerun on the reporter’s exact corpus remains pending, so this is source-reproducible rather than independently reproduced here.
Is this the best way to solve the issue?
Likely yes: classifying subagent rollout shape and accounting only the leaf-owned suffix is narrower and safer than global token-vector deduplication. It is not closure-ready until the requested same-corpus residual confirms the implementation handles the observed setup.
AGENTS.md: found and applied where relevant.
Remaining risk / open question:
- The reporter has not yet run the requested strict-prefix audit against current main, so the residual on the exact affected corpus is unknown.
- The candidate fix is not present in latest release v0.43.0, so released-user behavior has not changed yet.
- The merged fix intentionally does not complete the broader cross-file family-ledger work tracked in https://github.com/steipete/CodexBar/issues/2037; any eventual closure must remain limited to this copied-prefix subagent shape.
Codex review notes: model internal, reasoning high; reviewed against a1fad485d668.
Label changes
Label changes:
- remove
clawsweeper:no-new-fix-pr: Current issue advisory state no longer selects this label. - remove
clawsweeper:needs-maintainer-review: Current issue advisory state no longer selects this label.
Label justifications:
P2: The defect materially inflates local token and cost estimates for affected high-fanout sessions, but it does not make the core runtime unusable.impact:other: The issue concerns materially incorrect local usage and estimated-cost accounting, which does not fit a more specific owned impact category.
Evidence reviewed
What I checked:
- Maintainer-directed validation remains open: After merging the candidate fix, repository owner steipete reopened this issue on July 16, 2026 and requested a current-main rerun using the same frozen corpus and strict-prefix audit method before closing. (a1fad485d668)
- Candidate fix merged on current main: Merged pull request https://github.com/steipete/CodexBar/pull/2228 distinguishes reset-only subagent counters from copied-ancestor-prefix rollouts, uses the leaf-owned suffix when a valid turn marker exists, and preserves inherited-parent handling for ambiguous cases. (
Sources/CodexBarCore/Vendored/CostUsage/CostUsageScanner.swift, a1fad485d668) - Focused regression coverage accompanied the fix: The merged PR reports scanner, classifier, cache, parser-parity, ordering, and cold/warm/forced-scan coverage, including preservation of reset-only subagents and deterministic inherited-parent fallback behavior. (
Tests/CodexBarTests/CostUsageScannerBreakdownTests.swift, 25bbf5912935) - Real-corpus evidence establishes the defect: The reporter supplied a deterministic numeric-only audit that matched 5,427 consecutive child-prefix events to a contiguous parent stream despite rewritten timestamps, followed by full-day and cold-cache measurements.
- Fix is current-main-only: The latest release is v0.43.0 from July 14, 2026, while the candidate fix merged on July 16, 2026 at a1fad485; it has not shipped in the latest release. (
CHANGELOG.md, a1fad485d668) - Repository vision supports the fix direction: VISION.md lists bug fixes with a clear cause and bounded risk as merge-by-default work, matching this local usage-accounting correction. (
VISION.md:240, a1fad485d668)
Likely related people:
- steipete: Merged the candidate fix, explicitly reopened this issue, and defined the same-corpus validation required before closure. (role: merger and likely follow-up owner; confidence: high; commits: a1fad485d668; files:
Sources/CodexBarCore/Vendored/CostUsage/CostUsageScanner.swift) - hhh2210: Authored the merged copied-prefix classifier and supplied the 2,012-file corpus comparison, cache audit, and focused validation. (role: recent area contributor; confidence: high; commits: 25bbf5912935, a1fad485d668; files:
Sources/CodexBarCore/Vendored/CostUsage/CostUsageScanner.swift,Tests/CodexBarTests/CostUsageScannerBreakdownTests.swift) - harjothkhara: Authored the earlier reset-only subagent accounting change whose blanket source.subagent assumption was refined by the copied-prefix fix. (role: prior subagent-accounting contributor; confidence: high; commits: 59a18fcc4e37, 8489602f84ca; files:
Sources/CodexBarCore/Vendored/CostUsage/CostUsageScanner.swift,Sources/CodexBarCore/Vendored/CostUsage/CostUsageScanner+CodexFastJSON.swift) - xx205: Authored the merged parent-cache dependency and invalidation work that inherited-parent cases must preserve. (role: adjacent cache-accounting contributor; confidence: medium; commits: 45dfa3f959bc, 2acf34cdf860; files:
Sources/CodexBarCore/Vendored/CostUsage/CostUsageScanner.swift,Sources/CodexBarCore/Vendored/CostUsage/CostUsageScanner+CacheHelpers.swift) - Zihao-Qi: Authored the earlier file-local containment and fork-provenance fixtures that established the broader accounting boundary later narrowed by this corpus report. (role: earlier fork-containment contributor; confidence: medium; commits: be56cc9aff5e, c852c135e10c; files:
Sources/CodexBarCore/Vendored/CostUsage/CostUsageScanner.swift,Tests/CodexBarTests/CostUsageScannerBreakdownTests.swift)
How this review workflow works
- ClawSweeper keeps one durable marker-backed review comment per issue or PR.
- Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
- A fresh review can be triggered by eligible
@clawsweeper re-reviewcomments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch. - PR/issue authors and users with repository write access can comment
@clawsweeper re-reviewor@clawsweeper re-runon an open PR or issue to request a fresh review only. - Maintainers can also comment
@clawsweeper reviewto request a fresh review only. - Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
- Maintainer-only repair and merge flows require explicit commands such as
@clawsweeper autofix,@clawsweeper automerge,@clawsweeper fix ci, or@clawsweeper address review. - Maintainers can comment
@clawsweeper explainto ask for more context, or@clawsweeper stopto stop active automation.
Live follow-up from the same affected machine, captured on 2026-07-13 around 19:00 Asia/Shanghai.
CodexBar 0.42.0 currently reports:
Today: $6,356.79 / 15B tokens
I repeated the numeric-only parent/child prefix audit on today's files:
rollout files: 90
root files: 32
child files with explicit parent: 58
child files whose parent log was found: 58
token_count events with last_token_usage: 100,331
events in exact copied child prefixes: 98,613
raw last_token_usage.total_tokens sum: 18,430,664,310
sum inside exact copied prefixes: 18,260,666,199
remaining after exact prefix removal: 169,998,111
exact replay share of the raw token sum: 99.08%
Largest family breakdown, with session identifiers removed:
34 children: 70,482 exact replay events / 13,285,075,131 replay tokens
10 children: 24,428 exact replay events / 4,449,064,625 replay tokens
8 children: 3,409 exact replay events / 487,851,476 replay tokens
3 children: 294 exact replay events / 38,674,967 replay tokens
3 children: 0 exact prefix matches (different event shape)
Method: resolve each child's explicit parent, normalize only the five numeric last_token_usage fields, find the longest child prefix that exactly matches a contiguous section of that immutable parent stream, and remove only that exact prefix. Equal vectors outside the proven contiguous prefix are retained.
Important: the raw event sum and CodexBar's 15B output use different aggregation rules. The 99.08% figure should not be applied directly to the displayed dollar amount. It is evidence that today's high-fanout corpus is overwhelmingly copied cross-file history, not a corrected billing estimate.
No prompts, responses, filenames, paths, account details, or session identifiers were included in this follow-up.
Scope correction and full local-day audit, captured at 2026-07-13 19:04 Asia/Shanghai:
The previous 99.08% figure was explicitly calculated over the 90 rollout files created today. It should not be read as the replay percentage of the complete local day, because older parent files can continue receiving genuine events today.
I re-ran the audit using event timestamps across every JSONL file modified since local midnight, with the day bounded as 2026-07-12T16:00:00Z <= timestamp < 2026-07-13T16:00:00Z (Asia/Shanghai):
files containing possible local-day events: 115
child files among them: 62
children with a strict matched replay prefix: 37
daily events with last_token_usage: 109,589
daily raw last_token_usage.total_tokens: 19,975,928,751
strict replay-prefix events: 98,613
strict replay-prefix token sum: 18,260,666,199
strict replay share of full local day: 91.41%
retained after strict prefix removal: 1,715,262,552
retained after also dropping unchanged
cumulative-total snapshots: 1,686,747,608
The strict matcher compares all five numeric fields from both last_token_usage and total_token_usage (ten values per event). A separate five-field last_token_usage matcher produced exactly the same 98,613-event result.
Coverage check for the same local-day window:
token_count rows: 109,599
rows with last_token_usage: 109,589
rows with total_token_usage but no last usage: 0
rows with neither usage object: 10
So there is no omitted total-only usage bucket in this snapshot. The approximately 1.687B retained token sum is still not an exact bill: 25 child files did not have a strict parent-prefix match, so their retained events may include either legitimate work or another replay shape. It is best treated as a conservative upper bound for locally logged non-replay usage, not an official daily total.
The released CodexBar output remains structurally incomparable to the raw sum because its scanner applies additional cumulative/delta rules. This correction strengthens the cross-file replay evidence but does not claim that $6,360.95 can be corrected by multiplying it by the retained percentage.
v0.42.1 cold-cache vs repeat-scan evidence from the same affected machine (numeric only, Asia/Shanghai).
Procedure:
codexbar cache --cost
codexbar cost --provider codex --days 2 --refresh --format json
codexbar cost --provider codex --days 2 --format json
Before clearing the cost cache, the existing v9 cache reported:
2026-07-13 2,201,979,822 tokens $1,716.862588
2026-07-14 476,804,659 tokens $335.888340 (through 02:01:57Z)
The first cold scan after clearing the cache reported:
2026-07-13 13,147,445,914 tokens $3,572.669502
gpt-5.6-sol 4,492,157,525
unknown 8,474,761,655
2026-07-14 2,744,340,590 tokens $338.980055 (through 02:07:30Z)
gpt-5.6-sol 479,098,877
unknown 2,263,762,472
An independent exact-provenance audit over the same local-day windows, removing only child prefixes that match a contiguous parent sequence across all five numeric fields in both last_token_usage and total_token_usage, then dropping unchanged cumulative snapshots, produced:
2026-07-13
raw last-usage sum: 20,640,581,873
proven replay removed: 18,652,730,202
retained: 1,957,095,204
priced known models: $1,510.838495
retained gpt-5.6-sol: 1,922,084,421
retained unknown: 0
2026-07-14 through 02:07:30Z
raw last-usage sum: 1,976,742,515
proven replay removed: 1,490,922,792
retained: 479,672,035
priced known models: $338.431562
retained gpt-5.6-sol: 478,241,717
retained unknown: 0
The cached repeat scan kept 2026-07-13 exactly unchanged. For the live current day, known-model tokens advanced normally while the large unknown bucket stayed frozen:
2026-07-14 repeat:
total: 2,749,004,294
gpt-5.6-sol: 483,708,597
unknown: 2,263,762,472
cost: $341.846479
Interpretation:
- This is not only stale pre-upgrade cache state. A v0.42.1 cold scan generates a much larger overcount than the prior incremental cache.
- Today the dollar total happens to be close because the 2.264B excess is unattributed and unpriced; the token total is still about 4.72x high relative to the strict retained result.
- Yesterday the cold scan also over-attributes priced Sol usage (4.492B vs 1.922B retained), so the dollar estimate is materially inflated too.
- The cold-scan and cached repeat-scan outputs are deterministic for the completed day; live-day known usage advances while the unexplained unknown bucket persists.
No prompts, responses, paths, filenames, account details, or session identifiers are included.
Current-main regression update, with a concrete fix: #2228.
#2208 fixed the reset-only subagent shape from #2193, but its unconditional source.subagent branch regressed the copied-prefix shape documented here. source.subagent is lineage provenance, not a counter-semantics guarantee. Because that branch bypasses the parent resolver, #2118 cannot repair the attribution afterward.
On the same frozen 2,012-file corpus with isolated empty caches:
| Scanner | Jul 16 tokens | Jul 16 Unknown |
|---|---|---|
origin/main (6d71af30) |
4,086,288,236 | 886,306,282 |
#2228 (67862278) |
231,475,556 | 0 |
#2228 handles both real shapes instead of choosing one globally:
- reset-only subagents keep their full independent counters;
- copied-prefix subagents use the first valid leaf turn marker after the final embedded ancestor;
- copied rollouts without that marker retain the inherited-parent fallback;
- ordinary forks keep the existing parent-baseline behavior.
Cold, warm, and forced scans are identical. The cache audit produced 197 marker-owned suffixes, 10 independent counters, one inherited dependency, and no missing dependency mode. The parser producer hash rotates automatically; there is no unnecessary codex-v10 bump.
The current head also makes the inherited-parent fallback deterministic when a copied rollout arrives before its parent can be resolved. A focused regression test covers that ordering case. In total, 121 relevant tests pass, and the corpus figures above are unchanged.
This should close the concrete subagent corpus defect in #2108. It deliberately does not claim to complete the broader cross-file family ledger in #2037.
The copied-prefix subagent accounting fix has landed via #2228. It now distinguishes copied ancestor history from reset-only subagent counters and keeps ambiguous lineage conservative.
@1939869736luosi, could you rerun the strict-prefix audit against a build from current main and report the residual? Please keep the same corpus and audit method where possible so the before/after is comparable. Keeping this issue open pending that measurement.
I completed the requested same-corpus rerun. The residual among prefixes proven by the same strict matching rule is zero on this frozen corpus.
Build and input
- commit:
d9cae08c, which contains the #2228 merge commita1fad485 - corpus: the same frozen corpus directory and 2,012-file snapshot used for the #2228 comparison, totaling 3,959,955,954 bytes
- corpus manifest SHA-256:
7ec548cf8a49821c9abba5d0901e1d130d4546316e40f92f2cbb0decb1240368 - cache: a fresh isolated cache directory (produced artifact:
codex-v10.json) - parser hash and cache producer key:
75b1c680ad3d91c9/codex:cu:p75b1c680ad3d91c9
Between the earlier 7f2c5965 build and this commit, the only change under Vendored/CostUsage adds .longcat to the non-local-scanner provider switch. It does not change Codex parsing or fork classification, but it does rotate the generated parser hash and producer key. I therefore rebuilt and reran the corpus with a new cache instead of reusing the earlier result.
Scanner rerun
| Mode | Jul 16 tokens | Jul 16 Unknown | Jul 16 cost | 30-day tokens | 30-day cost |
|---|---|---|---|---|---|
| cold | 231,475,556 | 0 | $186.318118 | 3,799,232,783 | $2,765.5475077 |
| warm | 231,475,556 | 0 | $186.318118 | 3,799,232,783 | $2,765.5475077 |
| forced | 231,475,556 | 0 | $186.318118 | 3,799,232,783 | $2,765.5475077 |
The cold scan started from an empty cache. The warm scan disabled the top-level refresh shortcut so it exercised per-file cache validation. The forced scan rescanned the same input. The three reports are identical after omitting the mode label.
Strict-prefix audit
The independent audit implements the same numeric-only method: resolve each child's explicit parent, compare all five numeric fields from both last_token_usage and total_token_usage, and remove only the longest child prefix that exactly matches a contiguous parent sequence. Envelope timestamps are ignored. Equal vectors outside the proven prefix remain attributed.
| Jul 16 measure | Events | Tokens |
|---|---|---|
raw last_token_usage |
20,458 | 3,371,569,795 |
| proven copied prefix | 18,573 | 3,131,261,340 |
| retained after strict prefix removal | 1,885 | 240,308,455 |
| retained after also dropping unchanged cumulative snapshots | 1,826 | 231,475,556 |
| proven prefix at or after the owned boundary in the independent current-main rule replay | 0 | 0 |
All 512 explicit children had their parent available. The ten-field matcher found a copied prefix in 260 children, totaling 120,195 events across the full corpus. A five-field last_token_usage matcher selected the same prefix length for all 512 children.
The 252 unmatched children were retained; their Jul 16 raw last_token_usage contribution is 2,404,347 tokens. Raw last-usage sums and scanner cumulative/delta totals are structurally different, so the raw-minus-prefix figures are diagnostic rather than a billing estimate.
The boundary check is an independent replay of the current-main rollout-shape rules against the exact build's cache. The Swift scanner independently produced the matching Jul 16 aggregate: the final strict retained total and scanner total are both 231,475,556. The cache contains 197 marker-owned suffixes, 10 independent counters, one inherited dependency, and no missing or unexpected dependency mode. No Jul 16 proven-prefix event remained on the conservative inherited path or outside the scanner window.
The final forced-scan cache still contains 307,441,975 Unknown tokens across the 30-day window. This rerun does not classify that broader historical bucket.
The requested strict-prefix residual is zero on this corpus. This provides the requested evidence for #2108; the repository owner can decide closure. It does not establish agreement with OpenAI's official usage totals or close the broader cross-file lineage scope tracked in #2037.
No prompts, responses, local paths, filenames, account details, or session identifiers are included here.
🦞🔧 ClawSweeper is automatically building this issue.
The issue review finished and no active implementation pull request was found.
Automatic implementation progress:
- State: Queued
- Detail: Review complete; no active implementation PR was found. The Codex implementation worker is queued.
- Run: https://github.com/openclaw/clawsweeper/actions/runs/29578907139
- Updated: 2026-07-17T12:03:55.134Z
- Opt out: add
clawsweeper:manual-onlyorclawsweeper:human-review.
Implemented in #2285.
The remaining v0.44.0 residual is a compact single-leaf rollout shape that #2228 did not cover: it has an explicit parent and copied counters before the first turn_context, but no embedded ancestor metadata. The patch suppresses that prefix only after an exact parent snapshot match. Mismatch and unresolved-parent cases remain independent, and candidate classifications keep a parent cache dependency.
On the Jul 17 repro, Unknown falls from 49,528,505 tokens to zero while both attributed model buckets remain unchanged. On the frozen 2,012-file corpus, the previous 30-day Unknown bucket falls from 307,441,975 to zero; Jul 16 is unchanged, and cold, warm, and forced scans are identical. Full evidence and tests are in the PR.
#2285 changes the remaining residual expectation here. Compact v0.44 single-leaf subagent rollouts can carry a copied parent prefix without embedded ancestor metadata; the scanner now drops that prefix only when the first-turn boundary candidate exactly matches the resolved parent snapshot. Mismatch and unresolved cases stay independent, and parent-key cache invalidation remains required.
The PR's frozen-corpus audit reports the remaining 30-day Unknown bucket moving from 307,441,975 to 0, with the July 17 residual moving from 49,528,505 to 0 and attributed model totals unchanged. Cold, warm, and forced scans matched. I independently verified the classification and cache behavior with 129 focused scanner/cache tests plus all 9 exact-head CI checks.
Merged in dbcba17b28b2841d38017a30c52ded5fb330a9e0; GitHub closed this issue through the PR. Scope remains the copied-prefix residual described here, not agreement with official usage totals or the broader #2037 ledger.
Parked CostUsageScanner consolidation analysis (2026-07-21)
Decision: no refactor PR and no merge. The behavior-identity gate was not met, so the scanner remains unchanged.
Why this is parked
The safe candidate is a code-movement-only extraction of the existing Codex totals primitives, monotonic/interleaved tracker, and parent snapshot accumulator from CostUsageScanner.swift into a dedicated scanner extension. That would reduce the hottest file's patch surface without changing arithmetic or control flow.
I built a gated parity probe that serialized every daily and model-breakdown integer plus exact Double.bitPattern values, then started cold/warm/forced scans against an isolated cache and the completed Jul 16 window in the local ~/.codex corpus. Cold and warm reached the cache artifact, but a real forceRescan changes file discovery: loadCodexDaily passes includeRecursive: true, which intentionally includes the entire legacy sessions/archive tree rather than only the requested date partitions. After more than an hour, the forced pass was still traversing older archived parents. I stopped it without accepting partial output.
That means there is no complete baseline forced signature and therefore no possible pre/post exact comparison. The hard gate explicitly forbids replacing that proof with source inspection, fixture-only confidence, a smaller ad hoc sample, or CI. No production files were edited.
Risk map / invariants that must remain load-bearing
Do not consolidate across these boundaries:
- Fast JSON vs Foundation fallback parsing. Field precedence, empty-model handling, timestamp validation, and clamping contain deliberate asymmetries. A shared generic parser could silently change malformed/legacy-row behavior.
- Subagent shape classification. Reset-only counters, embedded copied prefixes, and compact copied-prefix candidates are distinct. A compact candidate becomes suppressible only after an exact parent snapshot match.
- Owned-boundary selection. The local boundary is the first valid adjacent
turn_context+inter_agent_communication_metadata(trigger_turn: true)pair after the final embedded ancestor, and its baseline is the last cumulative total before that marker. - Parent dependency keys. Candidate outcomes and inherited baselines remain parent-dependent even when the final classification is independent. Missing, changed, or unstable parents must invalidate reuse exactly as today.
- Totals containment. Watermark latching, seen-total suppression, divergent totals, last-only streams, unresolved-parent first-row suppression, and post-latch
min(last, contained)are one state machine. Ordering is behavior. - Cache contract. Keep
codex-v10and stored schema unchanged. Any source movement must follow the generated parser-hash workflow; compatibility with the immediately previous producer key may be declared only after old-cache reuse is included in exact parity proof.
Smallest safe implementation slice
- Move the bodies of the pure component-wise totals helpers,
CodexTotalsTracker, andCodexSnapshotAccumulatorverbatim intoCostUsageScanner+CodexTotals.swift. - Make only the minimum access-level changes required by the file split. Do not rename stored fields, reorder branches/deferred commits, merge the snapshot and daily reducers, or touch parser/classifier/cache-dependency code.
- Regenerate the parser hash as required by repository lint. Do not bump the artifact version. Prove warm reuse from an artifact carrying the prior producer key before adding it to the compatibility set.
- Keep later ideas separate. In particular, extracting the nested daily token reducer into a state object and unifying fast/fallback parsing are follow-up candidates only after their own corpus contracts exist.
Required proof before any future merge
- Frozen corpus manifest
7ec548cf8a49821c9abba5d0901e1d130d4546316e40f92f2cbb0decb1240368(2,012 files): byte-identical serialized cold, warm, forced, and prior-producer-cache reports before/after. - Preserve the canonical Jul 16 result from #2285: 231,475,556 tokens, $186.318118, zero Unknown, with unchanged attributed model buckets and cache dependency-mode audit.
- All
Issue2037*,CostUsageScannerTests,CostUsageScannerBreakdownTests,CodexSubagentRolloutShapeTests,CodexSubagentAccountingIntegrationTests,CodexCompactSubagentAccountingTests, cache, priority, project, session, and fetcher breakdown suites green. make check;make testthree consecutive times with zero retries/failures; clean autoreview; exact-head CI fully green.- A second real local
~/.codexA/B with an isolated cache, complete cold/warm/forced signatures, zero new Unknown attribution, and no report/cache-dependency differences.
Abort and park again on any serialized-field difference, dependency-mode/key drift, new Unknown attribution, producer-cache mismatch, flaky/retried full-suite run, incomplete forced scan, or CI failure. Fixture and CI success cannot waive the real-corpus gate.
This plan deliberately leaves the broader #2037 family-ledger work out of scope.