feat: add async feature flag evaluation - #900
Open
marandaneto wants to merge 11 commits into
Open
Conversation
This was referenced Aug 26, 2026
Contributor
posthog-python Compliance ReportDate: 2026-08-27 20:15:27 UTC ✅ All Tests Passed!111/111 tests passed Capture_V1 Tests✅ 94/94 tests passed View Details
Feature_Flags Tests✅ 17/17 tests passed View Details
|
marandaneto
marked this pull request as ready for review
August 26, 2026 14:03
Contributor
Prompt To Fix All With AI### Issue 1
posthog/test/test_async_request.py:151-173
**Incomplete retry-flow coverage**
The success-path test covers only one transient failure before success, while `async_flags` supports multiple attempts and attempt-dependent backoff. A regression in later retries or exponential backoff progression would therefore pass this suite undetected.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Reviews (1): Last reviewed commit: "fix: evaluate flags for zero distinct ID" | Re-trigger Greptile |
…ags-v2 # Conflicts: # posthog/async_client.py
dustinbyrne
reviewed
Aug 26, 2026
dustinbyrne
left a comment
Contributor
There was a problem hiding this comment.
Agent-led review, human-reviewed before posting.
dustinbyrne
approved these changes
Aug 26, 2026
…ags-v2 # Conflicts: # posthog/async_client.py
…ags-v2 # Conflicts: # posthog/_async_request.py # posthog/test/test_async_request.py
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.
💡 Motivation and Context
Continues the async SDK work for #103. This PR is stacked on #899, supersedes #720, and incorporates its open review feedback.
The new
await AsyncPosthog.evaluate_flags(...)method sends a non-blocking/flagsrequest and returns the existingFeatureFlagEvaluationssnapshot. Itsis_enabled(),get_flag(), andget_flag_payload()accessors remain synchronous because they only read the returned snapshot. Passing that snapshot tocapture(flags=...)attaches the exact values used for application branching.This PR intentionally does not add the deprecated single-flag client methods or deprecated
capture(send_feature_flags=...)behavior. It also does not add local flag-definition polling or fallback caches. The initial async API focuses on the reported problem: remote evaluation when local evaluation is unavailable. This avoids synchronous Redis access, poller lifecycle failures, and the deferred flag-called-event races reported on #720.$feature_flag_calledevents use the synchronous bufferedcapture()method from #899. Deduplication therefore happens before control returns without scheduling extra tasks. The client also tracks flag and remote-config requests as in-flight operations so shutdown waits before closing its instance-owned HTTP transport.await get_remote_config_payload(...)provides the corresponding non-blocking remote-config API with bearer authentication and encoded request paths.All changes remain additive. Existing synchronous clients and module-level APIs are unchanged. The new constructor options are appended to the new async client's signature.
playgrounds/fastapi-async-clientdemonstrates the complete stacked API in FastAPI, including buffered and immediate capture, identify operations, exception capture, flag evaluation, remote config, flush, and lifespan-managed shutdown.💚 How did you test it?
uv run ruff format --check .uv run ruff check .uv run mypy --no-site-packages --config-file mypy.ini . | uv run mypy-baseline filteruv run --extra test pytest --timeout=30 -q- 2306 passed, 15 skipped, 36 subtests passeduv run --extra dev make public_api_checkuv lock --checkuv run python -W error -c "import posthog"posthoganalyticsmirror with the async flag APIsorigin/feat/async-client-capture-v2reported no actionable findings at598b7f8📝 Checklist
If releasing new changes
sampo addto generate a changeset file🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Implemented with pi. We narrowed the old #720 API to the recommended snapshot-based evaluation method and remote config. Prior review findings guided the retry contract, request sanitization, shutdown tracking, flag-called deduplication, and the decision to omit deprecated and local-evaluation surfaces from this stack.