fix(codex): ignore duplicate token_count totals#824
fix(codex): ignore duplicate token_count totals#824KosBeg wants to merge 1 commit intoryoppippi:mainfrom
Conversation
📝 WalkthroughWalkthroughModified the data loader to detect and handle duplicate token usage events. Introduces a new Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |



Summary
Codex session logs can emit duplicate
token_countevents where the cumulativetotal_token_usagedoes not advance. The loader previously trustedlast_token_usageunconditionally, which causes duplicated deltas and inflates all token totals (often close to x2). This change skipslast_token_usagewhen totals are unchanged, and only derives deltas from totals whenlastis missing.Why this happens
Codex logs contain both:
info.last_token_usage: per-event deltainfo.total_token_usage: cumulative totalsIn practice, some sessions emit the same
token_countpayload twice without advancing the cumulative totals. When we sumlast_token_usagefor every event, those duplicates are counted again even thoughtotal_token_usageshows no progress.Example from real logs (simplified)
Event A (first emission):
Event B (duplicate emission, totals unchanged):
Old behavior:
New behavior:
How the fix works
total_token_usageper sessiontotal_token_usageequals the previous total, treat theevent as a duplicate and ignore
last_token_usagelast_token_usageis missing but totals exist, derive a delta from thetotals (existing behavior)
What changed
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.