Skip to content

docs(flags): identify the flag definition on locally evaluated flag-called events - #168

Draft
posthog[bot] wants to merge 1 commit into
mainfrom
posthog/flag-called-local-flag-identity
Draft

posthog[bot] wants to merge 1 commit into
mainfrom
posthog/flag-called-local-flag-identity

Conversation

@posthog

@posthog posthog Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Why

Nothing in the specs says a $feature_flag_called event identifies which flag definition produced the value. feature-flag-called-tracker names $feature_flag_id and $feature_flag_version only in passing, inside the minimal-event allowlist, as "evaluation debug scalars the server/SDK already attaches" — which reads as "whatever the remote response happened to carry". A server SDK evaluating a flag locally therefore had no stated obligation to attach either one.

PostHog/posthog-python#1149 closed that gap. A locally evaluated read now takes id and version from the local flag definition, across get_feature_flag(), feature_enabled(), get_feature_flag_result() and the tracked get_feature_flag_payload() path. evaluate_flags() previously set $feature_flag_id but hardcoded version=None on the belief that local definitions carry no version; they do, so the snapshot record now reads it from the definition.

posthog-go still sets both properties only from evalResult.FlagDetail (remote /flags metadata) in posthog.go, so its locally evaluated events omit them. This records posthog-python's behavior as the winner for that divergence.

What changed

New requirement Flag definition identity on flag-called events in feature-flag-called-tracker:

  • $feature_flag_called carries $feature_flag_id and $feature_flag_version for a locally evaluated read as well as a remote one.
  • Local values come from the definition that produced the value, read from the same definitions snapshot, so a refresh between evaluation and capture cannot report another revision's identity.
  • Each property is omitted when its source does not carry it; a missing version does not suppress the id.
  • Applies to every read path that emits the event, and a structured snapshot read records the same values on the locally evaluated flag record.

No public API change, no change to the dedupe contract, and no change to the minimal-event allowlist — both properties were already on it.

Proposed, applied and archived on this branch per AGENTS.md: openspec/changes/archive/2026-11-03-add-local-flag-called-identity/.

Uncertain

  • The snapshot-consistency rule ("read the local definition from the same definitions snapshot that produced the value") generalizes an implementation detail of the posthog-python fix. It is the correct behavior under a concurrent definitions refresh, but no other SDK states it today.
  • The openspec CLI is not installed in this environment, so openspec validate --specs --strict was not run; the delta was applied and archived by hand following the format of the existing archived changes.

Created with PostHog Desktop

🤖 Generated with Claude Code

…cally evaluated flag-called events

Adds a requirement that $feature_flag_called carries $feature_flag_id and
$feature_flag_version for locally evaluated reads, taken from the local flag
definition, alongside the remote-metadata source the spec already implied.

Applied and archived under
openspec/changes/archive/2026-11-03-add-local-flag-called-identity/.

Generated-By: PostHog Desktop
Task-Id: 112c6ed8-79c4-492d-8bd5-7b3e2d16ed61
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.

0 participants