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 rejected access tokens as non-retryable (#130436)

Tom Owers5954e571dd41
diff --git a/products/warehouse_sources/sources/linkedin_ads/source.py b/products/warehouse_sources/sources/linkedin_ads/source.py
index 13dd576ee820..5886ec832fd3 100644
--- a/products/warehouse_sources/sources/linkedin_ads/source.py
+++ b/products/warehouse_sources/sources/linkedin_ads/source.py
@@ -136,6 +136,11 @@ class LinkedInAdsSource(ResumableSource[LinkedinAdsSourceConfig, LinkedInAdsResu
# token can't be used until LinkedIn lifts the restriction, so retrying never recovers —
# stop syncing and tell the user to resolve it with LinkedIn and re-authorize.
"RESTRICTED_MEMBER": "LinkedIn has restricted the account that authorized this integration, so PostHog can no longer access your ad data. Resolve the restriction with LinkedIn, then re-authorize the LinkedIn Ads integration.",
+ # LinkedIn returns a 401 with this stable error code when it rejects the access token
+ # itself (invalid, malformed, or simply no longer accepted) — distinct from the more
+ # specific REVOKED_ACCESS_TOKEN / RESTRICTED_MEMBER cases above. Retrying can't recover;
+ # only re-authorizing gets a usable token.
+ '"code":"AUTHENTICATION_FAILED"': "LinkedIn rejected the credentials for this integration. Please re-authorize the LinkedIn Ads integration.",
# The Account ID is a free-text field. A malformed value (a profile URL, a name, stray
# whitespace) makes LinkedIn reject the `urn:li:sponsoredAccount:<id>` accounts param with
# a deterministic 400 ("...is invalid. Reason: Deserializing output ... failed"). Retrying
diff --git a/products/warehouse_sources/sources/linkedin_ads/tests/test_linkedin_source.py b/products/warehouse_sources/sources/linkedin_ads/tests/test_linkedin_source.py
index 86158a0adb84..759c0573d3bd 100644
--- a/products/warehouse_sources/sources/linkedin_ads/tests/test_linkedin_source.py
+++ b/products/warehouse_sources/sources/linkedin_ads/tests/test_linkedin_source.py
@@ -45,6 +45,9 @@ class TestLinkedInAdsSource:
"The token used in the request has expired",
"Failed to refresh token for LinkedIn Ads integration. Please re-authorize the integration.",
'LinkedIn API error (401): {"status":401,"serviceErrorCode":65608,"code":"RESTRICTED_MEMBER","message":"Member is restricted"}',
+ # A rejected access token (invalid, malformed, or no longer accepted) — distinct from
+ # REVOKED_ACCESS_TOKEN and RESTRICTED_MEMBER above.
+ 'LinkedIn API error (401): {"status":401,"code":"AUTHENTICATION_FAILED","message":"Could not authenticate"}',
# Integration.DoesNotExist when the OAuth integration row was deleted/disconnected.
"Integration matching query does not exist.",
# A sunset version header (see `deprecated_versions`) — happens on every call under that