: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): accept the new claude startup failure reasons (#126188)
Alessandro Pogliaghi1b5c0e1abf81
diff --git a/products/signals/backend/startup_failure.py b/products/signals/backend/startup_failure.pyindex 0936f1186082..6a7769146d0a 100644--- a/products/signals/backend/startup_failure.py+++ b/products/signals/backend/startup_failure.py@@ -70,6 +70,9 @@ def startup_failure_message(failure: AgentStartupFailure) -> str:"org_pin_mismatch": "The agent's organization settings do not match its credentials.","cli_version_too_old": "The agent requires a newer provider runtime.","bypass_root": "The provider rejected the agent's permission configuration.",+ "sandbox_required_unavailable": "The repository's Claude Code settings require a sandbox that is not available in this environment.",+ "provider_not_allowed": "The agent's managed settings do not allow the configured provider.",+ "org_config_refused": "The provider refused the organization's configuration for this sign-in.",}explanation = explanations.get(failure.reason or "") if failure.provider == "claude" else Noneif explanation and failure.retryability == "requires_action":diff --git a/products/tasks/backend/facade/contracts.py b/products/tasks/backend/facade/contracts.pyindex d1e7bb920263..4af282628272 100644--- a/products/tasks/backend/facade/contracts.py+++ b/products/tasks/backend/facade/contracts.py@@ -99,6 +99,10 @@ class AgentStartupFailure:"worktree_unverified","cli_version_too_old","bypass_root",+ "sandbox_required_unavailable",+ "provider_not_allowed",+ "org_config_required_unavailable",+ "org_config_refused",]| None)diff --git a/products/tasks/backend/logic/services/startup_failure.py b/products/tasks/backend/logic/services/startup_failure.pyindex 8ca5e083147e..d697790c325e 100644--- a/products/tasks/backend/logic/services/startup_failure.py+++ b/products/tasks/backend/logic/services/startup_failure.py@@ -20,18 +20,34 @@ _ACTION_REQUIRED_MESSAGES = {"shell_tool_missing": "A shell required by the agent is unavailable. Update the sandbox image to include a supported shell, then retry.","cli_version_too_old": "The agent's provider runtime is too old. Update the provider runtime in the sandbox image, then retry.","bypass_root": "The provider rejected the agent's permission configuration. Run the agent as a non-root user or update its permission settings, then retry.",+ "sandbox_required_unavailable": "The repository's Claude Code settings require a sandbox that is not available in this environment. Remove the sandbox requirement from the repository settings, then retry.",+ "provider_not_allowed": "The agent's managed settings do not allow the configured provider. Use an allowed provider, then retry.",+ "org_config_refused": "The provider refused the organization's configuration for this sign-in. Sign in again or ask an organization admin to restore access, then retry.",}_ACTION_REQUIRED_REASONS = frozenset({"credential_unavailable", *_ACTION_REQUIRED_MESSAGES})_TRANSIENT_REASONS = frozenset({"credential_service_unavailable", "session_held_by_background", "worktree_unverified"})-def read_startup_failure(state: Mapping[str, object] | None) -> AgentStartupFailure | None:+def _validate_startup_failure(value: object) -> AgentStartupFailure | None:+ try:+ return _startup_failure_adapter.validate_python(value)+ except ValidationError:+ pass+ if not isinstance(value, Mapping):+ return None+ reason = value.get("reason")+ if not isinstance(reason, str) or not reason:+ return Nonetry:- return _startup_failure_adapter.validate_python((state or {}).get("startup_failure"))+ return _startup_failure_adapter.validate_python({**value, "reason": None})except ValidationError:return None+def read_startup_failure(state: Mapping[str, object] | None) -> AgentStartupFailure | None:+ return _validate_startup_failure((state or {}).get("startup_failure"))++class AgentServerStartupError(SandboxExecutionError):def __init__(self, failure: AgentStartupFailure, run_id: str, sandbox_id: str) -> None:self.startup_failure = failure@@ -57,9 +73,8 @@ def raise_startup_failure(stdout: str, sandbox_id: str) -> None:run_id = payload.get("runId")if not isinstance(run_id, str) or not run_id:continue- try:- failure = _startup_failure_adapter.validate_python(payload.get("startupFailure"))- except ValidationError:+ failure = _validate_startup_failure(payload.get("startupFailure"))+ if failure is None:continuereason = (failure.reasondiff --git a/products/tasks/backend/logic/services/tests/test_sandbox_health_check.py b/products/tasks/backend/logic/services/tests/test_sandbox_health_check.pyindex dedaed627730..c6f6009b7cc0 100644--- a/products/tasks/backend/logic/services/tests/test_sandbox_health_check.py+++ b/products/tasks/backend/logic/services/tests/test_sandbox_health_check.py@@ -193,16 +193,18 @@ def test_preflight_reports_only_the_capabilities_the_binary_carries(@pytest.mark.parametrize(- ("provider", "reason", "reported_retryability", "expected_retryability"),+ ("provider", "reason", "reported_retryability", "expected_reason", "expected_retryability"),[- ("claude", "proxy_invalid", "unknown", "requires_action"),- ("claude", "worktree_unverified", "requires_action", "transient"),- ("claude", None, "requires_action", "unknown"),- ("codex", "credential_service_unavailable", "requires_action", "transient"),+ ("claude", "proxy_invalid", "unknown", "proxy_invalid", "requires_action"),+ ("claude", "sandbox_required_unavailable", "unknown", "sandbox_required_unavailable", "requires_action"),+ ("claude", "worktree_unverified", "requires_action", "worktree_unverified", "transient"),+ ("claude", None, "requires_action", None, "unknown"),+ ("claude", "arbitrary-reason", "requires_action", None, "unknown"),+ ("codex", "credential_service_unavailable", "requires_action", "credential_service_unavailable", "transient"),],)def test_health_check_carries_validated_startup_failure(- tmp_path: Path, provider, reason, reported_retryability, expected_retryability+ tmp_path: Path, provider, reason, reported_retryability, expected_reason, expected_retryability) -> None:payload = {"status": "ok",@@ -227,7 +229,7 @@ def test_health_check_carries_validated_startup_failure(with pytest.raises(AgentServerStartupError) as raised:raise_startup_failure(result.stdout, "example-sandbox")assert raised.value.run_id == "example-run"- assert raised.value.startup_failure.reason == reason+ assert raised.value.startup_failure.reason == expected_reasonassert raised.value.startup_failure.retryability == expected_retryability@@ -237,14 +239,6 @@ def test_health_check_carries_validated_startup_failure({"runId": None},{"hasSession": True},{"readiness": "ready"},- {- "startupFailure": {- "provider": "claude",- "phase": "sdk_initialization",- "reason": "arbitrary-reason",- "retryability": "requires_action",- }- },],)def test_health_check_ignores_unconfirmed_startup_failures(change) -> None: