Bounty
XE-0056 · Bounty

sdk: a 429 rate limit is classified as non retryable, so XeClient gives up after one attempt and ignores Retry-After (Minor)

Accepted claimed Minor xe#76 filed 2026-10-26 20:20 UTC by BoomGone

Report

  • Suggested tier: Minor, possibly Medium (degradation under load for every SDK client)
  • Area: SDK (@xeprotocol/sdk client retry logic), API rate limiting
  • Found: 2026-10-26, SDK master 0dbc92e, node repo master 9787859

Summary

When a node rate limits a client it answers 429 {"error":"rate limit exceeded"} with no retryable field (api/handler.go:368). The SDK decides retryability as typeof rec['retryable'] === 'boolean' ? rec['retryable'] : res.status >= 500 (src/client.ts:197). 429 is below 500, so retryable is false, isRetryable(err) is false, and XeClient.request gives up after one attempt even with retries: 3.

A rate limit is temporary by definition. The docs tell clients to back off on 429 using Retry-After (https://test.network/developers#rate-limits; llms-full.txt: "a 429 adds Retry-After"), and the deployment docs warn that clients of the public nodes share one egress bucket behind Caddy, so "a plain sequential sweep of the public URLs can trip 429, back off rather than retry hot". The SDK tutorial "Errors and retries" says "The HTTP client already retries retryable failures" and that isRetryable(err) "answers the question for you". For 429 it answers wrongly, so the recommended withRetry loop in that tutorial also stops.

Evidence

src/client.ts (SDK 0dbc92e):

const retryable = typeof rec['retryable'] === 'boolean' ? rec['retryable'] : res.status >= 500
throw new XeApiError(message, res.status, retryable, body)

api/handler.go (node 9787859):

if !rls.pick(r).getLimiter(ip).Allow() {
    writeError(w, http.StatusTooManyRequests, "rate limit exceeded")

Retry-After is never read anywhere in the SDK (grep -rn -i retry-after src returns nothing).

Steps to reproduce

No load needed: the PoC replays the exact 429 bodies through the real SDK with a fake fetch.

  1. git clone https://github.com/xeprotocol/sdk && cd sdk && npm install && npm run build
  2. Save the script below as 002-sdk-429.mjs and point its import at your built dist/index.js.
  3. node 002-sdk-429.mjs

Output on 2026-10-26:

node 429 : status=429 retryable=false isRetryable=false attempts=1 message="rate limit exceeded"
proxy 429: status=429 retryable=false isRetryable=false attempts=1 message="HTTP 429"
node 503 : status=503 retryable=true isRetryable=true attempts=4 message="block rejected: dependency not synced"

The 503 control shows the retry loop itself works (4 attempts = 1 + 3 retries). Both 429 shapes get a single attempt.

Impact

  • Any SDK app that hits the per IP limit fails hard instead of backing off, including leasing flows (hold.ts and attestation.ts also gate on isRetryable). Because clients behind the same egress share a bucket, one heavy user can cause hard failures for other SDK users.
  • Under load the opposite of the intended behaviour happens: callers who wrap operations in their own loop must special case 429 themselves, and the docs tell them not to.
  • No fund risk.

Suggested fix

  1. In #once, treat 429 as retryable (res.status === 429 || res.status >= 500 when the body has no retryable).
  2. Honour Retry-After when present instead of the fixed exponential backoff.
  3. Optionally have the node add "retryable": true to its 429 body.

PoC script (node, no network traffic)

// PoC: the SDK treats a node's 429 as terminal and never retries it.
// A fake fetch replays the exact bodies the node and the proxy send; no network traffic.
import { XeClient, isRetryable } from '../src/sdk/dist/index.js'

async function run(label, status, body, headers = {}) {
  let calls = 0
  const fakeFetch = async () => {
    calls++
    return new Response(JSON.stringify(body), { status, headers: { 'Content-Type': 'application/json', ...headers } })
  }
  const client = new XeClient({ url: 'https://ldn.core.test.network', retries: 3, backoffMs: 1, fetch: fakeFetch })
  try { await client.request('/node') } catch (err) {
    console.log(`${label}: status=${err.status} retryable=${err.retryable} isRetryable=${isRetryable(err)} attempts=${calls} message="${err.message}"`)
  }
}

// Node's own reply, api/handler.go:368 writeError(w, 429, "rate limit exceeded")
await run('node 429 ', 429, { error: 'rate limit exceeded' }, { 'Retry-After': '1' })
// Proxy reply as documented: Error shape, code rate_limited, Retry-After header
await run('proxy 429', 429, { error: { code: 'rate_limited', status: 429, message: 'Too many requests.', hint: 'Wait and retry.', docs: 'https://test.network/developers#rate-limits' } }, { 'Retry-After': '1' })
// Control: a transient 503 from the node is retried as designed
await run('node 503 ', 503, { error: 'block rejected: dependency not synced', retryable: true })

Related

#30 is the opposite direction (terminal blocks marked retryable). Here a temporary condition is marked terminal. The SDK repo has issues disabled, so this is filed here.

Payout

XE address: 6591eab453dbd93b27e2cd674712f94b42d9e7e4d52980b966fa6da4ccd832dc (same as #75; please confirm it is valid for the mainnet payout).

Thread

XE deskteam2026-11-10 00:15 UTCgithub

Read and accepted. It is tracked internally and the fix will land in a public PR; this issue is updated when it does, and the tier and award follow the fix. The desk entry is https://bounty.xe.network/XE-0056.