From aa1bf5cd109c573b0165e73563011a26f1ee176b Mon Sep 17 00:00:00 2001 From: Bassam Khouri Date: Mon, 15 Jun 2026 14:46:48 -0400 Subject: [PATCH] Add retry when retrieving PR information Fixes: #283 --- .../workflows/scripts/cross-pr-checkout.swift | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/.github/workflows/scripts/cross-pr-checkout.swift b/.github/workflows/scripts/cross-pr-checkout.swift index d9f1ed2a..c4fdea34 100644 --- a/.github/workflows/scripts/cross-pr-checkout.swift +++ b/.github/workflows/scripts/cross-pr-checkout.swift @@ -117,11 +117,23 @@ func getPRInfo(repository: String, prNumber: String) async throws -> PRInfo { throw GenericError("Failed to form URL for GitHub API") } - do { - let data = try await downloadData(from: prInfoUrl) - return try JSONDecoder().decode(PRInfo.self, from: data) - } catch { - throw GenericError("Failed to load PR info from \(prInfoUrl): \(error)") + let maxAttempts = 5 + var attempt = 1 + while true { + do { + let data = try await downloadData(from: prInfoUrl) + return try JSONDecoder().decode(PRInfo.self, from: data) + } catch { + if attempt == maxAttempts { + throw GenericError("Failed to load PR info from \(prInfoUrl) after \(maxAttempts) attempts: \(error)") + } + let delaySeconds = UInt64(1 << (attempt - 1)) + print( + "Failed to load PR info from \(prInfoUrl) (attempt \(attempt) of \(maxAttempts)): \(error). Retrying in \(delaySeconds)s..." + ) + try await Task.sleep(nanoseconds: delaySeconds * 1_000_000_000) + attempt += 1 + } } }