: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): skip error-tracking capture on transient agent-server health-check timeouts (#68163)
posthog[bot]788200d3c9dc
diff --git a/products/tasks/backend/logic/services/docker_sandbox.py b/products/tasks/backend/logic/services/docker_sandbox.pyindex 4ebb3287a483..38c1889ba54f 100644--- a/products/tasks/backend/logic/services/docker_sandbox.py+++ b/products/tasks/backend/logic/services/docker_sandbox.py@@ -911,10 +911,12 @@ class DockerSandbox(SandboxBase):log_result = self.execute("cat /tmp/agent-server.log 2>/dev/null || echo 'No log file'", timeout_seconds=5)logger.warning(f"Agent-server health check failed for sandbox {self.id}. Log output:\n{log_result.stdout}")+ # Transient timeout Temporal retries — skip error-tracking capture to avoid noisy issues.raise SandboxExecutionError("Agent-server failed to start",{"sandbox_id": self.id, "log": log_result.stdout},cause=RuntimeError("Health check failed after retries"),+ capture=False,)def wait_for_agent_server_ready(self, allowed_domains: list[str] | None = None) -> None:@@ -923,10 +925,12 @@ class DockerSandbox(SandboxBase):returnlog_result = self.execute("cat /tmp/agent-server.log 2>/dev/null || echo 'No log file'", timeout_seconds=5)logger.warning(f"Agent-server health check failed for sandbox {self.id}. Log output:\n{log_result.stdout}")+ # Transient timeout Temporal retries — skip error-tracking capture to avoid noisy issues.raise SandboxExecutionError("Agent-server failed to start",{"sandbox_id": self.id, "log": log_result.stdout},cause=RuntimeError("Health check failed after retries"),+ capture=False,)def mark_repo_ready(self, repo_ready_file: str) -> None:diff --git a/products/tasks/backend/logic/services/tests/test_docker_sandbox.py b/products/tasks/backend/logic/services/tests/test_docker_sandbox.pynew file mode 100644index 000000000000..4c4bcd5f9615--- /dev/null+++ b/products/tasks/backend/logic/services/tests/test_docker_sandbox.py@@ -0,0 +1,62 @@+import pytest+from unittest.mock import patch++from products.tasks.backend.exceptions import SandboxExecutionError+from products.tasks.backend.logic.services.docker_sandbox import DockerSandbox+from products.tasks.backend.logic.services.sandbox import ExecutionResult, SandboxConfig+++def sandbox() -> DockerSandbox:+ config = SandboxConfig(name="test-sandbox")+ return DockerSandbox(container_id="c" * 64, config=config, host_port=8000)+++def _log_result() -> ExecutionResult:+ return ExecutionResult(stdout="agent-server log", stderr="", exit_code=0)+++def test_wait_for_agent_server_ready_timeout_is_retryable_and_not_captured(sandbox: DockerSandbox):+ with (+ patch.object(sandbox, "_wait_for_health_check", return_value=False),+ patch.object(sandbox, "execute", return_value=_log_result()),+ patch("products.tasks.backend.exceptions.capture_exception") as capture_exception,+ pytest.raises(SandboxExecutionError) as exc,+ ):+ sandbox.wait_for_agent_server_ready()++ # Transient health-check timeout Temporal retries — retryable, and no error-tracking issue.+ assert exc.value.non_retryable is False+ capture_exception.assert_not_called()+++def test_start_agent_server_health_check_timeout_is_retryable_and_not_captured(sandbox: DockerSandbox):+ with (+ patch.object(sandbox, "is_running", return_value=True),+ patch.object(sandbox, "write_file"),+ patch.object(sandbox, "_build_agent_server_command", return_value="run-agent-server"),+ patch.object(sandbox, "_launch_and_check", return_value=False),+ patch.object(sandbox, "execute", return_value=_log_result()),+ patch("products.tasks.backend.exceptions.capture_exception") as capture_exception,+ pytest.raises(SandboxExecutionError) as exc,+ ):+ sandbox.start_agent_server(repository=None, task_id="t1", run_id="r1")++ assert exc.value.non_retryable is False+ capture_exception.assert_not_called()+++def test_start_agent_server_launch_failure_is_captured(sandbox: DockerSandbox):+ failed = ExecutionResult(stdout="", stderr="boom", exit_code=1)+ with (+ patch.object(sandbox, "is_running", return_value=True),+ patch.object(sandbox, "write_file"),+ patch.object(sandbox, "_build_agent_server_command", return_value="run-agent-server"),+ patch.object(sandbox, "execute", return_value=failed),+ patch("products.tasks.backend.exceptions.capture_exception") as capture_exception,+ pytest.raises(SandboxExecutionError),+ ):+ sandbox.start_agent_server(repository=None, task_id="t1", run_id="r1", wait_for_health=False)++ # A genuine non-zero launch is a real fault — it still gets captured.+ capture_exception.assert_called_once()