Skip to content

feat(rails): expose flag_definition_cache_provider in PostHog.init block - #302

Merged
seanpem merged 2 commits into
mainfrom
flag-definition-cache-provider
Oct 14, 2026
Merged

seanpem merged 2 commits into
mainfrom
flag-definition-cache-provider

Conversation

@seanpem

@seanpem seanpem commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Summary

Rails apps couldn't set flag_definition_cache_provider from the PostHog.init block. The core client has accepted the option since #114, but the Rails InitConfig wrapper is an explicit allowlist of setters written in #81 and was never extended, so config.flag_definition_cache_provider = ... raised NoMethodError. The only workaround was the hash form of PostHog.init.

This PR:

  • Adds a flag_definition_cache_provider= setter to PostHog::Rails::InitConfig
  • Documents the option in the generated initializer template and the mirrored example, pointing at examples/redis_flag_cache.rb
  • Regenerates public_api_snapshot.txt
  • Adds the first specs covering the block form of PostHog.init: one asserts the provider receives fetched definitions, one asserts the core interface validation still fires
  • Adds a posthog-rails minor changeset

Scope is intentionally limited to the cache provider. Other newer core options (feature_flags_async_load, feature_flag_request_max_retries, etc.) are still missing from InitConfig and could get the same treatment in a follow-up.

Test plan

  • bundle exec rspec (1263 examples, 0 failures)
  • bundle exec rubocop on changed files
  • bundle exec rake public_api:check

🤖 Generated with Claude Code

The Rails InitConfig is an explicit allowlist of setters and was never
extended when the distributed flag definition cache landed, so Rails apps
could only pass the provider via the hash form of PostHog.init. Add the
setter, document it in the generated initializer, and cover the block form
with specs.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

posthog-ruby-async Compliance Report

Date: 2026-10-13T21:26:38.352677+00:00
Duration: 98355ms

⚠️ Some Tests Failed

46/47 tests passed, 1 failed


Capture Tests

✅ 30/30 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields ✅ 111ms
Format Validation.Event Has Uuid ✅ 107ms
Format Validation.Event Has Lib Properties ✅ 109ms
Format Validation.Distinct Id Is String ✅ 107ms
Format Validation.Token Is Present ✅ 109ms
Format Validation.Custom Properties Preserved ✅ 108ms
Format Validation.Event Has Timestamp ✅ 108ms
Format Validation.Non Utc Event Timestamp Is Converted To Utc ✅ 10ms
Retry Behavior.Retries On 503 ✅ 5311ms
Retry Behavior.Does Not Retry On 400 ✅ 2109ms
Retry Behavior.Does Not Retry On 401 ✅ 2108ms
Retry Behavior.Respects Retry After Header ✅ 8017ms
Retry Behavior.Implements Backoff ✅ 15624ms
Retry Behavior.Retries On 500 ✅ 5212ms
Retry Behavior.Retries On 502 ✅ 5213ms
Retry Behavior.Retries On 504 ✅ 5212ms
Retry Behavior.Max Retries Respected ✅ 15523ms
Deduplication.Generates Unique Uuids ✅ 112ms
Deduplication.Preserves Uuid On Retry ✅ 5213ms
Deduplication.Preserves Uuid And Timestamp On Retry ✅ 10412ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry ✅ 5213ms
Deduplication.No Duplicate Events In Batch ✅ 112ms
Deduplication.Different Events Have Different Uuids ✅ 108ms
Compression.Sends Gzip When Enabled ✅ 106ms
Batch Format.Uses Proper Batch Structure ✅ 107ms
Batch Format.Flush With No Events Sends Nothing ✅ 5ms
Batch Format.Multiple Events Batched Together ✅ 110ms
Error Handling.Does Not Retry On 403 ✅ 2106ms
Error Handling.Does Not Retry On 413 ✅ 2110ms
Error Handling.Retries On 408 ✅ 5212ms

Feature_Flags Tests

⚠️ 16/17 tests passed, 1 failed

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

Failures

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', 'groups', 'person_properties', 'group_properties', 'flag_keys_to_evaluate', 'token']

@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

posthog-ruby-sync Compliance Report

Date: 2026-10-13T21:26:49.596813+00:00
Duration: 93952ms

⚠️ Some Tests Failed

45/47 tests passed, 2 failed


Capture Tests

⚠️ 29/30 tests passed, 1 failed

View Details
Test Status Duration
Format Validation.Event Has Required Fields ✅ 9ms
Format Validation.Event Has Uuid ✅ 6ms
Format Validation.Event Has Lib Properties ✅ 6ms
Format Validation.Distinct Id Is String ✅ 8ms
Format Validation.Token Is Present ✅ 6ms
Format Validation.Custom Properties Preserved ✅ 6ms
Format Validation.Event Has Timestamp ✅ 6ms
Format Validation.Non Utc Event Timestamp Is Converted To Utc ✅ 6ms
Retry Behavior.Retries On 503 ✅ 5258ms
Retry Behavior.Does Not Retry On 400 ✅ 2008ms
Retry Behavior.Does Not Retry On 401 ✅ 2010ms
Retry Behavior.Respects Retry After Header ✅ 8016ms
Retry Behavior.Implements Backoff ✅ 15322ms
Retry Behavior.Retries On 500 ✅ 5114ms
Retry Behavior.Retries On 502 ✅ 5141ms
Retry Behavior.Retries On 504 ✅ 5148ms
Retry Behavior.Max Retries Respected ✅ 15542ms
Deduplication.Generates Unique Uuids ✅ 15ms
Deduplication.Preserves Uuid On Retry ✅ 5145ms
Deduplication.Preserves Uuid And Timestamp On Retry ✅ 10260ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry ✅ 5156ms
Deduplication.No Duplicate Events In Batch ✅ 15ms
Deduplication.Different Events Have Different Uuids ✅ 7ms
Compression.Sends Gzip When Enabled ✅ 4ms
Batch Format.Uses Proper Batch Structure ✅ 5ms
Batch Format.Flush With No Events Sends Nothing ✅ 3ms
Batch Format.Multiple Events Batched Together ❌ 18ms
Error Handling.Does Not Retry On 403 ✅ 2007ms
Error Handling.Does Not Retry On 413 ✅ 2006ms
Error Handling.Retries On 408 ✅ 5115ms

Failures

batch_format.multiple_events_batched_together

Expected 1 requests, got 5

Feature_Flags Tests

⚠️ 16/17 tests passed, 1 failed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id ✅ 7ms
Request Payload.Flags Request Uses V2 Query Param ✅ 5ms
Request Payload.Flags Request Hits Flags Path Not Decide ✅ 6ms
Request Payload.Flags Request Omits Authorization Header ✅ 6ms
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 ✅ 7ms
Request Payload.Disable Geoip Omitted Defaults To False ❌ 5ms
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 ✅ 5ms
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 ✅ 157ms
Retry Behavior.Retries Flags On 504 ✅ 112ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event ✅ 8ms

Failures

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', 'groups', 'person_properties', 'group_properties', 'flag_keys_to_evaluate', 'token']

@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Retrigger

[Medium impact] Adds optional feature flag cache configuration to Rails SDK.

The PR appears safe to merge, with a non-blocking cleanup issue in the new provider test.

Reviews (1) · Last reviewed commit: "feat(rails): expose flag_definition_cach..." · Reviewed by Greptile

Comment thread spec/posthog/rails/railtie_spec.rb
@marandaneto
marandaneto marked this pull request as ready for review October 13, 2026 21:23
@marandaneto
marandaneto requested a review from a team as a code owner October 13, 2026 21:23
@marandaneto

Copy link
Copy Markdown
Member

thanks @seanpem

@seanpem
seanpem merged commit f3eb5e3 into main Oct 14, 2026
24 checks passed
@seanpem
seanpem deleted the flag-definition-cache-provider branch October 14, 2026 00:58
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