fix(git): clone and fetch retry three times on a 5xx or connection error #546

Merged
sharang merged 1 commits from fix/git-fetch-retry into main 2026-10-09 14:22:35 +00:00
Owner

On 2026-10-09 a tenant's managed Gitea was OOM-killed and restarted; six scheduled scans that cloned during the restart failed with Git error: unexpected http status code: 502.

What changes

  • New pipeline/git_retry.rs: Backoff (schedule 5 s, 15 s, 30 s) with retry(what, op), and is_transient(&git2::Error).
    • Retried: HTTP 5xx (unexpected http status code: 5xx), ErrorCode::Timeout, ErrorClass::Net (connect refused, resolve, socket read/write) except the URL errors (invalid url, invalid scp-style path, cannot redirect).
    • Not retried: ErrorCode::Auth (401), 403, 404, reference/repository errors, and AgentError::Other (so the GIT_CLONE_TIMEOUT_SECS / GIT_CLONE_MAX_MB limits never retry).
  • GitOps::clone_or_fetch retries the fetch of a cached entry (before the corruption fallback can mistake a 502 for a broken entry) and the atomic clone (which cleans its temp dir per attempt). Submodule fetches retry too. This covers every caller: orchestrator, PR review, ingest, graph and chat builds.
  • Each retry: WARN with attempt, wait_secs, error. The final error is returned unchanged, so callers log it as before.
  • The wait uses block_in_place on a multi-thread runtime, so the other tasks on that worker move elsewhere while it sleeps.

Tests

  • git_retry::tests: 502/503/500 transient; connection refused, timeout, unresolved transient; 401/403/404/missing ref/invalid URL/redirect not; fails twice then succeeds (3 runs); fails 4 times then errors (4 runs); permanent and limit errors run once; default schedule 5/15/30.
  • git::tests::a_clone_the_host_answers_with_502_is_tried_four_times: a local TCP server answering 502 sees exactly 4 requests and no checkout is left behind.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p

On 2026-10-09 a tenant's managed Gitea was OOM-killed and restarted; six scheduled scans that cloned during the restart failed with `Git error: unexpected http status code: 502`. ## What changes - New `pipeline/git_retry.rs`: `Backoff` (schedule 5 s, 15 s, 30 s) with `retry(what, op)`, and `is_transient(&git2::Error)`. - Retried: HTTP 5xx (`unexpected http status code: 5xx`), `ErrorCode::Timeout`, `ErrorClass::Net` (connect refused, resolve, socket read/write) except the URL errors (`invalid url`, `invalid scp-style path`, `cannot redirect`). - Not retried: `ErrorCode::Auth` (401), 403, 404, reference/repository errors, and `AgentError::Other` (so the `GIT_CLONE_TIMEOUT_SECS` / `GIT_CLONE_MAX_MB` limits never retry). - `GitOps::clone_or_fetch` retries the fetch of a cached entry (before the corruption fallback can mistake a 502 for a broken entry) and the atomic clone (which cleans its temp dir per attempt). Submodule fetches retry too. This covers every caller: orchestrator, PR review, ingest, graph and chat builds. - Each retry: WARN with `attempt`, `wait_secs`, error. The final error is returned unchanged, so callers log it as before. - The wait uses `block_in_place` on a multi-thread runtime, so the other tasks on that worker move elsewhere while it sleeps. ## Tests - `git_retry::tests`: 502/503/500 transient; connection refused, timeout, unresolved transient; 401/403/404/missing ref/invalid URL/redirect not; fails twice then succeeds (3 runs); fails 4 times then errors (4 runs); permanent and limit errors run once; default schedule 5/15/30. - `git::tests::a_clone_the_host_answers_with_502_is_tried_four_times`: a local TCP server answering 502 sees exactly 4 requests and no checkout is left behind. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
sharang added 1 commit 2026-10-09 14:01:22 +00:00
fix(git): clone and fetch retry three times on a 5xx or connection error
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 9m57s
d78d143457
A git host that restarts answers 502 or refuses connections for a few
seconds, and every scan cloning in that window failed with "unexpected
http status code: 502". A clone, fetch or submodule fetch that fails with
a 5xx status, a timeout or a network error is now tried again after 5,
15 and 30 seconds. Authentication failures, 403, 404, bad references and
the download limits fail at once, as before. Each retry is logged at WARN
with the attempt and the wait; the wait hands the worker's other tasks to
another worker (block_in_place), so a waiting retry does not stall them.

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