Fix Codex cost scanner overcounting and cross-day undercounting#680
Open
xx205 wants to merge 1 commit intosteipete:mainfrom
Open
Fix Codex cost scanner overcounting and cross-day undercounting#680xx205 wants to merge 1 commit intosteipete:mainfrom
xx205 wants to merge 1 commit intosteipete:mainfrom
Conversation
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 two issues in the local Codex cost scanner:
total_token_usage, causing severe overcounting.token_count.timestampfell inside the report window, causing undercounting.This also hardens fork baseline selection by comparing parsed timestamps instead of relying only on lexical string ordering.
Root Cause
token_count.timestampevents.Changes
forked_from_idfor Codex session files.session_meta.id.Datevalues, with warning + lexical fallback on parse failure.*.jsonlfiles under the Codex sessions root during refresh.forkedFromId.Tests Added
session_meta.id.Validation
Passed locally:
swift test --filter CostUsageScannerBreakdownTestsswift test --filter CostUsageFetcherTests./Scripts/compile_and_run.shgit diff --checkReal-data validation on local
.codexdata,Asia/Shanghaitimezone:2026-03-11:166,904,086tokens2026-03-11:166,904,086tokensBefore the fix, the same day was incorrectly reported around
8.4Btokens because forked child session replay dominated the result. Separately, upstream discovery could omit cross-day sessions stored under old path partitions.