Summary
Codex child rollout files contain copied parent token history followed by the child's new work. Token Meter groups these files under the shared session_id and prices every token_count.last_token_usage row, so inherited history is counted repeatedly.
Tested against main at 79f1759d854c84ecda4858b3e350755bf765c894 on macOS.
Evidence
- At one fixed checkpoint, Token Meter displayed $2,503.041764 and 3.63B priced tokens.
- Removing only exact inherited prefixes and 39 adjacent duplicate snapshots produced $156.084712 and 200.91M priced tokens: 16.04× inflation.
- The checkpoint contained 54 physical traces for five logical tasks; 49 traces were children.
token_meter/runtimes/codex.py:190-195 prefers the shared session_id as the source ID.
token_meter/runtimes/codex.py:227-229 selects payload.session_id before the unique payload.id.
token_meter/runtimes/codex.py:878-905 prices every token-count row without accounting for lineage.
- Related issue #2 covers duplicate Claude sources, but choosing one canonical Codex file would lose legitimate child work. Codex children require inherited-prefix removal.
Impact
Daily, session, model, and budget totals can be overstated by an order of magnitude when Codex uses multiple or nested subagents. Users may also interpret the API-equivalent estimate as actual subscription spend.
Suggested fix
- Preserve separate physical trace ID, logical session ID,
forked_from_id, and parent_thread_id fields.
- For each child, remove only the longest exact token-event prefix shared with
forked_from_id, falling back to parent_thread_id.
- Compare model plus numeric
last_token_usage fields and ignore timestamps because copied history is re-stamped.
- After prefix removal, skip only adjacent events whose model,
last_token_usage, and total_token_usage are all identical.
- Continue pricing
last_token_usage; do not price cumulative-total deltas.
- Label Codex dollars as estimated public API equivalent.
Acceptance criteria
- Root, direct-child, and nested-child fixtures count inherited history once.
- Children without a resolvable exact prefix retain all events.
- Adjacent exact snapshots are removed only after lineage matching.
- Session, Daily, Models, and budget totals agree after correction.
- The reproduced checkpoint is approximately $156.08, not $2,503.04.
If accepted I can work on fixing this
Summary
Codex child rollout files contain copied parent token history followed by the child's new work. Token Meter groups these files under the shared
session_idand prices everytoken_count.last_token_usagerow, so inherited history is counted repeatedly.Tested against
mainat79f1759d854c84ecda4858b3e350755bf765c894on macOS.Evidence
token_meter/runtimes/codex.py:190-195prefers the sharedsession_idas the source ID.token_meter/runtimes/codex.py:227-229selectspayload.session_idbefore the uniquepayload.id.token_meter/runtimes/codex.py:878-905prices every token-count row without accounting for lineage.Impact
Daily, session, model, and budget totals can be overstated by an order of magnitude when Codex uses multiple or nested subagents. Users may also interpret the API-equivalent estimate as actual subscription spend.
Suggested fix
forked_from_id, andparent_thread_idfields.forked_from_id, falling back toparent_thread_id.last_token_usagefields and ignore timestamps because copied history is re-stamped.last_token_usage, andtotal_token_usageare all identical.last_token_usage; do not price cumulative-total deltas.Acceptance criteria
If accepted I can work on fixing this