Preserve wider retained Codex cost history across dashboard projections - #2920
Conversation
Usage & Spend saves a 7- or 30-day requested reporting window while the cache may retain a wider configured history. Budget enforcement treated the requested window as the retention boundary, so a narrow dashboard save under row/byte pressure pruned older retained rows and aggregates and rewrote the persisted scan coverage down to the narrow request. Derive the budget-protection window as the union of the cache's retained coverage and the requested window, on both the identical-content and full-save paths, and add a synthetic regression covering both. Fixes #2914 Co-authored-by: CodexBar Contributor <codexbar-contributor@users.noreply.github.com>
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 13, 2026, 11:32 PM ET / August 14, 2026, 03:32 UTC. ClawSweeper reviewWhat this changesThe PR protects the cache’s full retained Codex cost-history window when a shorter Usage & Spend dashboard projection triggers budget enforcement. Regression provenancePossible regression — probable (reviewed change; known regression link). No predecessor PR is attributed. Merge readinessKeep this owner-authored PR open for normal merge review. The supplied diff is a focused repair for persisted Codex cost-cache retention and includes regression coverage for both save paths, but local source/history inspection could not run because the sandbox command failed before execution. Priority: P2 Review scores
Verification
How this fits togetherCodex usage scanning persists a local cost cache that feeds Usage & Spend dashboard projections. A projection save enforces cache budgets and updates persisted rows, aggregates, and scan coverage used by subsequent dashboard reads. flowchart LR
A[Codex usage files] --> B[Cost cache]
C[Dashboard date range] --> D[Cache save]
B --> D
D --> E[Budget enforcement]
E --> F[Persisted rows and aggregates]
F --> G[Usage and Spend dashboard]
Before merge
Agent review detailsSecurityNone. Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Retain the persisted cache coverage as the budget-protection boundary, preserve the focused regression, and merge after the pending validation confirms the intended compatibility behavior. Do we have a high-confidence way to reproduce the issue? Yes, the supplied regression design gives a concrete byte-pressure reproduction through both cache-save paths, though independent local execution was blocked by the sandbox failure. Is this the best way to solve the issue? Yes, based on the supplied diff: separating retained cache coverage from a read projection is the narrowest way to prevent projection saves from redefining retention. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 3a848565bcd2. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
Summary
Usage & Spend requests a narrow 7- or 30-day reporting window while the cost cache may retain a wider configured history. Budget enforcement in the save path treated the requested reporting window as the retention boundary: under row/byte pressure, a narrow dashboard save pruned completed cached rows and daily aggregates outside the projection and rewrote the persisted scan coverage down to the narrow request. This matches the reporter evidence in #2914 of history collapsing to the last 1-2 days after updates.
This lands the fix from #2915 by @thomaschow19, rebased onto current main (post-#2918 catch-up cluster):
saveCodexCachenow derives a budget-protection window as the union of the cache's retained coverage (scanSinceKey/scanUntilKey) and the requested window, and passes that toenforceBudgetson both the identical-content and full-save paths. Projections stay read slices; retention stays owned by the persisted history window.Proof
narrow dashboard windows preserve wider retained cache under byte pressure) fails on unfixed main with 11 issues (older row deleted, aggregates pruned,scanSinceDaynarrowed) and passes with the fix, covering both the identical-content and full-save paths under a 1-byte file budget.swift test --filter CostUsageStoreTests: 73 tests pass.make check: 0 violations.Fixes #2914
Supersedes #2915 (same fix, rebased and verified against current main). Thanks @thomaschow19!