Repository navigation
Conversation
…ent splits When the stored record that supplied a read's value is a config version 2 experiment split, posthog-js now sends `$experiment_exposure` next to `$feature_flag_called`. The `$feature_flag_called` of every config version 2 flag carries the config version, the reason code and, by the contract's table, the rule ID, rule type and variant key, in place of the human-readable `$feature_flag_reason`. Config version 1 events do not change. This ports the posthog-node change to the browser. Both events and their dedupe keys are built in one step from the stored record, in `flag-events.ts`, which the v4 response format brings with it: a client of the shared flags extension that does not opt in to v4 sends its events as before, and does not bundle the module. A record supplies a value only when no value override applies and the legacy rendering of its typed value is the stored flag value, so a bootstrapped, overridden or separately written value sends the call as before and no exposure. A payload override keeps both. The dedupe keys are stored in `$flag_call_reported`, under the flag key, next to the values that config version 1 calls are deduped by. The exposure has its own key, so a reported call never suppresses it, and both follow the reported calls across page loads, tabs, identity changes and per-session dedupe. Older posthog-js versions that share the storage ignore the keys and keep theirs. A key is kept only when capture handles its event. It is released when the capture call or `before_send` throws, the client rate limit drops the event, or capturing is turned off while the event is captured. The capture pipeline drops the properties that a config version 2 flag event never carries after the super properties are merged, and a minimal config version 2 call keeps its attribution. `$experiment_exposure` is never minimized.
Coherence📄 0 spec file errors · ⛔ 0 broken rules · 🚪 0 unchecked inputs · 🐛 0 bugs that came back What is Coherence?Coherence compares the code with its spec files ( This check read 44 parts of the code and 7 rules. Tip Nothing to fix. |
|
Size Change: +85.9 kB (+0.31%) Total Size: 27.4 MB 📦 View Changed
ℹ️ View Unchanged
|
Node SDK acceptance v2Commit: e3373c5 Capture v0✅ 233 passed / ❌ 4 non-passing / Drill-down: run artifacts → ❌ server_snapshot_payload_false — failed_assertionExpected native data result Code: Failed step: acceptance/public/evaluate-flags.feature:868 the public snapshot outcomes should have these semantics: ❌ server_snapshot_payload_zero — failed_assertionExpected native data result Code: Failed step: acceptance/public/evaluate-flags.feature:868 the public snapshot outcomes should have these semantics: ❌ server_snapshot_payload_null — failed_assertionExpected native data result Code: Failed step: acceptance/public/evaluate-flags.feature:868 the public snapshot outcomes should have these semantics: ❌ migration/yaml-parity-v1/remote-flags-v1.feature::Omitted GeoIP settings default to enabled in flag requests — failed_assertionFlags field differs Code: Failed step: migration/yaml-parity-v1/remote-flags-v1.feature:135 the first flags request field "geoip_disable" should equal JSON false Operation: Field: Expected: false Actual value: true Harness exit: 1; report validation exit: 1. Capture v1✅ 298 passed / ❌ 4 non-passing / Drill-down: run artifacts → ❌ server_snapshot_payload_false — failed_assertionExpected native data result Code: Failed step: acceptance/public/evaluate-flags.feature:868 the public snapshot outcomes should have these semantics: ❌ server_snapshot_payload_zero — failed_assertionExpected native data result Code: Failed step: acceptance/public/evaluate-flags.feature:868 the public snapshot outcomes should have these semantics: ❌ server_snapshot_payload_null — failed_assertionExpected native data result Code: Failed step: acceptance/public/evaluate-flags.feature:868 the public snapshot outcomes should have these semantics: ❌ migration/yaml-parity-v1/remote-flags-v1.feature::Omitted GeoIP settings default to enabled in flag requests — failed_assertionFlags field differs Code: Failed step: migration/yaml-parity-v1/remote-flags-v1.feature:135 the first flags request field "geoip_disable" should equal JSON false Operation: Field: Expected: false Actual value: true Harness exit: 1; report validation exit: 1. |
SDK performance: posthog-nodeBenchmarks 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 |
…ndehen/browser-experiment-exposure
…owns them Four cases that a review of the events found: - A hook that reads the flag while its `$feature_flag_called` is captured sent the exposure, and the outer read then sent it again. Each capture now checks the stored keys itself. - The exposure is not sent when the distinct ID, groups or session changed while the call was captured, as for a read that is held. - A stored override state that is not a map of flags, which the deprecated `override(true)` stores, made every tracked read throw. Only an object with the flag as its own key is a value override. - A read that was held with a bootstrapped or older value was dropped when a typed record supplied the same value before capture was on. A held read is now dropped only when the value changed, or when both the held and the current read have a config version 2 assignment and they differ.
… every read A key is released when the capture of its config version 2 flag event throws, so a later read sends the event. With a hook that always throws, every read then captured again, and each capture uses a client rate limit token before the hook runs, so a render loop could starve other events. An event whose capture threw twice now waits for the next page load or identity.
…ndehen/browser-experiment-exposure # Conflicts: # packages/browser-common/src/flags-response-v4.ts
`flag-events.ts` in browser-common now mirrors `packages/node/src/flag-events.ts`: rule attribution, the config version 2 `$feature_flag_called` and `$experiment_exposure` properties, their dedupe keys and the two capture functions, with the same names and bodies, so that they can move to `@posthog/core` unchanged. What a browser SDK does differently stays outside it: - `flags-response-v4.ts` checks that the stored record supplied the read's value before it calls the shared builder. - The tracker in `feature-flags.ts` stores posthog-node's dedupe keys in the reported calls of the flag, with the exposure's key under its event name, and hands the client posthog-node's two capture options. - `capture()` applies them with `applyFlagEventCapture` and `minimizeConfigVersion2FlagCalledProperties`, as posthog-node's capture does. The events and when they are sent do not change. The stored dedupe keys now start with the flag key, as posthog-node's do.
…ndehen/browser-experiment-exposure
…ndehen/browser-experiment-exposure
…again This reverts d747e3e, which replaced the flag event code written for the browser with a copy of posthog-node's `flag-events.ts`. Together with the copied reader it added about 4.3 KiB to the minified bundle, and its only gain was an easier later move of that code to `@posthog/core`. The stored dedupe keys go back to the browser's format: they do not repeat the flag key, because they are stored per flag key.
…ndehen/browser-experiment-exposure Brings in the browser's own reader again and the public getters that return no typed member of a flag record. Conflicts: - `flags-response-v4.ts`: the reader of the base branch, with the flag events wired to it as before the copy of posthog-node's code. - `feature-flags.ts`: both sides kept. The properties of `$feature_flag_called` read the stored record. - `released-flags.test.ts`: both sides kept. The reason codes that the v4 response gives config version 2 flags also apply to the records that `getFlagsWithDetails()` returns. `flag-events.spec.ts` reads the record with `readFlagRecords` again, and gets a test of a stored record whose members have the wrong types.
Problem
For a config version 2 flag, the
/flags?v=4record names the reason code, rule and variant that produced a value, so the SDK can send the experiment exposure itself. posthog-node does this since #5636. posthog-js reads the record since #5729, but still reports every flag with the legacy$feature_flag_calledonly.Changes
When the stored record that supplied a read's value is a config version 2 experiment split, posthog-js now sends
$experiment_exposurenext to$feature_flag_called. The$feature_flag_calledof every config version 2 flag carries the config version, the reason code and the rule attribution, and the reason code replaces the human-readable$feature_flag_reasonon these events. Config version 1 events do not change. This ports #5636 to the browser and follows theexperiment-exposureandfeature-flag-called-trackerspecs in PostHog/sdk-specs.Stacked on #5729. The base branch is
andehen/browser-flags-v4, so the diff shows only this PR's change. The two PRs should land and release together.Where to look. Of the 2,820 added lines, about 2,220 are tests. The source is
packages/browser-common/src/flag-events.ts(243 lines: rule attribution, the properties of both events and their dedupe keys), about 260 lines inpackages/browser-common/src/feature-flags.ts(the stored tracker) and 24 inpackages/browser/src/posthog-core.ts.typed-flag-detail.ts(44 lines) is the type of the stored record, moved out of the reader so that both files use it.getFeatureFlag(),isFeatureEnabled()andgetFeatureFlagResult().send_event: falsesuppresses both events and stores nothing.getFeatureFlagPayload()sends no flag events, as before.updateFlags()value and a record stored by an older posthog-js version send the call as before, and no exposure. A payload override keeps both events.$flag_call_reported, under the flag key, next to the values that config version 1 calls are deduped by. The exposure's key starts with its event name, so a reported call never suppresses it. No stored property is added.before_sendthrows, the client rate limit drops the event, or capturing is turned off while the event is captured. After a throw one later read tries again; after a second throw the event waits for the next page load or identity, so a hook that always throws cannot make every read capture again.capture()drops them after super properties are merged, so a registered property can neither change the attribution nor add such a field. A minimal config version 2 call keeps its attribution.$experiment_exposureis never minimized.@posthog/browser, which does not opt in, sends its events as before and does not bundle the new module. Its flags bundle grows by 1,565 B minified (496 B gzip) from the shared code that calls the seam.posthog-jsminor,@posthog/browser-commonpatch.What users can notice, for config version 2 flags only:
$feature_flag_calledhas$feature_flag_reason_codeand no$feature_flag_reason.posthog.group()changes the groups sends both events again, because both dedupe keys include the groups (as in posthog-node). A config version 1 call is deduped by its value alone, as before.Bundle size (
pnpm bundle-size:array,array.js): +3.81 KiB minified, +1.38 KiB gzip (+1.06%) over #5729. Both PRs together againstmain: +5.96 KiB minified, +2.09 KiB gzip (+1.62%).Copies of posthog-node's reader and events code replaced the browser's own for a few commits, so that both could later move to
@posthog/coreas a plain move. Together they measured +9.72 KiB minified, +2.96 KiB gzip, and were taken out again (fe9839c,d45b2be) for that cost.Tests
flag-events.spec.ts(250 tests): every contract reader case on every read path, attribution by reason code (stray rule fields, failed records, half pairs, disallowed rule types, unknown and missing reason codes, non-UUID rule IDs, empty variant keys), exact properties of both events checked against the contract's event schemas, what sends no exposure, dedupe (A/A variants, a new rule, value changes, holdout then split, config version 1 to 2, groups, a reload, the next page load, identity change, per-session dedupe), capture failures, and stored records whose members have the wrong types.featureflags-exposure.test.ts(15 tests) runs a real client: super properties, minimal events,before_send(sees both, discards, throws), opt-out and opt-in, an opt-out while the call is captured, identify and reset, disabled flags. Each pipeline rule was checked to fail when the rule is removed.released-flags.test.ts: from the v2 response, every scenario still matches the 1.448.0 recording exactly. From the v4 response, the test states the whole difference: config version 2 calls carry their attribution, the split's call is followed by its exposure, and the group change above. Nothing else changes.@posthog/browser(660), browser functional tests, lint,check-types,oxfmt --check, the public API reference check and the mangled-name check.Detail: event properties, dedupe keys, differences from posthog-node
$feature_flag_calledadditions (config version 2 records only)$feature_flag_config_version2$feature_flag_reason_codereason.code. It replaces$feature_flag_reason.$feature_flag_rule_id,$feature_flag_rule_type$feature_flag_variant_keyA complete split has reason
experiment_split, rule typeexperiment, a rule ID in hyphenated UUID form and a variant key. A split without all of them reports its reason and no rule, and sends no exposure. A failed record, and a reason code this SDK does not know, report no rule either.$experiment_exposureproperties$feature_flag,$feature_flag_response(the same legacy value as on the call),$feature_flag_variant_key,$feature_flag_rule_id,locally_evaluated: false, and$feature_flag_id,$feature_flag_version,$feature_flag_request_idand$feature_flag_evaluated_atwhen the call has them. It goes through the normal capture path, so it has the same distinct ID, groups and session as its call, and its own UUID. It carries no config version, rule type, reason code or source marker.Dedupe keys
Stored as strings in
$flag_call_reported[<flag key>]:JSON.stringify([response, groups, 2, reasonCode, ruleId, ruleType, variantKey]), withnullfor an absent member and the groups sorted by type.JSON.stringify(['$experiment_exposure', groups, 2, ruleId, variantKey]). The value, request ID and evaluation time are left out, so one assignment sends one exposure. posthog-node keeps this key in a cache of its own; here both kinds live in one stored list, so the event name keeps them apart."true","control"), so the entries cannot collide.The keys follow the reported calls: the next page load and other tabs do not send the events again, and identify, reset and per-session dedupe clear both. A flags reload clears neither. An older posthog-js version that shares the storage does not find its value among the keys, sends its own legacy call once and adds its value. A scripted check with 1.448.0 and 1.300.0 from npm showed this, and that a later page of this build still sends nothing.
Differences from posthog-node
packages/node/src/flag-events.tsand shares the nameruleAttribution, but not its code. Sharing it through@posthog/coreis left for later.capture()only drops the names the event never carries.errorsWhileComputingFlagsis not stored, as before, so the read reports the cached record or a missing flag. A failed record of a complete response reports its config version and reason code.before_sendthrow.capture()tells the flags code when a hook throws for a flag event, as posthog-node's capture does, so that key is released. Other events are unchanged. After a second throw the event waits for the next page load or identity.MaporSetconstructor that takes values and no built-in that the flags code onmaindoes not already use, apart from aMapand aWeakMapthat start empty. The ES5 entrypoint is unchanged.Not in this PR
capture_v0andencoding_gzip.Release info Sub-libraries affected
Libraries affected
Checklist
If releasing new changes
pnpm changesetto generate a changeset file🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Written with Claude Code, as a port of #5636 with its review decisions kept: a value override drops the record and a payload override keeps it, and a key is released when the event is dropped by consent.
$flag_call_reportedinstead, because released builds copy unknown stored properties onto every event, and that property is already cleared with the identity.capture()the capture rules of an event through a method on the extension, keyed by the properties object. A module-level map was rejected because the slim core and the extension bundles are built separately, so each would get its own copy of it.__proto__in the reader.🤖 Generated with Claude Code