Skip to content

Codex forked sessions can double count replayed parent token history #1370

Description

@sijie-ni-0214

What happened?

Codex Desktop forked session logs can contain a copied prefix of the parent session history. The fork file has session_meta.payload.forked_from_id, then embeds the parent session metadata and replays the parent's historical token_count events with timestamps rewritten to the fork creation time.

ccusage codex daily currently treats those replayed token_count events as new usage. This can inflate the fork day and count the same parent usage again, especially when multiple archived fork snapshots are present.

I hit this locally with three archived fork snapshots of the same parent session. Each snapshot reported the same historical token sequence but under new timestamps, which made the daily total jump unexpectedly.

A fix PR is here: #1369

Steps to reproduce

  1. Create a Codex session with two token_count events.
  2. Create a forked Codex JSONL file that starts with a session_meta payload containing forked_from_id.
  3. Copy the parent token_count events into the forked file, with timestamps rewritten to the fork creation second.
  4. Add one real fork token_count event after the replay prefix.
  5. Run ccusage codex daily --json or load the fixture through the Codex adapter.

The replayed parent events are counted again under the fork session/day.

Expected behavior

For forked Codex sessions, replayed parent token_count history should be skipped. Only the parent session's original events and real fork events after the replay prefix should be counted.

The existing thread-spawn subagent replay skipping path already handles a similar shape; forked sessions can reuse that logic when forked_from_id is present.

Version

20.0.14

Activity

  1. pullfrog commented on Jun 25, 2026

    @pullfrog
    Contributor
  2. github-actions commented on Jun 25, 2026

    @github-actions
    Contributor

    This issue was auto-closed. Issues from new contributors are auto-closed by default.

    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.

    Keep the issue short, concrete, and written in your own voice.

    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.

  3. ryoppippi commented on Aug 31, 2026

    @ryoppippi
    Member

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

    Audit result: resolved. A later merged change or the current main implementation covers this request. This item is kept for history and does not need to be reopened.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    triage:resolvedResolved by a later change or current implementation.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions