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(github): treat missing App installation token refresh as non-retryable (#63782)

Tom Owerscf59b1fde850
diff --git a/posthog/temporal/data_imports/sources/github/source.py b/posthog/temporal/data_imports/sources/github/source.py
index 31de831a076e..356f560c2996 100644
--- a/posthog/temporal/data_imports/sources/github/source.py
+++ b/posthog/temporal/data_imports/sources/github/source.py
@@ -112,6 +112,12 @@ class GithubSource(ResumableSource[GithubSourceConfig, GithubResumeConfig], OAut
# the App JWT to refresh its installation token. Deterministic — retrying never resolves it.
"GITHUB_APP_CLIENT_ID is not configured": "The GitHub App is not configured on this PostHog instance. Please contact support.",
"GITHUB_APP_PRIVATE_KEY is not configured": "The GitHub App is not configured on this PostHog instance. Please contact support.",
+ # A 404 from POST /app/installations/{id}/access_tokens means the GitHub App installation
+ # no longer exists (uninstalled or its access revoked). Retrying can never mint a token, so
+ # stop syncing until the user reconnects. Match the not-found body specifically — a bare
+ # "Failed to refresh installation token" prefix would also swallow transient 5xx/429
+ # refresh failures, which must stay retryable.
+ 'Failed to refresh installation token: {"message":"Not Found"': "Your GitHub App installation could not be found. It may have been uninstalled or had its access revoked. Please reconnect your GitHub account.",
}
def _get_access_token(self, config: GithubSourceConfig, team_id: int) -> str:
diff --git a/posthog/temporal/tests/data_imports/github/test_github_source.py b/posthog/temporal/tests/data_imports/github/test_github_source.py
index 5965150395bb..223169ed38c8 100644
--- a/posthog/temporal/tests/data_imports/github/test_github_source.py
+++ b/posthog/temporal/tests/data_imports/github/test_github_source.py
@@ -912,3 +912,30 @@ class TestGithubSourceNonRetryableErrors:
# Mirrors the substring match done in external_data_job.update_external_data_job_model.
non_retryable_errors = self.source.get_non_retryable_errors()
assert any(pattern in internal_error for pattern in non_retryable_errors)
+
+ @parameterized.expand(
+ [
+ # GitHub returns this body verbatim when the App installation no longer exists; matching it
+ # stops the pipeline from retrying a token refresh that can never succeed.
+ (
+ "not_found",
+ 'Failed to refresh installation token: {"message":"Not Found",'
+ '"documentation_url":"https://docs.github.com/rest/reference/apps'
+ '#create-an-installation-access-token-for-an-app","status":"404"}',
+ True,
+ ),
+ # A 5xx during token refresh is transient and must stay retryable, so the generic
+ # "Failed to refresh installation token" prefix must not match on its own.
+ (
+ "server_error",
+ 'Failed to refresh installation token: {"message":"Server Error","status":"500"}',
+ False,
+ ),
+ ]
+ )
+ def test_installation_token_refresh_non_retryable_matching(
+ self, _name: str, error_message: str, expected_match: bool
+ ) -> None:
+ # Mirrors the substring match done in external_data_job.update_external_data_job_model.
+ non_retryable_errors = self.source.get_non_retryable_errors()
+ assert any(pattern in error_message for pattern in non_retryable_errors) == expected_match