Skip to content

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

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

marandaneto wants to merge 23 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 only apply to person filters, group keys only apply to group filters of their own group type, person_metadata filters (such as a created_at cohort leaf) never resolve from a listing and read the supplied value instead. 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 group-aggregated dependency whose group isn't supplied 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: a flag aggregated on that group type resolves as false locally with no /flags request (also as a dependency), and a mixed flag skips its conditions on that group type. Before, an empty string was used as the bucketing key and the other kinds fell back to /flags.

/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. Known limit: a flag literally named <flag>:known_absent:<64-character hex digest> shares a cache slot with that flag's listed entry for the same user. A wrong value is never returned, but one entry can evict the other's outage fallback. 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.

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).

📝 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

46 changes worth reviewing: 46 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 cohort-filtered flag Time per operation 10.67 µs/op 12.48 µs/op 16.9% more time
Evaluate a cohort-filtered flag Process CPU time per operation 10.67 µs/op 12.48 µs/op 16.9% more time
Evaluate all 1,000 flags Time per operation 7.63 ms/op 8.81 ms/op 15.4% more time
Evaluate all 1,000 flags Process CPU time per operation 7.63 ms/op 8.81 ms/op 15.4% more time
Evaluate all 100 flags Process CPU time per operation 769.57 µs/op 887.41 µs/op 15.3% more time
Evaluate all 100 flags Time per operation 769.53 µs/op 887.35 µs/op 15.3% more time
Evaluate all 10 flags Process CPU time per operation 82.13 µs/op 94.38 µs/op 14.9% more time
Evaluate all 10 flags Time per operation 82.13 µs/op 94.38 µs/op 14.9% more time
Evaluate a rollout flag Allocated memory per operation 14.89 KiB/op 17.09 KiB/op 14.7% more memory
Evaluate one boolean flag Allocated memory per operation 15.74 KiB/op 17.94 KiB/op 13.9% more memory
Evaluate a multivariate flag Allocated memory per operation 15.9 KiB/op 18.1 KiB/op 13.8% more memory
Evaluate a rollout flag Process CPU time per operation 7.2 µs/op 8.17 µs/op 13.5% more time

Showing the 12 largest flagged changes; 34 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.51 count/op 1,348.51 count/op 0.2% more Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Time per operation 76.67 µs/op 76.33 µs/op 0.4% less time Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Idle process memory (RSS) 37.67 MiB 37.68 MiB <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Observed peak process memory (RSS) 40.12 MiB 40.14 MiB <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Process memory after settling (RSS) 40.12 MiB 40.14 MiB <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Process CPU time per operation 79.13 µs/op 79.23 µs/op 0.1% more time Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Lifetime peak process memory (RSS) 40.62 MiB 40.62 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.51 count/op 1,340.51 count/op 0.2% more Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Time per operation 99.98 µs/op 99.42 µs/op 0.6% less time Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Idle process memory (RSS) 41.29 MiB 41.25 MiB <0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Observed peak process memory (RSS) 47.07 MiB 47.04 MiB <0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Process memory after settling (RSS) 47.07 MiB 47.04 MiB <0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Process CPU time per operation 95.46 µs/op 97.22 µs/op 1.8% more time Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Lifetime peak process memory (RSS) 51.53 MiB 51.52 MiB <0.1% less memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Allocated memory per operation 138.73 KiB/op 138.85 KiB/op <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Allocations per operation 1,390.3 count/op 1,393.29 count/op 0.2% more Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Time per operation 89.99 µs/op 89.94 µs/op <0.1% less time Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Idle process memory (RSS) 37.6 MiB 37.67 MiB 0.2% more memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Observed peak process memory (RSS) 37.78 MiB 37.86 MiB 0.2% more memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Process memory after settling (RSS) 37.78 MiB 37.86 MiB 0.2% more memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Process CPU time per operation 91.42 µs/op 91.01 µs/op 0.5% less time Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Lifetime peak process memory (RSS) 40.62 MiB 40.62 MiB No observed change Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Allocated memory per operation 190.9 KiB/op 191.02 KiB/op <0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Allocations per operation 1,382.19 count/op 1,385.2 count/op 0.2% more Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Time per operation 105.46 µs/op 105.97 µs/op 0.5% more time Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Idle process memory (RSS) 41.1 MiB 41.07 MiB <0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Observed peak process memory (RSS) 41.55 MiB 41.57 MiB <0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Process memory after settling (RSS) 41.16 MiB 41.15 MiB <0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Process CPU time per operation 103.09 µs/op 102.14 µs/op 0.9% less time Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Lifetime peak process memory (RSS) 41.52 MiB 41.46 MiB 0.2% less memory Not flagged
Queue an event (32-byte payload)
Shard: capture
Caller-thread CPU time per operation 57.07 µs/op 57.32 µs/op 0.4% more time Not flagged
Queue an event (32-byte payload)
Shard: capture
Time per operation 57.06 µs/op 57.32 µs/op 0.4% more time Not flagged
Queue an event (4,096-byte payload)
Shard: capture
Caller-thread CPU time per operation 57.33 µs/op 57.52 µs/op 0.3% more time Not flagged
Queue an event (4,096-byte payload)
Shard: capture
Time per operation 57.33 µs/op 57.52 µs/op 0.3% more time Not flagged
Evaluate all 10 flags
Shard: flags-scaling
Allocated memory per operation 225.43 KiB/op 245.66 KiB/op 9% more memory Worth reviewing: observed regression
Evaluate all 10 flags
Shard: flags-scaling
Allocations per operation 2,279.42 count/op 2,406.96 count/op 5.6% more Worth reviewing: observed regression
Evaluate all 10 flags
Shard: flags-scaling
Time per operation 82.13 µs/op 94.38 µs/op 14.9% more time Worth reviewing: observed regression
Evaluate all 10 flags
Shard: flags-scaling
Process CPU time per operation 82.13 µs/op 94.38 µs/op 14.9% more time Worth reviewing: observed regression
Evaluate all 100 flags
Shard: flags-scaling
Allocated memory per operation 2.17 MiB/op 2.36 MiB/op 8.7% more memory Worth reviewing: observed regression
Evaluate all 100 flags
Shard: flags-scaling
Allocations per operation 22,413.69 count/op 23,653.12 count/op 5.5% more Worth reviewing: observed regression
Evaluate all 100 flags
Shard: flags-scaling
Time per operation 769.53 µs/op 887.35 µs/op 15.3% more time Worth reviewing: observed regression
Evaluate all 100 flags
Shard: flags-scaling
Process CPU time per operation 769.57 µs/op 887.41 µs/op 15.3% more time Worth reviewing: observed regression
Evaluate all 1,000 flags
Shard: flags-scaling
Allocated memory per operation 21.63 MiB/op 23.51 MiB/op 8.7% more memory Worth reviewing: observed regression
Evaluate all 1,000 flags
Shard: flags-scaling
Allocations per operation 223,655.44 count/op 236,009.88 count/op 5.5% more Worth reviewing: observed regression
Evaluate all 1,000 flags
Shard: flags-scaling
Time per operation 7.63 ms/op 8.81 ms/op 15.4% more time Worth reviewing: observed regression
Evaluate all 1,000 flags
Shard: flags-scaling
Process CPU time per operation 7.63 ms/op 8.81 ms/op 15.4% more time Worth reviewing: observed regression
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Idle process memory (RSS) 43.97 MiB 43.97 MiB <0.1% less memory Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Observed peak process memory (RSS) 44.29 MiB 44.29 MiB <0.1% more memory Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Process memory after settling (RSS) 44.29 MiB 44.29 MiB <0.1% more memory Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Lifetime peak process memory (RSS) 44.09 MiB 43.94 MiB 0.3% less memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Idle process memory (RSS) 43.1 MiB 43.12 MiB <0.1% more memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Observed peak process memory (RSS) 43.1 MiB 43.13 MiB <0.1% more memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Process memory after settling (RSS) 43.07 MiB 43.13 MiB 0.1% more memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Lifetime peak process memory (RSS) 43.5 MiB 42.95 MiB 1.3% less memory Not flagged
Evaluate one boolean flag
Shard: flags-single
Allocated memory per operation 15.74 KiB/op 17.94 KiB/op 13.9% 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 7.64 µs/op 8.63 µs/op 13% more time Worth reviewing: observed regression
Evaluate one boolean flag
Shard: flags-single
Process CPU time per operation 7.64 µs/op 8.63 µs/op 13% more time Worth reviewing: observed regression
Evaluate a cohort-filtered flag
Shard: flags-single
Allocated memory per operation 24.6 KiB/op 27.59 KiB/op 12.2% more memory Worth reviewing: observed regression
Evaluate a cohort-filtered flag
Shard: flags-single
Allocations per operation 239.28 count/op 257.28 count/op 7.5% more Worth reviewing: observed regression
Evaluate a cohort-filtered flag
Shard: flags-single
Time per operation 10.67 µs/op 12.48 µs/op 16.9% more time Worth reviewing: observed regression
Evaluate a cohort-filtered flag
Shard: flags-single
Process CPU time per operation 10.67 µs/op 12.48 µs/op 16.9% more time Worth reviewing: observed regression
Evaluate a flag (early match)
Shard: flags-single
Allocated memory per operation 39.81 KiB/op 43.77 KiB/op 9.9% more memory Worth reviewing: observed regression
Evaluate a flag (early match)
Shard: flags-single
Allocations per operation 388.27 count/op 413.78 count/op 6.6% more Worth reviewing: observed regression
Evaluate a flag (early match)
Shard: flags-single
Time per operation 15.25 µs/op 16.96 µs/op 11.2% more time Worth reviewing: observed regression
Evaluate a flag (early match)
Shard: flags-single
Process CPU time per operation 15.25 µs/op 16.96 µs/op 11.2% more time Worth reviewing: observed regression
Evaluate a flag (late match)
Shard: flags-single
Allocated memory per operation 60.59 KiB/op 65.94 KiB/op 8.8% more memory Worth reviewing: observed regression
Evaluate a flag (late match)
Shard: flags-single
Allocations per operation 584.27 count/op 620.28 count/op 6.2% more Worth reviewing: observed regression
Evaluate a flag (late match)
Shard: flags-single
Time per operation 21.74 µs/op 23.89 µs/op 9.9% more time Worth reviewing: observed regression
Evaluate a flag (late match)
Shard: flags-single
Process CPU time per operation 21.74 µs/op 23.89 µs/op 9.9% more time Worth reviewing: observed regression
Evaluate a flag (no match)
Shard: flags-single
Allocated memory per operation 59.22 KiB/op 64.57 KiB/op 9% more memory Worth reviewing: observed regression
Evaluate a flag (no match)
Shard: flags-single
Allocations per operation 567.77 count/op 603.77 count/op 6.3% more Worth reviewing: observed regression
Evaluate a flag (no match)
Shard: flags-single
Time per operation 20.72 µs/op 23.22 µs/op 12.1% more time Worth reviewing: observed regression
Evaluate a flag (no match)
Shard: flags-single
Process CPU time per operation 20.72 µs/op 23.22 µs/op 12.1% more time Worth reviewing: observed regression
Evaluate a property-filtered flag
Shard: flags-single
Allocated memory per operation 19.04 KiB/op 21.6 KiB/op 13.5% more memory Worth reviewing: observed regression
Evaluate a property-filtered flag
Shard: flags-single
Allocations per operation 192.27 count/op 207.28 count/op 7.8% more Worth reviewing: observed regression
Evaluate a property-filtered flag
Shard: flags-single
Time per operation 8.6 µs/op 10.06 µs/op 17% more time Not flagged
Evaluate a property-filtered flag
Shard: flags-single
Process CPU time per operation 8.6 µs/op 10.06 µs/op 16.9% more time Not flagged
Evaluate a regex-filtered flag
Shard: flags-single
Allocated memory per operation 20.66 KiB/op 23.23 KiB/op 12.4% more memory Worth reviewing: observed regression
Evaluate a regex-filtered flag
Shard: flags-single
Allocations per operation 197.77 count/op 212.78 count/op 7.6% more Worth reviewing: observed regression
Evaluate a regex-filtered flag
Shard: flags-single
Time per operation 9.15 µs/op 10.32 µs/op 12.8% more time Worth reviewing: observed regression
Evaluate a regex-filtered flag
Shard: flags-single
Process CPU time per operation 9.15 µs/op 10.32 µs/op 12.8% more time Worth reviewing: observed regression
Evaluate a rollout flag
Shard: flags-single
Allocated memory per operation 14.89 KiB/op 17.09 KiB/op 14.7% 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 7.2 µs/op 8.17 µs/op 13.5% more time Worth reviewing: observed regression
Evaluate a rollout flag
Shard: flags-single
Process CPU time per operation 7.2 µs/op 8.17 µs/op 13.5% more time Worth reviewing: observed regression
Evaluate a multivariate flag
Shard: flags-single
Allocated memory per operation 15.9 KiB/op 18.1 KiB/op 13.8% 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 7.91 µs/op 8.9 µs/op 12.5% more time Worth reviewing: observed regression
Evaluate a multivariate flag
Shard: flags-single
Process CPU time per operation 7.91 µs/op 8.9 µs/op 12.5% 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 eeb6d675da3b8977177bd71805706b13a6d65da8 → 2705b8c465a39bed659c905e2b34b25a51d1eb78.

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

The PR adds support for known-absent property keys in local feature-flag evaluation, including separate cache entries for different property-key listings.

One issue remains open: listing-specific cache entries can grow without bound for a single flag and user, and expired entries are retained within the current definition generation. If an application derives these listings from request data, an attacker could drive host-memory growth; exploitability depends on how the application supplies those lists. No issues have been addressed yet.

Open issues (1)

Fixed/addressed: 0 · PR risk: 4/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
self.flag_cache.set_cached_flag(
distinct_id, key, cached_flag_result, local_definition_version
distinct_id,
cache_flag_key,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Medium: Bound listing-specific cache entries

cache_flag_key creates a separate entry for every listing, but FlagCache bounds only distinct IDs and does not prune expired entries within the current definition generation; checking the key/cache functions confirmed that 2,000 different one-key listings retain 2,000 entries for one flag/user even with size=1, including after expiry. If an application derives these lists from request data, this permits unbounded host-memory growth, so cap cached variants per user or total entries and evict expired entries while preserving listing isolation.

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.

2 participants