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(linkedin_ads): treat generic LinkedIn 404 as non-retryable (#110435)

Tom Owers219356017ea5
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/linkedin_ads/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/linkedin_ads/source.py
index 04886da894a9..a3fe688d0e0e 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/linkedin_ads/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/linkedin_ads/source.py
@@ -124,6 +124,11 @@ class LinkedInAdsSource(ResumableSource[LinkedinAdsSourceConfig, LinkedInAdsResu
# resource can't be resolved — typically a deleted account, a wrong Account ID, or lost
# access. Retrying can't recover it, so stop syncing instead of looping the 404.
"RESOURCE_NOT_FOUND": "LinkedIn could not find the requested ad account. It may have been deleted, the configured Account ID may be wrong, or PostHog may have lost access. Check the Account ID and re-authorize the LinkedIn Ads integration.",
+ # LinkedIn returns a plain 404 with this generic error code (no "RESOURCE_" prefix) for
+ # the same underlying condition — a deleted account, a wrong Account ID, or lost access
+ # to it. Match the quoted JSON key/value so this never also matches "RESOURCE_NOT_FOUND"
+ # above, which carries a more specific message.
+ '"code":"NOT_FOUND"': "LinkedIn could not find the requested ad account. It may have been deleted, the configured Account ID may be wrong, or PostHog may have lost access. Check the Account ID and re-authorize the LinkedIn Ads integration.",
# LinkedIn returns a 401 with this stable error code when the member who authorized the
# integration has been restricted on LinkedIn's side (suspended / flagged account). The
# token can't be used until LinkedIn lifts the restriction, so retrying never recovers —
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/linkedin_ads/tests/test_linkedin_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/linkedin_ads/tests/test_linkedin_source.py
index 315a9b6430d0..99e2bbcbadc0 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/linkedin_ads/tests/test_linkedin_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/linkedin_ads/tests/test_linkedin_source.py
@@ -33,6 +33,10 @@ class TestLinkedInAdsSource:
"observed_error",
[
'LinkedIn API error (404): {"status":404,"code":"RESOURCE_NOT_FOUND","message":"No virtual resource found"}',
+ # A plain 404 with the generic "NOT_FOUND" code (no "RESOURCE_" prefix) — same
+ # underlying condition (deleted/inaccessible account) under a different LinkedIn
+ # error code.
+ 'LinkedIn API error (404): {"code":"NOT_FOUND","message":"Not Found.","status":404}',
"REVOKED_ACCESS_TOKEN",
"The token used in the request has expired",
"Failed to refresh token for LinkedIn Ads integration. Please re-authorize the integration.",