Repository navigation
ci: retry transient compliance export failures #14694
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nv-rinig
merged 4 commits into
ai-dynamo:main
from
xianlubird:codex/compliance-export-retry
Sep 23, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d5896ac
ci: retry transient compliance export failures
xianlubird 78a18d5
ci: run compliance retry regression tests in pre-commit
xianlubird e8b93c4
test(ci): trim redundant compliance retry coverage
xianlubird 1a03cf1
ci: retry source archive export failures
xianlubird File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| #!/usr/bin/env bash | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| # Retry only transient BuildKit transport failures, preserving each attempt's log. | ||
| set -euo pipefail | ||
|
|
||
| destination=$1 | ||
| shift | ||
| attempt_root=$(mktemp -d "${RUNNER_TEMP:-${TMPDIR:-/tmp}}/compliance-extract.XXXXXX") | ||
| echo "Compliance extraction logs: ${attempt_root}" | ||
|
|
||
| for attempt in 1 2 3; do | ||
| output="${attempt_root}/output-${attempt}" | ||
| log="${attempt_root}/attempt-${attempt}.log" | ||
| mkdir -p "$output" | ||
| status=0 | ||
| "$@" --output "type=local,dest=${output}" 2>&1 | tee "$log" || status=$? | ||
| if [ "$status" -eq 0 ]; then | ||
| # Publish only a complete export; failed attempts never reach consumers. | ||
| rm -rf -- "$destination" | ||
| mv -- "$output" "$destination" | ||
| exit 0 | ||
| fi | ||
| rm -rf -- "$output" | ||
|
|
||
| # Inspect the terminal build error, not earlier warnings or command output. | ||
| error=$(grep '^ERROR:' "$log" | tail -n 1 || true) | ||
| if printf '%s\n' "$error" | grep -Eiq \ | ||
| '(process .*did not complete successfully|401 Unauthorized|403 Forbidden|denied:|manifest unknown)'; then | ||
| exit "$status" | ||
| fi | ||
| if [ "$attempt" -eq 3 ] || ! printf '%s\n' "$error" | grep -Eiq \ | ||
| '(Unavailable:.*error reading from server: (unexpected )?EOF|connection reset by peer|transport is closing|unexpected status.*(502 Bad Gateway|503 Service Unavailable|504 Gateway Timeout))'; then | ||
| exit "$status" | ||
| fi | ||
| delay=10 | ||
| [ "$attempt" -eq 2 ] && delay=30 | ||
| echo "::warning::Compliance extraction attempt ${attempt}/3 failed with a transient transport error; retrying in ${delay}s" | ||
| sleep "$delay" | ||
| done |
118 changes: 118 additions & 0 deletions
118
.github/actions/compliance-extract/test_extract_with_retry.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """Exercise the real retry wrapper with a fake BuildKit command and sleep.""" | ||
|
|
||
| import os | ||
| import subprocess | ||
| import tempfile | ||
| import unittest | ||
| from pathlib import Path | ||
|
|
||
| SCRIPT = Path(__file__).with_name("extract-with-retry.sh") | ||
| TRANSIENT = "ERROR: failed to build: failed to solve: Unavailable: error reading from server: EOF" | ||
|
|
||
|
|
||
| class ExtractRetryTest(unittest.TestCase): | ||
| def run_extract(self, errors): | ||
| with tempfile.TemporaryDirectory() as temp: | ||
| root = Path(temp) | ||
| for index, error in enumerate(errors, 1): | ||
| (root / f"error-{index}").write_text(error) | ||
| fake = root / "build" | ||
| fake.write_text( | ||
| """#!/usr/bin/env bash | ||
| set -eu | ||
| count=0 | ||
| [ ! -f "$STATE/count" ] || count=$(cat "$STATE/count") | ||
| count=$((count + 1)) | ||
| echo "$count" > "$STATE/count" | ||
| for arg in "$@"; do | ||
| case "$arg" in type=local,dest=*) output=${arg#type=local,dest=} ;; esac | ||
| done | ||
| mkdir -p "$output" | ||
| echo "$count" > "$output/attempt-$count" | ||
| error="$STATE/error-$count" | ||
| if [ -s "$error" ]; then | ||
| cat "$error" | ||
| exit 7 | ||
| fi | ||
| """ | ||
| ) | ||
| fake.chmod(0o755) | ||
| sleep = root / "sleep" | ||
| sleep.write_text('#!/usr/bin/env bash\necho "$1" >> "$STATE/delays"\n') | ||
| sleep.chmod(0o755) | ||
| destination = root / "result" | ||
| env = dict( | ||
| os.environ, | ||
| STATE=temp, | ||
| RUNNER_TEMP=temp, | ||
| PATH=temp + os.pathsep + os.environ["PATH"], | ||
| ) | ||
| result = subprocess.run( | ||
| ["bash", str(SCRIPT), str(destination), str(fake)], | ||
| env=env, | ||
| capture_output=True, | ||
| text=True, | ||
| ) | ||
| count = int((root / "count").read_text()) | ||
| delays = ( | ||
| (root / "delays").read_text().splitlines() | ||
| if (root / "delays").exists() | ||
| else [] | ||
| ) | ||
| files = sorted(p.name for p in destination.glob("*")) | ||
| logs = list(root.glob("compliance-extract.*/attempt-*.log")) | ||
| self.assertEqual(len(logs), count) | ||
| return result.returncode, count, delays, files | ||
|
|
||
| def test_success(self): | ||
|
xianlubird marked this conversation as resolved.
|
||
| self.assertEqual(self.run_extract([""]), (0, 1, [], ["attempt-1"])) | ||
|
|
||
| def test_transient_recovers_without_partial_files(self): | ||
| self.assertEqual( | ||
| self.run_extract([TRANSIENT, ""]), (0, 2, ["10"], ["attempt-2"]) | ||
| ) | ||
|
|
||
| def test_exhaustion_preserves_failure(self): | ||
| self.assertEqual(self.run_extract([TRANSIENT] * 3), (7, 3, ["10", "30"], [])) | ||
|
|
||
| def test_deterministic_errors_do_not_retry(self): | ||
| for error in [ | ||
| "ERROR: failed to solve: process did not complete: exit code: 1", | ||
| "ERROR: failed to authorize: 401 Unauthorized", | ||
| "ERROR: manifest unknown", | ||
| "No solution found when resolving dependencies", | ||
| ]: | ||
| with self.subTest(error=error): | ||
| self.assertEqual(self.run_extract([error]), (7, 1, [], [])) | ||
|
|
||
| def test_earlier_transient_does_not_mask_terminal_failure(self): | ||
| self.assertEqual( | ||
| self.run_extract([TRANSIENT + "\nERROR: manifest unknown"]), (7, 1, [], []) | ||
| ) | ||
|
|
||
| def test_other_transport_errors_recover(self): | ||
| for error in [ | ||
| "ERROR: failed to solve: connection reset by peer", | ||
| "ERROR: failed to solve: rpc error: transport is closing", | ||
| "ERROR: failed to solve: unexpected status from HEAD request: 503 Service Unavailable", | ||
| ]: | ||
| with self.subTest(error=error): | ||
| self.assertEqual( | ||
| self.run_extract([error, ""]), (0, 2, ["10"], ["attempt-2"]) | ||
| ) | ||
|
|
||
| def test_build_command_containing_transport_text_does_not_retry(self): | ||
| error = 'ERROR: process "echo connection reset by peer" did not complete successfully: exit code: 1' | ||
| self.assertEqual(self.run_extract([error]), (7, 1, [], [])) | ||
|
|
||
| def test_permanent_error_after_retry_stops(self): | ||
| self.assertEqual( | ||
| self.run_extract([TRANSIENT, "ERROR: manifest unknown"]), (7, 2, ["10"], []) | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.