Skip to content

fix(codex): scope event dedupe to sessions - #1459

Closed
MaxGhenis wants to merge 2 commits into
ccusage:mainfrom
MaxGhenis:codex-session-scoped-dedupe
Closed

MaxGhenis wants to merge 2 commits into
ccusage:mainfrom
MaxGhenis:codex-session-scoped-dedupe

Conversation

@MaxGhenis

@MaxGhenis MaxGhenis commented Jul 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • include Codex session provenance in loader and report-aggregation dedupe keys
  • keep identical events from independent sessions distinct in daily, weekly, and monthly reports
  • continue collapsing duplicate records within one session
  • rely on structural parser removal of copied fork prefixes for cross-file replay, rather than treating equal token values as event identity
  • add reconciliation coverage for independent identical sessions and retain realistic copied-prefix coverage

The collision probe and oracle comparison use the same independent fixture methodology documented in the Logpile accounting review. The exact 2026-07-18 probe behind this change is published as the 2026-07-18 ccusage verification.

Stacked on #1457 — the parser-level copied-prefix removal there is what lets dedupe stop treating value equality as event identity, so this branch includes that commit and fails its copied-history tests without it. Will rebase once the replay PR merges.

Testing

  • cargo +1.96.0 test --manifest-path rust/Cargo.toml --workspace --offline (445 passed)
  • loader tests: 17 passed
  • aggregate tests: 5 passed
  • independent identical-session probe matches the oracle in daily and session reports; the session report retains two groups
  • copied parent history remains excluded after structural replay parsing

Prepared with AI assistance; I reviewed the implementation and test results.


View with Codesmith Autofix with Codesmith
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.


Summary by cubic

Scopes Codex dedupe to sessions and adds structural fork-replay detection, so identical usage from different sessions is kept while copied parent history is counted only once. This fixes undercounting across independent sessions and keeps intra-session duplicates collapsed.

  • Bug Fixes

    • Scope value-based dedupe to the session by including session_id in loader keys and aggregation keys; remove report-kind from the key.
    • Keep matching token events from independent sessions in daily/weekly/monthly and session reports; totals reconcile across views.
    • Drop copied parent history from forked sessions via parser; same-second local work remains counted.
    • Preserve model alias resolution while not merging distinct sessions.
  • Refactors

    • Add parser logic to detect fork replay boundaries using adjacent session_meta, native task_started, and a legacy creation-second heuristic; skip replayed token_count events before the live turn.
    • Expand test coverage with modern and legacy fixtures for multi-second replays and same-second forks.

Written for commit 95ed95e. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • Bug Fixes
    • Corrected Codex usage aggregation so identical events from separate sessions are counted independently.
    • Improved replay and fork handling to count inherited history once while preserving new session activity.
    • Fixed aggregation totals across daily, weekly, monthly, and per-session reports.
  • Tests
    • Expanded coverage for modern and legacy replay formats, same-second forks, and multi-session usage scenarios.

MaxGhenis and others added 2 commits July 18, 2026 15:57
Prepared with AI assistance (audit + implementation: gpt-5.6-sol; review: Claude Fable 5); reviewed and tested before filing.

Co-Authored-By: gpt-5.6-sol <[email protected]>
Co-Authored-By: Claude Fable 5 <[email protected]>
Prepared with AI assistance (audit + implementation: gpt-5.6-sol; review: Claude Fable 5); reviewed and tested before filing.

Co-Authored-By: gpt-5.6-sol <[email protected]>
Co-Authored-By: Claude Fable 5 <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

This PR was auto-closed. Only contributors approved with lgtm can open PRs. Open an issue first.

Maintainers review auto-closed issues and reopen worthwhile ones. Issues that do not meet the quality bar in CONTRIBUTING.md may not be reopened or receive a reply.

If a maintainer replies lgtmi, your future issues will stay open. If a maintainer replies lgtm, your future issues and PRs will stay open.

See CONTRIBUTING.md.

@coderabbitai

coderabbitai Bot commented Jul 19, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e7890113-1ced-41e3-b585-b621dc8c638e

📥 Commits

Reviewing files that changed from the base of the PR and between 7acee6c and 95ed95e.

📒 Files selected for processing (8)
  • rust/crates/ccusage/src/adapter/codex/aggregate.rs
  • rust/crates/ccusage/src/adapter/codex/loader.rs
  • rust/crates/ccusage/src/adapter/codex/mod.rs
  • rust/crates/ccusage/src/adapter/codex/parser.rs
  • rust/crates/ccusage/tests/fixtures/codex/fork-local-same-second-legacy.jsonl
  • rust/crates/ccusage/tests/fixtures/codex/fork-local-same-second-modern.jsonl
  • rust/crates/ccusage/tests/fixtures/codex/replay-multisecond-legacy.jsonl
  • rust/crates/ccusage/tests/fixtures/codex/replay-multisecond-modern.jsonl

📝 Walkthrough

Walkthrough

Changes

Codex replay parsing now derives line-aware boundaries from session ancestry and task-start events for modern and legacy logs. Aggregation deduplication always includes session identity, preserving matching usage from distinct sessions while counting copied parent history once. Tests and fixtures cover replay boundaries and reconciled daily/session totals.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant SessionFile
  participant ReplayBoundary
  participant CodexParser
  participant Aggregator
  SessionFile->>ReplayBoundary: parse session_meta and task_started records
  ReplayBoundary-->>CodexParser: return replay boundary
  CodexParser->>CodexParser: filter inherited token_count events
  CodexParser->>Aggregator: emit accepted usage events
  Aggregator->>Aggregator: deduplicate using session-aware keys
Loading

Possibly related PRs

Suggested reviewers: ryoppippi, pullfrog

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@ryoppippi

Copy link
Copy Markdown
Member

Historical audit: this pull request was auto-closed by the legacy contributor gate. That closure did not assess technical importance.

Audit result: needs review. The current state does not prove resolution, but a fresh technical or product check is required before deciding whether the underlying request is still relevant. This closed PR will not be revived as-is; create a new PR only after reviewing the related issue and current main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

triage:needs-review Requires a fresh technical or product decision.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants