Skip to content

feat(flags): report unresolved local flags on EvaluateFlagsAsync snapshots - #357

Draft
gustavohstrassburger wants to merge 2 commits into
mainfrom
posthog/unresolved-local-flags
Draft

gustavohstrassburger wants to merge 2 commits into
mainfrom
posthog/unresolved-local-flags

Conversation

@gustavohstrassburger

Copy link
Copy Markdown
Contributor

💡 Motivation and Context

Why: sdk-specs #85 defines how a server SDK reports flags that local evaluation could not resolve. Today such a flag is absent from the EvaluateFlagsAsync snapshot, so it looks the same as a flag that does not exist, and $feature_flag_called reports flag_missing for both. With OnlyEvaluateLocally this is permanent. posthog-node already implements this (PostHog/posthog-js#5234).

Changes:

  • FeatureFlagEvaluations.UnresolvedFlags maps each unresolved flag to an UnresolvedFlagReason (ExperienceContinuity, UnsupportedDefinition, UnresolvedDependency, MissingContext; ToValueString() and the JSON form give the spec strings). When several causes apply, the spec's fixed precedence picks one. Only, OnlyAccessed and Empty snapshots have no entries, and reading the map is not an access.
  • A snapshot read of an unresolved flag reports local_evaluation_inconclusive instead of flag_missing.
  • InconclusiveMatchException and RequiresServerEvaluationException carry an internal reason, so their shipped public surface does not change. The date and semver parsers tell a bad filter value (UnsupportedDefinition) from a bad person value (MissingContext).
  • LocalFeatureFlagsLoader logs a warning for flags local evaluation can never resolve, deduplicated per flag on the definition plus the reason and rebuilt on each 200. A 304 does not repeat it. The per-evaluation static-cohort error log is removed.

Behavior changes (in the changeset):

  • A condition no longer stops at the first filter it cannot check. If another filter does not match, the condition resolves locally as no match. A static cohort still forces the fallback only when it is the first filter in its condition that cannot be checked, as in posthog-node.
  • A condition that depends on a flag that needs the server no longer stops local evaluation at that condition, so a later condition can resolve the flag.
  • An inactive flag with experience continuity resolves to false locally.

Divergences from the spec or posthog-node:

  • A missing group key still resolves to false and there is no device-id bucketing, so neither gives MissingContext and the device-id acceptance row does not apply.
  • The definition model has no version field, so the warning fingerprint compares the parsed definition. There is no shared definitions cache, so the shared-cache warning row does not apply.
  • OnlyAccessed() with nothing accessed still returns all flags (existing behavior), so the spec step "only accessed returns no flags" differs. Its unresolved map is empty.

💚 How did you test it?

About 100 new xUnit tests mirror every scenario tagged @unresolved_flags_capable and @unresolvable_flag_warning_capable in acceptance/public/evaluate-flags.feature, plus precedence, the condition loop, dependencies, warning dedup and pruning, and unexpected errors. Run locally with the .NET 9 SDK:

  • dotnet restore --locked-mode
  • dotnet build --configuration Release --no-restore (0 warnings, 0 errors, PublicApiAnalyzers included)
  • dotnet test --configuration Release --no-build -f net8.0 (UnitTests 1504 passed, 2 skipped; AspNetCore 68; AI 19)
  • bin/fmt --check

The netcoreapp3.1 tests did not run locally because the machine has no libssl 1.1; CI covers them. No manual testing in an app.

📝 Checklist

  • All commits are signed (see Commit signing)
  • 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

🤖 Agent context

Autonomy: Human-driven (agent-assisted)


Created with PostHog Desktop

🤖 Generated with Claude Code

…shots

Implements the "Snapshot unresolved flag reporting" and "Warning for flags local evaluation never resolves" requirements of the evaluate-flags spec (PostHog/sdk-specs#85).

- Add `FeatureFlagEvaluations.UnresolvedFlags`, with an `UnresolvedFlagReason` for each flag and the spec's fixed precedence.
- Report `local_evaluation_inconclusive` instead of `flag_missing` when a snapshot read hits an unresolved flag.
- Do not stop a condition at the first inconclusive filter, so a filter that does not match resolves the condition locally.
- Check `active` before experience continuity.
- Log one warning per flag that local evaluation can never resolve, repeated only when its definition changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Generated-By: PostHog Desktop
Task-Id: 39793b31-809e-4689-a5d8-b4359cbb22c1
@gustavohstrassburger gustavohstrassburger self-assigned this Oct 27, 2026

@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 3c0989a: 3 Should fix.

This is the only automatic review while this pull request is a draft. Comment @posthog review to review new changes sooner. Otherwise, a review of the new changes runs when you mark it ready for review.

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.

Comment on lines +64 to +66
throw new InconclusiveMatchException(
"Unicode regex matching requires server evaluation",
UnresolvedFlagReason.UnsupportedDefinition);

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.

P2 · Classify unsupported Unicode input as missing context

With a valid pattern such as ^pro$ and property value café, this branch reports UnsupportedDefinition in UnresolvedFlags. The definition works with ASCII input; the supplied context causes the failure. The SDK contract required by AGENTS.md:11 classifies unusable context as MissingContext; report that reason here.

Comment on lines +908 to +913
case ComparisonOperator.Regex or ComparisonOperator.NotRegex:
if (value.StringValue is { } pattern && !RegexHelpers.IsCompatiblePattern(pattern))
{
throw new InconclusiveMatchException("Regex syntax requires server evaluation", UnresolvedFlagReason.UnsupportedDefinition);
}
return;

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.

P2 · Validate malformed regex syntax when scanning cohort definitions

For a dynamic cohort whose sole filter uses regex [, IsCompatiblePattern returns true without compiling it. GetDefinitionUnresolvedReason skips the warning, although MatchPropertyGroup always reports UnsupportedDefinition. This misses the definition warning covered by AGENTS.md:11; validate regex syntax when scanning cohort filters.

Comment thread src/PostHog/Features/LocalEvaluator.cs Outdated
switch (filter)
{
case FilterSet filterSet:
return filterSet.Values.Any(child => IsUnsupportedFilter(child, visitedCohortIds, inCohort));

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.

P2 · Handle null cohort values before scanning for unsupported filters

When a loaded cohort contains "values": null, MatchPropertyGroup treats it as an empty group, but this new scan calls Any on null. The resulting ArgumentNullException escapes PollForFeatureFlagsAsync, which excludes argument exceptions from recovery, permanently stopping definition polling and leaving flags stale. Treat null values as empty here.

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

posthog-dotnet Compliance Report

Date: 2026-10-28T03:58:46.170819+00:00
Duration: 124956ms

✅ All Tests Passed!

47/47 tests passed


Capture Tests

✅ 30/30 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields ✅ 249ms
Format Validation.Event Has Uuid ✅ 129ms
Format Validation.Event Has Lib Properties ✅ 112ms
Format Validation.Distinct Id Is String ✅ 117ms
Format Validation.Token Is Present ✅ 112ms
Format Validation.Custom Properties Preserved ✅ 119ms
Format Validation.Event Has Timestamp ✅ 112ms
Format Validation.Non Utc Event Timestamp Is Converted To Utc ✅ 123ms
Retry Behavior.Retries On 503 ✅ 8120ms
Retry Behavior.Does Not Retry On 400 ✅ 2119ms
Retry Behavior.Does Not Retry On 401 ✅ 2116ms
Retry Behavior.Respects Retry After Header ✅ 8120ms
Retry Behavior.Implements Backoff ✅ 22131ms
Retry Behavior.Retries On 500 ✅ 6119ms
Retry Behavior.Retries On 502 ✅ 6122ms
Retry Behavior.Retries On 504 ✅ 6120ms
Retry Behavior.Max Retries Respected ✅ 22136ms
Deduplication.Generates Unique Uuids ✅ 118ms
Deduplication.Preserves Uuid On Retry ✅ 6118ms
Deduplication.Preserves Uuid And Timestamp On Retry ✅ 13131ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry ✅ 6123ms
Deduplication.No Duplicate Events In Batch ✅ 117ms
Deduplication.Different Events Have Different Uuids ✅ 112ms
Compression.Sends Gzip When Enabled ✅ 110ms
Batch Format.Uses Proper Batch Structure ✅ 110ms
Batch Format.Flush With No Events Sends Nothing ✅ 106ms
Batch Format.Multiple Events Batched Together ✅ 116ms
Error Handling.Does Not Retry On 403 ✅ 2112ms
Error Handling.Does Not Retry On 413 ✅ 2114ms
Error Handling.Retries On 408 ✅ 6118ms

Feature_Flags Tests

✅ 17/17 tests passed

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

This branch has not been deployed

No deployments
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