Repository navigation
Conversation
Local evaluation already evaluates a config version 2 definition when one is loaded. The definitions request now asks for them with v=2, on the first load and on every poll. The version 1 path and remote /flags requests are unchanged, and for a project without such flags the response is the same. The compliance adapter declares feature_flags_local_evaluation_v2 and lets /get_feature_flag use the default getter on the client with definitions (allow_remote_fallback).
SDK performance: posthog-pythonBenchmarks completed. No changes flagged for review. 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. View all results
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 102 metric rows; 102 rows shown in all results. Omitted or shortened data remain in |
…efinitions A client that fetched the v=2 feed kept its ETag after it loaded other definitions from a shared flag definition cache, such as the legacy feed an older release wrote. Its next request then got 304 for the unchanged v=2 feed and kept the legacy definitions, without config version 2 flags, until the feed changed. Loading definitions from the cache that differ from the installed ones now clears the ETag, so the next request gets the whole feed and stores it for the other readers. The same definitions keep it.
…h' into feat/flag-rules-v2-request-v2
…h' into feat/flag-rules-v2-request-v2 # Conflicts: # posthog/client.py
💡 Motivation and Context
Stacked on #1295, which evaluates flags whose
filters.versionis 2 when they are loaded but does not ask for them. This PR asks for them: the definitions request sendsv=2, on the first load and on every poll, including a poll that sends the ETag and gets304. The version 1 path and the remote/flagspath are unchanged. For a project without such flags, and from a server that ignoresv, the response is the same as today.Do not merge before #1250 and #1295 are merged, and before the server answers
v=2definitions requests everywhere this SDK calls it. Requestingv=2changes local results wherever a project holds config version 2 flags.Details
_fetch_feature_flags_from_api, gains&v=2. Its polls go through the same path.flag_definition_cache_provider, a client that loads definitions from the cache that differ from the ones it fetched (for example the legacy feed an older release wrote) drops its ETag. Otherwise its next request got304for the unchanged v=2 feed and kept definitions without the config version 2 flags until the feed changed. Loading the same definitions keeps the ETag.feature_flags_local_evaluation_v2, and/get_feature_flaghonorsallow_remote_fallback: the SDK's default getter on the client with definitions, local first and then/flags, with the read's events. It conflicts withonly_evaluate_locallyandforce_remote(400).feature_flags_local_evaluation_v2(feat(flags): add the local evaluation suite for config version 2 flags posthog-sdk-test-harness#123).minor, because local results change wherever a project holds such flags.💚 How did you test it?
Tests and harness runs
posthog/test/test_feature_flags_v2_dispatch.py:test_every_definitions_request_asks_for_the_version_2_feedreplaces the test that pinned the old request. It checks the URL of a first load, a poll answered304with the feed's ETag, and a later poll, and that the304keeps the loaded config version 2 definitions. It failed before the change.test_definitions_from_the_cache_do_not_keep_the_etag_of_other_definitions(fails without the cache change) andtest_the_same_definitions_from_the_cache_keep_the_etag.sdk_compliance_adapter/test_adapter.py: the capability, the conflicts, and the default getter with and without a local result, written first.ruff format --check .,ruff check ., mypy with the baseline,make public_api_check(unchanged),python -W error -c "import posthog", and the full suite (9296 passed; 3 fork tests intest_metrics_autocapture.pyfail on this machine with or without this change).feature_flags_local_evaluation_v2passes 306 of 306 (the same adapter on feat(flags): choose the local evaluator by each flag's config version #1295, withoutv=2, fails 230). All suites it selects pass, 717 of 717:capture_v1118,capture_ai_v1122,feature_flags17,feature_flags_v4150,feature_flags_local_evaluation4 andfeature_flags_local_evaluation_v2306. After the cache change,feature_flags_local_evaluation_v2again passes 306 of 306.📝 Checklist
If releasing new changes
sampo addto generate a changeset file🤖 Agent context
Autonomy: Human-driven (agent-assisted)
🤖 Generated with Claude Code