Skip to content

Codex usage is counted again after forking or cloning a Pi session #8564

Description

@Duro02

System details

Lenovo ThinkBook 14 G3 ACL, AMD Ryzen, Omarchy 4.0.1-1, Pi 0.84.3, pi-subagents 0.56.0, openai-codex provider

What's wrong?

After a Pi session is forked or cloned, the Codex usage shown in Omarchy's Agents panel includes the inherited historical usage from both the parent session file and the forked session file.

Creating the fork copies existing Pi message entries, including their already-recorded usage metadata, into a new session file. Those copied records do not represent new Codex responses. If work then continues in the fork, only the newly generated responses and their newly reported usage should be additional usage.

This can significantly inflate the local Prompt, Token, and Session statistics when multiple subagents use forked context.

Steps to reproduce

  1. Start a Pi session using the openai-codex provider.
  2. Exchange enough messages to produce recorded token usage.
  3. Fork or clone the session using Pi, or launch a subagent with context: "fork".
  4. Refresh the Omarchy Agents panel.
  5. Compare the reported local usage before and after the fork.

Expected behavior

Usage metadata attached to messages copied from the parent should be counted only once. New assistant responses generated inside the fork should still add their newly reported usage normally.

Actual behavior

The inherited assistant-message records are counted again for every forked session file.

On my machine, three forked sessions contained parent-derived historical usage totaling:

  • 15,716,982 tokens
  • 87,744,714 tokens
  • 87,744,714 tokens

This caused approximately 191,206,410 tokens of local usage to be counted more than once.

I verified these as inherited copies by following each session header's parentSession path and comparing the copied message IDs, timestamps, content, model, and usage data with the declared parent session.

Technical observation

Pi forked-session headers contain a parentSession field. Inherited message entries retain their original IDs, timestamps, contents, and usage records.

The current collector builds its deduplication key using both the file path and message ID:

message_key = path + ":" + str(entry.get("id") or "")

Because every fork has a different file path, inherited copies are treated as separate usage records. This is only a diagnostic observation; the appropriate deduplication strategy is left to the maintainers.

Activity

  1. added a commit that references this issue on Sep 25, 2026
    6a4be6a
  2. omarchybot commented on Oct 4, 2026

    @omarchybot
    Collaborator

    Fixed on quattro by #14049. Pi forked-session usage is deduplicated by the copied message id and timestamp instead of by its file path, while new responses still contribute usage. This incorporates #8602.

    Closing as completed. If the same failure persists after updating to a build containing the fix, please reopen with the collector output.

    Closure scope checked by GPT-6 in Codex and Codex Medium against the reports and landed source. The second opinion agreed; independence is not guaranteed. No runtime tests were rerun for this reconciliation.

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

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions