feat(drive,cli): add drive lease prune command (#1678) - #1684
Merged
Merged
Conversation
Bounds the lease ledger's and the backup directory/folder's unbounded growth, the ADR-0080 Consequences fast-follow named at #1664's close. Mirrors `omni-dev log prune`'s shape (--older-than/--max-size/--dry-run) but a live lease is never a candidate, and a ledger row is dropped only together with the backup it points at: a Bytes backup is deleted from disk, a DriveCopy backup is moved to Drive Trash via a new FilesApi::trash (the integration's first delete-adjacent capability, deliberately reversible rather than a permanent files.delete).
CoverageTotal: 97.28% ⚪ 0.01 pp vs Comparing
🔇 5 ignored region(s), 0 tolerated region(s)
Patch coveragePatch: 100% (1179/1179 new lines covered)
|
Persist the ledger immediately after each row's backup is cleared, inside the removal loop, instead of once at the end — a crash mid-run now strands at most the one row it was working on rather than the whole batch. Align the --older-than cutoff boundary with request_log::keep_by_age's inclusive semantics (a row expiring exactly at the cutoff survives). Fold WriteCapability::Trash into Metadata, since they gate the identical scope and only differed in wording. Document drive lease prune in docs/drive.md's Lease section and update ADR-0080's Consequences/Sync-obligation text now that it has landed.
…rune Fix a real correctness bug: --max-size alone could trash a zero-byte DriveCopy backup when it sorted behind an oversized Bytes backup that alone exceeded the budget, contradicting the documented "DriveCopy is only reachable via --older-than" contract. The size filter now sets DriveCopy rows aside before computing the byte budget, so they never participate in it regardless of position. Shrink the ledger lock's hold time: rather than one continuous lock across the whole run (including every sequential Drive trash call), the lock is now taken once to snapshot removal candidates and once per row (via the existing mutate_locked) to persist that row's own removal — the same brief load-mutate-save discipline every other lease command already uses, so a large prune no longer blocks concurrent acquire/restore/writes for the run's full duration. Log and audit every removal attempt: a clear_backup failure now carries its token/file id/error into a tracing::warn! instead of collapsing into an opaque count, and every attempt (pruned or failed) writes its own best-effort audit.jsonl record, mirroring acquire's audit trail so "why is this backup gone" stays answerable per lease. Smaller fixes: the CLI summary no longer claims backups were "trashed"/bytes were "freed" in past tense under --dry-run; a pre-existing acquire.rs comment claiming prune reclaims the AlreadyLeased race's orphaned backup is corrected (prune only ever walks existing ledger rows, so that orphan is a known, separate gap); a ledger-save failure immediately after a backup was cleared now surfaces a loud, actionable error naming the stranded token instead of propagating a generic one.
Adds direct/targeted tests for the lines PR #1684's coverage bot flagged: backup_size's DriveCopy arm, PruneOutcome's JsonlSerialize impl, a Bytes backup's NotFound-tolerated and non-NotFound-failure clear_backup paths, the best-effort audit-write failure being warned and swallowed, the --max-size-only/older_than:None CLI branch dispatched through LeaseCommand::execute, the dry-run and non-dry-run human-readable table summaries, and the "cleared the backup but failed to persist its ledger removal" dangling-row error path (forced deterministically via a delayed mock response plus a background thread that revokes the ledger directory's write permission mid-run).
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.
Summary
drive lease prune, bounding the lease ledger's and the backup directory/folder's unbounded growth — the ADR-0080 Consequences fast-follow named at drive: gate content writes behind a Touch ID-authorised backup lease, with a fail-closed audit log #1664's close.omni-dev log prune's shape (--older-than/--max-size/--dry-run, at least one bound required, age filter then size filter). A live lease is never a removal candidate, regardless of bounds.Bytesbackup is deleted from local disk, aDriveCopybackup is moved to Drive Trash via a newFilesApi::trash(files.updatewithtrashed: true) — the integration's first delete-adjacent capability, deliberately reversible (Trash, not permanentfiles.delete).Test plan
cargo buildcargo fmt --checkcargo clippy --all-targets -- -D warningscargo test(full suite green; the two pre-existingdaemon_test.rslifecycle flakes are unrelated — no daemon files touched)update-snapshotsskill run —help_allsnapshot diff reviewed and accepted, adds only the newprunesubcommand's help text