Skip to content

Codex reviews record no token usage, though Codex persists it on disk for every run #2948

Closed

Description

@omicron-soft

What's missing

codex_reviews defaults to enabled, so Codex runs as a standard step in
/review and /ship. Nothing records what those runs consume. After a day of
shipping there is no way to answer "what did review cost me" from anything
gstack wrote.

Checked on v1.88.1.0:

  • bin/gstack-codex-probe → _gstack_codex_log_event emits codex_timeout,
    codex_auth_failed, codex_cli_missing, codex_version_warning,
    codex_model_unusable. Failures only, and it returns early unless
    $_TEL != off. With the default telemetry: off it writes nothing at all.
  • lib/outside-review-result.ts validates the response and its markers. It
    never looks at usage.
  • The review-log instruction "Preserve all reported modelUsage" only bites on
    the Claude-subagent fallback, where the host reports it. On the Codex path
    there is nothing to preserve it from, because the invocation throws the
    numbers away (below).

The data is already there, twice over

1. The CLI prints it. The skill blocks call:

codex exec "$_OUTSIDE_PROMPT" -C "$_REPO_ROOT" -s read-only -c "model=..." ...

without --json, and the plain output ends with a trailer that gets dropped:

tokens used
12,029

With --json the same run emits it structurally:

{"type":"turn.completed","usage":{"input_tokens":12016,"cached_input_tokens":0,
 "cache_write_input_tokens":12013,"output_tokens":5,"reasoning_output_tokens":0}}

2. Codex persists it regardless. Every run writes
~/.codex/sessions/YYYY/MM/DD/rollout-<ts>-<session-id>.jsonl, containing
token_usage_record events:

{"type":"token_usage_record","payload":{
  "session_id":"01a0cfe1-...","turn_id":"01a0cfe1-...",
  "usage":{"input_tokens":12020,"cached_input_tokens":0,
           "cache_write_input_tokens":12017,"output_tokens":9,
           "reasoning_output_tokens":0,"total_tokens":12029},
  "thread_token_usage":{...cumulative...}}}

plus a session_meta carrying cwd, originator (codex_exec),
cli_version, and the model at
base_instructions.provenance.model.

So gstack does not need to wrap or intercept anything. It already knows the
session it started; it can read that rollout back, or pass --json and parse
turn.completed.

Why it matters beyond curiosity

#2519 (closed) reported 15.2M input tokens from a single /review, at up to
~1M input tokens/minute, with the parent spawning five review agents plus nested
codex exec calls. That reporter found it only by digging through Codex rollouts
by hand. Anyone hitting the same runaway today still gets no signal from gstack
itself — the pass simply completes and the bill arrives later.

#2188 asks for usage caps and light-ship toggles. A cap needs a measurement
first; this is that measurement.

Suggested shape

After each Codex invocation, attach usage to the row the pass already writes:

{"skill":"review","outside_provider":"codex","outside_status":"completed",
 "model":"gpt-6-sol",
 "usage":{"input_tokens":...,"cached_input_tokens":...,"output_tokens":...,
          "reasoning_output_tokens":...,"total_tokens":...}}

Two things follow cheaply once that exists:

  • /ship's review-status table gains a token column per pass, so a runaway is
    visible while it is happening rather than on the invoice.
  • The existing codex_reviews switch gets a measurable counterpart: cap or warn
    at N tokens per pass.

Worth logging even when telemetry: off — this is local cost accounting, not
telemetry, and it is arguably the wrong thing to gate on a data-sharing setting.

Meanwhile

Since the rollouts hold everything, a read-only reporter needs no changes to
gstack: scan ~/.codex/sessions/**/rollout-*.jsonl, take the last
thread_token_usage per file (cumulative, so resumes do not double-count), and
group by day / model / cwd. I wrote one for my own use and it reconciles
exactly with what the CLI printed. Happy to contribute it as
bin/gstack-codex-usage if that is a direction you want.

Environment: gstack 1.88.1.0, codex-cli 0.156.1, Linux (WSL2), telemetry: off.

Activity

  1. capy-ai commented on Oct 11, 2026

    @capy-ai
    Contributor

    Thanks @omicron-soft for the idea. In the Oct 11 triage we grouped the open feature requests by theme so related asks get built together instead of one at a time. This one is part of the Provider pluralism theme in TODOS.md (https://github.com/garrytan/gstack/blob/50d020ad9/TODOS.md#L54-L69), tracked as a whole in #3138. Closing it here so the open list stays actionable; it isn't rejected, and the theme credits every linked reporter when it's picked up.

  2. added
    parked
    on Oct 25, 2026
  3. capy-ai commented on Oct 25, 2026

    @capy-ai
    Contributor

    Reopened under the parked label: this is tracked in the Provider pluralism theme in TODOS.md and tracking issue #3138 (https://github.com/garrytan/gstack/blob/main/TODOS.md#p3-feature-themes-from-the-wave-9-triage-filed-2026-10-11), and what fixes it is one provider seam for outside voices, image providers and review bots, which these requests then plug into. Closed-but-tracked read as closed, so parked issues now stay open until they ship, are duplicates, or are declined (https://github.com/garrytan/gstack/blob/main/docs/triage.md).

  4. added
    S3
    enhancement
    on Oct 31, 2026
  5. capy-ai commented on Oct 31, 2026

    @capy-ai
    Contributor

    Thanks @omicron-soft for this report. #3729 does the first part: when a Codex outside review runs with --events (/review, /ship, /autoplan, the plan reviews, /codex), gstack now prints OUTSIDE_USAGE: with the token counters Codex reported (input, cached input, output, reasoning, plus cache-write and total when present), or OUTSIDE_USAGE: unknown. It also merges the two usage parsers into one, and that parser no longer undercounts sessions with more than one turn.

    It doesn't yet store usage in review-log rows, cover the native codex review rollout path, or add a token column to /ship. Those come in a follow-up, so this issue stays open.

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

    S3enhancementparked

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions