Skip to content

fix: cap long SDK retry-after waits#68474

Merged
steipete merged 1 commit into
openclaw:mainfrom
jetd1:fix/anthropic-429-retry-after-threshold
Apr 23, 2026
Merged

fix: cap long SDK retry-after waits#68474
steipete merged 1 commit into
openclaw:mainfrom
jetd1:fix/anthropic-429-retry-after-threshold

Conversation

@jetd1

@jetd1 jetd1 commented Apr 18, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Cap long provider SDK retry waits before they block OpenClaw model failover.
  • When a Stainless-based SDK retryable response (408, 409, 429, or 5xx) includes retry-after-ms or retry-after above 60 seconds, OpenClaw injects x-should-retry: false into the response so Anthropic/OpenAI SDKs surface the error immediately.
  • Keep short retry windows untouched so SDKs still handle normal transient throttling.
  • Add OPENCLAW_SDK_RETRY_MAX_WAIT_SECONDS to tune the cap; set it to 0, false, off, none, or disabled to leave long SDK sleeps intact.

Why

Anthropic and OpenAI's Stainless-based TypeScript SDKs check x-should-retry before their built-in retry status handling, and parse retry-after-ms / retry-after into retry sleep durations. Without this cap, a long provider retry window can make an interactive OpenClaw run silently wait inside the SDK instead of returning control to OpenClaw's auth/profile/model failover layer.

Refs: cline/cline#10139

Test plan

  • Verified Anthropic/OpenAI SDK source behavior for x-should-retry, retryable statuses, and retry-after-ms / retry-after parsing.
  • pnpm test src/agents/provider-transport-fetch.test.ts
  • pnpm check:changed
  • pnpm check
  • pnpm test ran full suite; one unrelated src/infra/gateway-lock.test.ts stale-lock timing case failed once, then passed on targeted rerun.
  • pnpm test src/infra/gateway-lock.test.ts

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Apr 18, 2026
@greptile-apps

greptile-apps Bot commented Apr 18, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Injects x-should-retry: false into the response headers when a 429 carries a retry-after value above 60 seconds, preventing the Anthropic SDK from sleeping for the full quota-refresh duration and letting OpenClaw's failover layer take over. The implementation is correct — parseFloat with an isNaN guard safely ignores HTTP-date format values, the response body stream is properly transferred before buildManagedResponse wraps it, and the header injection is a no-op for SDKs that don't inspect x-should-retry.

Confidence Score: 5/5

Safe to merge — only finding is a P2 model constant naming preference in the test fixture.

The core logic is correct: 429 detection, numeric parse with NaN guard, threshold comparison, header injection, and response body stream transfer all work as intended. Four new tests cover the meaningful branches. The single comment is a P2 style preference (test model constant claude-opus-4-7 vs sonnet-4.6) with no behavioral impact.

No files require special attention.

Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/agents/provider-transport-fetch.test.ts
Line: 99-103

Comment:
**Prefer `sonnet-4.6` for Anthropic test model constants**

Per the repo testing guidelines, new tests should use `sonnet-4.6` (not `claude-opus-4-7`) as the canonical Anthropic model fixture. The model ID has no effect on the 429 logic being tested, so the swap is mechanical.

```suggestion
    const anthropicModel = {
      id: "sonnet-4.6",
      provider: "anthropic",
      api: "anthropic-messages",
      baseUrl: "https://api.anthropic.com/v1",
    } as unknown as Model<"anthropic-messages">;
```

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "fix: skip SDK retry on 429 with retry-af..." | Re-trigger Greptile

Comment thread src/agents/provider-transport-fetch.test.ts Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 99561b5bd7

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/agents/provider-transport-fetch.ts Outdated
@jetd1
jetd1 force-pushed the fix/anthropic-429-retry-after-threshold branch from 99561b5 to f865ae5 Compare April 18, 2026 09:13
@jetd1 jetd1 changed the title fix: skip SDK retry on Anthropic 429 with retry-after > 60s fix: skip SDK retry on 429 with long retry-after across providers Apr 18, 2026
@jetd1
jetd1 force-pushed the fix/anthropic-429-retry-after-threshold branch 2 times, most recently from f3b1673 to a48822e Compare April 22, 2026 17:26
@jetd1
jetd1 requested review from a team as code owners April 22, 2026 17:26
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: discord Channel integration: discord gateway Gateway runtime cli CLI command changes scripts Repository scripts docker Docker and sandbox tooling extensions: qa-lab extensions: codex size: L and removed size: M labels Apr 22, 2026
@steipete
steipete force-pushed the fix/anthropic-429-retry-after-threshold branch from a48822e to 0d1afa7 Compare April 23, 2026 02:19
@steipete steipete changed the title fix: skip SDK retry on 429 with long retry-after across providers fix: cap long SDK retry-after waits Apr 23, 2026
@openclaw-barnacle openclaw-barnacle Bot removed channel: discord Channel integration: discord gateway Gateway runtime cli CLI command changes scripts Repository scripts labels Apr 23, 2026
@steipete
steipete force-pushed the fix/anthropic-429-retry-after-threshold branch from 0d1afa7 to f5db146 Compare April 23, 2026 02:22
@steipete
steipete force-pushed the fix/anthropic-429-retry-after-threshold branch from f5db146 to 14e1550 Compare April 23, 2026 02:28
@steipete
steipete merged commit b09aed8 into openclaw:main Apr 23, 2026
73 of 74 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Landed via rebase as b09aed8.\n\nValidation:\n- Verified OpenAI/Anthropic Stainless SDK retry behavior: both honor x-should-retry: false before retrying 408/409/429/5xx and parsing retry-after-ms / retry-after.\n- Local: pnpm test src/agents/provider-transport-fetch.test.ts (10/10).\n- Local: pnpm check:changed (386 files, 4062 passed / 4 skipped).\n- CI: standard check/build/test/extension shards green on head 14e15506ef.\n- CI: qa-lab parity gate stayed red with the same mock agentic pack result seen before landing (4/11 pass, 7/11 fail); not blocking merge.\n\nThanks @jetd1!

medikoo pushed a commit to medikoo/openclaw that referenced this pull request Apr 24, 2026
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 9, 2026
@jetd1
jetd1 deleted the fix/anthropic-429-retry-after-threshold branch May 10, 2026 10:58
globalcaos pushed a commit to globalcaos/tinkerclaw that referenced this pull request May 13, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
jameslcowan pushed a commit to jameslcowan/openclaw that referenced this pull request Jun 2, 2026
sablehead pushed a commit to sablehead/openclaw that referenced this pull request Jun 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants