Repository navigation
fix(cold-store-reaper): count backup bytes in project-budget accounting (#1028) - #1035
Merged
Merged
Conversation
…ng (#1028) _upload_accounting defined cold_bytes as verified bundles only, and put_backup records backups only in the transfer ledger — so a sequence of nightly backups could cross project_budget_bytes without any call being refused, and status's within_budget shared the blind spot. Count backup bytes from the ledger (all-time upload/backup-upload minus trash/backup-prune, the two rows put_backup and prune_backups already write) and enforce/report the budget against verified bundle bytes + backup bytes. status_data exposes backup_bytes separately and computes within_budget from the same total. Daily hard-stop and bundle-path accounting unchanged. Tests: two new TestUploadLimits cases — cumulative backups crossing the budget are refused with no Drive writes, and a backup-prune ledger row decrements the counted bytes.
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. |
|
Caution Review failedThe pull request is closed. Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1028.
Problem
PR #988 added project-budget enforcement to
put_backup(), but_upload_accounting()definedcold_bytesas verified bundles only, andput_backuprecords backups only in the rolling transfer ledger — backups never accumulated into the budget total. A sequence of nightly backups (backup-d1, backup-supabase, Turso exports) could cross the 3 TiBproject_budget_bytesunrefused, andstatus_data()'swithin_budgetshared the blind spot. Reproduced in triage (task 1198): budget 150 B, two 100 B backups both succeed, status reportscold_bytes: 0, within_budget: True.Fix (accounting decided in triage 1198)
Ledger-derived backup bytes in
_upload_accounting():backup_bytes =all-timeSUM(bytes)oftransfer_ledgerrowsdirection='upload' AND kind='backup-upload'minusdirection='trash' AND kind='backup-prune'(clamped at 0). The ledger is never pruned in code; only the daily hard stop uses the 24 h window.put_backup, which writes the upload row, andprune_backupswrites the matching prune row — so the ledger is complete for this class without putting a Drive API call inside an accounting function the bundle path and status also use._check_upload_limitsrefuses whenverified bundle bytes + backup bytes + this transfercrosses the budget; the refusal message names all three components.status_datauses the same total forwithin_budgetand exposesbackup_bytesas its own field; the CLI status line prints both components.prune-backups, is not decremented — the budget overcounts and refuses earlier, never later.Tests
TestUploadLimits.test_put_backup_cumulative_budget_refusal: budget between one and two backups — first succeeds, second raises a project-budgetColdStoreErrorwith no Drive writes; status countsbackup_bytes: 100.TestUploadLimits.test_backup_prune_ledger_row_decrements_backup_bytes: a prune row returns the counted bytes to 0 and the next backup fits again.python3 -m unittest discover -s pkgs/cold-store-reaper/tests— 63 tests OK (1 skipped); ruff format clean.🤖 Queue worker task 1205 (repo-health-code-pilot); triage was task 1198.
Need help on this PR? Tag
@codesmith-botwith what you need.