Skip to content

test(flags): validate failed reads against contract 11.0.0 - #1319

Open
andehen wants to merge 1 commit into
mainfrom
andehen/vendor-flag-contract-11
Open

andehen wants to merge 1 commit into
mainfrom
andehen/vendor-flag-contract-11

Conversation

@andehen

@andehen andehen commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

💡 Motivation and Context

The $feature_flag_called tests skipped the contract schema for failed and missing-flag reads, because the vendored schema required a non-null $feature_flag_response. Contract 11.0.0 (harness 1.38.0, PostHog/posthog-sdk-test-harness#116) allows a read without a value. This PR copies that release and validates those reads too. Test-only, no release.

Details

Re-vendor. Every file listed in posthog/test/fixtures/feature_flag_rules_v2/SOURCE.json is copied unchanged from harness tag 1.38.0 (9637117). Only feature_flag_called_context.schema.json differs from 1.30.0:

  • $feature_flag_response is no longer required, and it may be null.
  • $feature_flag_error is declared as a string, so the test projection now keeps it.
  • A config version 2 call may leave out the response only when $feature_flag_error lists evaluation_failed.

SOURCE.json and the digest test now name release 1.38.0, contract 11.0.0.

Tests that now validate failed reads (all in test_experiment_exposure.py):

  • test_reader_cases_... and test_async_reader_cases_...: the reader cases dependency_error, error, error_with_value, missing_flag and v1_failed.
  • test_flag_called_attribution_follows_the_record: dependency_error, error.
  • test_rule_fields_are_sent_only_for_reasons_that_name_a_rule: the failed dependency_error, error, experiment_split and holdout rows.
  • test_async_a_failed_split_sends_no_exposure.
  • test_a_config_version_2_call_reports_its_reason_by_code_only[failed-*].

The existing $feature_flag_error assertions stay.

The new schema does the work. With the 1.30.0 schema swapped back in, these 54 test cases fail with "None is not valid under any of the given schemas". With 1.38.0, all of them pass. A new parametrized test, test_a_config_version_2_call_without_a_value_must_list_evaluation_failed, takes a real failed read and checks that the schema rejects it when $feature_flag_error is removed or does not list evaluation_failed, with the response null or absent.

The new schema rejected nothing the SDK sends: v2 failed reads, v1 failed reads and missing flags all pass. No SDK source changed.

💚 How did you test it?

  • pytest posthog/test/test_experiment_exposure.py posthog/test/test_flags_v4_response.py posthog/test/test_failed_flag_records.py --timeout=30
  • The same exposure tests against the 1.30.0 schema, to confirm the newly validated cases fail there.
  • pytest --timeout=30, ruff format --check ., ruff check ., mypy --no-site-packages --config-file mypy.ini . | mypy-baseline filter.

📝 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

No changeset: this changes tests and test fixtures only.

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Written with Claude Code. The vendored files are byte copies from the harness tag, checked against SOURCE.json's digests. No SDK source changed.

🤖 Generated with Claude Code

Copy the vendored feature flag rules v2 contract files from harness
release 1.38.0 (contract 11.0.0). Only the $feature_flag_called context
schema changed: $feature_flag_response may now be absent or null, and a
config version 2 call may leave it out only when $feature_flag_error
lists evaluation_failed.

The exposure tests skipped the schema for failed and missing-flag reads,
because the old schema required a non-null response. They now validate
every $feature_flag_called through the same projection, and a new case
checks that the schema still rejects a config version 2 call with no
value whose error does not list evaluation_failed.
@andehen andehen self-assigned this Nov 30, 2026
@github-actions

Copy link
Copy Markdown
Contributor

SDK performance: posthog-python

1 change worth reviewing: 1 observed regression.

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
Queue an event (32-byte payload) Caller-thread CPU time per operation 42.43 µs/op 46.35 µs/op 9.2% more time
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.64 KiB/op 133.64 KiB/op <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Allocations per operation 1,345.48 count/op 1,345.48 count/op <0.1% more Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Time per operation 61.86 µs/op 60.02 µs/op 3% less time Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Idle process memory (RSS) 37.71 MiB 37.78 MiB 0.2% more memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Observed peak process memory (RSS) 40.16 MiB 40.23 MiB 0.2% more memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Process memory after settling (RSS) 40.16 MiB 40.23 MiB 0.2% more memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Process CPU time per operation 62.31 µs/op 60.44 µs/op 3% less time Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Lifetime peak process memory (RSS) 40.7 MiB 40.7 MiB No observed change Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Allocated memory per operation 185.73 KiB/op 185.73 KiB/op <0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Allocations per operation 1,337.52 count/op 1,337.52 count/op <0.1% fewer Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Time per operation 81.96 µs/op 78.86 µs/op 3.8% less time Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Idle process memory (RSS) 41.4 MiB 41.26 MiB 0.3% less memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Observed peak process memory (RSS) 47.19 MiB 47.04 MiB 0.3% less memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Process memory after settling (RSS) 47.19 MiB 47.04 MiB 0.3% less memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Process CPU time per operation 77.19 µs/op 73.93 µs/op 4.2% less time Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Lifetime peak process memory (RSS) 51.64 MiB 51.49 MiB 0.3% less memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Allocated memory per operation 138.72 KiB/op 138.72 KiB/op No observed change Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Allocations per operation 1,390.42 count/op 1,390.42 count/op No observed change Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Time per operation 69.07 µs/op 70.27 µs/op 1.7% more time Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Idle process memory (RSS) 37.71 MiB 37.74 MiB <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Observed peak process memory (RSS) 37.88 MiB 37.89 MiB <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Process memory after settling (RSS) 37.88 MiB 37.89 MiB <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Process CPU time per operation 67.51 µs/op 70.33 µs/op 4.2% more time Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Lifetime peak process memory (RSS) 40.7 MiB 40.7 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 190.9 KiB/op <0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Allocations per operation 1,382.38 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 86.53 µs/op 87.79 µs/op 1.5% more time Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Idle process memory (RSS) 41.25 MiB 41.25 MiB <0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Observed peak process memory (RSS) 41.71 MiB 41.69 MiB <0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Process memory after settling (RSS) 41.31 MiB 41.3 MiB <0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Process CPU time per operation 82.13 µs/op 83.22 µs/op 1.3% more time Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Lifetime peak process memory (RSS) 41.64 MiB 41.63 MiB <0.1% less memory Not flagged
Queue an event (32-byte payload)
Shard: capture
Caller-thread CPU time per operation 42.43 µs/op 46.35 µs/op 9.2% more time Worth reviewing: observed regression
Queue an event (32-byte payload)
Shard: capture
Time per operation 42.43 µs/op 47.02 µs/op 10.8% more time Not flagged
Queue an event (4,096-byte payload)
Shard: capture
Caller-thread CPU time per operation 43.11 µs/op 43.61 µs/op 1.2% more time Not flagged
Queue an event (4,096-byte payload)
Shard: capture
Time per operation 43.11 µs/op 44.71 µs/op 3.7% more time Not flagged
Evaluate all 10 flags
Shard: flags-scaling
Allocated memory per operation 233.85 KiB/op 233.85 KiB/op No observed change Not flagged
Evaluate all 10 flags
Shard: flags-scaling
Allocations per operation 2,352.93 count/op 2,352.93 count/op No observed change Not flagged
Evaluate all 10 flags
Shard: flags-scaling
Time per operation 123.2 µs/op 122.76 µs/op 0.4% less time Not flagged
Evaluate all 10 flags
Shard: flags-scaling
Process CPU time per operation 123.2 µs/op 122.75 µs/op 0.4% less time Not flagged
Evaluate all 100 flags
Shard: flags-scaling
Allocated memory per operation 2.25 MiB/op 2.25 MiB/op No observed change Not flagged
Evaluate all 100 flags
Shard: flags-scaling
Allocations per operation 23,148.75 count/op 23,148.75 count/op No observed change Not flagged
Evaluate all 100 flags
Shard: flags-scaling
Time per operation 1.22 ms/op 1.2 ms/op 1.2% less time Not flagged
Evaluate all 100 flags
Shard: flags-scaling
Process CPU time per operation 1.22 ms/op 1.2 ms/op 1.2% less time Not flagged
Evaluate all 1,000 flags
Shard: flags-scaling
Allocated memory per operation 22.45 MiB/op 22.45 MiB/op No observed change Not flagged
Evaluate all 1,000 flags
Shard: flags-scaling
Allocations per operation 231,005.5 count/op 231,005.5 count/op No observed change Not flagged
Evaluate all 1,000 flags
Shard: flags-scaling
Time per operation 11.99 ms/op 11.99 ms/op <0.1% more time Not flagged
Evaluate all 1,000 flags
Shard: flags-scaling
Process CPU time per operation 11.98 ms/op 11.99 ms/op <0.1% more time Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Idle process memory (RSS) 43.84 MiB 43.8 MiB <0.1% less memory Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Observed peak process memory (RSS) 44.19 MiB 44.12 MiB 0.2% less memory Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Process memory after settling (RSS) 44.19 MiB 44.12 MiB 0.2% less memory Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Lifetime peak process memory (RSS) 43.94 MiB 43.97 MiB <0.1% more memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Idle process memory (RSS) 43 MiB 42.93 MiB 0.2% less memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Observed peak process memory (RSS) 43.01 MiB 42.94 MiB 0.2% less memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Process memory after settling (RSS) 43.01 MiB 42.94 MiB 0.2% less memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Lifetime peak process memory (RSS) 42.87 MiB 42.8 MiB 0.2% less memory Not flagged
Evaluate one boolean flag
Shard: flags-single
Allocated memory per operation 15.74 KiB/op 15.74 KiB/op No observed change Not flagged
Evaluate one boolean flag
Shard: flags-single
Allocations per operation 162.77 count/op 162.77 count/op No observed change Not flagged
Evaluate one boolean flag
Shard: flags-single
Time per operation 8.21 µs/op 8.3 µs/op 1.1% more time Not flagged
Evaluate one boolean flag
Shard: flags-single
Process CPU time per operation 8.21 µs/op 8.3 µs/op 1.1% more time Not flagged
Evaluate a cohort-filtered flag
Shard: flags-single
Allocated memory per operation 25.28 KiB/op 25.28 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 11.72 µs/op 11.7 µs/op 0.1% less time Not flagged
Evaluate a cohort-filtered flag
Shard: flags-single
Process CPU time per operation 11.72 µs/op 11.7 µs/op 0.1% less time Not flagged
Evaluate a flag (early match)
Shard: flags-single
Allocated memory per operation 41.36 KiB/op 41.36 KiB/op No observed change Not flagged
Evaluate a flag (early match)
Shard: flags-single
Allocations per operation 401.77 count/op 401.77 count/op No observed change Not flagged
Evaluate a flag (early match)
Shard: flags-single
Time per operation 16.73 µs/op 16.93 µs/op 1.1% more time Not flagged
Evaluate a flag (early match)
Shard: flags-single
Process CPU time per operation 16.74 µs/op 16.92 µs/op 1.1% more time Not flagged
Evaluate a flag (late match)
Shard: flags-single
Allocated memory per operation 63.34 KiB/op 63.34 KiB/op No observed change Not flagged
Evaluate a flag (late match)
Shard: flags-single
Allocations per operation 608.27 count/op 608.27 count/op No observed change Not flagged
Evaluate a flag (late match)
Shard: flags-single
Time per operation 24.03 µs/op 24.13 µs/op 0.4% more time Not flagged
Evaluate a flag (late match)
Shard: flags-single
Process CPU time per operation 24.03 µs/op 24.13 µs/op 0.4% more time Not flagged
Evaluate a flag (no match)
Shard: flags-single
Allocated memory per operation 61.97 KiB/op 61.97 KiB/op No observed change Not flagged
Evaluate a flag (no match)
Shard: flags-single
Allocations per operation 591.77 count/op 591.77 count/op No observed change Not flagged
Evaluate a flag (no match)
Shard: flags-single
Time per operation 22.8 µs/op 22.75 µs/op 0.2% less time Not flagged
Evaluate a flag (no match)
Shard: flags-single
Process CPU time per operation 22.8 µs/op 22.74 µs/op 0.2% less time Not flagged
Evaluate a property-filtered flag
Shard: flags-single
Allocated memory per operation 19.38 KiB/op 19.38 KiB/op No observed change Not flagged
Evaluate a property-filtered flag
Shard: flags-single
Allocations per operation 195.27 count/op 195.27 count/op No observed change Not flagged
Evaluate a property-filtered flag
Shard: flags-single
Time per operation 9.27 µs/op 9.32 µs/op 0.5% more time Not flagged
Evaluate a property-filtered flag
Shard: flags-single
Process CPU time per operation 9.28 µs/op 9.32 µs/op 0.5% more time Not flagged
Evaluate a regex-filtered flag
Shard: flags-single
Allocated memory per operation 21.01 KiB/op 21.01 KiB/op No observed change Not flagged
Evaluate a regex-filtered flag
Shard: flags-single
Allocations per operation 200.77 count/op 200.77 count/op No observed change Not flagged
Evaluate a regex-filtered flag
Shard: flags-single
Time per operation 9.93 µs/op 9.98 µs/op 0.5% more time Not flagged
Evaluate a regex-filtered flag
Shard: flags-single
Process CPU time per operation 9.93 µs/op 9.98 µs/op 0.5% more time Not flagged
Evaluate a rollout flag
Shard: flags-single
Allocated memory per operation 14.89 KiB/op 14.89 KiB/op No observed change Not flagged
Evaluate a rollout flag
Shard: flags-single
Allocations per operation 152.77 count/op 152.77 count/op No observed change Not flagged
Evaluate a rollout flag
Shard: flags-single
Time per operation 7.75 µs/op 7.76 µs/op 0.2% more time Not flagged
Evaluate a rollout flag
Shard: flags-single
Process CPU time per operation 7.75 µs/op 7.76 µs/op 0.2% more time Not flagged
Evaluate a multivariate flag
Shard: flags-single
Allocated memory per operation 15.9 KiB/op 15.9 KiB/op No observed change Not flagged
Evaluate a multivariate flag
Shard: flags-single
Allocations per operation 166.77 count/op 166.77 count/op No observed change Not flagged
Evaluate a multivariate flag
Shard: flags-single
Time per operation 8.53 µs/op 8.51 µs/op 0.3% less time Not flagged
Evaluate a multivariate flag
Shard: flags-single
Process CPU time per operation 8.53 µs/op 8.51 µs/op 0.3% 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 c66216c38609fe3d21a88bbc492aed51367ff2df → eb4b4e4805da51913f656886cd63aa42970d7d89.

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.

@andehen
andehen marked this pull request as ready for review November 30, 2026 10:48
@andehen
andehen requested a review from a team as a code owner November 30, 2026 10:48
@andehen andehen added the stamphog Request stamphog review label Nov 30, 2026
@veria-ai

veria-ai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

PR overview

No security issues were found in this pull request.

Reviews

@stamphog stamphog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Approved.

Contained test and fixture updates with no production behavior changes or open substantive review concerns. The schema is used for test validation, not to alter a public API or runtime data model.

  • PostHog Review (Standard) reviewed the current head: no findings.
Gate mechanics and policy version
Gate Result
prerequisites ✓ all clear
deny-list ✓ no deny categories matched
every_file_attested ✓ not a bot PR
size ✓ 0L, 0F substantive, 92L/4F incl. docs/generated/snapshots — within ceiling
tier ✓ T0 auto-approve: T0-deterministic (92L, 4F, single-area, test)
stamphog 2.9.1 .stamphog/policy.yml @ eb4b4e4 · reviewed head eb4b4e4

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

stamphog Request stamphog review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant