fix(core): honor provider retry header (#43773)

This commit is contained in:
Aiden Cline
2026-08-20 23:43:52 -05:00
committed by Aiden Cline
parent d993f1b8ed
commit b84f5ad2fb
2 changed files with 28 additions and 0 deletions
@@ -15,6 +15,9 @@ export class RetryableFailure extends Data.TaggedError("SessionRunner.RetryableF
}> {}
export function isRetryable(error: AIError) {
const override = "http" in error.reason ? error.reason.http?.response?.headers["x-should-retry"] : undefined
if (override === "true") return true
if (override === "false") return false
switch (error.reason._tag) {
case "RateLimit":
case "ProviderInternal":
+25
View File
@@ -176,4 +176,29 @@ describe("toSessionError", () => {
expect(retryable.map(SessionRunnerRetry.isRetryable)).toEqual([true, true])
expect(ineligible.map(SessionRunnerRetry.isRetryable)).toEqual([false, false, false])
})
test("honors provider retry header overrides", () => {
const http = (headers: Record<string, string>) =>
new HttpContext({
request: new HttpRequestDetails({ method: "POST", url: "https://example.com", headers: {} }),
response: new HttpResponseDetails({ status: 500, headers }),
})
expect(
SessionRunnerRetry.isRetryable(
llm(
new ProviderInternalReason({
message: "do not retry",
status: 500,
http: http({ "x-should-retry": "false" }),
}),
),
),
).toBeFalse()
expect(
SessionRunnerRetry.isRetryable(
llm(new InvalidRequestReason({ message: "retry", http: http({ "x-should-retry": "true" }) })),
),
).toBeTrue()
})
})