Skip to content

Codex sessions miss native sub-agent tokens and record no observed Model #1651

Open

Description

@JacobStephens2

This was generated by AI during triage.

What happens

On Codex, a session's Run metrics count only the parent thread. Two things are missing:

  1. Native sub-agent tokens. When the Codex session spawns its own sub-agents (Codex's built-in thread_spawn), for example the two parallel reviewers that thirdshift-code-review asks for, their tokens never reach run_metrics.session_signals.
  2. The observed Model. Every Codex session's tokens_by_model entry has "model": null, and .models.json has "observed": [], even though Codex records the model it ran.

Evidence

From one Ticket run on Codex CLI 0.166.0 with gpt-6.1-sol high (thirdshift 0.18.5). The Codex rollouts are under the account's ~/.codex/sessions/<date>/:

Codex thread turn_context.model Final total_token_usage (input / cached / output) In thirdshift's implement totals?
parent (exec) gpt-6.1-sol 2,251,744 / 2,183,040 / 11,695 yes, exactly
sub-agent, source.subagent.thread_spawn.parent_thread_id = the parent gpt-6.1-sol 424,798 / 398,976 / 4,375 no
sub-agent, same parent gpt-6.1-sol 421,916 / 389,376 / 4,996 no

The implement session's recorded totals therefore under-count input by about 38% and output by about 80%. A Continuation of the same run showed the same pattern: parent 1,623,657 input counted, two sub-agents with 720,429 input not counted. The Security review session spawned no sub-agents, and its totals match its rollout exactly.

The parent's thread ID appears in thirdshift's Session trace (thread.started). Each sub-agent rollout names that ID as its parent_thread_id, so the rollouts can be joined to the session without guessing.

Why it matters

Per-Command token and cost figures, Experiment Arms (#1468) and any Process comparison under-count Codex work whenever a skill fans out to sub-agents. A Codex Ticket run with a two-axis code review looks cheaper than it is. Comparisons against a Claude Code Arm are skewed too, if Claude's Agent-tool subagents are counted there, which #1639 notes is inferred but not documented.

Related

Recommendation

bug. State needs-triage: the obvious fix reads the session's Codex rollouts (the parent by thread ID, and sub-agents by parent_thread_id), adding sub-agent usage once, by observed model, and taking the parent's model from turn_context. Whether to rely on rollout files is #1047's open decision. Once that's settled, this is agent-sized.

Activity

  1. added
    bug
    needs-triage
    on Oct 30, 2026
  2. added
    in-progress
    and removed
    needs-triage
    on Nov 10, 2026
  3. JacobStephens2 commented on Nov 10, 2026

    @JacobStephens2
    OwnerAuthor

    This was generated by AI during triage.

    Investigation summary

    The gaps remain on selected Base main at ecaf0d4.

    Confirmed from code and fixtures:

    • src/harness/codex/events.rs:47 emits parent turn usage; its native sub-agent handling at :172 emits lifecycles without usage measurements.
    • src/harness/codex/stream.rs:233 supplies no observed Model evidence. src/harness/interpretation_tests.rs:1111 explicitly verifies empty observed Models, including when a Model was requested.
    • src/session/recording/tests.rs:92 records the Codex fixture with model:null and exactly 100 input, 20 cached and 7 output tokens despite its native child-agent event.
    • src/session/usage.rs:206 falls back to unknown-model turn totals. Run metrics and Experiment Arms consume this shared usage module through src/logs/session_signals.rs and src/evals/experiment/usage.rs. Updating .models.json alone would leave token attribution incomplete.

    Existing rollout access is narrower than the proposed fix: src/harness/codex/patches.rs reconciles patch details, and src/harness/codex/limits.rs reads exact-session quota observations. Neither recovers Models or native descendant usage. These readers provide precedent and an implementation seam, but do not settle the additional accounting contract.

    Decision and proposed shaping

    #1047 remains open with no Trusted-account decision approving the additional evidence source. Decide whether optional rollout enrichment for observed Models and native usage may proceed independently of its per-request lifecycle question. Preserve the distinction between aggregate usage and model-request boundaries.

    Propose two Tickets after that decision: (A) observed Model attribution and normalized parent usage through retained reconciliation; (B) native descendant usage by observed Model, including exact membership, deduplication and attribution across Resumes. Require both retained-trace and Run metrics/Arm projections to agree. Separately launched agent CLIs remain #1639's scope. No matching duplicate was found.

    Validation and limits

    cargo test --bin thirdshift codex: 31 passed, one ignored pending #1047. The recording-fixture check passed; session::usage::tests: 10 passed. scripts/affected-tests main reported no changed files. Tests emitted process-environment permission warnings but passed. The original account rollouts were not supplied within this worktree, so their schema and reported production totals were not independently verified.

    Questionnaire

    For the Day shift deciding #1651: local code and fixture checks confirm missing observed Models and no native child-usage ingestion. Existing rollout readers handle patches and quotas; #1047 still leaves broader evidence sourcing undecided.

    1. May Codex sessions miss native sub-agent tokens and record no observed Model #1651 use optional native rollout evidence for observed Models and native descendant usage independently of Decide Codex per-request evidence for Session traces #1047's per-request lifecycle decision? Recommended: approve this bounded scope, preserve streamed parent evidence when native evidence is unavailable or ambiguous, and never fabricate request boundaries.
    2. Approve splitting the work into two Tickets: A, observed Model attribution plus normalized parent usage and the retained-reader foundation; B, blocked by A, native descendant accounting by observed Model, with deduplication and per-attempt attribution across Resumes? Recommended scope includes nested descendants and regression coverage proving no cumulative usage is counted twice; separately launched CLIs stay with Run metrics miss the tokens of agent CLIs a session starts itself #1639.
    3. Can the Day shift or original operator attach redacted parent/child rollout fixtures from the reported Codex version, including session_meta, turn_context and token_count records spanning a Resume? These would establish the native schema and cumulative-counter boundaries without requiring machine access or secrets.
  4. added
    ready-for-human
    and removed
    in-progress
    on Nov 10, 2026
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

    bugready-for-human

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions