pingdotgg / pingdotgg/t3code

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

Open
#5,793 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
23k
Forks
5.9k
Avg merge
11h 14m
Merged PRs (30d)
357

Description

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:

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:

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.
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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with apps/server/src/provider/Layers/CodexAdapter.ts lines 669-689 and compare the stored usage with the aggregation in apps/web/src/components/chat/MessagesTimeline.tsx lines 2163-2168. Then inspect packages/client-runtime/src/state/subagentRuntime.ts lines 931-939 and add regression coverage for inherited baselines, resumed children, matching totals, and billion-scale formatting; done means child totals count only new work and display correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
full-stack
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.