Skip to content

feat(runtime): preview what backup retention would delete - #388

Closed
prisis wants to merge 2 commits into
alphafrom
feat/backup-retention-preview
Closed

prisis wants to merge 2 commits into
alphafrom
feat/backup-retention-preview

Conversation

@prisis

@prisis prisis commented Aug 9, 2026

Copy link
Copy Markdown
Member

What

lunora backup retention — what the platform's retention would delete on its
next run, and nothing else.

$ lunora backup retention --url https://api.example.com
backup retention would keep the newest 3 of 5 under backups/ and delete 2
  backups/lunora-backup-2026-06-01T03-00-00-000Z.ndjson
  backups/lunora-backup-2026-06-02T03-00-00-000Z.ndjson

Backed by GET /_lunora/admin/backup/retention, admin-gated like the storage
read route.

Why this and not a log

backupRetain deletes on every cron run, an R2 delete has no undo, and the
thing deleted is the backup. #387 records what was destroyed; nothing could
say what will be. So the only way to learn what a retention setting does on a
real bucket was to let it run and read the aftermath.

That matters more than usual here because eligibility depends on the
lunoraBackupCron metadata marker, which sidecars written before that feature
lack. On a pre-existing bucket, retention may own a fraction of what the bucket
holds — and no amount of reading the config tells you which fraction. The
preview does, and says so explicitly when the answer is zero.

The surface, and why

lunora backup retention — a report verb, not prune --dry-run.

  • A verb named prune that refuses to prune is confusing, and one that previews
    by default with a --apply behind it advertises a deleter this PR does not
    build. retention names what it reports on, implies nothing destructive, and
    leaves prune unclaimed for the actual deleter when WS4's remaining half
    lands — so that name is not spent on something that refuses.
  • Not a flag on list, because it answers a different question from a different
    source: list reads the bucket, this reads the worker's own configuration.
    list also works against a --dir destination, where retention does not
    exist.
  • Nothing in this PR deletes, so there is no unsafe path to default away from.

Preview and prune are the same selection

pruneBackups already computed its set before deleting. That computation is now
selectStaleBackups, and both the prune and the preview call it — the preview
does not re-derive eligibility, because a preview that can disagree with the
prune is worse than no preview, and this subsystem has twice produced the bug
where one rule was written in two places.

The test that matters seeds one bucket with every case that makes
eligibility subtle — a legacy sidecar with no marker, a sidecar carrying another
deployment's cron expression, an operator-written snapshot — then runs the
preview and a real cron fire against identical bucket state and asserts the sets
are equal. Getting the inputs genuinely identical took care: the fire writes a
snapshot before it prunes, so the seed includes a snapshot at the fire's own key
and the fire overwrites it rather than adding one. Without that the two would be
answering about different buckets and an equal result would mean nothing.

Non-vacuity checked both ways. Perturbing selectStaleBackups moves both
sides together and the parity test stays green (correctly — that is what sharing
the code buys); perturbing only the preview fails it immediately.

Nothing here deletes

  • The route is GET, calls only the selection, and never reaches a delete.
  • A test asserts the bucket is byte-for-byte unchanged after a preview — same
    keys, same contents.
  • Retention itself stays on the cron. No second deleter.
  • Unauthenticated → 403 before the bucket is read, so no object key can leak;
    asserted.

Plan

Plan 313's §4.4 amendment claimed WS4 was wholly open. Narrowed: the preview
half shipped, the deletion becoming an operator-invoked step is what remains,
along with a way to run the cron backup without the prune attached.

Note for the merge order

#387 (the retention log) is still open and touches the same function. It
refactors pruneBackups into "compute stale, then delete, then log"; this PR
moves that same computation into selectStaleBackups. Whichever lands second
keeps both — the log line and the shared selection are independent. The preview's
output is deliberately phrased like #387's log line, so a prediction and the
record of a real run read as one story.

🤖 Generated with Claude Code

https://claude.ai/code/session_011sk9BLaUZDkPVAZ1sKhuDP

prisis and others added 2 commits August 9, 2026 10:34
`backupRetain` deletes on every cron run, R2 deletes have no undo, and the
thing deleted is a backup — so the only way to learn what a retention setting
does on a real bucket was to let it run and read what was gone. That is a poor
trade for a subsystem where both defects found in review were silent data loss,
and it is worse than it sounds because eligibility turns on a metadata marker
that legacy sidecars lack: on any pre-existing bucket, retention may own far
fewer snapshots than the bucket holds, and nothing said so.

`GET /_lunora/admin/backup/retention` answers "what would go next", and
`lunora backup retention` prints it. The worker has to be the one to answer —
it is the only party that knows its own `backupCron` and `backupRetain`, and
the marker is not visible in a plain listing.

The selection is shared, not re-derived. `pruneBackups` already computed its
set before deleting; that computation is now `selectStaleBackups`, which both
the prune and the preview call. A preview that can disagree with the prune is
worse than no preview, and this subsystem has twice shown what happens when one
rule gets written in two places. The test seeds one bucket with every case that
makes eligibility subtle — a legacy sidecar, another deployment's cron, an
operator's own snapshot — then runs the preview and a real cron fire against
identical bucket state and asserts the sets match. Diverging only the preview
fails it; perturbing the shared function moves both and is caught elsewhere.

Nothing here deletes. The route reads, the verb reads, and a test asserts the
bucket is byte-for-byte unchanged after a preview. Retention itself stays on
the cron — this adds no second deleter.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011sk9BLaUZDkPVAZ1sKhuDP
Plan 313's §4.4 amendment said WS4 was wholly open; half of it is now done.
The preview closes the "see it coming" half; what remains is the deletion
becoming a step an operator invokes rather than a side effect of a backup
succeeding.

The docs say to run the preview after changing `backupRetain` and on any bucket
that predates the marker — the case where the answer is least deducible from
the config.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011sk9BLaUZDkPVAZ1sKhuDP
@netlify

netlify Bot commented Aug 9, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for lunorash ready!

Name Link
🔨 Latest commit 191358b
🔍 Latest deploy log https://app.netlify.com/projects/lunorash/deploys/6a783d06276750000852663e
😎 Deploy Preview https://deploy-preview-388--lunorash.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@prisis, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 24 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: c2539311-3df8-43d7-b000-ff7f769db51b

📥 Commits

Reviewing files that changed from the base of the PR and between 2dc73bf and 191358b.

⛔ Files ignored due to path filters (5)
  • api-snapshots/lunora.api.md is excluded by none and included by none
  • api-snapshots/runtime.api.md is excluded by none and included by none
  • packages/cli/__tests__/commands/backup.test.ts is excluded by !**/__tests__/**, !**/*.test.ts and included by packages/**
  • packages/runtime/__tests__/scheduled-backup.test.ts is excluded by !**/__tests__/**, !**/*.test.ts and included by packages/**
  • plans/313-r2-backup-tier.md is excluded by none and included by none
📒 Files selected for processing (8)
  • apps/docs/src/content/docs/concepts/backups.mdx
  • packages/cli/docs/index.mdx
  • packages/cli/src/commands/backup/handler.ts
  • packages/cli/src/commands/backup/index.ts
  • packages/runtime/docs/index.mdx
  • packages/runtime/src/create-worker.ts
  • packages/runtime/src/index.ts
  • packages/runtime/src/scheduled-backup.ts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Thank you for following the naming conventions! 🙏

@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Thank you for confirming the Contributor License Agreement! 🙏

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.48276% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.09%. Comparing base (95d33d6) to head (191358b).
⚠️ Report is 67 commits behind head on alpha.

Files with missing lines Patch % Lines
packages/cli/src/commands/backup/handler.ts 78.37% 8 Missing ⚠️
packages/runtime/src/scheduled-backup.ts 93.75% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##            alpha     #388    +/-   ##
========================================
  Coverage   87.09%   87.09%            
========================================
  Files        1172     1177     +5     
  Lines       63383    63618   +235     
  Branches    15447    15641   +194     
========================================
+ Hits        55202    55411   +209     
- Misses       7654     7677    +23     
- Partials      527      530     +3     
Files with missing lines Coverage Δ
packages/cli/src/commands/backup/index.ts 25.00% <ø> (ø)
packages/runtime/src/create-worker.ts 87.96% <100.00%> (-0.26%) ⬇️
packages/runtime/src/index.ts 100.00% <ø> (ø)
packages/runtime/src/scheduled-backup.ts 94.52% <93.75%> (ø)
packages/cli/src/commands/backup/handler.ts 84.74% <78.37%> (-2.33%) ⬇️

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@codspeed

codspeed Bot commented Aug 9, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 253 untouched benchmarks
⏩ 10 skipped benchmarks1


Comparing feat/backup-retention-preview (191358b) with alpha (1762097)2

Open in CodSpeed

Footnotes

  1. 10 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

  2. No successful run was found on alpha (2dc73bf) during the generation of this report, so 1762097 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@prisis

prisis commented Aug 9, 2026

Copy link
Copy Markdown
Member Author

Superseded by #389, merged as 01dc8bf40.

This branch is an ancestor of feat/backup-prune-verb, so its commits went in with that merge. Because the repo squash-merges, they do not appear in alpha's history under their own shas and this PR will keep reporting as unmerged — the content is in.

Verified on alpha rather than inferred from PR state: the retention preview route, both retention log records, the retention and prune CLI verbs, and pruneBackups being reachable only from runBackupPrune (the scheduled path calls selectStaleBackups and never deletes).

@prisis prisis closed this Aug 9, 2026
@prisis
prisis deleted the feat/backup-retention-preview branch August 11, 2026 22:29
@github-actions

Copy link
Copy Markdown
Contributor

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.
Please note this issue tracker is not a help forum. We recommend using our GitHub Discussions tab for questions.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Sep 10, 2026

This branch was previously deployed

1 inactive deployment
benchmarks — 191358b4 Deployed Aug 9, 2026 by prisis via Benchmarks #1604
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants