: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(openai_ads): classify exhausted retryable errors as retryable noise (#73680)
Tom Owersed406d7334b0
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/openai_ads/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/openai_ads/source.pyindex 6ac0efd1c4f9..9df4e8067265 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/openai_ads/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/openai_ads/source.py@@ -31,6 +31,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.openai_adsfrom products.warehouse_sources.backend.temporal.data_imports.sources.openai_ads.settings import (ENDPOINTS,INCREMENTAL_FIELDS,+ OPENAI_ADS_BASE_URL,OPENAI_ADS_ENDPOINTS,)from products.warehouse_sources.backend.types import ExternalDataSourceType@@ -86,6 +87,19 @@ Create an API key in the Settings tab of [OpenAI Ads Manager](https://ads.openai"403 Client Error: Forbidden for url: https://api.ads.openai.com": "Your OpenAI Ads API key does not have access to this ad account. Create a key for this ad account in the Settings tab of OpenAI Ads Manager, then reconnect.",}+ def get_retryable_errors(self) -> set[str]:+ # The shared RESTClient (rest_client.py) already retries 429/5xx responses, connection+ # resets, timeouts, and malformed-JSON bodies in-process via tenacity (5 attempts,+ # exponential backoff honoring Retry-After) before re-raising RESTClientRetryableError.+ # A failure that survives all 5 attempts is a transient OpenAI Ads / edge blip, not a bug —+ # Temporal's activity retry recovers once the upstream issue clears, so keep it out of+ # error tracking as noise. The status code and path vary per request; the API host doesn't,+ # so match on that rather than the volatile parts of the message.+ return {+ f"for {OPENAI_ADS_BASE_URL}",+ f"from {OPENAI_ADS_BASE_URL}",+ }+def get_schemas(self,config: OpenAIAdsSourceConfig,diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/openai_ads/tests/test_openai_ads_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/openai_ads/tests/test_openai_ads_source.pyindex 636a32cbdac3..8308ace59aef 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/openai_ads/tests/test_openai_ads_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/openai_ads/tests/test_openai_ads_source.py@@ -129,6 +129,46 @@ class TestNonRetryableErrors:assert not any(key in other_error for key in non_retryable)+class TestRetryableErrors:+ @parameterized.expand(+ [+ ("server_error", "HTTP 500 for https://api.ads.openai.com/v1/campaigns"),+ ("rate_limited", "HTTP 429 for https://api.ads.openai.com/v1/ad_account/insights"),+ (+ "connection_error",+ "Connection error (ConnectionError) for https://api.ads.openai.com/v1/ad_groups",+ ),+ (+ "timeout",+ "Request timed out (ReadTimeout) for https://api.ads.openai.com/v1/ads",+ ),+ (+ "malformed_json",+ "Malformed JSON response from https://api.ads.openai.com/v1/campaigns: Expecting value: line 1 column 1 (char 0)",+ ),+ ]+ )+ def test_exhausted_transient_failures_are_recognized(self, _name: str, observed_error: str) -> None:+ retryable = OpenAIAdsSource().get_retryable_errors()+ assert any(pattern in observed_error for pattern in retryable)++ @parameterized.expand(+ [+ (+ "unauthorized",+ "401 Client Error: Unauthorized for url: https://api.ads.openai.com/v1/campaigns",+ ),+ (+ "not_found",+ "404 Client Error: Not Found for url: https://api.ads.openai.com/v1/campaigns/123",+ ),+ ]+ )+ def test_credential_and_client_errors_are_not_misclassified(self, _name: str, other_error: str) -> None:+ retryable = OpenAIAdsSource().get_retryable_errors()+ assert not any(pattern in other_error for pattern in retryable)++class TestDocumentedTables:def test_canonical_descriptions_cover_every_endpoint(self) -> None:# The docs' Supported tables section keys canonical entries by endpoint name — a drifted