:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(setup-detection): treat a 403 from the setup probe as no answer (#117003)
posthog[bot]0dfa228485f8
diff --git a/frontend/src/lib/components/ProductEmptyState/setupDetectionLogic.test.ts b/frontend/src/lib/components/ProductEmptyState/setupDetectionLogic.test.tsindex 50bd341d0322..e9f25fa3bf06 100644--- a/frontend/src/lib/components/ProductEmptyState/setupDetectionLogic.test.ts+++ b/frontend/src/lib/components/ProductEmptyState/setupDetectionLogic.test.ts@@ -50,10 +50,11 @@ describe('createSetupDetectionLogic', () => {expect(productSetupStatusLogic({ productKey: ProductKey.LOGS }).values.status).toBe(expected)})- // An outage answers null instead of failing, so a backend blip does not file an error+ // An outage or a 403 answers null instead of failing, so it does not file an error// tracking issue per product. Other failures still reach the failure path.it.each([['a 500', new ApiError('A server error occurred.', 500), 'detectStatusSuccess'],+ ['a 403', new ApiError('You do not have permission.', 403), 'detectStatusSuccess'],['a dropped connection', new TypeError('Failed to fetch'), 'detectStatusSuccess'],['a 400', new ApiError('Bad request', 400), 'detectStatusFailure'],['an application bug', new Error('x is not a function'), 'detectStatusFailure'],@@ -132,21 +133,28 @@ describe('createSetupDetectionLogic', () => {expect(detect).toHaveBeenCalledTimes(2)})- it('stops polling once a request 404s on a deleted or inaccessible project', async () => {+ it.each([+ [+ '404s on a deleted or inaccessible project',+ new ApiError('Project not found.', 404, undefined, { detail: 'Project not found.' }),+ ],+ ['403s on a resource the user cannot read', new ApiError('You do not have permission.', 403)],+ ] as const)('stops polling once a request %s', async (_, error) => {jest.useFakeTimers()const detect = jest.fn<Promise<ProductSetupStatus>, []>().mockResolvedValueOnce('needs-setup')- .mockRejectedValue(new ApiError('Project not found.', 404, undefined, { detail: 'Project not found.' }))+ .mockRejectedValue(error)const logic = buildLogic(detect, 1000)logic.mount()await flushMicrotasks()expect(detect).toHaveBeenCalledTimes(1)- // The first poll tick 404s, which disposes the poll...+ // The first poll tick fails, which disposes the poll...jest.advanceTimersByTime(1000)await flushMicrotasks()expect(detect).toHaveBeenCalledTimes(2)+ expect(productSetupStatusLogic({ productKey: ProductKey.LOGS }).values.status).toBe('needs-setup')// ...so no later tick fires another doomed request.jest.advanceTimersByTime(5000)diff --git a/frontend/src/lib/components/ProductEmptyState/setupDetectionLogic.ts b/frontend/src/lib/components/ProductEmptyState/setupDetectionLogic.tsindex 6f997b50aa18..19981ad4d681 100644--- a/frontend/src/lib/components/ProductEmptyState/setupDetectionLogic.ts+++ b/frontend/src/lib/components/ProductEmptyState/setupDetectionLogic.ts@@ -178,16 +178,18 @@ export function createSetupDetectionLogic(options: SetupDetectionLogicOptions):],})),actions({ revalidateCachedStatus: true }),- loaders({+ loaders(({ cache }) => ({detectedStatus: {__default: null as ProductSetupStatus | null,detectStatus: async (_: void, breakpoint: BreakPointFunction): Promise<ProductSetupStatus | null> => {- const status = await detectOrNullOnOutage(detect)+ const status = await detectOrNullOnOutageOrForbidden(detect, () =>+ cache.disposables.dispose('poll')+ )breakpoint()return status},},- }),+ })),listeners(({ actions, values, cache }) => ({...Object.fromEntries((recheckActionTypes?.() ?? []).map((actionType) => [@@ -270,14 +272,20 @@ async function detectOrNull(detect: () => Promise<ProductSetupStatus | null>): P}}-// A 5xx or a dropped connection says nothing about setup, and the gate treats null as "cannot-// answer". Throwing would file one error tracking issue per product for each backend blip.-async function detectOrNullOnOutage(- detect: () => Promise<ProductSetupStatus | null>+// A 5xx, a dropped connection or a 403 says nothing about setup, and the gate treats null as+// "cannot answer". Throwing would file one error tracking issue per product for each failure.+// A 403 does not clear on retry, so it also stops the poll.+async function detectOrNullOnOutageOrForbidden(+ detect: () => Promise<ProductSetupStatus | null>,+ onForbidden: () => void): Promise<ProductSetupStatus | null> {try {return await detect()} catch (error) {+ if (error instanceof ApiError && error.status === 403) {+ onForbidden()+ return null+ }if ((error instanceof ApiError && error.status !== undefined && error.status >= 500) ||isBrowserNetworkFailure(error)