Skip to content

fix: Clear feature flag called cache on close#585

Merged
marandaneto merged 3 commits into
mainfrom
fix/ff-called-cache-shutdown
Jun 24, 2026
Merged

fix: Clear feature flag called cache on close#585
marandaneto merged 3 commits into
mainfrom
fix/ff-called-cache-shutdown

Conversation

@marandaneto

Copy link
Copy Markdown
Member

💡 Motivation and Context

PostHogStateless.close() shut down the queue and feature flag provider but left the in-memory feature flag called cache populated. If the same SDK instance is closed and set up again, stale cache entries can suppress future $feature_flag_called events for values that were only seen before shutdown.

This PR clears the feature flag called cache during close and adds regression coverage for that behavior.

💚 How did you test it?

  • make stop && ./gradlew :posthog:test --tests "com.posthog.PostHogStatelessTest.close clears feature flag called cache"
  • make checkFormat

📝 Checklist

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

An OpenAI API coding agent prepared this PR using the existing dedicated fix/ff-called-cache-shutdown worktree. The branch was fast-forwarded to the latest main before committing because it was behind the base branch.

The implementation is intentionally narrow: clear the existing feature flag called cache during SDK close, add a regression test, and add a patch changeset for the affected release packages.

@marandaneto marandaneto self-assigned this Jun 24, 2026
@greptile-apps

greptile-apps Bot commented Jun 24, 2026

Copy link
Copy Markdown

Reviews (1): Last reviewed commit: "fix: Clear feature flag called cache on ..." | Re-trigger Greptile

Comment thread posthog/src/test/java/com/posthog/PostHogStatelessTest.kt Outdated
@github-actions

github-actions Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

posthog-android Compliance Report

Date: 2026-06-24 17:47:50 UTC
Duration: 119619ms

⚠️ Some Tests Failed

38/45 tests passed, 7 failed


Capture Tests

⚠️ 28/29 tests passed, 1 failed

View Details
Test Status Duration
Format Validation.Event Has Required Fields 330ms
Format Validation.Event Has Uuid 27ms
Format Validation.Event Has Lib Properties 27ms
Format Validation.Distinct Id Is String 29ms
Format Validation.Token Is Present 27ms
Format Validation.Custom Properties Preserved 24ms
Format Validation.Event Has Timestamp 25ms
Retry Behavior.Retries On 503 7021ms
Retry Behavior.Does Not Retry On 400 4022ms
Retry Behavior.Does Not Retry On 401 4022ms
Retry Behavior.Respects Retry After Header 7026ms
Retry Behavior.Implements Backoff 17035ms
Retry Behavior.Retries On 500 7013ms
Retry Behavior.Retries On 502 7020ms
Retry Behavior.Retries On 504 7020ms
Retry Behavior.Max Retries Respected 17022ms
Deduplication.Generates Unique Uuids 38ms
Deduplication.Preserves Uuid On Retry 7012ms
Deduplication.Preserves Uuid And Timestamp On Retry 12028ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry 7016ms
Deduplication.No Duplicate Events In Batch 32ms
Deduplication.Different Events Have Different Uuids 24ms
Compression.Sends Gzip When Enabled 18ms
Batch Format.Uses Proper Batch Structure 16ms
Batch Format.Flush With No Events Sends Nothing 11ms
Batch Format.Multiple Events Batched Together 30ms
Error Handling.Does Not Retry On 403 4017ms
Error Handling.Does Not Retry On 413 4014ms
Error Handling.Retries On 408 5029ms

Failures

error_handling.does_not_retry_on_413

Expected 1 requests, got 2

Feature_Flags Tests

⚠️ 10/16 tests passed, 6 failed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id 31ms
Request Payload.Flags Request Uses V2 Query Param 19ms
Request Payload.Flags Request Hits Flags Path Not Decide 22ms
Request Payload.Flags Request Omits Authorization Header 22ms
Request Payload.Token In Flags Body Matches Init 24ms
Request Payload.Groups Round Trip 20ms
Request Payload.Groups Default To Empty Object 23ms
Request Payload.Person Properties Distinct Id Auto Populated When Caller Omits It 22ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False 21ms
Request Payload.Disable Geoip Omitted Defaults To False 20ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key 19ms
Request Lifecycle.No Flags Request On Init Alone 9ms
Request Lifecycle.No Flags Request On Normal Capture 26ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests 2025ms
Request Lifecycle.Mock Response Value Is Returned To Caller 19ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event 20ms

Failures

request_payload.request_with_person_properties_device_id

Expected distinct_id='test_user_123', got '019efabe-cb72-7be6-8d6a-b82fa642725e'

request_payload.groups_default_to_empty_object

Field 'groups' not found in /flags request body at path 'groups'. Available keys: ['$anon_distinct_id', '$device_id', 'api_key', 'distinct_id', 'timezone', 'person_properties']

request_payload.person_properties_distinct_id_auto_populated_when_caller_omits_it

Field 'distinct_id' not found in /flags request body at path 'person_properties.distinct_id'. Available keys: ['$lib', '$lib_version', 'email']

request_payload.disable_geoip_false_propagates_as_geoip_disable_false

Field 'geoip_disable' not found in /flags request body at path 'geoip_disable'. Available keys: ['$anon_distinct_id', '$device_id', 'api_key', 'distinct_id', 'timezone', 'person_properties']

request_payload.disable_geoip_omitted_defaults_to_false

Field 'geoip_disable' not found in /flags request body at path 'geoip_disable'. Available keys: ['$anon_distinct_id', '$device_id', 'api_key', 'distinct_id', 'timezone', 'person_properties']

request_payload.flag_keys_to_evaluate_contains_only_requested_key

Field 'flag_keys_to_evaluate' not found in /flags request body at path 'flag_keys_to_evaluate'. Available keys: ['$anon_distinct_id', '$device_id', 'api_key', 'distinct_id', 'timezone', 'person_properties']

Comment thread .changeset/clear-flag-cache-close.md Outdated
Comment thread .changeset/clear-flag-cache-close.md Outdated
@marandaneto marandaneto marked this pull request as ready for review June 24, 2026 17:46
@marandaneto marandaneto requested a review from a team as a code owner June 24, 2026 17:46
@greptile-apps

greptile-apps Bot commented Jun 24, 2026

Copy link
Copy Markdown

Reviews (2): Last reviewed commit: "chore: update flag cache changeset" | Re-trigger Greptile

@marandaneto marandaneto merged commit 125f724 into main Jun 24, 2026
16 checks passed
@marandaneto marandaneto deleted the fix/ff-called-cache-shutdown branch June 24, 2026 18:24
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