Repository navigation
Conversation
Each Codex turn writes one token_count event with that turn's last_token_usage and the session's cumulative total_token_usage. Summing last_token_usage across a session reproduces its final cumulative total, except that some turns are written twice with identical last_token_usage and an unchanged cumulative total. The scanner added both. On one machine that was 232 duplicate events among 12,675, 21.1M tokens or 1.8% of Codex usage, and 181 extra prompts. Across the 831 sessions whose totals never reset, skipping them makes the summed turns equal the final cumulative total exactly. Skip an event whose total_token_usage.total_tokens equals the previous event's in the same file. A drop in the total can indicate a resumed or compacted session and still counts. The first event of a file has no previous total, so this check never skips it. Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com> Co-authored-by: GPT-6 Astra <noreply@openai.com>
st-eez
force-pushed
the
codex-duplicate-turn
branch
from
September 7, 2026 06:21
cc20767 to
58496b9
Compare
Member
|
Automated duplication check: this pull request looks similar to #10531, which covers the same Codex token snapshot skip. I keep that one open and close this one to consolidate review. If you feel this is the wrong decision, please open the PR again with a note on the difference. |
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.
scan_native_codex_sessionsaddslast_token_usagefrom everytoken_countevent. That reproduces the session's own
total_token_usage, except that someturns are logged twice with identical usage and an unchanged running total, and
the scanner counts both.
Measured on 887 session files: 232 duplicate events among 12,675 with usage,
21,129,968 tokens (1.8%) and 181 extra prompts. In the 831 sessions whose
running total never resets, the corrected sum equals the final cumulative
total exactly. The uncorrected sum is 1.6% over.
The fix skips an event whose
total_token_usage.total_tokensequals theprevious event's in the same file. A drop can indicate a resumed or compacted
session and still counts. The first event of a file has no previous total, so
the check never skips it.
Verification
Two new cases in
test/shell.d/agent-usage-codex-scanner-test.sh:last_token_usageand sametotal_token_usage, counts that turn once (fails onquattro)follows the drop (passes on
quattroand guards the fix)All nine resets in the measured history remain counted. None of the skipped
events carried usage the running total had not already absorbed.