Skip to content

feat(flags): request the v=2 definitions feed - #1314

Draft
andehen wants to merge 5 commits into
feat/flag-rules-v2-local-dispatchfrom
feat/flag-rules-v2-request-v2
Draft

andehen wants to merge 5 commits into
feat/flag-rules-v2-local-dispatchfrom
feat/flag-rules-v2-request-v2

Conversation

@andehen

@andehen andehen commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

💡 Motivation and Context

Stacked on #1295, which evaluates flags whose filters.version is 2 when they are loaded but does not ask for them. This PR asks for them: the definitions request sends v=2, on the first load and on every poll, including a poll that sends the ETag and gets 304. The version 1 path and the remote /flags path are unchanged. For a project without such flags, and from a server that ignores v, the response is the same as today.

Do not merge before #1250 and #1295 are merged, and before the server answers v=2 definitions requests everywhere this SDK calls it. Requesting v=2 changes local results wherever a project holds config version 2 flags.

Details
  • Request. One call site, _fetch_feature_flags_from_api, gains &v=2. Its polls go through the same path.
  • Definition cache. With a 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 got 304 for 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.
  • Compliance adapter. It declares feature_flags_local_evaluation_v2, and /get_feature_flag honors allow_remote_fallback: the SDK's default getter on the client with definitions, local first and then /flags, with the read's events. It conflicts with only_evaluate_locally and force_remote (400).
  • Spec. No published sdk-spec covers this yet; the draft is docs(flags): propose local evaluation of config version 2 flags sdk-specs#244 ("Requesting the version 2 feed"). The cross-SDK reference is the harness suite feature_flags_local_evaluation_v2 (feat(flags): add the local evaluation suite for config version 2 flags posthog-sdk-test-harness#123).
  • Changeset. 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_feed replaces the test that pinned the old request. It checks the URL of a first load, a poll answered 304 with the feed's ETag, and a later poll, and that the 304 keeps the loaded config version 2 definitions. It failed before the change.
  • The same file: test_definitions_from_the_cache_do_not_keep_the_etag_of_other_definitions (fails without the cache change) and test_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.
  • Locally: 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 in test_metrics_autocapture.py fail on this machine with or without this change).
  • The harness branch of feat(flags): add the local evaluation suite for config version 2 flags posthog-sdk-test-harness#123 against this adapter, run locally without Docker: feature_flags_local_evaluation_v2 passes 306 of 306 (the same adapter on feat(flags): choose the local evaluator by each flag's config version #1295, without v=2, fails 230). All suites it selects pass, 717 of 717: capture_v1 118, capture_ai_v1 122, feature_flags 17, feature_flags_v4 150, feature_flags_local_evaluation 4 and feature_flags_local_evaluation_v2 306. After the cache change, feature_flags_local_evaluation_v2 again passes 306 of 306.

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

🤖 Generated with Claude Code

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).
@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

SDK performance: posthog-python

Benchmarks 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
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.67 KiB/op No observed change Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Allocations per operation 1,345.53 count/op 1,345.53 count/op No observed change Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Time per operation 142.51 µs/op 149.73 µs/op 5.1% more time Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Idle process memory (RSS) 37.92 MiB 38.02 MiB 0.3% more memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Observed peak process memory (RSS) 40.4 MiB 40.51 MiB 0.3% more memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Process memory after settling (RSS) 40.4 MiB 40.51 MiB 0.3% more memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Process CPU time per operation 142.58 µs/op 151.67 µs/op 6.4% more time Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Lifetime peak process memory (RSS) 40.65 MiB 40.74 MiB 0.2% more memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Allocated memory per operation 185.76 KiB/op 185.76 KiB/op <0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Allocations per operation 1,337.57 count/op 1,337.56 count/op <0.1% fewer Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Time per operation 181.56 µs/op 178.37 µs/op 1.8% less time Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Idle process memory (RSS) 41.66 MiB 41.6 MiB 0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Observed peak process memory (RSS) 47.48 MiB 47.43 MiB 0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Process memory after settling (RSS) 47.48 MiB 47.43 MiB 0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Process CPU time per operation 176.32 µs/op 172.45 µs/op 2.2% less time Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Lifetime peak process memory (RSS) 51.85 MiB 51.78 MiB 0.1% less memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Allocated memory per operation 138.74 KiB/op 138.74 KiB/op <0.1% less memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Allocations per operation 1,390.45 count/op 1,390.42 count/op <0.1% fewer Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Time per operation 153.41 µs/op 152.7 µs/op 0.5% less time Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Idle process memory (RSS) 37.91 MiB 37.87 MiB 0.1% less memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Observed peak process memory (RSS) 38.12 MiB 38.07 MiB 0.1% less memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Process memory after settling (RSS) 38.12 MiB 38.07 MiB 0.1% less memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Process CPU time per operation 151.45 µs/op 149.57 µs/op 1.2% less time Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Lifetime peak process memory (RSS) 40.45 MiB 40.45 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 190.92 KiB/op <0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Allocations per operation 1,382.36 count/op 1,382.36 count/op <0.1% fewer Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Time per operation 189.77 µs/op 190.28 µs/op 0.3% more time Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Idle process memory (RSS) 41.54 MiB 41.5 MiB 0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Observed peak process memory (RSS) 42.05 MiB 42 MiB 0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Process memory after settling (RSS) 41.63 MiB 41.58 MiB 0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Process CPU time per operation 182 µs/op 183.57 µs/op 0.9% more time Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Lifetime peak process memory (RSS) 41.9 MiB 41.89 MiB <0.1% less memory Not flagged
Queue an event (32-byte payload)
Shard: capture
Caller-thread CPU time per operation 110.69 µs/op 105.25 µs/op 4.9% less time Not flagged
Queue an event (32-byte payload)
Shard: capture
Time per operation 113.55 µs/op 108.88 µs/op 4.1% less time Not flagged
Queue an event (4,096-byte payload)
Shard: capture
Caller-thread CPU time per operation 110.23 µs/op 114.09 µs/op 3.5% more time Not flagged
Queue an event (4,096-byte payload)
Shard: capture
Time per operation 111.96 µs/op 118.15 µs/op 5.5% more time Not flagged
Evaluate all 10 flags
Shard: flags-scaling
Allocated memory per operation 229.39 KiB/op 229.39 KiB/op No observed change Not flagged
Evaluate all 10 flags
Shard: flags-scaling
Allocations per operation 2,330.43 count/op 2,330.43 count/op No observed change Not flagged
Evaluate all 10 flags
Shard: flags-scaling
Time per operation 80.06 µs/op 78.19 µs/op 2.3% less time Not flagged
Evaluate all 10 flags
Shard: flags-scaling
Process CPU time per operation 80.06 µs/op 78.2 µs/op 2.3% less time Not flagged
Evaluate all 100 flags
Shard: flags-scaling
Allocated memory per operation 2.21 MiB/op 2.21 MiB/op No observed change Not flagged
Evaluate all 100 flags
Shard: flags-scaling
Allocations per operation 22,914.75 count/op 22,914.75 count/op No observed change Not flagged
Evaluate all 100 flags
Shard: flags-scaling
Time per operation 756.38 µs/op 777.08 µs/op 2.7% more time Not flagged
Evaluate all 100 flags
Shard: flags-scaling
Process CPU time per operation 756.45 µs/op 777.09 µs/op 2.7% more time Not flagged
Evaluate all 1,000 flags
Shard: flags-scaling
Allocated memory per operation 22.01 MiB/op 22.01 MiB/op No observed change Not flagged
Evaluate all 1,000 flags
Shard: flags-scaling
Allocations per operation 228,656.5 count/op 228,656.5 count/op No observed change Not flagged
Evaluate all 1,000 flags
Shard: flags-scaling
Time per operation 7.47 ms/op 7.33 ms/op 1.9% less time Not flagged
Evaluate all 1,000 flags
Shard: flags-scaling
Process CPU time per operation 7.47 ms/op 7.33 ms/op 1.9% less time Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Idle process memory (RSS) 43.91 MiB 43.94 MiB <0.1% more memory Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Observed peak process memory (RSS) 44.34 MiB 44.35 MiB <0.1% more memory Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Process memory after settling (RSS) 44.34 MiB 44.35 MiB <0.1% more memory Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Lifetime peak process memory (RSS) 44.08 MiB 44.05 MiB <0.1% less memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Idle process memory (RSS) 43.57 MiB 43.6 MiB <0.1% more memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Observed peak process memory (RSS) 43.58 MiB 43.61 MiB <0.1% more memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Process memory after settling (RSS) 43.58 MiB 43.61 MiB <0.1% more memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Lifetime peak process memory (RSS) 43.94 MiB 43.4 MiB 1.2% less memory Not flagged
Evaluate one boolean flag
Shard: flags-single
Allocated memory per operation 16.18 KiB/op 16.18 KiB/op No observed change Not flagged
Evaluate one boolean flag
Shard: flags-single
Allocations per operation 168.77 count/op 168.77 count/op No observed change Not flagged
Evaluate one boolean flag
Shard: flags-single
Time per operation 6.94 µs/op 6.89 µs/op 0.6% less time Not flagged
Evaluate one boolean flag
Shard: flags-single
Process CPU time per operation 6.94 µs/op 6.89 µs/op 0.6% less time Not flagged
Evaluate a cohort-filtered flag
Shard: flags-single
Allocated memory per operation 25.03 KiB/op 25.03 KiB/op No observed change Not flagged
Evaluate a cohort-filtered flag
Shard: flags-single
Allocations per operation 245.28 count/op 245.28 count/op No observed change Not flagged
Evaluate a cohort-filtered flag
Shard: flags-single
Time per operation 9.03 µs/op 8.98 µs/op 0.6% less time Not flagged
Evaluate a cohort-filtered flag
Shard: flags-single
Process CPU time per operation 9.03 µs/op 8.98 µs/op 0.6% less time Not flagged
Evaluate a flag (early match)
Shard: flags-single
Allocated memory per operation 40.25 KiB/op 40.25 KiB/op No observed change Not flagged
Evaluate a flag (early match)
Shard: flags-single
Allocations per operation 394.27 count/op 394.27 count/op No observed change Not flagged
Evaluate a flag (early match)
Shard: flags-single
Time per operation 13.07 µs/op 13.07 µs/op <0.1% less time Not flagged
Evaluate a flag (early match)
Shard: flags-single
Process CPU time per operation 13.07 µs/op 13.07 µs/op <0.1% less time Not flagged
Evaluate a flag (late match)
Shard: flags-single
Allocated memory per operation 61.03 KiB/op 61.03 KiB/op No observed change Not flagged
Evaluate a flag (late match)
Shard: flags-single
Allocations per operation 590.27 count/op 590.27 count/op No observed change Not flagged
Evaluate a flag (late match)
Shard: flags-single
Time per operation 19.09 µs/op 18.79 µs/op 1.6% less time Not flagged
Evaluate a flag (late match)
Shard: flags-single
Process CPU time per operation 19.09 µs/op 18.79 µs/op 1.6% less time Not flagged
Evaluate a flag (no match)
Shard: flags-single
Allocated memory per operation 59.66 KiB/op 59.66 KiB/op No observed change Not flagged
Evaluate a flag (no match)
Shard: flags-single
Allocations per operation 573.77 count/op 573.77 count/op No observed change Not flagged
Evaluate a flag (no match)
Shard: flags-single
Time per operation 18.95 µs/op 18.82 µs/op 0.7% less time Not flagged
Evaluate a flag (no match)
Shard: flags-single
Process CPU time per operation 18.95 µs/op 18.82 µs/op 0.7% less time Not flagged
Evaluate a property-filtered flag
Shard: flags-single
Allocated memory per operation 19.48 KiB/op 19.48 KiB/op No observed change Not flagged
Evaluate a property-filtered flag
Shard: flags-single
Allocations per operation 198.27 count/op 198.27 count/op No observed change Not flagged
Evaluate a property-filtered flag
Shard: flags-single
Time per operation 7.44 µs/op 7.56 µs/op 1.6% more time Not flagged
Evaluate a property-filtered flag
Shard: flags-single
Process CPU time per operation 7.44 µs/op 7.56 µs/op 1.6% more time Not flagged
Evaluate a regex-filtered flag
Shard: flags-single
Allocated memory per operation 21.1 KiB/op 21.1 KiB/op No observed change Not flagged
Evaluate a regex-filtered flag
Shard: flags-single
Allocations per operation 203.77 count/op 203.77 count/op No observed change Not flagged
Evaluate a regex-filtered flag
Shard: flags-single
Time per operation 7.99 µs/op 7.98 µs/op 0.1% less time Not flagged
Evaluate a regex-filtered flag
Shard: flags-single
Process CPU time per operation 7.99 µs/op 7.98 µs/op 0.1% less time Not flagged
Evaluate a rollout flag
Shard: flags-single
Allocated memory per operation 15.33 KiB/op 15.33 KiB/op No observed change Not flagged
Evaluate a rollout flag
Shard: flags-single
Allocations per operation 158.77 count/op 158.77 count/op No observed change Not flagged
Evaluate a rollout flag
Shard: flags-single
Time per operation 6.51 µs/op 6.47 µs/op 0.7% less time Not flagged
Evaluate a rollout flag
Shard: flags-single
Process CPU time per operation 6.51 µs/op 6.47 µs/op 0.7% less time Not flagged
Evaluate a multivariate flag
Shard: flags-single
Allocated memory per operation 16.34 KiB/op 16.34 KiB/op No observed change Not flagged
Evaluate a multivariate flag
Shard: flags-single
Allocations per operation 172.77 count/op 172.77 count/op No observed change Not flagged
Evaluate a multivariate flag
Shard: flags-single
Time per operation 7.13 µs/op 7.09 µs/op 0.6% less time Not flagged
Evaluate a multivariate flag
Shard: flags-single
Process CPU time per operation 7.13 µs/op 7.09 µs/op 0.6% less time Not flagged

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 b146f8aba7dc269db0c6d774c3142982c56b1810 → d802f325902bbf23d1908cdab81b3963dff3ead3.

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.

…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

# Conflicts:
#	posthog/client.py

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.

1 participant