Repository navigation
fix: Pass the environment ID to hooks on the async client - #598
Merged
keelerm84 merged 8 commits intoDec 1, 2026
Merged
Conversation
AsyncLDClient built EvaluationSeriesContext without environment_id, and the async data systems never recorded the X-LD-EnvID header. Mirror the sync implementation for FDv1 streaming, FDv1 polling and FDv2.
On Python 3.10 and 3.11, isinstance with a runtime_checkable Protocol uses hasattr. Every mock passes that check, so a mocked requester that configures only get_all_data never initializes the store.
…uesters without headers
keelerm84
approved these changes
Dec 1, 2026
keelerm84
left a comment
Member
There was a problem hiding this comment.
Thank you for another contribution! Appreciate all the work.
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.
Hooks registered on
AsyncLDClientalways receiveenvironment_id=NoneinEvaluationSeriesContext, while the same hooks onLDClientreceive the ID reported by LaunchDarkly.Root cause
#484 added environment ID support to the sync path only.
AsyncLDClientbuilds the series context withoutenvironment_id, and the async data systems never record theX-LD-EnvIDresponse header.Solution
Mirrors the sync implementation:
AsyncDataSystemexposesenvironment_id, andAsyncLDClientpasses it to the series context.Startaction. FDv1 polling reads it from the response headers throughget_all_data_with_headers; externally provided requesters that only implementget_all_datakeep working.AsyncFDv2records it from successful initializer results andVALIDsynchronizer updates only.Existing async polling tests now mock
get_all_data_with_headers, since that is the method the processor calls on the built-in requester.Tests
New end-to-end tests for streaming and polling with a local HTTP server, plus
AsyncFDv2tests for initializer and synchronizer paths. They fail onmainand pass with this change. The unit suite (excluding database integrations),mypy,isortandpycodestylepass locally on a single Python version.Related issues
Follow-up to #484. Sync/async parity: this brings the
async_*siblings in line.Requirements
async_*siblings (or N/A)This change was prepared with AI assistance.
Note
Overview
Async evaluation hooks now receive the LaunchDarkly environment ID in
EvaluationSeriesContext, matching syncLDClientbehavior after #484.The async data plane captures
X-LD-EnvIDfrom successful connections: FDv1 streaming on SSEStart, FDv1 polling via newget_all_data_with_headers(with fallback toget_all_datafor custom requesters), and AsyncFDv2 from successful initializer bases andVALIDsynchronizer updates only—not from error responses.AsyncDataSystem.environment_idexposes the value;AsyncLDClientthreads it into hook evaluation.Polling protocol detection switches from
isinstanceon a runtime-checkable Protocol tohasattron the requester class, fixing Python 3.10/3.11 mocks that falsely implementedget_all_data_with_headers. Contract tests advertisehook-environment-id.New coverage includes async polling/streaming/FDv2 unit tests and end-to-end hook checks for streaming and polling with a stub HTTP server.
Reviewed by Cursor Bugbot for commit 93de62c. Bugbot is set up for automated code reviews on this repo. Configure here.