Skip to content

feat(flags): evaluate feature enrollment locally - #411

Merged
marandaneto merged 11 commits into
mainfrom
feat/flags-feature-enrollment
Dec 1, 2026
Merged

marandaneto merged 11 commits into
mainfrom
feat/flags-feature-enrollment

Conversation

@marandaneto

@marandaneto marandaneto commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

💡 Motivation and Context

Local evaluation ignored filters.feature_enrollment, which marks an early access feature flag. Such a flag resolved from its release conditions, while /flags returns the person's enrollment. Since #397 evaluates holdouts locally, a flag with both could also return holdout-<id> where the flags service returns the enrollment.

This adds local enrollment evaluation per the local-feature-flag-evaluator spec in PostHog/sdk-specs: "Feature enrollment precedes holdouts and release conditions" and "Unavailable enrollment context remains inconclusive". It also matches the Rust flags service (FeatureFlagMatcher::get_match, FlagFilters::is_enrolled) and posthog-node.

Behavior

For an active flag with feature_enrollment: true and no experience continuity:

  • Enrollment is checked after the inactive and experience-continuity checks, and before the holdout and the release conditions.
  • The SDK reads the person property $feature_enrollment/<flag key>. The JSON boolean true or the string "true" resolves the flag to true. Any other passed value, null included, resolves it to false.
  • Group flags read the person property too, never the group's. They need no group key, and an unknown group type index doesn't matter.
  • Without the property, the flag is inconclusive with missing_context and falls back to /flags, or stays unresolved when OnlyEvaluateLocally is true. Flags that depend on it report unresolved_dependency.
  • When $feature_enrollment/<flag key> is listed in PersonPropertyKeysKnownAbsent, the person counts as not enrolled. Evaluation continues through the holdout and the release conditions, and the listing wins over a passed value.
  • The definition-level unresolved reason, used for the load-time warning, returns no reason for enrollment flags. Enrollment decides the flag before its aggregation and conditions are read, so a static cohort in its conditions doesn't make it unsupported_definition.
  • A feature_enrollment that is absent, null, false or any other non-boolean value keeps ordinary evaluation.

Device-id bucketing, which the spec also covers, is not part of this PR.

Flag dependencies

A flag dependency now evaluates only the flag it references, as the flags service does, instead of every flag in its dependency_chain. Without this, a flag that an enrollment flag's skipped release conditions depend on could leave its dependents unresolved or abort a fallback condition. A missing definition anywhere in the chain is still UnsupportedDefinition, and a chain that loops back is caught. During evaluation, the definition reason of an enrollment flag whose key is known absent counts its conditions, so UnsupportedDefinition still outranks UnresolvedDependency. FeatureFlagFilters equality includes feature_enrollment. The changesets are minor.

Dependencies deeper than 100 levels, or beyond 10,000 dependency evaluations in one flag evaluation, are UnresolvedDependency. Failures caused by the depth limit or a cycle aren't cached, so a shallower reference can still resolve. Every flag on a malformed dependency cycle reports UnsupportedDefinition; a flag that only depends on a cycle reports UnresolvedDependency. Enrollment passed as a System.Text.Json.Nodes.JsonValue is read like a JsonElement.

💚 How did you test it?

  • New tests/UnitTests/Features/FeatureEnrollmentTests.cs (37 cases) covers the spec scenarios:

    • enrolled values, including when no condition matches
    • opted-out values overriding matching targeting
    • precedence over a 100% holdout
    • inactive flags
    • inactive enrollment markers
    • bulk and dependency evaluation
    • missing enrollment (missing_context / unresolved_dependency, /flags fallback, local-only)
    • experience-continuity precedence
    • static-cohort conditions with known and missing enrollment
    • group flags (no group context needed; the group's property is ignored; unknown group type)
    • known-absent enrollment keys, including continuing to the holdout

    25 of the 37 cases failed on main and pass with the change.

  • dotnet test (UnitTests 2232 on net8.0 and net10.0) and dotnet format --verify-no-changes passed.

📝 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)

  • Implemented with Pi (Claude). The behavior was checked against the local-feature-flag-evaluator spec, the Rust flags service on PostHog/posthog master, and posthog-node's matchFeatureEnrollment.
  • Enrollment values are compared like the Rust is_enrolled: only boolean true and the exact string "true" count. The model keeps feature_enrollment as raw JSON, so an unexpected value doesn't fail loading the definitions.

Early access feature flags (filters.feature_enrollment: true) now resolve from the person property $feature_enrollment/<flag key> before the holdout and release conditions, matching the flags service and the local-feature-flag-evaluator spec. true or "true" means enrolled, and any other passed value means opted out. Group flags read the person property too. A missing property is missing_context and falls back to /flags. A key listed as known absent continues through the holdout and conditions.
@marandaneto marandaneto self-assigned this Nov 30, 2026
@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

posthog-dotnet Compliance Report

Date: 2026-12-01T13:06:27.997887+00:00
Duration: 125525ms

✅ All Tests Passed!

47/47 tests passed


Capture Tests

✅ 30/30 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields ✅ 262ms
Format Validation.Event Has Uuid ✅ 127ms
Format Validation.Event Has Lib Properties ✅ 112ms
Format Validation.Distinct Id Is String ✅ 115ms
Format Validation.Token Is Present ✅ 111ms
Format Validation.Custom Properties Preserved ✅ 119ms
Format Validation.Event Has Timestamp ✅ 111ms
Format Validation.Non Utc Event Timestamp Is Converted To Utc ✅ 121ms
Retry Behavior.Retries On 503 ✅ 8118ms
Retry Behavior.Does Not Retry On 400 ✅ 2118ms
Retry Behavior.Does Not Retry On 401 ✅ 2114ms
Retry Behavior.Respects Retry After Header ✅ 8115ms
Retry Behavior.Implements Backoff ✅ 22129ms
Retry Behavior.Retries On 500 ✅ 6118ms
Retry Behavior.Retries On 502 ✅ 6118ms
Retry Behavior.Retries On 504 ✅ 6118ms
Retry Behavior.Max Retries Respected ✅ 22133ms
Deduplication.Generates Unique Uuids ✅ 117ms
Deduplication.Preserves Uuid On Retry ✅ 6117ms
Deduplication.Preserves Uuid And Timestamp On Retry ✅ 13128ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry ✅ 6120ms
Deduplication.No Duplicate Events In Batch ✅ 116ms
Deduplication.Different Events Have Different Uuids ✅ 112ms
Compression.Sends Gzip When Enabled ✅ 110ms
Batch Format.Uses Proper Batch Structure ✅ 109ms
Batch Format.Flush With No Events Sends Nothing ✅ 105ms
Batch Format.Multiple Events Batched Together ✅ 116ms
Error Handling.Does Not Retry On 403 ✅ 2112ms
Error Handling.Does Not Retry On 413 ✅ 2113ms
Error Handling.Retries On 408 ✅ 6121ms

Feature_Flags Tests

✅ 17/17 tests passed

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

… expose

Add a PostHog.AspNetCore changeset for the feature enrollment change, which the feature manager picks up through local evaluation.
@marandaneto
marandaneto marked this pull request as ready for review November 30, 2026 09:01
@marandaneto
marandaneto requested a review from a team as a code owner November 30, 2026 09:01
@veria-ai

veria-ai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

PR overview

All previously flagged issues have been addressed. No open security concerns remain on this pull request.

Fixed/addressed: 1 · PR risk: 0/10

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 d08dabc: 1 Should fix.

New pushes to this pull request won't start an automatic review. Comment @posthog review to review new changes.

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 thread src/PostHog/Features/LocalEvaluator.cs Resolved
@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

SDK performance: posthog-dotnet

30 changes worth reviewing: 3 observed improvements, 27 observed regressions.

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.

Test Measurement Before PR With PR Change
Evaluate one boolean flag Allocated memory per operation 1.1 KiB/op 1.68 KiB/op 53.5% more memory
Evaluate a rollout flag Allocated memory per operation 1.2 KiB/op 1.78 KiB/op 49% more memory
Evaluate a multivariate flag Allocated memory per operation 1.24 KiB/op 1.82 KiB/op 47.4% more memory
Evaluate a property-filtered flag Allocated memory per operation 1.32 KiB/op 1.91 KiB/op 44.5% more memory
Evaluate a cohort-filtered flag Allocated memory per operation 1.35 KiB/op 1.94 KiB/op 43.4% more memory
Evaluate a property-filtered flag Time per operation 2.28 µs/op 2.99 µs/op 31% more time
Evaluate a property-filtered flag Process CPU time per operation 2.3 µs/op 3.01 µs/op 30.7% more time
Evaluate one boolean flag Time per operation 2.55 µs/op 3.25 µs/op 27.4% more time
Evaluate a cohort-filtered flag Time per operation 2.52 µs/op 3.21 µs/op 27.4% more time
Evaluate a cohort-filtered flag Process CPU time per operation 2.54 µs/op 3.22 µs/op 27% more time
Evaluate one boolean flag Process CPU time per operation 2.57 µs/op 3.27 µs/op 27% more time
Evaluate a multivariate flag Time per operation 2.68 µs/op 3.36 µs/op 25.4% more time

Showing the 12 largest flagged changes; 18 more are in all results.

View all results
Test Measurement Before PR With PR Change Assessment
Capture and deliver events (32-byte payload, burst) Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​; head:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​
Capture and deliver events (4,096-byte payload, burst) Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​; head:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​
Capture and deliver events (32-byte payload, steady) Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​; head:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​
Capture and deliver events (4,096-byte payload, steady) Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​; head:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​
Queue an event (32-byte payload) Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​; head:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​
Queue an event (4,096-byte payload) Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​; head:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​
Evaluate all 10 flags Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​; head:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​
Evaluate all 100 flags Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​; head:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​
Evaluate all 1,000 flags Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​; head:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​
Evaluate one boolean flag Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​; head:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​
Evaluate a cohort-filtered flag Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​; head:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​
Evaluate a flag (early match) Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​; head:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​
Evaluate a flag (late match) Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​; head:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​
Evaluate a flag (no match) Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​; head:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​
Evaluate a property-filtered flag Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​; head:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​
Evaluate a regex-filtered flag Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​; head:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​
Evaluate a rollout flag Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​; head:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​
Evaluate a multivariate flag Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​; head:​ CLR byte counters do not expose exact object allocation counts; native allocations are not included.​
Capture and deliver events (32-byte payload, burst) Allocated memory per operation 5.37 KiB/op 5.37 KiB/op <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, burst) Time per operation 6.49 µs/op 6.42 µs/op 1% less time Not flagged
Capture and deliver events (32-byte payload, burst) idle_managed_heap_bytes (estimated) 822.48 KiB 822.48 KiB No observed change Not flagged
Capture and deliver events (32-byte payload, burst) Idle process memory (RSS) 54.96 MiB 54.96 MiB No observed change Not flagged
Capture and deliver events (32-byte payload, burst) Observed peak process memory (RSS) 57.56 MiB 57.61 MiB <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, burst) Managed heap after settling (estimated) 2.24 MiB 2.24 MiB No observed change Not flagged
Capture and deliver events (32-byte payload, burst) Process memory after settling (RSS) 57.65 MiB 57.7 MiB <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, burst) Process CPU time per operation 6.51 µs/op 6.46 µs/op 0.8% less time Not flagged
Capture and deliver events (32-byte payload, burst) Lifetime peak process memory (RSS) 57.65 MiB 57.7 MiB <0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, burst) Allocated memory per operation 39.87 KiB/op 39.87 KiB/op <0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, burst) Time per operation 20.71 µs/op 20.66 µs/op 0.2% less time Not flagged
Capture and deliver events (4,096-byte payload, burst) idle_managed_heap_bytes (estimated) 2.13 MiB 2.13 MiB No observed change Not flagged
Capture and deliver events (4,096-byte payload, burst) Idle process memory (RSS) 56.88 MiB 56.87 MiB <0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, burst) Observed peak process memory (RSS) 82.02 MiB 82 MiB <0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, burst) Managed heap after settling (estimated) 25.63 MiB 25.63 MiB No observed change Not flagged
Capture and deliver events (4,096-byte payload, burst) Process memory after settling (RSS) 82.19 MiB 82.17 MiB <0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, burst) Process CPU time per operation 22 µs/op 21.94 µs/op 0.3% less time Not flagged
Capture and deliver events (4,096-byte payload, burst) Lifetime peak process memory (RSS) 82.19 MiB 82.17 MiB <0.1% less memory Not flagged
Capture and deliver events (32-byte payload, steady) Allocated memory per operation 18.15 KiB/op 18.15 KiB/op <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, steady) Time per operation 9.96 µs/op 9.95 µs/op 0.1% less time Not flagged
Capture and deliver events (32-byte payload, steady) idle_managed_heap_bytes (estimated) 822.48 KiB 823.68 KiB 0.1% more memory Not flagged
Capture and deliver events (32-byte payload, steady) Idle process memory (RSS) 54.97 MiB 54.99 MiB <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, steady) Observed peak process memory (RSS) 55.55 MiB 55.56 MiB <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, steady) Managed heap after settling (estimated) 938.29 KiB 939.48 KiB 0.1% more memory Not flagged
Capture and deliver events (32-byte payload, steady) Process memory after settling (RSS) 55.54 MiB 55.55 MiB <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, steady) Process CPU time per operation 10.09 µs/op 10.07 µs/op 0.2% less time Not flagged
Capture and deliver events (32-byte payload, steady) Lifetime peak process memory (RSS) 55.54 MiB 55.55 MiB <0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, steady) Allocated memory per operation 30.97 KiB/op 30.97 KiB/op <0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, steady) Time per operation 15.17 µs/op 15.37 µs/op 1.3% more time Not flagged
Capture and deliver events (4,096-byte payload, steady) idle_managed_heap_bytes (estimated) 2.13 MiB 2.13 MiB <0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, steady) Idle process memory (RSS) 56.83 MiB 56.88 MiB 0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, steady) Observed peak process memory (RSS) 63.81 MiB 63.95 MiB 0.2% more memory Not flagged
Capture and deliver events (4,096-byte payload, steady) Managed heap after settling (estimated) 3.12 MiB 3.12 MiB <0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, steady) Process memory after settling (RSS) 60.12 MiB 60.11 MiB <0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, steady) Process CPU time per operation 17.75 µs/op 18.03 µs/op 1.5% more time Not flagged
Capture and deliver events (4,096-byte payload, steady) Lifetime peak process memory (RSS) 63.49 MiB 63.57 MiB 0.1% more memory Not flagged
Queue an event (32-byte payload) Allocated memory per operation 1.67 KiB/op 1.67 KiB/op No observed change Not flagged
Queue an event (32-byte payload) Time per operation 2.13 µs/op 2.18 µs/op 2.4% more time Not flagged
Queue an event (32-byte payload) Process CPU time per operation 2.14 µs/op 2.18 µs/op 2.1% more time Not flagged
Queue an event (4,096-byte payload) Allocated memory per operation 1.67 KiB/op 1.67 KiB/op No observed change Not flagged
Queue an event (4,096-byte payload) Time per operation 1.98 µs/op 2.03 µs/op 2.1% more time Not flagged
Queue an event (4,096-byte payload) Process CPU time per operation 1.99 µs/op 2.04 µs/op 2.1% more time Not flagged
Evaluate all 10 flags Allocated memory per operation 23.91 KiB/op 22.42 KiB/op 6.2% less memory Worth reviewing: observed improvement
Evaluate all 10 flags Time per operation 38.69 µs/op 40.48 µs/op 4.6% more time Not flagged
Evaluate all 10 flags Process CPU time per operation 38.86 µs/op 40.57 µs/op 4.4% more time Not flagged
Evaluate all 100 flags Allocated memory per operation 237.31 KiB/op 217.1 KiB/op 8.5% less memory Worth reviewing: observed improvement
Evaluate all 100 flags Time per operation 334.34 µs/op 337.87 µs/op 1.1% more time Not flagged
Evaluate all 100 flags Process CPU time per operation 335.83 µs/op 338.73 µs/op 0.9% more time Not flagged
Evaluate all 1,000 flags Allocated memory per operation 2.32 MiB/op 2.11 MiB/op 8.7% less memory Worth reviewing: observed improvement
Evaluate all 1,000 flags Time per operation 3.17 ms/op 3.16 ms/op 0.4% less time Not flagged
Evaluate all 1,000 flags Process CPU time per operation 3.17 ms/op 3.16 ms/op 0.5% less time Not flagged
Evaluate 1,000 flags under concurrent load idle_managed_heap_bytes (estimated) 4.74 MiB 4.79 MiB 1.1% more memory Not flagged
Evaluate 1,000 flags under concurrent load Idle process memory (RSS) 84.65 MiB 85.31 MiB 0.8% more memory Not flagged
Evaluate 1,000 flags under concurrent load Observed peak process memory (RSS) 89.87 MiB 89.88 MiB <0.1% more memory Not flagged
Evaluate 1,000 flags under concurrent load Managed heap after settling (estimated) 4.8 MiB 4.94 MiB 2.9% more memory Not flagged
Evaluate 1,000 flags under concurrent load Process memory after settling (RSS) 89.92 MiB 90.04 MiB 0.1% more memory Not flagged
Evaluate 1,000 flags under concurrent load Lifetime peak process memory (RSS) 89.92 MiB 90.04 MiB 0.1% more memory Not flagged
Refresh 1,000 flag definitions idle_managed_heap_bytes (estimated) 19.53 MiB 19.55 MiB 0.1% more memory Not flagged
Refresh 1,000 flag definitions Idle process memory (RSS) 116.73 MiB 117.17 MiB 0.4% more memory Not flagged
Refresh 1,000 flag definitions Observed peak process memory (RSS) 120.87 MiB 124.94 MiB 3.4% more memory Not flagged
Refresh 1,000 flag definitions Managed heap after settling (estimated) 20.54 MiB 20.54 MiB <0.1% more memory Not flagged
Refresh 1,000 flag definitions Process memory after settling (RSS) 119.83 MiB 123.89 MiB 3.4% more memory Not flagged
Refresh 1,000 flag definitions Lifetime peak process memory (RSS) 120.41 MiB 124.43 MiB 3.3% more memory Not flagged
Evaluate one boolean flag Allocated memory per operation 1.1 KiB/op 1.68 KiB/op 53.5% more memory Worth reviewing: observed regression
Evaluate one boolean flag Time per operation 2.55 µs/op 3.25 µs/op 27.4% more time Worth reviewing: observed regression
Evaluate one boolean flag Process CPU time per operation 2.57 µs/op 3.27 µs/op 27% more time Worth reviewing: observed regression
Evaluate a cohort-filtered flag Allocated memory per operation 1.35 KiB/op 1.94 KiB/op 43.4% more memory Worth reviewing: observed regression
Evaluate a cohort-filtered flag Time per operation 2.52 µs/op 3.21 µs/op 27.4% more time Worth reviewing: observed regression
Evaluate a cohort-filtered flag Process CPU time per operation 2.54 µs/op 3.22 µs/op 27% more time Worth reviewing: observed regression
Evaluate a flag (early match) Allocated memory per operation 2.95 KiB/op 3.54 KiB/op 19.9% more memory Worth reviewing: observed regression
Evaluate a flag (early match) Time per operation 3.84 µs/op 4.55 µs/op 18.6% more time Worth reviewing: observed regression
Evaluate a flag (early match) Process CPU time per operation 3.86 µs/op 4.57 µs/op 18.5% more time Worth reviewing: observed regression
Evaluate a flag (late match) Allocated memory per operation 4.57 KiB/op 5.14 KiB/op 12.6% more memory Worth reviewing: observed regression
Evaluate a flag (late match) Time per operation 5.32 µs/op 5.98 µs/op 12.3% more time Worth reviewing: observed regression
Evaluate a flag (late match) Process CPU time per operation 5.34 µs/op 5.99 µs/op 12.3% more time Worth reviewing: observed regression
Evaluate a flag (no match) Allocated memory per operation 4.34 KiB/op 4.92 KiB/op 13.3% more memory Worth reviewing: observed regression
Evaluate a flag (no match) Time per operation 4.54 µs/op 5.09 µs/op 12% more time Worth reviewing: observed regression
Evaluate a flag (no match) Process CPU time per operation 4.55 µs/op 5.11 µs/op 12.2% more time Worth reviewing: observed regression
Evaluate a property-filtered flag Allocated memory per operation 1.32 KiB/op 1.91 KiB/op 44.5% more memory Worth reviewing: observed regression
Evaluate a property-filtered flag Time per operation 2.28 µs/op 2.99 µs/op 31% more time Worth reviewing: observed regression
Evaluate a property-filtered flag Process CPU time per operation 2.3 µs/op 3.01 µs/op 30.7% more time Worth reviewing: observed regression
Evaluate a regex-filtered flag Allocated memory per operation 5.75 KiB/op 6.33 KiB/op 10.1% more memory Worth reviewing: observed regression
Evaluate a regex-filtered flag Time per operation 9.56 µs/op 10.65 µs/op 11.3% more time Worth reviewing: observed regression
Evaluate a regex-filtered flag Process CPU time per operation 9.58 µs/op 10.66 µs/op 11.3% more time Worth reviewing: observed regression
Evaluate a rollout flag Allocated memory per operation 1.2 KiB/op 1.78 KiB/op 49% more memory Worth reviewing: observed regression
Evaluate a rollout flag Time per operation 3.06 µs/op 3.8 µs/op 24.2% more time Worth reviewing: observed regression
Evaluate a rollout flag Process CPU time per operation 3.08 µs/op 3.82 µs/op 24.1% more time Worth reviewing: observed regression
Evaluate a multivariate flag Allocated memory per operation 1.24 KiB/op 1.82 KiB/op 47.4% more memory Worth reviewing: observed regression
Evaluate a multivariate flag Time per operation 2.68 µs/op 3.36 µs/op 25.4% more time Worth reviewing: observed regression
Evaluate a multivariate flag Process CPU time per operation 2.69 µs/op 3.36 µs/op 25% more time Worth reviewing: observed regression

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.

Compared ed7ee81ee7729201e3338994b5fea7201333344f → 02637f996dd8c6c86c0d6d47b0da684610600117.

Full report and diagnostics

108 metric rows; 108 rows shown in all results. Omitted or shortened data remain in comparison.json, including per-runner environments, resource limits, measurement methods, samples and checkpoints.

@dustinbyrne dustinbyrne 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.

Core feature_enrollment evaluation, precedence over holdouts/conditions, group-flag person lookup, known-absent handling, JsonDocument/JsonElement unwrapping, and test coverage match PostHog/posthog, PostHog/sdk-specs, and peer server SDKs.

Left one inline Concern on TryGetDefinitionUnresolvedReason when $feature_enrollment/<flag key> is known absent and a preceding condition hits RequiresServerEvaluationException, plus a non-blocking Question on patch vs minor versioning and a minor Suggestion on FeatureFlagFilters.Equals.

Follow-up (external repo): Once this ships, PostHog/posthog.com (contents/docs/feature-flags/local-evaluation/index.mdx, line 365) still lists flags linked to an early access feature as unsupported for local evaluation and can be updated in a separate docs PR.

AI-assisted review.

Comment thread src/PostHog/Features/LocalEvaluator.cs Resolved
@dustinbyrne
dustinbyrne requested a review from a team November 30, 2026 16:25
A flag dependency no longer evaluates every flag in its dependency_chain first. Only the referenced flag is evaluated, with full flag evaluation, so a flag it skips, such as the release conditions of an enrollment flag, can't leave its dependents unresolved or abort a later fallback condition. A missing definition anywhere in the chain is still unsupported_definition, and a chain that loops back is caught.

During evaluation, the definition reason of an enrollment flag now counts its conditions, which are only reached when its enrollment key is known absent, so unsupported_definition still outranks unresolved_dependency. FeatureFlagFilters equality includes feature_enrollment. The changesets are minor.
A very deep acyclic dependency chain recursed until the stack overflowed, which ends the .NET process. Dependency evaluation deeper than 100 levels is now inconclusive with UnresolvedDependency, as in the other server SDKs.
Comment thread src/PostHog/Features/LocalEvaluator.cs Resolved
Only successful dependency results were cached, so a graph of flags sharing an unresolved dependency evaluated it again on every path, which took exponential time: 33 flags each depending on the previous two took 92 seconds. A dependency that can't be evaluated is now remembered for the evaluation and fails the same way without being evaluated again.

@dustinbyrne dustinbyrne 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.

All earlier review items (TryGetDefinitionUnresolvedReason with ignoreFeatureEnrollment, minor changesets for PostHog and PostHog.AspNetCore, FeatureFlagFilters.Equals/GetHashCode, and evaluating only the referenced flagKey in EvaluateDependencyChain) look solid, and core feature_enrollment evaluation aligns with PostHog/sdk-specs, the Rust flags service, and server SDK peers.

Left one inline Concern on state.Failures in ade960b caching path-dependent depth-limit (and cycle) failures and poisoning shallower valid fallback conditions within the same evaluation, plus three optional inline Suggestions on the new dependency cycle guard, JsonValue/JsonNode unwrapping, and stale comments.

  • Suggestion (outside diff — src/PostHog/Features/FeatureFlagOptions.cs:53-60): Consider adding one sentence to the XML <remarks> on AllFeatureFlagsOptions.PersonPropertyKeysKnownAbsent noting that listing $feature_enrollment/<flag key> treats the person as not enrolled so evaluation continues through holdouts and release conditions. Existing remarks cover property operators and __posthog_person_metadata__, but omit the new early-access enrollment bypass advertised in the changeset, so IDE tooltips and generated API docs won't surface it.
  • Follow-up (already noted): Skipping duplicate comment for the external PostHog/posthog.com local-evaluation restrictions update (contents/docs/feature-flags/local-evaluation/index.mdx:365), previously noted in review #6116121755.

AI-assisted review.

Comment thread src/PostHog/Features/LocalEvaluator.cs Resolved
Comment thread src/PostHog/Features/LocalEvaluator.cs Resolved
Comment thread src/PostHog/Features/LocalEvaluator.cs Resolved
Comment thread src/PostHog/Features/LocalEvaluator.cs Resolved
@dustinbyrne
dustinbyrne requested a review from a team November 30, 2026 19:35
A dependency that failed because of the depth limit or a cycle through a flag in progress was cached as its result, so a shallower reference later in the same evaluation failed too. Only failures that don't depend on the path are cached now, and a budget of 10,000 dependency evaluations per evaluation, as in posthog-rs, keeps the work bounded; dependencies past it are inconclusive with UnresolvedDependency.

The flag being evaluated is now tracked as in progress, so a malformed self-cycle no longer evaluates itself twice, and every flag on a malformed cycle reports UnsupportedDefinition, as evaluate-flags defines a circular dependency. A flag that only depends on a cycle reports UnresolvedDependency.
A $feature_enrollment value passed as a System.Text.Json.Nodes.JsonValue, such as JsonNode.Parse("true") or JsonValue.Create(true), was read as not enrolled, while /flags reads it as enrolled. It is now unwrapped like a JsonDocument or JsonElement.
…chain evaluation

PersonPropertyKeysKnownAbsent now explains that listing $feature_enrollment/<flag key> treats the person as not enrolled, and the dependency chain comments describe that only the referenced flag is evaluated.
@marandaneto

Copy link
Copy Markdown
Member Author

Done in 323f691. The <remarks> on AllFeatureFlagsOptions.PersonPropertyKeysKnownAbsent now say that listing $feature_enrollment/<flag key> treats the person as not enrolled in that flag's early access feature, so local evaluation continues through its holdout and release conditions.

@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.

Enrollment matches the spec and posthog-node as far as I can tell. Two optional suggestions inline, both on the dependency budget and not on enrollment itself.

Comment thread src/PostHog/Features/LocalEvaluator.cs Resolved

@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.

Approving. Both suggestions on the dependency budget are optional, they can be a follow-up.

…rollment

# Conflicts:
#	src/PostHog/Api/LocalEvaluationApiResult.cs
#	src/PostHog/Features/LocalEvaluator.cs
A flag that ran out of depth below it was not cached, so every path to it evaluated it again until the 10,000 budget ran out, which took seconds for a chain deeper than 100. Such a flag is now remembered with the depth it failed at and evaluated again only from a shallower path. A bulk evaluation shares one evaluation cache, so a dependency resolved for one flag is not evaluated again for the next, and the budget bounds the whole pass. The tests count dependency evaluations instead of timing them.
@marandaneto
marandaneto merged commit d663e60 into main Dec 1, 2026
23 checks passed
@marandaneto
marandaneto deleted the feat/flags-feature-enrollment branch December 1, 2026 13:13
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.

3 participants