:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(aio): map cancelled Gemini calls to ProviderConnectionError (#102831)
posthog[bot]872258a2c7a7
diff --git a/products/ai_observability/backend/llm/providers/gemini.py b/products/ai_observability/backend/llm/providers/gemini.pyindex cf6649524d7d..c8b941208ebc 100644--- a/products/ai_observability/backend/llm/providers/gemini.py+++ b/products/ai_observability/backend/llm/providers/gemini.py@@ -167,6 +167,11 @@ class GeminiAdapter:# gracefully instead of burning Temporal retries on an unhandled exception.if status_code == 404 or "no longer available" in error_message or "not found" in error_message:return ModelNotFoundError(model)+ # Google cancels a call with a 499/CANCELLED error. The retry policy already covers it,+ # but the message differs per occurrence, so an unmapped one files a new error tracking+ # issue every time. Share the transport lane, which the caller retries quietly.+ if status_code == 499 or "cancelled" in error_message or "canceled" in error_message:+ return ProviderConnectionError(str(error))return Noneif isinstance(error, httpx.TransportError):# google-genai doesn't wrap httpx transport failures (connection reset, read timeout)diff --git a/products/ai_observability/backend/llm/providers/test/test_gemini_adapter.py b/products/ai_observability/backend/llm/providers/test/test_gemini_adapter.pyindex 13b6df24fc8a..d6861dee16fe 100644--- a/products/ai_observability/backend/llm/providers/test/test_gemini_adapter.py+++ b/products/ai_observability/backend/llm/providers/test/test_gemini_adapter.py@@ -40,6 +40,10 @@ class TestGeminiAdapterErrorMapping:("403_permission", 403, "PERMISSION_DENIED", "permission denied", ModelPermissionError),("401_auth", 401, "UNAUTHENTICATED", "invalid api key", AuthenticationError),("429_rate_limit", 429, "RESOURCE_EXHAUSTED", "rate limit exceeded", RateLimitError),+ # A cancelled call is retryable, so it shares the transport lane. Without this the+ # per-occurrence message files a new error tracking issue on every cancellation.+ ("499_cancelled", 499, "CANCELLED", "The operation was cancelled.", ProviderConnectionError),+ ("cancelled_message", 400, "UNKNOWN", "The operation was cancelled.", ProviderConnectionError),])def test_api_error_is_mapped_to_llm_error(