Skip to content

Preserve Codex cost usage window under byte pressure - #2825

Open
Whiteknight07 wants to merge 1 commit into
steipete:mainfrom
Whiteknight07:agent/preserve-cost-usage-window
Open

Preserve Codex cost usage window under byte pressure#2825
Whiteknight07 wants to merge 1 commit into
steipete:mainfrom
Whiteknight07:agent/preserve-cost-usage-window

Conversation

@Whiteknight07

@Whiteknight07 Whiteknight07 commented Aug 10, 2026

Copy link
Copy Markdown

Summary

  • protect completed files that touch the requested Codex cost-usage window from both row- and byte-budget deletion
  • keep the 256 MiB database cap best-effort once only requested-window or recently active data remains
  • remove the fallback that stripped protected scan detail and immediately scheduled it for reconstruction
  • add repeated-enforcement, report-integrity, fork-parent, out-of-window pruning, and non-Gregorian calendar coverage
  • move the post-0.49.1 cost-cache CPU fix into the correct 0.49.2 changelog section

Root cause

The row-budget path protected the requested reporting window, but the byte-budget path explicitly disabled that protection. Deleting a file cascaded into file_day_aggregates, so rebuilding global aggregates permanently removed older requested days from Spend Dashboard.

The initial PR patch correctly enabled requested-window protection, but then fell back to stripOldestRebuildableDetail. That reset protected files to incomplete, deleted their token/row/accumulator state, and marked catch-up pending. The next refresh would reconstruct the same detail, exceed the same cap, strip it again, and potentially repeat indefinitely.

The maintainer revision uses a stable policy: delete only safe out-of-window completed files. Once every remaining file is protected, stop enforcement without mutating scan state. The current report and fork baselines remain authoritative, catch-up does not restart, and the database may remain above its best-effort byte cap.

Storage-policy decision

VISION.md requires explicit sign-off for data-storage behavior changes. This PR deliberately prioritizes requested-window report fidelity and stable refresh behavior over an absolute 256 MiB SQLite cap.

Recommendation: approve the fidelity-first policy. A hard cap cannot be maintained for arbitrarily large requested windows without either deleting displayed history or introducing a larger durable aggregate-only storage design.

Validation

  • CODEXBAR_SUPPRESS_TEST_KEYCHAIN_ACCESS=1 swift test --filter CostUsageStoreTests — 60 tests passed
  • CODEXBAR_SUPPRESS_TEST_KEYCHAIN_ACCESS=1 swift test --filter CostUsagePerformanceGateTests — 25 tests passed
  • make check — passed
  • CODEXBAR_SUPPRESS_TEST_KEYCHAIN_ACCESS=1 make test — 834 selections in 70 groups passed; zero failures or retries
  • structured autoreview — secret scan clean; no accepted/actionable findings
  • regression coverage uses the real CostUsageStore/SQLite path and proves two consecutive over-cap enforcement passes retain in-window rows and report aggregates without setting catch-up pending

Fixes #2823

@clawsweeper

clawsweeper Bot commented Aug 10, 2026

Copy link
Copy Markdown

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@Whiteknight07
Whiteknight07 marked this pull request as ready for review August 10, 2026 00:30
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. P1 Urgent regression or broken agent/channel workflow affecting real users now. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 10, 2026
@clawsweeper

clawsweeper Bot commented Aug 10, 2026

Copy link
Copy Markdown

Codex review: needs real behavior proof before merge. Reviewed August 12, 2026, 11:59 AM ET / 15:59 UTC.

ClawSweeper review

What this changes

This PR makes Codex cost-cache byte-budget cleanup retain files needed by the requested Spend Dashboard window, updates SQLite-store regression tests, and adds a release-note entry.

Regression provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

Blocked until real behavior proof from a real setup is added - 7 items remain

Keep open. The retention fix addresses a current-main data-loss path, but the branch has a concrete changelog merge conflict, lacks current-head real-cache proof, and changes a storage policy that VISION.md requires an explicit sign-off for.

Priority: P1
Reviewed head: 166d5e03556c3911ab6a3cbe49bfac04dc9426fc
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The retention change is focused, but a rebase conflict, missing real-cache proof, and the unresolved storage policy prevent merge readiness.
Proof confidence 🦪 silver shellfish (2/6) Needs real behavior proof before merge: The current body supplies focused SQLite-store test claims but no after-fix run against a real oversized cache; add redacted terminal output or logs showing retained requested-window data and resulting cache size, then update the PR body or ask a maintainer to comment @clawsweeper re-review.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The current body supplies focused SQLite-store test claims but no after-fix run against a real oversized cache; add redacted terminal output or logs showing retained requested-window data and resulting cache size, then update the PR body or ask a maintainer to comment @clawsweeper re-review.
Evidence reviewed 6 items Current-main defect: The byte-budget loop explicitly disables requested-window protection, then strips protected detail and marks catch-up pending when it cannot delete a file.
Proposed retention behavior: The PR passes requested-window protection to the byte loop and stops rather than stripping protected scan detail.
Regression coverage: The PR adds two-pass over-cap coverage that expects in-window usage rows and report aggregates to remain intact without catch-up.
Findings 1 actionable finding [P1] Rebase the release note onto the current unreleased section
Security None None.

How this fits together

CodexBar scans local Codex rollout files into a SQLite cost cache and reads that cache for Spend Dashboard reports. Post-save retention trims the cache by row and byte budgets before those reports are rendered.

flowchart LR
A[Codex rollout files] --> B[Cost cache scan]
B --> C[SQLite cost cache]
C --> D[Retention budgets]
D --> E{Outside report window?}
E -->|Yes| F[Prune safe file]
E -->|No| G[Retain report data]
C --> H[Spend Dashboard]
Loading

Decision needed

Question Recommendation
Should CodexBar explicitly prioritize complete requested Spend Dashboard history over enforcing the 256 MiB local cost-cache cap when no safely prunable file remains? Approve fidelity-first retention: Preserve requested-window data and allow the local cache to exceed the best-effort cap when only protected files remain.

Why: VISION.md requires sign-off for data-storage behavior changes, and the two outcomes intentionally trade disk use against report fidelity.

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The current body supplies focused SQLite-store test claims but no after-fix run against a real oversized cache; add redacted terminal output or logs showing retained requested-window data and resulting cache size, then update the PR body or ask a maintainer to comment @clawsweeper re-review.
  • Rebase the release note onto the current unreleased section (P1) - Current main has released 0.49.2 and opened 0.49.3, so the three-way merge conflicts in this hunk. Rebase and place the new retention note under the current unreleased section without restoring the already-moved CPU entry.
  • Resolve merge risk (P1) - The branch changes a strict 256 MiB cache cap into a best-effort cap; large existing caches can remain oversized until their requested window narrows.
  • Resolve merge risk (P1) - The current three-way merge conflicts in CHANGELOG.md, whose branch hunk targets the already released 0.49.2 section.
  • Resolve merge risk (P1) - The PR body documents store tests but not an after-fix run against a real oversized local cache.
  • Complete next step (P2) - The remaining blockers are an explicit storage-policy choice, a concrete rebase repair, and contributor-supplied real behavior proof.

Findings

  • [P1] Rebase the release note onto the current unreleased section — CHANGELOG.md:3-5
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Patch surface 3 files; production +5/-50, tests +65/-55, changelog +4/-1 The implementation is narrowly concentrated in retention policy and its focused SQLite-store coverage.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #2823
Summary: This PR is the candidate repair for the source-proven byte-budget retention bug.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Rebase and retain the fidelity-first policy (recommended)
    Resolve the changelog conflict under 0.49.3, obtain the storage-policy sign-off, and add redacted live-cache proof before merging.
  2. Pause for a hard-cap alternative
    Keep the existing cap behavior until maintainers choose and validate a separate storage design.

Technical review

Best possible solution:

Land a rebased retention fix after explicit approval of the fidelity-first storage policy, with one accurate entry under the current unreleased version and redacted real-cache evidence.

Do we have a high-confidence way to reproduce the issue?

Yes. Current main passes protectRequestedWindow: false in the byte-budget path, and the PR’s focused SQLite-store setup exercises an over-cap requested window.

Is this the best way to solve the issue?

Conditionally yes: protecting the requested window is a narrow repair for the demonstrated loss, but the cache-growth tradeoff requires the storage-policy sign-off before it is the accepted solution.

Full review comments:

  • [P1] Rebase the release note onto the current unreleased section — CHANGELOG.md:3-5
    Current main has released 0.49.2 and opened 0.49.3, so the three-way merge conflicts in this hunk. Rebase and place the new retention note under the current unreleased section without restoring the already-moved CPU entry.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.95

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against c4ed34d0e44a.

Labels

Label justifications:

  • P1: Current byte-budget enforcement can remove in-window cost data and leave Spend Dashboard history incomplete for large caches.
  • merge-risk: 🚨 compatibility: The PR intentionally changes existing cache-cap behavior for upgraded users with oversized local cost caches.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The current body supplies focused SQLite-store test claims but no after-fix run against a real oversized cache; add redacted terminal output or logs showing retained requested-window data and resulting cache size, then update the PR body or ask a maintainer to comment @clawsweeper re-review.

Evidence

What I checked:

Likely related people:

  • steipete: Current-main blame attributes the retention implementation to this author, who also authored the PR head and force-pushed its maintainer revision. (role: feature owner and recent area contributor; confidence: high; commits: 330ae4384b18, 166d5e03556c; files: Sources/CodexBarCore/Vendored/CostUsage/CostUsageStore+Retention.swift, Tests/CodexBarTests/CostUsageStoreTests.swift)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Rebase the changelog entry onto the 0.49.3 unreleased section.
  • Record explicit approval of the fidelity-first storage policy.
  • Post redacted evidence from an actual over-cap local cache showing the retained report window.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (5 earlier review cycles)
  • reviewed 2026-08-10T00:30:31.119Z sha 502d123 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-10T00:35:18.726Z sha 502d123 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-10T00:48:11.629Z sha 502d123 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-10T08:24:15.632Z sha 166d5e0 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-11T13:12:03.872Z sha 166d5e0 :: needs real behavior proof before merge. :: none

Copy link
Copy Markdown
Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 10, 2026

Copy link
Copy Markdown

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 10, 2026
Co-authored-by: Whiteknight07 <fiestyboxer@gmail.com>
@steipete
steipete force-pushed the agent/preserve-cost-usage-window branch from 502d123 to 166d5e0 Compare August 10, 2026 08:20
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed proof: sufficient Contributor real behavior proof is sufficient. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. P1 Urgent regression or broken agent/channel workflow affecting real users now. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Codex cost-usage byte budget (256 MiB) silently prunes in-window sessions; older days vanish from Spend Dashboard

2 participants