Repository navigation
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 |
|
Thank you for the contribution. I am sorry that the Rust migration made this no longer mergeable as-is. The production CLI has moved from the TypeScript implementation to the Rust implementation under If this idea or bug fix is still needed, please reopen it as a fresh Rust implementation against the current CLI. The underlying idea may still be useful, but this TypeScript patch is obsolete now. |



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.