: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(signals): stop filing deploy-skew 404s and 405s from the run cost read (#95055)
posthog[bot]7190de936afe
diff --git a/frontend/src/lib/api-error.test.ts b/frontend/src/lib/api-error.test.tsindex f5596b10c5aa..fc500316e5d2 100644--- a/frontend/src/lib/api-error.test.ts+++ b/frontend/src/lib/api-error.test.ts@@ -99,7 +99,10 @@ describe('api-error', () => {['a 409 that is not an approvals gate', { status: 409, data: {} }, true],['a 500 backend exception', { status: 500 }, true],['a 400 validation error', { status: 400 }, true],+ // A route the backend does not serve stays reportable here. Only a caller that already+ // degrades excuses one, through `isUnavailableEndpointError`.['a 404', { status: 404 }, true],+ ['a 405', { status: 405 }, true],// A request the browser never sent. Nothing of ours failed, and grouping is stack-based,// so reporting these opens one issue per loader that met the same connectivity blip.['a Chromium fetch failure', new TypeError('Failed to fetch'), false],diff --git a/frontend/src/lib/api-error.ts b/frontend/src/lib/api-error.tsindex 221ec3189255..ea3d0efe7684 100644--- a/frontend/src/lib/api-error.ts+++ b/frontend/src/lib/api-error.ts@@ -33,6 +33,25 @@ export function isTransientServerError(error: unknown): boolean {return error instanceof ApiError && isTransientGatewayStatus(error.status)}+/**+ * A route the backend does not serve: the path is unknown (404), or it is known but does not accept+ * the method (405). Both are what a deploy in progress looks like from the browser, since the+ * frontend bundle can reach a backend that does not have the endpoint yet. A new `detail=False`+ * DRF action reads as 405 rather than 404, because the router still matches the detail route and+ * only then refuses the method.+ *+ * This is deliberately not part of `shouldReportApiFailure`: a 404 on a resource the app expects to+ * exist is a real defect, so only a caller that already degrades to a partial view should excuse+ * one. Use it there, next to the code that renders the degraded state.+ */+export function isUnavailableEndpointError(error: unknown): boolean {+ if (error === null || typeof error !== 'object') {+ return false+ }+ const status = (error as { status?: number }).status+ return status === 404 || status === 405+}+/** The 403 gates `apiStatusLogic` recovers from, keyed by the DRF `code` the backend sends. */const HANDLED_AUTH_GATE_CODES: ReadonlySet<string> = new Set(['two_factor_setup_required',diff --git a/products/signals/frontend/inbox/logics/scoutFleetLogic.test.ts b/products/signals/frontend/inbox/logics/scoutFleetLogic.test.tsindex 29fe10205d46..ff22d953f814 100644--- a/products/signals/frontend/inbox/logics/scoutFleetLogic.test.ts+++ b/products/signals/frontend/inbox/logics/scoutFleetLogic.test.ts@@ -942,6 +942,10 @@ describe('scoutFleetLogic', () => {it.each([['a backend fault, which reaches error tracking', 500, true],['a gateway blip, which does not', 503, false],+ // Deploy skew: a bundle that has the cost feature can reach a backend that does not+ // have the endpoint yet, and DRF answers 405 when only the method is missing.+ ['a method the backend does not serve yet, which does not', 405, false],+ ['a path the backend does not serve yet, which does not', 404, false],])('recovers from %s', async (_name: string, status: number, reported: boolean) => {mockSignalsScoutRunsRecentPerScout.mockResolvedValue([makeRun({ run_id: 'run-priced' })])mockSignalsScoutRunsTokenCosts.mockRejectedValue(new ApiError('nope', status))diff --git a/products/signals/frontend/inbox/logics/scoutFleetLogic.ts b/products/signals/frontend/inbox/logics/scoutFleetLogic.tsindex f0ddf8475fa2..8b2e64568f45 100644--- a/products/signals/frontend/inbox/logics/scoutFleetLogic.ts+++ b/products/signals/frontend/inbox/logics/scoutFleetLogic.ts@@ -16,7 +16,7 @@ import posthog from 'posthog-js'import { lemonToast } from '@posthog/lemon-ui'-import { ApiError, shouldReportApiFailure } from 'lib/api-error'+import { ApiError, isUnavailableEndpointError, shouldReportApiFailure } from 'lib/api-error'import { dayjs } from 'lib/dayjs'import { reconcileById } from 'lib/utils/objects'import { aiConsentLogic } from 'scenes/settings/organization/aiConsentLogic'@@ -789,7 +789,10 @@ export const scoutFleetLogic = kea<scoutFleetLogicType>([// Recovering here skips the gate `initKea` applies to loader failures, so// reapply it: a refused or unreachable read is expected, but a backend// fault must still reach error tracking instead of reading as success.- if (shouldReportApiFailure(error)) {+ // A route the backend does not serve is expected too, because the+ // roster ships ahead of its endpoints and shows no number until both+ // sides are deployed.+ if (shouldReportApiFailure(error) && !isUnavailableEndpointError(error)) {posthog.captureException(error)}// A full fleet spans several batches, so keep the ones that answered and