Skip to content

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

Open
pcbeingused333 wants to merge 1 commit into
launchdarkly:mainfrom
pcbeingused333:fix/async-hooks-environment-id
Open

pcbeingused333 wants to merge 1 commit into
launchdarkly:mainfrom
pcbeingused333:fix/async-hooks-environment-id

Conversation

@pcbeingused333

@pcbeingused333 pcbeingused333 commented Nov 27, 2026 •

Copy link
Copy Markdown

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
Fixes async/sync parity so AsyncLDClient hooks get the real LaunchDarkly environment ID in EvaluationSeriesContext instead of always None.

AsyncLDClient now supplies environment_id from the active data system when running evaluation hooks. AsyncDataSystem (FDv1 and FDv2) exposes that ID after the SDK learns it from LaunchDarkly.

FDv1 streaming records X-LD-EnvID from SSE connect headers; FDv1 polling adds get_all_data_with_headers on the built-in requester and records the header on each poll, with a fallback for custom requesters that only implement get_all_data. FDv2 stores the ID from successful initializer results and VALID synchronizer updates only.

New end-to-end tests cover streaming and polling hooks; FDv2 and polling unit tests were updated accordingly.

Reviewed by Cursor Bugbot for commit dc5b8e4. 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.
@pcbeingused333
pcbeingused333 requested a review from a team as a code owner November 27, 2026 04:25
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.

1 participant