Skip to content

feat(subgraph): built-in retry with exponential backoff for subgraph queries - #160

Merged
Lakes41 merged 1 commit into
Adamantine-guild:mainfrom
addnad:feat/subgraph-retry-backoff
Jul 30, 2026
Merged

feat(subgraph): built-in retry with exponential backoff for subgraph queries#160
Lakes41 merged 1 commit into
Adamantine-guild:mainfrom
addnad:feat/subgraph-retry-backoff

Conversation

@addnad

@addnad addnad commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

What

Adds a built-in retry mechanism with exponential backoff to SubgraphClient, so transient subgraph/gateway failures no longer surface instantly as errors to downstream apps.

  • Retryable: network errors (fetch rejection), HTTP 5xx, invalid/truncated response bodies
  • Never retried: HTTP 4xx (incl. 400 Bad Request), GraphQL-level errors
  • Backoff: 500ms → 1s → 2s (base configurable via retryDelay)
  • Configurable: SubgraphClientOptions.retries (default 3) and retryDelay (default 500); retries: 0 opts out entirely

All retry logic lives in rawQuery, so every public method (getTopTraders, getTrades, getVaultSnapshots, getSyncStatus) benefits automatically. Existing error messages and WhiteChainError semantics are preserved.

Note: the issue lists src/api/graphqlClient.ts as the likely affected file — that path doesn't exist in the repo; the actual data-fetching module is src/subgraph/Client.ts, which is what this PR modifies.

Acceptance criteria

  • ✅ Failed queries automatically retry up to 3 times by default
  • ✅ 400 Bad Request errors are not retried (test: single fetch call, immediate throw)
  • ✅ Unit tests mock network failures and verify the backoff timing with fake timers (499ms → no retry, 500ms → retry; 1s; 2s)

Also: package.json repair (required)

package.json on main is not parseable JSON (missing }, after the ./zk export block; stray vitest/ws entries inside peerDependenciesMeta), so no npm script can run at all on a clean checkout. This PR repairs it minimally, matching the lockfile (ws → devDependencies, duplicate vitest dropped). Without this, the required local verification (npm run build, tests) cannot even start.

Verification

npx vitest run tests/subgraph/
Test Files  2 passed (2)
Tests  14 passed (14)   ← 8 new retry tests + 6 existing, all green

Full-workspace npm run build still fails on main-pre-existing syntax errors in unrelated files (src/utils/index.ts:13-15, tsconfig.esm.json:11) — verified present on a clean checkout before this change; left untouched as they're outside this issue's scope (and possibly other campaign issues).

Closes #149

…bgraphClient

Transient failures (network errors, HTTP 5xx, invalid response bodies) are
now retried automatically — 3 retries by default with exponential backoff
(500ms, 1s, 2s). HTTP 4xx and GraphQL-level errors are never retried.
Configurable via new SubgraphClientOptions.retries / retryDelay; retries: 0
opts out entirely.

Also repairs two pre-existing JSON syntax errors in package.json (missing
brace after the ./zk export, stray entries in peerDependenciesMeta) that
made npm unable to parse the manifest — required to run any npm script.

Closes Adamantine-guild#149
@Lakes41
Lakes41 merged commit faf7918 into Adamantine-guild:main Jul 30, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add built-in retry mechanism with exponential backoff for subgraph queries

2 participants