Skip to content

fix: exclude failed feature flag values and payloads - #156

Merged
marandaneto merged 4 commits into
mainfrom
fix/spec211-failed-flags
Nov 13, 2026
Merged

marandaneto merged 4 commits into
mainfrom
fix/spec211-failed-flags

Conversation

@marandaneto

@marandaneto marandaneto commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

💡 Motivation and Context

Detailed feature flags marked failed: true must not expose placeholder values or payloads, or prevent boolean getters from honoring the caller's default. This implements sdk-specs #211 on Unity's existing flag surfaces, including the canonical failed-result rules and complete-response replacement rules.

Flag values, payloads and diagnostics

  • Failed details have no evaluated value or payload and are excluded from cached key enumeration, even when flat mirrors are present. The failure marker survives cache serialization.
  • Getters honor caller defaults instead of serving placeholders. Failed tracked reads report evaluation_failed; response-wide errors_while_computing_flags remains independent and survives persistence. Tracking uses Unity's existing empty-string missing-response sentinel, not the caller's default.
  • Response-wide errored refreshes merge healthy updates while retaining previously successful value/payload pairs. Complete responses without response-wide errors replace state, including failed and omitted keys. Healthy false, legacy values, suppression and dedupe retain their meanings.

Identity-safe retention

The new errored-merge behavior exposed an existing lifecycle gap: neither identity path invalidated the old flag cache, allowing a parsed refresh for a new user to retain the previous user's targeted values and payloads.

  • Identify invalidates in-memory and persistent flag state on an actual effective distinct-ID change; same-ID and rejected-ID calls without other changes preserve valid fallback.
  • Reset always invalidates, including when anonymous-ID reuse keeps the same string. Invalidation is independent of preload configuration.
  • A bounded in-memory request generation prevents an old in-flight response from repopulating cleared cache/maps/metadata or persistence. Acceptance and invalidation share the existing manager lock through persistence. A reload queued after invalidation runs for the current identity before the original and queued callbacks or loaded event complete.
  • Native default-property population was moved unchanged into a private helper so the .NET source harness can execute the existing no-default/custom-only fast paths without JIT-resolving native Unity getters. Values, allocation, configuration gates and custom-property override order are unchanged.

Intentional difference from JS: Unity invalidates on anonymous-to-identified ID changes too; JS reloads while retaining prior cached values. The identify contract requires reload, not this extra wipe. This PR chooses strict distinct-ID-context isolation. An offline/failed login reload, or preload disabled without an explicit reload, therefore leaves getters using defaults and old persisted flags cleared across restart (subject to existing best-effort storage). A generation bump alone rejects late responses but still permits serving/merging old cached decisions. This intentionally changes Unity's earlier login retention.

No public API, cache schema, persisted identity fingerprint, per-user namespace or SDK dependency changes. The existing patch changeset covers the behavior changes.

Reproducible formatting

CSharpier 1.2.6 is pinned in the repository-local .NET tool manifest. Bootstrap and formatting restore/run that same tool rather than relying on a global installation; CONTRIBUTING documents this resolution. This preserves the verified formatter pin without unrelated source reformatting or a .NET SDK pin change.

💚 How did you test it?

Current signed and autoreviewed HEAD: 47848e248f69dcb46de86edb75209f04d394d390. Local verification used .NET SDK 9.0.121 and the existing Unity-stub source harness, not CI's 9.0.102 or a native Unity player.

  • Existing identity-suite baseline: 23 passed.
  • bin/test --filter FullyQualifiedName~IdentityInvalidation_FetchesCurrentIdentityBeforeSettlingCallbacks first failed all 4 paused-preload cases because Identify/Reset waiters completed before a current-identity request. The identical command passes after the fix, including anonymous-ID reuse and A-to-B-to-A transitions.
  • The full new identity matrix first had 8 expected behavioral failures / 22 passes, then 30 passes. It covers current-request values, payloads and persistent request metadata before task completion, repeated identity changes during the follow-up, fire-and-forget reloads, unchanged same-context coalescing, no unsolicited request when preload is disabled, and completion after empty/malformed current responses.
  • A controlled stale-acceptance mutation still fails all four paused-preload cases with an old value present. Restoring the generation guard passes, so the scheduling fix retains the prior privacy protection.
  • Earlier identity/cache regressions remain: flat/rich true/false/variant retention, failed/omitted keys, same/invalid identity, preload-disabled deletion and custom-only properties. Original model/cache/getter cases retain failed-marker round trips, error-bit independence, legacy flat mirrors, payload pairing, replacement boundaries, defaults, metadata, suppression and dedupe.
  • Full bin/test: 592 passed, 3 existing explicit skips, 0 failed.
  • bin/fmt --check: passed with pinned CSharpier 1.2.6. Only the two changed files were formatted.
  • bin/build: C#9/netstandard2.1 stub build passed. bin/check-public-api: passed, unchanged snapshot. git diff --check: passed.
  • Full-target test Authoring audit and deslop completed. Mandatory isolated autoreview --mode branch --base origin/main on the exact signed HEAD above and base 854e0c4e31ab22cb2609ee423a2823d599332aaa was clean, with TruffleHog clean and no accepted/actionable findings.

Limits and unchanged contracts

  • No real Unity Editor/player, IL2CPP, WebGL, actual HTTP or shared-harness wire conformance was run. The existing skips are the settings default comparison and two WebGL callback integration tests. Native default-enabled property values remain inspected rather than executed.
  • Same-generation concurrent reloads still share their current request. Only an invalidated response with a reload queued for the current generation starts a replacement request. Callback/listener bookkeeping completes after that current cycle, including its existing empty/malformed-response completion behavior.
  • Group/property-only invalidation and reload=false semantics remain separate. Storage is still best-effort; no migration of already mismatched state or transactional identity/cache protocol was introduced.
  • No new public API, persisted schema, dependency, manual version bump or duplicate release intent. CI is not awaited and no full platform/conformance claim is made.

📝 Checklist

  • New follow-up commit is signed and locally signature-verified.
  • Reviewed the full branch diff and retained meaningful regression tests.
  • Added tests before production fixes and observed the expected behavioral failures.
  • Formatting, stub build, public API and .NET tests passed locally.
  • Existing patch changeset retained; no manual version bump or extra release intent.
  • Contributor tooling documentation updated; no new public API documentation required.

🤖 Agent context

Autonomy: Human-driven (agent-assisted). Human DRI: @marandaneto. Pi implemented the approved fixes and ran the tests, source/test audit, and isolated autoreview listed above. Human review is required before merge. No shareable session link is available.

@marandaneto marandaneto self-assigned this Nov 12, 2026
@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

posthog-unity Compliance Report

Date: 2026-11-12 14:21:00 UTC
Duration: 105816ms

✅ All Tests Passed!

46/46 tests passed


Capture Tests

✅ 29/29 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields ✅ 78ms
Format Validation.Event Has Uuid ✅ 12ms
Format Validation.Event Has Lib Properties ✅ 8ms
Format Validation.Distinct Id Is String ✅ 8ms
Format Validation.Token Is Present ✅ 9ms
Format Validation.Custom Properties Preserved ✅ 13ms
Format Validation.Event Has Timestamp ✅ 9ms
Retry Behavior.Retries On 503 ✅ 6519ms
Retry Behavior.Does Not Retry On 400 ✅ 2015ms
Retry Behavior.Does Not Retry On 401 ✅ 2011ms
Retry Behavior.Respects Retry After Header ✅ 8017ms
Retry Behavior.Implements Backoff ✅ 18535ms
Retry Behavior.Retries On 500 ✅ 5517ms
Retry Behavior.Retries On 502 ✅ 5516ms
Retry Behavior.Retries On 504 ✅ 5516ms
Retry Behavior.Max Retries Respected ✅ 18518ms
Deduplication.Generates Unique Uuids ✅ 13ms
Deduplication.Preserves Uuid On Retry ✅ 5515ms
Deduplication.Preserves Uuid And Timestamp On Retry ✅ 11524ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry ✅ 5518ms
Deduplication.No Duplicate Events In Batch ✅ 12ms
Deduplication.Different Events Have Different Uuids ✅ 8ms
Compression.Sends Gzip When Enabled ✅ 8ms
Batch Format.Uses Proper Batch Structure ✅ 6ms
Batch Format.Flush With No Events Sends Nothing ✅ 4ms
Batch Format.Multiple Events Batched Together ✅ 10ms
Error Handling.Does Not Retry On 403 ✅ 2008ms
Error Handling.Does Not Retry On 413 ✅ 2010ms
Error Handling.Retries On 408 ✅ 5516ms

Feature_Flags Tests

✅ 17/17 tests passed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id ✅ 21ms
Request Payload.Flags Request Uses V2 Query Param ✅ 6ms
Request Payload.Flags Request Hits Flags Path Not Decide ✅ 5ms
Request Payload.Flags Request Omits Authorization Header ✅ 4ms
Request Payload.Token In Flags Body Matches Init ✅ 5ms
Request Payload.Groups Round Trip ✅ 5ms
Request Payload.Groups Default To Empty Object ✅ 5ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False ✅ 5ms
Request Payload.Disable Geoip Omitted Defaults To False ✅ 5ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key ✅ 6ms
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 ✅ 9ms
Request Lifecycle.Mock Response Value Is Returned To Caller ✅ 7ms
Retry Behavior.Retries Flags On 502 ✅ 509ms
Retry Behavior.Retries Flags On 504 ✅ 509ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event ✅ 8ms

@marandaneto
marandaneto marked this pull request as ready for review November 12, 2026 12:13
@marandaneto
marandaneto requested a review from a team as a code owner November 12, 2026 12:13
@veria-ai

veria-ai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

PR overview

No security issues were found in this pull request.

Reviews

@posthog posthog Bot left a comment

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.

PostHog Review · Standard · reviewed 1aacbd5: 1 Should fix.

See this review and its findings in PostHog Review. Comment @posthog review --deep for a Deep review. A Deep review takes longer and looks deeper than a Standard review.

@posthog posthog Bot left a comment

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.

PostHog Review · Standard · reviewed f64fe00: 1 Should fix.

@ioannisj ioannisj left a comment

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.

🤖 An AI agent wrote this on behalf of @ioannisj.

One question, nothing blocking. identify now clears the cached and persisted flags on any distinct ID change, including the anonymous to identified login, and posthog-js and the identify spec only reload there. Worth confirming that's intended before merge.

Comment thread com.posthog.unity/Runtime/PostHogSDK.cs Resolved
@marandaneto
marandaneto merged commit db001d8 into main Nov 13, 2026
19 of 20 checks passed
@marandaneto
marandaneto deleted the fix/spec211-failed-flags branch November 13, 2026 13:52
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.

2 participants