Skip to content
Source
Sign inSign up
pingdotgg/t3code

[Bug]: Usage page never scans Codex archived_sessions/, so archived sessions' usage silently disappears #7090

Openjameswasher(GitHub profile, opens in a new tab) opened this issue 5 comments

Before submitting

  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.

Area

apps/server

Steps to reproduce

  1. Use Codex interactively, then archive some sessions (rollouts move from ~/.codex/sessions/ to ~/.codex/archived_sessions/).
  2. Open the Usage page for a window covering that work.
  3. Compare the reported Codex tokens/cost against the transcripts actually on disk.

Observed behavior

UsageService.resolveTranscriptDirs resolves only <codexHome>/sessions for the Codex provider, so rollouts in archived_sessions/ are never scanned — even though the Codex shadow-home layout elsewhere in the codebase treats archived_sessions as a known shared directory alongside sessions.

On my machine the effect is dramatic:

  • ~/.codex/archived_sessions/ holds 2.7 GB, with 148 files modified inside the 30-day window, containing ~6,700 gpt-5.6-sol turn-context records — this is where nearly all of my real interactive Codex work lives.
  • The scanned ~/.codex/sessions/ retains only ~300 gpt-5.6-sol records; the rest of it is dominated by codex-auto-review traffic (~31,000 model records).
  • The Usage page therefore reports 177M priced Codex tokens ($131.09) for the window; the true interactive figure is several times that.

Compounding it, codex-auto-review has no LiteLLM rate, so the 885M tokens that are scanned price at $0.00 (the display side of that is tracked in #5799). Net result: Codex usage is doubly understated — most real usage is invisible, and most visible usage is unpriced.

Expected behavior

Usage should cover archived sessions: scan archived_sessions/ alongside sessions/. Transcripts are append-only and the existing mtime filter + (size, mtime) scan cache already bound the cost of the extra walk. At minimum, the page should disclose that archived sessions are excluded from the totals.

  1. +1

    The codex-auto-review being left without pricing makes the raw token cost tracking questionable as that model isn't cheap and I have coworkers telling me it burns through there limits. Impossible to verify without detailed price tracking to know how much of the token usage is discounted due to caching.

  2. I really want to know my actual Codex API spend without unarchiving all of my chats 😆

  3. tanstack-source added labelsbug

  4. Since #34829, this affects all delegated Codex work by default, not only sessions a user archives. T3 now calls thread/archive on each finished delegated Codex child, so Codex moves that child's rollout into archived_sessions/. codexUsageReader.directories still returns only <CODEX_HOME>/sessions, so the Usage page stops counting the child's usage.

    On our install, running nightly 4606 since 2026-11-13, there are now 132 rollouts in archived_sessions/. Every one of them was written by T3 for a delegated child. Over the same period, 42 new rollouts stayed in sessions/.

    As a local workaround, we return archived_sessions as a second directory from codexUsageReader.directories, after sessions. The usage summary already removes duplicate Codex records across files (sharedSessionsAcrossFiles), so a rollout that was scanned in sessions/ and then moved still counts once.

    A test covers this:

    1. Scan a 17-token rollout.
    2. Move it into archived_sessions/ and add a 23-token rollout that only exists there.
    3. The total is 40 tokens, both before and after a restart.

    #21666 covers more cases than this workaround, but its automated pipeline stopped.

    Measured and written by Claude (Opus 5.5) in T3 Code; posted with the owner's approval.

  5. Still happening on 0.1.12-nightly.20261123.5151 (Linux). Delegated Codex workers make it much worse, as the previous comment describes.

    What happened: a lead thread sent a fix round to 67 delegated Codex children (gpt-6.2-astra), which ran from 02:34 to about 08:00 UTC. T3 archived each child when it finished, so its rollout moved to ~/.codex/archived_sessions/. In usage-scan-cache-v17.json, the latest row from those rollouts is at 02:40 UTC, six minutes into the run. Nothing after that was ever counted.

    Missing from the Usage page, 25 Nov from 02:00 UTC on:

    • 501M input tokens (486M cached) and 1.63M output tokens.
    • The page shows about $20 of Codex for that window. At the page's own per-token rates, the missing part is roughly $380.

    Over 23–25 Nov:

    • 301 rollouts now in archived_sessions/: 130 never appear in the scan cache, and 157 were cached only part of the way.
    • 2.37B input tokens (2.30B cached) and 10.1M output tokens in them were never read.

    The usage itself was real: the server-reported rate_limits.primary.used_percent in those same rollouts went from 87% to 100% of the weekly limit during the run.

    For anyone using delegated Codex workers, the Usage page currently shows only a small part of their Codex usage. It would be great if someone could finish or take over #21666.

    Measured and written by Claude (Opus 5.5) in T3 Code; posted with the owner's approval.

  6. I reproduced this on Windows with T3 Code Nightly 0.1.14-nightly.20261130.5479. The installed codexUsageReader.directories returns only <CODEX_HOME>/sessions. Usage records in archived_sessions are absent from the scan cache unless a scan read them before the rollout moved.

    For the 24 hours ending December 1, 2026 at 01:09 UTC+08:00, I compared the local OpenCodex request log with Codex rollout records and T3 Code’s usage-scan-cache-v18.json.

    Records in the same windowRequestsTokens
    OpenCodex request log4,914450,336,694
    Present in T3 Code’s cache1,383100,578,160
    Present in archived T3 Code rollouts and absent from the cache3,405341,385,795
    Present in active sessions after the last scan382,630,281
    Router requests without a matching rollout record885,742,458

    I matched requests by completion time and exact input, output, cached input, and reasoning token counts. The archived records matched the router and came from 80 rollouts marked originator: T3 Code. They explain 97.6% of the gap. The totals include cached input as part of input.

    A reproduction case is to finish or archive a Codex session before the Usage page scans its latest turns. A fresh scan should include those turns and count each request once when its rollout moves from sessions to archived_sessions.

Sign in to join this conversation.