Skip to content

fix(flags): honor versioned local property matching - #312

Draft
marandaneto wants to merge 4 commits into
mainfrom
fix/versioned-boolean-local-evaluation
Draft

fix(flags): honor versioned local property matching#312
marandaneto wants to merge 4 commits into
mainfrom
fix/versioned-boolean-local-evaluation

Conversation

@marandaneto

@marandaneto marandaneto commented Sep 5, 2026

Copy link
Copy Markdown
Member

💡 Motivation and Context

Local flag evaluation needs to use the matching rules selected by the definitions response. This follows the backend change and shared SDK contract.

  • Read property_matching_version from definitions. Missing, 1, and unknown versions keep released legacy matching. Exactly 2 uses explicit scalar equality and member equality for nonempty filter arrays. Empty filters keep recursive truthiness, and is_not complements exact for known properties. For example, version 2 stops matching false against "banana" and matches ["true", "false"] against "true".
  • Keep the version, flags, dependency index, group mapping, cohorts, and ETag in one atomically replaced definitions snapshot. Each local evaluation pins that snapshot through value/payload APIs, all-flags, EvaluateFlags, capture enrichment, and recursive group/cohort/dependency evaluation. A version-only refresh takes effect even when flags are unchanged. A 304 retains the version, including when its ETag changes. Dependency result caches remain per evaluation.
  • Fix only the cohort dependency_chain decoding seam needed for recursive flag dependencies. JSON decodes chains as []any, while the parser previously accepted only []string. Accept either valid string-only form and leave malformed chains nil for the existing inconclusive path. Other parser behavior is unchanged.
  • Preserve server fallback when an active dependency has experience continuity enabled. Resolving a JSON-decoded cohort chain must not bypass the same continuity restriction applied to direct flag evaluation.
  • Require server evaluation when a dependency needs group context or is reached from a group-targeted condition. The dependency helper cannot safely reconstruct the referenced flag's person or group properties and bucketing ID. This also covers mixed-targeting flags, nested and negated cohorts, and cached references. A private per-call marker preserves that boundary without disabling ordinary group property-only cohorts. Person-context dependencies on person-only flags still evaluate locally.
  • Refresh the generated public API snapshot for the intentional FeatureFlagsResponse.PropertyMatchingVersion field addition.

This deliberately reduces local coverage for dependencies across group contexts, including mixed-targeting dependencies that also have person conditions. Normal calls can fall back to /flags. Local-only value and payload calls stay inconclusive, while bulk, EvaluateFlags, and capture paths omit unresolved flags without contacting the server.

Missing-property and ambiguous integral-number safeguards remain unchanged. The existing patch changeset documents the matching and cohort-chain fixes. There is no new disk or shared cache provider, and already-returned evaluation results remain snapshots. This PR does not opt the Go adapter into the optional harness coverage.

Compatibility: Adding an exported field to FeatureFlagsResponse requires consumers using unkeyed struct literals to update them. Keyed literals remain compatible.

💚 How did you test it?

Added featureflags_matching_version_test.go with HTTP definitions-to-local-API tests for missing/1/2/unknown versions, scalar and array matching, negation, null/missing properties, Unicode and canonical values, version-only reloads, 304/error retention, groups, recursive cohorts, flag dependencies, and both capture paths. A deterministic mid-evaluation snapshot replacement verifies that definitions cannot mix across a single evaluation. Dependency-chain tests cover typed, JSON-decoded, and malformed inputs.

Added featureflags_cohort_continuity_test.go after independently reproducing the continuity regression. It covers versions 0/1/2/3, enabled and disabled continuity, direct and cohort local-only evaluation, combined value/payload evaluation, raw and pre-parsed cohorts, and cached inconclusive dependencies. The regression failed before the fix and passes afterward. The API snapshot check also failed before regeneration and passes afterward.

Added featureflags_cohort_group_context_test.go after independently reproducing both directions of the group-context bug. Its 76 cases cover flag-level and condition-level targeting, versions 0/1/2/3 for referenced group flags and 1/2 for group callers, OR/AND/nested/negated cohorts, indirect dependencies, raw and pre-parsed cohorts, and repeated cached references. Controls verify direct group flags, person-only dependencies, and group property-only cohorts still evaluate locally. Local-only value/payload/bulk/EvaluateFlags/capture paths make no remote requests. Both regressions failed before their respective fixes and pass afterward.

Validation for 4bd87debb95d6311abb4c7ab0c835fc00b88fc05:

go test -run '^(TestGroupContextPersonFlagDependency|TestCohortFlagDependencyGroupContext)$' -count=1 -v .
go test -race -count=1 -timeout=5m ./...
go vet ./...
bin/api-diff
git diff --check

All final checks passed. The full race suite passed all root-module packages, with the root package completing in 47.016s. Changed Go files are formatted. An earlier race run hit an existing shutdown timing assertion, and an intermediate test fixture needed its logger initialized. Both logs were retained and the final full suite passed. The first required committed-branch autoreview found the inverse group-to-person dependency bug. That finding was independently reproduced and fixed in a second new signed commit. The final isolated autoreview against origin/main reported no actionable findings for this exact commit. Live-service and cross-SDK harness integration were not run. These are local results, not a claim that CI passed.

📝 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 pnpm changeset to generate a changeset file

The existing .changeset/versioned-property-matching.md patch entry is included. The generator was not rerun. The public struct-literal compatibility caveat is described above.

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Pi agents implemented, independently reviewed, and updated this change under human direction using file tools, Git, Go tests, GitHub CLI, and the isolated autoreview helper. The review fixes preserve continuity and group-context fallback boundaries and refresh the generated API snapshot. A private group-context marker was approved after the inverse dependency bug was reproduced. No public API or matching-rule changes were added by these fixes. The human-directed scope includes the narrow JSON dependency-chain fix, not broader parser cleanup. Human review is required before merge.

Session context is local and has no shareable URL. Review, reproduction, and publication evidence were retained outside the repository.

@marandaneto marandaneto self-assigned this Sep 5, 2026
@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

posthog-go Compliance Report

Date: 2026-09-05 15:51:49 UTC
Duration: 169194ms

✅ All Tests Passed!

111/111 tests passed


Capture_V1 Tests

94/94 tests passed

View Details
Test Status Duration
Endpoint And Method.Targets V1 Endpoint 24ms
Endpoint And Method.Does Not Use Legacy Endpoints 6ms
Required Headers.Has Authorization Bearer Header 6ms
Required Headers.Has Content Type Json 16ms
Required Headers.Has Posthog Sdk Info Format 6ms
Required Headers.Has Posthog Attempt Header 6ms
Required Headers.Has Posthog Request Id 6ms
Required Headers.Has Posthog Request Timestamp 5ms
Required Headers.Has User Agent 7ms
Body Format.Body Has Created At And Batch 6ms
Body Format.No Api Key In Body 5ms
Body Format.No Sent At In Body 6ms
Event Format.Event Has Required Root Fields 6ms
Event Format.Event Uuid Is Valid 6ms
Event Format.Event Timestamp Is Rfc3339 6ms
Event Format.Distinct Id Is String 6ms
Event Format.Distinct Id At Root Not Properties 6ms
Event Format.Custom Properties Preserved 6ms
Event Format.Set Properties Preserved 6ms
Event Format.Set Once Properties Preserved 6ms
Event Format.Groups Properties Preserved 6ms
Event Format.Sdk Generates Uuid If Not Provided 6ms
Event Format.Event Has Required Root Fields Batch 8ms
Event Format.Event Uuid Is Valid Batch 9ms
Event Format.Event Timestamp Is Rfc3339 Batch 8ms
Event Format.Distinct Id Is String Batch 8ms
Event Format.Distinct Id At Root Not Properties Batch 9ms
Event Format.Custom Properties Preserved Batch 8ms
Event Format.Set Properties Preserved Batch 8ms
Event Format.Set Once Properties Preserved Batch 9ms
Event Format.Groups Properties Preserved Batch 8ms
Event Format.Sdk Generates Uuid If Not Provided Batch 9ms
Batch Behavior.Multiple Events In Single Batch 31ms
Batch Behavior.Batch Envelope Smoke 10ms
Batch Behavior.Flush With No Events Sends Nothing 3ms
Batch Behavior.Flush At Triggers Batch 1008ms
Batch Behavior.Created At Reflects Batch Creation Time 7ms
Deduplication.Generates Unique Uuids 16ms
Deduplication.Different Events Same Content Different Uuids 9ms
Deduplication.Preserves Uuid On Retry 5132ms
Deduplication.Preserves Timestamp On Retry 5134ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry 5137ms
Deduplication.No Duplicate Events In Batch 31ms
Header Behavior On Retry.Attempt Header Starts At One 6ms
Header Behavior On Retry.Attempt Header Increments On Retry 10140ms
Header Behavior On Retry.Request Id Preserved On Retry 5134ms
Header Behavior On Retry.Different Requests Have Different Request Ids 2014ms
Header Behavior On Retry.Request Timestamp Changes On Retry 5134ms
Response Format Validation.Success Response Has Uuid Keyed Results 7ms
Response Format Validation.Success Response Has Ok For Each Event 28ms
Response Format Validation.Success No Retry After When All Ok 28ms
Response Format Validation.Success Retry After Present When Retry Events 130ms
Response Format Validation.Success No Retry After When Drop Only 28ms
Response Format Validation.Response Echoes Request Id 6ms
Retry Behavior.Retries On 408 5135ms
Retry Behavior.Retries On 500 5135ms
Retry Behavior.Retries On 503 5137ms
Retry Behavior.Retries On 504 5136ms
Retry Behavior.Retryable Errors Have Retry After 2134ms
Retry Behavior.Respects Retry After On Retryable Error 8139ms
Retry Behavior.Does Not Retry On 400 2133ms
Retry Behavior.Does Not Retry On 401 2133ms
Retry Behavior.Does Not Retry On 402 2134ms
Retry Behavior.Does Not Retry On 413 2133ms
Retry Behavior.Does Not Retry On 415 2134ms
Retry Behavior.Non Retryable Errors Have No Retry After 2134ms
Retry Behavior.Implements Backoff 15145ms
Retry Behavior.Max Retries Respected 15143ms
Partial Batch Handling.Handles 200 Full Success 2010ms
Partial Batch Handling.Handles 200 With All Ok 3031ms
Partial Batch Handling.Does Not Retry Dropped Events 3031ms
Partial Batch Handling.Does Not Retry Limited Events 3032ms
Partial Batch Handling.Prunes Ok Events On Partial Retry 5133ms
Partial Batch Handling.Prunes Dropped Events On Partial Retry 5135ms
Partial Batch Handling.Retries Only Retry Events From Partial 5138ms
Partial Batch Handling.Partial Retry Preserves Uuids 5135ms
Partial Batch Handling.Partial Retry Attempt Header Increments 5136ms
Partial Batch Handling.Partial Retry Request Id Preserved 5137ms
Partial Batch Handling.Respects Retry After On Partial 5136ms
Partial Batch Handling.Unknown Result Treated As Terminal 3030ms
Partial Batch Handling.Mixed Ok Drop Limited No Retry 3033ms
Compression.Sends Gzip Content Encoding 18ms
Compression.No Content Encoding When Disabled 7ms
Compression.Compressed Body Is Decompressible 16ms
Error Handling.Does Not Retry On Unknown 4Xx 2133ms
Event Options.Cookieless Mode Override 7ms
Event Options.Disable Skew Correction Override 6ms
Event Options.Process Person Profile Override 6ms
Event Options.Product Tour Id Override 6ms
Event Options.Unset Options Omitted 5ms
Event Options.Options Override In Batch 9ms
Geoip And Historical Migration.Geoip Disable Injected Into Properties 6ms
Geoip And Historical Migration.Historical Migration Set In Body 6ms
Geoip And Historical Migration.Historical Migration Absent By Default 6ms

Feature_Flags Tests

17/17 tests passed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id 16ms
Request Payload.Flags Request Uses V2 Query Param 15ms
Request Payload.Flags Request Hits Flags Path Not Decide 16ms
Request Payload.Flags Request Omits Authorization Header 16ms
Request Payload.Token In Flags Body Matches Init 15ms
Request Payload.Groups Round Trip 17ms
Request Payload.Groups Default To Empty Object 15ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False 16ms
Request Payload.Disable Geoip Omitted Defaults To False 16ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key 16ms
Request Lifecycle.No Flags Request On Init Alone 2ms
Request Lifecycle.No Flags Request On Normal Capture 7ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests 29ms
Request Lifecycle.Mock Response Value Is Returned To Caller 16ms
Retry Behavior.Retries Flags On 502 17ms
Retry Behavior.Retries Flags On 504 17ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event 18ms

@marandaneto
marandaneto marked this pull request as ready for review September 5, 2026 17:29
@marandaneto
marandaneto requested a review from a team as a code owner September 5, 2026 17:29
@greptile-apps

greptile-apps Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor
Prompt To Fix All With AI
### Issue 1
.changeset/versioned-property-matching.md:2
**Patch release breaks consumers**

If consumers use unkeyed composite literals for the exported `FeatureFlagsResponse` struct, adding `PropertyMatchingVersion` makes their code fail to compile. This changeset requests a patch release even though the repository's release policy reserves major releases for breaking changes. Please either use a non-breaking representation or mark the release accordingly.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Reviews (1): Last reviewed commit: "fix(flags): reject dependencies evaluate..." | Re-trigger Greptile

@@ -0,0 +1,5 @@
---
"posthog-go": patch

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Patch release breaks consumers

If consumers use unkeyed composite literals for the exported FeatureFlagsResponse struct, adding PropertyMatchingVersion makes their code fail to compile. This changeset requests a patch release even though the repository's release policy reserves major releases for breaking changes. Please either use a non-breaking representation or mark the release accordingly.

Prompt To Fix With AI
This is a comment left during a code review.
Path: .changeset/versioned-property-matching.md
Line: 2

Comment:
**Patch release breaks consumers**

If consumers use unkeyed composite literals for the exported `FeatureFlagsResponse` struct, adding `PropertyMatchingVersion` makes their code fail to compile. This changeset requests a patch release even though the repository's release policy reserves major releases for breaking changes. Please either use a non-breaking representation or mark the release accordingly.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@marandaneto
marandaneto marked this pull request as draft September 6, 2026 07:00
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.

1 participant