Skip to content

fix(flags): keep $ip and cookieless inputs on minimal $feature_flag_called events - #1340

Open
haacked wants to merge 5 commits into
mainfrom
haacked/minimal-flag-called-ingestion-inputs
Open

haacked wants to merge 5 commits into
mainfrom
haacked/minimal-flag-called-ingestion-inputs

Conversation

@haacked

@haacked haacked commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

💡 Motivation and Context

Minimal $feature_flag_called events stripped the $ip and $raw_user_agent that the Django, Flask and ASGI integrations attach. Ingestion fills $ip from the capture request only when the event doesn't have one. posthog-python sends from the app's server, so every minimal flag call got the server's GeoIP location instead of the visitor's. The allowlist also stripped the other inputs that ingestion hashes into the cookieless distinct id and session id. Ingestion drops a cookieless event that lacks $raw_user_agent, $ip or $host, so in cookieless mode it dropped every minimal flag call.

This adds $ip, $raw_user_agent, $host, $timezone and $cookieless_extra to the minimal allowlist, next to $geoip_disable. $cookieless_mode is already on it. The SDK keeps these keys whenever the full event carries them and doesn't check for cookieless mode. Cookieless mode can come from super_options, a context option, the $cookieless_mode property, or a before_send hook that runs after the allowlist. This implements follow-up task 3.5 of PostHog/sdk-specs#281.

$current_url, $user_agent, $request_method, $request_path and the browser and device properties stay off the list, as the spec requires of a server SDK. $os, $os_version and the other system_context() keys describe the server's runtime, so they stay on it.

💚 How did you test it?

  • New tests in test_feature_flag_called_minimization.py check that a minimal flag call keeps the ingestion inputs from the context and strips the request-only properties.
  • The cookieless test sets cookieless mode through super_options, through set_context_option, and through the $cookieless_mode property. In each case the v1 event has options.cookieless_mode: true and still carries the inputs in properties.
  • A new test in test_middleware.py makes a flag call while PosthogContextMiddleware handles a request. The event keeps $ip and $raw_user_agent and strips $current_url, $user_agent, $request_method and $request_path.
  • Without the new allowlist keys, all five new tests fail.
  • mypy passes against the baseline, and ruff 0.12.2 lint and format pass. Locally, the rest of the suite passes except 16 tests in posthog/test/mcp/test_fastmcp_v2.py, which fail because my installed fastmcp is older than the version they need.

📝 Checklist

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

  • I wrote the tests first, confirmed they failed, then changed the allowlist. A review-code pass and a Codex correctness review found no code defects, and I applied their wording fixes.
  • I merged main to resolve a conflict in the allowlist. Main had added option sources and super_options, so I kept main's list, added the five keys, and bound the cookieless test to super_options as the spec scenario describes.
  • The compliance adapter doesn't bind the "SDK attaches these properties to every event" step, so I didn't change it.

@haacked haacked self-assigned this Dec 2, 2026
@haacked
haacked marked this pull request as ready for review December 2, 2026 19:16
@haacked
haacked requested a review from a team as a code owner December 2, 2026 19:16
@veria-ai

veria-ai Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

PR overview

No security issues were found in this pull request.

Reviews

@haacked haacked added the stamphog Request stamphog review label Dec 2, 2026

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

Not approved — this change needs a human reviewer.

Ask for another review through the PostHog MCP or comment @posthog stamp once you have addressed this.

The prerequisites gate refused this pull request because it has merge conflicts. The other gates (deny-list, attestation, size, and tier) all passed, so the conflicts are the only thing blocking it. The author should resolve the conflicts against the base branch and push the update. If the pull request still needs a decision after that, they can ask a human reviewer to look at it.

Gate mechanics and policy version
Gate Result
prerequisites ✗ merge conflicts present
deny-list ✓ no deny categories matched
every_file_attested ✓ not a bot PR
size ✓ 21L, 1F substantive, 158L/4F incl. size-exempt files — within ceiling
tier ✓ T1-agent / T1c-medium (158L, 4F, two-areas, fix)
stamphog 2.11.0 .stamphog/policy.yml @ unknown · reviewed head 6330704

@stamphog stamphog Bot removed the stamphog Request stamphog review label Dec 2, 2026
@haacked haacked added the stamphog Request stamphog review label Dec 2, 2026

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

The ingestion-path change has independent assurance through the author's reported STRONG familiarity and added regression tests. No unresolved review concerns or other refusal grounds were found; the discussion bot summary is not a current-head review.

  • Author wrote 100% of the modified lines and has 2 merged PRs in these paths (familiarity STRONG).
Gate mechanics and policy version
Gate Result
prerequisites ✓ all clear
deny-list ✓ no deny categories matched
every_file_attested ✓ not a bot PR
size ✓ 19L, 1F substantive, 165L/4F incl. size-exempt files — within ceiling
tier ✓ T1-agent / T1c-medium (165L, 4F, two-areas, fix)
stamphog 2.11.0 .stamphog/policy.yml @ 911d013 · reviewed head 911d013

@github-actions

github-actions Bot commented Dec 2, 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 75.21 KiB/op 75.21 KiB/op <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Allocations per operation 775.55 count/op 775.55 count/op <0.1% more Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Time per operation 50.15 µs/op 50.63 µs/op 1% more time Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Idle process memory (RSS) 38.01 MiB 38.02 MiB <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Observed peak process memory (RSS) 40.47 MiB 40.49 MiB <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Process memory after settling (RSS) 40.47 MiB 40.49 MiB <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Process CPU time per operation 53.6 µs/op 54.55 µs/op 1.8% more time Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Lifetime peak process memory (RSS) 40.63 MiB 40.67 MiB <0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Allocated memory per operation 127.29 KiB/op 127.29 KiB/op No observed change Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Allocations per operation 767.55 count/op 767.55 count/op No observed change Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Time per operation 72.93 µs/op 73.5 µs/op 0.8% more time Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Idle process memory (RSS) 41.68 MiB 41.69 MiB <0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Observed peak process memory (RSS) 47.49 MiB 47.5 MiB <0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Process memory after settling (RSS) 47.49 MiB 47.5 MiB <0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Process CPU time per operation 71.05 µs/op 71.42 µs/op 0.5% more time Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Lifetime peak process memory (RSS) 51.84 MiB 52.01 MiB 0.3% more memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Allocated memory per operation 80.27 KiB/op 80.27 KiB/op <0.1% less memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Allocations per operation 820.32 count/op 820.31 count/op <0.1% fewer Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Time per operation 60.74 µs/op 61.02 µs/op 0.5% more time Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Idle process memory (RSS) 37.88 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.08 MiB 38.08 MiB <0.1% less memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Process memory after settling (RSS) 38.08 MiB 38.08 MiB <0.1% less memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Process CPU time per operation 62.74 µs/op 63.07 µs/op 0.5% more time Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Lifetime peak process memory (RSS) 40.61 MiB 40.61 MiB No observed change Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Allocated memory per operation 132.44 KiB/op 132.44 KiB/op <0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Allocations per operation 812.23 count/op 812.22 count/op <0.1% fewer Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Time per operation 78.13 µs/op 77.78 µs/op 0.4% less time Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Idle process memory (RSS) 41.55 MiB 41.48 MiB 0.2% less memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Observed peak process memory (RSS) 42.05 MiB 41.98 MiB 0.2% less memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Process memory after settling (RSS) 41.63 MiB 41.56 MiB 0.2% less memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Process CPU time per operation 75.99 µs/op 76 µs/op <0.1% more time Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Lifetime peak process memory (RSS) 41.91 MiB 41.85 MiB 0.1% less memory Not flagged
Queue an event (32-byte payload)
Shard: capture
Caller-thread CPU time per operation 31.27 µs/op 30.91 µs/op 1.2% less time Not flagged
Queue an event (32-byte payload)
Shard: capture
Time per operation 31.46 µs/op 31.07 µs/op 1.2% less time Not flagged
Queue an event (4,096-byte payload)
Shard: capture
Caller-thread CPU time per operation 30.77 µs/op 30.94 µs/op 0.5% more time Not flagged
Queue an event (4,096-byte payload)
Shard: capture
Time per operation 30.77 µs/op 30.93 µs/op 0.5% more time Not flagged
Evaluate all 10 flags
Shard: flags-scaling
Allocated memory per operation 249.89 KiB/op 249.89 KiB/op No observed change Not flagged
Evaluate all 10 flags
Shard: flags-scaling
Allocations per operation 2,525.94 count/op 2,525.94 count/op No observed change Not flagged
Evaluate all 10 flags
Shard: flags-scaling
Time per operation 131.08 µs/op 130.23 µs/op 0.6% less time Not flagged
Evaluate all 10 flags
Shard: flags-scaling
Process CPU time per operation 131.08 µs/op 130.23 µs/op 0.7% less time Not flagged
Evaluate all 100 flags
Shard: flags-scaling
Allocated memory per operation 2.4 MiB/op 2.4 MiB/op No observed change Not flagged
Evaluate all 100 flags
Shard: flags-scaling
Allocations per operation 24,815.94 count/op 24,815.94 count/op No observed change Not flagged
Evaluate all 100 flags
Shard: flags-scaling
Time per operation 1.27 ms/op 1.26 ms/op 0.8% less time Not flagged
Evaluate all 100 flags
Shard: flags-scaling
Process CPU time per operation 1.27 ms/op 1.26 ms/op 0.8% less time Not flagged
Evaluate all 1,000 flags
Shard: flags-scaling
Allocated memory per operation 23.93 MiB/op 23.93 MiB/op No observed change Not flagged
Evaluate all 1,000 flags
Shard: flags-scaling
Allocations per operation 247,612.69 count/op 247,612.69 count/op No observed change Not flagged
Evaluate all 1,000 flags
Shard: flags-scaling
Time per operation 12.98 ms/op 13 ms/op 0.2% more time Not flagged
Evaluate all 1,000 flags
Shard: flags-scaling
Process CPU time per operation 12.98 ms/op 13 ms/op 0.2% more time Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Idle process memory (RSS) 44.06 MiB 43.53 MiB 1.2% less memory Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Observed peak process memory (RSS) 44.38 MiB 43.84 MiB 1.2% less memory Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Process memory after settling (RSS) 44.38 MiB 43.84 MiB 1.2% less memory Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Lifetime peak process memory (RSS) 44.09 MiB 44.03 MiB 0.1% less memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Idle process memory (RSS) 43.89 MiB 43.98 MiB 0.2% more memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Observed peak process memory (RSS) 43.91 MiB 43.99 MiB 0.2% more memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Process memory after settling (RSS) 43.91 MiB 43.99 MiB 0.2% more memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Lifetime peak process memory (RSS) 44.27 MiB 43.82 MiB 1% less memory Not flagged
Evaluate one boolean flag
Shard: flags-single
Allocated memory per operation 17.72 KiB/op 17.72 KiB/op No observed change Not flagged
Evaluate one boolean flag
Shard: flags-single
Allocations per operation 180.77 count/op 180.77 count/op No observed change Not flagged
Evaluate one boolean flag
Shard: flags-single
Time per operation 7.73 µs/op 7.71 µs/op 0.3% less time Not flagged
Evaluate one boolean flag
Shard: flags-single
Process CPU time per operation 7.73 µs/op 7.71 µs/op 0.3% less time Not flagged
Evaluate a cohort-filtered flag
Shard: flags-single
Allocated memory per operation 28.32 KiB/op 28.32 KiB/op No observed change Not flagged
Evaluate a cohort-filtered flag
Shard: flags-single
Allocations per operation 283.28 count/op 283.28 count/op No observed change Not flagged
Evaluate a cohort-filtered flag
Shard: flags-single
Time per operation 10.28 µs/op 10.12 µs/op 1.6% less time Not flagged
Evaluate a cohort-filtered flag
Shard: flags-single
Process CPU time per operation 10.28 µs/op 10.12 µs/op 1.6% less time Not flagged
Evaluate a flag (early match)
Shard: flags-single
Allocated memory per operation 44.85 KiB/op 44.85 KiB/op No observed change Not flagged
Evaluate a flag (early match)
Shard: flags-single
Allocations per operation 438.78 count/op 438.78 count/op No observed change Not flagged
Evaluate a flag (early match)
Shard: flags-single
Time per operation 14.63 µs/op 14.78 µs/op 1% more time Not flagged
Evaluate a flag (early match)
Shard: flags-single
Process CPU time per operation 14.63 µs/op 14.78 µs/op 1% more time Not flagged
Evaluate a flag (late match)
Shard: flags-single
Allocated memory per operation 68.04 KiB/op 68.04 KiB/op No observed change Not flagged
Evaluate a flag (late match)
Shard: flags-single
Allocations per operation 659.28 count/op 659.28 count/op No observed change Not flagged
Evaluate a flag (late match)
Shard: flags-single
Time per operation 21.29 µs/op 20.85 µs/op 2.1% less time Not flagged
Evaluate a flag (late match)
Shard: flags-single
Process CPU time per operation 21.29 µs/op 20.85 µs/op 2.1% less time Not flagged
Evaluate a flag (no match)
Shard: flags-single
Allocated memory per operation 66.67 KiB/op 66.67 KiB/op No observed change Not flagged
Evaluate a flag (no match)
Shard: flags-single
Allocations per operation 642.77 count/op 642.77 count/op No observed change Not flagged
Evaluate a flag (no match)
Shard: flags-single
Time per operation 20.46 µs/op 20.2 µs/op 1.3% less time Not flagged
Evaluate a flag (no match)
Shard: flags-single
Process CPU time per operation 20.46 µs/op 20.2 µs/op 1.3% less time Not flagged
Evaluate a property-filtered flag
Shard: flags-single
Allocated memory per operation 21.67 KiB/op 21.67 KiB/op No observed change Not flagged
Evaluate a property-filtered flag
Shard: flags-single
Allocations per operation 218.28 count/op 218.28 count/op No observed change Not flagged
Evaluate a property-filtered flag
Shard: flags-single
Time per operation 8.49 µs/op 8.32 µs/op 2% less time Not flagged
Evaluate a property-filtered flag
Shard: flags-single
Process CPU time per operation 8.49 µs/op 8.32 µs/op 2% less time Not flagged
Evaluate a regex-filtered flag
Shard: flags-single
Allocated memory per operation 23.3 KiB/op 23.3 KiB/op No observed change Not flagged
Evaluate a regex-filtered flag
Shard: flags-single
Allocations per operation 223.78 count/op 223.78 count/op No observed change Not flagged
Evaluate a regex-filtered flag
Shard: flags-single
Time per operation 8.93 µs/op 8.95 µs/op 0.2% more time Not flagged
Evaluate a regex-filtered flag
Shard: flags-single
Process CPU time per operation 8.93 µs/op 8.95 µs/op 0.3% more time Not flagged
Evaluate a rollout flag
Shard: flags-single
Allocated memory per operation 16.87 KiB/op 16.87 KiB/op No observed change Not flagged
Evaluate a rollout flag
Shard: flags-single
Allocations per operation 170.77 count/op 170.77 count/op No observed change Not flagged
Evaluate a rollout flag
Shard: flags-single
Time per operation 7.23 µs/op 7.36 µs/op 1.9% more time Not flagged
Evaluate a rollout flag
Shard: flags-single
Process CPU time per operation 7.23 µs/op 7.36 µs/op 1.9% more time Not flagged
Evaluate a multivariate flag
Shard: flags-single
Allocated memory per operation 17.88 KiB/op 17.88 KiB/op No observed change Not flagged
Evaluate a multivariate flag
Shard: flags-single
Allocations per operation 184.77 count/op 184.77 count/op No observed change Not flagged
Evaluate a multivariate flag
Shard: flags-single
Time per operation 7.94 µs/op 7.81 µs/op 1.7% less time Not flagged
Evaluate a multivariate flag
Shard: flags-single
Process CPU time per operation 7.94 µs/op 7.81 µs/op 1.7% 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 3857d8833a46642bf152dfa5a73de60a33f58ca3 → 911d0139dc7b629ca90ede8c1dfa8c3a24e4b65e.

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.

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