Skip to content

fix: Pass the environment ID to hooks on the async client - #598

Merged
keelerm84 merged 8 commits into
launchdarkly:mainfrom
pcbeingused33:fix/async-hooks-environment-id
Dec 1, 2026
Merged

keelerm84 merged 8 commits into
launchdarkly:mainfrom
pcbeingused33:fix/async-hooks-environment-id

Conversation

@pcbeingused33

@pcbeingused33 pcbeingused33 commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Hooks registered on AsyncLDClient always receive environment_id=None in EvaluationSeriesContext, while the same hooks on LDClient receive the ID reported by LaunchDarkly.

Root cause

#484 added environment ID support to the sync path only. AsyncLDClient builds the series context without environment_id, and the async data systems never record the X-LD-EnvID response header.

Solution

Mirrors the sync implementation:

  • AsyncDataSystem exposes environment_id, and AsyncLDClient passes it to the series context.
  • FDv1 streaming records the header from the SSE Start action. FDv1 polling reads it from the response headers through get_all_data_with_headers; externally provided requesters that only implement get_all_data keep working.
  • AsyncFDv2 records it from successful initializer results and VALID synchronizer 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 AsyncFDv2 tests for initializer and synchronizer paths. They fail on main and pass with this change. The unit suite (excluding database integrations), mypy, isort and pycodestyle pass locally on a single Python version.

Related issues

Follow-up to #484. Sync/async parity: this brings the async_* siblings in line.

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 (one Python version locally; relying on CI for the rest)
  • Sync/async parity: matching changes made to 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 sync LDClient behavior after #484.

The async data plane captures X-LD-EnvID from successful connections: FDv1 streaming on SSE Start, FDv1 polling via new get_all_data_with_headers (with fallback to get_all_data for custom requesters), and AsyncFDv2 from successful initializer bases and VALID synchronizer updates only—not from error responses. AsyncDataSystem.environment_id exposes the value; AsyncLDClient threads it into hook evaluation.

Polling protocol detection switches from isinstance on a runtime-checkable Protocol to hasattr on the requester class, fixing Python 3.10/3.11 mocks that falsely implemented get_all_data_with_headers. Contract tests advertise hook-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.

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.
@pcbeingused33
pcbeingused33 requested a review from a team as a code owner November 27, 2026 04:25

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

Thank you for another contribution! Appreciate all the work.

@keelerm84
keelerm84 merged commit c19b32f into launchdarkly:main Dec 1, 2026
16 checks passed
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.

2 participants