Skip to content

fix(usage): include archived Codex rollouts under one source - #21666

Open
juliusmarminge wants to merge 3675 commits into
codex-02/archive-compatfrom
codex-02/archive-sources
Open

juliusmarminge wants to merge 3675 commits into
codex-02/archive-compatfrom
codex-02/archive-sources

Conversation

@juliusmarminge

@juliusmarminge juliusmarminge commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Problem

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:

Before: active session only, 10 tokens

After — active and archived sessions, 30 tokens:

After: archived rollout included, 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 #7090

@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Oct 19, 2026
@juliusmarminge juliusmarminge changed the title codex 02/archive sources fix(usage): include archived Codex rollouts under one source Oct 19, 2026
@juliusmarminge juliusmarminge added the macroscope-review Opt PRs made by unvouched contributors in for Macroscope review. Vouched contributors auto-reviews label Oct 19, 2026
@macroscopeapp

macroscopeapp Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • 2 blocking correctness issues found at or above your repo's Minimum Blocking Severity

No code changes detected at 58de4b3. Prior analysis still applies.

Adjust the Minimum Blocking Severity for this repo — including turning it Off — in Settings. You can add or adjust custom eligibility rules. Learn more.

@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Thread transfer impact

✅ Thread transfer remains within every enforced ceiling.

ℹ️ No successful main baseline 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: success

Scenario 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.

@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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_status to false in 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.ts
The directory descriptor now accepts transcript roots. The Codex reader supplies sessions and archived_sessions under 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.ts
UsageService 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 matches
Loading

Suggested reviewers: maria-rcks

Merge Risk: Minimal · previous review 12aa2

No blocking issue was established in the Codex usage changes; the PR is ready for normal merge checks.

Pre-merge checks: Passed 3 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Description check Warning 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 Passed checks: 3 passed

Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: grouping archived Codex rollouts under one usage source.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed 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 ece1c20 and 12aa22b.

📒 Files selected for processing: 4

  • apps/server/src/provider/Drivers/codexUsage.ts
  • apps/server/src/usage/UsageService.test.ts
  • apps/server/src/usage/UsageService.ts
  • packages/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.

Ephraim-9 and others added 16 commits November 9, 2026 19:56
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Co-authored-by: maria-rcks <maria@kuuro.net>
…bar changes (#33611)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…rashpad pipe (#26374)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
Co-authored-by: PR Batch Tester <agent@local.test>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: maria-rcks <maria@kuuro.net>
…ab (#23589)

Co-authored-by: PR Batch Tester <agent@local.test>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: PR Batch Tester <agent@local.test>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: maria-rcks <maria@kuuro.net>
Add a Details action for pending background commands and subagents. Preserve Claude command metadata across roster updates and bind output visibility to the explicit command item. Keep internal task IDs, duplicate command labels, and empty output headings out of the dialog.

Validation: check:changed passed with 371 tests; CI and agentic reviews completed on a0326ab. Verified command details in real Codex and Claude runs.

Implemented and verified with GPT 6.1 Sol in the Codex harness.
…anup (#33664)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…33678)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: codex <codex@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…24599)

Co-authored-by: maria-rcks <maria@kuuro.net>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
juliusmarminge and others added 28 commits November 11, 2026 04:53
…ar file (#26594)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
…ds the inspection limit (#26593)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…eckpoints (#27425)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…4170)

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
Co-authored-by: Sinan Turna <189102964+Sinan53x@users.noreply.github.com>
Co-authored-by: Julius Marminge <julius0216@outlook.com>
…10495)

Co-authored-by: Julius Marminge <julius0216@outlook.com>
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Co-authored-by: maria-rcks <maria@kuuro.net>
)

Co-authored-by: Julius Marminge <julius0216@outlook.com>
…at t3_thread_list takes allProjects (#26525)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Julius Marminge <julius0216@outlook.com>
…ll other git work (#26601)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Co-authored-by: maria-rcks <maria@kuuro.net>
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…inks off (#21641)

Co-authored-by: Julius Marminge <julius0216@outlook.com>
…6311)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Co-authored-by: Vladislav Nikonorov <vladislav@nikonorov.dev>
…8379)

Co-authored-by: Julius Marminge <julius0216@outlook.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
AI-assisted; verified with the tests and tools listed above.
AI-assisted; verified with the tests and tools listed above.
@juliusmarminge

Copy link
Copy Markdown
Member Author

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 Before: archive omitted After: both sessions included
Active rollout copied into archive Before: copied rollout After: copy counted once
Active copy removed Before: active copy removed After: moved rollout counted once
Active directory missing Before: missing active directory After: incomplete-scan warning
Archive unreadable Before: archive unreadable After: read warning and cached 10K preserved
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.

@juliusmarminge

Copy link
Copy Markdown
Member Author

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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

macroscope-review Opt PRs made by unvouched contributors in for Macroscope review. Vouched contributors auto-reviews size:L 100-499 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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