: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(tasks): preserve expected GitHub credential failures (#119514)
Alessandro Pogliaghi643ac2a5fdf3
diff --git a/docs/internal/task-run-api.md b/docs/internal/task-run-api.mdindex 51db287a385c..46c7b6030e83 100644--- a/docs/internal/task-run-api.md+++ b/docs/internal/task-run-api.md@@ -53,6 +53,8 @@ The `state` field must be a JSON object.Run responses omit internal cost accounting, including gateway request IDs.+GitHub credentials that require user action fail the run without retrying. Fresh runs and resumed sandboxes preserve the actionable error, and Temporal does not report these expected failures to error tracking.+## Model selectionTask runs accept `gpt-6.1-sol` with the `codex` runtime adapter and `low`, `medium`, `high`, `xhigh`, or `max` reasoning effort.diff --git a/products/tasks/backend/exceptions.py b/products/tasks/backend/exceptions.pyindex e4a9915e4cc4..e05411e34b89 100644--- a/products/tasks/backend/exceptions.py+++ b/products/tasks/backend/exceptions.py@@ -6,6 +6,7 @@ from temporalio import activityfrom temporalio.exceptions import ApplicationErrorfrom posthog.exceptions_capture import capture_exception+from posthog.temporal.common.errors import NonReportableErrorfrom products.tasks.backend.facade.compute_quota import ComputeBillingLimitExceeded@@ -283,7 +284,7 @@ class GitHubAuthenticationError(ProcessTaskFatalError):pass-class CredentialUnavailableError(ProcessTaskFatalError):+class CredentialUnavailableError(ProcessTaskFatalError, NonReportableError):"""A sandbox credential can never be resolved again for this run — the backingintegration row was deleted mid-run or the user must re-authorize.diff --git a/products/tasks/backend/temporal/process_task/activities/provision_sandbox.py b/products/tasks/backend/temporal/process_task/activities/provision_sandbox.pyindex e08f45ee5a49..63b093960558 100644--- a/products/tasks/backend/temporal/process_task/activities/provision_sandbox.py+++ b/products/tasks/backend/temporal/process_task/activities/provision_sandbox.py@@ -407,6 +407,8 @@ def _repository_snapshot_integration_id(ctx: TaskProcessingContext, *, has_repo:def _github_token_error(error: Exception, message: str, context: dict[str, Any]) -> ProcessTaskError:+ if isinstance(error, CredentialUnavailableError):+ return errorif isinstance(error, GitHubRateLimitError | GitHubEgressBudgetExhausted):retry_after = getattr(error, "retry_after", None) or DEFAULT_GITHUB_RATE_LIMIT_BACKOFF_SECONDSreturn GitHubRateLimitedError(f"{message}; retrying in {retry_after}s", context, retry_after=retry_after)diff --git a/products/tasks/backend/tests/test_exceptions.py b/products/tasks/backend/tests/test_exceptions.pyindex 2bc89bb82ba9..1159bf2a78b0 100644--- a/products/tasks/backend/tests/test_exceptions.py+++ b/products/tasks/backend/tests/test_exceptions.py@@ -9,6 +9,7 @@ from temporalio.testing import ActivityEnvironmentfrom posthog.temporal.common.posthog_client import is_expected_activity_failurefrom products.tasks.backend.exceptions import (+ CredentialUnavailableError,SandboxControlPlaneUnavailableError,SandboxNotRunningError,SandboxRateLimitedError,@@ -26,8 +27,15 @@ def test_temporal_failure_type_defaults_to_class_name():assert not error.non_retryable[email protected]("error", [SandboxRateLimitedError("x", {}), SandboxControlPlaneUnavailableError("x", {})])-def test_control_plane_errors_are_expected_activity_failures(error: Exception):+ "error",+ [+ SandboxRateLimitedError("x", {}),+ SandboxControlPlaneUnavailableError("x", {}),+ CredentialUnavailableError("x", {}),+ ],+)+def test_expected_errors_are_not_reported_by_the_activity_interceptor(error: Exception) -> None:assert is_expected_activity_failure(error) is Truediff --git a/products/tasks/backend/tests/test_sandbox_utils.py b/products/tasks/backend/tests/test_sandbox_utils.pyindex 5f585cefc8a9..d624e04454e5 100644--- a/products/tasks/backend/tests/test_sandbox_utils.py+++ b/products/tasks/backend/tests/test_sandbox_utils.py@@ -5,6 +5,7 @@ from django.test import override_settingsimport requestsfrom parameterized import parameterized+from temporalio.testing import ActivityEnvironmentfrom posthog.egress.github.transport import GitHubRateLimitErrorfrom posthog.models.github_integration_base import GitHubIntegrationError@@ -221,28 +222,39 @@ def test_repo_less_report_run_follows_the_integration_the_create_path_attached(assert token == expected[email protected]("resume", [False, True])@pytest.mark.parametrize("error, expected_error",[(ReauthorizationRequired("relink GitHub"), CredentialUnavailableError),+ (CredentialUnavailableError("missing repository", {"repositories": ["acme/repo"]}), CredentialUnavailableError),(GitHubRateLimitError("limited", retry_after=30), GitHubRateLimitedError),(requests.ConnectionError("reset"), ProcessTaskTransientError),(GitHubIntegrationError("bad gateway", status_code=502), ProcessTaskTransientError),(GitHubIntegrationError("not accessible", status_code=422), GitHubAuthenticationError),],- ids=["reauthorization", "rate_limited", "connection_error", "server_error", "rejected_mint"],+ ids=[+ "reauthorization",+ "unavailable_credential",+ "rate_limited",+ "connection_error",+ "server_error",+ "rejected_mint",+ ],)@patch("products.tasks.backend.temporal.process_task.activities.provision_sandbox.emit_agent_log")@patch("products.tasks.backend.temporal.process_task.activities.provision_sandbox.get_sandbox_github_token")-def test_github_token_failure_maps_to_run_error(- mock_full: MagicMock, _mock_log: MagicMock, error: Exception, expected_error: type[Exception]+async def test_github_token_failure_maps_to_run_error(+ mock_full: MagicMock, _mock_log: MagicMock, error: Exception, expected_error: type[Exception], resume: bool) -> None:# ReauthorizationRequired is a user-actionable "re-link your GitHub account" signal, not a# system fault. Provisioning must surface it as CredentialUnavailableError (fatal, non-retryable,# not captured to error tracking) rather than wrapping it in GitHubAuthenticationError, which# captures the raw exception and floods error tracking with noise.from products.tasks.backend.temporal.process_task.activities.provision_sandbox import ( # noqa: PLC0415 — activities import the workflow stack; keep it off this module's import path+ InjectFreshTokensOnResumeInput,_resolve_sandbox_github_token,+ inject_fresh_tokens_on_resume,)mock_full.side_effect = error@@ -258,9 +270,21 @@ def test_github_token_failure_maps_to_run_error(state={},)- with pytest.raises(expected_error) as raised:- _resolve_sandbox_github_token(ctx, task=MagicMock(), actor_user=None, repository="acme/repo", has_repo=True)+ with (+ patch("products.tasks.backend.temporal.process_task.activities.provision_sandbox._load_task"),+ patch("products.tasks.backend.temporal.process_task.activities.provision_sandbox.get_task_run_credential_user"),+ pytest.raises(expected_error) as raised,+ ):+ if resume:+ await ActivityEnvironment().run(+ inject_fresh_tokens_on_resume,+ InjectFreshTokensOnResumeInput(context=ctx, sandbox_id="sandbox-id", repository="acme/repo"),+ )+ else:+ _resolve_sandbox_github_token(ctx, task=MagicMock(), actor_user=None, repository="acme/repo", has_repo=True)assert type(raised.value) is expected_error+ if isinstance(error, CredentialUnavailableError):+ assert raised.value is error@pytest.mark.parametrize(