perf: persist Claude cost report memo across launches - #3284
Conversation
Keep the local-cost daily report and source inventory next to claude-v6.json so an unchanged transcript set skips the full JSON cache decode after process restart. Pricing and cache-artifact stamp changes still miss the memo and reprice from the persisted rows. Investigated alongside steipete#3247.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 778b3793c2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } | ||
|
|
||
| static let shared = CostUsageClaudeReportMemo() | ||
| static let persistedVersion = 1 |
There was a problem hiding this comment.
Invalidate persisted reports when the app version changes
When a user upgrades to a build that changes bundled Claude pricing, model aliases, or report aggregation while the transcripts, cache artifact, pricing artifact, and requested date range remain unchanged, this constant still accepts the report produced by the previous binary. loadClaudeDaily then returns that report before running the current CostUsagePricing/aggregation code, so costs can remain calculated with old application logic until another key input changes; include an application/report-logic version in the persisted key or invalidate this sidecar across relevant upgrades.
Useful? React with 👍 / 👎.
|
Codex review: needs maintainer review before merge. Reviewed September 8, 2026, 12:18 AM ET / 04:18 UTC. ClawSweeper reviewWhat this changesPersist Claude and Vertex AI daily cost reports beside their transcript caches so unchanged inputs can reuse calculated totals after relaunch. Merge readiness✅ Ready for maintainer review This remains a useful, merge-ready performance improvement: current main lacks persistent report reuse, both prior findings are resolved, and the maintainer verified the changed behavior on the reviewed head. No actionable correctness or security findings remain. Priority: P2 Review scores
Verification
How this fits togetherCodexBar’s local cost scanner combines transcript usage with model pricing to supply CLI reports and spend displays. The saved report memo avoids rebuilding those totals when the source inventory, pricing, requested dates, and report semantics still match. flowchart TD
A[Local transcripts] --> C[Check inventory and report key]
B[Pricing and requested dates] --> C
D[Saved report memo] --> C
C -->|Compatible| F[Daily cost report]
C -->|Missing or changed| E[Scan cache and calculate totals]
E --> D
E --> F
F --> G[CLI and spend displays]
Before mergeNone. Agent review detailsSecurityNone. Review metrics
Technical reviewBest possible solution: Retain the versioned, disposable report sidecar with existing invalidation and fallback behavior, keeping future report-semantics revisions synchronized with pricing and aggregation changes. Do we have a high-confidence way to reproduce the issue? Not applicable as a discrete bug reproduction: this optimizes established report generation. Current-main source proves the memo is process-local, and recorded CLI runs demonstrate the proposed persistent reuse. Is this the best way to solve the issue? Yes. Extending the existing memo with a versioned, disposable sidecar preserves the scanner’s established validation path without replacing the transcript cache or changing user settings. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 2a71b479a5d4. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (4 earlier review cycles)
|
Integrate current main's transcript identity protections and reject saved reports with missing or incompatible report semantics. Preserve pricing, source-inventory, cancellation, and report-field round-trip behavior. Co-authored-by: sunke <sunke@keep.com>
|
Maintainer verification complete on
Changelog is consolidated in #3491. Land-ready; no merge performed here. Contributor credit remains preserved for @eggyrooch-blip / sunke. |
Persist the Claude local-cost report memo beside
claude-v6.json, allowing an unchanged transcript inventory to reuse its report after relaunch without decoding the full transcript cache. This addresses repeated cold-start work on large Claude histories, investigated alongside #3247.The saved envelope now has separate format and report-semantics revisions. Missing or mismatched semantics reject the saved report before the early return, so changed bundled pricing, aliases, or aggregation can invalidate it. Source identities, cache/pricing stamps, requested window, cancellation handling, and atomic writes retain current main's protections. Missing or corrupt sidecars fall back to the normal cache path.
Maintainer repair of @eggyrooch-blip's contribution; human commit credit remains sunke sunke@keep.com. Added regressions cover poisoned old/missing/future revisions, corrupt sidecars, cold pricing replacement, cancellation preserving sidecar bytes, and complete report-field round trips. Changelog context is collected in the batch's separate notes PR.
Built CLI proof on
1d690b69c7cd96e5f05d08cebb018fefb5e0fbc2used 1,250 compact synthetic Claude events in 25 files, isolated child-process storage, and a seeded pricing catalog. Every row below is a new process runningCodexBarCLI cost --provider claude --days 1 --format json:The second process had no readable transcript/cache fallback; nonempty matching totals prove persisted-report reuse. Modes were restored in a
finallyblock. The semantic mismatch was rewritten at the current revision. Assertions passed for all token and cost totals.Local and committed-branch autoreview are clean through P2. The focused memo suite passed all 18 tests after correcting fixture discriminators and checking transcript stability across a rebuild. Final
make checkand fullmake testpassed: 1,033 selections across 87 groups, with no failures, retries, or timeouts. Exact-head CI succeeded. Land-ready.