Skip to content

feat: Support waiting indefinitely for initialization - #36

Open
kinyoklion wants to merge 13 commits into
mainfrom
devin/1788360613-ruby-zero-start-wait
Open

kinyoklion wants to merge 13 commits into
mainfrom
devin/1788360613-ruby-zero-start-wait

Conversation

@kinyoklion

@kinyoklion kinyoklion commented Sep 2, 2026 •

Copy link
Copy Markdown
Member

Passing LaunchDarkly::OpenFeature::Provider::WAIT_INDEFINITELY as the wait time now asks the provider to wait for the LaunchDarkly client without a deadline.

  • WAIT_INDEFINITELY makes init wait until the client is initialized, the data source becomes valid or fails permanently, or the provider is shut down. The client constructor is given a wait time of zero, so it does not block, and the constant is never passed to the SDK as a wait time.
  • A wait time of zero keeps its duration meaning: nothing waits, and init reports a failed initialization unless the client is already ready.
  • A positive wait time is unchanged; the client constructor applies it and init does not wait a second time.
  • Since LaunchDarkly Ruby SDK 8.19.0 a rejected SDK key is retried rather than failing permanently, so the data source no longer reaches OFF for it and WAIT_INDEFINITELY can wait indefinitely. This is what the spec requires (OFP 4.3.7.3); the README row now says so.
  • Follows the initialization requirements of the OpenFeature provider behavior spec, which requires a value distinct from any duration to request indefinite waiting (OFP 4.3.4).

Found during the weekly OpenFeature provider audit. Earlier revisions of this PR overloaded a zero wait time, and then nil, to mean "wait indefinitely".

Requirements

  • I have added test coverage for new or changed functionality
  • I have followed the repository's pull request submission guidelines
  • I have validated my changes against all supported platform versions

Related issues

#39 (provider-emitted lifecycle events) covers two limitations this PR documents in the README eventing row rather than fixes.

Implementation details

WAIT_INDEFINITELY is Float::INFINITY, so passing Float::INFINITY directly behaves the same. The LaunchDarkly Ruby SDK has no indefinite wait time for its constructor (wait_for_sec is a timeout, and nil is not accepted), so the provider passes zero to the constructor and does the waiting in init.

When the wait is indefinite, init subscribes a DataSourceOutcomeListener to the data source status provider, replays the current status through it (so an outcome reached before subscribing is not missed), and waits on a queue. VALID and OFF decide the outcome; INITIALIZING and INTERRUPTED do not. Some data sources initialize the client without reporting VALID (custom data sources, an FDv2 initializer basis without a selector), so the wait also re-checks initialized? every second. The queue is kept on the provider and shutdown closes it, so a pending init raises instead of leaking its thread, including for data sources that do not report OFF when stopped.

Whether initialization succeeded is still decided by initialized?, read under the status lock so a concurrent status change is emitted rather than overwritten. A failure raises with the data source's last error, which the OpenFeature SDK turns into the ERROR state. A failed initialization is not terminal: status changes keep flowing, so a later VALID state reports the provider as ready.

With OpenFeature Ruby SDK 0.6.x, replacing a provider whose indefinite init is still pending delivers a PROVIDER_ERROR for the replaced provider to API-level handlers (0.7+ drops it). The provider cannot suppress this: 0.6.x dispatches PROVIDER_READY or PROVIDER_ERROR whichever way init ends. It is documented in the README; raising the floor to 0.7 is tracked with #39.

Describe alternatives you've considered

nil for an indefinite wait (an earlier revision): a named constant is more explicit at the call site.

A non-numeric sentinel (e.g. a symbol): Float::INFINITY already reads as "no deadline" in Ruby and keeps the parameter numeric.

Applying a default timeout: an indefinite wait is the caller asking for no deadline, and the OpenFeature SDK decides how long to wait for a provider.

Relying on status events alone: not every data source reports VALID when it initializes the client, so initialized? is also checked once a second.

Additional context

Testing: bundle exec rspec (95 examples) and bundle exec rubocop on Ruby 3.4; CI also runs JRuby 10.0 and Windows. spec/provider_initialization_spec.rb drives real clients: a custom data source that becomes valid, one that initializes without reporting VALID, shutdown during a blocked init and before init, and FDv2 initializers that report VALID, initialize without VALID, and fail (then shut down). The new tests hang or fail without the fix.

SDK-3285

Link to Devin session: https://app.devin.ai/sessions/9478c0d905024dc38d831070eb64ea7c
Link to Bot: https://app.devin.ai/org/launchdarkly/bots/649040a7a000452fbe03eca40165f725
Open in Devin Desktop: https://app.devin.ai/desktop/session/9478c0d905024dc38d831070eb64ea7c?variant=devin


Devin Review


Note

Overview
Adds Provider::WAIT_INDEFINITELY (Float::INFINITY) so callers can block in init until the LaunchDarkly client is ready, the data source reaches VALID or permanent OFF, or the provider is shut down—without passing an infinite timeout into LDClient (constructor still uses 0 for indefinite mode).

init now uses a DataSourceOutcomeListener plus periodic initialized? checks for indefinite waits, records init success/failure under a mutex (without duplicating the SDK’s init lifecycle event), and surfaces data-source errors in failure messages. emit_status_event replaces raw emissions from the status listener: repeated status that does not change provider state is suppressed, and events are held back until initialization finishes.

shutdown unregisters data-source and flag listeners, closes the init wait queue (unblocking pending init), and the README feature matrix documents the new initialization behavior and refined eventing limitations.

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

@devin-ai-integration

Copy link
Copy Markdown
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration devin-ai-integration Bot added the devin-pr PRs created by Devin label Sep 2, 2026
@devin-ai-integration

Copy link
Copy Markdown
Contributor

@cursor review

Co-Authored-By: rlamb@launchdarkly.com <4955475+kinyoklion@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor

@cursor review

devin-ai-integration Bot and others added 2 commits September 29, 2026 22:56
Co-Authored-By: rlamb@launchdarkly.com <4955475+kinyoklion@users.noreply.github.com>
The provider's data source status and flag change listeners stayed
registered on the LaunchDarkly client after `shutdown`, so a provider
which the OpenFeature SDK had already replaced could still emit events.
They are now removed before the client is closed.

Event deduplication and the events emitted after a failed
initialization, which this PR previously carried, now live in
[#36](#36)
instead; this branch has been merged with that one and keeps only the
`shutdown` change. Review
[#36](#36)
first.

Found during the weekly OpenFeature provider audit.

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

**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)
- [x] I have validated my changes against all supported platform
versions

**Related issues**

None.

**Describe the solution you've provided**

The listeners the constructor registers are kept on the provider so that
`shutdown` can pass them to `remove_listener` on the data source status
provider and the flag tracker before closing the client.

**Describe alternatives you've considered**

Relying on `close` alone: the LaunchDarkly client stops notifying
listeners once it is closed, but the provider is the owner of those
subscriptions and a closed client is not a guarantee the OpenFeature SDK
makes about a replaced provider.

**Additional context**

Testing: `bundle exec rspec` (83 examples) and `bundle exec rubocop` on
Ruby 3.4.5. The `shutdown` spec now asserts both listeners are removed
as well as the client being closed.
</details>

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

---------

Signed-off-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Devin AI <devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
kinyoklion added a commit to launchdarkly/js-core that referenced this pull request Oct 9, 2026
Gives the OpenFeature providers the initialization waiting values the
OpenFeature provider spec (OFP) requires, which the numeric-only
`initTimeoutSeconds` could not express.

- `initTimeoutSeconds: 'forever'` waits indefinitely for the
LaunchDarkly client
- `initTimeoutSeconds: 0` waits nowhere and fails initialization unless
the client is already ready, so readiness is observed through provider
events
- A positive timeout behaves as before, and the default is still 10
seconds
- Node provider README feature matrix row updated for the new values

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

**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)
- [x] I have validated my changes against all supported platform
versions

**Related issues**

OFP requirement 4.3.4 requires a value distinct from any duration to
request waiting indefinitely, and 4.3.6 requires a zero wait to wait
nowhere and fail initialization. Sibling changes for the same
requirement: launchdarkly/openfeature-java-server#66,
launchdarkly/openfeature-python-server#64,
launchdarkly/openfeature-dotnet-server#71,
launchdarkly/openfeature-ruby-server#36.

**Describe the solution you've provided**

`BaseProviderConfig.initTimeoutSeconds` and the Node provider's
constructor parameter are now `number | 'forever'`, and zero is no
longer coalesced into the default, since `??` only replaces `undefined`.
`waitForInitialization` treats a falsy timeout as no timeout, so zero
cannot be passed through: initialization races the pending
initialization promise against an immediately rejected one, which
succeeds only when the client is already ready.

The Cloudflare provider is unaffected because it evaluates from a KV
namespace and has no data source to wait for.

**Describe alternatives you've considered**

`number | null` was used initially for the indefinite case; `'forever'`
reads better at the call site and matches the repository's preference
for string unions. Adding `initialized()` to the client contract would
let the zero case be checked directly, but that is a breaking change to
a published interface for behavior the existing promise already
expresses.

**Additional context**

Verified with `yarn workspace @launchdarkly/openfeature-js-server-common
test` (82 tests), `yarn workspace @launchdarkly/openfeature-node-server
test` (29 tests), and lint, format and build checks for both packages.

</details>

Link to Devin session:
https://app.devin.ai/sessions/1fd3fcbfe79f482e8b58be29e8df2ffb
Open in Devin Desktop:
https://app.devin.ai/desktop/session/1fd3fcbfe79f482e8b58be29e8df2ffb?variant=devin
Requested by: @kinyoklion

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Overview**
> Extends **`initTimeoutSeconds`** on the shared
**`BaseOpenFeatureProvider`** and the Node **`LaunchDarklyProvider`** to
**`number | 'forever'`**, aligning initialization with the OpenFeature
provider spec.
> 
> **`'forever'`** calls **`waitForInitialization()`** with no timeout.
**`0`** no longer falls through to the 10-second default (only
**`undefined`** does); initialization races the client’s init promise
against an immediate failure so it succeeds only when the client is
already ready, otherwise it throws a clear error. Positive timeouts
behave as before (default **10** seconds).
> 
> The Node provider README initialization row documents the new values,
and unit tests cover indefinite wait, zero-timeout failure, and
zero-timeout success when already ready.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
87e9a23. 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>
Co-Authored-By: Ryan Lamb <4955475+kinyoklion@users.noreply.github.com>
@kinyoklion

Copy link
Copy Markdown
Member Author

Devin can we use some constant to represent waiting forever instead of nil? If we do, then make sure we won't pass a giant number to the SDK and instead use its canonical way of waiting forever.

@devin-ai-integration

Copy link
Copy Markdown
Contributor

❌ Cannot revive Devin session - the session is too old. Please start a new session instead.

View session

… initialization waiting

Co-Authored-By: Ryan Lamb <4955475+kinyoklion@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor

Devin can we use some constant to represent waiting forever instead of nil? If we do, then make sure we won't pass a giant number to the SDK and instead use its canonical way of waiting forever.

Done in 2bfcb5c. nil is replaced by LaunchDarkly::OpenFeature::Provider::WAIT_INDEFINITELY (it is Float::INFINITY).

The constant never reaches the SDK. The Ruby SDK has no way to wait forever in its constructor: wait_for_sec is only a timeout, and nil fails on wait_for_sec > 0. So for WAIT_INDEFINITELY the provider passes 0 to LDClient.new and does the waiting in init by listening to the data source status provider. A new spec asserts that the constructor receives 0.

Written by Devin

@kinyoklion
kinyoklion marked this pull request as ready for review October 30, 2026 23:38
@kinyoklion
kinyoklion requested a review from a team as a code owner October 30, 2026 23:38
cursor[bot]

This comment was marked as resolved.

…wait subscribes

Co-Authored-By: Ryan Lamb <4955475+kinyoklion@users.noreply.github.com>
kinyoklion added a commit to launchdarkly/openfeature-java-server that referenced this pull request Nov 4, 2026
**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)
- [x] I have validated my changes against all supported platform
versions

**Related issues**

Fixes #58.

**Describe the solution you've provided**

Adds `Provider(String sdkKey, LDConfig config, Duration startWait)` so
an application can bound, or deliberately opt out of, waiting for
initialization, matching the OpenFeature provider spec (OFP)
requirements for start wait behavior:

- a positive `Duration` is applied by the LaunchDarkly client
constructor, and `initialize` then reports whether the client became
ready without waiting a second time
- `Duration.ZERO` waits nowhere; `initialize` fails unless the client is
already ready, and the application learns when it becomes usable from
provider events
- `Provider.INFINITE_START_WAIT` requests indefinite waiting: nothing is
waited for during construction and `initialize` blocks until the data
source becomes valid or fails permanently

The existing constructors keep honouring
`LDConfig.Builder.startWait(...)` and no longer wait again in
`initialize`, so a configured start wait is the only bound on
initialization instead of being followed by an unbounded wait. The
README feature matrix row and initialization section describe the new
behavior.

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

`initialize` still registers data source and flag change listeners and
evaluates the current data source status. Only the indefinite mode
leaves the completion future pending; every other mode completes it with
the outcome that is already known, so `initialize` returns promptly.

The OpenFeature SDK emits its own event for the transition that
completes initialization, so the provider records that one state without
emitting a duplicate, and emits every state change after it — including
a permanent failure that arrives immediately after the data source
became valid, and a recovery after a failed initialization.

</details>

**Describe alternatives you've considered**

Keeping the existing indefinite wait and adding a timeout parameter
interpreted only inside `initialize` would double-wait when
`LDConfig.startWait` is also set, and would not match OFP, which treats
the start wait as a bound over construction plus initialization.

Java has no built-in infinite `Duration`, so indefinite waiting was
initially expressed as `null`. It is now the explicit
`Provider.INFINITE_START_WAIT` constant, matching
`Timeout.InfiniteTimeSpan` in the .NET provider.

**Additional context**

Sibling changes for the same OFP requirement:
launchdarkly/openfeature-python-server#64,
launchdarkly/openfeature-ruby-server#36,
launchdarkly/openfeature-dotnet-server#71, and
launchdarkly/js-core#2024.

Verified with `./gradlew test` (all tests pass, including new coverage
for positive, zero, and indefinite start wait).

Link to Devin session:
https://app.devin.ai/sessions/1fd3fcbfe79f482e8b58be29e8df2ffb
Open in Devin Desktop:
https://app.devin.ai/desktop/session/1fd3fcbfe79f482e8b58be29e8df2ffb?variant=devin
Requested by: @kinyoklion

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

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Overview**
> Fixes OpenFeature initialization behavior (**#58**) by adding
**`Provider(String, LDConfig, Duration startWait)`** and
**`Provider.INFINITE_START_WAIT`**, so startup waiting is bounded in one
place instead of blocking again indefinitely inside **`initialize()`**
after **`LDConfig.startWait`**.
> 
> **Positive durations** apply during client construction;
**`Duration.ZERO`** fails fast unless already ready; **indefinite** mode
skips construction blocking and waits in **`initialize()`** until the
data source is valid, fails, or the provider shuts down. Oversized
durations are treated as indefinite to avoid SDK millis overflow.
> 
> **`initialize()`** is reworked around a completion future and tighter
state/event handling: failed init surfaces data-source errors, duplicate
**STALE**/**READY** events are deduped, teardown **OFF** does not emit
**PROVIDER_ERROR**, and **`shutdown()`** calls **`super.shutdown()`** to
stop leaking the event executor. README documents cancellation of
indefinite **`setProviderAndWait`** (direct **`provider.shutdown()`** vs
API lock contention).
> 
> Lifecycle tests cover bounded/zero/infinite waits, recovery, and
classification boundaries.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
1c96e64. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

---

## tanderson-ld additional changes

Review-driven hardening of the start wait time behavior, on top of the
commits above. Summary of the delta:

**Indefinite wait is now cancellable.** `shutdown()` completes the
initialization future, and the interrupt flag is restored if the waiting
thread is interrupted. The README and constructor javadoc document how
to cancel an indefinite `setProviderAndWait`: call `provider.shutdown()`
directly from another thread, or register with the non-blocking
`setProvider`. `OpenFeatureAPI.shutdown()` **cannot** end such a wait —
it blocks on the same API lock `setProviderAndWait` holds for the
duration of initialization. This lock-contention deadlock is inherent to
the OpenFeature Java SDK (it holds the API write lock across a
synchronous `initialize()` and contends on it in `shutdown()`), so it is
documented rather than worked around; an upstream issue will be filed
against the OpenFeature Java SDK.

**Start wait time classification / validation.**
- Any start wait time too large to represent in milliseconds — including
`Provider.INFINITE_START_WAIT` and any other "forever" duration — is
classified as indefinite, so it saturates to the indefinite path instead
of overflowing when the SDK converts it to milliseconds. (Separately, a
too-large duration configured through `LDConfig.Builder.startWait`
instead of the constructor still overflows inside the SDK client
constructor and leaks the client; that is pre-existing SDK behavior and
has been filed as a separate java-core ticket. The sentinel is
documented as constructor-argument-only.)
- A `null` start wait time falls through to the SDK's default start wait
rather than throwing.

**Status / event fidelity.**
- A failed initialization carries the data source's last error into the
thrown exception, so the OpenFeature error event reports the cause
rather than a generic message.
- The client's `isInitialized()` latch no longer reports `READY` when
the data source is currently `OFF`.
- Repeated interruptions emit one `PROVIDER_STALE` per state change
(state-based dedupe, retained and documented), and stale events now
carry the HTTP error detail.

**Lifecycle cleanup.** `shutdown()` removes its flag-change and
data-source status listeners and calls `super.shutdown()` to terminate
the event emitter executor.

**Tests.** Added lifecycle coverage for bounded / zero / indefinite
waits, failed-init-then-recovery, interruption → stale → ready,
single-stale-per-outage dedupe, cancellation of an indefinite
`setProviderAndWait` via a direct `provider.shutdown()`, the
`OFF`-while-initialized exclusion, listener removal on shutdown, and a
direct unit test of the start-wait classification boundary. Full suite
and checkstyle pass.


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

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Todd Anderson <tanderson@launchdarkly.com>
kinyoklion added a commit that referenced this pull request Nov 6, 2026
#43)

**Requirements**

- [ ] 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)
- [x] I have validated my changes against all supported platform
versions

**Related issues**

`build-linux (jruby-10.0)` fails on #36 (and any PR that runs CI) since
`ubuntu-latest` moved to `ubuntu-26.04`.

**Describe the solution you've provided**

Bumps the pinned `ruby/setup-ruby` from v1.299.0 to v1.336.0 (`de492cf`)
in the CI action, the Windows job, and the docs publish workflow.
v1.299.0 does not list `ubuntu-26.04-x64` as a GitHub-hosted platform,
so it treats the runner as self-hosted and refuses to install JRuby:

```
The current runner (ubuntu-26.04-x64) was detected as self-hosted because the platform does not match a GitHub-hosted runner image
```

v1.336.0 includes `ubuntu-26.04-x64` and `ubuntu-26.04-arm64` in
`GitHubHostedPlatforms`.

**Describe alternatives you've considered**

Pinning `runs-on: ubuntu-24.04`: works, but defers the problem and
diverges from the other jobs.

**Additional context**

CI-only change; no release needed. Found during the weekly OpenFeature
provider audit.

Link to Devin session:
https://app.devin.ai/sessions/a5c7e7288f924650ba0ccbd5417d33d2
Open in Devin Desktop:
https://app.devin.ai/desktop/session/a5c7e7288f924650ba0ccbd5417d33d2?variant=devin

[SDK-3499](https://launchdarkly.atlassian.net/browse/SDK-3499)
<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Overview**
> Pins **`ruby/setup-ruby`** from **v1.299.0** to **v1.336.0** in the
shared CI composite action (`.github/actions/ci/action.yml`), the
Windows CI job in `ci.yml`, and the manual docs publish workflow.
> 
> This restores Linux CI (including **JRuby**) after **`ubuntu-latest`**
switched to **ubuntu-26.04**: the older action did not treat that image
as GitHub-hosted and failed Ruby/JRuby setup. No application or runtime
code changes.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
a340e63. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

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

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
kinyoklion added a commit that referenced this pull request Nov 6, 2026
…chDarkly Ruby SDK 8.19 (#40)

Updates the README feature matrix after the OpenFeature Ruby SDK
0.6.6–0.8.1 releases (2026-10-22/23) and LaunchDarkly Ruby SDK 8.19.0.

- **Eventing** goes from ✅ to ⚠️, listing two provider gaps:
- A data source update that leaves the provider status unchanged is
emitted again (fix in #36).
- The provider relies on SDK-emitted `PROVIDER_READY`/`PROVIDER_ERROR`,
which OpenFeature Ruby SDK 0.7.0 deprecates (tracked in #39).
- **Initialization** notes that since LaunchDarkly Ruby SDK 8.19.0 a
rejected SDK key is retried, so the constructor waits the full wait time
before initialization fails.
- **Domains** notes that the provider is not domain-scoped
(`domain_scoped?`, OpenFeature Ruby SDK 0.6.7).

<details>
<summary>Details</summary>

- Duplicate events: LaunchDarkly Ruby SDK's
`DataSourceUpdateSinkImpl#update_status` broadcasts again when the state
is unchanged but there is a new error. `DataSourceStatusListener` emits
every broadcast, so one `INTERRUPTED` period can produce several
`PROVIDER_STALE` events (OFP 4.2.2). #36 already adds the status
de-duplication.
- Deprecation: in OpenFeature Ruby SDK 0.7.0
(open-feature/ruby-sdk#353), a provider with `init` but without
`emits_lifecycle_events?` takes the legacy path, and the SDK logs a
deprecation warning once per provider class. The gemspec's `~> 0.6.1`
keeps 0.7 out of range today, and #38 widens it. #39 describes the
follow-up and what blocks it: #38, #36, the Bundler cooldown, and a
needed OFP 4.2.5 update.
- Rejected key: in 8.19.0 the stream and polling data sources report
`INTERRUPTED` and retry after any failure, and they go to `OFF` only
from `stop`. `@ready` is set only on success, so a rejected key keeps
the constructor waiting for the full `wait_for_seconds`.
- Other changes in 0.6.6–0.8.1 need no provider change:
- Hook inputs are immutable and flag metadata is frozen. The provider
builds a new metadata hash on each evaluation.
  - Clients resolve their domain's provider on every call.
- Isolated API instances are supported. The provider includes
`EventEmitter`, so the SDK rejects registering one instance with two
APIs.
- `PROVIDER_RECONCILING`/`PROVIDER_CONTEXT_CHANGED` are static-context
events and don't apply to a server provider.
- Docs only, so no changelog entry or release.

</details>

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

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


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

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Overview**
> Updates the README **feature matrix** to reflect OpenFeature Ruby SDK
0.7.x and LaunchDarkly Ruby SDK **8.19.0** behavior—documentation only,
no code changes.
> 
> **Eventing** is downgraded from fully supported to **partially
supported (⚠️)** with notes on two known gaps: duplicate provider events
when the data source status stays the same but errors update
([#36](#36)),
and reliance on SDK-emitted init lifecycle events that 0.7.0 deprecates
([#39](#39)).
> 
> **Initialization** now explains that rejected SDK keys are retried in
8.19.0, so `init` may block for the full configured wait before
reporting failure. **Domains** clarifies the provider is not
domain-scoped, so one provider instance can back multiple OpenFeature
domains with a shared LaunchDarkly client.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
7cac07d. 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>
…-zero-start-wait

Co-Authored-By: Ryan Lamb <4955475+kinyoklion@users.noreply.github.com>

# Conflicts:
#	README.md

@keelerm84 keelerm84 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Review of 8218e72 against origin/main, graded against OFP sections 4.1-4.3 and 5.4 (sdk-specs @ 76471a4). Each finding was reproduced with a script or proof test, or confirmed by reading the code, with ruby-server-sdk 8.20.1 and openfeature-sdk 0.8.1.

The PR meets what it claims: a distinct indefinite value (4.3.4), duplicate suppression (4.2.2), no event for the transition that completes init (4.2.5), and no constructor wait or timeout for an indefinite wait (4.3.7.1-2). The two blocking issues are inline on wait_for_data_source_outcome: shutdown cannot release an indefinite init for several data sources, and the wait misses a client that becomes ready without a VALID report.

One finding has no line in the diff. The gemspec allows openfeature-sdk >= 0.6.1. On 0.6.1, replacing a provider whose indefinite init is still pending makes the old provider's init fail when it is shut down, and 0.6.1 then delivers a PROVIDER_ERROR with the LaunchDarkly provider's name to API-level handlers. A repro delivered one such event on 0.6.1 and none on 0.8.1, which drops it. This is new with WAIT_INDEFINITELY, because init previously never outlived the call. Suggested fix: raise the floor to >= 0.7, or drop the init outcome after shutdown.

Checked and dismissed: out-of-order listener delivery (all broadcasters share one SingleThreadExecutor), hangs in offline/LDD/FDv2 daemon/cached store modes (initialized? is true at entry), and an outcome reached before subscribing (covered by the replay of the current status).

Comment thread lib/ldclient-openfeature/provider.rb Outdated
Comment on lines +238 to +248
outcome = Queue.new
listener = Impl::DataSourceOutcomeListener.new(outcome)
status_provider = @client.data_source_status_provider
status_provider.add_listener(listener)

begin
return if @client.initialized?

# An outcome reached before the listener was added is not reported to it.
listener.update(status_provider.status)
outcome.pop

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

shutdown cannot release this wait. The queue is local, and it only receives a value when the data source reports VALID or OFF. Several data sources never report OFF when stopped: FDv2 configured with initializers only, the FDv2 main-loop and synchronizer-build error exits (fdv2.rb stop only sets @stop_event), FileData with a file that fails to load, and custom sources. In each case the init thread was still blocked 8 seconds after shutdown (SDK 8.20.1). The thread leaks, and a caller of set_provider_and_wait hangs. FDv1 streaming/polling and default FDv2 streaming do report OFF on stop, so they are fine.

Suggested fix: keep the queue in an instance variable, and have shutdown close it (or push a marker) before client.close. Queue#pop on a closed empty queue returns nil, so init can raise "shut down" on nil.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Fixed in b44fa43. The wait queue is now kept on the provider, and shutdown closes it under @status_lock before closing the client, so a pending init raises "shut down". A provider shut down before init starts closes the queue at once, and a late listener push onto the closed queue is ignored. New specs in spec/provider_initialization_spec.rb shut down during a blocked init with a custom data source that never reports OFF and with FDv2 configured with only a failing initializer, plus shutdown before init. They hang or fail on the previous code.

Written by Devin

Comment thread lib/ldclient-openfeature/provider.rb Outdated
status_provider.add_listener(listener)

begin
return if @client.initialized?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

initialized? is checked only once. A client can become initialized without the data source ever reporting VALID: a custom config.data_source that never calls update_status, or an FDv2 initializer that applies a basis without a selector (fdv2.rb sets @ready_event with the state still INITIALIZING). A repro with such a custom source showed client.initialized? true and init still blocked, which violates OFP 4.3.1.

Suggested fix: loop on outcome.pop(timeout: 1) and re-check @client.initialized? between pops. The gem already requires Ruby 3.4, so the timeout form is available.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Fixed in b44fa43, as suggested: the wait loops on outcome.pop(timeout: 1) and re-checks @client.initialized? between pops. New specs cover a custom data source that initializes the store without update_status, and an FDv2 initializer that applies a basis without a selector (status stays INITIALIZING). Both hang on the previous code.

Written by Devin

Comment thread lib/ldclient-openfeature/provider.rb Outdated
return if @client.initialized?
wait_for_data_source_outcome if @wait_indefinitely

initialized = @client.initialized?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This read is outside @status_lock. If VALID is processed between this line and line 83, the listener records READY without emitting it, and lines 86-91 then overwrite it with ERROR. The SDK does not broadcast a repeated VALID, so the provider stays ERROR while the client is valid (OFP 4.2.6 / 4.3.3). I reproduced this with a proof test that delivers VALID right after this read.

The final state was the same before this PR, but reading initialized? inside the lock is a cheap way to narrow the window. The remaining window is in the next comment.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Fixed in b44fa43: initialized? is now read inside @status_lock. A new spec emits READY from another thread while init reads initialized?, and checks the event is emitted rather than overwritten.

Written by Devin

::OpenFeature::SDK::ProviderEvent::PROVIDER_ERROR
end
@initialization_complete = true
end

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

After the lock is released, a status change can be emitted by the listener before the OpenFeature SDK dispatches its own READY/ERROR for this init. The SDK event then wins. Repro: data source interrupted right after this block gives events [PROVIDER_STALE, PROVIDER_READY] and a final provider state of READY while the data source is INTERRUPTED. This predates the PR and only #39 (provider-emitted lifecycle events with emits_lifecycle_events?) can close it. It may be worth noting in the README eventing row.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Agreed this predates the PR and only #39 can close it, so no code change here. In b44fa43 the README eventing row notes that a status change just as init completes can be emitted before the OpenFeature SDK's own event, which then sets the status.

Written by Devin

Comment thread lib/ldclient-openfeature/provider.rb Outdated
outcome = Queue.new
listener = Impl::DataSourceOutcomeListener.new(outcome)
status_provider = @client.data_source_status_provider
status_provider.add_listener(listener)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Minor: add_listener runs before the begin, so an async Timeout that fires between this line and line 243 leaves the listener registered. Moving it inside the begin costs nothing.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Fixed in b44fa43: add_listener is now inside the begin, so the ensure always removes it.

Written by Devin

Comment thread lib/ldclient-openfeature/provider.rb Outdated
return if initialized

state = @client.data_source_status_provider.status.state
raise "the LaunchDarkly client was unable to initialize; the data source state is #{state}"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Pre-existing, minor: on the init-failure path the OpenFeature SDK uses this message for the PROVIDER_ERROR event. It includes the state but not status.last_error, so for example the 401 reason is dropped. OFP 4.2.3 asks for the last error message on ERROR events.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Fixed in b44fa43: the init failure message now includes last_error (kind, status code and message), with the same formatting as the status listener's events. A new spec checks a 401 reason appears in the message.

Written by Devin

#
# @return [void]
#
def emit_status_event(event, **details)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: this is new public API on Provider that only the internal status listener uses. Consider marking it @api private.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Fixed in b44fa43: marked @api private.

Written by Devin

Comment thread spec/provider_spec.rb Outdated

it "shutdown closes the client" do
allow(provider.client).to receive(:close)
it "init without a deadline waits for the data source to become valid" do

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This test never waits: TestData is already VALID when the constructor returns, so initialized? is true when init starts.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Agreed. In b44fa43 this test is renamed to what it checks (an already-initialized client does not wait). Real waits are now covered in spec/provider_initialization_spec.rb, with a custom data source that reports nothing until the test tells it to.

Written by Devin

Comment thread spec/provider_spec.rb
expect(LaunchDarkly::LDClient).to have_received(:new).with("example-key", anything, 0)
end

it "init without a deadline waits for a data source outcome which arrives later" do

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This would also pass if wait_for_data_source_outcome subscribed but did not block, because initialized? is stubbed false and init raises either way. Asserting that the init thread is still alive before the reporter pushes OFF would make it test the wait.

Missing tests: shutdown while an indefinite init is blocked, and any FDv2 coverage.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Fixed in b44fa43: the test runs init in a thread, asserts it is still alive before OFF is pushed, then that it raises. Shutdown during a blocked init and FDv2 (an initializer that reports VALID, one that initializes without VALID, and one that fails) are covered in spec/provider_initialization_spec.rb.

Written by Devin

@devin-ai-integration

Copy link
Copy Markdown
Contributor

❌ Cannot revive Devin session - the session is too old. Please start a new session instead.

View session

…alizes without reporting VALID

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

@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.

Stale comment

Risk: medium. Not approved: SDK risk classification (max low) — this initialization/wait/eventing change is above the low-risk threshold. Cursor Bugbot completed with no unresolved findings that require this automation to block; 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

@devin-ai-integration devin-ai-integration Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Note

Newer findings are available below. Devin Review posted a newer report on this PR, in addition to the findings presented here.

Devin Review found 4 potential issues.

Devin Review

Comment thread lib/ldclient-openfeature/provider.rb Resolved
Comment on lines +75 to +80
def update(status)
case status.state
when ::LaunchDarkly::Interfaces::DataSource::Status::VALID,
::LaunchDarkly::Interfaces::DataSource::Status::OFF
begin
@outcome.push(status.state)

@devin-ai-integration devin-ai-integration Bot Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔴 Protocol fallback fails provider registration

On an FDv2-to-FDv1 fallback before flags load, DataSourceOutcomeListener treats OFF as terminal. The Ruby SDK still starts the configured fallback, but set_provider_and_wait raises if that fallback has not loaded flags yet.

Learn more

The supported LaunchDarkly SDK range includes 8.19.0, where LaunchDarkly::DataSystem.streaming configures an FDv1 fallback. When StreamingDataSource#handle_error receives an HTTP error with a fallback directive, it produces an OFF update with fallback_to_fdv1: true. The FDv2 coordinator publishes that status before switching to its configured fallback, so OFF does not establish terminal failure. The provider's init can raise before the fallback loads data. A later READY event does not change the result of that synchronous registration call.

Example: The initial FDv2 request directs the client to FDv1, and the FDv1 poll returns flags a second later. The caller receives an initialization exception during that second instead of waiting for the poll to succeed.

Recommended fix: Base the wait on a terminal outcome from the whole data system rather than an OFF update from one synchronizer. Add coverage for both a configured fallback that succeeds and a fallback directive with no configured fallback.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not changing this. The status the SDK reports for an FDv2-to-FDv1 fallback is a plain OFF, which the provider cannot tell apart from a permanent failure. If it ships as is, init fails and the provider is ERROR until the fallback loads flags; then VALID is emitted as READY, because a failed init is not terminal. Telling the two apart needs the SDK to report the fallback differently.

Written by Devin

Comment thread lib/ldclient-openfeature/provider.rb Resolved
Comment thread lib/ldclient-openfeature/provider.rb Resolved
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…tus_event from the API docs

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Devin Review found 1 new potential issue.

Devin Review

Comment on lines +131 to +139
it "emits status changes after an interrupted wait" do
provider = manual_provider
emitted = Queue.new
allow(provider).to receive(:emit_event) { |event, **| emitted << event }

expect { Timeout.timeout(0.2) { provider.init(evaluation_context) } }.to raise_error(Timeout::Error)
manual_data_source.become_valid

expect(emitted.pop(timeout: 5)).to eq(OpenFeature::SDK::ProviderEvent::PROVIDER_READY)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔍 Untested SDK recovery after timeout

The timeout test calls init directly and stubs emit_event. It does not verify that a client reports READY after set_provider_and_wait times out and the data source recovers.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Leaving this as a provider-level test. OpenFeature SDK 0.8.1's set_provider_and_wait takes no timeout, so the timeout comes from the caller wrapping it (as here), and what the SDK does with a READY after that is SDK behavior that differs between 0.6 and 0.8. The provider's part is to emit READY once the data source recovers, which this spec and the one added in 159ada2 check.

Written by Devin

cursor[bot]

This comment was marked as 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.

Stale comment

Risk: medium. Not approved: SDK risk classification (max low) — this initialization/wait/eventing change is above the low-risk threshold. Cursor Bugbot completed unsuccessfully with 1 unresolved finding (interrupted init records the wrong status); 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

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

@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: medium. Not approved: Risk Classification (max low) — this initialization, wait, and eventing change is above the low-risk threshold. Cursor Bugbot completed with no unresolved findings that require this automation to block; 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

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

devin-pr PRs created by Devin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants