Skip to content

: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.

fix(openai_ads): stop reporting body-flagged server errors as bugs (#82838)

Tom Owers5fec2660857a
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.py
index 089bd6391960..979870962e7a 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
@@ -95,6 +95,12 @@ Create an API key in the Settings tab of [OpenAI Ads Manager](https://ads.openai
return {
f"for {OPENAI_ADS_BASE_URL}",
f"from {OPENAI_ADS_BASE_URL}",
+ # A 400 response whose body labels itself `code=server_error` (appended by
+ # `_error_identity` in rest_client.py) is a backend blip on OpenAI's side reported
+ # through an unusual status code — 400s fall outside the 429/5xx range this client
+ # retries in-process, so the body is the only transience signal available. Trust it,
+ # the same way Meta Ads trusts its own documented error codes over raw HTTP status.
+ "code=server_error",
}
def get_schemas(
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.py
index 8308ace59aef..0e81c60f32b3 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
@@ -146,6 +146,10 @@ class TestRetryableErrors:
"malformed_json",
"Malformed JSON response from https://api.ads.openai.com/v1/campaigns: Expecting value: line 1 column 1 (char 0)",
),
+ (
+ "body_reported_server_error",
+ "400 Client Error: Bad Request for url: https://api.ads.openai.com/v1/ads?ad_group_id=adgrp_123&limit=500&order=asc | api error: code=server_error",
+ ),
]
)
def test_exhausted_transient_failures_are_recognized(self, _name: str, observed_error: str) -> None:
@@ -162,6 +166,10 @@ class TestRetryableErrors:
"not_found",
"404 Client Error: Not Found for url: https://api.ads.openai.com/v1/campaigns/123",
),
+ (
+ "genuine_bad_request",
+ "400 Client Error: Bad Request for url: https://api.ads.openai.com/v1/campaigns | api error: code=invalid_request_error",
+ ),
]
)
def test_credential_and_client_errors_are_not_misclassified(self, _name: str, other_error: str) -> None: