From 13a2be43d5e89103a024926092b2a88f267f0a58 Mon Sep 17 00:00:00 2001 From: bradyyie Date: Fri, 16 Jan 2026 20:00:31 -0500 Subject: [PATCH] Fix Request object reuse bug in retry logic When a 429 rate limit response occurs, the retryFetch function was attempting to reuse the same Request object for subsequent retry attempts. Request objects in the Fetch API can only be used once - after their body is consumed, they become "used" and cannot be passed to fetch() again. This caused the error: "Cannot construct a Request with a Request object that has already been used" The fix clones the Request object before each fetch attempt, ensuring that retries always work with a fresh, unused Request object. This bug could manifest in high-traffic scenarios where rate limiting occurs, causing workflow executions to fail unexpectedly. --- src/sdk/createConductorClient/helpers/fetchWithRetry.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/sdk/createConductorClient/helpers/fetchWithRetry.ts b/src/sdk/createConductorClient/helpers/fetchWithRetry.ts index 723550f8..9ca09bd5 100644 --- a/src/sdk/createConductorClient/helpers/fetchWithRetry.ts +++ b/src/sdk/createConductorClient/helpers/fetchWithRetry.ts @@ -8,7 +8,12 @@ export const retryFetch = async ( retries = 5, delay = 1000 ): Promise => { - const response = await fetchFn(input, init); + // Clone the Request object if input is a Request, so retries work correctly. + // Request objects can only be used once - attempting to reuse them throws: + // "Cannot construct a Request with a Request object that has already been used" + const requestInput = input instanceof Request ? input.clone() : input; + + const response = await fetchFn(requestInput, init); if (response.status == 429 && retries > 0) { await new Promise((resolve) => setTimeout(resolve, delay)); return retryFetch(input, init, fetchFn, retries - 1, delay * 2);