Skip to content
Source
Sign inSign up
pingdotgg/t3code

[Bug]: Codex Agents panel counts inherited parent history in each child token total #5793

Closedrabesss(GitHub profile, opens in a new tab) opened this issue 2 comments

Before submitting

  • I searched existing issues and open PRs and did not find a duplicate or pending fix.
  • I included enough detail to reproduce or investigate the problem.

Area

apps/server

Steps to reproduce

  1. Start a long-running T3 Code thread using the Codex app-server provider.
  2. Have the parent agent spawn two or more native Codex subagents.
  3. Open the Agents panel or inspect the subagent CTA while the children are working.
  4. Compare each child's reported thread/tokenUsage/updated total with its cumulative token total at the start of the child task.

Expected behavior

Each subagent should contribute only the tokens generated by that child after it was spawned.

Summing multiple children should therefore show the combined new work performed by those children, without counting the inherited parent conversation once per child.

Actual behavior

Codex child threads begin with the parent conversation's cumulative token history. T3 treats each child's raw tokenUsage.total.totalTokens value as usage generated by that child and then sums those values in the Agents UI.

In one live reproduction with two children:

ChildStarting inherited totalLater raw totalActual new usage
A5,800,940,5575,803,101,9432,161,386
B5,801,183,2955,803,507,4472,324,152

T3 summed the raw totals:

5,803,101,943 + 5,803,507,447 = 11,606,609,390

The CTA displayed:

Σ 11606.6M

The actual combined work performed by the children was:

2,161,386 + 2,324,152 = 4,485,538

The display should therefore have been approximately Σ 4.5M.

Likely cause

Current main maps the child notification's cumulative total.totalTokens directly into RuntimeTaskUsage:

https://github.com/pingdotgg/t3code/blob/ba9c9ae81dce4e554b4dd52abfd28d0c01b5c651/apps/server/src/provider/Layers/CodexAdapter.ts#L669-L689

The CTA then sums every agent's stored total:

https://github.com/pingdotgg/t3code/blob/ba9c9ae81dce4e554b4dd52abfd28d0c01b5c651/apps/web/src/components/chat/MessagesTimeline.tsx#L2163-L2168

This assumes a Codex child's cumulative total starts at zero. In practice, the child inherits the parent's existing conversation history.

The formatter also has no billions branch, so a genuinely billion-scale input is rendered as thousands of millions:

https://github.com/pingdotgg/t3code/blob/ba9c9ae81dce4e554b4dd52abfd28d0c01b5c651/packages/client-runtime/src/state/subagentRuntime.ts#L931-L939

Suggested direction

Normalize each Codex child's cumulative counters against its inherited starting baseline before storing or summing its usage.

The implementation should preserve monotonic accounting across child follow-ups and resumed activations. Simply switching every display to tokenUsage.last may not be sufficient because that value can shrink between follow-ups.

Suggested regression coverage:

  • A newly spawned child whose cumulative counter begins at a large non-zero value.
  • Two children with different inherited baselines.
  • A resumed child that must not reset or double-count prior child work.
  • Matching totals between the Agents panel and the spawn CTA.
  • A real total above one billion formatting with a B suffix rather than thousands of M.

These are related but do not fix this path:

  • #5758 covers replayed rollout history in the Usage analytics page.
  • #5681 / #5682 cover excessive Codex subagent progress-event volume, not the values inside the snapshots.
  • #4664 introduces the orchestrator-v2 Agents model but currently retains the same raw cumulative-total assumption, so the baseline behavior should also be covered there.

Impact

Minor bug or occasional failure

The agents themselves continue working, but the Agents panel's usage reporting becomes unusable and can overstate a small amount of child work by several orders of magnitude.

Version or commit

t3@0.0.33-nightly.20260808.1035 Installed app commit: a20923ce4633

Also reproduced by inspection against current main at ba9c9ae81dce4e554b4dd52abfd28d0c01b5c651.

Environment

Linux x86_64 Codex app-server provider Native Codex multi-agent/subagent notifications

Workaround

Ignore the Agents total and manually subtract each child's starting cumulative counter from its latest counter.

  1. This happened to me too. An agent investigated my personal Mac build and said it is unmodified upstream Agents/Codex-collab code, not a fork-only bug. Posting the extra trace here instead of opening a second issue. Hope it helps; if not, ignore or delete.

    Still present on current main (a3a8cbd60). Second live case: Codex native subagents (tiny probes, including a child labeled run 2) showed ~136M tok each. Same notification had last.totalTokens = 31,908 and total.cachedInputTokens = 132,374,272. Parent context meter on that thread did not look like 136M of new child work.

    Extra source notes (no patch)

    Proven in current source:

    Inferred: the 136M chip is Codex thread-lifetime processed tokens (cache re-counted every turn, and/or inherited parent history as in the table above), labeled as if it were this subagent’s work. Switching the headline number to last alone is not a full lifetime metric; subtracting each child’s starting total (this issue’s suggested direction) still matches the live billions case. Either way, summing raw child totals double-counts overlapping cache/history.

    Not proven here: that every new spawn shares one account-global counter. Routing does not copy parent usage onto children; each child gets its own notification. The huge shared baseline is still a Codex total that does not start at zero.

    Cursor / OpenCode / Grok do not emit this typedUsage path. Claude uses a different SDK total. Mobile has no Agents panel.

  2. Note

    🤖 GPT-6.1-Sol responding on behalf of Theo

    This issue should be resolved in the next nightly build by Orchestrator v2 (#2829).

    Please try that nightly. If the problem still exists, open a new issue with the nightly version you tested and steps to reproduce it.

Sign in to join this conversation.