Skip to content

feat(flags): support known-absent property keys in local evaluation - #1280

Open
marandaneto wants to merge 35 commits into
mainfrom
feat/flags-known-absent-property-keys
Open

marandaneto wants to merge 35 commits into
mainfrom
feat/flags-known-absent-property-keys

Conversation

@marandaneto

@marandaneto marandaneto commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

💡 Motivation and Context

Closes the Python part of PostHog/posthog#88947.

Local flag evaluation can't tell a missing property apart from one the caller didn't pass. If a key is left out of person_properties, the condition that reads it is inconclusive and the SDK asks /flags. Callers had no way to say "this person definitely doesn't have plan". So a flag with plan is_not_set could never resolve locally. The local result and the /flags result could also disagree.

The flags service now accepts known-absent keys (PostHog/posthog#138239). This PR adds the same input to the SDK, following the cross-SDK spec in PostHog/sdk-specs#233.

New input

Two optional keyword arguments:

  • person_property_keys_known_absent: a collection of person property keys.
  • group_property_keys_known_absent: a mapping from group type to a collection of group property keys.
flags = posthog.evaluate_flags(
    "user-1",
    person_properties={"email": "a@example.com"},
    person_property_keys_known_absent=["plan"],
    groups={"organization": "org-1"},
    group_property_keys_known_absent={"organization": ["tier"]},
)

They are accepted by evaluate_flags, get_feature_flag, get_feature_flag_result, feature_enabled, get_feature_flag_payload, get_all_flags, get_all_flags_and_payloads, get_feature_variants, get_feature_payloads, get_feature_flags_and_payloads, get_flags_decision, and the module-level wrappers. They also work in capture(send_feature_flags={...}) and in AsyncClient.evaluate_flags. Existing signatures don't change.

Local evaluation

  • A listed key counts as absent, even when the caller also passes a value for it. This also overrides values the SDK adds itself, such as distinct_id and $group_key.
  • For a listed key, is_not_set, is_not, not_icontains, not_starts_with, not_ends_with and not_regex match. Every other supported operator does not match. That includes is_set, exact, gt, all semver_* operators and the date operators. The result is final, with no /flags request.
  • Unsupported operators and invalid filters are still checked first. They stay inconclusive and fall back to /flags even when the key is listed.
  • Operator support is checked before the known-absent table, in flag conditions and in cohort leaves, as required by the latest spec revision (docs(flags): specify known-absent property keys sdk-specs#233). test_cohort_leaf_unsupported_operator_falls_back_before_known_absence covers a cohort leaf plan not_between [1, 2] with and without negation.
  • A key that is left out and not listed stays inconclusive, same as today.
  • An omitted or JSON null condition value on a listed key stays inconclusive and falls back to /flags, per docs(flags): resolve known-absent keys without reading the condition value sdk-specs#239. is_set and is_not_set keep their known-absent result whatever the value is.
  • Person keys starting with __posthog_person_metadata__ are ignored.
  • Listed keys are scoped by filter type: person keys apply to person filters and to filters with an omitted, null or empty type, group keys only apply to group filters of their own group type, and person_metadata filters (such as a created_at cohort leaf) never resolve from a listing and fall back to /flags (main fix(flags): don't match person_metadata filters against person properties #1288, docs(flags): treat unsupported property-filter types as inconclusive sdk-specs#251). A group filter without group_type_index reads the condition's group type.
  • Cohort property conditions use the absent result before applying the condition's negation. Flag dependencies are evaluated in their own context with the same listed keys (see below).
  • A listed $feature_enrollment/<flag key> means the person is not enrolled. Evaluation then continues to holdouts and release conditions instead of returning early or falling back. Python is the only SDK with local enrollment handling.

Flag dependencies and group filters without an index

Per PostHog/sdk-specs#250, a flag dependency is now evaluated in its own context: the referenced flag is evaluated as if it were evaluated directly with the same distinct id, groups, person and group properties, known-absent keys and device id, using its own aggregation, properties and bucketing value, and a dependency's conditions aggregated on a group that isn't supplied are skipped, so a group dependency with only such conditions resolves as false. A type: "group" filter without group_type_index now reads the condition's group type, including its known-absent keys, as the flags service does. This also fixes local results without known-absent keys: before, a person flag that depended on a group flag evaluated the group flag with the person's properties and distinct id, so it could differ from /flags, and a group dependency without its group fell back to /flags.

Per PostHog/sdk-specs#250 a usable group key is a non-empty string or a number. An empty-string, None, boolean, list or dict group key counts as no group key: conditions aggregated on that group type are skipped locally with no /flags request (also as a dependency), so a flag with only such conditions resolves as false. Before, an empty string was used as the bucketing key and the other kinds fell back to /flags.

Per the amended PostHog/sdk-specs#250 (matching the flags service), a group flag without a usable group key now skips only its group conditions, so a condition with aggregation_group_type_index: null still runs on the person's properties and distinct id, directly and as a dependency; a group flag with a holdout above 0% and no usable key is inconclusive (missing_context) and falls back to /flags. Tested with TestGroupConditionsWithoutGroupKey and TestGroupFlagHoldoutWithoutGroupKey (13 red before the fix, plus a person-bucketing test red on the old code), full pytest 8670 passed with the 3 known fork failures, ruff, mypy baseline and make public_api_check passed.

/flags request body

When the SDK calls /flags and the caller listed keys, the body includes person_property_keys_known_absent: [...] and group_property_keys_known_absent: {"<group type>": [...]}. This happens for local fallback, forced remote calls, and remote-only calls. A field is left out when it wasn't provided or is empty.

Limits

Each list holds at most 1000 keys. Duplicates count. For groups the limit applies per group type. A longer list raises ValueError from the flag getters. Nothing is evaluated and no request is sent. The SDK never truncates the list. Wrong types raise TypeError, for example a plain string or a non-string group type. A bytearray or a mapping (such as a property dict passed by mistake) also raises TypeError, while a dict's .keys() view is accepted. With capture(send_feature_flags={...}), the error is handled like other capture errors. capture logs it and returns None, and no event is sent. With debug=True it raises.

Compliance adapter

The adapter now declares feature_flags_known_absent_v1. /get_feature_flag passes both new params to the SDK unchanged. It also accepts allow_remote_fallback: true, which calls the default getter on the client with local definitions. That mode returns HTTP 400 when combined with force_remote: true or only_evaluate_locally: true.

Not included

Links

💚 How did you test it?

New tests in posthog/test/test_feature_flags_known_absent.py:

  • Every supported operator on a listed key, resolved locally with no request.
  • A listed key overriding a supplied value, the SDK-added distinct_id, and $group_key.
  • An omitted key that isn't listed still falling back to /flags.
  • The metadata prefix being ignored.
  • Group-type scoping, and person keys not applying to groups.
  • An unsupported filter on a listed key still falling back.
  • Cohort conditions with and without negation, and a flag dependency.
  • Enrollment continuing to release conditions and holdouts, and group enrollment staying unsupported.
  • The /flags body including the fields on fallback and on every remote entry point, including capture(send_feature_flags=...) and async evaluate_flags. The fields are left out when not provided or empty.
  • The 1000-key limit. This covers duplicates, the per-group-type limit, unbounded iterators, the capture path with default and debug settings, and wrong types.
  • Iterator inputs reaching the /flags body.

sdk_compliance_adapter/test_adapter.py covers the new adapter params and allow_remote_fallback.

Commands run locally with uv run --no-sync on macOS:

  • ruff format --check . passed.
  • ruff check . passed.
  • mypy --no-site-packages --config-file mypy.ini . | mypy-baseline filter passed.
  • make public_api_check passed. The snapshot is updated in this PR.
  • python -W error -c "import posthog" passed.
  • pytest sdk_compliance_adapter/test_adapter.py passed.
  • pytest --timeout=30 gave 8397 passed and 3 failed. The 3 failures are fork tests in posthog/test/test_metrics_autocapture.py. They also fail on unchanged main on macOS.

After the spec revision I added the cohort-leaf test. It passed with no production change. I re-ran ruff format --check ., ruff check ., mypy with the baseline filter, make public_api_check and python -W error -c "import posthog", and all passed. pytest --timeout=30 gave 8399 passed and the same 3 fork test failures in posthog/test/test_metrics_autocapture.py.

For PostHog/sdk-specs#239 I added test_listed_key_with_omitted_or_null_value_stays_inconclusive (is_not with the value omitted, and is_not, exact and gt with "value": null) and test_listed_key_with_null_value_resolves_presence_operator (is_not_set and is_set with "value": null). Before the fix, the is_not omitted, is_not null and exact null cases failed because the known-absent table resolved them. gt null already fell back. After the fix all 6 cases pass. In local-only mode the flag is unresolved with unsupported_definition, which matches an omitted condition value on a present key, and the default getter falls back to /flags. ruff format --check ., ruff check ., mypy with the baseline filter, make public_api_check and python -W error -c "import posthog" passed. pytest posthog/test gave 8467 passed and the same 3 fork test failures in posthog/test/test_metrics_autocapture.py.

For filter type scoping (b6c0dd3) I added 19 cases: test_listed_key_does_not_resolve_a_person_metadata_filter, test_person_metadata_filter_on_listed_key_reads_the_supplied_value, test_listed_key_does_not_resolve_a_person_metadata_cohort_leaf, test_person_keys_do_not_resolve_a_group_filter_in_a_person_flag, test_group_keys_do_not_resolve_a_person_filter_in_a_group_flag, test_group_keys_do_not_resolve_a_person_cohort_leaf_in_a_group_flag, test_group_keys_do_not_resolve_a_filter_for_another_group_type and test_flag_dependency_does_not_read_keys_of_another_aggregation. All 19 failed before the fix, and the file gave 110 passed after it. For the input check (da10384) the bytearray, person dict, empty person dict and group dict cases of test_wrong_type_raises_without_a_request failed before the fix, and the file gave 117 passed after it. For repeated keys (98124ab) test_duplicate_person_key_still_reads_the_supplied_value_outside_its_scope and test_duplicate_group_key_still_reads_the_supplied_value_outside_its_scope failed before the fix because a repeated key wrapped its own marker, and the file gave 119 passed after it. ruff format --check, ruff check and mypy with the baseline filter passed.

For PostHog/sdk-specs#250 I added these tests to posthog/test/test_feature_flags_known_absent.py. Each failed before its fix and passes after it:

  • test_group_filter_without_index_reads_the_condition_group_type (exact "enterprise" gives false and is_not_set gives true with a supplied tier="enterprise" listed for organization, plus a null index and $group_key is_set) and test_group_filter_without_index_reads_the_condition_level_group_type (mixed targeting). Before ddc25fa they read the supplied value. test_group_filter_without_index_ignores_keys_of_another_group_type already passed and stays as a regression test.
  • test_dependency_is_evaluated_with_its_own_aggregation (person region=us, organization region=eu: parent and child both false, no request). Before 6f71109 the child was true.
  • test_group_dependency_without_its_group_resolves_as_false (no organization group, tier listed for organization: parent and child both false, no request). Before 6f71109 the child fell back to /flags.
  • test_group_dependency_is_bucketed_by_the_group_key (50% rollout: org-0 out and org-1 in, matching direct evaluation). Before 6f71109 the dependency hashed the distinct id.
  • test_person_dependency_of_a_group_flag_reads_person_context (organization child with a person parent reads person properties and hashes the distinct id). Before 6f71109 it read the organization properties.

test_property_matching_version.py and test_redis_flag_cache_snapshot.py now patch posthog.feature_flags.match_feature_flag_properties, because the client delegates to the shared _compute_flag_locally. ruff format --check ., ruff check ., mypy with the baseline filter and make public_api_check passed, and pytest posthog/test passed apart from the same fork tests in posthog/test/test_metrics_autocapture.py.

For cold-start group known-absent keys (7bd5a4b) I added TestKnownAbsentColdStart to posthog/test/test_feature_flags_known_absent.py. It uses a fresh client that never called load_feature_flags(), lists tier and $group_key for organization, supplies tier="gold" and allows no /flags call. Its three tests, test_evaluate_flags_marks_group_keys_after_lazy_load, test_get_feature_flag_marks_group_keys_after_lazy_load and test_get_all_flags_marks_group_keys_after_lazy_load, failed before the fix because the keys were marked before the definitions loaded, so they carried no group type index (org-tier-flag was false and org-key-flag was true). All three pass now. ruff check, ruff format --check, mypy with the baseline filter and make public_api_check passed. pytest posthog/test gave 8555 passed and the same 3 fork test failures in posthog/test/test_metrics_autocapture.py.

For group cohort leaves without an index (a2e6e9e) I added test_group_cohort_leaf_reads_the_condition_group_type (organization flag, cohort leaf tier exact "enterprise" with the index omitted, null or 0, tier="enterprise" supplied and listed for organization: false, no request) and test_group_cohort_leaf_with_another_index_ignores_the_condition_keys (leaf with index 1 reads the supplied value: true). The omitted and null cases failed before the fix because the supplied value won. A group filter without an index now reads the condition's listing everywhere, so _with_condition_group_type is removed. ruff, mypy with the baseline filter and make public_api_check passed, pytest gave 8559 passed and the same 3 fork test failures, and CI passed.

For the outage fallback cache (52dd053, d96892d) I added TestKnownAbsentFallbackCache: results are cached under the flag key plus a digest of the sorted, deduplicated person and group listings, so a result cached for one listing is not served to a call with a different listing during a /flags outage, and a stale result is only served for the flag it belongs to. The flags service has no such cache, so there is nothing to mirror there. The person, group and unlisted-to-listed cases and the literal-key case failed before the fix. ruff, mypy with the baseline filter and make public_api_check passed, and pytest gave 8564 passed and the same 3 fork test failures.

The fallback cache now keeps at most one unlisted and one listed entry per user and flag (0f352e5, 1d0b21d). The listed entry stores the listing digest and lives in a separate Redis namespace (_posthog:flags:known_absent: for the default prefix; the full configured prefix behind a different first character), so SDKs up to 7.37.0, which ignore the digest, never read it. Testing: 2000 distinct listings left 2000 entries before and 2 after, and posthog==7.37.0 gets a cache miss on a new listed write; pytest gave 8625 passed and the same 3 fork test failures.

For unusable group keys (2705b8c) I added TestUnusableGroupKeys to posthog/test/test_feature_flags.py, parameterized over "", None, True, False, [] and {}: direct group flag, mixed flag, group dependency, _compute_flag_locally, get_all_flags, evaluate_flags and capture(send_feature_flags=...). All 30 cases failed before the fix and pass after it; string, integer and float keys still evaluate and bucket as before, and a usable key without the needed group properties still falls back. ruff, mypy with the baseline filter and make public_api_check passed, and pytest gave 8595 passed and the same 3 fork test failures.

CI now runs SDK test harness 1.34.0. The feature_flags_known_absent suite ran and passed 12/12 in each compliance job (gzip, deflate and zstd).

Round 7 changes

  • Merged main (fix(flags): don't match person_metadata filters against person properties #1288 person_metadata filters); the test that expected a person_metadata filter to read the supplied value is deleted and the duplicate person key test now uses a person filter (5ebaf6d).
  • Redis listed entries now keep the full key prefix, so apps with prefixes like project-1 and project-2 no longer share listed entries (8f684cc, f510866).
  • Person known-absent keys now apply to filters with an omitted, null or empty type, in conditions and cohort leaves, as the flags service does (cfe635a).
  • A direct match_feature_flag_properties call without groups matches a group flag's conditions against the passed properties again, as on main, while an explicit groups={} skips them (9e6146b); tested with TestDirectGroupFlagMatchWithoutGroups, red then green, pytest 8716 passed with the 3 known macOS fork failures.
  • Tests: red then green for the prefix and untyped filter cases; ruff, mypy baseline, make public_api_check passed; pytest 8712 passed with the 3 known macOS fork failures.

📝 Checklist

  • All commits are signed (see Commit signing)
  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Ran sampo add to generate a changeset file

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Written with Pi (Claude) and reviewed with the autoreview skill (GPT model, branch mode). Review found three real problems, which are fixed in separate commits. Validation consumed one-shot iterators before the /flags call. Unbounded iterables were read fully before the limit check. Non-string group types and None group lists were accepted. A fourth review run was clean.

capture keeps its existing error handling for invalid known-absent keys instead of raising. This matches how it already treats an invalid send_feature_flags value.

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

SDK performance: posthog-python

43 changes worth reviewing: 43 observed regressions.

Flags require at least a 5% change in the median and all six pairs agreeing on direction. This is a noise filter, not proof of a performance change or a CI gate.

Test Measurement Before PR With PR Change
Evaluate a regex-filtered flag Time per operation 18.14 µs/op 21.32 µs/op 17.6% more time
Evaluate a regex-filtered flag Process CPU time per operation 18.14 µs/op 21.32 µs/op 17.5% more time
Evaluate a property-filtered flag Time per operation 16.96 µs/op 19.89 µs/op 17.3% more time
Evaluate a property-filtered flag Process CPU time per operation 16.96 µs/op 19.89 µs/op 17.3% more time
Evaluate a rollout flag Allocated memory per operation 14.89 KiB/op 17.19 KiB/op 15.4% more memory
Evaluate a rollout flag Time per operation 13.34 µs/op 15.35 µs/op 15.1% more time
Evaluate a rollout flag Process CPU time per operation 13.34 µs/op 15.35 µs/op 15% more time
Evaluate one boolean flag Allocated memory per operation 15.74 KiB/op 18.04 KiB/op 14.6% more memory
Evaluate a multivariate flag Allocated memory per operation 15.9 KiB/op 18.2 KiB/op 14.4% more memory
Evaluate one boolean flag Time per operation 14.18 µs/op 16.19 µs/op 14.2% more time
Evaluate one boolean flag Process CPU time per operation 14.18 µs/op 16.19 µs/op 14.2% more time
Evaluate a property-filtered flag Allocated memory per operation 19.38 KiB/op 22.05 KiB/op 13.7% more memory

Showing the 12 largest flagged changes; 31 more are in all results.

View all results
Test Measurement Before PR With PR Change Assessment
Capture and deliver events (32-byte payload, burst)
Shard: capture
Managed heap after settling — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​; head:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Managed heap after settling — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​; head:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​
Capture and deliver events (32-byte payload, steady)
Shard: capture
Managed heap after settling — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​; head:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Managed heap after settling — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​; head:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​
Queue an event (32-byte payload)
Shard: capture
Allocated memory per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​; head:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​
Queue an event (32-byte payload)
Shard: capture
Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​; head:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​
Queue an event (4,096-byte payload)
Shard: capture
Allocated memory per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​; head:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​
Queue an event (4,096-byte payload)
Shard: capture
Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​; head:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Managed heap after settling — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​; head:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​
Refresh 1,000 flag definitions
Shard: flags-memory
Managed heap after settling — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​; head:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​
Capture and deliver events (32-byte payload, burst)
Shard: capture
Allocated memory per operation 133.67 KiB/op 133.79 KiB/op <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Allocations per operation 1,345.53 count/op 1,348.53 count/op 0.2% more Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Time per operation 81.12 µs/op 80.92 µs/op 0.2% less time Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Idle process memory (RSS) 37.79 MiB 37.72 MiB 0.2% less memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Observed peak process memory (RSS) 40.24 MiB 40.17 MiB 0.2% less memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Process memory after settling (RSS) 40.24 MiB 40.17 MiB 0.2% less memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Process CPU time per operation 80.86 µs/op 80.58 µs/op 0.3% less time Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Lifetime peak process memory (RSS) 40.8 MiB 40.8 MiB No observed change Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Allocated memory per operation 185.75 KiB/op 185.87 KiB/op <0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Allocations per operation 1,337.52 count/op 1,340.52 count/op 0.2% more Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Time per operation 110.84 µs/op 109.33 µs/op 1.4% less time Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Idle process memory (RSS) 41.35 MiB 41.39 MiB 0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Observed peak process memory (RSS) 47.13 MiB 47.17 MiB <0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Process memory after settling (RSS) 47.13 MiB 47.17 MiB <0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Process CPU time per operation 103.71 µs/op 101.92 µs/op 1.7% less time Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Lifetime peak process memory (RSS) 51.59 MiB 51.63 MiB <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Allocated memory per operation 138.74 KiB/op 138.86 KiB/op <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Allocations per operation 1,390.45 count/op 1,393.42 count/op 0.2% more Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Time per operation 94.36 µs/op 97.96 µs/op 3.8% more time Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Idle process memory (RSS) 37.73 MiB 37.77 MiB <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Observed peak process memory (RSS) 37.9 MiB 37.96 MiB 0.2% more memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Process memory after settling (RSS) 37.9 MiB 37.96 MiB 0.2% more memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Process CPU time per operation 92.9 µs/op 97.16 µs/op 4.6% more time Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Lifetime peak process memory (RSS) 40.8 MiB 40.8 MiB No observed change Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Allocated memory per operation 190.92 KiB/op 191.04 KiB/op <0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Allocations per operation 1,382.36 count/op 1,385.36 count/op 0.2% more Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Time per operation 115.54 µs/op 115.49 µs/op <0.1% less time Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Idle process memory (RSS) 41.15 MiB 41.27 MiB 0.3% more memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Observed peak process memory (RSS) 41.6 MiB 41.78 MiB 0.4% more memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Process memory after settling (RSS) 41.21 MiB 41.36 MiB 0.4% more memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Process CPU time per operation 109.67 µs/op 109.74 µs/op <0.1% more time Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Lifetime peak process memory (RSS) 41.54 MiB 41.64 MiB 0.2% more memory Not flagged
Queue an event (32-byte payload)
Shard: capture
Caller-thread CPU time per operation 61.33 µs/op 59.76 µs/op 2.6% less time Not flagged
Queue an event (32-byte payload)
Shard: capture
Time per operation 61.35 µs/op 62.82 µs/op 2.4% more time Not flagged
Queue an event (4,096-byte payload)
Shard: capture
Caller-thread CPU time per operation 60.02 µs/op 64.21 µs/op 7% more time Not flagged
Queue an event (4,096-byte payload)
Shard: capture
Time per operation 60.02 µs/op 64.21 µs/op 7% more time Not flagged
Evaluate all 10 flags
Shard: flags-scaling
Allocated memory per operation 233.85 KiB/op 254.46 KiB/op 8.8% more memory Worth reviewing: observed regression
Evaluate all 10 flags
Shard: flags-scaling
Allocations per operation 2,352.93 count/op 2,462.97 count/op 4.7% more Not flagged
Evaluate all 10 flags
Shard: flags-scaling
Time per operation 84.86 µs/op 95.92 µs/op 13% more time Worth reviewing: observed regression
Evaluate all 10 flags
Shard: flags-scaling
Process CPU time per operation 84.85 µs/op 95.92 µs/op 13% more time Worth reviewing: observed regression
Evaluate all 100 flags
Shard: flags-scaling
Allocated memory per operation 2.25 MiB/op 2.44 MiB/op 8.6% more memory Worth reviewing: observed regression
Evaluate all 100 flags
Shard: flags-scaling
Allocations per operation 23,148.75 count/op 24,213.19 count/op 4.6% more Not flagged
Evaluate all 100 flags
Shard: flags-scaling
Time per operation 795.61 µs/op 900.52 µs/op 13.2% more time Worth reviewing: observed regression
Evaluate all 100 flags
Shard: flags-scaling
Process CPU time per operation 795.64 µs/op 900.59 µs/op 13.2% more time Worth reviewing: observed regression
Evaluate all 1,000 flags
Shard: flags-scaling
Allocated memory per operation 22.45 MiB/op 24.37 MiB/op 8.6% more memory Worth reviewing: observed regression
Evaluate all 1,000 flags
Shard: flags-scaling
Allocations per operation 231,005.5 count/op 241,609.94 count/op 4.6% more Not flagged
Evaluate all 1,000 flags
Shard: flags-scaling
Time per operation 7.94 ms/op 8.95 ms/op 12.7% more time Worth reviewing: observed regression
Evaluate all 1,000 flags
Shard: flags-scaling
Process CPU time per operation 7.94 ms/op 8.95 ms/op 12.7% more time Worth reviewing: observed regression
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Idle process memory (RSS) 43.87 MiB 43.86 MiB <0.1% less memory Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Observed peak process memory (RSS) 44.2 MiB 44.18 MiB <0.1% less memory Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Process memory after settling (RSS) 44.2 MiB 44.18 MiB <0.1% less memory Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Lifetime peak process memory (RSS) 43.95 MiB 43.92 MiB <0.1% less memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Idle process memory (RSS) 43.05 MiB 43.08 MiB <0.1% more memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Observed peak process memory (RSS) 43.06 MiB 43.08 MiB <0.1% more memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Process memory after settling (RSS) 43.06 MiB 43.08 MiB <0.1% more memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Lifetime peak process memory (RSS) 43.16 MiB 42.89 MiB 0.6% less memory Not flagged
Evaluate one boolean flag
Shard: flags-single
Allocated memory per operation 15.74 KiB/op 18.04 KiB/op 14.6% more memory Worth reviewing: observed regression
Evaluate one boolean flag
Shard: flags-single
Allocations per operation 162.77 count/op 174.77 count/op 7.4% more Worth reviewing: observed regression
Evaluate one boolean flag
Shard: flags-single
Time per operation 14.18 µs/op 16.19 µs/op 14.2% more time Worth reviewing: observed regression
Evaluate one boolean flag
Shard: flags-single
Process CPU time per operation 14.18 µs/op 16.19 µs/op 14.2% more time Worth reviewing: observed regression
Evaluate a cohort-filtered flag
Shard: flags-single
Allocated memory per operation 25.28 KiB/op 28.38 KiB/op 12.2% more memory Worth reviewing: observed regression
Evaluate a cohort-filtered flag
Shard: flags-single
Allocations per operation 245.28 count/op 263.28 count/op 7.3% more Worth reviewing: observed regression
Evaluate a cohort-filtered flag
Shard: flags-single
Time per operation 23.21 µs/op 26.28 µs/op 13.2% more time Worth reviewing: observed regression
Evaluate a cohort-filtered flag
Shard: flags-single
Process CPU time per operation 23.21 µs/op 26.28 µs/op 13.2% more time Worth reviewing: observed regression
Evaluate a flag (early match)
Shard: flags-single
Allocated memory per operation 41.36 KiB/op 45.28 KiB/op 9.5% more memory Worth reviewing: observed regression
Evaluate a flag (early match)
Shard: flags-single
Allocations per operation 401.77 count/op 423.78 count/op 5.5% more Worth reviewing: observed regression
Evaluate a flag (early match)
Shard: flags-single
Time per operation 29.08 µs/op 32.59 µs/op 12.1% more time Worth reviewing: observed regression
Evaluate a flag (early match)
Shard: flags-single
Process CPU time per operation 29.07 µs/op 32.59 µs/op 12.1% more time Worth reviewing: observed regression
Evaluate a flag (late match)
Shard: flags-single
Allocated memory per operation 63.34 KiB/op 68.52 KiB/op 8.2% more memory Worth reviewing: observed regression
Evaluate a flag (late match)
Shard: flags-single
Allocations per operation 608.27 count/op 637.28 count/op 4.8% more Not flagged
Evaluate a flag (late match)
Shard: flags-single
Time per operation 40.42 µs/op 44.51 µs/op 10.1% more time Worth reviewing: observed regression
Evaluate a flag (late match)
Shard: flags-single
Process CPU time per operation 40.41 µs/op 44.51 µs/op 10.1% more time Worth reviewing: observed regression
Evaluate a flag (no match)
Shard: flags-single
Allocated memory per operation 61.97 KiB/op 67.15 KiB/op 8.4% more memory Worth reviewing: observed regression
Evaluate a flag (no match)
Shard: flags-single
Allocations per operation 591.77 count/op 620.78 count/op 4.9% more Not flagged
Evaluate a flag (no match)
Shard: flags-single
Time per operation 36.87 µs/op 40.45 µs/op 9.7% more time Worth reviewing: observed regression
Evaluate a flag (no match)
Shard: flags-single
Process CPU time per operation 36.87 µs/op 40.44 µs/op 9.7% more time Worth reviewing: observed regression
Evaluate a property-filtered flag
Shard: flags-single
Allocated memory per operation 19.38 KiB/op 22.05 KiB/op 13.7% more memory Worth reviewing: observed regression
Evaluate a property-filtered flag
Shard: flags-single
Allocations per operation 195.27 count/op 210.28 count/op 7.7% more Worth reviewing: observed regression
Evaluate a property-filtered flag
Shard: flags-single
Time per operation 16.96 µs/op 19.89 µs/op 17.3% more time Worth reviewing: observed regression
Evaluate a property-filtered flag
Shard: flags-single
Process CPU time per operation 16.96 µs/op 19.89 µs/op 17.3% more time Worth reviewing: observed regression
Evaluate a regex-filtered flag
Shard: flags-single
Allocated memory per operation 21.01 KiB/op 23.67 KiB/op 12.7% more memory Worth reviewing: observed regression
Evaluate a regex-filtered flag
Shard: flags-single
Allocations per operation 200.77 count/op 215.78 count/op 7.5% more Worth reviewing: observed regression
Evaluate a regex-filtered flag
Shard: flags-single
Time per operation 18.14 µs/op 21.32 µs/op 17.6% more time Worth reviewing: observed regression
Evaluate a regex-filtered flag
Shard: flags-single
Process CPU time per operation 18.14 µs/op 21.32 µs/op 17.5% more time Worth reviewing: observed regression
Evaluate a rollout flag
Shard: flags-single
Allocated memory per operation 14.89 KiB/op 17.19 KiB/op 15.4% more memory Worth reviewing: observed regression
Evaluate a rollout flag
Shard: flags-single
Allocations per operation 152.77 count/op 164.77 count/op 7.9% more Worth reviewing: observed regression
Evaluate a rollout flag
Shard: flags-single
Time per operation 13.34 µs/op 15.35 µs/op 15.1% more time Worth reviewing: observed regression
Evaluate a rollout flag
Shard: flags-single
Process CPU time per operation 13.34 µs/op 15.35 µs/op 15% more time Worth reviewing: observed regression
Evaluate a multivariate flag
Shard: flags-single
Allocated memory per operation 15.9 KiB/op 18.2 KiB/op 14.4% more memory Worth reviewing: observed regression
Evaluate a multivariate flag
Shard: flags-single
Allocations per operation 166.77 count/op 178.77 count/op 7.2% more Worth reviewing: observed regression
Evaluate a multivariate flag
Shard: flags-single
Time per operation 14.9 µs/op 16.93 µs/op 13.6% more time Worth reviewing: observed regression
Evaluate a multivariate flag
Shard: flags-single
Process CPU time per operation 14.9 µs/op 16.93 µs/op 13.6% more time Worth reviewing: observed regression

Values are medians of paired measurements. Not flagged does not mean unchanged. Unavailable means a measurement could not be provided, not zero. Estimated allocation measurements retain their instrumentation uncertainty. RSS measures the whole process, not just SDK allocations; observed peaks are sampled checkpoints. Paired ranges in the diagnostics describe variability, not confidence intervals.

Each shard uses its own runner; compare Before PR against With PR within a row, not across shards.

Compared 218ad1d1ab3a5786fc4982c889cede6fbaabe280 → 9e6146ba2c5cda021ddfa9e5d9aa9325b526cf3d.

Full report and diagnostics

102 metric rows; 102 rows shown in all results. Omitted or shortened data remain in comparison.json, including per-runner environments, resource limits, measurement methods, samples and checkpoints.

@marandaneto
marandaneto marked this pull request as ready for review November 20, 2026 10:28
@marandaneto
marandaneto requested a review from a team as a code owner November 20, 2026 10:28
@veria-ai

veria-ai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

PR overview

All previously flagged issues have been addressed. No open security concerns remain on this pull request.

Fixed/addressed: 2 · PR risk: 0/10

Reviews

@dustinbyrne dustinbyrne left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall the additive keyword-only API, bounded iterator validation, sentinel isolation, and compliance adapter wiring look solid. Left three inline items to address before approval (one Breaking omitted-condition-value bug on negated operators, plus two Concern gaps around eager condition-value validation on known-absent keys and type: "person_metadata" dynamic cohort filters) and one small Suggestion on Mapping/bytearray validation.

Notes on existing comments & follow-ups:

  • Suggestion (benchmark allocation delta — addressing the SDK performance report): A base-vs-head tracemalloc check confirms zero memory leak (net_delta=416B on both base and head). The ~+0.88 KiB/op short-lived allocation increase on the default (None, None) path comes from unconditionally calling _validate_known_absent_keys(None, None), allocating group_properties or {} in Client._properties_for_local_evaluation (posthog/client.py:6268-6283), and calling _mark_known_absent_properties. Remote/fallback calls also re-run _validate_known_absent_keys a second time inside _get_flags_decision (posthog/client.py:2341-2343). Consider short-circuiting when both known-absent arguments are None on the local-eval hot path and accepting pre-validated lists/dicts in internal _get_flags_decision (matching AsyncClient._get_flags_decision).
  • Follow-up (PostHog/posthog.com): Once this ships, contents/docs/feature-flags/local-evaluation/index.mdx (lines 365–367, which currently state is_not_set and early-access enrollment cannot be evaluated locally) and contents/docs/integrate/feature-flags-code/_snippets/feature-flags-code-api.mdx will need a follow-up docs update.

AI-assisted review.

Comment thread posthog/feature_flags.py Resolved
Comment thread posthog/feature_flags.py Resolved
Comment thread posthog/feature_flags.py Resolved
@dustinbyrne
dustinbyrne requested a review from a team November 24, 2026 03:42

@dustinbyrne dustinbyrne left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing all four prior threads across b142a176..98124ab5 — omitted/None condition values, skipping condition-value validation on known-absent keys, person_metadata isolation from known-absent listings, duplicate-key marking, and Mapping/bytearray input checks all look good now.

The filter-type scoping change in b6c0dd3b introduced two issues on group_property_keys_known_absent to address before approval (left inline): one Breaking cold-start lazy-load / snapshot-tearing bug in Client._properties_for_local_evaluation, and one Concern where legacy type: "group" / $group_key filters omitting group_type_index diverge from Rust /flags.

Notes on existing comments & follow-ups:

  • Suggestion (hot-path overhead — updating the prior note on the SDK performance report): Comparing 46a88b5c → 98124ab5 still shows zero memory leak (tracemalloc net delta ~1.5 KiB on head vs ~1.6 KiB on base), while the CI benchmark now flags 14 regressions (+5.9–6.7% short-lived allocated memory/op on flags-single, +5.2–5.4% CPU/time on Evaluate a flag (no match) and Evaluate all 10 flags). Alongside short-circuiting (None, None) before _validate_known_absent_keys/_mark_known_absent_properties and avoiding re-validation in internal _get_flags_decision, consider inlining _supplied_value in _match_property_value (posthog/feature_flags.py:1629) with a single type(override_value) is _KnownAbsent check so the non-known-absent hot loop pays neither an extra function call nor a second isinstance check per property.
  • Follow-up (PostHog/posthog.com): Post-release docs updates noted in the prior review remain unchanged.

AI-assisted review.

Comment thread posthog/client.py Resolved
Comment thread posthog/feature_flags.py Resolved
@dustinbyrne
dustinbyrne requested a review from a team November 24, 2026 21:11
Build the local evaluation property maps after definitions load, from the same snapshot that evaluates the flags, so a cold-start client marks group keys with their group type index.
Comment thread posthog/client.py Resolved
Store the known-absent listing digest with the cached result under the
plain flag key instead of a per-listing key. A different listing gets no
fallback and a new listing replaces the old entry, so distinct listings
no longer grow the cache. Redis entries without a digest read as
unlisted.
…mespace

Released SDKs up to 7.37.0 serve any Redis entry under the plain flag
key and ignore the listing digest. Store listed results in a sibling
Redis namespace those versions never read, with one listed slot per
user and flag. The memory cache keeps the listed slot apart too, so a
listed write never evicts the unlisted fallback.
Comment thread posthog/utils.py Resolved
A group flag without a usable group key no longer resolves false before its
conditions run. Each condition uses its own aggregation, an explicit null
meaning the person, so person conditions of a group flag still run, directly
and as a dependency, and read person properties and the person bucketing value.

A group flag with a holdout above 0% and no usable group key is now
inconclusive with reason missing_context instead of false, since the flags
service hashes an empty key for the holdout.
…ests

Main #1288 (sdk-specs#251) sends a person_metadata filter to /flags instead of
matching it against a supplied created_at, even when created_at is listed. The
test that expected a person_metadata filter to read the supplied value is
deleted; test_listed_key_does_not_resolve_a_person_metadata_filter already
asserts the new behavior.

The duplicate person key test used a person_metadata filter to read the value
outside the listing's scope. No supported filter reads a person listing outside
its scope now, so it checks that a duplicated person key still reads as absent.
The group duplicate test keeps covering the out-of-scope read.
The listed namespace replaced the prefix's last character, so prefixes
project-1 and project-2 both became project-_known_absent: and two apps
sharing Redis could read each other's listed entries. The listed namespace
now holds the full prefix behind a leading character that differs from the
prefix's first one, so it still never extends the unlisted namespace.
Unlisted keys are unchanged.
A filter without a type, or with a null or empty type, is a person filter
(sdk-specs#251, and the flags service defaults the type to person). The person
listing only applied to filters typed "person", so an untyped filter on a listed
key read the supplied value. Condition filters and cohort leaves both go through
the same check. Group, cohort and flag filters are unchanged.
…oups

A direct match_feature_flag_properties call that passes no groups matches the flag-level group's conditions against the passed properties and bucketing value, as on main. Client paths still pass an explicit groups mapping and skip group conditions without a usable key.

@ioannisj ioannisj left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 An AI agent wrote this on behalf of @ioannisj.

Nothing blocking from me. The one thing worth settling is whether a bad known-absent list should drop the whole capture event. The rest are smaller: a person filter, or a filter for another group type, inside a group condition still reads the condition's group where go, js and rs don't, a docstring promises no /flags fallback in cases that still fall back, and a direct matcher call stops matching when group_type_mapping is left out.

Comment thread posthog/feature_flags.py
return properties, bucketing_value

group_name = group_type_mapping.get(str(condition_aggregation))
if not group_name or not _is_usable_group_key((groups or {}).get(group_name)):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 An AI agent wrote this on behalf of @ioannisj.

A direct match_feature_flag_properties call that passes groups but no group_type_mapping now returns False for a condition on the flag's own group. The mapping lookup comes back empty, so the condition is skipped. On main that call matched, because a condition on the flag's own aggregation never read the mapping:

match_feature_flag_properties(flag, "acme", {"plan": "pro"}, bucketing_value="acme",
    groups={"company": "acme"}, group_properties={"company": {"plan": "pro"}})
# main: True, this PR: False

The client always passes the mapping, so only direct callers of this public helper hit it. Could the groups is None shortcut above also cover a missing mapping when the condition is on the flag's own aggregation? groups={} would still skip.

Comment thread posthog/client.py
"group_properties": send_feature_flags.get("group_properties"),
"flag_keys_filter": send_feature_flags.get("flag_keys_filter"),
}
# Validate here so invalid keys fail the whole capture call instead of

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 An AI agent wrote this on behalf of @ioannisj.

[question] Is dropping the whole event the intended contract here? With an over-limit or wrongly typed list, capture returns None and nothing is enqueued, so a bad known-absent list loses the event itself, not just the $feature/* enrichment. On main the same call still sends the event.

If it's deliberate, I'd mention it in .sampo/changesets/known-absent-property-keys.md, since that's the one path where the list costs analytics data. If not, validating inside the enrichment try in _capture and sending the event without flag properties would keep it. Which one did you have in mind?

Comment thread posthog/client.py
person_property_keys_known_absent: Person property keys the caller knows are
absent for this person. Local evaluation treats a listed key as absent,
even when ``person_properties`` supplies a value for it: ``is_not_set``
and the negated operators match, and every other operator does not, with

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 An AI agent wrote this on behalf of @ioannisj.

[suggestion] "every other operator does not, with no remote fallback" is a bit stronger than what the matcher does. An unknown operator, or an omitted or null condition value on a listed key, still raises inconclusive and falls back to /flags (posthog/feature_flags.py:1835).

Maybe something like "for supported operators with a condition value; an unknown operator or an omitted or null value still falls back to /flags"? The same sentence is in posthog/__init__.py:1290 too.

Comment thread posthog/feature_flags.py
_evaluation_context=_evaluation_context,
)
_assert_property_filter_type_supported(prop)
return match_property(prop, properties, property_matching_version)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[suggestion] A type: "person" filter in a group-aggregated condition is matched against the group's properties here, so it never sees the person properties or the person known-absent listing.

posthog-go routes that filter to the person properties in featureflags.go#L2191 (PostHog/posthog-go#461), and posthog-js does the same in feature-flags.ts#L847 (PostHog/posthog-js#5819), which is also what the spec's filter-type table says. Ruby (PostHog/posthog-ruby#369) and php (PostHog/posthog-php#328) have the same gap.

Worth reading a person filter in a group condition from the person properties and listing here too?

Comment thread posthog/feature_flags.py
filter_group_type_index = prop.get("group_type_index")
if filter_group_type_index is None:
return True
return self.group_type_index is not None and self.group_type_index == str(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[suggestion] When a group filter's own group_type_index names another group type, applies_to only withholds the listing, and the filter still reads the condition's group properties, so the other group type's properties and listing are never used.

posthog-rs reads that group type's properties and listing in feature_flags.rs#L1247 (PostHog/posthog-rs#388), and go and dotnet do the same. Ruby (PostHog/posthog-ruby#369), php (PostHog/posthog-php#328) and js (PostHog/posthog-js#5819) still read the condition's group.

Would it be worth routing that filter to its own group type's properties and known-absent keys?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants