agents icon indicating copy to clipboard operation
agents copied to clipboard

createAI: binding errors flagged retryable: true are not retried

Open mattzcarey opened this issue 1 month ago • 1 comments

When env.AI.run throws an error that the runtime marks retryable: true (e.g. Network connection lost.), createAI wraps it as non-retryable, so the AI SDK's maxRetries never kicks in and fallback legs treat it as terminal.

const ai = createAI({ binding: env.AI });
await generateText({ model: ai("@cf/meta/llama-3.3-70b-instruct-fp8-fast"), prompt, maxRetries: 2 });
// binding throws Object.assign(new Error("Network connection lost."), { retryable: true })
// -> one call, no retry

normalizeThrownError in packages/agents/src/models/core/errors.ts only looks for a known Workers AI code in the message; with no code it sets isRetryable: false and ignores the error's own retryable flag. It should honour retryable: true (and false) when present, before falling back to the code table.

Confirmed with a fake-binding test on main.

From cloudflare/ai#656.

mattzcarey avatar Oct 20 '26 15:10 mattzcarey

Proposed fix on kanchingyg:fix/createai-retryable-flag (API PR creation is blocked by collaborators_only).

Compare: https://github.com/cloudflare/agents/compare/main...kanchingyg:fix/createai-retryable-flag?expand=1

Honours the binding's boolean retryable flag in normalizeThrownError.

kanchingyg avatar Oct 25 '26 00:10 kanchingyg