fix: deduplicate 401 logout and fix error interceptor - #561
Merged
Conversation
Multiple concurrent 401 responses no longer each trigger separate logout+navigate cycles. Non-401 errors now properly reject instead of resolving with error.response. Batch size reduced to 1 to serialize studio requests until backend session refresh dedup lands. Fixes studio page sign-out caused by concurrent request race condition. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Deploying frontend-alpha with
|
| Latest commit: |
0d70435
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://0c126f10.frontend-btm.pages.dev |
| Branch Preview URL: | https://fix-studio-session-signout.frontend-btm.pages.dev |
Deploying frontend-stage with
|
| Latest commit: |
0d70435
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://bfa98b12.frontend-d7v.pages.dev |
| Branch Preview URL: | https://fix-studio-session-signout.frontend-d7v.pages.dev |
3 tasks
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.
Summary
logout()+ navigate cyclereturn error.response→return Promise.reject(error))Root Cause Analysis
The Bug
When the studio page fires multiple concurrent API requests (batch submission sends up to 5 at a time via
Promise.allSettled), and the user's WorkOS access token has expired, all concurrent requests race to refresh the same session. WorkOS refresh tokens are single-use (rotated on refresh). Only 1 request wins; the others fail.Failure Trace
useBatchSubmit.ts:84) fires up to 5 concurrentPromise.allSettledrequestsrequireAuthmiddleware with the same expired session cookieauthenticateWorkOS()→authenticateAndGetWorkOSSession()returnsnull(expired)refreshWorkOSSession()— but WorkOS refresh tokens are single-usecatchblock → returnsnullnullresult →handleWorkOSAuthFailure()→ clears thewos-sessioncookie and returns 401logout()multiple times → navigates to sign-inWhy Only Studio
The studio page is the only feature that fires concurrent authenticated API requests. Normal pages make sequential requests, so the refresh happens once and subsequent requests use the new cookie.
Additional Bug: Error Swallowing
useHttpInterceptors.ts:48hadreturn error.responsewhich resolved the promise for non-401 errors (like 403 Forbidden). This meant role check failures and other server errors were silently treated as successful responses by calling code, masking related auth issues.Changes
src/hooks/useHttpInterceptors.ts: AddedisLoggingOutflag to deduplicate 401 handling; fixed non-401 error path to properly rejectsrc/components/pages/studio/hooks/useBatchSubmit.ts: BATCH_SIZE 5 → 1 (temporary safety measure until backend fix deploys)Companion PR
Test plan
🤖 Generated with Claude Code