Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(ingestion): validate $group_set is an object on $groupidentify (#72866)

Paweł Ledwoń4d757025240d
diff --git a/.agents/skills/adding-ingestion-warnings/SKILL.md b/.agents/skills/adding-ingestion-warnings/SKILL.md
index e4df16ef72ae..7595c1fd7b87 100644
--- a/.agents/skills/adding-ingestion-warnings/SKILL.md
+++ b/.agents/skills/adding-ingestion-warnings/SKILL.md
@@ -3,7 +3,7 @@ name: adding-ingestion-warnings
description: >
How to add a new ingestion warning type to the event ingestion pipeline.
Use when emitting a new warning from nodejs ingestion code (emitIngestionWarning, captureIngestionWarning, pipeline `warnings` arrays, `drop()` with warnings), when adding a warning type, category, or severity, or when a typecheck error says a string is not assignable to IngestionWarningType.
- Covers the INGESTION_WARNING_TYPES registry (the single source of truth for type, category, and severity), the details-key conventions that ClickHouse v2 materializes into columns, debouncing, and the downstream surfaces to keep in sync (v1 UI map, docs, v2 API).
+ Covers the INGESTION_WARNING_TYPES registry (the single source of truth for type, category, and severity), the details-key conventions that ClickHouse v2 materializes into columns, debouncing, and the downstream surfaces to keep in sync (v1 UI map, resolving-ingestion-warnings skill, docs, v2 API).
---
# Adding ingestion warnings
@@ -97,9 +97,6 @@ Adding a `captureProduced` type is an additive schema change, but nodejs and Rus
When adding a type, also update:
- **v1 UI map** — `WARNING_TYPE_TO_DESCRIPTION` (and `WARNING_TYPE_TO_DOCS_ANCHOR` if documented) in `frontend/src/scenes/data-management/ingestion-warnings/IngestionWarningsView.tsx`.
+- **Resolution skill (MCP)** — add the type to the routing table in [products/ingestion/skills/resolving-ingestion-warnings/SKILL.md](../../../products/ingestion/skills/resolving-ingestion-warnings/SKILL.md), the agent-facing skill that diagnoses each warning for customers. An inline fix in the table row is enough for simple warnings; add a `references/fixing-<type>.md` there when the diagnosis needs per-SDK or multi-cause detail.
- **posthog.com docs** — the ingestion warnings page (`https://posthog.com/docs/data/ingestion-warnings`) if the warning is user-actionable.
- **v2 API / MCP descriptions** — only if you added a new category or severity value; the example vocabularies live in the `ingestion_warnings_v2` serializer help texts (`posthog/api/ingestion_warnings_v2.py`).
-
-## Related
-
-- Warning-fixing skills (`fixing-<warning-type>`) that teach agents how to resolve each warning are planned under the ingestion warnings v2 effort; authoring one per new warning type will become part of this checklist.
diff --git a/frontend/src/scenes/data-management/ingestion-warnings/IngestionWarningsView.tsx b/frontend/src/scenes/data-management/ingestion-warnings/IngestionWarningsView.tsx
index e39a8ee010cf..b83627d319a2 100644
--- a/frontend/src/scenes/data-management/ingestion-warnings/IngestionWarningsView.tsx
+++ b/frontend/src/scenes/data-management/ingestion-warnings/IngestionWarningsView.tsx
@@ -38,6 +38,7 @@ export const WARNING_TYPE_TO_DESCRIPTION: Record<string, string> = {
set_on_exception: '$set or $set_once is ignored on exception events and should not be sent',
schema_validation_failed: 'Event rejected due to schema validation failure',
invalid_heatmap_data: 'Invalid heatmap data',
+ invalid_group_set: 'Discarded a $groupidentify event whose $group_set is not an object',
// Emitted by the capture service when it drops events at validation time
missing_event_name: 'Discarded event with no event name',
event_name_too_long: 'Discarded event whose name exceeds the length limit',
diff --git a/nodejs/src/ingestion/common/ingestion-warning-types.ts b/nodejs/src/ingestion/common/ingestion-warning-types.ts
index 1827652d7281..4eacef744e79 100644
--- a/nodejs/src/ingestion/common/ingestion-warning-types.ts
+++ b/nodejs/src/ingestion/common/ingestion-warning-types.ts
@@ -61,6 +61,7 @@ export const INGESTION_WARNING_TYPES = {
schema_validation_failed: { category: 'event', severity: 'error' },
skipping_event_invalid_distinct_id: { category: 'event', severity: 'error' },
invalid_ai_token_property: { category: 'event', severity: 'warning' },
+ invalid_group_set: { category: 'event', severity: 'error' },
invalid_process_person_profile: { category: 'event', severity: 'warning' },
invalid_event_when_process_person_profile_is_false: { category: 'event', severity: 'error' },
event_dropped_too_old: { category: 'event', severity: 'info' },
diff --git a/nodejs/src/ingestion/common/steps/event-processing/process-groups-step.test.ts b/nodejs/src/ingestion/common/steps/event-processing/process-groups-step.test.ts
index 12bcd751d43d..28d98117d10e 100644
--- a/nodejs/src/ingestion/common/steps/event-processing/process-groups-step.test.ts
+++ b/nodejs/src/ingestion/common/steps/event-processing/process-groups-step.test.ts
@@ -151,6 +151,69 @@ describe('createProcessGroupsStep', () => {
expect(mockGroupStore.upsertGroup).not.toHaveBeenCalled()
})
+ it.each([
+ { desc: 'string', groupSet: 'some-random-token', receivedType: 'string' },
+ { desc: 'number', groupSet: 42, receivedType: 'number' },
+ { desc: 'boolean', groupSet: true, receivedType: 'boolean' },
+ { desc: 'array', groupSet: ['a', 'b'], receivedType: 'array' },
+ ])(
+ 'drops the event with an invalid_group_set warning when $group_set is a $desc',
+ async ({ groupSet, receivedType }) => {
+ mockGroupTypeManager.fetchGroupTypeIndex.mockResolvedValue(0)
+
+ const step = createStep()
+ const result = await step(
+ createInput({
+ preparedEvent: createTestPreIngestionEvent({
+ event: '$groupidentify',
+ properties: {
+ $group_type: 'organization',
+ $group_key: 'org::5',
+ $group_set: groupSet,
+ },
+ }),
+ })
+ )
+
+ expect(result.type).toBe(PipelineResultType.DROP)
+ expect(mockGroupStore.upsertGroup).not.toHaveBeenCalled()
+ expect(result.warnings).toEqual([
+ expect.objectContaining({
+ type: 'invalid_group_set',
+ details: expect.objectContaining({
+ eventUuid: 'test-uuid',
+ distinctId: 'test-distinct-id',
+ groupType: 'organization',
+ groupKey: 'org::5',
+ receivedType,
+ }),
+ }),
+ ])
+ }
+ )
+
+ it('upserts with empty properties when $group_set is null', async () => {
+ mockGroupTypeManager.fetchGroupTypeIndex.mockResolvedValue(0)
+
+ const step = createStep()
+ const result = await step(
+ createInput({
+ preparedEvent: createTestPreIngestionEvent({
+ event: '$groupidentify',
+ properties: {
+ $group_type: 'organization',
+ $group_key: 'org::5',
+ $group_set: null,
+ },
+ }),
+ })
+ )
+
+ expect(result.type).toBe(PipelineResultType.OK)
+ expect(result.warnings).toEqual([])
+ expect(mockGroupStore.upsertGroup).toHaveBeenCalledWith(1, 1, 0, 'org::5', {}, expect.any(DateTime))
+ })
+
it('does not call upsertGroup when group type index is null', async () => {
mockGroupTypeManager.fetchGroupTypeIndex.mockResolvedValue(null)
diff --git a/nodejs/src/ingestion/common/steps/event-processing/process-groups-step.ts b/nodejs/src/ingestion/common/steps/event-processing/process-groups-step.ts
index ac67e4db7377..5485947f002a 100644
--- a/nodejs/src/ingestion/common/steps/event-processing/process-groups-step.ts
+++ b/nodejs/src/ingestion/common/steps/event-processing/process-groups-step.ts
@@ -6,7 +6,8 @@ import { logger } from '~/common/utils/logger'
import { captureException } from '~/common/utils/posthog'
import { TeamManager } from '~/common/utils/team-manager'
import { GroupStoreForBatch } from '~/ingestion/common/groups/group-store-for-batch'
-import { ok } from '~/ingestion/framework/results'
+import { PipelineWarning } from '~/ingestion/framework/pipeline.interface'
+import { drop, ok } from '~/ingestion/framework/results'
import { ProcessingStep } from '~/ingestion/framework/steps'
import { Properties } from '~/plugin-scaffold'
import { PreIngestionEvent, ProjectId, Team, TeamId } from '~/types'
@@ -56,6 +57,10 @@ export function createProcessGroupsStep<TInput extends ProcessGroupsStepInput>(
)
if (preparedEvent.event === '$groupidentify') {
+ const invalidGroupSetWarning = validateGroupSet(preparedEvent)
+ if (invalidGroupSetWarning) {
+ return drop('invalid_group_set', [], [invalidGroupSetWarning])
+ }
await upsertGroup(
groupTypeManager,
groupStoreForBatch,
@@ -100,6 +105,34 @@ async function updateGroupsAndFirstEvent(
await Promise.all(promises)
}
+// Group properties must be a plain JSON object — anything else (string, number,
+// array, ...) would reach Postgres as an invalid jsonb parameter and poison the
+// whole write batch.
+function validateGroupSet(preparedEvent: PreIngestionEvent): PipelineWarning | null {
+ const { $group_type: groupType, $group_key: groupKey, $group_set: groupPropertiesToSet } = preparedEvent.properties
+
+ if (
+ groupPropertiesToSet == null ||
+ (typeof groupPropertiesToSet === 'object' && !Array.isArray(groupPropertiesToSet))
+ ) {
+ return null
+ }
+
+ return {
+ type: 'invalid_group_set',
+ details: {
+ eventUuid: preparedEvent.eventUuid,
+ distinctId: preparedEvent.distinctId,
+ groupType: String(groupType),
+ groupKey: sanitizeString(String(groupKey)),
+ receivedType: Array.isArray(groupPropertiesToSet) ? 'array' : typeof groupPropertiesToSet,
+ },
+ // No `key`: the limiter's bucket map never evicts, so a client-supplied
+ // key (like $group_key) would let a sender bypass the per-team debounce
+ // and grow the map without bound. Debounce per team and type instead.
+ }
+}
+
async function upsertGroup(
groupTypeManager: GroupTypeManager,
groupStore: GroupStoreForBatch,
diff --git a/products/ingestion/skills/resolving-ingestion-warnings/SKILL.md b/products/ingestion/skills/resolving-ingestion-warnings/SKILL.md
index 1ab38439587b..551a8595c12c 100644
--- a/products/ingestion/skills/resolving-ingestion-warnings/SKILL.md
+++ b/products/ingestion/skills/resolving-ingestion-warnings/SKILL.md
@@ -47,17 +47,18 @@ A second cross-cutting check: **SDK version clustering**. Pull `$lib` / `$lib_ve
### Event validation (`event`)
-| Type | What happened | Fix |
-| ------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
-| `client_ingestion_warning` | The SDK itself reported a problem | Read `details.message` — the SDK wrote the diagnosis at the moment it caught the misuse (e.g. an invalid group key). Never debounced (like `merge_race_condition`), so counts are true counts; group by message and map each back to the misused SDK call |
-| `ignored_invalid_timestamp` | `timestamp` didn't parse; the event was kept with the server time | Read [references/fixing-ignored-invalid-timestamp.md](references/fixing-ignored-invalid-timestamp.md) — send ISO 8601; the event was kept at server time |
-| `schema_validation_failed` | Event dropped: it violates a schema the team enforces for that event | Compare `details.errors` against the payload; align the code or update the schema |
-| `skipping_event_invalid_distinct_id` | Event dropped: distinct ID over 400 chars | Read [references/fixing-invalid-distinct-ids.md](references/fixing-invalid-distinct-ids.md) — a token/payload was passed as the distinct ID |
-| `invalid_ai_token_property` | An `$ai_*` token property wasn't numeric; it was nulled | Read [references/fixing-invalid-ai-token-property.md](references/fixing-invalid-ai-token-property.md) — token counts must be plain numbers |
-| `invalid_process_person_profile` | `$process_person_profile` wasn't boolean; the default (true) was used | Read [references/fixing-process-person-profile-warnings.md](references/fixing-process-person-profile-warnings.md) — a stringified boolean silently opts back into person processing |
-| `invalid_event_when_process_person_profile_is_false` | `$identify`/`$create_alias`/`$merge_dangerously`/`$groupidentify` dropped because the event disabled person processing | Read [references/fixing-process-person-profile-warnings.md](references/fixing-process-person-profile-warnings.md) — identity events require person processing |
-| `event_dropped_too_old` | Intentional: the event is older than the team's configured drop threshold | Read [references/fixing-event-dropped-too-old.md](references/fixing-event-dropped-too-old.md) — mind mobile SDKs: offline queues legitimately deliver days-old events; threshold changes are the user's call |
-| `cookieless_missing_timestamp` / `cookieless_timestamp_out_of_range` / `cookieless_missing_user_agent` / `cookieless_missing_ip` / `cookieless_missing_host` | Cookieless-mode event dropped: a field required to compute the cookieless ID was missing or invalid | Read [references/fixing-cookieless-warnings.md](references/fixing-cookieless-warnings.md) — the missing field identifies the broken layer; beware the silent variant where a server relay omits $ip and users collapse onto the server's IP |
+| Type | What happened | Fix |
+| ------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| `client_ingestion_warning` | The SDK itself reported a problem | Read `details.message` — the SDK wrote the diagnosis at the moment it caught the misuse (e.g. an invalid group key). Never debounced (like `merge_race_condition`), so counts are true counts; group by message and map each back to the misused SDK call |
+| `ignored_invalid_timestamp` | `timestamp` didn't parse; the event was kept with the server time | Read [references/fixing-ignored-invalid-timestamp.md](references/fixing-ignored-invalid-timestamp.md) — send ISO 8601; the event was kept at server time |
+| `schema_validation_failed` | Event dropped: it violates a schema the team enforces for that event | Compare `details.errors` against the payload; align the code or update the schema |
+| `skipping_event_invalid_distinct_id` | Event dropped: distinct ID over 400 chars | Read [references/fixing-invalid-distinct-ids.md](references/fixing-invalid-distinct-ids.md) — a token/payload was passed as the distinct ID |
+| `invalid_ai_token_property` | An `$ai_*` token property wasn't numeric; it was nulled | Read [references/fixing-invalid-ai-token-property.md](references/fixing-invalid-ai-token-property.md) — token counts must be plain numbers |
+| `invalid_group_set` | `$groupidentify` dropped: `$group_set` wasn't a plain object (a string, number, boolean, or array was sent) | `details.receivedType` names what was sent — `string` usually means the caller JSON-stringified the group properties before passing them; pass a plain object to the SDK's `groupIdentify` call. Omitting `$group_set` is fine (group upserts with no property changes) |
+| `invalid_process_person_profile` | `$process_person_profile` wasn't boolean; the default (true) was used | Read [references/fixing-process-person-profile-warnings.md](references/fixing-process-person-profile-warnings.md) — a stringified boolean silently opts back into person processing |
+| `invalid_event_when_process_person_profile_is_false` | `$identify`/`$create_alias`/`$merge_dangerously`/`$groupidentify` dropped because the event disabled person processing | Read [references/fixing-process-person-profile-warnings.md](references/fixing-process-person-profile-warnings.md) — identity events require person processing |
+| `event_dropped_too_old` | Intentional: the event is older than the team's configured drop threshold | Read [references/fixing-event-dropped-too-old.md](references/fixing-event-dropped-too-old.md) — mind mobile SDKs: offline queues legitimately deliver days-old events; threshold changes are the user's call |
+| `cookieless_missing_timestamp` / `cookieless_timestamp_out_of_range` / `cookieless_missing_user_agent` / `cookieless_missing_ip` / `cookieless_missing_host` | Cookieless-mode event dropped: a field required to compute the cookieless ID was missing or invalid | Read [references/fixing-cookieless-warnings.md](references/fixing-cookieless-warnings.md) — the missing field identifies the broken layer; beware the silent variant where a server relay omits $ip and users collapse onto the server's IP |
### Heatmaps (`event`)