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(bing_ads): give report generation a realistic deadline (#96292)

Tom Owers9bddeef71d92
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/bing_ads/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/bing_ads/source.py
index 9dd2f1b8b3b1..79a79f4fa4a7 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/bing_ads/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/bing_ads/source.py
@@ -150,14 +150,21 @@ class BingAdsSource(ResumableSource[BingAdsSourceConfig, BingAdsResumeConfig], O
}
def get_retryable_errors(self) -> set[str]:
- # A Bing SOAP call that comes back with a bare HTTP 400 (no SOAP fault) is rejected at the
- # transport/edge layer, not by request validation — suds surfaces it as `Exception((400,
- # 'Bad Request'))`, which our wrapper re-raises as `ValueError(... Exception: (400, 'Bad
- # Request'))`. A genuinely malformed report request instead returns a coded WebFault
- # (InvalidReportColumn, etc.), so this shape is a transient upstream blip that Temporal's
- # activity retry clears — keep it out of error tracking as noise rather than paging as a bug.
- # Match the stable status tuple only; a fault-backed 400 never produces this substring.
- return {"(400, 'Bad Request')"}
+ return {
+ # A Bing SOAP call that comes back with a bare HTTP 400 (no SOAP fault) is rejected at the
+ # transport/edge layer, not by request validation — suds surfaces it as `Exception((400,
+ # 'Bad Request'))`, which our wrapper re-raises as `ValueError(... Exception: (400, 'Bad
+ # Request'))`. A genuinely malformed report request instead returns a coded WebFault
+ # (InvalidReportColumn, etc.), so this shape is a transient upstream blip that Temporal's
+ # activity retry clears — keep it out of error tracking as noise rather than paging as a bug.
+ # Match the stable status tuple only; a fault-backed 400 never produces this substring.
+ "(400, 'Bad Request')",
+ # Bing did not finish building the report before the SDK exhausted its own polling window
+ # (REPORT_TIMEOUT_MS), which it reports as `ReportingDownloadException`. Generation runs on
+ # Bing's queue, so the next Temporal attempt submits a fresh request and normally clears it.
+ # Match the SDK's stable message text, which carries no request or account values.
+ "Reporting file download tracking status timeout",
+ }
@property
def get_source_config(self) -> SourceConfig:
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/bing_ads/tests/test_bing_ads_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/bing_ads/tests/test_bing_ads_source.py
index ed01f561a3be..e967dfeaa4b2 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/bing_ads/tests/test_bing_ads_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/bing_ads/tests/test_bing_ads_source.py
@@ -364,12 +364,20 @@ class TestBingAdsSource:
assert not any(pattern in transient_message for pattern in non_retryable_errors)
- def test_transient_bad_request_is_retryable_not_disabling(self):
- # A bare transport-level HTTP 400 on a Bing SOAP call (no coded WebFault) is a transient edge
- # rejection: it must be recognised as retryable (kept out of error tracking) and must NOT match
- # any non-retryable pattern, or a transient blip would disable the schema.
- error_message = "Failed to generate ad_performance_report report: Exception: (400, 'Bad Request')"
-
+ @pytest.mark.parametrize(
+ "error_message",
+ [
+ # A bare transport-level HTTP 400 on a Bing SOAP call (no coded WebFault) is a transient edge
+ # rejection: it must be recognised as retryable (kept out of error tracking) and must NOT match
+ # any non-retryable pattern, or a transient blip would disable the schema.
+ "Failed to generate ad_performance_report report: Exception: (400, 'Bad Request')",
+ # Bing did not finish building the report inside the SDK's polling window. The next attempt
+ # submits a fresh report request, so this must stay retryable rather than disable the schema.
+ "Failed to generate ad_group_performance_report report: ReportingDownloadException: "
+ "Reporting file download tracking status timeout.",
+ ],
+ )
+ def test_transient_failures_are_retryable_not_disabling(self, error_message):
# Assert through the same case-insensitive matcher production classification uses.
assert error_message_matches(error_message, self.source.get_retryable_errors())
assert not error_message_matches(error_message, self.source.get_non_retryable_errors())
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/bing_ads/utils.py b/products/warehouse_sources/backend/temporal/data_imports/sources/bing_ads/utils.py
index 0b16deacb7ad..003f5f6702e6 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/bing_ads/utils.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/bing_ads/utils.py
@@ -34,7 +34,10 @@ class BingAdsResumeConfig:
ENVIRONMENT = "production"
REPORT_POLL_INTERVAL_MS = 5000
-REPORT_TIMEOUT_MS = 360000
+# Bing builds the report on its own queue, and Microsoft documents generation as taking minutes to
+# hours for a large request. A retry re-queues the report from scratch, so a deadline below that
+# window never converges for an account whose reports are slow to build.
+REPORT_TIMEOUT_MS = 1_800_000
def parse_csv_to_dicts(csv_data: str) -> list[dict[str, Any]]: