diff --git a/packages/frontend/src/lib/pending-authorization.ts b/packages/frontend/src/lib/pending-authorization.ts index 36bba8f36..c85648107 100644 --- a/packages/frontend/src/lib/pending-authorization.ts +++ b/packages/frontend/src/lib/pending-authorization.ts @@ -62,7 +62,12 @@ export function pendingAuthorizationPath(step: PendingAuthorizationStep): '/auth /** Asks the backend; null when nothing is waiting or the question failed. */ export async function fetchPendingAuthorization(timeoutMs = 5000): Promise { const controller = typeof AbortController === 'undefined' ? null : new AbortController(); - const timer = controller ? setTimeout(() => controller.abort(), timeoutMs) : null; + // Abort with a named reason: a bare abort() rejects with "signal is aborted + // without reason", which Sentry's fetch instrumentation reported as an + // unhandled error (CLOUD-FRONTEND-Y / -10) although this function catches it. + const timer = controller + ? setTimeout(() => controller.abort(new DOMException('GET /auth/pending timed out', 'TimeoutError')), timeoutMs) + : null; try { const response = await fetch('/auth/pending', { headers: { Accept: 'application/json' }, diff --git a/packages/frontend/tests/e2e/pending-authorization.spec.ts b/packages/frontend/tests/e2e/pending-authorization.spec.ts index 434377f95..1d8a13b59 100644 --- a/packages/frontend/tests/e2e/pending-authorization.spec.ts +++ b/packages/frontend/tests/e2e/pending-authorization.spec.ts @@ -2,6 +2,7 @@ import { expect, test, type Page } from '@playwright/test'; import { CLIENT_NAME_MAX, displayClientName, + fetchPendingAuthorization, parsePendingAuthorization, pendingAuthorizationPath, signUpClientName, @@ -156,6 +157,25 @@ test.describe('pending-authorization helpers', () => { expect(Array.from(displayClientName('😀'.repeat(60))!)).toHaveLength(CLIENT_NAME_MAX); }); + test('a question that takes too long is aborted with a named reason and gives null', async () => { + const realFetch = globalThis.fetch; + let reason: unknown; + globalThis.fetch = ((_input: unknown, init?: { signal?: AbortSignal }) => + new Promise((_resolve, reject) => { + init?.signal?.addEventListener('abort', () => { + reason = init.signal!.reason; + reject(init.signal!.reason); + }); + })) as typeof fetch; + try { + expect(await fetchPendingAuthorization(10)).toBeNull(); + } finally { + globalThis.fetch = realFetch; + } + expect(reason).toBeInstanceOf(DOMException); + expect((reason as DOMException).name).toBe('TimeoutError'); + }); + test('the sign-up names only the assistants it knows', () => { expect(signUpClientName('claude')).toBe('Claude'); expect(signUpClientName('ChatGPT')).toBe('ChatGPT');