Skip to content

fix: release OpenFeature evaluation access trackers - #217

Merged
marandaneto merged 2 commits into
mainfrom
fix/openfeature-agent-leak
Sep 25, 2026
Merged

marandaneto merged 2 commits into
mainfrom
fix/openfeature-agent-leak

Conversation

@marandaneto

@marandaneto marandaneto commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

💡 Motivation and Context

Addresses the unresolved Agent leak reported on #214. Each OpenFeature evaluation created an access-tracking Agent and discarded its snapshot without stopping the process. Repeated evaluations in a long-lived caller accumulated one Agent per call, including when feature flag events were disabled or the flag was missing.

Stop the Agent in a try/after block after reading the result and optionally reporting the flag access. This keeps cleanup scoped to snapshots owned by the provider and does not change the public snapshot API. The evaluate-flags spec was checked; snapshot access and event behavior are unchanged.

💚 How did you test it?

  • Added four regression cases for events enabled/disabled and flags present/missing. Each failed before the fix with 10 retained Agents and passed afterward.
  • Verified that test cleanup stops evaluation access trackers without stopping unrelated linked Agents. The leak assertion still checks all newly retained links.
  • mix test test/posthog/open_feature_test.exs: 79 passed.
  • mix test: 600 passed, 18 integration tests excluded.
  • mix format --check-formatted and mix credo --strict passed.
  • Branch autoreview against origin/main found no actionable issues at 76c1864.

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed. No documentation changes needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Ran sampo add to generate a changeset file

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Implemented with Pi using file-editing tools, shell commands, GitHub CLI, and the isolated autoreview helper. The fix uses the provider-owned snapshot lifetime rather than changing the shared snapshot API. Human review is required. No shared session link is available.

@marandaneto marandaneto self-assigned this Sep 25, 2026
@marandaneto
marandaneto requested a review from a team September 25, 2026 13:03
@marandaneto
marandaneto marked this pull request as ready for review September 25, 2026 13:03
@marandaneto
marandaneto requested a review from a team as a code owner September 25, 2026 13:03
@posthog-project-board-bot posthog-project-board-bot Bot moved this to In Review in Feature Flags Sep 25, 2026
@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

posthog-elixir Compliance Report

Date: 2026-09-25T13:21:05.556519+00:00
Duration: 108399ms

⚠️ Some Tests Failed

40/47 tests passed, 7 failed


Capture Tests

⚠️ 29/30 tests passed, 1 failed

View Details
Test Status Duration
Format Validation.Event Has Required Fields ✅ 608ms
Format Validation.Event Has Uuid ✅ 608ms
Format Validation.Event Has Lib Properties ✅ 608ms
Format Validation.Distinct Id Is String ✅ 608ms
Format Validation.Token Is Present ✅ 607ms
Format Validation.Custom Properties Preserved ✅ 607ms
Format Validation.Event Has Timestamp ✅ 608ms
Format Validation.Non Utc Event Timestamp Is Converted To Utc ❌ 608ms
Retry Behavior.Retries On 503 ✅ 5612ms
Retry Behavior.Does Not Retry On 400 ✅ 2610ms
Retry Behavior.Does Not Retry On 401 ✅ 2611ms
Retry Behavior.Respects Retry After Header ✅ 5614ms
Retry Behavior.Implements Backoff ✅ 15623ms
Retry Behavior.Retries On 500 ✅ 5612ms
Retry Behavior.Retries On 502 ✅ 5614ms
Retry Behavior.Retries On 504 ✅ 5613ms
Retry Behavior.Max Retries Respected ✅ 15622ms
Deduplication.Generates Unique Uuids ✅ 617ms
Deduplication.Preserves Uuid On Retry ✅ 5615ms
Deduplication.Preserves Uuid And Timestamp On Retry ✅ 10619ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry ✅ 5614ms
Deduplication.No Duplicate Events In Batch ✅ 612ms
Deduplication.Different Events Have Different Uuids ✅ 610ms
Compression.Sends Gzip When Enabled ✅ 607ms
Batch Format.Uses Proper Batch Structure ✅ 607ms
Batch Format.Flush With No Events Sends Nothing ✅ 605ms
Batch Format.Multiple Events Batched Together ✅ 610ms
Error Handling.Does Not Retry On 403 ✅ 2610ms
Error Handling.Does Not Retry On 413 ✅ 2609ms
Error Handling.Retries On 408 ✅ 5612ms

Failures

format_validation.non_utc_event_timestamp_is_converted_to_utc

Event 0 field 'timestamp' instant '2026-09-25T13:19:21.583365Z' != expected '2025-01-02T03:04:05Z'

Feature_Flags Tests

⚠️ 11/17 tests passed, 6 failed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id ✅ 7ms
Request Payload.Flags Request Uses V2 Query Param ✅ 4ms
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 ✅ 4ms
Request Payload.Groups Default To Empty Object ❌ 5ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False ✅ 4ms
Request Payload.Disable Geoip Omitted Defaults To False ❌ 4ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key ✅ 5ms
Request Lifecycle.No Flags Request On Init Alone ✅ 2ms
Request Lifecycle.No Flags Request On Normal Capture ✅ 606ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests ✅ 8ms
Request Lifecycle.Mock Response Value Is Returned To Caller ❌ 5ms
Retry Behavior.Retries Flags On 502 ❌ 307ms
Retry Behavior.Retries Flags On 504 ❌ 307ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event ❌ 607ms

Failures

request_payload.groups_default_to_empty_object

Field 'groups' not found in /flags request body at path 'groups'. Available keys: ['api_key', 'distinct_id', 'flag_keys_to_evaluate']

request_payload.disable_geoip_omitted_defaults_to_false

Field 'geoip_disable' not found in /flags request body at path 'geoip_disable'. Available keys: ['api_key', 'distinct_id', 'flag_keys_to_evaluate']

request_lifecycle.mock_response_value_is_returned_to_caller

Last action result missing field 'value'. Keys: ['error', 'success']

retry_behavior.retries_flags_on_502

Last action result missing field 'value'. Keys: ['error', 'success']

retry_behavior.retries_flags_on_504

Last action result missing field 'value'. Keys: ['error', 'success']

side_effect_events.get_feature_flag_captures_feature_flag_called_event

Expected 1 events with name '$feature_flag_called', got 0

@marandaneto
marandaneto enabled auto-merge (squash) September 25, 2026 13:03
@greptile-apps

greptile-apps Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Retrigger

[Medium risk] Fixes a resource leak in feature flag evaluation.

The PR appears safe to merge; the test cleanup should be narrowed to access trackers.

Reviews (1) · Last reviewed commit: "fix: release OpenFeature evaluation acce..."

Comment thread test/posthog/open_feature_test.exs Outdated
@marandaneto
marandaneto enabled auto-merge (squash) September 25, 2026 13:18
@marandaneto
marandaneto merged commit a401bd2 into main Sep 25, 2026
30 of 31 checks passed
@marandaneto
marandaneto deleted the fix/openfeature-agent-leak branch September 25, 2026 13:19
@github-project-automation github-project-automation Bot moved this from Approved to Done in Feature Flags Sep 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants