Skip to content

: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.

fix(ai-observability): guard null event definitions in hasRecentAIEvents (#64969)

posthog[bot]ecaa72ca7df2
diff --git a/products/ai_observability/frontend/utils/aiEvents.test.ts b/products/ai_observability/frontend/utils/aiEvents.test.ts
index 489c8bf3a927..6a52e9bae801 100644
--- a/products/ai_observability/frontend/utils/aiEvents.test.ts
+++ b/products/ai_observability/frontend/utils/aiEvents.test.ts
@@ -157,6 +157,19 @@ describe('aiEventsUtils', () => {
expect(queryApiSpy).toHaveBeenCalled()
})
+ it('falls back to ClickHouse when the EventDefinition list resolves to null', async () => {
+ jest.spyOn(api.eventDefinitions, 'list').mockResolvedValueOnce(null as any)
+
+ const queryApiSpy = jest.spyOn(api, 'query').mockResolvedValue({
+ results: [[1]],
+ } as any)
+
+ const result = await hasRecentAIEvents()
+
+ expect(result).toBe(true)
+ expect(queryApiSpy).toHaveBeenCalled()
+ })
+
it('handles null results from ClickHouse gracefully', async () => {
useMocks({
get: {
diff --git a/products/ai_observability/frontend/utils/aiEvents.ts b/products/ai_observability/frontend/utils/aiEvents.ts
index 47638553d832..dc7567bdb9fe 100644
--- a/products/ai_observability/frontend/utils/aiEvents.ts
+++ b/products/ai_observability/frontend/utils/aiEvents.ts
@@ -27,7 +27,7 @@ export async function hasRecentAIEvents(): Promise<boolean> {
search: '$ai_',
})
- const validDefinition = aiEventDefinitions.results.find(
+ const validDefinition = aiEventDefinitions?.results?.find(
(r) => AI_EVENT_NAMES.includes(r.name) && !isDefinitionStale(r, AI_STALE_EVENT_SECONDS)
)