fix(git): the clone cache heals itself after an interrupted clone or fetch (#486) #487

Merged
sharang merged 1 commits from fix/486-clone-cache-heal into main 2026-10-06 08:19:14 +00:00
Owner

Closes #486. A bug report from the platform session; stage only.

Problem

Scans interrupted by redeploys leave broken entries in the clone cache:

  • an empty directory, which fails with "could not find repository";
  • a half-written FETCH_HEAD, which fails with "corrupted loose reference file".

Every scheduled scan of those targets fails afterwards; nothing cleans the entry.

Change (pipeline/git.rs)

  • Before a fetch: FETCH_HEAD (every fetch writes it anew) and *.lock files under .git are removed. Scans of one target never overlap, so no other git process holds them.
  • Entry does not open as a repository with an origin → it is removed and cloned again, with a WARN naming the tenant and target.
  • A fetch fails with a corruption-class git error (repository, reference, object database, object, index, checkout) → the same, once.
  • Network and remote errors still fail the scan as before.
  • The stored remote is still checked again before every fetch. The existing test a_fetch_rechecks_the_stored_remote caught a first version that skipped it.
  • Atomic clone: a clone is made in .<name>.cloning-<uuid> next to the entry and renamed into place, so an interrupted clone never leaves a half entry. Leftovers of an earlier interrupted clone are removed.

Tests

  • empty directory;
  • garbage FETCH_HEAD, index.lock and refs/heads/main.lock;
  • error classification (repository → broken; network → not);
  • atomic clone from a real repository, with a leftover temp dir;
  • a failing clone leaves nothing behind.

fmt and clippy -D warnings pass. Agent lib: 693 tests; git_source integration: green.

To check on stage

Check 14 in docs/release/staging-test-plan-after-v0.4.5.md:

  1. Break a cache entry in each of the three ways and start a scan after each; all scans must complete.
  2. The two targets that failed overnight must scan again on their next schedule.
  3. In the agent log, grep clone cache entry is not a usable repository / is broken.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p

Closes #486. A bug report from the platform session; stage only. ## Problem Scans interrupted by redeploys leave broken entries in the clone cache: - an empty directory, which fails with "could not find repository"; - a half-written `FETCH_HEAD`, which fails with "corrupted loose reference file". Every scheduled scan of those targets fails afterwards; nothing cleans the entry. ## Change (`pipeline/git.rs`) - **Before a fetch:** `FETCH_HEAD` (every fetch writes it anew) and `*.lock` files under `.git` are removed. Scans of one target never overlap, so no other git process holds them. - **Entry does not open as a repository with an `origin`** → it is removed and cloned again, with a WARN naming the tenant and target. - **A fetch fails with a corruption-class git error** (repository, reference, object database, object, index, checkout) → the same, once. - **Network and remote errors** still fail the scan as before. - **The stored remote** is still checked again before every fetch. The existing test `a_fetch_rechecks_the_stored_remote` caught a first version that skipped it. - **Atomic clone:** a clone is made in `.<name>.cloning-<uuid>` next to the entry and renamed into place, so an interrupted clone never leaves a half entry. Leftovers of an earlier interrupted clone are removed. ## Tests - empty directory; - garbage `FETCH_HEAD`, `index.lock` and `refs/heads/main.lock`; - error classification (repository → broken; network → not); - atomic clone from a real repository, with a leftover temp dir; - a failing clone leaves nothing behind. fmt and clippy `-D warnings` pass. Agent lib: 693 tests; `git_source` integration: green. ## To check on stage Check 14 in `docs/release/staging-test-plan-after-v0.4.5.md`: 1. Break a cache entry in each of the three ways and start a scan after each; all scans must complete. 2. The two targets that failed overnight must scan again on their next schedule. 3. In the agent log, grep `clone cache entry is not a usable repository` / `is broken`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
sharang added 1 commit 2026-10-06 08:10:26 +00:00
fix(git): the clone cache heals itself after an interrupted clone or fetch (#486)
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Check (pull_request) Successful in 7m59s
1b3ac48e03
Closes #486. Scans a redeploy interrupted left broken cache entries
(an empty directory: "could not find repository"; a half-written
FETCH_HEAD: "corrupted loose reference file"), and every scheduled scan
of those targets failed after it.

- Before a fetch: FETCH_HEAD (every fetch writes it anew) and *.lock
  files under .git are removed; a target's scans never overlap, so no
  other git holds them.
- An entry that does not open as a repository with an origin is removed
  and cloned again; a fetch that fails with a corruption-class error
  (repository, reference, object database, object, index, checkout) does
  the same, once, with a WARN naming tenant and target. Network and
  remote errors still fail the scan, and the stored remote is still
  checked before any fetch.
- Clones go into `.<name>.cloning-<uuid>` beside the entry and are renamed
  into place, so an interrupted clone never leaves a half entry; leftovers
  of an earlier one are removed.
- Tests: empty directory, garbage FETCH_HEAD and leftover locks, the
  error classification, an atomic clone from a real repository with a
  leftover temp dir, a failing clone leaving nothing; the existing
  stored-remote recheck stays green.
- Staging test plan: check 14.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
sharang merged commit ecc6466a18 into main 2026-10-06 08:19:14 +00:00
Sign in to join this conversation.