Repository navigation
fix(client): bound + guard the collab-token retry policy (wiki-v2#385) - #40
Merged
Merged
Conversation
…v2#385) useCollabToken was the only query overriding the app-wide `retry: false`, and its override did the opposite of a correct client: - read `error.response.status` unguarded -> threw a TypeError inside the retry callback on a network error (no `response`), the very cold-start race it existed to survive; - retried every non-404, including deliberate edge refusals (WAF 403 / 429) -- the only client-side retry amplifier in the app; - returned a truthy `10` from a retry *function*, which coerces to `true` -> retried UNBOUNDEDLY (not 10x) with an uncapped, unjittered backoff. Replace it with a bounded, standards-aligned policy, extracted into two exported pure functions so the branch logic is unit-tested directly: - retry only transient failures -- a network error (no response) or 5xx -- and a 429, capped at COLLAB_TOKEN_MAX_RETRIES (4); - deliberate 4xx refusals (403/404/...) are terminal; - honor Retry-After exactly on 429/503 (a minimum; jitter is added on top, never a down-clamp, so we never retry early), else React Query's default capped backoff. Adds a Vitest regression suite (runs in the docmost-client CI job). Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ccvu/wiki-v2#385) Review round 1 (Testing, non-blocking Level 3): the `retryAfterSec > 0` sub-condition in collabTokenRetryDelay was deletable without any test failing — no fixture exercised a finite non-positive Retry-After, so a refactor could silently drop it and let a "0"/negative header produce a zero/negative (immediate) delay. Add cases that a non-positive or HTTP-date Retry-After falls back to the capped backoff (mutation-verified: removing `> 0` reds the new test). Also resolve the wiring-test mock to a valid token so React Query doesn't error on undefined + background-retry. Production code unchanged (test-only). Co-Authored-By: Claude Opus 4.8 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fork half of cccvu/wiki-v2#385. Fork-first: merge this, then the super-repo PR re-pins the gitlink to this merge SHA.
Problem
useCollabTokenis the only query that overrides the app-wideretry: false, and its override does the opposite of a correct client:error.response.statusis read unguarded; a network error is anAxiosErrorwith noresponse, so.statusthrows aTypeErrorinside the retry callback — the exact cold-start/rolling-deploy race the override was written to survive. (The//@ts-ignorewas hiding this possibly-undefined read.)retryis a function,return 10is coerced to booleantrue(query-coreretryer.js), so it retries forever (until success/unmount) with an uncapped, unjittered backoff.Fix
Replace it with a bounded, standards-aligned (RFC 9110) policy, extracted into two exported pure functions so the branch logic is unit-tested directly:
shouldRetryCollabToken— retry only transient failures: a network error (noresponse) or a 5xx, plus a 429; every other 4xx (403/404/…) is terminal. Bounded byCOLLAB_TOKEN_MAX_RETRIES(4 — one above React Query's default of 3, for the cold-start race).collabTokenRetryDelay— honorRetry-Afterexactly on a 429/503 (it's a minimum: jitter is added on top, never a down-clamp, so we never retry early), else React Query's own default capped-exponential backoff. Jitter only where a rate-limited fleet would otherwise rebound in one synchronized wave.useQueryis pinned to<ICollabToken, Error>so theerror: unknownpredicates don't widenTError; the//@ts-ignoreis gone.Recovery backstops for anything longer than the cap are unchanged:
refetchOnMountand the editor'sonAuthenticationFailedrefetch.Tests
New Vitest suite
auth-query.test.tsx(runs in thedocmost-clientCI job): network-error retries without throwing (the core regression), 403/404 terminal, 429 retries + honorsRetry-Afteras a minimum (a large value is not down-clamped), 5xx retries up to the cap then stops (the unbounded-retry lock), fallback backoff capped, and a hook-level wiring check.Math.randomis pinned for determinism.Local: full client suite green (308 tests),
tsc --noEmitclean,check-upstream-boundary.shgreen (documented as UPSTREAM_MODIFICATIONS.md §42(b) + §154 in the super-repo PR).🤖 Generated with Claude Code