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(ingestion): treat ai meta-events as ai event types (#74234)

Paweł Ledwoń8128e00ca815
diff --git a/nodejs/src/ingestion/common/subpipelines/ai-event-types.ts b/nodejs/src/ingestion/common/subpipelines/ai-event-types.ts
index 23671ac5b218..264889de9a1e 100644
--- a/nodejs/src/ingestion/common/subpipelines/ai-event-types.ts
+++ b/nodejs/src/ingestion/common/subpipelines/ai-event-types.ts
@@ -1,6 +1,10 @@
// AI event type names, shared by the ai lane and the ingestion steps that route AI events.
-// Canonical Node.js list. Python mirror: posthog/hogql_queries/ai/ai_table_resolver.py
+// The Python query-routing list in posthog/hogql_queries/ai/ai_table_resolver.py
+// intentionally lists only the core types: ai_events lacks full history for the
+// meta-events, so their queries must stay on the shared events table to avoid the
+// resolver misreading the missing rows as expired data.
export const AI_EVENT_TYPES = new Set([
+ // Core AI telemetry, enriched by process-ai-event.ts (costs, model params, tool calls).
'$ai_generation',
'$ai_embedding',
'$ai_evaluation',
@@ -8,4 +12,11 @@ export const AI_EVENT_TYPES = new Set([
'$ai_trace',
'$ai_metric',
'$ai_feedback',
+ // Internal meta-events emitted about AI telemetry (taggers, summarization, eval
+ // reports). Cost and model-param enrichment gates on the exact core names above,
+ // so these only get trace-property normalization and the ai_events double-write.
+ '$ai_tag',
+ '$ai_generation_summary',
+ '$ai_trace_summary',
+ '$ai_evaluation_report',
])
diff --git a/nodejs/src/ingestion/pipelines/ai/pipelines/steps/process-ai-event-step.test.ts b/nodejs/src/ingestion/pipelines/ai/pipelines/steps/process-ai-event-step.test.ts
index a3ed6f0f2107..f1b83a30bad8 100644
--- a/nodejs/src/ingestion/pipelines/ai/pipelines/steps/process-ai-event-step.test.ts
+++ b/nodejs/src/ingestion/pipelines/ai/pipelines/steps/process-ai-event-step.test.ts
@@ -52,6 +52,10 @@ describe('processAiEventStep', () => {
'$ai_trace',
'$ai_metric',
'$ai_feedback',
+ '$ai_tag',
+ '$ai_generation_summary',
+ '$ai_trace_summary',
+ '$ai_evaluation_report',
])('calls processAiEvent for %s event', async (eventName) => {
const event = createTestEvent({ event: eventName, properties: { $ai_model: 'gpt-4' } })
const step = createProcessAiEventStep()
diff --git a/posthog/hogql_queries/ai/ai_table_resolver.py b/posthog/hogql_queries/ai/ai_table_resolver.py
index d235c91a7d93..f5f31cc02123 100644
--- a/posthog/hogql_queries/ai/ai_table_resolver.py
+++ b/posthog/hogql_queries/ai/ai_table_resolver.py
@@ -163,7 +163,11 @@ def query_ai_events(
raise AIEventsNotFoundError(f"AI events for {query_type} were not found")
-# Canonical Python list. Node.js mirror: nodejs/src/ingestion/ai/process-ai-event.ts
+# Query-routing list: event types whose full history lives in the dedicated ai_events table.
+# The ingestion list (nodejs/src/ingestion/common/subpipelines/ai-event-types.ts) additionally
+# contains the AI meta-events ($ai_tag, summaries, eval reports); they are excluded here
+# because ai_events lacks their full history, so their queries must stay on the shared
+# events table to avoid misreading the missing rows as expired data.
AI_EVENT_NAMES = frozenset(
{
"$ai_generation",