fix(usage): include archived Codex rollouts under one source #21666
codex-02/archive-compat fromrefs/pull/21666/head·opened View on GitHubProblem#
Codex usage omitted archived rollouts. Adding archived_sessions as a separate source also inflates combined totals when cached history overlaps after a rollout moves.
Change#
Read sessions and archived_sessions under one canonical Codex-home source. The provider extension supplies multiple transcript roots; the service retains cached roots, deduplicates aliases and copied rollouts, and marks directory-read failures partial. Recover canonical home identity from old root-cache metadata when a configured symlink disappears.
Scope and approval#
Addresses the archived-rollout omission in #7090. Maintainer accounting approval is pending; no approval comment is claimed.
Built from @maria-rcks’s archived-session fix in #15451. Adversarial review found that adding a second source could count moved rollouts twice across environments, so this replacement separates compatibility from scanning. Companion layer: #21664. Both layers must ship together. Human approval of the accounting change is still required; neither PR has been merged.
Compatibility: new clients omit Codex data from v4–v6 servers while retaining their other providers. Older v6 clients reject all usage from a v7 server until upgraded. Independently configured Codex homes that share only a symlinked sessions directory can still count twice across environments; standard aliases of the same home deduplicate.
Verification limitations: Linux server and web only. No macOS, Windows, iOS, Android, or Electron desktop run; no real upstream account or billing validation. Shared compatibility logic and web/mobile typechecks cover the native-client code change, but do not replace native verification.
Verification#
Validation: server/Codex usage tests 139 → 142 across nine existing files, including three service regressions; shared merge/format 37 → 39 across two existing files. The archive regression was 50 → 70 tokens. The narrow two-source implementation merged overlapping histories as 110 tokens; the rebuilt service returns 70. The migration regression was 100 → 50 tokens after a removed home alias. Scoped source lint/format and server/provider-core typechecks passed. Reviews: the initial narrow review found cross-environment double-counting; stack round 1 found a removed-alias cache migration bug. Both were reproduced and fixed. Opus and Sol independently reviewed the full updated stack in rounds 2 and 3 with no code blockers. Round 3 includes the CI cleanup that makes the former exported version helper private. Opus also ran 251 server usage/driver tests and 39 shared tests successfully.
Live isolated UsageService proof: active 10 + archived 20 + copied 40 = 70 once; moving a rollout and combining newer partial history with an older complete scan stays 70. Missing archived directories retain cached history, and unreadable roots report partial results.
CI found an unused exported helper, now fixed and verified with the scoped Knip exports check. Three unchanged browser suites passed 14/14 tests on both the actual base and this implementation in fresh focused runs; their CI failures were not reproduced locally. The latest full CI workflows pass on both layers: #21664 CI, attempt 2 at 077708030d, and #21666 CI at 3482136b91. The bottom layer passed after one rerun of the failed browser jobs. Human accounting approval remains pending on both layers. Earlier superseded workflows were cancelled during the stack push; their results are not the current workflow result.
Browser proof from the actual base (1451e7cb23) and implementation (captured at 12aa22b0dd; runtime behavior is unchanged by the subsequent export-only cleanup), same isolated transcript fixtures, 1280×800 viewport and provider filter. Active rollout 10 + archived rollout 20: 10 → 30 tokens.
Before — archived rollout omitted:

After — active and archived sessions, 30 tokens:

Implementation: Codex gpt-6.1-sol; tests: Codex gpt-6-astra; reviews: Claude Opus 5.5 and Codex gpt-6-sol, through T3 Code.
Closes https://git.cafe/pingdotgg/t3code/issues/7090
Fixes pingdotgg/t3code#7090
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
juliusmarminge changed the title
juliusmarminge added labelsmacroscope-review
Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
ℹ️ No successful
mainbaseline artifact is available yet. This run establishes the initial measurement.Provider Metric Main baseline This PR Impact PR ceiling Codex Total thread wire — 5.0 KiB — 6.8 KiB ✅ Codex Thread snapshot wire — 3.8 KiB — 4.9 KiB ✅ Codex Live turn WebSocket wire — 1.2 KiB — 2.0 KiB ✅ Codex Live turn WebSocket decoded — 20.9 KiB — 29.3 KiB ✅ Codex Live turn messages — 2 — 8 ✅ Claude Total thread wire — 5.0 KiB — 6.8 KiB ✅ Claude Thread snapshot wire — 3.8 KiB — 4.9 KiB ✅ Claude Live turn WebSocket wire — 1.2 KiB — 2.0 KiB ✅ Claude Live turn WebSocket decoded — 21.2 KiB — 29.3 KiB ✅ Claude Live turn messages — 1 — 8 ✅ Baseline: unavailable · PR result:
3482136· Source CI: successScenario and decoded snapshot size
10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
- Codex decoded thread snapshot: 108.5 KiB
- Claude decoded thread snapshot: 108.8 KiB
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.
Important
Review skipped#
We couldn't safely recover the incremental review. No full review was started, and the last reviewed checkpoint was preserved. Retry later, or explicitly request a full review by commenting
@coderabbitai full review.You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
- Trigger review
No actionable comments were generated in the recent review.
Walkthrough
-
Codex usage now scans live and archived transcript directories under one logical source. UsageService resolves those roots, scans their files, and retains cached files across them.
Changes: Codex transcript scanning
Layer / File(s) Summary Transcript root contract and resolution
packages/provider-core/src/server/usage.ts,apps/server/src/provider/Drivers/codexUsage.ts,apps/server/src/usage/UsageService.tsThe directory descriptor now accepts transcript roots. The Codex reader supplies sessionsandarchived_sessionsunder the Codex home directory. UsageService resolves and deduplicates roots, retaining canonical mappings for cache use.Multi-root scanning and cache validation
apps/server/src/usage/UsageService.ts,apps/server/src/usage/UsageService.test.tsUsageService lists files across roots and retains cached files under any associated root. Tests cover archived rollouts, duplicate copies, partial scans, merges, and compatibility with a v6 cache keyed by a configured-home symlink. Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix
Sequence Diagram(s)#
sequenceDiagram participant CodexUsageReader participant UsageService participant Filesystem CodexUsageReader->>UsageService: Provide source directory and transcript roots UsageService->>Filesystem: Check and list transcript roots Filesystem-->>UsageService: Return files or path errors UsageService->>UsageService: Combine files and retain cached matchesSuggested reviewers:
maria-rcks
Merge Risk:
Minimal · previous review12aa2-
No blocking issue was established in the Codex usage changes; the PR is ready for normal merge checks.
Pre-merge checks:
3 · 1-
Failed checks: 1 warningCheck name Status Explanation Resolution Description check The description covers the problem, changes, scope, and verification in detail. However, the required maintainer approval for the accounting change is explicitly pending, and the description does not … Add a maintainer approval comment on the linked issue or discussion that confirms approval of the direction and scope. If the change qualifies for the small, focused, obvious-bug exemption, explain why it qualifies. Passed checks: 3 passed-
Check name Status Explanation Title check The title clearly and concisely describes the main change: grouping archived Codex rollouts under one usage source. Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check skipped because no linked issues were found for this pull request.
Full details: Description check
-
Explanation
The description covers the problem, changes, scope, and verification in detail. However, the required maintainer approval for the accounting change is explicitly pending, and the description does not explain why the change qualifies for an approval exemption.
Resolution
Add a maintainer approval comment on the linked issue or discussion that confirms approval of the direction and scope. If the change qualifies for the small, focused, obvious-bug exemption, explain why it qualifies.
-
Finishing Touches
-
Fix failing CI checks
-
- Commit to this branch
- Create a new PR
Generate docstrings
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
ℹ️ Recent review info
-
⚙️ Run configuration
-
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Team
- Run ID:
fdbaf68c-e89e-42ea-855e-c4d31b765896
📥 Commits
-
Reviewing files that changed from the base of the PR and between ece1c206dbd82203d4b04a051f65f3c268dccb41 and 12aa22b0dd69fcb613c4ea4e54638586063a5998.
📒 Files selected for processing: 4
-
apps/server/src/provider/Drivers/codexUsage.tsapps/server/src/usage/UsageService.test.tsapps/server/src/usage/UsageService.tspackages/provider-core/src/server/usage.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
-
- @@ -0,0 +1,21 @@1+name: Deploy relay preview2+3+# Labeling a same-repository PR `relay:preview` deploys Alchemy stage `pr-<n>`.4+# This job runs the PR's own code with account credentials, so it waits for an5+# approval in the `relay-preview` environment on every run. Teardown is in6+# relay-preview-cleanup.yml and never runs PR code.7+on:8+ pull_request:9+ types: [labeled, synchronize, reopened]10+11+permissions:12+ contents: read13+ pull-requests: read14+15+concurrency:16+ group: relay-preview-${{ github.event.pull_request.number }}17+ cancel-in-progress: false18+19+jobs:20+ deploy_preview:21+ name: Deploy relay preview
🟡 Medium
workflows/relay-preview.yml:15An ineligible rerun can cancel the queued cleanup workflow, leaving the preview deployed. Workflow-level concurrency processes every PR event before the job-level
ifskips deployment, and a new pending run replaces the existing pending run even withcancel-in-progress: false. Move the concurrency group ontodeploy_previewso skipped runs do not occupy the cleanup slot.- concurrency: - group: relay-preview-${{ github.event.pull_request.number }} - cancel-in-progress: false - jobs: deploy_preview: + concurrency: + group: relay-preview-${{ github.event.pull_request.number }} + cancel-in-progress: false name: Deploy relay preview🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file @.github/workflows/relay-preview.yml around lines 15-21: An ineligible rerun can cancel the queued cleanup workflow, leaving the preview deployed. Workflow-level concurrency processes every PR event before the job-level `if` skips deployment, and a new pending run replaces the existing pending run even with `cancel-in-progress: false`. Move the concurrency group onto `deploy_preview` so skipped runs do not occupy the cleanup slot.@@ -0,0 +209,21 @@209+ - id: update210+ name: Publish the Android update211+ if: steps.expo-token.outputs.present == 'true'212+ working-directory: apps/mobile213+ shell: bash214+ env:215+ EXPO_TOKEN: ${{ secrets.EXPO_PREVIEW_TOKEN }}216+ PR: ${{ github.event.pull_request.number }}217+ run: |218+ group="$(eas update --auto --branch "pr-$PR" --platform android --environment preview --non-interactive --json | sed -n '/^\[/,$p' | jq -er '.[0].group')"219+ echo "group=$group" >> "$GITHUB_OUTPUT"220+221+ - name: Comment222+ if: steps.expo-token.outputs.present == 'true'223+ env:224+ GH_TOKEN: ${{ github.token }}225+ PR: ${{ github.event.pull_request.number }}226+ FINGERPRINT: ${{ steps.client.outputs.fingerprint }}227+ CLIENT: ${{ steps.client.outputs.link }}228+ GROUP: ${{ steps.update.outputs.group }}229+ run: node .trusted/.github/scripts/mobile-preview-comment.cjs🟠 High
workflows/mobile-eas-preview-fork.yml:229Fork-controlled scripts can replace
.trusted/.github/scripts/mobile-preview-comment.cjsbefore this step executes it, so the replacement runs withGH_TOKENand the job’spull-requests: writepermission. This lets the fork modify other PRs’ comments or labels; the Android build job repeats the same trust-boundary problem. Run commenting in a separate trusted job that never executes fork code.🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file @.github/workflows/mobile-eas-preview-fork.yml around line 229: Fork-controlled scripts can replace `.trusted/.github/scripts/mobile-preview-comment.cjs` before this step executes it, so the replacement runs with `GH_TOKEN` and the job’s `pull-requests: write` permission. This lets the fork modify other PRs’ comments or labels; the Android build job repeats the same trust-boundary problem. Run commenting in a separate trusted job that never executes fork code. Evidence#
Real web app, Linux Chromium, 1280×800, light theme, fresh databases and synthetic transcripts on both commits. Seed an active rollout containing 3K tokens and an archive-only rollout containing 7K tokens in the same reporting window. Open Usage → Tokens → 30 days, filter to Codex, and refresh. Then copy the active rollout into the archive, move it into the archive, and make the archive unreadable, refreshing after each step.
Step Before — c82e1ba515 After — 3107e47ddd Initial scan 3K tokens, 1 session. 
10K tokens, 2 sessions. 
Copy rollout, refresh 
Total stays 10K / 2 sessions. 
Move rollout, refresh Cached active usage remains at 3K. 
Total stays 10K / 2 sessions. 
Unreadable archive No warning. 
Incomplete-usage warning; cached totals preserved. 
Before recording · After recording. Recordings omit setup; base pauses are assertion waits.
Scenario and seed driver · Harness isolation patch · Reproduction instructions.
AI-assisted; verified with the tests and tools listed above.
Not shown:
- Actual Codex session creation and its archive UI were not exercised; synthetic transcripts and filesystem copy/move operations reproduced the scanner inputs.
- Estimated cost was not verified because the synthetic model label was deliberately unpriced.
- Mixed-version compatibility was not exercised; each web client ran against its matching server commit.
- Desktop and mobile clients were not exercised.
tanstack-source added labelsbug
Evidence#
Seed two synthetic Codex rollouts dated yesterday: active 3K tokens and archive-only 7K tokens before the first scan. Select Usage → Tokens → 7 days → Codex and refresh. Copy the active rollout into archived_sessions, refresh, remove its active copy, and refresh again. Remove the empty sessions directory and refresh. Finally make archived_sessions unreadable and refresh before restoring permissions.
Real web app, Chromium 157, light theme, fresh databases and isolated homes. Both sides use 1280×800 CSS pixels, DPR 2; missing/unreadable-directory stills use 1280×900 on both sides. Retained stills matched screenshots taken at least 500 ms apart.
Base reports 3K tokens and one session throughout. Fix reports 10K tokens and two sessions throughout. Copying and moving do not change the fixed total. Missing or unreadable directories produce incomplete-scan warnings while preserving usage.
Step Before — 31eea883c7 After — 58de4b3733 Archive present before first scan 

Active rollout copied into archive 

Active copy removed 

Active directory missing 

Archive unreadable 

Archive/copy/move recording Before recording After recording Unreadable-directory recording Before recording After recording Seed and launcher · Filesystem steps · Reproduction instructions
Archive state was seeded directly; Codex's archive command was not exercised. AI-assisted; verified with the tests and tools listed above.
Not shown:
- Codex's archive command itself was not exercised; standard synthetic archived rollout files were seeded directly.
- Cross-environment source merging and legacy-cache migration were not exercised; captures use one isolated environment per commit.
The automated pipeline stopped on this pull request and will not merge it:
not finished after 6 rounds
It stays open for a person to finish or close.
Another data point from
0.1.14-nightly.20261130.5492on Linux.One Codex home has 261 rollouts in
sessions/and 1,524 inarchived_sessions/, all from the last 18 days. Most of the archived ones are finished delegated children that T3 archived itself (see the #34829 note on #7090). The Usage page only reads the 261, so it shows a small part of the real Codex spend.The pipeline stopped on this stack on Nov 11. Is anything besides that blocking it from landing?
Sign in to join this conversation.
Approvability#
Verdict: Needs Human Approval
Macroscope's review found this PR requires human approval — The visible changes expand build, publishing, and preview infrastructure and add a lint suppression in .pnpmfile.cjs:31 that requires human review. Supplied findings also identify preview-cleanup and fork-workflow token-exposure risks.
Needs human approval because:
No code changes detected at
Adjust the Minimum Blocking Severity for this repo — including turning it Off — in [Settings](https://app.macroscope.com/pingdotgg/settings#Repos). You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).58de4b3. Prior analysis still applies.