Repository navigation
Conversation
Retention is opt-in and its deletes are irreversible, but a successful prune left no trace - only the failure path logged. Both retention defects found in review, pruning an operator's snapshots and then another deployment's, were silent successes that had to be reconstructed from a missing file. It now names the count and the keys, capped so a first run on an old bucket does not print a line nobody can read, and stays quiet when it deletes nothing. This is a forensic record, not an approval gate - that is plan 313's WS4, still open. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011sk9BLaUZDkPVAZ1sKhuDP
✅ Deploy Preview for lunorash ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Thank you for following the naming conventions! 🙏 |
WalkthroughThe retention flow now handles empty stale-manifest lists, deletes stale snapshots and sidecars concurrently in snapshot-first order, and limits retention logs to 10 deleted keys with an additional count. ChangesRetention pruning
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
|
Thank you for confirming the Contributor License Agreement! 🙏 |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/runtime/src/scheduled-backup.ts`:
- Around line 138-149: Update the stale-pruning deletion flow around the
Promise.all call to use per-delete tracking or Promise.allSettled, recording
each successfully deleted backup key even when another deletion rejects.
Preserve the existing snapshot-then-sidecar deletion order and failure warning
behavior, while ensuring successful deletions are logged after partial failures.
- Around line 142-143: Update the retention-order comment near the snapshot and
sidecar deletion logic to replace the ungrammatical phrase with “because the
retention marker lives on the sidecar,” preserving the explanation that snapshot
deletion must precede sidecar deletion.
- Around line 162-167: Update the retention-success logging around shown and
rest to represent both R2 deletion targets for each stale manifest, including
snapshot keys, and report the actual deleted-object count and capped key list.
Preserve the cap behavior, and add tests covering one stale manifest and the cap
boundary.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 8aa5f91c-22ca-4f3c-b0b2-32e8cfadba6e
⛔ Files ignored due to path filters (1)
packages/runtime/__tests__/scheduled-backup.test.tsis excluded by!**/__tests__/**,!**/*.test.tsand included bypackages/**
📒 Files selected for processing (1)
packages/runtime/src/scheduled-backup.ts
| await Promise.all( | ||
| mine | ||
| .toSorted((a, b) => b.localeCompare(a)) | ||
| .slice(retain) | ||
| .map(async (manifestKey) => { | ||
| // Snapshot first, sidecar second. A sidecar without its snapshot | ||
| // is a listable entry that fails to restore; a snapshot without | ||
| // its sidecar is invisible to retention forever, because the | ||
| // marker retention prunes on lives on the sidecar. If only one | ||
| // delete lands, this order is the recoverable one — the next run | ||
| // sees the sidecar again and retries. | ||
| await store.delete(backupObjectKeyOfManifest(manifestKey)); | ||
| await store.delete(manifestKey); | ||
| }), | ||
| stale.map(async (manifestKey) => { | ||
| // Snapshot first, sidecar second. A sidecar without its snapshot | ||
| // is a listable entry that fails to restore; a snapshot without | ||
| // its sidecar is invisible to retention forever, because the | ||
| // marker retention prunes on lives on the sidecar. If only one | ||
| // delete lands, this order is the recoverable one — the next run | ||
| // sees the sidecar again and retries. | ||
| await store.delete(backupObjectKeyOfManifest(manifestKey)); | ||
| await store.delete(manifestKey); | ||
| }), | ||
| ); |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
Record successful deletions when pruning partially fails.
Promise.all rejects when one deletion fails, so execution skips the success log even though other deletion promises can already have completed. R2 does not roll back those deletions. Collect fulfilled delete results with Promise.allSettled or equivalent per-delete tracking, log the successful keys, and preserve the existing failure warning for rejected operations.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/runtime/src/scheduled-backup.ts` around lines 138 - 149, Update the
stale-pruning deletion flow around the Promise.all call to use per-delete
tracking or Promise.allSettled, recording each successfully deleted backup key
even when another deletion rejects. Preserve the existing snapshot-then-sidecar
deletion order and failure warning behavior, while ensuring successful deletions
are logged after partial failures.
| // its sidecar is invisible to retention forever, because the | ||
| // marker retention prunes on lives on the sidecar. If only one |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Correct the retention-order comment.
The phrase because the marker retention prunes on lives on the sidecar is not grammatical. Replace it with because the retention marker lives on the sidecar. This comment documents why snapshot deletion must precede sidecar deletion.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/runtime/src/scheduled-backup.ts` around lines 142 - 143, Update the
retention-order comment near the snapshot and sidecar deletion logic to replace
the ungrammatical phrase with “because the retention marker lives on the
sidecar,” preserving the explanation that snapshot deletion must precede sidecar
deletion.
| const shown = stale.slice(0, MAX_LOGGED_PRUNED_KEYS); | ||
| const rest = stale.length - shown.length; | ||
|
|
||
| // eslint-disable-next-line no-console -- server-side diagnostic, same channel as the retention-failure warning below; a Worker has no other operator-visible sink here. | ||
| console.info( | ||
| `[lunora] backup retention kept the newest ${String(retain)} and deleted ${String(stale.length)}: ${shown.join(", ")}${rest > 0 ? ` (+${String(rest)} more)` : ""}`, |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Log the actual deleted object keys and count.
stale contains manifest keys, but each entry triggers two R2 deletions. A successful prune of one stale manifest therefore reports deleted 1 while deleting two objects, and the snapshot key is absent from the forensic record. Build the capped log list from both delete targets, or rename the message to explicitly describe backup records rather than deleted keys. Add a test for one stale manifest and for the cap boundary.
Proposed fix
- const shown = stale.slice(0, MAX_LOGGED_PRUNED_KEYS);
- const rest = stale.length - shown.length;
+ const deletedKeyCount = stale.length * 2;
+ const shown = stale
+ .slice(0, Math.ceil(MAX_LOGGED_PRUNED_KEYS / 2))
+ .flatMap((manifestKey) => [backupObjectKeyOfManifest(manifestKey), manifestKey])
+ .slice(0, MAX_LOGGED_PRUNED_KEYS);
+ const rest = deletedKeyCount - shown.length;
console.info(
- `[lunora] backup retention kept the newest ${String(retain)} and deleted ${String(stale.length)}: ${shown.join(", ")}${rest > 0 ? \` (+${String(rest)} more)\` : ""}`,
+ `[lunora] backup retention kept the newest ${String(retain)} and deleted ${String(deletedKeyCount)}: ${shown.join(", ")}${rest > 0 ? \` (+${String(rest)} more)\` : ""}`,
);📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const shown = stale.slice(0, MAX_LOGGED_PRUNED_KEYS); | |
| const rest = stale.length - shown.length; | |
| // eslint-disable-next-line no-console -- server-side diagnostic, same channel as the retention-failure warning below; a Worker has no other operator-visible sink here. | |
| console.info( | |
| `[lunora] backup retention kept the newest ${String(retain)} and deleted ${String(stale.length)}: ${shown.join(", ")}${rest > 0 ? ` (+${String(rest)} more)` : ""}`, | |
| const deletedKeyCount = stale.length * 2; | |
| const shown = stale | |
| .slice(0, Math.ceil(MAX_LOGGED_PRUNED_KEYS / 2)) | |
| .flatMap((manifestKey) => [backupObjectKeyOfManifest(manifestKey), manifestKey]) | |
| .slice(0, MAX_LOGGED_PRUNED_KEYS); | |
| const rest = deletedKeyCount - shown.length; | |
| // eslint-disable-next-line no-console -- server-side diagnostic, same channel as the retention-failure warning below; a Worker has no other operator-visible sink here. | |
| console.info( | |
| `[lunora] backup retention kept the newest ${String(retain)} and deleted ${String(deletedKeyCount)}: ${shown.join(", ")}${rest > 0 ? ` (+${String(rest)} more)` : ""}`, |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/runtime/src/scheduled-backup.ts` around lines 162 - 167, Update the
retention-success logging around shown and rest to represent both R2 deletion
targets for each stale manifest, including snapshot keys, and report the actual
deleted-object count and capped key list. Preserve the cap behavior, and add
tests covering one stale manifest and the cap boundary.
Merging this PR will not alter performance
Comparing Footnotes
|
|
Superseded by #389, merged as This branch is an ancestor of Verified on |
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
The scheduled backup's retention deletes objects from R2 and, until now, said nothing when it worked. The only log was on the failure path.
That is the gap behind plan 313 §4.4 ("No silent deletion of anything"). It is narrower than it sounds — retention is opt-in, so with no
backupRetainconfigured nothing is ever deleted — but when an operator does configure it, snapshots were disappearing with no record.Both retention defects found during review were silent successes: the cron deleting an operator's hand-taken snapshots, and later deleting another deployment's. Each was reconstructed afterwards from a missing file. A line naming what was pruned turns the next one into something you notice.
What it does
Names the retention window and the deleted keys, capped at 10 with a
(+N more)summary — a first run after enabling retention on an old bucket can delete many, and a log line nobody can read is its own kind of silence. Stays quiet when it deletes nothing, so an ordinary cron fire adds no noise.It uses the same
consolechannel as the existing retention-failure warning; a Worker has no other operator-visible sink at this point in the run.What it deliberately is not
A forensic record, not an approval gate. R2 deletes are irreversible and this is emitted after the fact — an operator who wants to review a prune before it destroys anything wants the
pruneverb with--dry-run, which is plan 313's WS4 and still open. The comment says so, so the next reader does not mistake this for the fix.Verification
@lunora/runtime857 tests (one new). The new test asserts both halves — that a prune names what it deleted, and that a no-op prune logs nothing — and I confirmed it is not vacuous by removing the log and watching only that test fail (expected \"info\" to be called), then restoring.lint:typesandlint:eslint --max-warnings=0clean, Prettier clean.🤖 Generated with Claude Code
https://claude.ai/code/session_011sk9BLaUZDkPVAZ1sKhuDP
Summary by CodeRabbit