Repository navigation
feat: Accept synchronous hooks on the async client - #548
Merged
Merged
Conversation
AsyncLDClient now takes the same ldclient.hook.Hook as LDClient, so integrations such as the OpenTelemetry tracing hook work with it. The hook stages run synchronously in the caller's task, so a span made current in the before stage stays current until the after stage. AsyncHook is removed. AsyncPlugin keeps its async register(), and its get_hooks() returns Hook instances. AsyncConfig now raises TypeError for a hook that is not a Hook or a plugin that is not an AsyncPlugin, which matches add_hook().
Match the sync client: AsyncConfig and add_hook() ignore items of the wrong type. The async contract-test service uses the sync PostingHook. Remove redundant docstring notes.
The after stages get an error detail with the default value, and the exception is re-raised. A hook such as the OpenTelemetry tracing hook can then detach its context and end its span.
jsonbailey
force-pushed
the
jb/sdk-3077/sync-hooks-async-client
branch
from
November 2, 2026 14:24
915b8d6 to
17e8352
Compare
jsonbailey
marked this pull request as ready for review
November 2, 2026 15:06
keelerm84
approved these changes
Nov 2, 2026
jsonbailey
added a commit
that referenced
this pull request
Nov 2, 2026
🤖 I have created a release *beep* *boop* --- ## [9.19.0](9.18.4...9.19.0) (2026-11-02) ### Breaking changes to the experimental async client The async client is experimental, so these changes do not cause a major version bump. If you use `AsyncLDClient` with hooks or plugins, update your code: * Remove the experimental `AsyncHook` class. The async client now uses the same synchronous `Hook` class as the sync client. Change each `AsyncHook` subclass to subclass `Hook`, and change its `async def` stages to `def`. The stages run on the event loop, so they must not block. ([#548](#548)) ([2457311](2457311)) * `AsyncPlugin.get_hooks` now returns a list of `Hook` instances. `AsyncPlugin.register` stays async. ([#548](#548)) ([2457311](2457311)) ### Features * Accept synchronous hooks on the async client ([#548](#548)) ([2457311](2457311)) ### Bug Fixes * Run after-evaluation hooks when an async evaluation is cancelled or raises ([2457311](2457311)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Overview** > **Release 9.19.0** — bumps the package version from **9.18.4** to **9.19.0** in `pyproject.toml`, `ldclient/version.py`, `.release-please-manifest.json`, and the provenance verification example in `PROVENANCE.md`, and adds the **9.19.0** section to `CHANGELOG.md`. > > What ships in this release (documented in the new changelog entry, not in this diff’s code): > > The **experimental async client** unifies on the sync **`Hook`** API: **`AsyncHook` is removed**, **`AsyncPlugin.get_hooks`** returns **`Hook`** instances ( **`AsyncPlugin.register`** stays async), and the async client **accepts synchronous hooks**. Hook stage methods should be plain **`def`** (non-blocking on the event loop). A bug fix ensures **after-evaluation hooks run** when an async evaluation is **cancelled or raises**. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 54a6f6a. 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: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: jsonbailey <jbailey@launchdarkly.com>
kinyoklion
added a commit
that referenced
this pull request
Nov 12, 2026
Conflicts in the capability lists of the contract test services keep both sides: flag-overrides from feat/overrides, and the retry conformance, service endpoints, wrapper, proxy and TLS capabilities from main. The async override test that captured evaluation details used AsyncHook, which #548 removed from main; it now uses Hook, which the async client accepts.
kinyoklion
added a commit
that referenced
this pull request
Nov 12, 2026
<!-- 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 `overrideAffected` in the evaluation reason, and count them under separate summary counters fix: Stop the components that already started when the client fails to start END_COMMIT_OVERRIDE Every change in this PR was already reviewed and merged through its own PR against `feat/overrides`: #525, #526, #527, #528, #529, #530, #572, #574, #576, #577. This PR merges the branch into `main`. 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, on both `LDClient` and `AsyncLDClient`, with a file-based source in `ldclient.integrations.overrides.FileOverrideSourceBuilder`, and are experimental. The one change outside the feature: #527 stops the components that had already started when the data system fails to start, so a failed client construction no longer leaves threads behind. `main` was merged into `feat/overrides` in 46e5f0e, so the branch has every `main` commit. That merge resolved two conflicts and made one follow-up change: - The capability lists of both contract test services keep both sides: `flag-overrides` from this branch, and the retry conformance, service endpoints, wrapper, proxy and TLS capabilities from `main`. - One async override test used `AsyncHook`, which #548 removed from `main`. It now uses `Hook`, which the async client accepts. Before the push: - the unit test suite passed (2,357 tests, without the Redis, DynamoDB and Consul store tests, which need servers); - `mypy`, `isort` and `pycodestyle` were clean; - the contract test harness's `flag overrides` suite passed against both the sync and the async test service (88 tests each). <!-- TERMAG_PR_BODY_END --> <!-- termag: box=i-0575d1c54853058d7 project=python-server-sdk --> <sub>Opened from termag</sub> <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Overview** > Adds **experimental flag overrides** so operators can force known flag/segment definitions at runtime (via local JSON/YAML files through `FileOverrideSourceBuilder`, or a custom `OverrideSource`), integrated into the FDv2 data system for sync and async clients through `datasystem_config.override_source` / `ConfigBuilder.overrides()`. > > The data system now maintains an **override layer** merged over the normal store, serves override-only flags when LaunchDarkly data is not ready, and fans out **dependency-aware flag-change notifications** when LD data affects overridden prerequisites/segments. Evaluations propagate an **`overrideAffected`** reason marker; analytics treat those evaluations differently (summary counters only, `all_flags_state` disables per-flag tracking for them). > > Contract test services advertise **`flag-overrides`** and build override sources from harness config; docs add `ldclient.integrations.overrides`. > > Also **fixes client startup**: if the data system fails to start, already-started components are stopped so failed construction does not leak threads. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 46e5f0e. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
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.
feat: Remove the experimental AsyncHook class
Warning
Breaking change to the experimental async API. Code that subclasses
AsyncHookor passesAsyncHookinstances toAsyncLDClientmust change to useldclient.hook.Hook. The async API is experimental, so this is not marked with!and does not need a major version. Edit the release notes to call out the break for async users.Summary
AsyncLDClientnow uses the sameldclient.hook.HookasLDClient, so existing integrations such as the OpenTelemetry tracing hook work with the async client. Before this change, the async client accepted onlyAsyncHookand ignored sync hooks.AsyncHookis removed. The async API is experimental.AsyncPluginkeeps its asyncregister(). Itsget_hooks()now returnsHookinstances.AsyncConfigandadd_hook()ignore items of the wrong type, the same as the sync client.PostingHook.Note
Overview
Breaking change for the experimental async client:
AsyncHookis removed.AsyncLDClientandAsyncConfignow take the sameHooktype asLDClient, so shared integrations (e.g. OpenTelemetry) work without a separate async hook API.Hook before/after stages run synchronously in the caller’s task (not awaited). Context set in
before_evaluationstays visible through the evaluation and is cleared inafter_evaluation, which matters forcontextvarsand tracing under concurrentvariation()calls.When evaluation raises or is cancelled, after hooks still run with an error
EvaluationDetail(default value +EXCEPTIONreason) before the exception propagates, so hooks can tear down spans/context.add_hook()and confighooksfiltering match the sync client (ignore non-Hooktypes instead of raising on sync hooks).AsyncPlugin.get_hooks()returnsHookinstances; contract tests dropAsyncPostingHookand registerPostingHookvia config.Reviewed by Cursor Bugbot for commit 17e8352. Bugbot is set up for automated code reviews on this repo. Configure here.