Skip to content

feat: Add experimental support for flag overrides - #523

Merged
keelerm84 merged 12 commits into
feat/9.xfrom
mk/SDK-3806/port-flag-overrides
Dec 3, 2026
Merged

keelerm84 merged 12 commits into
feat/9.xfrom
mk/SDK-3806/port-flag-overrides

Conversation

@keelerm84

@keelerm84 keelerm84 commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

BEGIN_COMMIT_OVERRIDE
feat: Add experimental support for flag overrides, read from local JSON
or YAML files or supplied by a custom override source
feat: Mark evaluations that a flag override affected with
override_affected in the evaluation reason, and count them under
separate summary counters
END_COMMIT_OVERRIDE

Every change in this PR was already reviewed and merged through its own
PR against feat/overrides: #449, #450, #451, #452, #453, #454, #484,
#493. This PR merges the branch into main and adds nothing of its own.

Flag overrides let an operator force flags and segments to known
definitions on a running client, whether or not the client can reach
LaunchDarkly, and remove the override when the incident is over. They
are an option of the FDv2 data system
(LaunchDarkly::DataSystem::ConfigBuilder#overrides), with a file-based
source in LaunchDarkly::Integrations::FileData.override_source, and
are experimental.

main has one commit that feat/overrides does not (#490), and the two
merge without conflicts. CI on feat/overrides @ 156611b is green on
every job, Windows included.

Opened from termag


Note

Overview
Adds experimental flag overrides: optional per-key flag/segment definitions that win over LaunchDarkly data at evaluation time, configured via LaunchDarkly::DataSystem::ConfigBuilder#overrides and intended for incident response.

The FDv2 data system wires an override layer + overlay on the feature store, starts/stops an OverrideSource, and exposes override_items so evaluations and all_flags_state can still serve override-only data before LaunchDarkly init. A new file-based source (LaunchDarkly::Integrations::FileData.override_source) loads JSON/YAML from local paths with merge/reload logic, polling or listen-based watching, and contract-test harness support (flag-overrides capability). Dependency tracking links LaunchDarkly store changes to override dependents for flag-change notifications.

Evaluations that read override data are marked with override_affected on EvaluationReason (including transitive prereq/segment reads). Those evaluations skip individual and debug analytics events and appear only in summary counters tagged with overrideAffected. Docs/examples now call .build on data-system presets.

Reviewed by Cursor Bugbot for commit 4cb8af9. Bugbot is set up for automated code reviews on this repo. Configure here.

(cherry picked from commit 9e2452c)

Ported to v9: the FDv2 file data source and its spec are the renamed
file_data_source files, the FDv1 data system and file data source are
gone, data kinds live in Interfaces::DataStore, Config takes
data_system:, and the specs use the v9 MockFeatureStore and
InMemoryFeatureStore.

kinyoklion and others added 11 commits December 2, 2026 21:05
#473)

Fixes an intermittent JRuby failure in
`big_segment_store_status_provider sends status updates`
(`spec/ldclient_listeners_spec.rb:34`, `expected false, got true`), seen
on #472.

- `spec/mock_components.rb`: adds `GatedBigSegmentStore`, a Big Segment
store whose metadata queries wait for the test to supply each result
- `spec/ldclient_listeners_spec.rb`: the example adds its observer and
checks what it received only while the poller is waiting inside a query

**Requirements**

- [x] I have added test coverage for new or changed functionality
- [x] I have followed the repository's [pull request submission
guidelines](../blob/main/CONTRIBUTING.md#submitting-pull-requests)
- [ ] I have validated my changes against all supported platform
versions

<details>
<summary>Implementation details</summary>

**Root cause**

The status poller caches each status inside `@poll_lock` and notifies
observers after it releases the lock. `status_provider.status` returns
the cached status without waiting for that notification. When the
poller's first poll runs before the example reads the status, as it
usually does on JRuby, the example can do all of the following before
the poller delivers its first notification:

1. Read the healthy status.
2. Add its observer.
3. Inject the store error.

The provider has not notified anyone yet, so that first notification
goes to the new observer, carrying the healthy status. `statuses.pop`
returns it instead of the unavailable status.

#440 fixed the same race in the `status polling` examples in
`spec/impl/big_segments_spec.rb`. There it caused a hang; here it
delivers the wrong first status.

**Solution**

`GatedBigSegmentStore#get_metadata` counts the query, then waits until
the test queues a result. The poller notifies observers of one result
before it starts its next query. So once query N has started, every
earlier result has been delivered, and nothing else happens until the
test queues another result.

The example now runs in three steps:

1. It queues a healthy result and reads it through
`status_provider.status`.
2. It waits for query 2, then adds the observer. Only the poller can
make that query, because later status reads come from the cache.
3. It queues an error and waits for query 3. Then it checks that the
observer received exactly one status, that the status is unavailable,
and that `status_provider.status` returns it.

None of these steps depends on how long a poll or notification takes:
- `status_poll_interval: 0.01` only controls how quickly the poller
moves on to its next query.
- The 5-second wait timeouts only bound how long a failure takes to
report.

The example releases the store in `ensure`. The client can't stop its
poller while a query is waiting.

**Alternatives considered**

- Skipping statuses until an unavailable one arrives, as
`next_status_matching` does in `big_segments_spec.rb`. That would pass,
but it would hide an extra or out-of-order notification, and it waits in
a sleep loop.
- Changing the manager so the first status reaches observers before
`status` returns. That changes SDK behavior to suit a test. The manager
also deliberately notifies outside `@poll_lock` (see
`query_store_status`).

**Testing**

With no code changes, the failure reproduces on JRuby 9.4.6 pinned to
one or two cores. Every failure was the CI one: `expected false, got
true` at line 34.

| Unmodified SDK, JRuby 9.4.6 | Old example | New example |
|---|---|---|
| Pinned to 1 core (`taskset -c 0`) | 6/1,000 failed; 8/1,000 on a rerun
| 1,000/1,000 passed |
| Pinned to 2 cores | 4/1,000 failed | 1,000/1,000 passed |
| 8 cores, not pinned | 1,500/1,500 passed | 1,500/1,500 passed |

The next rows inject delays, gated by environment variables, into a
local copy of `big_segments.rb` and the spec. None of that code is in
this PR. The random delays apply at 5 points in the poll and notify
path, plus the example's status read and `add_observer`.

| Injected delays | Old example | New example |
|---|---|---|
| Poller polls first, notify delayed 0.3s (MRI 3.2) | 10/10 failed |
10/10 passed |
| Same, JRuby 9.4.6 | 10/10 failed | 10/10 passed |
| Random delay up to 5ms at each point (MRI 3.2) | 121/300 failed |
300/300 passed |
| Same, JRuby 9.4.6 | 141/300 failed | 300/300 passed |
| Random delay up to 50ms at each point (MRI 3.2) | 23/60 failed | 60/60
passed |
| Same, JRuby 9.4.6 | 23/60 failed | 60/60 passed |

The new example still fails when the SDK is broken in each of these
ways:
- The poller never notifies.
- A store error is reported as available.
- A change is notified twice.
- Polls never update the cached status.
- The store is queried only once.

The full suite passes on MRI 3.2 (`bundle exec rspec spec`) and on JRuby
9.4.6 (`--tag '~flaky'`, as in CI), with one exception.
`launchdarkly-server-sdk_spec.rb:5` fails on `main` too: its unbundled
subprocess can't find the gems in my local bundle path. RuboCop reports
no offenses on the changed files.

**Not addressed here**

The same timing can affect an application. If it reads the status and
then adds a listener while the client is starting, the listener can
receive the status that was just read. That's a redundant notification
rather than a wrong status, so this PR doesn't change it.

</details>

[SDK-3424](https://launchdarkly.atlassian.net/browse/SDK-3424)

[SDK-3424]:
https://launchdarkly.atlassian.net/browse/SDK-3424?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Overview**
> Fixes a flaky JRuby failure in **`big_segment_store_status_provider
sends status updates`** where the observer could receive the initial
healthy status instead of the post-error unavailable status, because the
status poller notifies observers after caching and the old mock returned
results immediately.
>
> Adds **`GatedBigSegmentStore`** in `spec/mock_components.rb`: metadata
**`get_metadata`** blocks until the test **`queue_metadata`** /
**`queue_metadata_error`**, exposes **`wait_for_queries`** for poll
ordering, and **`release`** so the client can shut down without hanging
on a blocked query.
>
> The listener example switches from **`MockBigSegmentStore`** to the
gated store: queue healthy metadata, wait for the second poll before
registering the observer, then queue an error and wait for the third
poll before asserting exactly one unavailable notification and matching
**`status`**.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
1ecf5d0. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

(cherry picked from commit d3f643e)
…verification in the contract test service (#481)

<!-- TERMAG_PR_BODY_BEGIN -->

The contract test service now maps `configuration.wrapper` to
`wrapper_name`/`wrapper_version` (an empty name or version counts as
unset) and `configuration.serviceEndpoints` to
`stream_uri`/`base_uri`/`events_uri`, and streams by default when only
`serviceEndpoints.streaming` is given. It declares `wrapper`,
`service-endpoints` and `tls:verify-peer`, so the harness now runs the
wrapper header tests, `events/disabling`, `service endpoints/using
separate service endpoints properties` (v2) and the three `invalid tls
certificate` tests. The SDK verifies peers by default, so TLS needs no
mapping.

Tested locally against harness v2.42.0 and v3.2.0-alpha.15 with
persistence tests enabled: every newly run test passes and no test that
passed on main fails or disappears.
<!-- TERMAG_PR_BODY_END -->

<!-- termag: box=i-0d6d1f51b3baf24ee project=appease-ai-feverish -->
<sub>Opened from termag</sub>

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Overview**
> The contract test **ClientEntity** now maps harness
**`configuration.serviceEndpoints`** onto SDK **`stream_uri` /
`base_uri` / `events_uri`** (applied early; legacy
streaming/polling/events blocks can still override). When there is no
**`dataSystem`**, **`streaming`**, or **`polling`** block, **`use_ldd`**
is enabled only if **`serviceEndpoints.streaming`** is absent—so a
streaming-only endpoint config can drive live updates without an
explicit streaming section.
>
> **`configuration.wrapper`** is mapped to **`wrapper_name`** and
**`wrapper_version`**, treating empty strings as unset.
>
> The test service advertises **`wrapper`**, **`service-endpoints`**,
and **`tls:verify-peer`** capabilities so the harness runs wrapper
header, separate-endpoints, events-disable, and invalid-TLS scenarios
(peer verification relies on SDK defaults, not new mapping).
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
0370c08. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

(cherry picked from commit 9a2f5b9)
…github/actions/publish (#511)

(cherry picked from commit b89031c)
…#507)

## Summary

Declares `diagnostic-events` in the contract test service so the new
sdk-test-harness test `events/diagnostic events` runs. The test was
added in v3.2.0-alpha.20 and checks that `diagnostic-init` is sent to
`/diagnostic` and that no diagnostic payload reaches the analytics
route.

- The entity already sets `diagnostic_opt_out = !enableDiagnostics`, so
the entity needs no other change.

<details>
<summary>Testing</summary>

I ran the v3.2.0-alpha.20 harness locally with `-run diagnostic` against
the service (Ruby 3.3), and all 3 diagnostic tests passed.

</details>

Link to Devin session:
https://app.devin.ai/sessions/56b8ade9602745fbba00e59a531bbefa
Open in Devin Desktop:
https://app.devin.ai/desktop/session/56b8ade9602745fbba00e59a531bbefa?variant=devin
Requested by: @joker23

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Overview**
> Adds **`diagnostic-events`** to the capabilities returned by the
contract test service’s root endpoint so the sdk-test-harness
**diagnostic events** suite (v3.2.0-alpha.20+) is selected for this
adapter. No other service or entity changes are required because
diagnostics opt-out is already driven by `enableDiagnostics` in the
client entity.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
b40a9c9. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
(cherry picked from commit 81e7544)
<!-- TERMAG_PR_BODY_BEGIN -->
BEGIN_COMMIT_OVERRIDE
feat: Add experimental support for flag overrides, read from local JSON
or YAML files or supplied by a custom override source
feat: Mark evaluations that a flag override affected with
`override_affected` in the evaluation reason, and count them under
separate summary counters
END_COMMIT_OVERRIDE

Every change in this PR was already reviewed and merged through its own
PR against `feat/overrides`: #449, #450, #451, #452, #453, #454, #484,
#493. This PR merges the branch into `main` and adds nothing of its own.

Flag overrides let an operator force flags and segments to known
definitions on a running client, whether or not the client can reach
LaunchDarkly, and remove the override when the incident is over. They
are an option of the FDv2 data system
(`LaunchDarkly::DataSystem::ConfigBuilder#overrides`), with a file-based
source in `LaunchDarkly::Integrations::FileData.override_source`, and
are experimental.

`main` has one commit that `feat/overrides` does not (#490), and the two
merge without conflicts. CI on `feat/overrides` @ 156611b is green on
every job, Windows included.
<!-- TERMAG_PR_BODY_END -->

<!-- termag: box=i-0575d1c54853058d7 project=ruby-server-sdk -->
<sub>Opened from termag</sub>

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Overview**
> Adds **experimental flag overrides** so operators can force known
flag/segment definitions at evaluation time without replacing
LaunchDarkly streaming or polling.
>
> **Configuration & data path.** FDv2 gains an optional override source
via `DataSystemConfig` / `ConfigBuilder#overrides`. When set, the client
builds an override layer, overlays it on the feature store for reads,
and wires the layer’s dependency graph into the main store so
prerequisite/segment changes still fan out to affected flags. Contract
tests advertise `flag-overrides` and can wire file paths through
`LaunchDarkly::Integrations::FileData.override_source`.
>
> **File-based source.** New `FileData` plumbing (parse/merge, poller,
reloader with in-place rewrite handling, optional `listen`-based
watcher) backs `FileData.override_source` with polling or watching,
duplicate-key policy, and resilient reload/retry. The `listen` gem is
added for contract tests’ watching mode.
>
> **Evaluation & analytics.** Flag/segment models carry an internal
override marker. The evaluator propagates **override-affected** marking
through prerequisites and segment matches; `EvaluationReason` exposes
`overrideAffected` in JSON when true. Override-affected evaluations are
excluded from individual and debug events but get **separate summary
counters** keyed by the marker.
>
> **Client behavior.** Before initialization (or when the store is
unavailable), evaluations and `all_flags_state` can serve override
entries only, with one-time warnings. Docs/examples shift to
`data_system_config: ... .build` instead of passing raw builders.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
156611b. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
(cherry picked from commit 9e2452c)

Ported to v9: the FDv2 file data source and its spec are the renamed
file_data_source files, the FDv1 data system and file data source are
gone, data kinds live in Interfaces::DataStore, Config takes
data_system:, and the specs use the v9 MockFeatureStore and
InMemoryFeatureStore.
@keelerm84
keelerm84 requested a review from a team as a code owner December 3, 2026 15:14

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 4cb8af9. Configure here.

Comment thread lib/ldclient-rb/ldclient.rb Resolved

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Risk: high. Not approved: Cursor Bugbot reported 1 unresolved finding, and this experimental overrides change (evaluation, events, and data-store overlay) is above the low-risk approval threshold. SDK approval policy rule 4; human review is needed and no reviewers were assigned.

Open in Web View Automation 

Sent by Cursor Approval Agent: SDK - Pull Request Router and Approver

Base automatically changed from mk/SDK-3806/sync-main-chores to feat/9.x December 3, 2026 17:44
@keelerm84
keelerm84 added this pull request to stack #527 December 3, 2026 17:45
…flag-overrides

# Conflicts:
#	contract-tests/service.rb
@keelerm84
keelerm84 merged commit e1990f0 into feat/9.x Dec 3, 2026
8 of 9 checks passed
@keelerm84
keelerm84 deleted the mk/SDK-3806/port-flag-overrides branch December 3, 2026 18:11
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.

4 participants