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(clickhouse): quarantine incompatible feature flag maps (#97754)

Rory Shanksc25d46c9e7d2
diff --git a/clickhouse-udfs/util/cmd/json_clean_posthog_event_properties_udf/main.go b/clickhouse-udfs/util/cmd/json_clean_posthog_event_properties_udf/main.go
index c7f44b0f33b7..8f2745314fd3 100644
--- a/clickhouse-udfs/util/cmd/json_clean_posthog_event_properties_udf/main.go
+++ b/clickhouse-udfs/util/cmd/json_clean_posthog_event_properties_udf/main.go
@@ -21,6 +21,7 @@ const (
normalizationNone normalizationKind = iota
normalizationStringArray
normalizationObjectArray
+ normalizationObject
)
type propertiesKind byte
@@ -127,6 +128,7 @@ func makeEventPropertyRules() *pathRule {
addPathRules(root, normalizationObjectArray,
"$exception_list",
)
+ addPathRules(root, normalizationObject, "$feature_flags")
return root
}
@@ -863,7 +865,11 @@ func (p *processor) cleanObject(pathRules *pathRule, obj *value, depth int) erro
writeJSONString(&unparsable, entry.key)
unparsable.WriteByte(':')
p.writeValue(&unparsable, cleaned)
- cleaned = p.reuseAsEmptyArray(cleaned)
+ if childPathRules.normalization == normalizationObject {
+ p.resetValue(cleaned, kindObject)
+ } else {
+ cleaned = p.reuseAsEmptyArray(cleaned)
+ }
}
}
if cleaned.kind == kindNull {
@@ -1055,6 +1061,11 @@ func (p *processor) normalizeValue(normalization normalizationKind, v *value, de
return p.coerceStringArray(v, depth)
case normalizationObjectArray:
return p.coerceObjectArray(v, depth)
+ case normalizationObject:
+ if v.kind != kindObject && v.kind != kindNull {
+ return nil, fmt.Errorf("cannot coerce %s to Map", valueKindName(v.kind))
+ }
+ return v, nil
default:
return v, nil
}
diff --git a/clickhouse-udfs/util/cmd/json_clean_posthog_event_properties_udf/main_test.go b/clickhouse-udfs/util/cmd/json_clean_posthog_event_properties_udf/main_test.go
index 6698522c47f9..55aa8af8a23b 100644
--- a/clickhouse-udfs/util/cmd/json_clean_posthog_event_properties_udf/main_test.go
+++ b/clickhouse-udfs/util/cmd/json_clean_posthog_event_properties_udf/main_test.go
@@ -92,6 +92,9 @@ func TestEventPropertyRulesCoverComplexSchemaPaths(t *testing.T) {
normalizationObjectArray: {
"$exception_list",
},
+ normalizationObject: {
+ "$feature_flags",
+ },
}
for want, paths := range tests {
@@ -121,8 +124,13 @@ func TestProcessLinePreservesScalarPropertiesAndNormalizesComplexProperties(t *t
}
}
-func TestProcessLineQuarantinesInvalidExceptionList(t *testing.T) {
+func TestProcessLineQuarantinesInvalidComplexProperties(t *testing.T) {
tests := map[string]string{
+ `{"$feature_flags":"not-a-map","kept":"value"}`: `{"$feature_flags":{},"kept":"value","$unparseable_properties":"{\"$feature_flags\":\"not-a-map\"}"}`,
+ `{"$feature_flags":["flag"]}`: `{"$feature_flags":{},"$unparseable_properties":"{\"$feature_flags\":[\"flag\"]}"}`,
+ `{"$feature_flags":true}`: `{"$feature_flags":{},"$unparseable_properties":"{\"$feature_flags\":true}"}`,
+ `{"$feature_flags":42}`: `{"$feature_flags":{},"$unparseable_properties":"{\"$feature_flags\":42}"}`,
+ `{"$feature_flags":null}`: `{}`,
`{"$unparseable_properties":"spoofed","$exception_list":"[redacted]","kept":"value"}`: `{"$exception_list":[],"kept":"value","$unparseable_properties":"{\"$exception_list\":\"[redacted]\"}"}`,
`{"$exception_list":[1]}`: `{"$exception_list":[],"$unparseable_properties":"{\"$exception_list\":[1]}"}`,
`{"$exception_list":true}`: `{"$exception_list":[],"$unparseable_properties":"{\"$exception_list\":true}"}`,
diff --git a/docs/internal/clickhouse-utility-udfs.md b/docs/internal/clickhouse-utility-udfs.md
index 20a3304aa121..7c7629e52278 100644
--- a/docs/internal/clickhouse-utility-udfs.md
+++ b/docs/internal/clickhouse-utility-udfs.md
@@ -5,6 +5,10 @@ Before emitting JSON for insertion, it sorts the keys in `$feature_flags` alphab
This also applies to existing `$feature_flags` objects, after cleanup resolves duplicates and expands dotted keys.
Flag values and person-property ordering follow the existing cleanup rules.
+Invalid scalar and array `$feature_flags` values are replaced with an empty map and retained in
+`$unparseable_properties`, alongside other invalid complex properties. This keeps malformed
+map values from failing insertion into the typed JSON column while preserving unrelated properties.
+
See [the utility UDF README](../../clickhouse-udfs/util/README.md) for build and integration-test commands.
The utility module and CI use Go 1.27.1, declared in `clickhouse-udfs/util/go.mod`.
Rebuild all three utilities for Linux amd64 and arm64 with `./scripts/build.sh` whenever this version changes; CI verifies the checked-in binaries.
diff --git a/posthog/user_scripts/json_clean_posthog_event_properties_udf_aarch64 b/posthog/user_scripts/json_clean_posthog_event_properties_udf_aarch64
index 3a54e0e607a8..77104d5ee885 100755
Binary files a/posthog/user_scripts/json_clean_posthog_event_properties_udf_aarch64 and b/posthog/user_scripts/json_clean_posthog_event_properties_udf_aarch64 differ
diff --git a/posthog/user_scripts/json_clean_posthog_event_properties_udf_x86_64 b/posthog/user_scripts/json_clean_posthog_event_properties_udf_x86_64
index 718596098e62..676940073097 100755
Binary files a/posthog/user_scripts/json_clean_posthog_event_properties_udf_x86_64 and b/posthog/user_scripts/json_clean_posthog_event_properties_udf_x86_64 differ