Repository navigation
fix(server): recover missing initial Codex usage tiers - #21899
Conversation
ApprovabilityVerdict: Needs Human Approval Macroscope's review found this PR requires human approval — This PR changes production Codex usage parsing, historical reconciliation, and persisted cache data, potentially changing reported token costs for existing activity. The SQL lookup and cross-scan cache behavior warrant maintainer review of the accounting impact. You can add or adjust custom eligibility rules. Learn more. |
Thread transfer impact✅ Thread transfer remains within every enforced ceiling.
Baseline: Scenario and decoded snapshot size10 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.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed. |
c5b0b1e to
e5ef040
Compare
# Conflicts: # apps/server/src/usage/UsageService.ts
# Conflicts: # apps/server/src/usage/UsageService.test.ts # apps/server/src/usage/UsageService.ts # apps/server/src/usage/usageScanCache.test.ts # apps/server/src/usage/usageScanCache.ts
Problem
Codex can omit initial rollout settings for a Fast or Ultrafast request. Those first records then use Standard pricing even when T3 retained the original selection.
Change
Recover the initial tier only when the own OpenAI session, native turn, model, and unambiguous first-running V2 selection match. Native rollout settings stay authoritative. Pending records retry without file growth and survive restarts; successful corrections persist without changing parser tier state. The provider reader owns historical resolution through an optional generic hook.
Cache v7 preserves v6/v5/original fallbacks, cold-parses available older Codex transcripts, and retains saved prices for deleted files. It preserves compatible v6 positions for other providers, including Pi, and retains cumulative-counter reconciliation.
Rebuilt from @PixPMusic's #15275. Depends on the historical lookup layer and #21863.
Scope and approval
Authorized by the maintainer takeover. Related to #15267, which stays open: imported V1 histories without retained V2 attempts are unchanged. Historical accounting, SQL, and cache changes still need human maintainer review. No client or wire contract changes; every client consumes the shared server summary.
Verification
Four fresh parallel review rounds with Opus 5.5 and GPT-6 Sol covered both layers. They caught and fixed writer-thread SQL execution and unnecessary v6 Pi cache invalidation. CI also exposed a stale migration-64 test expectation, which now includes migration 65. The final round found no blockers.
Before — initial records priced Standard:
After — initial Fast recovered, later Standard preserved:
Implementation: GPT-6.1 Sol; tests: GPT-6 Astra. Harness: Codex in T3 Code.