Repository navigation
fix(flags): keep session properties on minimal flag called events - #1027
Conversation
Keep $os_name, $os_version, $device_type, $app_version, $referring_domain and the utm and click-ID campaign keys that posthog-js keeps. The sessions table takes a session's initial OS, device type and attribution from its first event, and a minimal flag call can be that first event.
There was a problem hiding this comment.
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.
stamphog can't approve this pull request because the prerequisites gate failed: the branch has merge conflicts. The other gates (deny-list, attestation, size and tier) passed, so the conflicts are the only thing blocking it. To move forward, the author should resolve the conflicts with the base branch and push the update, then 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 | ✓ | 39L, 1F substantive, 125L/3F incl. size-exempt files — within ceiling |
| tier | ✓ | T1-agent / T1c-medium (125L, 3F, two-areas, fix) |
| stamphog 2.11.0 | .stamphog/policy.yml @ unknown · reviewed head f9f26eb |
…called-session-props
posthog-android Compliance ReportDate: 2026-12-02T23:10:09.904841+00:00 ✅ All Tests Passed!243/243 tests passed Capture_V1 Tests✅ 111/111 tests passed View Details
Capture_Ai_V1 Tests✅ 115/115 tests passed View Details
Feature_Flags Tests✅ 17/17 tests passed View Details
|
dustinbyrne
left a comment
There was a problem hiding this comment.
AI-assisted review.
Verified that the new and updated tests fail on main and pass on this head, the client path minimizes via PostHog.kt:1455, ingestion copies $os_name → $os, and the added keys fit the sdk-specs "platform identity" and "session-attribution" categories. The campaign list matches posthog-js exactly.
Follow-up: Other client SDKs still blank session-initial device/OS on minimal flag calls. posthog-ios (PostHogSDK.swift:3603-3646) keeps $os_name/$os_version/$app_version but drops $device_type, which it sets in PostHogContext.swift:74. It also keeps only 9 of the 26 campaign keys. posthog-js core's MINIMAL_FLAG_CALLED_EVENT_PROPERTIES (featureFlagUtils.ts:226-264) has no OS or device keys, so React Native, which attaches $os_name/$os_version/$device_type/$app_version, has the same initial-OS and device blanking this PR fixes for Android. Consider aligning both to this list, with tests matching the two in this PR. You could also name the session-read OS and device fields in sdk-specs feature-flag-called-tracker :268. Not a merge condition here.
A new review started for this PR. Its verdict replaces this approval.
A new review started for this PR. Its verdict replaces this approval.
There was a problem hiding this comment.
Approved.
The event write-path changes enter risky territory, but the author's trusted STRONG familiarity supplies the policy's assurance path and the diff includes targeted tests. Neither listed review covers the current head; no concrete unresolved substantive concern or other refusal ground is present.
- Author wrote 75% of the modified lines and has 1 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 | ✓ | 75L, 2F substantive, 357L/5F incl. size-exempt files — within ceiling |
| tier | ✓ | T1-agent / T1d-complex (357L, 5F, two-areas, fix) |
| stamphog 2.11.0 | .stamphog/policy.yml @ 4ca94ef · reviewed head 4ca94ef |
💡 Motivation and Context
PostHog sets each session's initial OS, device type and attribution (utm params, referring domain, channel type) from the first event in that session. A property missing from that event is stored as an empty string, and later events in the session don't fill it in. When a team turns on minimal
$feature_flag_calledevents, Android sends a flag call for a flag without an experiment with only a short allowlist of properties. That list didn't include any of these keys. So when a flag call is the first event of a session, that session's initial OS, device type and attribution are blank in session filters, breakdowns and the replay list. A flag call is the first event of 2-3% of Android sessions and up to 15% of Flutter sessions, and Flutter on Android uses this SDK. This blocks making minimal flag call events the default for new organizations.The list also dropped
$raw_user_agentand$timezone, which Android puts on every event. Ingestion hashes those, with$ip,$hostand$cookieless_extra, to derive a cookieless event's distinct id and session id, and drops a cookieless event that is missing$raw_user_agent,$ipor$host. The sdk-specs requirement "Minimal event mode for non-experiment flags" (a1c38b6) now says to keep all of them whether or not the event is in cookieless mode.This PR keeps these on every minimal event:
$ip,$raw_user_agent,$host,$timezone,$cookieless_extra,$referring_domainand the utm and click-ID keys from posthog-jsMINIMAL_FLAG_CALLED_EVENT_CAMPAIGN_PROPERTIES.mainalready keeps$geoip_disableand$cookieless_mode. The Android client also keeps the spec's session-initial device and URL properties when the event carries them:$browser,$browser_version,$os,$os_name,$os_version,$device_type,$viewport_width,$viewport_heightand$current_url, plus$app_versionas static platform identity. Android itself sends$os_name,$os_version,$device_typeand$app_version. Ingestion copies$os_nameinto$os. The full$referreris still stripped.The spec says a server SDK strips
$current_urland the session-initial device properties, because on a server they come from the request, not the host. posthog-server shares this allowlist throughPostHogStateless, so the device keys sit in a client-only set thatcom.posthog.PostHogadds, and posthog-server strips them. posthog-server doesn't send minimal flag calls today, because its feature flags never report the gate, so that part only takes effect once it does.💚 How did you test it?
$app_buildand$app_namespaceare dropped.$referring_domain, every campaign key and$referreras super properties, and checks that each allowlisted key survives and$referrerdoesn't.$raw_user_agent,$timezone,$host,$cookieless_extra,$user_agentand$locale, and checks that only the first four survive.$browser,$browser_version,$os,$viewport_width,$viewport_heightand$current_url, and checks that all of them survive.PostHogStatelessTesttest, on the path posthog-server inherits, turns the gate on and passes a caller's values for all ten client-only keys through the context. It checks that all ten are stripped and that$raw_user_agentand$ipstay. It doesn't run in the server module, because posthog-server can't turn the gate on yet.Each new test failed before its change.
:posthog:test,:posthog-server:testand:posthog:apiCheckpass.📝 Checklist
If releasing new changes
pnpm changesetto generate a changeset file🤖 Agent context
Autonomy: Human-driven (agent-assisted)
$os. It sends$os_name, so I kept that key.mainalready keeps$geoip_disableon minimal events, so this PR leaves it alone.