From 81cdd2eb9f5414ca455af21d10d6272c44f40ec7 Mon Sep 17 00:00:00 2001 From: Dante Date: Mon, 12 Oct 2026 17:43:48 +0000 Subject: [PATCH] FE-3381 fix(auth): ask for a new login when the session sign-in was revoked (#20834) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Why Prod RUM, right after the 2026-10-12 web-session rollout: a Desktop (Electron) user got "Couldn't load your workspace / Check your connection and try again." and pressed Try again for about 12 minutes before logging out (Datadog issue `8fe722d4`, first seen 12:57Z). Retrying can never succeed, so the screen sends the user into a loop. ## Root cause Ingest refused `POST /api/auth/session` with `401 SESSION_REVOKED` ("This session was signed out; sign in again"). It returns this when the remembered Firebase sign-in predates a revocation of the user's sessions (`websession.ErrSignInPredatesRevocation`, cloud `services/ingest/server/implementation/auth.go`). `useSessionCookie.readSessionError` turned every non-SSO refusal into a plain `Error`, so `WorkspaceAuthGate` classified it as retryable. Each retry replays the same stale sign-in and gets the same 401. ## How - `readSessionError` maps `401` + `code: SESSION_REVOKED` to a typed `SessionRevokedError`. The code comes from the server as received; nothing is derived on the client. - `WorkspaceAuthGate` treats `SessionRevokedError` as non-retryable. The existing non-retryable panel then shows "Sign out and log in again to continue." with only Log Out. - Tests: a table on `ensureSessionCookie` (401 SESSION_REVOKED → typed, 401 UNAUTHORIZED and 403 SESSION_REVOKED → plain), and two rows in the gate's error table (SSO on/off). Red/green: locally the test commit (b5674147e7) fails exactly the 3 new cases and the fix (ceefcd5da9) passes all 64. On CI the test-only commit's unit job was skipped because fallow flagged an unused class member, so the red is local only. ## AS IS / TO BE | AS IS (`origin/main`) | TO BE (this PR) | |---|---| | AS IS: Couldn't load your workspace, Check your
connection and try again, Try again + Log Out | TO BE: Couldn't load your workspace, Sign out
and log in again to continue, Log Out only | | "Check your connection and try again." + Try again | "Sign out and log in again to continue." + Log Out only | Captured in the real cloud app (local dev server, signed-in session against cloud.comfy.org). Only `POST /api/auth/session` was stubbed (in-page `fetch` override) to return `401 {"code":"SESSION_REVOKED","message":"This session was signed out; sign in again"}`; every other request hit the real backend. Same session and stub for both shots; only the two changed source files differ. ## Plan position | Step | Item | State | |---|---|---| | 1 | Prod flags: session 20%, billing_web 20% | Done 2026-10-12 | | 2 | RUM rollout watch | Running | | 3 | FE-3380: report `unified_web_session` to RUM (#20831) | In review | | **4** | **This PR: revoked sign-in asks for a new login** | **This PR** | | 5 | 1.56 backport of 3 and 4, then ramp decision | After merge | ```mermaid flowchart LR A[Prod flags 20%] --> B[RUM watch] B --> C[FE-3380 RUM cohort tag] B --> D[This PR: SESSION_REVOKED → log in again]:::me C --> E[1.56 backport] D --> E E --> F[Ramp decision] classDef me fill:#f9d71c,stroke:#333,color:#000 ``` - Fixes FE-3381 --- .../auth/session/useSessionCookie.test.ts | 43 +++++++++++++++++++ src/platform/auth/session/useSessionCookie.ts | 15 +++++-- .../workspace/auth/WorkspaceAuthGate.test.ts | 19 ++++++++ .../workspace/auth/WorkspaceAuthGate.vue | 2 + 4 files changed, 75 insertions(+), 4 deletions(-) diff --git a/src/platform/auth/session/useSessionCookie.test.ts b/src/platform/auth/session/useSessionCookie.test.ts index 0d70fc61e18..43e9ea2a512 100644 --- a/src/platform/auth/session/useSessionCookie.test.ts +++ b/src/platform/auth/session/useSessionCookie.test.ts @@ -366,6 +366,49 @@ describe('useSessionCookie', () => { } ) + it.for([ + { + name: 'a 401 SESSION_REVOKED', + status: 401, + code: 'SESSION_REVOKED', + revoked: true + }, + { + name: 'a 401 UNAUTHORIZED', + status: 401, + code: 'UNAUTHORIZED', + revoked: false + }, + { + name: 'a 403 SESSION_REVOKED', + status: 403, + code: 'SESSION_REVOKED', + revoked: false + } + ])( + 'ensureSessionCookie rejects with SessionRevokedError: $revoked for $name', + async ({ status, code, revoked }) => { + vi.mocked(useAuthStore().getIdToken).mockResolvedValue( + 'firebase-id-token' + ) + vi.mocked(globalThis.fetch).mockImplementation(async () => + Response.json( + { code, message: 'This session was signed out; sign in again' }, + { status } + ) + ) + const { useSessionCookie, SessionRevokedError } = + await loadUseSessionCookie() + + const failure = await useSessionCookie() + .ensureSessionCookie() + .catch((error: unknown) => error) + + expect(failure).toBeInstanceOf(Error) + expect(failure instanceof SessionRevokedError).toBe(revoked) + } + ) + it('sessionRequiresSso is false once the session is created', async () => { vi.mocked(useAuthStore().getIdToken).mockResolvedValue('firebase-id-token') vi.mocked(globalThis.fetch).mockResolvedValue( diff --git a/src/platform/auth/session/useSessionCookie.ts b/src/platform/auth/session/useSessionCookie.ts index 4b1289347a3..8893151bd4c 100644 --- a/src/platform/auth/session/useSessionCookie.ts +++ b/src/platform/auth/session/useSessionCookie.ts @@ -1,4 +1,5 @@ import { isSsoRequiredRefusal } from '@comfyorg/account-core/sso' +import { zErrorResponse } from '@comfyorg/ingest-types/zod' import { useCurrentUser } from '@/composables/auth/useCurrentUser' import { useFeatureFlags } from '@/composables/useFeatureFlags' @@ -17,6 +18,9 @@ class SsoRequiredSessionError extends Error { readonly code = 'SSO_REQUIRED' } +/** Ingest refused the session because the sign-in predates a sign-out. */ +export class SessionRevokedError extends Error {} + let inFlightCreateSession: InFlightCreateSession | null = null let confirmedSessionOwnerUid: string | null = null let sessionMutationTail = Promise.resolve() @@ -42,10 +46,13 @@ export const useSessionCookie = () => { const readSessionError = async (response: Response): Promise => { const errorData: unknown = await response.json().catch(() => null) - const message = (errorData as { message?: unknown } | null)?.message - const text = typeof message === 'string' ? message : response.statusText - return isSsoRequiredRefusal(response.status, errorData) - ? new SsoRequiredSessionError(text) + const refusal = zErrorResponse.partial().safeParse(errorData).data + const text = refusal?.message ?? response.statusText + if (isSsoRequiredRefusal(response.status, errorData)) { + return new SsoRequiredSessionError(text) + } + return response.status === 401 && refusal?.code === 'SESSION_REVOKED' + ? new SessionRevokedError(text) : new Error(text) } diff --git a/src/platform/workspace/auth/WorkspaceAuthGate.test.ts b/src/platform/workspace/auth/WorkspaceAuthGate.test.ts index fe11e5bc261..fecf64ea00e 100644 --- a/src/platform/workspace/auth/WorkspaceAuthGate.test.ts +++ b/src/platform/workspace/auth/WorkspaceAuthGate.test.ts @@ -7,6 +7,7 @@ import type { } from '@/platform/auth/session/webSessionFetch' import { provideWebSessionRequests } from '@/platform/auth/session/webSessionFetch' import { useCloudWebSessionStore } from '@/platform/auth/session/cloudWebSessionStore' +import { SessionRevokedError } from '@/platform/auth/session/useSessionCookie' import { useApiKeyAuthStore } from '@/stores/apiKeyAuthStore' import { useAuthStore } from '@/stores/authStore' import { NoWorkspaceAccessError } from '@/platform/workspace/api/workspaceApiError' @@ -666,6 +667,24 @@ describe('WorkspaceAuthGate', () => { error: new Error('Workspace init failed'), heading: "Couldn't load your workspace", retry: true + }, + { + name: 'sso off, session revoked', + sso: false, + error: new SessionRevokedError( + 'This session was signed out; sign in again' + ), + heading: "Couldn't load your workspace", + retry: false + }, + { + name: 'sso on, session revoked', + sso: true, + error: new SessionRevokedError( + 'This session was signed out; sign in again' + ), + heading: "Couldn't load your workspace", + retry: false } ])( '$name: shows "$heading" with sign-out', diff --git a/src/platform/workspace/auth/WorkspaceAuthGate.vue b/src/platform/workspace/auth/WorkspaceAuthGate.vue index 6af36533f7c..d2ed98b8e66 100644 --- a/src/platform/workspace/auth/WorkspaceAuthGate.vue +++ b/src/platform/workspace/auth/WorkspaceAuthGate.vue @@ -96,6 +96,7 @@ import { import Button from '@/components/ui/button/Button.vue' import { useAuthActions } from '@/composables/auth/useAuthActions' import { useFeatureFlags } from '@/composables/useFeatureFlags' +import { SessionRevokedError } from '@/platform/auth/session/useSessionCookie' import { signedInOnWebSession } from '@/platform/auth/session/webSessionFetch' import { isCloud } from '@/platform/distribution/types' import { @@ -245,6 +246,7 @@ function isRetryableInitializationError(error: unknown): boolean { ) { return false } + if (error instanceof SessionRevokedError) return false return !( error instanceof Error && error.message === 'No workspaces available' )