Skip to content

fix(auth): stop profile screens loading empty after a 401 (#579) - #595

Merged
thinkclay merged 1 commit into
mainfrom
claude/fix-579-auth-401-retry
Aug 12, 2026
Merged

thinkclay merged 1 commit into
mainfrom
claude/fix-579-auth-401-retry

Conversation

@thinkclay

Copy link
Copy Markdown
Contributor

Closes #579. First of the profile-building audit rollup (#594) — the epic sequences this one alone, because it is the root of the empty-form reports and it changes how every other client-side symptom presents.

The bug

Every profile editor rendered blank for a signed-in user whose access token needed a refresh. One load of /profile/resume:

GET /v1/profiles/general             -> 401
GET /v1/profiles/employment          -> 401
GET /v1/profiles/slug/history        -> 401
GET /v1/profiles/import/data         -> 401
GET /v1/resume/has-uploaded          -> 401
GET /v1/profiles/widgets/general-info-> 401

Only three unrelated queries were retried; the rest stayed failed for the life of the page. The same endpoint with the same session, fetched by hand from the page console, returned the user's full record.

Three gaps, all fixed here

  1. retry: 2 retried 401s against the same stale client. All three attempts burned inside ~3s, so nothing was left by the time Supabase refreshed. Replaced with a status-aware policy (provider/react-query/retry.ts): deterministic 4xx give up immediately, network and 5xx keep the exponential backoff, 429 stays retryable.

  2. Recovery invalidation fired only on the isLoading true→false transition. A token that expired while the tab was open produced no transition, so nothing refetched. Now keyed on the access token itself, which covers the initial load and every later refresh.

  3. That invalidation filtered by a hand-maintained list of ten query-key prefixes, against 30+ roots scf-core actually registers — resume, idVerification, user-profiles, ['scaffald','skills',…] and a dozen more were never covered. The allow-list is gone. One that must be updated whenever a hook is added will drift again; not having one cannot.

Also adds a single-flight, cooldown-guarded refresh on 401. That same load issued nine POST /auth/v1/token because every failing query kicked its own refresh; the lock collapses a burst into one, and the 10s cooldown stops a dead refresh token becoming a request loop.

Tests

33 assertions, all new or updated:

  • retry.test.ts — per-status policy, including the "never retries a 401" regression.
  • requestSessionRefresh.test.ts — 20 concurrent 401s produce one refresh; cooldown holds; a rejected refresh is swallowed rather than surfacing as a second error.
  • jobs-sdk-context.test.tsx — adds the five key roots the old allow-list missed, plus mid-session token refresh and a no-op re-render case.

One existing assertion inverted deliberately: ['unrelated','thing'] used to assert not invalidated, to prove the allow-list was selective. Everything in the cache was fetched with the credential that just changed, so everything is now invalidated; react-query only refetches what is mounted.

Note for reviewers

This branch was built against submodule pointers synced to main (packages/sdk → 2ae9506, packages/ui → fdaa0d4). The worktree had them stale-behind, which produced 35 phantom tsc errors and a failing scf-core:build in pre-push; after syncing, scf-core typechecks clean at 0 errors. No submodule pointer change is included in this PR.

🤖 Generated with Claude Code

Every profile editor rendered blank for a signed-in user whose access token
needed a refresh. A single load of /profile/resume 401'd on /profiles/general,
/profiles/employment, /profiles/slug/history, /profiles/import/data,
/resume/has-uploaded and /profiles/widgets/general-info, and only some of them
were ever retried — the rest stayed failed for the life of the page while the
same endpoints returned full data to a hand-rolled fetch with the same session.

Three independent gaps, all fixed here:

1. `retry: 2` retried 401s against the same stale client, burning all three
   attempts inside ~3s so nothing was left once the refresh landed. Queries now
   use a status-aware policy that gives up immediately on deterministic 4xx and
   keeps the exponential backoff for network and 5xx failures.

2. The recovery invalidation fired only on the isLoading true->false transition,
   so a token that expired while the tab was open never triggered it. It now
   fires on every access_token change.

3. That invalidation filtered by a hand-maintained list of ten query-key
   prefixes, but scf-core registers 30+ roots — `resume`, `idVerification`,
   `user-profiles`, `['scaffald','skills',...]` and a dozen more were never
   covered. The allow-list is gone; an allow-list that must be updated whenever
   a hook is added will drift again, not having one cannot.

Adds a single-flight, cooldown-guarded session refresh on 401. The same load
that produced these 401s also issued nine POST /auth/v1/token because every
failing query kicked its own refresh; the lock collapses a burst into one.

Co-Authored-By: Claude Opus 5 <[email protected]>
@thinkclay
thinkclay merged commit e000d53 into main Aug 12, 2026
9 of 13 checks passed
@thinkclay
thinkclay deleted the claude/fix-579-auth-401-retry branch August 12, 2026 02:56
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.

fix(profile): every profile editor loads empty — first-load reads 401 and are never retried

1 participant