[Bug]: Codex Agents panel counts inherited parent history in each child token total #5793
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#
- Start a long-running T3 Code thread using the Codex app-server provider.
- Have the parent agent spawn two or more native Codex subagents.
- Open the Agents panel or inspect the subagent CTA while the children are working.
- Compare each child's reported
thread/tokenUsage/updatedtotal 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:
| Child | Starting inherited total | Later raw total | Actual new usage |
|---|---|---|---|
| A | 5,800,940,557 | 5,803,101,943 | 2,161,386 |
| B | 5,801,183,295 | 5,803,507,447 | 2,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:
The CTA then sums every agent's stored total:
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:
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
Bsuffix rather than thousands ofM.
Related work#
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.
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.
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
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 labeledrun 2) showed ~136M tok each. Same notification hadlast.totalTokens = 31,908andtotal.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:
thread/tokenUsage/updatedis forwarded ascollabAgent/tokenUsage, thenCodexAdapterstorestokenUsage.totalastypedUsage.totalTokens. Comment in tree: usetotal, neverlast, because last shrinks on follow-ups. https://github.com/pingdotgg/t3code/blob/a3a8cbd60539b4af4de8f96c892dbd07a2b6c041/apps/server/src/provider/Layers/CodexAdapter.ts#L671-L704usedTokens = last.totalTokens,totalProcessedTokens = total.totalTokens. The context meter labels those “used” vs “Total processed”. https://github.com/pingdotgg/t3code/blob/a3a8cbd60539b4af4de8f96c892dbd07a2b6c041/apps/server/src/provider/Layers/CodexAdapter.ts#L160-L178agent.usage.totalTokens(AgentsPanel.tsx,MessagesTimeline.tsx). Client fold max-merges and does not clear usage on idle→running.codexMultiAgentWire.json): childtotalis per child thread, not the parent thread. First child turn haslast === total. Next update is the sum oflastframes. Thoselastframes already include cached input.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
lastalone is not a full lifetime metric; subtracting each child’s startingtotal(this issue’s suggested direction) still matches the live billions case. Either way, summing raw childtotals 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
totalthat does not start at zero.Cursor / OpenCode / Grok do not emit this
typedUsagepath. Claude uses a different SDK total. Mobile has no Agents panel.