[CI][ROCm] Prevent Git maintenance races during shallow fetches (#52810)

Signed-off-by: Andreas Karatzas <Andreas.Karatzas@amd.com> Co-authored-by: OpenAI Codex <codex@openai.com>

Andreas Karatzas committed Aug 18, 2026 at 17:34 UTC aa6abec49a7ed7e40ee4c2a07586d0d83887fa2a
2 files changed +38 -3
.buildkite/scripts/ci-bake-rocm.sh
+4 -2
@@ -199,11 +199,13 @@ get_buildkite_target_repo_url() {
199
200 git_fetch_with_timeout() {
201 local timeout_secs="${ROCM_CACHE_GIT_FETCH_TIMEOUT:-60}"
202 + local -a fetch_command=(git fetch --no-auto-maintenance)
203
204 + # Detached maintenance can race a later shallow fetch on .git/shallow.
205 if command -v timeout >/dev/null 2>&1; then
204 - timeout "${timeout_secs}s" git fetch "$@"
206 + timeout "${timeout_secs}s" "${fetch_command[@]}" "$@"
207 else
206 - git fetch "$@"
208 + "${fetch_command[@]}" "$@"
209 fi
210 }
211
tests/tools/test_docker_build_metadata_args.py
+34 -1
@@ -8,6 +8,7 @@ from pathlib import Path
8
9 REPO_ROOT = Path(__file__).resolve().parents[2]
10 HELPER = REPO_ROOT / ".buildkite" / "scripts" / "docker-build-metadata-args.sh"
11 +ROCM_CI_BAKE = REPO_ROOT / ".buildkite" / "scripts" / "ci-bake-rocm.sh"
12
13
14 def run_helper(
@@ -165,7 +166,7 @@ def test_rocm_ci_base_bake_embeds_content_hash_label() -> None:
166
167
168 def test_rocm_ci_base_metadata_inputs_cover_ci_base_files() -> None:
168 - ci_bake = (REPO_ROOT / ".buildkite" / "scripts" / "ci-bake-rocm.sh").read_text()
169 + ci_bake = ROCM_CI_BAKE.read_text()
170
171 for expected in (
172 "requirements/common.txt",
@@ -174,3 +175,35 @@ def test_rocm_ci_base_metadata_inputs_cover_ci_base_files() -> None:
175 "docker/Dockerfile.rocm",
176 ):
177 assert expected in ci_bake
178 +
179 +
180 +def test_rocm_git_fetch_disables_automatic_maintenance(tmp_path: Path) -> None:
181 + fake_bin = tmp_path / "bin"
182 + fake_bin.mkdir()
183 + git = fake_bin / "git"
184 + git.write_text('#!/bin/sh\nprintf "%s\\n" "$@"\n')
185 + git.chmod(0o755)
186 +
187 + env = os.environ.copy()
188 + env["PATH"] = f"{fake_bin}:{env['PATH']}"
189 + result = subprocess.run(
190 + [
191 + "bash",
192 + "-c",
193 + 'source "$1"; git_fetch_with_timeout --quiet origin HEAD',
194 + "bash",
195 + str(ROCM_CI_BAKE),
196 + ],
197 + check=True,
198 + env=env,
199 + stdout=subprocess.PIPE,
200 + text=True,
201 + )
202 +
203 + assert result.stdout.splitlines() == [
204 + "fetch",
205 + "--no-auto-maintenance",
206 + "--quiet",
207 + "origin",
208 + "HEAD",
209 + ]