perf: avoid reprocessing stable Codex cost cache - #2834
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 10, 2026, 3:26 AM ET / 07:26 UTC. ClawSweeper reviewWhat this changesThe PR plans Codex cost-cache persistence before conversion so stable records are reused and safe appends encode only new snapshots and rows. Merge readinessKeep open for normal owner review and CI completion. The current main implementation still materializes every snapshot and row before reuse is decided; this PR replaces that work with equivalent reuse, append, and replacement branches, and no blocking correctness defect was found. Priority: P2 Review scores
Verification
How this fits togetherCodexBar scans Codex usage into token snapshots and usage rows, then persists them in a local SQLite cost cache for later usage displays. This change sits between scanned usage data and the stored cache records. flowchart LR
A[Codex usage scan] --> B[Usage snapshots and rows]
B --> C[Cost cache save]
C --> D[Persistence planner]
D --> E[Reuse stored records]
D --> F[Append new records]
D --> G[Replace changed records]
E --> H[Local SQLite cost cache]
F --> H
G --> H
Before merge
Agent review detailsSecurityNone. Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Land the planner with its focused persistence coverage once required checks complete and the final merge result preserves current release metadata. Do we have a high-confidence way to reproduce the issue? Not applicable as a bug report: this is a performance optimization PR, and its body supplies a real-cache profiler comparison rather than an issue reproduction. Is this the best way to solve the issue? Yes. Deciding reuse, append, or replacement before conversion is the narrowest maintainable way to eliminate unchanged-record encoding while retaining the established cache-state rules. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 930b1c4d0d43. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
Summary
Stable Codex cost-cache saves were converting every unchanged historical token snapshot and encoding every row before deciding whether persistence could reuse, append, or replace the existing data.
This change plans persistence first: stable collections are reused without materialization, safe appends materialize only the suffix using absolute indexes, and the cache is fully replaced whenever append safety is lost.
Performance
saveCodexCachebranch accounted for 4,085 ms andCostUsageTimestampParser.parseISOfor 3,307 ms.CostUsageTimestampParserorparseISO.Validation
CostUsageStoreTests,CodexForkAppendResumeTests, andCostUsagePerformanceGateTestspassed.DEVELOPER_DIR=/Applications/Xcode-beta.app/Contents/Developer make checkpassed.git diff --checkpassed.make testran 834 selections and failed only the pre-existing unrelatedMenuSwitchFlickerProbeTestsexpectation that its synthetic 400 ms probe log containshandled=true. The same expectation fails unchanged in isolation under the machine's extreme load.