Skip to content

fix(graphql-query): retry admission-control refusals and keep Retry-After - #2102

Open
Zetazzz wants to merge 1 commit into
mainfrom
fix/query-client-retryable-refusals
Open

Zetazzz wants to merge 1 commit into
mainfrom
fix/query-client-retryable-refusals

Conversation

@Zetazzz

@Zetazzz Zetazzz commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Problem

When admission control refuses a request because its API already has too many requests in flight, the server answers HTTP 429 with Retry-After and the CONCURRENCY_LIMIT_REACHED code. On the client side:

  • the code comes through, but isRetryable() doesn't list it, so retry logic built on it gives up on a refusal that's designed to clear;
  • Retry-After is dropped, so a caller that does retry can't wait as long as the server asked.

Change

  • isRetryable() now includes CONCURRENCY_LIMIT_REACHED.
  • Retry-After on an HTTP error response, in seconds or as an HTTP date, is kept in the error's context as retryAfterSeconds. The server's own context, such as limit, is kept alongside it.
  • retryAfterMs(error) returns that wait in milliseconds, or undefined when the response had none. It's exported from @constructive-io/graphql-query, and the codegen client re-exports it like the other error helpers.

For example, with React Query:

import { isRetryable, retryAfterMs } from '@constructive-io/graphql-query';

new QueryClient({
  defaultOptions: {
    queries: {
      retry: (count, error) => count < 3 && isRetryable(error),
      retryDelay: (attempt, error) => retryAfterMs(error) ?? Math.min(1000 * 2 ** attempt, 30_000),
    },
  },
});

Not in this PR

Tests

graphql/query/__tests__/client-retry.test.ts drives execute against mocked fetch responses:

  • a 429 refusal is retryable, keeps its message and the server's context, and reports Retry-After: 5 as 5000 ms;
  • an HTTP-date Retry-After is read, within a second;
  • no Retry-After, or an unreadable one, leaves the wait undefined while the refusal stays retryable;
  • a rejected operation (a validation error) isn't retryable;
  • values that aren't client errors have no wait.

Removing the new code from the list fails three of these; dropping the Retry-After handling fails two.

Run locally

  • graphql/query: 63 passed;
  • tsc --noEmit for graphql/query and graphql/codegen;
  • eslint on the changed files.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added retry support for concurrency-limit errors.
    • Exposed retry delay information in milliseconds when available, including hints provided by the server.
  • Bug Fixes
    • Retry hints are now handled for both numeric delays and HTTP dates; missing or unreadable hints do not produce a delay.
    • GraphQL validation errors remain non-retryable.

…fter

When admission control refuses a request because its API has too many
requests in flight, the server answers HTTP 429 with Retry-After and the
CONCURRENCY_LIMIT_REACHED code. The client parsed that code but
isRetryable() did not list it, and Retry-After was dropped, so callers
could neither tell the refusal would clear nor how long to wait.

isRetryable() now includes CONCURRENCY_LIMIT_REACHED. An HTTP error's
Retry-After, in seconds or as an HTTP date, is kept in the error's
context as retryAfterSeconds, and retryAfterMs(error) reads it, for use
in retry delays. The codegen client re-exports the helper.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The GraphQL query client now marks concurrency-limit errors as retryable, parses numeric and HTTP-date Retry-After headers into error context, and exports retryAfterMs through query and codegen client entry points. Tests cover retry classification, delay conversion, and missing or invalid headers.

Changes: Retry-After handling

Layer / File(s) Summary
Parse retry delays and update error handling
graphql/query/src/client/execute.ts, graphql/query/src/client/error.ts
The client parses numeric and HTTP-date Retry-After values and adds parsed seconds to mapped error context. CONCURRENCY_LIMIT_REACHED is retryable. retryAfterMs converts a numeric delay in a ConstructiveError context to milliseconds.
Expose and test retry delay behavior
graphql/query/src/client/index.ts, graphql/codegen/src/client/error.ts, graphql/codegen/src/client/index.ts, graphql/query/__tests__/client-retry.test.ts
The query and codegen client entry points export retryAfterMs. Tests cover concurrency-limit errors, numeric and date-based delays, missing or unreadable headers, GraphQL validation errors, and non-client-error values.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant HTTPResponse
  participant handleHttpError
  participant errorForResponse
  participant parseRetryAfter
  participant Client
  participant retryAfterMs
  HTTPResponse->>handleHttpError: Provide status, body, and Retry-After header
  handleHttpError->>errorForResponse: Map status and response body
  errorForResponse-->>handleHttpError: Return mapped error
  handleHttpError->>parseRetryAfter: Parse Retry-After header
  parseRetryAfter-->>handleHttpError: Return seconds or undefined
  handleHttpError-->>Client: Return mapped error with parsed delay context
  Client->>retryAfterMs: Read delay from error
  retryAfterMs-->>Client: Return milliseconds or undefined
Loading

Suggested reviewers: pyramation, luxor-code-review

Merge Risk: Minimal · up to c6f21

This change makes concurrency-limit refusals retryable and keeps the server's Retry-After delay available to callers through a new helper. No merge-blocking risk was found.

Security architecture risk: Low · up to c6f21

The client still sends each request only once. Applications that use the new helper can let a server response set their retry delay, but the helper does not bound that delay and can return a value even when the Retry-After header is absent.

Retained concerns

  • Low · reliability · inferred: The new helper treats any numeric retryAfterSeconds in a ConstructiveError as a delay hint. A GraphQL error body can therefore supply the delay without a Retry-After header, including on an HTTP-success response carrying GraphQL errors. Neither the helper nor the header parser ensures a finite, bounded delay. Callers that schedule directly from the result can bypass their normal fallback backoff and retry too soon or remain stalled, depending on the scheduler.
Security review details

Security Blast Radius

  • inferred — Response-originated timing influence is limited to operations whose callers adopt the helper and schedule from its output. The inspected transport issues one request to the caller-supplied endpoint; the response does not select a new destination or trigger a replay there.

Trust Boundaries and Controls

  • observed — A response producer can supply a delay through the HTTP header or through GraphQL error extensions with a code. The helper checks the normalized error type and the field's numeric type, but neither check establishes that the value came from the header.

Hardening Proposals

  • proposed — Keep header-derived timing separate from generic error context and enforce finite, nonnegative delays within a caller-owned retry budget. Use the caller's fallback backoff when a hint is unusable.
Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the two main changes: admission-control refusals (CONCURRENCY_LIMIT_REACHED) become retryable, and the Retry-After value is kept in error context. The changeset matches this. The retry…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the two main changes: admission-control refusals (CONCURRENCY_LIMIT_REACHED) become retryable, and the Retry-After value is kept in error context. The changeset matches this. The retryable-code change in error.ts, the Retry-After parsing in execute.ts, and the retryAfterMs export all support the title. The title uses the conventional commit form and is specific to the graphql-query package.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between cb1161c and c6f2192.

Files selected for processing: 6

  • graphql/codegen/src/client/error.ts
  • graphql/codegen/src/client/index.ts
  • graphql/query/__tests__/client-retry.test.ts
  • graphql/query/src/client/error.ts
  • graphql/query/src/client/execute.ts
  • graphql/query/src/client/index.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

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.

1 participant