fix(codex): attribute resumed token counts to later model#496
Merged
junhoyeo merged 1 commit intojunhoyeo:mainfrom May 3, 2026
Merged
Conversation
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Contributor
There was a problem hiding this comment.
1 issue found across 3 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="crates/tokscale-core/src/sessions/codex.rs">
<violation number="1" location="crates/tokscale-core/src/sessions/codex.rs:238">
P2: Pending model-less token_count rows can remain buffered when a headless JSON line sets `current_model` but returns `None`, so earlier rows are later emitted as `unknown` instead of the discovered model.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
Validation - scripts/ledger/check: Not applicable - scripts/ledger/ does not exist in this repository. - git fetch --no-tags origin main:refs/remotes/origin/main: PASS - cargo test -p tokscale-core test_model_only_headless_line_flushes_pending_token_counts: PASS, 1 passed - cargo test -p tokscale-core token_count: PASS, 11 passed - cargo test -p tokscale-core codex_cache: PASS, 2 passed - cargo test -p tokscale-core: PASS, 600 passed, 1 ignored; codebuff 10 passed; hermes 3 passed; doc-tests 0 passed - cargo clippy -p tokscale-core --all-features -- -D warnings: PASS - cargo fmt --all --check: PASS - git diff --check: PASS - git diff --cached --check: PASS - Cyrillic scan for touched source files: PASS, no matches Rollback - git revert HEAD
c3ca2ce to
58a9732
Compare
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
Fix Codex resumed-session attribution so early
token_countevents emitted beforeturn_contextinherit the later model instead of staying underunknown.Fixes #490.
Why
Codex 0.124 resumed sessions can replay
event_msg/token_countrows before the firstturn_contextrow that carriespayload.model. The previous parser emitted those early rows immediately withmodelId = unknown, which also meant pricing stayed at0even after the real model appeared later in the same session file.Diff scope
crates/tokscale-core/src/sessions/codex.rs: buffer model-less Codextoken_countmessages until the parser observes a model, then flush them with that model; preserveunknownonly when no model ever appears.crates/tokscale-core/src/lib.rs: avoid writing Codex source-cache entries when a file still has unresolved model-less token events.crates/tokscale-core/src/message_cache.rs: bump the source-message cache schema from8to9so stale cachedunknownCodex rows are invalidated.This is a narrow runtime parser/cache change. No frontend, release, workflow, migration, or CLI command behavior changed.
Branch integrity
mainorigin/main:97809e755b58b07e21c0eaceb9005f0ba073de0cgit rev-list --left-right --count origin/main...HEAD:0 behind / 1 ahead97809e755b58b07e21c0eaceb9005f0ba073de0cgit merge-base --is-ancestor origin/main HEAD: PASSCommit integrity
c3ca2ce9cfc113bc465dff8965f49da6cb83d865 fix(codex): attribute resumed token counts to later modelscripts/ledger/does not exist in this repository.scripts/ledger/does not exist in this repository.Ledger proof
Not applicable —
scripts/ledger/does not exist in this repository.Diff hygiene
git diff --name-status origin/main...HEAD:git diff --check origin/main...HEAD: PASS, no output..envfiles, local environment files, secrets, tokens, credentials, cache files, build artifacts, or unrelated generated files are included.CACHE_SCHEMA_VERSIONwas bumped because the interpretation of cached Codex source messages changed; invalidating old cache entries prevents previously cachedunknownrows from surviving the parser fix.Validation tier and test proof
Validation tier: Tier 2 — narrow runtime parser/cache change.
Reason: the change is localized to Codex session parsing and source-message cache eligibility. It does not alter migrations, auth, permissions, payment/billing logic, global configuration, CI, release tooling, production infrastructure, or external service contracts.
Run:
scripts/ledger/check: Not applicable —scripts/ledger/does not exist in this repository.git fetch --no-tags origin main:refs/remotes/origin/main: PASS.cargo test -p tokscale-core token_count: PASS, 10 passed.cargo test -p tokscale-core codex_cache: PASS, 2 passed.cargo test -p tokscale-core: PASS, 599 passed, 1 ignored;codebuffintegration tests 10 passed;hermesintegration tests 3 passed; doc-tests 0 passed.cargo clippy -p tokscale-core --all-features -- -D warnings: PASS.cargo fmt --all --check: PASS.git diff --check: PASS.git diff --cached --check: PASS.Not run:
tokscale-coretests and clippy.External gates:
Verification-pack proof
Not applicable — no infra, governance, replay, invariant, or verification-pack files changed.
Migration notes
Not applicable — no DB migration changed.
CI context confirmation
Runtime safety
Reviewed runtime files/modules:
crates/tokscale-core/src/sessions/codex.rscrates/tokscale-core/src/lib.rscrates/tokscale-core/src/message_cache.rsSafety reasoning:
unknownattribution from being persisted.No invariant regression introduced.
Documentation integrity
Not applicable — no docs, runbooks, public commands, release procedure, deployment procedure, or user-facing documented behavior changed.
Rollback plan
git revert <post_merge_commit_sha>.<post_merge_commit_sha>with the final squash or merge commit SHA after merge.8; users may keep regenerated cache entries from the fixed parser until the cache naturally refreshes or is removed.Known residual risks
No known residual risks.