: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(aio): stop reporting expected expired-content summary 404s (#127712)
posthog[bot]795322d45f1c
diff --git a/frontend/src/initKea.ts b/frontend/src/initKea.tsindex 97c0e599b9f2..460843f62eb1 100644--- a/frontend/src/initKea.ts+++ b/frontend/src/initKea.ts@@ -216,6 +216,16 @@ Owned by inviteLogic's inviteTeamMembersFailure listener.*/const EXISTING_MEMBER_SELF_HANDLED = new Set(['inviteTeamMembers'])+/*+Loads whose owning logic renders a 404 with code `content_expired` inline. AI events drop their+message content after the retention window, so the 404 is an expected state, not a defect. Other 404s+from these loads still report. Owned by summaryViewLogic's summaryError reducer. The backend raises+the code in products/ai_observability/backend/api/summarization.py.+*/+const CONTENT_EXPIRED_SELF_HANDLED_BY_LOGIC_PATH: Record<string, string> = {+ generateSummary: 'products.ai_observability.frontend.summary-view.summaryViewLogic',+}+interface InitKeaProps {state?: Record<string, any>routerHistory?: any@@ -375,10 +385,15 @@ export function initKea({NOT_FOUND_SELF_HANDLED.has(String(actionKey)) && isUnavailableEndpointError(error)const isSelfHandledExistingMember =error?.code === 'existing_member' && EXISTING_MEMBER_SELF_HANDLED.has(String(actionKey))+ const isSelfHandledContentExpired =+ error?.status === 404 &&+ error?.code === 'content_expired' &&+ isOwnedByLogic(CONTENT_EXPIRED_SELF_HANDLED_BY_LOGIC_PATH, actionKey, logic.pathString)if (shouldReportApiFailure(error) &&!isSelfHandledNotFound &&!isSelfHandledExistingMember &&+ !isSelfHandledContentExpired &&!isSelfHandledValidationError) {posthog.captureException(error)diff --git a/products/ai_observability/backend/api/summarization.py b/products/ai_observability/backend/api/summarization.pyindex d3e0bc357dff..7dbbd031b025 100644--- a/products/ai_observability/backend/api/summarization.py+++ b/products/ai_observability/backend/api/summarization.py@@ -80,6 +80,10 @@ logger = structlog.get_logger(__name__)# Event types the formatters can render on their own, so a single one of them can be summarized by UUID.SUMMARIZABLE_EVENT_TYPES = ["$ai_generation", "$ai_span", "$ai_embedding", "$ai_evaluation"]+# The frontend matches this code to keep the expected 404 out of error tracking+# (CONTENT_EXPIRED_SELF_HANDLED_BY_LOGIC_PATH in frontend/src/initKea.ts). Keep both in sync.+CONTENT_EXPIRED_ERROR_CODE = "content_expired"+def _compact_cache_key(cache_key: str) -> str:return f"{cache_key}:compact"@@ -458,7 +462,8 @@ class AIObservabilitySummarizationViewSet(TeamAndOrgViewSetMixin, viewsets.Gener)except AIEventsExpiredError:raise exceptions.NotFound(- "The message content for this event is no longer available, so it can't be summarized."+ "The message content for this event is no longer available, so it can't be summarized.",+ code=CONTENT_EXPIRED_ERROR_CODE,) from Noneexcept AIEventsUnavailableError:return {}diff --git a/products/ai_observability/backend/api/test/test_summarization.py b/products/ai_observability/backend/api/test/test_summarization.pyindex f75e5c905341..bdad4d0f2f83 100644--- a/products/ai_observability/backend/api/test/test_summarization.py+++ b/products/ai_observability/backend/api/test/test_summarization.py@@ -805,6 +805,7 @@ class TestSummarizationByID(ClickhouseTestMixin, APIBaseTest):if settings.CLICKHOUSE_HOGQL_USE_NEW_EVENTS_SCHEMA:self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND, response.data)self.assertIn("message content for this event is no longer available", response.data["detail"])+ self.assertEqual(response.data["code"], "content_expired")mock_summarize.assert_not_called()else:self.assertEqual(response.status_code, status.HTTP_200_OK, response.data)diff --git a/products/ai_observability/frontend/summary-view/summaryViewLogic.test.ts b/products/ai_observability/frontend/summary-view/summaryViewLogic.test.tsindex 678c9121a303..94bc0adbdc7a 100644--- a/products/ai_observability/frontend/summary-view/summaryViewLogic.test.ts+++ b/products/ai_observability/frontend/summary-view/summaryViewLogic.test.ts@@ -178,6 +178,20 @@ describe('summaryViewLogic', () => {expect(reported.message).toBe(NETWORK_ERROR_MESSAGES.offline)})+ test.each([+ ['an expired-content 404', 'content_expired', false],+ ['a missing-trace 404', 'not_found', true],+ ])('%s with code %s reaches error tracking: %s', async (_label, code, reported) => {+ const captureSpy = jest.spyOn(posthog, 'captureException').mockImplementation(() => undefined as any)+ const detail = 'The message content for this event is no longer available.'+ mockSummarization(Promise.reject(new ApiError(detail, 404, undefined, { detail, code })))++ await generateSummary()++ expect(logic.values.summaryError).toBe(detail)+ expect(captureSpy.mock.calls.length > 0).toBe(reported)+ })+it('keeps the panel loading when a newer summary replaces an in-flight one', async () => {summarizationPendingUntilAborted()logic = summaryViewLogic({ trace, tree: [] })