feat: Add AsyncLDClient with FDv1 data system and public API - #480
Draft
jsonbailey wants to merge 12 commits into
Draft
feat: Add AsyncLDClient with FDv1 data system and public API#480jsonbailey wants to merge 12 commits into
jsonbailey wants to merge 12 commits into
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.
❌ 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 3cef7b5. Configure here.
jsonbailey
marked this pull request as draft
August 5, 2026 23:08
Address review findings in the async client evaluation and shutdown paths: - __evaluate_with_hooks held the hooks read lock across `await block()` on the empty-hooks fast path. A concurrent sync add_hook() takes the write lock with a blocking wait, freezing the event-loop thread. Snapshot the hooks under the lock and release it before awaiting, mirroring the sync client's no-await safety. - all_flags_state referenced `result.prerequisites` unconditionally even when a per-flag evaluation raised, causing UnboundLocalError on the first failure or reuse of a neighbor's prerequisites on a later one. Bind the prerequisites safely in both branches so an error degrades only that flag. - __try_execute_stage swallowed asyncio.CancelledError via `except BaseException`, defeating cancellation and shutdown. Re-raise it. - _close_components stopped components in sequence with no isolation, so one failing stop() skipped the rest. Stop each component in its own try/except.
The async client is single-event-loop, so a plain list copy of the hooks is atomic and add_hook is a same-loop sync append. This replaces the interim snapshot-under-lock fix and removes the threading ReadWriteLock entirely, so no lock is held across an await.
…nent isolation) The three component stop() methods (event processor, data system, big segment store manager) do not raise a regular exception in practice — the event processor guards its own shutdown, and the data-source/store closes bottom out in aiohttp/redis close() calls that do not raise. The only escaping exception is CancelledError, which the per-component 'except Exception' would not catch. So the isolation guarded a non-occurring path and diverged from the sync client; remove it for parity.
Set prerequisites next to detail in the success and error branches instead of a post-hoc result-is-None guard, so it's clear an errored flag yields no prerequisites.
… objects The decode was copied from the sync client, where it exists for pre-8.0.0 custom stores that predate the model-object migration. The async SDK is post-8.0.0 with no such legacy: the only async feature store (AsyncInMemoryFeatureStore) decodes on init and returns model objects, and all_flags_state already reads the store without decoding. Evaluate off store.get() directly.
The _get_store_item shim used to decode raw dicts on read. With it gone, MockAsyncFeatureStore.force_set must decode on write, as the real store does on init/upsert, so variation tests get model objects.
…sed client Every other LaunchDarkly server SDK (sync Python, Go, .NET, Node, Ruby) degrades lifecycle misuse to a logged no-op rather than throwing. Match that: start() on a closed AsyncLDClient logs a warning and returns.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Adds the async LaunchDarkly client (
AsyncLDClient) built onasyncio/aiohttp, wired to the FDv1 data system, plus the public API surface for constructing it. This is the first extraction slice from the async SDK implementation branch (epic SDK-60).What's included
ldclient/async_client.py—AsyncLDClientwith the FDv1 data system path.ldclient/impl/datasystem/async_fdv1.py— async FDv1 data system.ldclient/impl/datasystem/__init__.py— adds theAsyncDataSystemprotocol.ldclient/__init__.py,ldclient/client.py,ldclient/impl/client_common.py,ldclient/impl/stubs.py— public API / shared plumbing needed by the async client.ldclient/testing/mock_async_components.py,ldclient/testing/stub_util.py— async test doubles.ldclient/testing/test_async_client.py,ldclient/testing/test_sync_async_parity.py— coverage for the async client and sync/async API parity.Held back for a later PR (FDv2)
This slice is FDv1-only. The FDv2 data-system branch in
_make_data_system()(lazy imports ofasync_fdv2/datasourcev2.async_polling/async_streaming) is not included — those modules land in PR 11. For now the FDv2 path raisesNotImplementedError("FDv2 is not yet supported in the async client"). The_wire_data_source_sessionshelper (FDv2-only) was likewise omitted.Follow-ups
Verification
uv run pytest ldclient/testing/test_async_client.py ldclient/testing/test_sync_async_parity.py -q→ 21 passedpycodestyle,isort --check --atomic, andmypyclean on all changed filesasync_fdv2ordatasourcev2.async_*in the treeNote
Medium Risk
Large new experimental client surface touching flag evaluation, networking, and lifecycle; FDv2 is blocked but misconfiguration could surprise adopters until follow-up PRs land.
Overview
Introduces an experimental asyncio-based
AsyncLDClientwith explicitawait start()/close()(or async context manager), mirroring the sync client’s evaluation, events, hooks, and status APIs onAsyncConfigand aiohttp.Wires the client to a new
AsyncFDv1implementation and anAsyncDataSystemprotocol (streaming/polling via existing async datasource types). FDv2 is intentionally unsupported for now (NotImplementedErrorwhendatasystem_configis set).Public plumbing:
ldclientexposesAsyncLDClientvia lazy__getattr__;get_plugin_hooksnow takes a plugin sequence (syncLDClientupdated accordingly). AddsAsyncNullEventProcessor/AsyncNullUpdateProcessorfor offline and no-op paths.Tests:
test_async_client.py(lifecycle, variation, hooks, events) andtest_sync_async_parity.pyto guard sync/async API surface drift.Reviewed by Cursor Bugbot for commit 3cef7b5. Bugbot is set up for automated code reviews on this repo. Configure here.