Repository navigation
github-backup(clone_all): clear partial destinations and retry the clone (#3233) - #4332
Conversation
…one (#3233) A clone killed mid-flight (driver timeout, interrupt, laptop sleep) left a non-empty destination that is not a valid mirror; git refused every rerun with already-exists and nothing cleared it, so the repo stayed unmirrored until manual cleanup. clone_one now clears a partial destination before cloning (clear_partial_dest, guarded to the driver-managed <root>/<owner>/<repo>.git path only; anything outside it fails loudly instead of being removed) and stamps cleared_partial on the clone-status.jsonl record so a cleared-partial retry is distinguishable from an ordinary failure, including on the timeout path. Valid mirrors are untouched (already-present), and an empty directory is not treated as partial. Regression tests (tests/test_clone_all_partial.py) drive the real clone_all.main() with a git-faithful fake clone: the 8 partial-destination checks fail on the previous code and pass now; valid-mirror, absent, and empty-dir controls pass throughout. Sibling suites still pass: drain_queue 54/54, inventory_owner 18/18, reconcile_retention 9/9.
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 1 minute. View limit details
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. |
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c1ed3fa1db
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| # clone below fails on 'already exists' forever. The status | ||
| # record carries cleared_partial so a cleared-partial retry is | ||
| # distinguishable from an ordinary failure in clone-status.jsonl. | ||
| cleared_partial = clear_partial_dest(root, dest) |
There was a problem hiding this comment.
Preserve mirrors when Git inspection fails for policy reasons
If an intact backup has different ownership after a restore, valid_mirror() can return false because Git reports detected dubious ownership, not because the clone is partial. When the running user can remove that tree, this new unconditional cleanup deletes the entire existing backup before attempting a network clone. This was reproduced with a real bare repository whose directory ownership was changed; the legitimate safe.bareRepository=explicit setting also produces the same false-negative. Distinguish inspection or policy errors from confirmed partial destinations before deleting anything, otherwise a failed replacement clone leaves the user without their intact local backup.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 7cf8578 — thank you, this was a real data-loss path.
clone_one now clears a destination only when dest_is_confirmed_partial() positively proves it is not a repository:
- git answering
rev-parse --is-bare-repositoryat all (rc 0) means a real repository lives there — preserved, whatevervalid_mirrorconcluded; - a git failure other than "not a git repository" (dubious ownership,
safe.bareRepository=explicit, any policy/inspection error) — preserved, with a loud fail record naming the path; - only "not a git repository" destinations and stray files at the mirror path are confirmed partial, and those are still cleared (driver-managed-tree guard unchanged) and retried.
Regression coverage added in test_clone_all_partial.py: a policy_error case (fake git refuses inspection of an intact mirror while valid_mirror is patched false) and a real-repo case (git opens the destination though valid_mirror says no) both assert the mirror is untouched, no clone is attempted, and no cleared_partial marker is written. 36/36 checks pass on the laptop.
…3233) Codex P1 on PR #4332: valid_mirror() also returns false for intact mirrors when git refuses inspection for policy reasons (dubious ownership after a restore, safe.bareRepository=explicit) — the first cut would have deleted an intact backup and, if the replacement clone then failed, left no local copy at all. clone_one now clears a destination only when dest_is_confirmed_partial proves it is not a repository: git answering rev-parse at all (rc 0) means a real repository lives there, and any git failure other than not-a-git-repository is an inspection/policy error. Both shapes are preserved with a loud fail record naming the path. Confirmed partials (not-a-repository, stray file) are still cleared and retried as before, still guarded to the driver-managed mirror tree. Tests: new policy_error case (fake git refuses inspection of an intact mirror while valid_mirror is patched false) and real-repo case (git opens the destination though valid_mirror says no) both assert preservation, no clone attempted, no cleared_partial marker; stray-file case asserts clearing. 36/36 checks pass.
Fixes #3233 (queue task 5682).
Problem
clone_all.py'sclone_oneonly checkedvalid_mirror(dest)before cloning. A clone killed mid-flight (driverTIMEOUT=5400, interrupt, laptop sleep) leaves a partial destination that is not a valid mirror;git clone --mirrorrefuses it ("already exists and is not an empty directory") and nothing ever cleared it — the repo stayed unmirrored on every rerun until manual cleanup, andreconcile.py's clone pass inherited the wedge.Change (
infra/github-backup/bin/clone_all.py)clear_partial_dest(root, dest): removes a leftover partial destination, guarded to the driver-managed mirror path only — the destination must resolve to<root>/<owner>/<repo>.gitexactly asmirror_pathbuilds it. Anything outside that tree is left untouched andclone_onefails loudly naming the path, instead of the confusing git error.already-presentbehavior preserved).cleared_partial: truewhenever a partial was cleared — on success, on clone failure, and on theTimeoutExpiredpath — soclone-status.jsonldistinguishes a cleared-partial retry from an ordinary failure.Tests (
infra/github-backup/tests/test_clone_all_partial.py)Drives the real
clone_all.main()against a temp backup root with a git-faithful fakegit clone(refuses non-empty destinations, otherwise creates a real bare mirror;valid_mirrorstays real):cleared_partialset — fails on the previous code (8 partial checks failed pre-fix), passes nowcleared_partialSibling suites on the laptop:
test_drain_queue.py54/54,test_inventory_owner.py18/18,test_reconcile_retention.py9/9.Out of scope per the task packet:
drain_queue.pyack behavior (#3219),inventory_ownernull-owner handling (#3229),fetch_mirrors.py, ROADMAP files.Need help on this PR? Tag
@codesmith-botwith what you need.