Repository navigation
Conversation
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 |
Local evaluation now evaluates a loaded definition whose `filters.version` is not absent or 1 with the config version 2 evaluator. Version 1 definitions keep the version 1 evaluator. The definitions request is unchanged, so no such definition arrives from the API yet. - `_compute_flag_locally` dispatches on the config version. Each config version 2 document is parsed once, when definitions load. - A local result is the record a `/flags?v=4` response gives, for single reads and `evaluate_flags()` snapshots, so the existing event step sends `$feature_flag_called` and, for a complete split, `$experiment_exposure`, with `locally_evaluated` true. - An unsupported document or an undecided rule falls back to `/flags` per flag, or is unresolved with `only_evaluate_locally=True`. It never reads as false or the default. - A version 1 flag that depends on a config version 2 flag goes to the server instead of reading the dependency as version 1. - The external definition cache keeps version 1 definitions in `flags` and puts the others in a separate `flags_v2` field, left out when empty. - Tests cover each read path, the fallbacks, the dependency path, both events, the cache field, and the boolean, value and experiment corpora replayed through the client.
- Hash the definitions with the version 1 definitions first, in the order the definition cache stores them. A client that loads them from the cache then gives them the same fingerprint as the client that fetched them, so it accepts the flag results that client cached. Version 1 definitions keep their order, so their fingerprint is unchanged. - Keep an integral `id` or `version`, such as 41.0, in the local record of a config version 2 flag, as the v4 reader keeps it. - Build the number type tuple of the config version check once.
No behaviour change. - Split the definitions by config version in one helper, used both to store them in the definition cache and to hash them in that order. - Read a local record's `id` and `version` with the v4 reader's own integer rule. - Read the parsed definitions from the snapshot directly, since every snapshot holds them. - Shorten `_parse_definitions`, `_unresolved_reason`, `_with_cached_v2_flags` and the dependency format check. - Say in the event helper's docstring that a local config version 2 flag passes its record. - Tests: share the client that loads definitions from the cache, and drop an unused constant and a redundant check.
e9c905d to
ddfdf44
Compare
…s-v2-local-dispatch Brings in the contract files of posthog-sdk-test-harness 1.36.0 (contract 10.1.0) and the evaluator replay that the contract's local outcome mapping drives. The evaluator test no longer has `OMITTED`; it exports the cases a local evaluator runs as `REPLAYED`. The client replay now takes those, which include the 8 cases of `v2_local_evaluation.json`. Through the client, 7 of them give their result and 1 falls back with `missing_context`, so the pinned counts move from (203, 8, 35, 8) to (210, 8, 36, 8).
The contract of posthog-sdk-test-harness 1.36.0 has a whole definitions feed that states the outcome a local reader gives each entry, and a mapping from each evaluation case's expected result to its unresolved reason. - Each feed entry goes to the evaluator the contract names. A config version 2 entry gives the exact expected value, reason, rule and variant, and an unsupported entry is inconclusive with `unsupported_definition`. - One read of the whole feed in each mode. In the default mode only the 3 unsupported entries come from `/flags`. With `only_evaluate_locally` they are unresolved with `unsupported_definition`. Every other entry, version 1 included, is evaluated locally and keeps its result. - These tests replace the invented mixed feed test. - The client replay takes the unresolved reason of an undecided corpus case from `local_outcomes.json` instead of its own table.
…or' into feat/flag-rules-v2-local-dispatch
…on 2 read Review fixes for the config version dispatch. - A single read of a locally evaluated config version 2 flag now sends the ID and version of its record in `$feature_flag_called` and `$experiment_exposure`, as a snapshot read already did. The single read took them from the raw definition instead, so a stored `41.0` was sent as `41.0` and a value that is not an integer was sent as it was stored, where the record reads `41.0` as `41` and leaves other values out, as the v4 reader does. Version 1 reads are unchanged. - The tests' check that a read makes no `/flags` request now runs after the reads. The client catches the error of a failed request, so the error the mock raised never reached the test, and a read that fell back remotely could pass. Every existing use of the check still passes.
The definitions feed replay added the rule member only when a record had a rule ID, so a record with a rule type or condition index but no rule ID still matched an expectation without a rule. Read the three rule fields as a set: all present or all absent, and compared to the expectation's rule member when present.
…or' into feat/flag-rules-v2-local-dispatch
…or' into feat/flag-rules-v2-local-dispatch
There was a problem hiding this comment.
PostHog Review · Standard · reviewed ec31bca: 1 Should fix.
New pushes to this pull request won't start an automatic review. Comment @posthog review to review new changes.
See this review and its findings in PostHog Review. Comment @posthog review --deep for a Deep review. A Deep review takes longer and looks deeper than a Standard review.
There was a problem hiding this comment.
Not approved — this change needs a human reviewer.
Add the stamphog label to request another review once you have addressed this.
The current code confirms @PostHog's unresolved publication-lock concern, so its comment-only review does not provide concern-free assurance. Address that thread and request a current-head review from a teammate or agent; Eli Reisman and Manoel Aranda Neto are suggested reviewers given their familiarity.
- Author wrote 22% of the modified lines and has 8 merged PRs in these paths (familiarity MODERATE).
- PostHog Review (Standard) reviewed the current head: 1 finding, posted on the PR.
- posthog[bot] reviewed the current head.
- @PostHog, posthog/client.py: The publication-lock performance concern remains unaddressed: _update_flag_state acquires the lock before assigning feature_flags, whose setter parses all version-2 definitions; snapshot readers require the same lock, and unchanged cache hydration still invokes that setter. Prepare parsed definitions outside the lock and publish them atomically before re-requesting. If the bot's finding is incorrect, explain why in its thread and resolve it.
Gate mechanics and policy version
| Gate | Result | |
|---|---|---|
| prerequisites | ✓ | all clear |
| deny-list | ✓ | no deny categories matched |
| every_file_attested | ✓ | not a bot PR |
| size | ✓ | 404L, 4F substantive, 1881L/6F incl. docs/generated/snapshots — within ceiling |
| tier | ✓ | T1-agent / T1d-complex (1881L, 6F, two-areas, feat) |
| stamphog 2.9.1 | .stamphog/policy.yml @ ec31bca · reviewed head ec31bca |
…n lock Loading definitions parsed each config version 2 document in the feature_flags setter, which runs under the publication lock, so every concurrent flag read waited for the parse. Definitions fetched from the API and definitions read from the definition cache provider are now parsed first, and only the result is published, with the rest of the flag state, under the lock. A read during a load keeps the definitions published before, with the documents parsed from them.
There was a problem hiding this comment.
Not approved — this change needs a human reviewer.
Add the stamphog label to request another review once you have addressed this.
The bot's open security concern is still supported by the current code and must be fixed before re-requesting. The risky changes also lack current-head independent assurance; request review from a teammate or agent reviewer, with Eli Reisman or Manoel Aranda Neto suggested by familiarity.
- Author wrote 18% of the modified lines and has 8 merged PRs in these paths (familiarity MODERATE).
- @veria-ai on posthog/client.py: the unbounded-regex concern remains valid. The new dispatch reaches posthog/_feature_flags_v2.py:945 and then posthog/feature_flags.py:1342, which calls Python regex.search synchronously without a timeout. The translator rejects nested quantified groups but does not reject repeated overlapping alternatives; the value guard does not protect ordinary ASCII inputs ending in a non-newline mismatch. A configured susceptible rule can therefore allow attacker-controlled properties to monopolize an application worker. Use a bounded/non-backtracking matcher or defer unsafe patterns before local execution, add a regression test, and re-request review.
Gate mechanics and policy version
| Gate | Result | |
|---|---|---|
| prerequisites | ✓ | all clear |
| deny-list | ✓ | no deny categories matched |
| every_file_attested | ✓ | not a bot PR |
| size | ✓ | 441L, 4F substantive, 2008L/6F incl. docs/generated/snapshots — within ceiling |
| tier | ✓ | T1-agent / T1d-complex (2008L, 6F, two-areas, feat) |
| stamphog 2.9.1 | .stamphog/policy.yml @ b146f8a · reviewed head b146f8a |
There was a problem hiding this comment.
Not approved — escalated to a human reviewer.
Add the stamphog label to request another review once you have addressed this.
Risky contract, cache-format and event-write changes lack independent assurance on the current head; the older review and discussion summary do not supply it. Request a current-head review from a teammate or agent covering these areas before re-requesting, with Eli Reisman or Manoel Aranda Neto as suggested reviewers.
- Author wrote 18% of the modified lines and has 8 merged PRs in these paths (familiarity MODERATE).
- Risky territory without independent assurance: Public API contracts — posthog/client.py and posthog/feature_flag_evaluations.py now expose locally evaluated version 2 results through single and snapshot reads, including typed values and experiment attribution.; Data models — posthog/client.py changes the shared definition-cache representation by separating non-version-1 definitions into flags_v2 and recombining them on load.; Data ingestion or write paths — posthog/_feature_flags_v2.py and posthog/client.py construct local attribution records that feed feature-flag and experiment-exposure events, and cache local evaluation results.
Gate mechanics and policy version
| Gate | Result | |
|---|---|---|
| prerequisites | ✓ | all clear |
| deny-list | ✓ | no deny categories matched |
| every_file_attested | ✓ | not a bot PR |
| size | ✓ | 441L, 4F substantive, 2008L/6F incl. docs/generated/snapshots — within ceiling |
| tier | ✓ | T1-agent / T1d-complex (2008L, 6F, two-areas, feat) |
| stamphog 2.9.1 | .stamphog/policy.yml @ b146f8a · reviewed head b146f8a |
💡 Motivation and Context
Stacked on #1250, which adds an evaluator for flags whose
filters.versionis 2 and does not call it. This PR calls it. It stays inert: the definitions request is unchanged (nov=2), and the definitions the server sends today leave these flags out, so none arrives from the API. A later PR requests them._compute_flag_locally.filters.versionabsent or 1 runs the version 1 evaluator, unchanged. Any other value goes to the new evaluator, whose closed parser accepts only 2. Each such document is parsed once, when definitions load./flags?v=4response gives, for single reads andevaluate_flags()snapshots. The existing event step then sends$feature_flag_calledwith the rule attribution, and$experiment_exposurefor a complete split, withlocally_evaluated: true.Falseor the default. The flag falls back to/flagson its own, or is listed inunresolved_flagswithonly_evaluate_locally=True, as an inconclusive version 1 flag is.flagskeeps the version 1 definitions; other definitions go to a separateflags_v2field, so an older release that shares the cache never evaluates one. The field is left out when empty, so the cached data of a project without such flags is unchanged. The name is provisional and private until the sdk-specs change for local evaluation names it.Evaluator inputs: the person properties are never treated as complete, so a filter on a property the call did not pass falls back; exact matching follows
property_matching_version; dates without an offset and relative dates are read in UTC, as version 1 local evaluation reads them; the distinct ID is read as a string; experience continuity and device bucketing do not apply, because the flags service evaluates these flags by distinct ID only.No published sdk-spec covers local evaluation of this format yet; the draft is PostHog/sdk-specs#244, which uses the same
flags_v2cache field. The contract of posthog-sdk-test-harness 1.36.0 (contract 10.1.0) is the cross-SDK reference.💚 How did you test it?
posthog/test/test_feature_flags_v2_dispatch.py(tests written first; they failed before the change):1,1.0) never reach the new evaluator; every other version does;/flagsrequest; the local record equals the record the v4 reader builds, also for an integralidorversionsuch as41.0; object values are copies;flag_disabled; each undecided case falls back per flag in the default mode and is unresolved, with its reason, when evaluating only locally;definitions_feed.json): each entry gets the evaluator and the exact result it states, and in one read of the feed only the 3 unsupported entries fall back (default mode) or are unresolved withunsupported_definition(only_evaluate_locally), while every other entry, version 1 included, keeps its local result;local_outcomes.jsongives (36 errors and parse errors, and 8 cases that need a complete property map); 8 cases set in another timezone are left to the evaluator's own replay.Also run locally on Python 3.14:
ruff format --check .,ruff check ., mypy with the baseline,make public_api_check(unchanged),python -W error -c "import posthog", the full suite, and 18 hand-made mutations of the change (for example a complete property map, no copy of an object value, no cache split, a dropped dependency check), each caught by the new tests.📝 Checklist
If releasing new changes
sampo addto generate a changeset fileA
patchchangeset, so that this step is released on its own before the request change: a regression in the version 1 paths it touches then shows up without config version 2 flags in play, and releases that read the new cache field exist before any release writes it.🤖 Agent context
Autonomy: Human-driven (agent-assisted)
main(8.x) merged into it first, with a merge commit, because this change edits the 8.x client. Its re-vendor to harness 1.36.0 is merged in the same way.🤖 Generated with Claude Code