Skip to content

feat: Avoid updating populated store with empty configs during init#36

Closed
stephenreid wants to merge 1 commit intostatsig-io:mainfrom
stephenreid:Empty-network-response-should-not-update-an-existing-store
Closed

feat: Avoid updating populated store with empty configs during init#36
stephenreid wants to merge 1 commit intostatsig-io:mainfrom
stephenreid:Empty-network-response-should-not-update-an-existing-store

Conversation

@stephenreid
Copy link

@stephenreid stephenreid commented Feb 24, 2026

Summary

This pull request introduces a safeguard to prevent the local configuration from being wiped when the network returns an empty set of specifications while a data store is in use. This ensures that the SDK continues to use the last known good configuration if the network sync fetches an empty response.

Changes

lib/spec_store.rb

  • Added is_empty_specs?(specs_json): A private helper method to determine if a given specifications object contains no feature gates, dynamic configs, or layer configs.
  • Updated process_specs(specs_string, from_adapter: false):
    • Added a check to see if the incoming specifications are empty.
    • If the specs are empty, the network is the source (from_adapter is false), and a data store is configured, the update is skipped (returns nil early).

test/data_adapter_test.rb

  • Added test_datastore_preserves_data_when_network_returns_empty_specs:
    • A new test case that simulates a network response returning empty specifications.
    • Verifies that both the SpecStore's internal state and the configured DataStore preserve the original configuration instead of being overwritten by the empty response.

Test Plan

  • Run test_datastore_preserves_data_when_network_returns_empty_specs to verify data preservation.
  • Ensure existing data adapter tests still pass.

Impact

This change improves the resilience of the SDK when using a persistent data store. It prevents a "blank slate" scenario where all feature gates and configurations would temporarily evaluate to their default values if the network sync happens to fetch an empty response.

@stephenreid stephenreid changed the title Don't update existing store with empty spec from network Avoid updating populated store with empty configs during init Feb 24, 2026
@stephenreid stephenreid changed the title Avoid updating populated store with empty configs during init feat: Avoid updating populated store with empty configs during init Feb 24, 2026
@stephenreid
Copy link
Author

stephenreid commented Feb 24, 2026

@lfoster-statsig For consideration for those of us who have implemented Redis (or other persistence) with an iDataStore interface to share across multi-instance envs

@lfoster-statsig
Copy link
Contributor

@lfoster-statsig For consideration for those of us who have implemented Redis (or other persistence) with an iDataStore interface to share across multi-instance envs

Honestly do think this is a beneficial idea, will get more eyes internally

@stephenreid
Copy link
Author

stephenreid commented Feb 26, 2026

The test failure appears to be a change in how the sdk key is passed in the test/ci environment between 2.5.0 and 3.2.0

secret = ENV['test_api_key']

@stephenreid
Copy link
Author

The bootstrap and adapter choice already choose this

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