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.

feat(ingestion): remove the ai branch from the analytics pipeline (#78219)

Paweł Ledwońe3871b99ebd9
diff --git a/nodejs/src/cdp/cdp-api.test.ts b/nodejs/src/cdp/cdp-api.test.ts
index 2e12cec83160..582c40a40624 100644
--- a/nodejs/src/cdp/cdp-api.test.ts
+++ b/nodejs/src/cdp/cdp-api.test.ts
@@ -95,6 +95,11 @@ describe('CDP API', () => {
}
beforeAll(async () => {
+ // Reset before caching the team: without this, getFirstTeam picks up
+ // whatever team the previous suite left with the lowest id, and every
+ // beforeEach reset then deletes it — inserts against the cached team
+ // id fail on the team FK.
+ await resetTestDatabase()
hub = await createHub({
SITE_URL: 'http://localhost:8000',
})
diff --git a/nodejs/src/ingestion/__snapshots__/ingestion-consumer.test.ts.snap b/nodejs/src/ingestion/__snapshots__/ingestion-consumer.test.ts.snap
index 6f73bae8c1ff..90f6878315bb 100644
--- a/nodejs/src/ingestion/__snapshots__/ingestion-consumer.test.ts.snap
+++ b/nodejs/src/ingestion/__snapshots__/ingestion-consumer.test.ts.snap
@@ -411,30 +411,7 @@ exports[`IngestionConsumer typical event processing ai event 1`] = `
"person_mode": "full",
"person_properties": "{"$current_url":"http://localhost:8000","$creator_event_uuid":"<REPLACED-UUID-1>","$initial_current_url":"http://localhost:8000"}",
"project_id": 2,
- "properties": "{"$current_url":"http://localhost:8000","$ai_model":"gpt-4","$ai_provider":"openai","$ai_input_tokens":100,"$ai_output_tokens":50,"$ip":"127.0.0.1","$set":{"$current_url":"http://localhost:8000"},"$set_once":{"$initial_current_url":"http://localhost:8000"},"$ai_cache_reporting_exclusive":false,"$ai_input_cost_usd":0.003,"$ai_output_cost_usd":0.003,"$ai_request_cost_usd":0,"$ai_web_search_cost_usd":0,"$ai_total_cost_usd":0.006,"$ai_model_cost_used":"openai/gpt-4","$ai_cost_model_source":"openrouter","$ai_cost_model_provider":"openai"}",
- "team_id": 2,
- "timestamp": "2025-01-01 00:00:00.000",
- "uuid": "<REPLACED-UUID-1>",
- },
- },
- {
- "headers": {
- "productTrack": "llma",
- },
- "key": "<REPLACED-UUID-1>",
- "topic": "clickhouse_ai_events_json_test",
- "value": {
- "captured_at": "2025-01-01 00:00:00.000",
- "created_at": "2025-01-01 00:00:00.000",
- "distinct_id": "user-1",
- "elements_chain": "",
- "event": "$ai_generation",
- "person_created_at": "2025-01-01 00:00:00",
- "person_id": "<REPLACED-UUID-0>",
- "person_mode": "full",
- "person_properties": "{"$current_url":"http://localhost:8000","$creator_event_uuid":"<REPLACED-UUID-1>","$initial_current_url":"http://localhost:8000"}",
- "project_id": 2,
- "properties": "{"$current_url":"http://localhost:8000","$ai_model":"gpt-4","$ai_provider":"openai","$ai_input_tokens":100,"$ai_output_tokens":50,"$ip":"127.0.0.1","$set":{"$current_url":"http://localhost:8000"},"$set_once":{"$initial_current_url":"http://localhost:8000"},"$ai_cache_reporting_exclusive":false,"$ai_input_cost_usd":0.003,"$ai_output_cost_usd":0.003,"$ai_request_cost_usd":0,"$ai_web_search_cost_usd":0,"$ai_total_cost_usd":0.006,"$ai_model_cost_used":"openai/gpt-4","$ai_cost_model_source":"openrouter","$ai_cost_model_provider":"openai"}",
+ "properties": "{"$current_url":"http://localhost:8000","$ai_model":"gpt-4","$ai_provider":"openai","$ai_input_tokens":100,"$ai_output_tokens":50,"$ip":"127.0.0.1","$set":{"$current_url":"http://localhost:8000"},"$set_once":{"$initial_current_url":"http://localhost:8000"}}",
"team_id": 2,
"timestamp": "2025-01-01 00:00:00.000",
"uuid": "<REPLACED-UUID-1>",
diff --git a/nodejs/src/ingestion/common/steps/event-preprocessing/index.ts b/nodejs/src/ingestion/common/steps/event-preprocessing/index.ts
index 9016351bcb69..43ad2a62d667 100644
--- a/nodejs/src/ingestion/common/steps/event-preprocessing/index.ts
+++ b/nodejs/src/ingestion/common/steps/event-preprocessing/index.ts
@@ -12,7 +12,6 @@ export {
createSkipCookielessRateLimitToOverflowStep,
} from './rate-limit-to-overflow-step'
export { createResolveTeamStep } from './resolve-team'
-export { createValidateAiEventTokensStep } from './validate-ai-event-tokens'
export { createValidateEventMetadataStep } from './validate-event-metadata'
export { createValidateEventPropertiesStep } from './validate-event-properties'
export { createValidateEventSchemaStep } from './validate-event-schema'
diff --git a/nodejs/src/ingestion/common/subpipelines/ai-subpipeline.contract.ts b/nodejs/src/ingestion/common/subpipelines/ai-subpipeline.contract.ts
deleted file mode 100644
index 01e5862d1085..000000000000
--- a/nodejs/src/ingestion/common/subpipelines/ai-subpipeline.contract.ts
+++ /dev/null
@@ -1,58 +0,0 @@
-import { Message } from 'node-rdkafka'
-
-import { GroupTypeManager } from '~/common/groups/group-type-manager'
-import { HogTransformer } from '~/common/hog-transformations/hog-transformer.interface'
-import {
- AiEventOutput,
- AsyncOutput,
- EventOutput,
- IngestionWarningsOutput,
- PersonDistinctIdsOutput,
- PersonMergeEventsOutput,
- PersonsOutput,
-} from '~/common/outputs'
-import { IngestionOutputs } from '~/common/outputs/ingestion-outputs'
-import { TeamManager } from '~/common/utils/team-manager'
-import { GroupStoreForBatch } from '~/ingestion/common/groups/group-store-for-batch'
-import { PersonsStoreForBatch } from '~/ingestion/common/persons/persons-store-for-batch'
-import { EmitEventStepOutput } from '~/ingestion/common/steps/event-processing/emit-event-step'
-import { EventPipelineRunnerOptions } from '~/ingestion/common/steps/event-processing/event-pipeline-options'
-import { PipelineBuilder, StartPipelineBuilder } from '~/ingestion/framework/builders/pipeline-builders'
-import { TopHogWrapper } from '~/ingestion/framework/extensions/tophog'
-import { PluginEvent } from '~/plugin-scaffold'
-import { EventHeaders, Team } from '~/types'
-
-export interface AiEventSubpipelineInput {
- message: Message
- event: PluginEvent
- team: Team
- headers: EventHeaders
- personsStoreForBatch: PersonsStoreForBatch
- groupStoreForBatch: GroupStoreForBatch
-}
-
-export interface AiEventSubpipelineConfig {
- options: EventPipelineRunnerOptions
- outputs: IngestionOutputs<
- | EventOutput
- | AiEventOutput
- | IngestionWarningsOutput
- | PersonsOutput
- | PersonDistinctIdsOutput
- | PersonMergeEventsOutput
- >
- teamManager: TeamManager
- groupTypeManager: GroupTypeManager
- hogTransformer: HogTransformer
- topHog: TopHogWrapper
-}
-
-/**
- * Abstract factory for the AI event sub-pipeline. The analytics lane composes the AI branch through
- * this contract instead of importing the `ai` lane directly; the concrete `createAiEventSubpipeline`
- * (ai lane) is injected at the composition root (servers). This keeps ai and analytics decoupled.
- */
-export type AiEventSubpipelineFactory = <TInput extends AiEventSubpipelineInput, TContext>(
- builder: StartPipelineBuilder<TInput, TContext>,
- config: AiEventSubpipelineConfig
-) => PipelineBuilder<TInput, EmitEventStepOutput, TContext, AsyncOutput>
diff --git a/nodejs/src/ingestion/ingestion-consumer.test.ts b/nodejs/src/ingestion/ingestion-consumer.test.ts
index 403efa6c6410..9b09e0ce93db 100644
--- a/nodejs/src/ingestion/ingestion-consumer.test.ts
+++ b/nodejs/src/ingestion/ingestion-consumer.test.ts
@@ -22,7 +22,6 @@ import {
import { BatchWritingPersonsStore } from '~/ingestion/common/persons/batch-writing-person-store'
import { createPrepareEventStep } from '~/ingestion/common/steps/event-processing/prepare-event-step'
import { createProcessGroupsStep } from '~/ingestion/common/steps/event-processing/process-groups-step'
-import { createAiEventSubpipeline } from '~/ingestion/pipelines/ai'
import { IngestionTestInfra, createIngestionTestInfra } from '~/tests/helpers/ingestion-e2e'
import { createTestIngestionOutputs, createTestMonitoringOutputs } from '~/tests/helpers/ingestion-outputs'
import { forSnapshot } from '~/tests/helpers/snapshots'
@@ -121,7 +120,6 @@ describe('IngestionConsumer', () => {
...infra,
outputs,
clickhouseGroupRepository: new ClickhouseGroupRepository(outputs),
- aiSubpipelineFactory: createAiEventSubpipeline,
hogTransformer: createHogTransformerService(infra.config, {
...infra,
monitoringOutputs: createTestMonitoringOutputs(mockProducer),
@@ -848,134 +846,6 @@ describe('IngestionConsumer', () => {
expect(recentEventMessage).toBeDefined()
expect(recentEventMessage?.value.historical_migration).toBeUndefined()
})
-
- it('should process AI events with invalid token properties by nulling the bad values', async () => {
- const events = [
- createEvent({
- distinct_id: 'user-valid-ai',
- event: '$ai_generation',
- properties: {
- $ai_input_tokens: 100,
- $ai_cache_read_input_tokens: 50,
- $ai_model: 'gpt-4',
- },
- }),
- createEvent({
- distinct_id: 'user-invalid-ai',
- event: '$ai_generation',
- properties: {
- $ai_input_tokens: 'invalid-not-a-number',
- $ai_model: 'gpt-4',
- },
- }),
- createEvent({
- distinct_id: 'user-invalid-ai-cache',
- event: '$ai_embedding',
- properties: {
- $ai_input_tokens: 100,
- $ai_cache_read_input_tokens: { nested: 'object' },
- $ai_model: 'text-embedding-3-small',
- },
- }),
- createEvent({
- distinct_id: 'user-nested-token-objects',
- event: '$ai_generation',
- properties: {
- $ai_input_tokens: { total: 10585, noCache: 10585, cacheRead: 0, cacheWrite: 0 },
- $ai_output_tokens: { total: 163, text: 163, reasoning: 0 },
- $ai_provider: 'amazon-bedrock',
- $ai_model: 'anthropic.claude-sonnet-4-6',
- },
- }),
- createEvent({
- distinct_id: 'user-non-ai',
- event: '$pageview',
- properties: {
- $ai_input_tokens: 'invalid-but-not-ai-event',
- },
- }),
- ]
-
- const messages = createKafkaMessages(events)
- await ingester.handleKafkaBatch(messages)
-
- const producedMessages = mockProducerObserver.getProducedKafkaMessages()
- const eventsTopicMessages = producedMessages.filter((m) => m.topic === 'clickhouse_events_json_test')
-
- // Valid AI event should be processed with tokens intact
- const validAiEvent = eventsTopicMessages.find((m) => m.value.distinct_id === 'user-valid-ai')
- expect(validAiEvent).toBeDefined()
-
- // AI event with invalid string token should be processed with token nulled
- const invalidAiEvent = eventsTopicMessages.find((m) => m.value.distinct_id === 'user-invalid-ai')
- expect(invalidAiEvent).toBeDefined()
- expect(parseJSON(invalidAiEvent?.value.properties as any).$ai_input_tokens).toBeNull()
-
- // AI event with non-normalizable object token should be processed with token nulled
- const invalidCacheEvent = eventsTopicMessages.find((m) => m.value.distinct_id === 'user-invalid-ai-cache')
- expect(invalidCacheEvent).toBeDefined()
- expect(parseJSON(invalidCacheEvent?.value.properties as any).$ai_cache_read_input_tokens).toBeNull()
- expect(parseJSON(invalidCacheEvent?.value.properties as any).$ai_input_tokens).toBe(100)
-
- // AI event with nested token objects (Bedrock/Vercel V3) should be normalized
- const nestedTokenEvent = eventsTopicMessages.find(
- (m) => m.value.distinct_id === 'user-nested-token-objects'
- )
- expect(nestedTokenEvent).toBeDefined()
- expect(parseJSON(nestedTokenEvent?.value.properties as any).$ai_input_tokens).toBe(10585)
- expect(parseJSON(nestedTokenEvent?.value.properties as any).$ai_output_tokens).toBe(163)
-
- // Non-AI event with invalid token property should still be processed unchanged
- const nonAiEvent = eventsTopicMessages.find((m) => m.value.event === '$pageview')
- expect(nonAiEvent).toBeDefined()
- expect(nonAiEvent?.value.distinct_id).toBe('user-non-ai')
- })
-
- it('should split AI events with large properties into events + ai_events', async () => {
- await ingester.stop()
- ingester = await createIngestionConsumer(infra)
-
- const events = [
- createEvent({
- distinct_id: 'user-ai-split',
- event: '$ai_generation',
- properties: {
- $ai_model: 'gpt-4',
- $ai_provider: 'openai',
- $ai_input_tokens: 100,
- $ai_output_tokens: 50,
- $ai_input: 'What is the meaning of life?',
- $ai_output: 'The meaning of life is 42.',
- },
- }),
- ]
-
- await ingester.handleKafkaBatch(createKafkaMessages(events))
-
- const producedMessages = mockProducerObserver.getProducedKafkaMessages()
- const eventsTopicMessages = producedMessages.filter((m) => m.topic === 'clickhouse_events_json_test')
- const aiEventsTopicMessages = producedMessages.filter((m) => m.topic === 'clickhouse_ai_events_json_test')
-
- // Main events topic: stripped of large AI properties
- expect(eventsTopicMessages).toHaveLength(1)
- const mainEvent = eventsTopicMessages[0]
- expect(mainEvent.value.event).toBe('$ai_generation')
- expect(typeof mainEvent.value.properties).toBe('string')
- const mainProps = parseJSON(mainEvent.value.properties as any)
- expect(mainProps.$ai_model).toBe('gpt-4')
- expect(mainProps.$ai_input).toBeUndefined()
- expect(mainProps.$ai_output).toBeUndefined()
-
- // AI events topic: full event with all properties
- expect(aiEventsTopicMessages).toHaveLength(1)
- const aiEvent = aiEventsTopicMessages[0]
- expect(aiEvent.value.event).toBe('$ai_generation')
- expect(typeof aiEvent.value.properties).toBe('string')
- const aiProps = parseJSON(aiEvent.value.properties as any)
- expect(aiProps.$ai_model).toBe('gpt-4')
- expect(aiProps.$ai_input).toBe('What is the meaning of life?')
- expect(aiProps.$ai_output).toBe('The meaning of life is 42.')
- })
})
describe('error handling', () => {
diff --git a/nodejs/src/ingestion/ingestion-consumer.ts b/nodejs/src/ingestion/ingestion-consumer.ts
index c245ec492130..1fab5e16297e 100644
--- a/nodejs/src/ingestion/ingestion-consumer.ts
+++ b/nodejs/src/ingestion/ingestion-consumer.ts
@@ -16,7 +16,6 @@ import {
TophogOutput,
} from '~/common/outputs'
import {
- AiEventOutput,
AsyncOutput,
EventOutput,
PersonDistinctIdsOutput,
@@ -62,7 +61,6 @@ import { OverflowLaneOverflowRedirect } from './common/overflow-redirect/overflo
import { OverflowRedirectService } from './common/overflow-redirect/overflow-redirect-service'
import { RedisOverflowRepository } from './common/overflow-redirect/overflow-redis-repository'
import { createAnalyticsOverflowStrategies } from './common/overflow-redirect/overflow-strategy'
-import { AiEventSubpipelineFactory } from './common/subpipelines/ai-subpipeline.contract'
import { IngestionConsumerConfig, IngestionOutputsConfig } from './config'
export type IngestionConsumerFullConfig = IngestionConsumerConfig &
@@ -78,7 +76,6 @@ export interface IngestionConsumerDeps {
featureFlagCalledDedupRedisPool?: RedisPool
outputs: IngestionOutputs<
| EventOutput
- | AiEventOutput
| IngestionWarningsOutput
| DlqOutput
| OverflowOutput
@@ -97,7 +94,6 @@ export interface IngestionConsumerDeps {
personRepository: PersonRepository
cookielessManager: CookielessManager
hogTransformer: HogTransformer
- aiSubpipelineFactory: AiEventSubpipelineFactory
}
export const latestOffsetTimestampGauge = new Gauge({
@@ -308,7 +304,6 @@ export class IngestionConsumer {
personsStore: this.personsStore,
groupStore: this.groupStore,
hogTransformer: this.hogTransformer,
- aiSubpipelineFactory: this.deps.aiSubpipelineFactory,
eventFilterManager: this.eventFilterManager,
eventIngestionRestrictionManager: this.eventIngestionRestrictionManager,
eventSchemaEnforcementManager: this.eventSchemaEnforcementManager,
diff --git a/nodejs/src/ingestion/common/subpipelines/ai-event-types.ts b/nodejs/src/ingestion/pipelines/ai/ai-event-types.ts
similarity index 91%
rename from nodejs/src/ingestion/common/subpipelines/ai-event-types.ts
rename to nodejs/src/ingestion/pipelines/ai/ai-event-types.ts
index 264889de9a1e..c416b55598b0 100644
--- a/nodejs/src/ingestion/common/subpipelines/ai-event-types.ts
+++ b/nodejs/src/ingestion/pipelines/ai/ai-event-types.ts
@@ -1,4 +1,4 @@
-// AI event type names, shared by the ai lane and the ingestion steps that route AI events.
+// AI event type names accepted by the ai lane.
// 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
diff --git a/nodejs/src/ingestion/pipelines/ai/index.ts b/nodejs/src/ingestion/pipelines/ai/index.ts
index 1c4693644c3d..faa27891620a 100644
--- a/nodejs/src/ingestion/pipelines/ai/index.ts
+++ b/nodejs/src/ingestion/pipelines/ai/index.ts
@@ -1,5 +1,4 @@
export { normalizeTraceProperties, processAiEvent, type EventWithProperties } from './process-ai-event'
-export { AI_EVENT_TYPES } from '~/ingestion/common/subpipelines/ai-event-types'
-export { createAiEventSubpipeline, type AiEventSubpipelineConfig } from './pipelines/ai-event-subpipeline'
+export { AI_EVENT_TYPES } from './ai-event-types'
export { createAiIngestionPipeline, type AiIngestionPipelineConfig } from './pipeline'
export { createAiConsumer, type AiConsumerConfig, type AiSharedScope } from './consumer'
diff --git a/nodejs/src/ingestion/common/subpipelines/large-ai-properties.ts b/nodejs/src/ingestion/pipelines/ai/large-ai-properties.ts
similarity index 100%
rename from nodejs/src/ingestion/common/subpipelines/large-ai-properties.ts
rename to nodejs/src/ingestion/pipelines/ai/large-ai-properties.ts
diff --git a/nodejs/src/ingestion/pipelines/ai/pipeline.test.ts b/nodejs/src/ingestion/pipelines/ai/pipeline.test.ts
index 3e0aa37e5b6f..82dc5aab22d6 100644
--- a/nodejs/src/ingestion/pipelines/ai/pipeline.test.ts
+++ b/nodejs/src/ingestion/pipelines/ai/pipeline.test.ts
@@ -185,6 +185,13 @@ describe('AiIngestionPipeline', () => {
expect(producedForTopic(DLQ_TOPIC)).toHaveLength(0)
})
+ it('nulls invalid AI token properties before emitting', async () => {
+ await runPipeline([createMessage('$ai_generation', { $ai_input_tokens: 'not-a-number' })])
+
+ const [emitted] = producedForTopic(AI_EVENTS_TOPIC)
+ expect(parseJSON(emitted.properties).$ai_input_tokens).toBeNull()
+ })
+
it.each(['$pageview', '$autocapture', '$identify', '$exception', 'custom_event'])(
'DLQs non-AI %s events instead of processing them',
async (eventName) => {
diff --git a/nodejs/src/ingestion/pipelines/ai/pipeline.ts b/nodejs/src/ingestion/pipelines/ai/pipeline.ts
index 00a7a0f38073..797676eeb520 100644
--- a/nodejs/src/ingestion/pipelines/ai/pipeline.ts
+++ b/nodejs/src/ingestion/pipelines/ai/pipeline.ts
@@ -26,7 +26,6 @@ import {
createOnlyCookielessRateLimitToOverflowStep,
createOverflowLaneTTLRefreshStep,
createSkipCookielessRateLimitToOverflowStep,
- createValidateAiEventTokensStep,
createValidateEventMetadataStep,
createValidateEventPropertiesStep,
createValidateEventSchemaStep,
@@ -42,14 +41,13 @@ import { createNormalizeEventStep } from '~/ingestion/common/steps/event-process
import { createNormalizeProcessPersonFlagStep } from '~/ingestion/common/steps/event-processing/normalize-process-person-flag-step'
import { createPrepareEventStep } from '~/ingestion/common/steps/event-processing/prepare-event-step'
import { createReadOnlyProcessGroupsStep } from '~/ingestion/common/steps/event-processing/readonly-process-groups-step'
-import { createSplitAiEventsStep } from '~/ingestion/common/steps/event-processing/split-ai-events-step'
import { createStripPersonUpdatePropertiesStep } from '~/ingestion/common/steps/event-processing/strip-person-update-properties-step'
import { createRecordIngestionLagStep } from '~/ingestion/common/steps/record-ingestion-lag'
-import { AI_EVENT_TYPES } from '~/ingestion/common/subpipelines/ai-event-types'
import { IngestionOverflowMode } from '~/ingestion/config'
import { TopHogRegistry, sum, sumOk, sumResult } from '~/ingestion/framework/extensions/tophog'
import { isDropResult } from '~/ingestion/framework/results'
+import { AI_EVENT_TYPES } from './ai-event-types'
import { BlobStore } from './blob-offload/blob-store'
import { AiEventOutput, EVENTS_OUTPUT, EventOutput } from './outputs'
import {
@@ -58,8 +56,10 @@ import {
createUploadAiBlobStep,
extractAiBlobsFanOut,
mergeAiBlobPointersFanIn,
-} from './pipelines/steps/offload-ai-blobs-step'
-import { createProcessAiEventStep } from './pipelines/steps/process-ai-event-step'
+} from './steps/offload-ai-blobs-step'
+import { createProcessAiEventStep } from './steps/process-ai-event-step'
+import { createSplitAiEventsStep } from './steps/split-ai-events-step'
+import { createValidateAiEventTokensStep } from './steps/validate-ai-event-tokens'
export interface AiIngestionPipelineConfig {
outputs: IngestionOutputs<
@@ -95,8 +95,7 @@ interface AiIngestionPipelineContext {
}
/**
- * Standalone AI ingestion pipeline. Mirrors the AI branch of the analytics
- * joined pipeline, but:
+ * Standalone AI ingestion pipeline. Compared to the analytics pipeline:
* - only AI events flow through (everything else is DLQ'd by the allow step),
* - person and group data are read-only (fetched, never written), like error
* tracking — so there are no person/group batch stores or per-distinct-id
@@ -104,9 +103,9 @@ interface AiIngestionPipelineContext {
* - overflow uses the dedicated `'ai'` keyspace (wired at service construction),
* so AI overflow can never affect analytics.
*
- * AI events are still double-written to both the events output and the
- * ai_events output (via the split step), keeping it a drop-in for the analytics
- * AI branch once capture-side routing switches over.
+ * AI events are double-written to both the events output and the ai_events
+ * output (via the split step), so they appear on the shared events table as
+ * well as the dedicated ai_events table.
*/
export function createAiIngestionPipeline<
TInput extends AiIngestionPipelineInput,
diff --git a/nodejs/src/ingestion/pipelines/ai/pipelines/ai-event-subpipeline.ts b/nodejs/src/ingestion/pipelines/ai/pipelines/ai-event-subpipeline.ts
deleted file mode 100644
index 7697a45fec05..000000000000
--- a/nodejs/src/ingestion/pipelines/ai/pipelines/ai-event-subpipeline.ts
+++ /dev/null
@@ -1,134 +0,0 @@
-import { AsyncOutput, EVENTS_OUTPUT } from '~/common/outputs'
-import { createImmediateMergeFoldStep } from '~/ingestion/common/persons/person-merge-fold'
-import { createCreateEventStep } from '~/ingestion/common/steps/event-processing/create-event-step'
-import { EmitEventStepOutput, createEmitEventStep } from '~/ingestion/common/steps/event-processing/emit-event-step'
-import { createHogTransformEventStep } from '~/ingestion/common/steps/event-processing/hog-transform-event-step'
-import { createNormalizeEventStep } from '~/ingestion/common/steps/event-processing/normalize-event-step'
-import { createNormalizeProcessPersonFlagStep } from '~/ingestion/common/steps/event-processing/normalize-process-person-flag-step'
-import { createPrepareEventStep } from '~/ingestion/common/steps/event-processing/prepare-event-step'
-import { createProcessGroupsStep } from '~/ingestion/common/steps/event-processing/process-groups-step'
-import { createProcessPersonlessStep } from '~/ingestion/common/steps/event-processing/process-personless-step'
-import { createProcessPersonsStep } from '~/ingestion/common/steps/event-processing/process-persons-step'
-import { createSplitAiEventsStep } from '~/ingestion/common/steps/event-processing/split-ai-events-step'
-import { createRecordIngestionLagStep } from '~/ingestion/common/steps/record-ingestion-lag'
-import type {
- AiEventSubpipelineConfig,
- AiEventSubpipelineInput,
-} from '~/ingestion/common/subpipelines/ai-subpipeline.contract'
-import { PipelineBuilder, StartPipelineBuilder } from '~/ingestion/framework/builders/pipeline-builders'
-import { sum, sumOk, sumResult, timer } from '~/ingestion/framework/extensions/tophog'
-import { isDropResult } from '~/ingestion/framework/results'
-
-import { createProcessAiEventStep } from './steps/process-ai-event-step'
-
-export type {
- AiEventSubpipelineConfig,
- AiEventSubpipelineInput,
-} from '~/ingestion/common/subpipelines/ai-subpipeline.contract'
-
-export function createAiEventSubpipeline<TInput extends AiEventSubpipelineInput, TContext>(
- builder: StartPipelineBuilder<TInput, TContext>,
- config: AiEventSubpipelineConfig
-): PipelineBuilder<TInput, EmitEventStepOutput, TContext, AsyncOutput> {
- const { options, outputs, teamManager, groupTypeManager, hogTransformer, topHog } = config
-
- return (
- builder
- .pipe(createNormalizeProcessPersonFlagStep())
- .pipe(
- topHog(createHogTransformEventStep(hogTransformer), [
- sumOk(
- 'transformations_run',
- (output) => ({ team_id: String(output.team.id) }),
- (output) => output.transformationsRun
- ),
- sumOk(
- 'transformations_run_per_partition',
- (output, input) => ({
- team_id: String(output.team.id),
- partition: String(input.message.partition),
- }),
- (output) => output.transformationsRun
- ),
- sumResult(
- 'events_dropped_by_transformation',
- (_result, input) => ({ team_id: String(input.team.id) }),
- (result) => (isDropResult(result) ? 1 : 0)
- ),
- sumResult(
- 'events_dropped_by_transformation_per_partition',
- (_result, input) => ({
- team_id: String(input.team.id),
- partition: String(input.message.partition),
- }),
- (result) => (isDropResult(result) ? 1 : 0)
- ),
- ]),
- { retry: { tries: 5, sleepMs: 100, name: 'hog_transform_event' } }
- )
- .pipe(createNormalizeEventStep())
- .pipe(createProcessAiEventStep())
- .pipe(
- createProcessPersonlessStep(
- options.FLAG_CALLED_PERSONLESS_DEFAULT_TEAMS,
- options.PERSONLESS_WRITES_DISABLED_TEAMS
- ),
- {
- retry: { tries: 5, sleepMs: 100, name: 'process_personless' },
- }
- )
- // AI events are never merge events, so there are no merges to fold in
- // this branch: every event processes immediately. The branch itself is
- // temporary and goes away once ingestion fully switches over to the
- // dedicated AI pipeline.
- .pipe(createImmediateMergeFoldStep())
- .pipe(
- topHog(createProcessPersonsStep(options, outputs), [
- timer('process_persons_time', (input) => ({
- team_id: String(input.team.id),
- distinct_id: input.normalizedEvent.distinct_id,
- })),
- ]),
- { retry: { tries: 5, sleepMs: 100, name: 'process_persons' } }
- )
- .pipe(createPrepareEventStep())
- .pipe(createProcessGroupsStep(teamManager, groupTypeManager, options), {
- retry: { tries: 5, sleepMs: 100, name: 'process_groups' },
- })
- .pipe(createCreateEventStep(EVENTS_OUTPUT))
- .pipe(createSplitAiEventsStep())
- .pipe(
- topHog(
- createEmitEventStep({
- outputs,
- }),
- [
- sum(
- 'emitted_events',
- (input) => ({ team_id: String(input.teamId) }),
- (input) => input.eventsToEmit.length
- ),
- sum(
- 'emitted_events_per_distinct_id',
- (input) => ({
- team_id: String(input.teamId),
- distinct_id: input.eventsToEmit[0]?.event.distinct_id ?? '',
- partition: String(input.message.partition),
- }),
- (input) => input.eventsToEmit.length
- ),
- sum(
- 'emitted_events_per_partition',
- (input) => ({
- team_id: String(input.teamId),
- partition: String(input.message.partition),
- }),
- (input) => input.eventsToEmit.length
- ),
- ]
- ),
- { retry: { tries: 5, sleepMs: 100, name: 'emit_event' } }
- )
- .pipe(createRecordIngestionLagStep())
- )
-}
diff --git a/nodejs/src/ingestion/pipelines/ai/process-ai-event.ts b/nodejs/src/ingestion/pipelines/ai/process-ai-event.ts
index e4029a14e643..c1bfe78a4228 100644
--- a/nodejs/src/ingestion/pipelines/ai/process-ai-event.ts
+++ b/nodejs/src/ingestion/pipelines/ai/process-ai-event.ts
@@ -8,7 +8,7 @@
* - Model parameter extraction (for generation/embedding/evaluation events)
*/
import { logger } from '~/common/utils/logger'
-import { AI_EVENT_TYPES } from '~/ingestion/common/subpipelines/ai-event-types'
+import { AI_EVENT_TYPES } from '~/ingestion/pipelines/ai/ai-event-types'
import { PluginEvent } from '~/plugin-scaffold'
import { convertRawEvent } from './convert-raw-event'
diff --git a/nodejs/src/ingestion/pipelines/ai/pipelines/steps/offload-ai-blobs-step.test.ts b/nodejs/src/ingestion/pipelines/ai/steps/offload-ai-blobs-step.test.ts
similarity index 100%
rename from nodejs/src/ingestion/pipelines/ai/pipelines/steps/offload-ai-blobs-step.test.ts
rename to nodejs/src/ingestion/pipelines/ai/steps/offload-ai-blobs-step.test.ts
diff --git a/nodejs/src/ingestion/pipelines/ai/pipelines/steps/offload-ai-blobs-step.ts b/nodejs/src/ingestion/pipelines/ai/steps/offload-ai-blobs-step.ts
similarity index 99%
rename from nodejs/src/ingestion/pipelines/ai/pipelines/steps/offload-ai-blobs-step.ts
rename to nodejs/src/ingestion/pipelines/ai/steps/offload-ai-blobs-step.ts
index 11b839a44d6e..be301cc5369c 100644
--- a/nodejs/src/ingestion/pipelines/ai/pipelines/steps/offload-ai-blobs-step.ts
+++ b/nodejs/src/ingestion/pipelines/ai/steps/offload-ai-blobs-step.ts
@@ -1,8 +1,8 @@
-import { LARGE_AI_PROPERTIES } from '~/ingestion/common/subpipelines/large-ai-properties'
import { ok } from '~/ingestion/framework/results'
import { ProcessingStep } from '~/ingestion/framework/steps'
import { BlobStore, EnsureStoredOutcome } from '~/ingestion/pipelines/ai/blob-offload/blob-store'
import { DetectedBlob, extractBlobs } from '~/ingestion/pipelines/ai/blob-offload/detect'
+import { LARGE_AI_PROPERTIES } from '~/ingestion/pipelines/ai/large-ai-properties'
import {
aiBlobOffloadBelowFloorBytes,
aiBlobOffloadBelowFloorCounter,
diff --git a/nodejs/src/ingestion/pipelines/ai/pipelines/steps/process-ai-event-step.test.ts b/nodejs/src/ingestion/pipelines/ai/steps/process-ai-event-step.test.ts
similarity index 100%
rename from nodejs/src/ingestion/pipelines/ai/pipelines/steps/process-ai-event-step.test.ts
rename to nodejs/src/ingestion/pipelines/ai/steps/process-ai-event-step.test.ts
diff --git a/nodejs/src/ingestion/pipelines/ai/pipelines/steps/process-ai-event-step.ts b/nodejs/src/ingestion/pipelines/ai/steps/process-ai-event-step.ts
similarity index 95%
rename from nodejs/src/ingestion/pipelines/ai/pipelines/steps/process-ai-event-step.ts
rename to nodejs/src/ingestion/pipelines/ai/steps/process-ai-event-step.ts
index 56c99b667819..a868cf2f3de2 100644
--- a/nodejs/src/ingestion/pipelines/ai/pipelines/steps/process-ai-event-step.ts
+++ b/nodejs/src/ingestion/pipelines/ai/steps/process-ai-event-step.ts
@@ -1,8 +1,8 @@
import { logger } from '~/common/utils/logger'
import { captureException } from '~/common/utils/posthog'
-import { AI_EVENT_TYPES } from '~/ingestion/common/subpipelines/ai-event-types'
import { dlq, ok } from '~/ingestion/framework/results'
import { ProcessingStep } from '~/ingestion/framework/steps'
+import { AI_EVENT_TYPES } from '~/ingestion/pipelines/ai/ai-event-types'
import { processAiEvent } from '~/ingestion/pipelines/ai/process-ai-event'
import { PluginEvent } from '~/plugin-scaffold'
diff --git a/nodejs/src/ingestion/common/steps/event-processing/split-ai-events-step.test.ts b/nodejs/src/ingestion/pipelines/ai/steps/split-ai-events-step.test.ts
similarity index 100%
rename from nodejs/src/ingestion/common/steps/event-processing/split-ai-events-step.test.ts
rename to nodejs/src/ingestion/pipelines/ai/steps/split-ai-events-step.test.ts
diff --git a/nodejs/src/ingestion/common/steps/event-processing/split-ai-events-step.ts b/nodejs/src/ingestion/pipelines/ai/steps/split-ai-events-step.ts
similarity index 89%
rename from nodejs/src/ingestion/common/steps/event-processing/split-ai-events-step.ts
rename to nodejs/src/ingestion/pipelines/ai/steps/split-ai-events-step.ts
index 40c269e1f9b5..0d2b4f092c5a 100644
--- a/nodejs/src/ingestion/common/steps/event-processing/split-ai-events-step.ts
+++ b/nodejs/src/ingestion/pipelines/ai/steps/split-ai-events-step.ts
@@ -1,12 +1,11 @@
import { AI_EVENTS_OUTPUT, AiEventOutput, EventOutput } from '~/common/outputs'
-import { AI_EVENT_TYPES } from '~/ingestion/common/subpipelines/ai-event-types'
-import { LARGE_AI_PROPERTIES } from '~/ingestion/common/subpipelines/large-ai-properties'
+import { EventToEmit } from '~/ingestion/common/steps/event-processing/emit-event-step'
import { ok } from '~/ingestion/framework/results'
import { ProcessingStep } from '~/ingestion/framework/steps'
+import { AI_EVENT_TYPES } from '~/ingestion/pipelines/ai/ai-event-types'
+import { LARGE_AI_PROPERTIES } from '~/ingestion/pipelines/ai/large-ai-properties'
import { ProcessedEvent } from '~/types'
-import { EventToEmit } from './emit-event-step'
-
export interface SplitAiEventsStepInput {
eventsToEmit: EventToEmit<EventOutput>[]
teamId: number
diff --git a/nodejs/src/ingestion/common/steps/event-preprocessing/validate-ai-event-tokens.test.ts b/nodejs/src/ingestion/pipelines/ai/steps/validate-ai-event-tokens.test.ts
similarity index 100%
rename from nodejs/src/ingestion/common/steps/event-preprocessing/validate-ai-event-tokens.test.ts
rename to nodejs/src/ingestion/pipelines/ai/steps/validate-ai-event-tokens.test.ts
diff --git a/nodejs/src/ingestion/common/steps/event-preprocessing/validate-ai-event-tokens.ts b/nodejs/src/ingestion/pipelines/ai/steps/validate-ai-event-tokens.ts
similarity index 97%
rename from nodejs/src/ingestion/common/steps/event-preprocessing/validate-ai-event-tokens.ts
rename to nodejs/src/ingestion/pipelines/ai/steps/validate-ai-event-tokens.ts
index 6a846ca5e816..34e66890beef 100644
--- a/nodejs/src/ingestion/common/steps/event-preprocessing/validate-ai-event-tokens.ts
+++ b/nodejs/src/ingestion/pipelines/ai/steps/validate-ai-event-tokens.ts
@@ -1,7 +1,7 @@
-import { AI_EVENT_TYPES } from '~/ingestion/common/subpipelines/ai-event-types'
import { PipelineWarning } from '~/ingestion/framework/pipeline.interface'
import { ok } from '~/ingestion/framework/results'
import { ProcessingStep } from '~/ingestion/framework/steps'
+import { AI_EVENT_TYPES } from '~/ingestion/pipelines/ai/ai-event-types'
import { PipelineEvent } from '~/types'
const TOKEN_PROPERTIES = [
diff --git a/nodejs/src/ingestion/pipelines/analytics/index.ts b/nodejs/src/ingestion/pipelines/analytics/index.ts
index abca0bc59023..ac54f40ea55d 100644
--- a/nodejs/src/ingestion/pipelines/analytics/index.ts
+++ b/nodejs/src/ingestion/pipelines/analytics/index.ts
@@ -1,12 +1,5 @@
export { createEventSubpipeline, type EventSubpipelineConfig, type EventSubpipelineInput } from './event-subpipeline'
-export {
- createPerDistinctIdPipeline,
- type PerDistinctIdPipelineConfig,
- type PerDistinctIdPipelineContext,
- type PerDistinctIdPipelineInput,
-} from './per-distinct-id-pipeline'
-
export {
createPostTeamPreprocessingSubpipeline,
type PostTeamPreprocessingSubpipelineConfig,
diff --git a/nodejs/src/ingestion/pipelines/analytics/joined-ingestion-pipeline.ts b/nodejs/src/ingestion/pipelines/analytics/joined-ingestion-pipeline.ts
index aeebc2d4ee20..0a08b59981b3 100644
--- a/nodejs/src/ingestion/pipelines/analytics/joined-ingestion-pipeline.ts
+++ b/nodejs/src/ingestion/pipelines/analytics/joined-ingestion-pipeline.ts
@@ -25,7 +25,6 @@ import {
createApplyEventRestrictionsStep,
createEnrichSurveyPersonPropertiesStep,
createSkipCookielessRateLimitToOverflowStep,
- createValidateAiEventTokensStep,
createValidateHistoricalMigrationStep,
} from '~/ingestion/common/steps/event-preprocessing'
import { EventPipelineRunnerOptions } from '~/ingestion/common/steps/event-processing/event-pipeline-options'
@@ -33,23 +32,11 @@ import { createFlushBatchStoresStep } from '~/ingestion/common/steps/event-proce
import { createFlushHogTransformerStep } from '~/ingestion/common/steps/event-processing/flush-hog-transformer-step'
import { createGroupStoreBeforeBatchStep } from '~/ingestion/common/steps/group-store-batch-step'
import { createPersonsStoreBeforeBatchStep } from '~/ingestion/common/steps/persons-store-batch-step'
-import { AiEventSubpipelineFactory } from '~/ingestion/common/subpipelines/ai-subpipeline.contract'
import { IngestionOverflowMode } from '~/ingestion/config'
import { TopHogRegistry, createTopHogWrapper } from '~/ingestion/framework/extensions/tophog'
-import {
- AiEventOutput,
- AsyncOutput,
- EventOutput,
- PersonDistinctIdsOutput,
- PersonMergeEventsOutput,
- PersonsOutput,
-} from './outputs'
-import {
- PerDistinctIdPipelineConfig,
- PerDistinctIdPipelineInput,
- createPerDistinctIdPipeline,
-} from './per-distinct-id-pipeline'
+import { EventSubpipelineConfig, EventSubpipelineInput, createEventSubpipeline } from './event-subpipeline'
+import { AsyncOutput, EventOutput, PersonDistinctIdsOutput, PersonMergeEventsOutput, PersonsOutput } from './outputs'
import {
PostTeamPreprocessingSubpipelineConfig,
createPostTeamPreprocessingSubpipeline,
@@ -63,7 +50,6 @@ export interface JoinedIngestionPipelineConfig {
groupsPrefetchEnabled: boolean
outputs: IngestionOutputs<
| EventOutput
- | AiEventOutput
| IngestionWarningsOutput
| DlqOutput
| OverflowOutput
@@ -89,7 +75,6 @@ export interface JoinedIngestionPipelineDeps {
personsStore: PersonsStore
groupStore: BatchWritingGroupStore
hogTransformer: HogTransformer
- aiSubpipelineFactory: AiEventSubpipelineFactory
eventFilterManager: EventFilterManager
eventIngestionRestrictionManager: EventIngestionRestrictionManager
eventSchemaEnforcementManager: EventSchemaEnforcementManager
@@ -111,7 +96,7 @@ export interface JoinedIngestionPipelineContext {
message: Message
}
-function getTokenAndDistinctId(input: PerDistinctIdPipelineInput): string {
+function getTokenAndDistinctId(input: EventSubpipelineInput): string {
const token = input.headers.token ?? ''
const distinctId = input.event.distinct_id ?? ''
return `${token}:${distinctId}`
@@ -147,7 +132,6 @@ export function createJoinedIngestionPipeline<
cookielessManager,
groupTypeManager,
topHog,
- aiSubpipelineFactory,
} = deps
const topHogWrapper = createTopHogWrapper(topHog)
@@ -169,17 +153,16 @@ export function createJoinedIngestionPipeline<
personlessWritesDisabledTeams: perDistinctIdOptions.PERSONLESS_WRITES_DISABLED_TEAMS,
}
- const perEventConfig: PerDistinctIdPipelineConfig = {
+ const perEventConfig: EventSubpipelineConfig = {
options: perDistinctIdOptions,
outputs,
- aiSubpipelineFactory,
teamManager,
groupTypeManager,
hogTransformer,
topHog: topHogWrapper,
}
- const mergeFoldPlanningStep = createMergeFoldPlanningStep<PerDistinctIdPipelineInput>(perDistinctIdOptions)
+ const mergeFoldPlanningStep = createMergeFoldPlanningStep<EventSubpipelineInput>(perDistinctIdOptions)
return (
newCommonIngestionPipeline<TInput, TContext, OverflowOutput | AsyncOutput>({
@@ -219,7 +202,6 @@ export function createJoinedIngestionPipeline<
.parseMessage()
.resolveTeam()
.pipe(createValidateHistoricalMigrationStep())
- .pipe(createValidateAiEventTokensStep())
.pipe(createEnrichSurveyPersonPropertiesStep())
.compose((b) => createPostTeamPreprocessingSubpipeline(b, postTeamConfig))
// Group by token:distinctId and process each group concurrently.
@@ -230,7 +212,7 @@ export function createJoinedIngestionPipeline<
.concurrentlyPerGroup(getTokenAndDistinctId, (group) =>
group
.pipeChunk(mergeFoldPlanningStep)
- .sequentially((event) => createPerDistinctIdPipeline(event, perEventConfig))
+ .sequentially((event) => createEventSubpipeline(event, perEventConfig))
)
.afterBatch((afterBatch) =>
afterBatch
diff --git a/nodejs/src/ingestion/pipelines/analytics/outputs/registry.ts b/nodejs/src/ingestion/pipelines/analytics/outputs/registry.ts
index 0e555b7e8e1c..4ab95c713ff5 100644
--- a/nodejs/src/ingestion/pipelines/analytics/outputs/registry.ts
+++ b/nodejs/src/ingestion/pipelines/analytics/outputs/registry.ts
@@ -1,11 +1,4 @@
-import {
- AI_EVENTS_OUTPUT,
- ASYNC_OUTPUT,
- EVENTS_OUTPUT,
- PERSONS_OUTPUT,
- PERSON_DISTINCT_IDS_OUTPUT,
- PERSON_MERGE_EVENTS_OUTPUT,
-} from '.'
+import { ASYNC_OUTPUT, EVENTS_OUTPUT, PERSONS_OUTPUT, PERSON_DISTINCT_IDS_OUTPUT, PERSON_MERGE_EVENTS_OUTPUT } from '.'
import {
APP_METRICS_OUTPUT,
@@ -26,10 +19,6 @@ export function createOutputsRegistry() {
topicKey: 'INGESTION_OUTPUT_EVENTS_TOPIC',
producerKey: 'INGESTION_OUTPUT_EVENTS_PRODUCER',
})
- .register(AI_EVENTS_OUTPUT, {
- topicKey: 'INGESTION_OUTPUT_AI_EVENTS_TOPIC',
- producerKey: 'INGESTION_OUTPUT_AI_EVENTS_PRODUCER',
- })
.register(INGESTION_WARNINGS_OUTPUT, {
topicKey: 'INGESTION_OUTPUT_INGESTION_WARNINGS_TOPIC',
producerKey: 'INGESTION_OUTPUT_INGESTION_WARNINGS_PRODUCER',
diff --git a/nodejs/src/ingestion/pipelines/analytics/per-distinct-id-pipeline.ts b/nodejs/src/ingestion/pipelines/analytics/per-distinct-id-pipeline.ts
deleted file mode 100644
index daf925e34fd0..000000000000
--- a/nodejs/src/ingestion/pipelines/analytics/per-distinct-id-pipeline.ts
+++ /dev/null
@@ -1,100 +0,0 @@
-import { Message } from 'node-rdkafka'
-
-import { GroupTypeManager } from '~/common/groups/group-type-manager'
-import { HogTransformer } from '~/common/hog-transformations/hog-transformer.interface'
-import { IngestionWarningsOutput } from '~/common/outputs'
-import { IngestionOutputs } from '~/common/outputs/ingestion-outputs'
-import { TeamManager } from '~/common/utils/team-manager'
-import { WithMergeFoldDecision } from '~/ingestion/common/persons/person-merge-fold'
-import { EmitEventStepOutput } from '~/ingestion/common/steps/event-processing/emit-event-step'
-import { EventPipelineRunnerOptions } from '~/ingestion/common/steps/event-processing/event-pipeline-options'
-import { AI_EVENT_TYPES } from '~/ingestion/common/subpipelines/ai-event-types'
-import {
- AiEventSubpipelineFactory,
- AiEventSubpipelineInput,
-} from '~/ingestion/common/subpipelines/ai-subpipeline.contract'
-import { PipelineBuilder, StartPipelineBuilder } from '~/ingestion/framework/builders/pipeline-builders'
-import { TopHogWrapper } from '~/ingestion/framework/extensions/tophog'
-import { Team } from '~/types'
-
-import { EventSubpipelineInput, createEventSubpipeline } from './event-subpipeline'
-import {
- AiEventOutput,
- AsyncOutput,
- EventOutput,
- PersonDistinctIdsOutput,
- PersonMergeEventsOutput,
- PersonsOutput,
-} from './outputs'
-
-export type PerDistinctIdPipelineInput = EventSubpipelineInput & AiEventSubpipelineInput
-
-export interface PerDistinctIdPipelineConfig {
- options: EventPipelineRunnerOptions
- outputs: IngestionOutputs<
- | EventOutput
- | AiEventOutput
- | IngestionWarningsOutput
- | PersonsOutput
- | PersonDistinctIdsOutput
- | PersonMergeEventsOutput
- >
- aiSubpipelineFactory: AiEventSubpipelineFactory
- teamManager: TeamManager
- groupTypeManager: GroupTypeManager
- hogTransformer: HogTransformer
- topHog: TopHogWrapper
-}
-
-export interface PerDistinctIdPipelineContext {
- message: Message
- team: Team
-}
-
-type EventBranch = 'ai' | 'event'
-
-const EVENT_BRANCH_MAP = new Map<string, EventBranch>([
- ...[...AI_EVENT_TYPES].map((t): [string, EventBranch] => [t, 'ai']),
-])
-
-function classifyEvent(input: PerDistinctIdPipelineInput): EventBranch {
- return EVENT_BRANCH_MAP.get(input.event.event) ?? 'event'
-}
-
-// The event branch's person step consumes the merge-fold decision, so this pipeline requires it on
-// its inputs (the joined pipeline's planning step attaches it); the AI branch ignores it.
-export function createPerDistinctIdPipeline<
- TInput extends PerDistinctIdPipelineInput & WithMergeFoldDecision,
- TContext,
->(
- builder: StartPipelineBuilder<TInput, TContext>,
- config: PerDistinctIdPipelineConfig
-): PipelineBuilder<TInput, EmitEventStepOutput, TContext, AsyncOutput> {
- const { options, outputs, aiSubpipelineFactory, teamManager, groupTypeManager, hogTransformer, topHog } = config
-
- // Retry is applied per step inside each branch's subpipeline (on the I/O
- // steps that can throw transient errors), rather than around the whole chain.
- return builder.branching(classifyEvent, (branches) =>
- branches
- .branch('ai', (b) =>
- aiSubpipelineFactory(b, {
- options,
- outputs,
- teamManager,
- groupTypeManager,
- hogTransformer,
- topHog,
- })
- )
- .branch('event', (b) =>
- createEventSubpipeline(b, {
- options,
- outputs,
- teamManager,
- groupTypeManager,
- hogTransformer,
- topHog,
- })
- )
- )
-}
diff --git a/nodejs/src/servers/ingestion-api-server.ts b/nodejs/src/servers/ingestion-api-server.ts
index 4c1acd4957b4..a38fd232409b 100644
--- a/nodejs/src/servers/ingestion-api-server.ts
+++ b/nodejs/src/servers/ingestion-api-server.ts
@@ -44,7 +44,6 @@ import {
} from '~/ingestion/common/steps/event-processing/flush-batch-stores-step'
import { createKafkaDebugContext, createOkContext } from '~/ingestion/framework/helpers'
import { TopHog } from '~/ingestion/framework/tophog'
-import { createAiEventSubpipeline } from '~/ingestion/pipelines/ai'
import {
JoinedIngestionPipelineConfig,
JoinedIngestionPipelineContext,
@@ -418,7 +417,6 @@ export class IngestionApiServer implements NodeServer {
personsStore,
groupStore,
hogTransformer: this.hogTransformer,
- aiSubpipelineFactory: createAiEventSubpipeline,
eventFilterManager: eventFilterManagerStarted.value,
eventIngestionRestrictionManager,
// Schema loads run detached in the LazyLoader buffer, so an un-retried transient
diff --git a/nodejs/src/servers/ingestion-general-server.ts b/nodejs/src/servers/ingestion-general-server.ts
index ca496a65ebc5..8bce90d912bd 100644
--- a/nodejs/src/servers/ingestion-general-server.ts
+++ b/nodejs/src/servers/ingestion-general-server.ts
@@ -34,7 +34,7 @@ import {
getDefaultKafkaDownstreamProducerEnvConfig,
getDefaultKafkaUpstreamProducerEnvConfig,
} from '~/ingestion/common/outputs/producers'
-import { createAiConsumer, createAiEventSubpipeline } from '~/ingestion/pipelines/ai'
+import { createAiConsumer } from '~/ingestion/pipelines/ai'
import { createOutputsRegistry as createAiOutputsRegistry } from '~/ingestion/pipelines/ai/outputs/registry'
import { createOutputsRegistry } from '~/ingestion/pipelines/analytics/outputs/registry'
import { createClientWarningsConsumer } from '~/ingestion/pipelines/clientwarnings'
@@ -281,7 +281,6 @@ export class IngestionGeneralServer implements NodeServer {
personRepository,
cookielessManager,
hogTransformer: createHogTransformerService(this.config, hogTransformerDeps),
- aiSubpipelineFactory: createAiEventSubpipeline,
}
const startClientWarnings = (override?: { topic: string; groupId: string }) => {
diff --git a/nodejs/tests/ingestion/ingestion-e2e.test.ts b/nodejs/tests/ingestion/ingestion-e2e.test.ts
index 06e6f6405fc3..2d5341389e7e 100644
--- a/nodejs/tests/ingestion/ingestion-e2e.test.ts
+++ b/nodejs/tests/ingestion/ingestion-e2e.test.ts
@@ -6,7 +6,6 @@ import { fetchDistinctIds } from '~/common/persons/repositories/test-helpers'
import { parseJSON } from '~/common/utils/json-parse'
import { UUIDT } from '~/common/utils/utils'
import { IngestionConsumer } from '~/ingestion/ingestion-consumer'
-import { createAiEventSubpipeline } from '~/ingestion/pipelines/ai'
import { Clickhouse } from '~/tests/helpers/clickhouse'
import { waitForExpect } from '~/tests/helpers/expectations'
import {
@@ -67,7 +66,6 @@ describe.each([
cookielessManager: infra.cookielessManager,
outputs,
clickhouseGroupRepository: new ClickhouseGroupRepository(outputs),
- aiSubpipelineFactory: createAiEventSubpipeline,
hogTransformer: createHogTransformerService(infra.config, {
geoipService: infra.geoipService,
postgres: infra.postgres,
@@ -4952,116 +4950,4 @@ describe.each([
})
}
)
-
- testWithTeamIngester(
- 'should route $ai_generation events through AI subpipeline with full enrichment',
- {},
- async ({ ingester, team, kafkaProducer, token }) => {
- const distinctId = new UUIDT().toString()
- await ingester.handleKafkaBatch(
- createKafkaMessages(
- [
- new EventBuilder(team, distinctId)
- .withEvent('$ai_generation')
- .withProperties({
- $ai_model: 'gpt-4',
- $ai_provider: 'openai',
- $ai_input_tokens: 100,
- $ai_output_tokens: 50,
- $ai_trace_id: 12345,
- $ai_parent_id: 67890,
- $ai_model_parameters: {
- temperature: 0.7,
- stream: true,
- max_tokens: 1024,
- },
- $ai_output_choices: JSON.stringify([
- {
- role: 'assistant',
- message: {
- tool_calls: [
- { function: { name: 'get_weather' } },
- { function: { name: 'search_docs' } },
- ],
- },
- },
- ]),
- })
- .build(),
- ],
- token
- )
- )
-
- await waitForKafkaMessages(kafkaProducer)
- await waitForExpect(async () => {
- const events = await fetchEvents(clickhouse, team.id)
- expect(events.length).toBe(1)
- const props = events[0].properties
-
- // Cost calculation: input/output/total costs from token counts + model pricing
- expect(props.$ai_input_cost_usd).toBeGreaterThan(0)
- expect(props.$ai_output_cost_usd).toBeGreaterThan(0)
- expect(props.$ai_total_cost_usd).toBeGreaterThan(0)
- expect(props.$ai_total_cost_usd).toBe(props.$ai_input_cost_usd + props.$ai_output_cost_usd)
-
- // Cost model metadata
- expect(props.$ai_model_cost_used).toBeDefined()
- expect(props.$ai_cost_model_provider).toBeDefined()
-
- // Trace property normalization: numeric IDs converted to strings
- expect(props.$ai_trace_id).toBe('12345')
- expect(props.$ai_parent_id).toBe('67890')
-
- // Model parameter extraction: promoted to top-level properties
- expect(props.$ai_temperature).toBe(0.7)
- expect(props.$ai_stream).toBe(true)
- expect(props.$ai_max_tokens).toBe(1024)
-
- // Tool call extraction: parsed from $ai_output_choices
- expect(props.$ai_tools_called).toBe('get_weather,search_docs')
- expect(props.$ai_tool_call_count).toBe(2)
- })
- }
- )
-
- testWithTeamIngester(
- 'should route $ai_trace events through AI subpipeline with trace normalization',
- {},
- async ({ ingester, team, kafkaProducer, token }) => {
- const distinctId = new UUIDT().toString()
- await ingester.handleKafkaBatch(
- createKafkaMessages(
- [
- new EventBuilder(team, distinctId)
- .withEvent('$ai_trace')
- .withProperties({
- $ai_trace_id: 'trace-abc',
- $ai_span_id: 99999,
- $ai_session_id: true,
- })
- .build(),
- ],
- token
- )
- )
-
- await waitForKafkaMessages(kafkaProducer)
- await waitForExpect(async () => {
- const events = await fetchEvents(clickhouse, team.id)
- expect(events.length).toBe(1)
- const props = events[0].properties
-
- // Trace normalization applied to all AI events
- expect(props.$ai_trace_id).toBe('trace-abc')
- expect(props.$ai_span_id).toBe('99999')
- expect(props.$ai_session_id).toBe('true')
-
- // No cost enrichment for $ai_trace events
- expect(props.$ai_input_cost_usd).toBeUndefined()
- expect(props.$ai_output_cost_usd).toBeUndefined()
- expect(props.$ai_total_cost_usd).toBeUndefined()
- })
- }
- )
})
diff --git a/nodejs/tests/ingestion/person-properties-metadata.e2e.test.ts b/nodejs/tests/ingestion/person-properties-metadata.e2e.test.ts
index f69d9b8a7b6b..9b3a1c1ac53f 100644
--- a/nodejs/tests/ingestion/person-properties-metadata.e2e.test.ts
+++ b/nodejs/tests/ingestion/person-properties-metadata.e2e.test.ts
@@ -15,7 +15,6 @@ import { ClickhouseGroupRepository } from '~/common/groups/repositories/clickhou
import { KafkaProducerWrapper } from '~/common/kafka/producer'
import { UUIDT } from '~/common/utils/utils'
import { IngestionConsumer } from '~/ingestion/ingestion-consumer'
-import { createAiEventSubpipeline } from '~/ingestion/pipelines/ai'
import { waitForExpect } from '~/tests/helpers/expectations'
import { IngestionTestInfra, createIngestionTestInfra } from '~/tests/helpers/ingestion-e2e'
import { createTestIngestionOutputs, createTestMonitoringOutputs } from '~/tests/helpers/ingestion-outputs'
@@ -185,7 +184,6 @@ const createTestWithTeamIngester = (baseConfig: Partial<PluginsServerConfig> = {
const outputs = createTestIngestionOutputs(kafkaProducer)
const ingester = new IngestionConsumer(infra.config, {
...infra,
- aiSubpipelineFactory: createAiEventSubpipeline,
hogTransformer: createHogTransformerService(infra.config, {
...infra,
monitoringOutputs: createTestMonitoringOutputs(kafkaProducer),
diff --git a/nodejs/tests/ingestion/person-updates-e2e.test.ts b/nodejs/tests/ingestion/person-updates-e2e.test.ts
index db39df2c2d21..da9b23daa1de 100644
--- a/nodejs/tests/ingestion/person-updates-e2e.test.ts
+++ b/nodejs/tests/ingestion/person-updates-e2e.test.ts
@@ -21,7 +21,6 @@ import { KafkaProducerWrapper } from '~/common/kafka/producer'
import { UUIDT } from '~/common/utils/utils'
import { PersonBatchWritingDbWriteMode } from '~/ingestion/config'
import { IngestionConsumer } from '~/ingestion/ingestion-consumer'
-import { createAiEventSubpipeline } from '~/ingestion/pipelines/ai'
import { Clickhouse } from '~/tests/helpers/clickhouse'
import { waitForExpect } from '~/tests/helpers/expectations'
import { IngestionTestInfra, createIngestionTestInfra } from '~/tests/helpers/ingestion-e2e'
@@ -238,7 +237,6 @@ describe.each(FLAG_COMBINATIONS)('Person Updates E2E ($#)', (config) => {
groupRepository: infra.groupRepository,
personRepository: infra.personRepository,
cookielessManager: infra.cookielessManager,
- aiSubpipelineFactory: createAiEventSubpipeline,
hogTransformer: createHogTransformerService(infra.config, {
geoipService: infra.geoipService,
postgres: infra.postgres,
diff --git a/nodejs/tests/ingestion/pipelines/ai/pipelines/ai-event-subpipeline.integration.test.ts b/nodejs/tests/ingestion/pipelines/ai/pipelines/ai-event-subpipeline.integration.test.ts
deleted file mode 100644
index 3d6c0099fac5..000000000000
--- a/nodejs/tests/ingestion/pipelines/ai/pipelines/ai-event-subpipeline.integration.test.ts
+++ /dev/null
@@ -1,264 +0,0 @@
-import { DateTime } from 'luxon'
-
-import { INGESTION_WARNINGS_OUTPUT } from '~/common/outputs'
-import {
- AI_EVENTS_OUTPUT,
- EVENTS_OUTPUT,
- PERSONS_OUTPUT,
- PERSON_DISTINCT_IDS_OUTPUT,
- PERSON_MERGE_EVENTS_OUTPUT,
-} from '~/common/outputs'
-import { IngestionOutputs } from '~/common/outputs/ingestion-outputs'
-import { parseJSON } from '~/common/utils/json-parse'
-import { GroupStoreForBatch } from '~/ingestion/common/groups/group-store-for-batch'
-import { PersonsStoreForBatch } from '~/ingestion/common/persons/persons-store-for-batch'
-import { newPipelineBuilder } from '~/ingestion/framework/builders'
-import { createOkContext } from '~/ingestion/framework/helpers'
-import { PipelineResultType } from '~/ingestion/framework/results'
-import {
- AiEventSubpipelineConfig,
- AiEventSubpipelineInput,
- createAiEventSubpipeline,
-} from '~/ingestion/pipelines/ai/pipelines/ai-event-subpipeline'
-import { PluginEvent } from '~/plugin-scaffold'
-import { createTestEventHeaders } from '~/tests/helpers/event-headers'
-import { createTestMessage } from '~/tests/helpers/kafka-message'
-import { createMockIngestionOutputs } from '~/tests/helpers/mock-ingestion-outputs'
-import { createTestPluginEvent } from '~/tests/helpers/plugin-event'
-import { createTestTeam } from '~/tests/helpers/team'
-import { InternalPerson, PropertyUpdateOperation } from '~/types'
-
-const team = createTestTeam()
-const message = createTestMessage()
-const headers = createTestEventHeaders()
-
-const existingPerson: InternalPerson = {
- id: '1',
- team_id: team.id,
- uuid: 'person-uuid-1',
- properties: { email: '[email protected]' },
- is_user_id: null,
- is_identified: false,
- properties_last_updated_at: {},
- properties_last_operation: { email: PropertyUpdateOperation.Set },
- created_at: DateTime.fromISO('2020-01-01T00:00:00Z'),
- version: 0,
- last_seen_at: null,
-}
-
-const mockPersonsStoreForBatch: jest.Mocked<PersonsStoreForBatch> = {
- fetchForChecking: jest.fn().mockResolvedValue(null),
- getPersonlessBatchResult: jest.fn().mockReturnValue(false),
- fetchForUpdate: jest.fn().mockResolvedValue(existingPerson),
- updatePersonWithPropertiesDiffForUpdate: jest.fn().mockResolvedValue([existingPerson, [], false]),
-} as unknown as jest.Mocked<PersonsStoreForBatch>
-
-const mockGroupStoreForBatch: jest.Mocked<GroupStoreForBatch> = {
- upsertGroup: jest.fn().mockResolvedValue(undefined),
-} as unknown as jest.Mocked<GroupStoreForBatch>
-
-function createAiEvent(overrides: Partial<PluginEvent> = {}): PluginEvent {
- return createTestPluginEvent({
- event: '$ai_generation',
- team_id: team.id,
- timestamp: '2020-02-23T02:15:00Z',
- properties: {
- $ai_model: 'gpt-4',
- $ai_provider: 'openai',
- $ai_input_tokens: 100,
- $ai_output_tokens: 50,
- ...overrides.properties,
- },
- ...overrides,
- // Restore properties after spread since overrides may have properties
- ...(overrides.properties
- ? {
- properties: {
- $ai_model: 'gpt-4',
- $ai_provider: 'openai',
- $ai_input_tokens: 100,
- $ai_output_tokens: 50,
- ...overrides.properties,
- },
- }
- : {}),
- })
-}
-
-function buildPipeline(configOverrides: Partial<AiEventSubpipelineConfig> = {}) {
- const mockOutputs = createMockIngestionOutputs<AiOutputs>()
-
- const config: AiEventSubpipelineConfig = {
- options: {
- SKIP_UPDATE_EVENT_AND_PROPERTIES_STEP: true,
- PERSON_MERGE_MOVE_DISTINCT_ID_LIMIT: 0,
- PERSON_MERGE_ASYNC_ENABLED: false,
- PERSON_MERGE_SYNC_BATCH_SIZE: 0,
- PERSON_MERGE_EVENTS_ENABLED: false,
- PERSON_MERGE_EVENTS_PARTITION_COUNT: 64,
- PERSON_MERGE_EVENTS_TEAM_ALLOWLIST: '*',
- PERSON_MERGE_FOLD_ENABLED: false,
- PERSON_MERGE_FOLD_TEAM_ALLOWLIST: '*',
- PERSON_MERGE_ALWAYS_V1_TEAM_ALLOWLIST: '',
- PERSONLESS_WRITES_DISABLED_TEAMS: '',
- PERSON_JSONB_SIZE_ESTIMATE_ENABLE: 0,
- PERSON_PROPERTIES_UPDATE_ALL: false,
- FLAG_CALLED_PERSONLESS_DEFAULT_TEAMS: '*',
- EXPERIMENT_EXPOSURE_DUPLICATION_TEAMS: '',
- },
- outputs: mockOutputs,
- teamManager: {
- setTeamIngestedEvent: jest.fn().mockResolvedValue(undefined),
- } as any,
- groupTypeManager: {
- fetchGroupTypeIndex: jest.fn().mockResolvedValue(0),
- } as any,
- hogTransformer: {
- transformEventAndProduceMessages: (event: PluginEvent) => Promise.resolve({ event, invocationResults: [] }),
- } as any,
- topHog: (step) => step,
- ...configOverrides,
- }
-
- return {
- pipeline: createAiEventSubpipeline(newPipelineBuilder<AiEventSubpipelineInput>(), config).build(),
- mockOutputs,
- config,
- }
-}
-
-function createInput(event: PluginEvent): AiEventSubpipelineInput {
- return {
- message,
- event,
- team,
- headers,
- personsStoreForBatch: mockPersonsStoreForBatch,
- groupStoreForBatch: mockGroupStoreForBatch,
- }
-}
-
-type AiOutputs =
- | typeof EVENTS_OUTPUT
- | typeof AI_EVENTS_OUTPUT
- | typeof INGESTION_WARNINGS_OUTPUT
- | typeof PERSONS_OUTPUT
- | typeof PERSON_DISTINCT_IDS_OUTPUT
- | typeof PERSON_MERGE_EVENTS_OUTPUT
-
-function getProduceCall(mockOutputs: jest.Mocked<IngestionOutputs<AiOutputs>>, output: AiOutputs = EVENTS_OUTPUT) {
- const call = mockOutputs.produce.mock.calls.find(([outputName]) => outputName === output)
- if (!call) {
- throw new Error(`No produce call for output ${output}`)
- }
- const [outputName, message] = call
- const event = parseJSON(message.value!.toString())
- return {
- outputName: outputName as string,
- key: message.key as string,
- headers: message.headers as Record<string, string>,
- event,
- properties: parseJSON(event.properties) as Record<string, unknown>,
- }
-}
-
-describe('AI event subpipeline integration', () => {
- it('exercises all steps: hog transform → normalize → AI enrich → person → prepare → emit', async () => {
- const event = createAiEvent({
- properties: {
- $ai_model: 'gpt-4',
- $ai_provider: 'openai',
- $ai_input_tokens: 1000,
- $ai_output_tokens: 500,
- $ai_trace_id: 12345,
- // $set triggers person property handling
- $set: { plan: 'enterprise' },
- // $groups triggers group property lookup in prepareEvent
- $groups: { company: 'posthog' },
- },
- })
-
- const { pipeline, mockOutputs } = buildPipeline({
- // Hog transform adds a property with un-normalized casing
- hogTransformer: {
- transformEventAndProduceMessages: (e: PluginEvent) =>
- Promise.resolve({
- event: { ...e, properties: { ...e.properties, $hog_transformed: true } },
- invocationResults: [{}],
- }),
- } as any,
- })
-
- const result = await pipeline.process(createOkContext(createInput(event), {}))
- expect(result.result.type).toBe(PipelineResultType.OK)
-
- const { outputName, event: produced, properties } = getProduceCall(mockOutputs)
-
- // Emit step: correct output
- expect(outputName).toBe(EVENTS_OUTPUT)
-
- // Split step: AI events are unconditionally duplicated to the dedicated ai_events output
- expect(mockOutputs.produce).toHaveBeenCalledTimes(2)
- expect(getProduceCall(mockOutputs, AI_EVENTS_OUTPUT).event.event).toBe('$ai_generation')
-
- // Event identity preserved
- expect(produced.event).toBe('$ai_generation')
- expect(produced.team_id).toBe(team.id)
- expect(produced.distinct_id).toBe(event.distinct_id)
-
- // Hog transform step: property was added
- expect(properties.$hog_transformed).toBe(true)
-
- // Normalize step: $process_person_profile defaults to true (person_mode=full)
- expect(produced.person_mode).toBe('full')
-
- // AI enrich step: cost calculated, trace ID normalized to string
- expect(properties.$ai_input_cost_usd).toBeGreaterThan(0)
- expect(properties.$ai_output_cost_usd).toBeGreaterThan(0)
- expect(typeof properties.$ai_total_cost_usd).toBe('number')
- expect(properties.$ai_trace_id).toBe('12345')
-
- // Person step: person resolved from personsStore
- expect(produced.person_id).toBe(existingPerson.uuid)
- // $set person properties merged onto the event
- expect(parseJSON(produced.person_properties)).toMatchObject({ email: '[email protected]', plan: 'enterprise' })
-
- // Prepare step: group resolved via groupTypeManager
- expect(properties.$group_0).toBe('posthog')
- })
-
- it('personless: $process_person_profile=false produces event with propertyless person_mode', async () => {
- const event = createAiEvent({
- properties: {
- $process_person_profile: false,
- },
- })
-
- const { pipeline, mockOutputs } = buildPipeline()
- const result = await pipeline.process(createOkContext(createInput(event), {}))
- expect(result.result.type).toBe(PipelineResultType.OK)
-
- const { event: produced, properties } = getProduceCall(mockOutputs)
-
- // Personless: person_mode is propertyless, person properties are empty
- expect(produced.person_mode).toBe('propertyless')
- expect(parseJSON(produced.person_properties)).toEqual({})
-
- // AI enrichment still applied
- expect(properties.$ai_input_cost_usd).toBeDefined()
- })
-
- it('hog transform dropping event short-circuits the pipeline', async () => {
- const event = createAiEvent()
-
- const { pipeline, mockOutputs } = buildPipeline({
- hogTransformer: {
- transformEventAndProduceMessages: () => Promise.resolve({ event: null, invocationResults: [{}] }),
- } as any,
- })
-
- const result = await pipeline.process(createOkContext(createInput(event), {}))
- expect(result.result.type).toBe(PipelineResultType.DROP)
- expect(mockOutputs.produce).not.toHaveBeenCalled()
- })
-})
diff --git a/posthog/hogql_queries/ai/ai_table_resolver.py b/posthog/hogql_queries/ai/ai_table_resolver.py
index f5f31cc02123..7149417b2346 100644
--- a/posthog/hogql_queries/ai/ai_table_resolver.py
+++ b/posthog/hogql_queries/ai/ai_table_resolver.py
@@ -164,7 +164,7 @@ def query_ai_events(
# 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
+# The ingestion list (nodejs/src/ingestion/pipelines/ai/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.
diff --git a/rust/capture/src/v0_request.rs b/rust/capture/src/v0_request.rs
index 77f3f8b5e4c5..a3bec95d8706 100644
--- a/rust/capture/src/v0_request.rs
+++ b/rust/capture/src/v0_request.rs
@@ -185,8 +185,8 @@ pub enum DataType {
}
/// Event names diverted to the dedicated AI lane. Must stay in sync with the
-/// ingestion AI subpipeline's allowlist (`AI_EVENT_TYPES` in
-/// `nodejs/src/ingestion/common/subpipelines/ai-event-types.ts`), which DLQs
+/// AI lane's allowlist (`AI_EVENT_TYPES` in
+/// `nodejs/src/ingestion/pipelines/ai/ai-event-types.ts`), which DLQs
/// anything it receives that isn't on the list. Matching on the `$ai_` prefix
/// instead would divert prefixed-but-unlisted names (e.g. `$ai_call`) into the
/// AI topic only for the ingestion pipeline to DLQ them.