fix(skills-init): clean stale dest before cloning - #2350
Open
mario-valente wants to merge 1 commit into
Open
Conversation
CloneGit never removed a pre-existing ref.Dest before starting. A prior attempt killed between the clone/checkout and applySubPath's final os.Rename leaves the full clone sitting in dest — non-empty, but not yet reduced to the subPath. Every subsequent retry then fails git's own pre-flight "already exists and is not an empty directory" check before touching the network, permanently, even though the container is documented to retry from scratch on failure. Reproduced against a real Agent on AKS: skills-init crash-looped forever after the first (interrupted) attempt left a full-repo clone behind. Fix: os.RemoveAll(ref.Dest) at the top of CloneGit, before any clone attempt, so every invocation genuinely starts from scratch as intended.
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Ensures CloneGit retries truly start from a clean slate by deleting any pre-existing destination directory, preventing permanent failures after interrupted clones (especially when subPath rewriting is involved).
Changes:
- Remove
ref.Destat the start ofCloneGitto avoidgit clonefailing on non-empty destinations. - Add a regression test that simulates a stale destination and asserts
CloneGitsucceeds and removes leftover files.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| go/core/internal/skillsinit/git.go | Deletes ref.Dest before cloning to guarantee retry-from-scratch semantics. |
| go/core/internal/skillsinit/clonegit_stale_dest_test.go | Adds a regression test proving stale destination cleanup works. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+29
to
+31
| if err := os.RemoveAll(ref.Dest); err != nil { | ||
| return fmt.Errorf("clean stale dest %q: %w", ref.Dest, err) | ||
| } |
| } | ||
|
|
||
| origin := t.TempDir() | ||
| runIn(t, origin, "init", "--initial-branch=main") |
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
CloneGitnever removes a pre-existingref.Destbefore starting a clone, so a leftover from any prior failed attempt permanently poisons every retry withdestination path already exists and is not an empty directory— the pre-flight check in git's ownclonefails before any network I/O.Note on how this was hit: in our case the original trigger of that first failed attempt was a separate bug in this same file —
Full: true'sgit checkout -- <ref.Ref>treats a 40-hex SHA as a pathspec (because of the--separator) and always exits 1, so the clone (step 1) succeeds and leavesdestfully populated, but the checkout (step 2) fails every time andapplySubPathnever runs. I'm not fixing that pathspec bug here (worked around it operationally by switching to a branch/tag ref, avoiding theFull: truepath entirely) but wanted to flag it separately since it's the more common way to end up in the stuck state this PR fixes. Filing this PR for the general idempotency gap regardless: any interrupted attempt (OOM, node preemption, unrelated pod restart) leaves the same poisoneddest, not just the pathspec case.Fix
os.RemoveAll(ref.Dest)at the top ofCloneGit, before any clone attempt, so every invocation genuinely starts from scratch — matching whatRun's own doc comment already claims happens ("the container restarts and re-runs from scratch").Test plan
Test_CloneGit_cleansStaleDest: seedsdestwith leftover content from a simulated interrupted attempt, then assertsCloneGitagainst a local git fixture repo succeeds and the stale content is gone.go test ./core/internal/skillsinit/...— all passing (including pre-existing tests, no regressions).