From 4e69f21da08f7e12f962abb8ae88acab01da3280 Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto Date: Fri, 22 May 2026 10:49:20 +0200 Subject: [PATCH 1/2] chore: stabilize sdk compliance adapter --- sdk_compliance_adapter/adapter.py | 33 ++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/sdk_compliance_adapter/adapter.py b/sdk_compliance_adapter/adapter.py index 5ec29cff..cb3e168d 100644 --- a/sdk_compliance_adapter/adapter.py +++ b/sdk_compliance_adapter/adapter.py @@ -69,6 +69,22 @@ def __init__(self): def reset(self): """Reset all state""" + client_to_shutdown = None + with self.lock: + client_to_shutdown = self.client + self.client = None + + if client_to_shutdown: + # Flush and shutdown the existing client outside state.lock. + # The patched transport records successful flush requests through + # SDKState.record_request(), which also needs state.lock. Holding the + # lock while shutdown() waits for the queue to drain can deadlock when + # a pending background event is being flushed during test reset. + try: + client_to_shutdown.shutdown() + except Exception as e: + logger.warning(f"Error shutting down client: {e}") + with self.lock: self.pending_events = 0 self.total_events_captured = 0 @@ -77,13 +93,6 @@ def reset(self): self.last_error = None self.requests_made = [] self.retry_attempts = {} - if self.client: - # Flush and shutdown existing client - try: - self.client.shutdown() - except Exception as e: - logger.warning(f"Error shutting down client: {e}") - self.client = None def increment_captured(self): """Increment total events captured""" @@ -235,6 +244,10 @@ def init(): gzip=enable_compression, max_retries=max_retries, debug=True, + # Compliance tests assert the request-level default when callers omit + # disable_geoip. Configure the adapter to exercise geoip-enabled + # /flags requests by default while still allowing per-call overrides. + disable_geoip=False, ) state.client = client @@ -393,6 +406,12 @@ def get_feature_flag(): only_evaluate_locally=not force_remote, ) + # Ensure the SDK's side-effect $feature_flag_called event is sent before + # the adapter action returns. Otherwise the harness may reset mock-server + # state for the next test while the background consumer is still flushing, + # leaking the previous test's event into the next test. + state.client.flush() + logger.info(f"Feature flag {key} for {distinct_id}: {value}") return jsonify({"success": True, "value": value}) From 131b925b1e65d038b6730229895eb18fafd4616d Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto Date: Fri, 22 May 2026 14:01:31 +0200 Subject: [PATCH 2/2] ci: pin sdk compliance harness sha --- .github/workflows/sdk-compliance.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/sdk-compliance.yml b/.github/workflows/sdk-compliance.yml index 1c78c0eb..99a214ed 100644 --- a/.github/workflows/sdk-compliance.yml +++ b/.github/workflows/sdk-compliance.yml @@ -14,8 +14,8 @@ on: jobs: compliance: name: PostHog SDK compliance tests - uses: PostHog/posthog-sdk-test-harness/.github/workflows/test-sdk-action.yml@39d05346c4638d24f94e591ab89c9c6fcdb52d6b + uses: PostHog/posthog-sdk-test-harness/.github/workflows/test-sdk-action.yml@85e2901ea3260a28e07a83086d59b4fb4dfc814f with: adapter-dockerfile: "sdk_compliance_adapter/Dockerfile" adapter-context: "." - test-harness-version: "latest" + test-harness-version: "main-85e2901@sha256:4c8eac34e7ff66554a2c6947788c0a42b82456bc949c03bd8f6b9a10bef23ef5"