fix(codex): skip replayed parent usage in fork logs - #649
Merged
IvGolovach merged 1 commit intoJun 4, 2026
Merged
Conversation
Validation * Validation tier: Tier 3 - shared parser/accounting change affecting submit totals. * cargo fmt --all -- --check: PASS * cargo test -p tokscale-core codex: PASS, 72 passed. * cargo test -p tokscale-core: PASS, 817 passed, 1 ignored. * cargo clippy -p tokscale-core --all-targets -- -D warnings: PASS * Focused local Codex 2026-05-24 verifier over real ~/.codex JSONL: PASS, 177,833,822 tokens after skipping 614,239 inherited replay token_count rows. * git diff --check: PASS * git diff --cached --check: PASS * Ledger: not applicable - not required for selected validation tier/change family. * Version: not applicable - not required for selected validation tier/change family. Rollback * git revert HEAD
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
|
Any movement on this? Tried to submit again and same error. |
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.
Summary
Fixes #601.
This updates the Codex session parser so forked subagent logs no longer count replayed parent
token_counthistory as fresh usage. It also bumps the source message cache schema so previously cached inflated Codex parse results are not reused.Why
Codex fork/subagent JSONL logs can embed the parent session metadata and replay the parent transcript before the child session reaches its own turn. Those replayed rows can carry child-local timestamps, so timestamp-based deduplication treats them as distinct usage and
tokscale submitcan produce impossible daily totals such as tens of billions of Codex tokens and five-figure daily costs. The server-side validation failure is correct; the local parser was overcounting inherited replay history.Diff scope
crates/tokscale-core/src/sessions/codex.rs: tracks fork child session identity, skips nested parent replay until the first child-owned turn, and uses cumulativetotal_token_usageplus upstream session identity for Codex token_count dedup keys.crates/tokscale-core/src/lib.rs: adds end-to-end parser/accounting regressions for parent replay across forked child logs while preserving real child usage and repeated legitimate turns.crates/tokscale-core/src/message_cache.rs: bumps the source message cache schema from 16 to 17 to force reparsing with the corrected Codex semantics.Branch integrity
maina86e688d620939d2c973c6d5625baa815ea223d70 behind / 1 aheada86e688d620939d2c973c6d5625baa815ea223d7origin/main.Commit integrity
c732360818e8f7a151101592243f624a0aa05118 fix(codex): skip replayed parent usage in fork logsLedger and version proof
Diff hygiene
git diff --check origin/main...HEAD: PASS, no output.crates/tokscale-core/src/lib.rscrates/tokscale-core/src/message_cache.rscrates/tokscale-core/src/sessions/codex.rsValidation mode and proof
cargo fmt --all -- --check: PASScargo test -p tokscale-core codex: PASS, 72 passed.cargo test -p tokscale-core: PASS, 817 passed, 1 ignored.cargo clippy -p tokscale-core --all-targets -- -D warnings: PASS~/.codex/sessions/2026/05/24/*.jsonl: PASS, corrected total was177,833,822tokens after skipping614,239inherited replaytoken_countrows from the local Codex corpus.Migration notes
CI context confirmation
Pending - required CI will run after this PR is opened. CI workflow/context names are unchanged.
Runtime safety
The change is limited to local Codex source parsing and cache invalidation. It does not add network calls, blocking locks, unbounded queues, or submit API contract changes. No invariant regression introduced.
Documentation integrity
Not applicable - no user-facing command, runbook, or documented workflow changed.
Rollback plan
Rollback: revert this PR. DB downgrade: not applicable. Data repair: not applicable. Operational caveats: users may need to rerun local scan/submit after rollback if they want cache contents regenerated under the previous parser behavior.
Known residual risks
Remote CI is pending until the PR is opened. The parser intentionally relies on Codex v7-style turn/session ordering only while a forked child is replaying embedded parent metadata; if a future Codex format removes that ordering signal, the fallback is conservative and stops applying the replay skip rather than silently dropping child-owned usage.
Summary by cubic
Skips replayed parent
token_countentries in Codex fork/subagent logs and deduplicates by cumulative totals to fix inflated usage and invalid submit totals. Also bumps the cache schema to force correct re-parsing.Bug Fixes
token_countusing cumulativetotal_token_usageplus upstream session id (fall back to timestamp only if totals are missing).Migration
Written for commit c732360. Summary will update on new commits.