: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
feat(ingestion): add team-gated personless-table write and read stop (#75907)
José Sequeirae5353e3ee94c
diff --git a/nodejs/src/ingestion/common/persons/person-context.ts b/nodejs/src/ingestion/common/persons/person-context.tsindex 2c6df8b39150..2106a84e64e0 100644--- a/nodejs/src/ingestion/common/persons/person-context.ts+++ b/nodejs/src/ingestion/common/persons/person-context.ts@@ -39,6 +39,21 @@ export type MergeEventsConfig = {isTeamEnabled: ValueMatcher<number>}+/** Per-team gates for the personless-table removal rollout (steps 2-4 of the RFC). */+export type PersonlessRolloutConfig = {+ /**+ * Always-v1: merge-added distinct id mappings get version 1 unconditionally (always writing a+ * ClickHouse override) instead of consulting posthog_personlessdistinctid.+ */+ mergeAlwaysV1: boolean+ /**+ * Stop-reading/stop-writing: merges skip the posthog_personlessdistinctid upserts entirely.+ * Forces mergeAlwaysV1 (normalized in the PersonContext constructor): without the upserts the+ * table has gaps for this team, so a version decision must never consult it again.+ */+ writesDisabled: boolean+}+/*** Lightweight data holder containing all the context needed for person processing.* This replaces the previous PersonState class which mixed data and business logic.@@ -64,15 +79,18 @@ export class PersonContext {partitionCount: 64,isTeamEnabled: () => false,},- /**- * Always-v1 rollout of the personless-table removal: when true, merge-added distinct id- * mappings get version 1 unconditionally instead of consulting posthog_personlessdistinctid.- */- public readonly mergeAlwaysV1: boolean = false,+ public readonly personlessRollout: PersonlessRolloutConfig = {+ mergeAlwaysV1: false,+ writesDisabled: false,+ },/** Fold plan shared by this event's consecutive $identify run; see person-merge-fold.ts. */public readonly mergeFoldPlan?: MergeFoldPlan) {this.eventProperties = event.properties!+ this.personlessRollout = {+ mergeAlwaysV1: personlessRollout.mergeAlwaysV1 || personlessRollout.writesDisabled,+ writesDisabled: personlessRollout.writesDisabled,+ }}async produceMessages(messages: PersonMessage[]): Promise<void> {diff --git a/nodejs/src/ingestion/common/persons/person-merge-service.ts b/nodejs/src/ingestion/common/persons/person-merge-service.tsindex 7ab2834294d0..8084e4101e10 100644--- a/nodejs/src/ingestion/common/persons/person-merge-service.ts+++ b/nodejs/src/ingestion/common/persons/person-merge-service.ts@@ -267,11 +267,10 @@ export class PersonMergeService {this.discardOverrideCounts()const result = await this.context.personStore.inTransaction('mergeDistinctIds-OneExists', async (tx) => {// See comment above about `distinctIdVersion`- const insertedDistinctId = await tx.addPersonlessDistinctIdForMerge(- this.context.team.id,- distinctIdToAdd- )- const distinctIdVersion = this.context.mergeAlwaysV1 || !insertedDistinctId ? 1 : 0+ const insertedDistinctId = this.context.personlessRollout.writesDisabled+ ? false+ : await tx.addPersonlessDistinctIdForMerge(this.context.team.id, distinctIdToAdd)+ const distinctIdVersion = this.context.personlessRollout.mergeAlwaysV1 || !insertedDistinctId ? 1 : 0this.recordOverrideCount('oneExists', distinctIdVersion > 0)const kafkaMessages = await tx.addDistinctId(existingPerson, distinctIdToAdd, distinctIdVersion)@@ -304,11 +303,14 @@ export class PersonMergeService {this.discardOverrideCounts()const result = await this.context.personStore.inTransaction('mergeDistinctIds-NeitherExist', async (tx) => {- // See comment above about `distinctIdVersion`- const insertedDistinctId1 = await tx.addPersonlessDistinctIdForMerge(this.context.team.id, distinctId1)-- // See comment above about `distinctIdVersion`- const insertedDistinctId2 = await tx.addPersonlessDistinctIdForMerge(this.context.team.id, distinctId2)+ // See comment above about `distinctIdVersion`. With personless writes disabled the+ // upserts are skipped; the always-v1 branch below never reads the results.+ const insertedDistinctId1 = this.context.personlessRollout.writesDisabled+ ? false+ : await tx.addPersonlessDistinctIdForMerge(this.context.team.id, distinctId1)+ const insertedDistinctId2 = this.context.personlessRollout.writesDisabled+ ? false+ : await tx.addPersonlessDistinctIdForMerge(this.context.team.id, distinctId2)// `createPerson` uses the first Distinct ID provided to generate the Person// UUID. That means the first Distinct ID definitely doesn't need an override,@@ -317,7 +319,7 @@ export class PersonMergeService {// need to actually write an override. (But mostly we're being verbose for// documentation purposes)let distinctId2Version = 0- if (this.context.mergeAlwaysV1) {+ if (this.context.personlessRollout.mergeAlwaysV1) {// The upsert results are not consulted: the second Distinct ID always gets an// override, and no swap is needed since the first one derives the Person UUID.distinctId2Version = 1@@ -614,8 +616,10 @@ export class PersonMergeService {const addMessages: PersonMessage[] = []for (const pair of missingPairs) {// See mergeDistinctIds for the personless distinctIdVersion logic.- const inserted = await tx.addPersonlessDistinctIdForMerge(teamId, pair.anonDistinctId)- const distinctIdVersion = this.context.mergeAlwaysV1 || !inserted ? 1 : 0+ const inserted = this.context.personlessRollout.writesDisabled+ ? false+ : await tx.addPersonlessDistinctIdForMerge(teamId, pair.anonDistinctId)+ const distinctIdVersion = this.context.personlessRollout.mergeAlwaysV1 || !inserted ? 1 : 0this.recordOverrideCount('fold', distinctIdVersion > 0)addMessages.push(...(await tx.addDistinctId(person, pair.anonDistinctId, distinctIdVersion)))}diff --git a/nodejs/src/ingestion/common/steps/event-processing/event-pipeline-options.ts b/nodejs/src/ingestion/common/steps/event-processing/event-pipeline-options.tsindex e11b7bdc2c42..58ac41601b41 100644--- a/nodejs/src/ingestion/common/steps/event-processing/event-pipeline-options.ts+++ b/nodejs/src/ingestion/common/steps/event-processing/event-pipeline-options.ts@@ -10,6 +10,8 @@ export interface EventPipelineRunnerOptions {PERSON_MERGE_FOLD_TEAM_ALLOWLIST: string/** Teams whose merge-added distinct id mappings always get version 1: '*' for all, '' to disable, or comma-separated team IDs */PERSON_MERGE_ALWAYS_V1_TEAM_ALLOWLIST: string+ /** Teams with personless-table writes and is_merged reads disabled (implies always-v1): '*' for all, '' to disable, or comma-separated team IDs */+ PERSONLESS_WRITES_DISABLED_TEAMS: stringPERSON_JSONB_SIZE_ESTIMATE_ENABLE: numberPERSON_PROPERTIES_UPDATE_ALL: boolean/** Teams whose $feature_flag_called events default to personless: '*' for all, '' to disable, or comma-separated team IDs */diff --git a/nodejs/src/ingestion/common/steps/event-processing/process-personless-step.test.ts b/nodejs/src/ingestion/common/steps/event-processing/process-personless-step.test.tsindex eac3ee6cf6b4..902708344cc7 100644--- a/nodejs/src/ingestion/common/steps/event-processing/process-personless-step.test.ts+++ b/nodejs/src/ingestion/common/steps/event-processing/process-personless-step.test.ts@@ -472,6 +472,56 @@ describe('createProcessPersonlessStep', () => {})})+ describe('personless writes disabled', () => {+ const buildGatedStep = () => createProcessPersonlessStep('*', '*')++ it('ignores the is_merged race hint and stays personless', async () => {+ const personUuid = new UUIDT().toString()+ const person = await createPerson(infra, timestamp, {}, {}, {}, teamId, null, false, personUuid, {+ distinctId: 'merge-target',+ })++ // A concurrent merge left an is_merged hint; with the gate on it is never read, so the+ // event stays on the implied person id and the always-written override corrects it later.+ jest.spyOn(personsStore, 'getPersonlessBatchResult').mockReturnValue(true)+ const fetchForUpdateSpy = jest.spyOn(personsStore, 'fetchForUpdate').mockResolvedValue(person)++ const step = buildGatedStep()+ const result = await step(createInput())++ expect(result.type).toBe(PipelineResultType.OK)+ if (isOkResult(result)) {+ const returnedPerson = result.value.personlessPerson!+ expect(returnedPerson.uuid).not.toBe(personUuid)+ expect(returnedPerson.created_at.toISO()).toBe('1970-01-01T00:00:05.000Z')+ }+ expect(fetchForUpdateSpy).not.toHaveBeenCalled()+ })++ it('defaults $feature_flag_called to personless without recording the distinct ID', async () => {+ const addPersonlessDistinctIdSpy = jest.spyOn(personsStore, 'addPersonlessDistinctId')++ const step = buildGatedStep()+ const result = await step(+ createInput({+ processPerson: true,+ normalizedEvent: {+ ...pluginEvent,+ event: '$feature_flag_called',+ properties: { $feature_flag: 'new-homepage', $feature_flag_response: 'test' },+ },+ })+ )++ expect(result.type).toBe(PipelineResultType.OK)+ if (isOkResult(result)) {+ expect(result.value.processPerson).toBe(false)+ expect(result.value.personlessPerson).toBeDefined()+ }+ expect(addPersonlessDistinctIdSpy).not.toHaveBeenCalled()+ })+ })+describe('force_upgrade logic', () => {it('sets force_upgrade=true when event timestamp > person.created_at + 1 minute', async () => {const personUuid = new UUIDT().toString()diff --git a/nodejs/src/ingestion/common/steps/event-processing/process-personless-step.ts b/nodejs/src/ingestion/common/steps/event-processing/process-personless-step.tsindex e51fdda722fe..29ab8c0e5499 100644--- a/nodejs/src/ingestion/common/steps/event-processing/process-personless-step.ts+++ b/nodejs/src/ingestion/common/steps/event-processing/process-personless-step.ts@@ -1,5 +1,6 @@import { DateTime } from 'luxon'+import { buildIntegerMatcher } from '~/common/config/config'import { normalizeProcessPerson } from '~/common/utils/event'import {buildFlagCalledPersonlessMatcher,@@ -47,9 +48,11 @@ export type ProcessPersonlessOutput = {* 4. Returns person (real or fake) with potential force_upgrade flag*/export function createProcessPersonlessStep<TInput extends ProcessPersonlessInput>(- flagCalledPersonlessDefaultTeams: string = DEFAULT_FLAG_CALLED_PERSONLESS_DEFAULT_TEAMS+ flagCalledPersonlessDefaultTeams: string = DEFAULT_FLAG_CALLED_PERSONLESS_DEFAULT_TEAMS,+ personlessWritesDisabledTeams: string = ''): ProcessingStep<TInput, TInput & ProcessPersonlessOutput> {const flagCalledDefaultEnabledForTeam = buildFlagCalledPersonlessMatcher(flagCalledPersonlessDefaultTeams)+ const writesDisabledForTeam = buildIntegerMatcher(personlessWritesDisabledTeams, true)return async function processPersonlessStep(input: TInput@@ -66,7 +69,11 @@ export function createProcessPersonlessStep<TInput extends ProcessPersonlessInpureturn ok(input)}- return await applyFeatureFlagCalledPersonlessDefault(input, input.personsStoreForBatch)+ return await applyFeatureFlagCalledPersonlessDefault(+ input,+ input.personsStoreForBatch,+ writesDisabledForTeam(input.team.id)+ )}const { normalizedEvent, team, timestamp, forceDisablePersonProcessing, personsStoreForBatch } = input@@ -79,10 +86,13 @@ export function createProcessPersonlessStep<TInput extends ProcessPersonlessInpu// Check if a real person exists for this distinct_id (from prefetch cache)let existingPerson = await personsStoreForBatch.fetchForChecking(team.id, distinctId)- if (!existingPerson) {+ if (!existingPerson && !writesDisabledForTeam(team.id)) {// Check if batch insert found this distinct_id was merged// The chunk step (processPersonlessDistinctIdsChunkStep) already did the INSERT- // and stored is_merged=true results in the personsStore cache+ // and stored is_merged=true results in the personsStore cache.+ // With personless writes disabled (stop-reading rollout) the hint is skipped: an+ // event racing a merge stays propertyless and the always-written override+ // re-points it instead.const personIsMerged = personsStoreForBatch.getPersonlessBatchResult(team.id, distinctId)if (personIsMerged) {@@ -124,14 +134,15 @@ export function createProcessPersonlessStep<TInput extends ProcessPersonlessInpu*/async function applyFeatureFlagCalledPersonlessDefault<TInput extends ProcessPersonlessInput>(input: TInput,- personsStore: PersonsStoreForBatch+ personsStore: PersonsStoreForBatch,+ personlessWritesDisabled: boolean): Promise<PipelineResult<TInput & ProcessPersonlessOutput>> {const { normalizedEvent, team } = inputconst distinctId = normalizedEvent.distinct_idlet existingPerson = await personsStore.fetchForChecking(team.id, distinctId)- if (!existingPerson) {+ if (!existingPerson && !personlessWritesDisabled) {let personIsMerged = personsStore.getPersonlessBatchResult(team.id, distinctId)if (personIsMerged === undefined) {diff --git a/nodejs/src/ingestion/common/steps/event-processing/process-persons-step.ts b/nodejs/src/ingestion/common/steps/event-processing/process-persons-step.tsindex 992aebe59818..fbcced96ea6d 100644--- a/nodejs/src/ingestion/common/steps/event-processing/process-persons-step.ts+++ b/nodejs/src/ingestion/common/steps/event-processing/process-persons-step.ts@@ -46,6 +46,7 @@ export function createProcessPersonsStep<TInput extends ProcessPersonsInput>(isTeamEnabled: buildIntegerMatcher(options.PERSON_MERGE_EVENTS_TEAM_ALLOWLIST, true),}const isMergeAlwaysV1Team = buildIntegerMatcher(options.PERSON_MERGE_ALWAYS_V1_TEAM_ALLOWLIST, true)+ const isPersonlessWritesDisabledTeam = buildIntegerMatcher(options.PERSONLESS_WRITES_DISABLED_TEAMS, true)return async function processPersonsStep(input: TInput@@ -71,7 +72,10 @@ export function createProcessPersonsStep<TInput extends ProcessPersonsInput>(options.PERSON_PROPERTIES_UPDATE_ALL,shouldUpdateLastSeenAt,mergeEventsConfig,- isMergeAlwaysV1Team(team.id),+ {+ mergeAlwaysV1: isMergeAlwaysV1Team(team.id),+ writesDisabled: isPersonlessWritesDisabledTeam(team.id),+ },input.mergeFold.type === 'planned' ? input.mergeFold.plan : undefined)diff --git a/nodejs/src/ingestion/config.ts b/nodejs/src/ingestion/config.tsindex c5a857d10a47..bd9159be7aa0 100644--- a/nodejs/src/ingestion/config.ts+++ b/nodejs/src/ingestion/config.ts@@ -173,6 +173,11 @@ export type IngestionConsumerConfig = {// consulting posthog_personlessdistinctid for the version-0 optimization. Comma-separated team// IDs, or '*' for all teams; empty means no teams.PERSON_MERGE_ALWAYS_V1_TEAM_ALLOWLIST: string+ // Steps 3+4 of the personless-table removal RFC: for these teams, stop writing+ // posthog_personlessdistinctid (chunk inserts, single-row fallback, merge upserts) and stop+ // reading the is_merged race hint. Implies always-v1 merge versioning for the team, so the+ // table's absence can never orphan events. Comma-separated team IDs, or '*' for all teams.+ PERSONLESS_WRITES_DISABLED_TEAMS: string// Group batch writing configGROUP_BATCH_WRITING_USE_BATCH_UPDATES: boolean@@ -316,6 +321,7 @@ export function getDefaultIngestionConsumerConfig(): IngestionConsumerConfig {PERSON_MERGE_FOLD_ENABLED: false,PERSON_MERGE_FOLD_TEAM_ALLOWLIST: '*',PERSON_MERGE_ALWAYS_V1_TEAM_ALLOWLIST: '',+ PERSONLESS_WRITES_DISABLED_TEAMS: '',// Group batch writing configGROUP_BATCH_WRITING_USE_BATCH_UPDATES: true,diff --git a/nodejs/src/ingestion/ingestion-consumer.ts b/nodejs/src/ingestion/ingestion-consumer.tsindex 4e37231087e0..d4037b2b5a3c 100644--- a/nodejs/src/ingestion/ingestion-consumer.ts+++ b/nodejs/src/ingestion/ingestion-consumer.ts@@ -292,6 +292,7 @@ export class IngestionConsumer {PERSON_MERGE_FOLD_ENABLED: this.config.PERSON_MERGE_FOLD_ENABLED,PERSON_MERGE_FOLD_TEAM_ALLOWLIST: this.config.PERSON_MERGE_FOLD_TEAM_ALLOWLIST,PERSON_MERGE_ALWAYS_V1_TEAM_ALLOWLIST: this.config.PERSON_MERGE_ALWAYS_V1_TEAM_ALLOWLIST,+ PERSONLESS_WRITES_DISABLED_TEAMS: this.config.PERSONLESS_WRITES_DISABLED_TEAMS,PERSON_JSONB_SIZE_ESTIMATE_ENABLE: this.config.PERSON_JSONB_SIZE_ESTIMATE_ENABLE,PERSON_PROPERTIES_UPDATE_ALL: this.config.PERSON_PROPERTIES_UPDATE_ALL,FLAG_CALLED_PERSONLESS_DEFAULT_TEAMS: this.config.FLAG_CALLED_PERSONLESS_DEFAULT_TEAMS,diff --git a/nodejs/src/ingestion/pipelines/ai/pipelines/ai-event-subpipeline.ts b/nodejs/src/ingestion/pipelines/ai/pipelines/ai-event-subpipeline.tsindex 84b67cf08500..7697a45fec05 100644--- a/nodejs/src/ingestion/pipelines/ai/pipelines/ai-event-subpipeline.ts+++ b/nodejs/src/ingestion/pipelines/ai/pipelines/ai-event-subpipeline.ts@@ -68,9 +68,15 @@ export function createAiEventSubpipeline<TInput extends AiEventSubpipelineInput,).pipe(createNormalizeEventStep()).pipe(createProcessAiEventStep())- .pipe(createProcessPersonlessStep(options.FLAG_CALLED_PERSONLESS_DEFAULT_TEAMS), {- retry: { tries: 5, sleepMs: 100, name: 'process_personless' },- })+ .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 thediff --git a/nodejs/src/ingestion/pipelines/analytics/event-subpipeline.ts b/nodejs/src/ingestion/pipelines/analytics/event-subpipeline.tsindex 9cc15482f921..8d2ef9800631 100644--- a/nodejs/src/ingestion/pipelines/analytics/event-subpipeline.ts+++ b/nodejs/src/ingestion/pipelines/analytics/event-subpipeline.ts@@ -108,9 +108,15 @@ export function createEventSubpipeline<TInput extends EventSubpipelineInput & Wi{ retry: { tries: 5, sleepMs: 100, name: 'hog_transform_event' } }).pipe(createNormalizeEventStep())- .pipe(createProcessPersonlessStep(options.FLAG_CALLED_PERSONLESS_DEFAULT_TEAMS), {- retry: { tries: 5, sleepMs: 100, name: 'process_personless' },- })+ .pipe(+ createProcessPersonlessStep(+ options.FLAG_CALLED_PERSONLESS_DEFAULT_TEAMS,+ options.PERSONLESS_WRITES_DISABLED_TEAMS+ ),+ {+ retry: { tries: 5, sleepMs: 100, name: 'process_personless' },+ }+ ).pipe(topHog(createProcessPersonsStep(options, outputs), [timer('process_persons_time', (input) => ({diff --git a/nodejs/src/ingestion/pipelines/analytics/joined-ingestion-pipeline.ts b/nodejs/src/ingestion/pipelines/analytics/joined-ingestion-pipeline.tsindex 82542aa2fcfc..0dddcb76e0e4 100644--- a/nodejs/src/ingestion/pipelines/analytics/joined-ingestion-pipeline.ts+++ b/nodejs/src/ingestion/pipelines/analytics/joined-ingestion-pipeline.ts@@ -168,6 +168,7 @@ export function createJoinedIngestionPipeline<groupsPrefetchEnabled,groupTypeManager,flagCalledPersonlessDefaultTeams: perDistinctIdOptions.FLAG_CALLED_PERSONLESS_DEFAULT_TEAMS,+ personlessWritesDisabledTeams: perDistinctIdOptions.PERSONLESS_WRITES_DISABLED_TEAMS,hogTransformer,cdpHogWatcherSampleRate,}diff --git a/nodejs/src/ingestion/pipelines/analytics/post-team-preprocessing-subpipeline.ts b/nodejs/src/ingestion/pipelines/analytics/post-team-preprocessing-subpipeline.tsindex 82ecb3b0c572..6227a0091e00 100644--- a/nodejs/src/ingestion/pipelines/analytics/post-team-preprocessing-subpipeline.ts+++ b/nodejs/src/ingestion/pipelines/analytics/post-team-preprocessing-subpipeline.ts@@ -55,6 +55,7 @@ export interface PostTeamPreprocessingSubpipelineConfig {groupsPrefetchEnabled: booleangroupTypeManager: GroupTypeManagerflagCalledPersonlessDefaultTeams: string+ personlessWritesDisabledTeams: stringhogTransformer: HogTransformercdpHogWatcherSampleRate: number}@@ -83,6 +84,7 @@ export function createPostTeamPreprocessingSubpipeline<groupsPrefetchEnabled,groupTypeManager,flagCalledPersonlessDefaultTeams,+ personlessWritesDisabledTeams,hogTransformer,cdpHogWatcherSampleRate,} = config@@ -128,7 +130,11 @@ export function createPostTeamPreprocessingSubpipeline<// This step awaits its DB write, so retry transient persons-Postgres failures// (e.g. PgBouncer scale-down) instead of letting them crash the consumer loop..pipeChunk(- processPersonlessDistinctIdsChunkStep(personsPrefetchEnabled, flagCalledPersonlessDefaultTeams),+ processPersonlessDistinctIdsChunkStep(+ personsPrefetchEnabled,+ flagCalledPersonlessDefaultTeams,+ personlessWritesDisabledTeams+ ),{retry: {tries: 5,diff --git a/nodejs/src/ingestion/pipelines/analytics/steps/processPersonlessDistinctIdsChunkStep.test.ts b/nodejs/src/ingestion/pipelines/analytics/steps/processPersonlessDistinctIdsChunkStep.test.tsindex 2c63a6a66d77..1f946d83f48c 100644--- a/nodejs/src/ingestion/pipelines/analytics/steps/processPersonlessDistinctIdsChunkStep.test.ts+++ b/nodejs/src/ingestion/pipelines/analytics/steps/processPersonlessDistinctIdsChunkStep.test.ts@@ -91,6 +91,19 @@ describe('processPersonlessDistinctIdsChunkStep', () => {])})+ it('should skip inserts for teams with personless writes disabled', async () => {+ const gatedTeam = createTestTeam({ id: 42 })+ const step = processPersonlessDistinctIdsChunkStep(true, '', String(gatedTeam.id))+ const events = [createInput('user-1', false, {}, gatedTeam), createInput('user-2', false)]++ const results = await step(events)++ expect(results).toHaveLength(2)+ expect(mockPersonsStore.processPersonlessDistinctIdsBatch).toHaveBeenCalledWith([+ { teamId: team.id, distinctId: 'user-2' },+ ])+ })+it('should not call batch insert when no personless events', async () => {const step = processPersonlessDistinctIdsChunkStep(true)const events = [createInput('user-1', true), createInput('user-2')]diff --git a/nodejs/src/ingestion/pipelines/analytics/steps/processPersonlessDistinctIdsChunkStep.ts b/nodejs/src/ingestion/pipelines/analytics/steps/processPersonlessDistinctIdsChunkStep.tsindex da32f58b8abe..7737b250b065 100644--- a/nodejs/src/ingestion/pipelines/analytics/steps/processPersonlessDistinctIdsChunkStep.ts+++ b/nodejs/src/ingestion/pipelines/analytics/steps/processPersonlessDistinctIdsChunkStep.ts@@ -1,3 +1,4 @@+import { buildIntegerMatcher } from '~/common/config/config'import {buildFlagCalledPersonlessMatcher,isFlagCalledPersonlessCandidate,@@ -42,9 +43,11 @@ type PersonlessSource = 'batch' | 'flag_called'*/export function processPersonlessDistinctIdsChunkStep<T extends ProcessPersonlessDistinctIdsChunkStepInput>(enabled: boolean,- flagCalledPersonlessDefaultTeams: string = DEFAULT_FLAG_CALLED_PERSONLESS_DEFAULT_TEAMS+ flagCalledPersonlessDefaultTeams: string = DEFAULT_FLAG_CALLED_PERSONLESS_DEFAULT_TEAMS,+ personlessWritesDisabledTeams: string = '') {const flagCalledDefaultEnabledForTeam = buildFlagCalledPersonlessMatcher(flagCalledPersonlessDefaultTeams)+ const writesDisabledForTeam = buildIntegerMatcher(personlessWritesDisabledTeams, true)return async function processPersonlessDistinctIdsChunkStep(events: T[]): Promise<PipelineResult<T>[]> {if (enabled) {@@ -57,6 +60,11 @@ export function processPersonlessDistinctIdsChunkStep<T extends ProcessPersonlesconst cacheMisses: Record<PersonlessSource, number> = { batch: 0, flag_called: 0 }for (const e of events) {+ // Personless-table writes are disabled for this team (stop-writing rollout);+ // the event still goes personless, just without the bookkeeping row.+ if (writesDisabledForTeam(e.team.id)) {+ continue+ }const source = personlessSource(e, flagCalledDefaultEnabledForTeam)if (source === null) {continuediff --git a/nodejs/src/servers/ingestion-api-server.ts b/nodejs/src/servers/ingestion-api-server.tsindex e7a5dcc1b9fe..c30e39c5cfd3 100644--- a/nodejs/src/servers/ingestion-api-server.ts+++ b/nodejs/src/servers/ingestion-api-server.ts@@ -398,6 +398,7 @@ export class IngestionApiServer implements NodeServer {PERSON_MERGE_FOLD_ENABLED: this.config.PERSON_MERGE_FOLD_ENABLED,PERSON_MERGE_FOLD_TEAM_ALLOWLIST: this.config.PERSON_MERGE_FOLD_TEAM_ALLOWLIST,PERSON_MERGE_ALWAYS_V1_TEAM_ALLOWLIST: this.config.PERSON_MERGE_ALWAYS_V1_TEAM_ALLOWLIST,+ PERSONLESS_WRITES_DISABLED_TEAMS: this.config.PERSONLESS_WRITES_DISABLED_TEAMS,PERSON_JSONB_SIZE_ESTIMATE_ENABLE: this.config.PERSON_JSONB_SIZE_ESTIMATE_ENABLE,PERSON_PROPERTIES_UPDATE_ALL: this.config.PERSON_PROPERTIES_UPDATE_ALL,FLAG_CALLED_PERSONLESS_DEFAULT_TEAMS: this.config.FLAG_CALLED_PERSONLESS_DEFAULT_TEAMS,diff --git a/nodejs/tests/ingestion/common/steps/event-processing/process-persons-step.integration.test.ts b/nodejs/tests/ingestion/common/steps/event-processing/process-persons-step.integration.test.tsindex 495741a6e196..3b46a58a9490 100644--- a/nodejs/tests/ingestion/common/steps/event-processing/process-persons-step.integration.test.ts+++ b/nodejs/tests/ingestion/common/steps/event-processing/process-persons-step.integration.test.ts@@ -55,6 +55,7 @@ describe('createProcessPersonsStep', () => {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: '*',@@ -417,7 +418,7 @@ describe('createProcessPersonsStep', () => {}})- describe('always-v1 team allowlist', () => {+ describe('personless-table removal rollout gates', () => {function identify(anonDistinctId: string, targetDistinctId: string): PluginEvent {return {...pluginEvent,@@ -428,11 +429,8 @@ describe('createProcessPersonsStep', () => {}}- async function runIdentify(event: PluginEvent, allowlist: string): Promise<void> {- const step = createProcessPersonsStep(- { ...options, PERSON_MERGE_ALWAYS_V1_TEAM_ALLOWLIST: allowlist },- personOutputs- )+ async function runIdentify(event: PluginEvent, overrides: Partial<EventPipelineRunnerOptions>): Promise<void> {+ const step = createProcessPersonsStep({ ...options, ...overrides }, personOutputs)const result = await step(createInput({ normalizedEvent: event, timestamp: DateTime.fromISO(event.timestamp!) }))@@ -454,20 +452,43 @@ describe('createProcessPersonsStep', () => {await createPersonWithDistinctIds('user-1')// Neither anon id has personless history, so without the gate both would get version 0.- await runIdentify(identify('anon-gated', 'user-1'), `${teamId}`)- await runIdentify(identify('anon-ungated', 'user-1'), `${teamId + 1}`)+ await runIdentify(identify('anon-gated', 'user-1'), {+ PERSON_MERGE_ALWAYS_V1_TEAM_ALLOWLIST: `${teamId}`,+ })+ await runIdentify(identify('anon-ungated', 'user-1'), {+ PERSON_MERGE_ALWAYS_V1_TEAM_ALLOWLIST: `${teamId + 1}`,+ })expect(await versionOf('anon-gated')).toBe(1)expect(await versionOf('anon-ungated')).toBe(0)})it('gives the non-primary distinct id version 1 when neither points at a person', async () => {- await runIdentify(identify('anon-new', 'user-new'), '*')+ await runIdentify(identify('anon-new', 'user-new'), { PERSON_MERGE_ALWAYS_V1_TEAM_ALLOWLIST: '*' })// The event distinct id derives the person uuid, so it stays at version 0.expect(await versionOf('user-new')).toBe(0)expect(await versionOf('anon-new')).toBe(1)})++ it('skips personless bookkeeping but still writes version 1 when writes are disabled', async () => {+ await createPersonWithDistinctIds('user-2')++ // The always-v1 allowlist is empty: writes-disabled alone must force version 1,+ // since without the bookkeeping row a table consult would pick version 0.+ await runIdentify(identify('anon-nowrites', 'user-2'), {+ PERSONLESS_WRITES_DISABLED_TEAMS: `${teamId}`,+ })++ expect(await versionOf('anon-nowrites')).toBe(1)+ const personlessRows = await infra.postgres.query(+ PostgresUse.PERSONS_WRITE,+ 'SELECT 1 FROM posthog_personlessdistinctid WHERE team_id = $1 AND distinct_id = $2',+ [teamId, 'anon-nowrites'],+ 'fetchPersonlessRow'+ )+ expect(personlessRows.rows).toHaveLength(0)+ })})describe('merge folding', () => {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.tsindex 05e80b0df1b7..eceb5ff34e34 100644--- 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@@ -100,6 +100,7 @@ function buildPipeline(configOverrides: Partial<AiEventSubpipelineConfig> = {})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: '*',