{"id":"XE-0056","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"76","source_url":"https://github.com/xeprotocol/xe/issues/76","reporter_id":25,"title":"sdk: a 429 rate limit is classified as non retryable, so XeClient gives up after one attempt and ignores Retry-After (Minor)","area":"sdk-docs-web","claimed_tier":"minor","assessed_tier":null,"verdict":null,"duplicate_of":null,"tracked":true,"internal_ref":"","internal_url":null,"status":"accepted","closed_reason":null,"github_state":"open","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-10-29T13:57:19.852748+00:00","updated_at":"2026-11-10T11:38:22.246377+00:00","source_created_at":"2026-10-26T20:20:51+00:00","told_at":"2026-11-10T00:15:45+00:00","status_changed_at":"2026-10-29T14:04:13.308307+00:00","url":"https://bounty.xe.network/XE-0056","body":"- Suggested tier: Minor, possibly Medium (degradation under load for every SDK client)\n- Area: SDK (`@xeprotocol/sdk` client retry logic), API rate limiting\n- Found: 2026-10-26, SDK master `0dbc92e`, node repo master `9787859`\n\n## Summary\n\nWhen 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`.\n\nA 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.\n\n## Evidence\n\n`src/client.ts` (SDK `0dbc92e`):\n\n```ts\nconst retryable = typeof rec['retryable'] === 'boolean' ? rec['retryable'] : res.status >= 500\nthrow new XeApiError(message, res.status, retryable, body)\n```\n\n`api/handler.go` (node `9787859`):\n\n```go\nif !rls.pick(r).getLimiter(ip).Allow() {\n    writeError(w, http.StatusTooManyRequests, \"rate limit exceeded\")\n```\n\n`Retry-After` is never read anywhere in the SDK (`grep -rn -i retry-after src` returns nothing).\n\n## Steps to reproduce\n\nNo load needed: the PoC replays the exact 429 bodies through the real SDK with a fake `fetch`.\n\n1. `git clone https://github.com/xeprotocol/sdk && cd sdk && npm install && npm run build`\n2. Save the script below as `002-sdk-429.mjs` and point its import at your built `dist/index.js`.\n3. `node 002-sdk-429.mjs`\n\nOutput on 2026-10-26:\n\n```\nnode 429 : status=429 retryable=false isRetryable=false attempts=1 message=\"rate limit exceeded\"\nproxy 429: status=429 retryable=false isRetryable=false attempts=1 message=\"HTTP 429\"\nnode 503 : status=503 retryable=true isRetryable=true attempts=4 message=\"block rejected: dependency not synced\"\n```\n\nThe 503 control shows the retry loop itself works (4 attempts = 1 + 3 retries). Both 429 shapes get a single attempt.\n\n## Impact\n\n- 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.\n- 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.\n- No fund risk.\n\n## Suggested fix\n\n1. In `#once`, treat 429 as retryable (`res.status === 429 || res.status >= 500` when the body has no `retryable`).\n2. Honour `Retry-After` when present instead of the fixed exponential backoff.\n3. Optionally have the node add `\"retryable\": true` to its 429 body.\n\n## PoC script (node, no network traffic)\n\n```js\n// PoC: the SDK treats a node's 429 as terminal and never retries it.\n// A fake fetch replays the exact bodies the node and the proxy send; no network traffic.\nimport { XeClient, isRetryable } from '../src/sdk/dist/index.js'\n\nasync function run(label, status, body, headers = {}) {\n  let calls = 0\n  const fakeFetch = async () => {\n    calls++\n    return new Response(JSON.stringify(body), { status, headers: { 'Content-Type': 'application/json', ...headers } })\n  }\n  const client = new XeClient({ url: 'https://ldn.core.test.network', retries: 3, backoffMs: 1, fetch: fakeFetch })\n  try { await client.request('/node') } catch (err) {\n    console.log(`${label}: status=${err.status} retryable=${err.retryable} isRetryable=${isRetryable(err)} attempts=${calls} message=\"${err.message}\"`)\n  }\n}\n\n// Node's own reply, api/handler.go:368 writeError(w, 429, \"rate limit exceeded\")\nawait run('node 429 ', 429, { error: 'rate limit exceeded' }, { 'Retry-After': '1' })\n// Proxy reply as documented: Error shape, code rate_limited, Retry-After header\nawait 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' })\n// Control: a transient 503 from the node is retried as designed\nawait run('node 503 ', 503, { error: 'block rejected: dependency not synced', retryable: true })\n```\n\n## Related\n\n#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.\n\n## Payout\n\nXE address: `6591eab453dbd93b27e2cd674712f94b42d9e7e4d52980b966fa6da4ccd832dc` (same as #75; please confirm it is valid for the mainnet payout).\n","patch_refs":[],"thread":[{"id":1573,"source":"github","source_ref":"6755093463","author":"XE desk","team":true,"body":"Read and accepted. It is tracked internally and the fix will land in a public PR; this issue is\nupdated when it does, and the tier and award follow the fix. The desk entry is https://bounty.xe.network/XE-0056.","created_at":"2026-11-10T00:15:45+00:00"}]}