Skip to content

fix(net): a 404 mutation is retried, though 404 is in NON_RETRYABLE_STATUSES #647

Closed

Description

@thinkclay

A failed mutation is sent twice, ~1s apart, even when the failure is a 404 — a status the app's own retry policy lists as non-retryable.

Evidence

scripts/audit/smoke-move-undo.mjs, one stage move, real session:

+18901ms PATCH applications/d95a852c-... {"status":"reviewing"}
      ↳ 404 {"error":"Not Found","message":"Application not found"}
+19996ms PATCH applications/d95a852c-... {"status":"reviewing"}
      ↳ 404 {"error":"Not Found","message":"Application not found"}

One user action. Two identical writes, 1,095ms apart — react-query's first retry backoff.

What should have stopped it

packages/scf-core/provider/react-query/QueryProvider.tsx:38

mutations: {
  retry: (failureCount, error) => shouldRetry(failureCount, error, 1),
},

packages/scf-core/provider/react-query/retry.ts:17,37

const NON_RETRYABLE_STATUSES = new Set([400, 401, 403, 404, 409, 422])

export function shouldRetry(failureCount, error, maxRetries) {
  const statusCode = statusCodeOf(error)
  if (statusCode !== undefined && NON_RETRYABLE_STATUSES.has(statusCode)) return false
  return failureCount < maxRetries
}

404 is in the set, so this should return false on the first failure and no retry should happen. It retried anyway.

The likely cause

statusCodeOf reads error.statusCode. The SDK's NotFoundError does set it (packages/sdk/src/http/errors.ts:37 → super(message, 404, 'not_found')), so the property exists in source. Two candidates for why the policy does not see it:

  1. @scaffald/sdk resolves to a stale dist. The SDK is a submodule built to a gitignored dist; if the built copy predates the statusCode plumbing, the thrown error is a plain Error and statusCodeOf returns undefined — which falls through to failureCount < maxRetries and retries.
  2. The error is wrapped before react-query sees it. Anything that re-throws as a bare Error loses statusCode the same way.

Worth confirming which before fixing — the difference decides whether the fix is a rebuild, a build-freshness guard, or a change to how errors propagate.

Why it matters

A retried non-idempotent write is a correctness risk, not just noise. It is harmless here only because the endpoint 404s (#646) so neither attempt does anything. Against a working endpoint this is a double write on every transient failure the policy was specifically written to stop retrying — and #579 shows the cost of getting this predicate wrong in the other direction (a 401 burning the whole retry budget in 3s).

Acceptance

  • Determine whether the runtime error carries statusCode; if not, why not.
  • A 404 (and every status in NON_RETRYABLE_STATUSES) produces exactly one request from one mutation.
  • A test asserts the predicate against a real SDK-thrown error, not a hand-built { statusCode } object — a unit test on shouldRetry alone would pass today while the app misbehaves.

Related

Activity

  1. added
    bug
    agent-ready
    on Aug 25, 2026
  2. thinkclay commented on Aug 25, 2026

    @thinkclay
    ContributorAuthor

    The reproduction is gone, but the question is not. Reopening context rather than closing.

    #646 is fixed (#649, 63c85be63). The endpoint now returns 200, and with it the duplicate write disappears:

    before: writes=2  ↳ 404 ... ↳ 404      (1,095ms apart)
    after:  writes=1  ↳ 200
    

    That confirms the second request was the client retrying the failure — this was a symptom of #646, not an independent double-send. Which lowers the urgency but does not answer the actual question filed here:

    404 is in NON_RETRYABLE_STATUSES, and shouldRetry should have returned false on the first failure. It retried anyway.

    That predicate is still wrong, or the error reaching it still lacks statusCode. It just no longer has a convenient way to reproduce through the ATS board, since that path succeeds now.

    Suggested next step for whoever picks this up: force a 404 from any SDK-backed mutation (a deleted id works) and count the requests. If it sends two, the predicate is not seeing statusCode and the two candidates in the body above still apply — stale @scaffald/sdk dist, or an error re-thrown as a bare Error.

    The acceptance criterion stands, including the note that a unit test on shouldRetry alone would pass today while the app misbehaves.

  3. thinkclay commented on Aug 27, 2026

    @thinkclay
    ContributorAuthor

    Recording why this closed, since the title still asserts something untrue.

    The premise does not hold. I filed this after seeing two identical PATCHes 1,095ms apart; retry was the obvious explanation. It is not the explanation:

    check result
    SDK's built dist carries statusCode yes — dist/index.js:54
    a real 404 through the SDK NotFoundError, statusCode: 404
    statusCodeOf(err) 404
    shouldRetry(0, err, 1) false
    react-query's mutation machinery, with the app's exact retry default, against a real SDK 404 1 PATCH, not 2

    That last check exists because the first four only test pieces in isolation. It rules out both candidate causes in the original body — stale dist, and the error being re-wrapped as a bare Error.

    The duplicate was real and timestamped, but it was not a retry, and it no longer reproduces now that #649 stopped the endpoint 404ing. I could not identify what sent it. That is unsatisfying, but "the retry policy is broken" is not supported, and leaving it open would send someone to fix a predicate that works.

    If it recurs it will not go unnoticed: smoke-move-undo.mjs now pins exactly one write, 2xx per move.

    Kept — acceptance criterion 3, which was right. The existing tests used a hand-built { statusCode } object, which cannot notice a real SDK error losing its status. The assertions now also run against NotFoundError, AuthenticationError, RateLimitError and APIError as the SDK constructs them (#650).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Frontendagent-readybug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions