Skip to content

fix(flags): load shared definitions without a secret key - #225

Open
dustinbyrne wants to merge 2 commits into
mainfrom
fix/flag-cache-without-secret-key
Open

dustinbyrne wants to merge 2 commits into
mainfrom
fix/flag-cache-without-secret-key

Conversation

@dustinbyrne

@dustinbyrne dustinbyrne commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

💡 Motivation and Context

Like PostHog/posthog-python#1039, a worker consuming shared feature flag definitions should not need a privileged secret key. Existing initialization gates prevent that supported cache-consumer configuration from evaluating flags locally.

Changes

  • Permit the configured definition cache provider to supply definitions without a secret/personal API key.
  • Keyless consumers read the shared cache directly, without invoking the fetch-decision callback or publishing definitions. They cannot claim fetch leadership they are unable to use.
  • With privileged credentials, retain the existing decision flow: false reads the cache; true fetches definitions and publishes them. Direct definition requests remain authenticated.
  • Add public-entry regressions, update active credential/provider docs, and include scoped patch release metadata.

Cache-only readers bypass the shared loader specification's decision-first provider step; credentialed consumers retain that step.

The existing supervision, NegativeKnowledge dependency, bounded provider callbacks and polling lifecycle are retained.

💚 How did you test it?

  • Focused provider/loader suites: 30 tests passed.
  • mix test: 614 tests, zero failures, 18 integration tests excluded.
  • mix format --check-formatted, forced warnings-as-errors compilation, strict Credo and public API snapshot check: passed.
  • Shared-leadership regression fails against the prior loader and passes with the fix; true, raising, throwing and hanging decision callbacks are never invoked by keyless readers.
  • Local validation used Elixir 1.19.5/OTP 28; no live service credentials were used.

Release scope

Patch release for hex/posthog. Existing signatures, capture defaults and wire formats are unchanged.

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Implemented with Pi worker agents and reviewed by separate fresh-context Pi reviewers. A simplify pass covered the scoped source/tests/docs before final local validation. Human review remains required.

@dustinbyrne
dustinbyrne requested a review from a team as a code owner October 9, 2026 15:33
@dustinbyrne dustinbyrne self-assigned this Oct 9, 2026
@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

posthog-elixir Compliance Report

Date: 2026-10-10T04:16:37.539898+00:00
Duration: 108702ms

⚠️ 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 ✅ 610ms
Format Validation.Event Has Uuid ✅ 612ms
Format Validation.Event Has Lib Properties ✅ 611ms
Format Validation.Distinct Id Is String ✅ 611ms
Format Validation.Token Is Present ✅ 611ms
Format Validation.Custom Properties Preserved ✅ 611ms
Format Validation.Event Has Timestamp ✅ 611ms
Format Validation.Non Utc Event Timestamp Is Converted To Utc ❌ 611ms
Retry Behavior.Retries On 503 ✅ 5616ms
Retry Behavior.Does Not Retry On 400 ✅ 2614ms
Retry Behavior.Does Not Retry On 401 ✅ 2612ms
Retry Behavior.Respects Retry After Header ✅ 5618ms
Retry Behavior.Implements Backoff ✅ 15627ms
Retry Behavior.Retries On 500 ✅ 5615ms
Retry Behavior.Retries On 502 ✅ 5616ms
Retry Behavior.Retries On 504 ✅ 5616ms
Retry Behavior.Max Retries Respected ✅ 15619ms
Deduplication.Generates Unique Uuids ✅ 623ms
Deduplication.Preserves Uuid On Retry ✅ 5616ms
Deduplication.Preserves Uuid And Timestamp On Retry ✅ 10621ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry ✅ 5618ms
Deduplication.No Duplicate Events In Batch ✅ 617ms
Deduplication.Different Events Have Different Uuids ✅ 614ms
Compression.Sends Gzip When Enabled ✅ 610ms
Batch Format.Uses Proper Batch Structure ✅ 610ms
Batch Format.Flush With No Events Sends Nothing ✅ 607ms
Batch Format.Multiple Events Batched Together ✅ 615ms
Error Handling.Does Not Retry On 403 ✅ 2612ms
Error Handling.Does Not Retry On 413 ✅ 2612ms
Error Handling.Retries On 408 ✅ 5615ms

Failures

format_validation.non_utc_event_timestamp_is_converted_to_utc

Event 0 field 'timestamp' instant '2026-10-10T04:14:53.435257Z' != 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 ✅ 10ms
Request Payload.Flags Request Uses V2 Query Param ✅ 8ms
Request Payload.Flags Request Hits Flags Path Not Decide ✅ 7ms
Request Payload.Flags Request Omits Authorization Header ✅ 8ms
Request Payload.Token In Flags Body Matches Init ✅ 8ms
Request Payload.Groups Round Trip ✅ 8ms
Request Payload.Groups Default To Empty Object ❌ 8ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False ✅ 9ms
Request Payload.Disable Geoip Omitted Defaults To False ❌ 7ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key ✅ 9ms
Request Lifecycle.No Flags Request On Init Alone ✅ 4ms
Request Lifecycle.No Flags Request On Normal Capture ✅ 610ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests ✅ 13ms
Request Lifecycle.Mock Response Value Is Returned To Caller ❌ 8ms
Retry Behavior.Retries Flags On 502 ❌ 311ms
Retry Behavior.Retries Flags On 504 ❌ 313ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event ❌ 611ms

Failures

request_payload.groups_default_to_empty_object

Field 'groups' not found in /flags request body at path 'groups'. Available keys: ['distinct_id', 'api_key', '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: ['distinct_id', 'api_key', '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

Comment thread lib/posthog/feature_flags/definition_loader.ex
@turnipdabeets
turnipdabeets requested a review from a team October 9, 2026 20:05

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants