Uh oh!
There was an error while loading. Please reload this page.
fix(usage): stop counting replayed codex rollout heads - #5701
Conversation
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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 |
Uh oh!
There was an error while loading. Please reload this page.
ApprovabilityVerdict: Needs human review This PR modifies usage metering logic to filter out replayed Codex rollout records based on timing heuristics. Changes that affect how usage/tokens are counted warrant human review to verify the filtering logic correctly identifies duplicates without dropping legitimate usage. You can customize Macroscope's approvability policy. Learn more. |
t3dotgg
commented
Aug 27, 2026
Note 🤖 GPT-5.6 Sol responding on behalf of Theo We're closing this PR as we clean up the T3 Code backlog. Thank you for taking the time to put this together. Closing because this timing-only filter can discard genuine usage from ordinary Codex sessions. #5887 already added replay suppression that first checks fork or subagent metadata. Any remaining overcount should be shown with a transcript so we can fix that case without removing valid records. If you believe we closed this in error, please reopen the PR and leave a comment explaining what we missed. If GitHub does not let you reopen it, leave a comment here and we'll take another look. |
What changed
Codex usage scanning now drops the replayed head of a rollout file before aggregation.
usageTranscripts.ts— new puredropReplayedRolloutHead: a file whose records open withtoken_countevents spaced under a second apart replayed a history it did not spend; the burst is dropped up to the first real pause. A lone leading event, or a head that opens at working pace, is left alone.UsageService.ts— applies it to Codex files, after the scan cache on purpose (cached entries keep the raw records, so the heuristic can evolve without a cache version bump).Why it should exist
parseCodexLinecurrently returnsdedupeKey: nullwith the comment "rollout files are unique per session, so events need no global dedup" — and that assumption doesn't hold. Resuming a session, forking it, and every subagent it spawns replay the entire conversation so far into a fresh rollout file,token_countevents included, with fresh timestamps. So there is no key and no clock to dedupe on, and the existing consecutive-duplicate filter (single-slot, per file) cannot see copies that live in another file. Every replayed event is counted again, and lands on the day the resume happened.The write pattern is what identifies a copy: replayed history is flushed in one sub-second burst at the head of the file, while real work has pauses between turns — a genuine first turn never emits two
token_counts within a second of each other. On our logs the double counting is far from cosmetic: days with heavy resume/subagent use read ~1.5× their true Codex volume, and a 90-day window read roughly a third high.Notes
session_meta'sforked_from_id/parent_thread_idfor exact prefix matching; the burst rule alone already removes the bulk of the double counting with far less machinery.Note
Medium Risk
Changes reported Codex token/session totals (often downward) via a timing heuristic; wrong classification could under- or over-count, but scope is limited to usage aggregation and is covered by unit tests.
Overview
Codex usage scanning now strips replayed rollout heads before aggregation so resume/fork/subagent copies of prior
token_countevents are not counted again.Adds
dropReplayedRolloutHeadinusageTranscripts.ts: if a file’s records start with consecutive events less than 1 second apart, that prefix is treated as copied history and dropped up to the first real pause; a single leading event or a head that already opens at working pace is unchanged. Comments on CodexdedupeKeynow point at this path instead of assuming one rollout per session.UsageServiceruns the filter only for Codex, after the per-file scan cache returns parsed records, so cached payloads stay raw and the heuristic can change without a cache version bump. Files that become empty after filtering count as skipped.Reviewed by Cursor Bugbot for commit 6b034bc. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Fix usage counting by filtering replayed rollout heads from Codex transcripts
dropReplayedRolloutHeadin usageTranscripts.ts, which removes the leading burst of events where consecutive gaps are under 1,000 ms — the signature of a replayed rollout head.provider === "codex"before counting records toward usage, sessions, and costs.Macroscope summarized 6b034bc.