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(tasks): make subscription billing answerable from the API, not just Desktop (#107814)

Tom Owersce9c22cf42ec
diff --git a/products/tasks/backend/logic/services/agent_server_launcher.py b/products/tasks/backend/logic/services/agent_server_launcher.py
index d24476a2d046..10c8fec1cbb6 100644
--- a/products/tasks/backend/logic/services/agent_server_launcher.py
+++ b/products/tasks/backend/logic/services/agent_server_launcher.py
@@ -39,6 +39,7 @@ from products.tasks.backend.logic.services.agentsh import (
)
from products.tasks.backend.logic.services.mcp_url import resolve_mcp_url
from products.tasks.backend.logic.services.sandbox import (
+ CLAUDE_CREDENTIAL_UNAVAILABLE_MESSAGE,
CODEX_CREDENTIAL_UNAVAILABLE_MESSAGE,
WORKING_DIR,
SandboxBase,
@@ -542,7 +543,7 @@ class AgentServerLaunchMixin(SandboxBase):
)
if result.exit_code == AGENT_SERVER_PREFLIGHT_CREDENTIAL_EXIT_CODE:
raise ProcessTaskFatalError(
- "The Claude token did not arrive. Open Desktop and check your token in Settings > Harness. Then start the task again.",
+ CLAUDE_CREDENTIAL_UNAVAILABLE_MESSAGE,
{"sandbox_id": self.id},
RuntimeError("Claude token unavailable"),
capture=False,
@@ -802,7 +803,7 @@ class AgentServerLaunchMixin(SandboxBase):
marker = _credential_marker(*sources)
if marker == CLAUDE_CREDENTIAL_UNAVAILABLE_MARKER:
return ProcessTaskFatalError(
- "The Claude token did not arrive. Open Desktop and check your token in Settings > Harness. Then start the task again.",
+ CLAUDE_CREDENTIAL_UNAVAILABLE_MESSAGE,
context,
RuntimeError("Claude token unavailable"),
capture=False,
diff --git a/products/tasks/backend/logic/services/sandbox.py b/products/tasks/backend/logic/services/sandbox.py
index 04c9a29d7584..47aafc03fd30 100644
--- a/products/tasks/backend/logic/services/sandbox.py
+++ b/products/tasks/backend/logic/services/sandbox.py
@@ -839,6 +839,16 @@ CODEX_CREDENTIAL_UNAVAILABLE_MESSAGE = (
"If it keeps failing, connect your ChatGPT account again in Settings > Harness."
)
+# Named for the same reason as the Codex message above, and worded for whoever is actually
+# listening. PostHog Desktop is no longer the only client that can answer a credential
+# request — an API caller relays the token itself — so telling everyone to "open Desktop"
+# leaves those callers with no way to act on the one error that ends their run.
+CLAUDE_CREDENTIAL_UNAVAILABLE_MESSAGE = (
+ "The Claude token did not arrive. Whoever started this run has to answer its "
+ "credential_request within 120 seconds: PostHog Desktop answers from Settings > Harness, "
+ "and an API caller relays the token to the run's command endpoint. Then start the task again."
+)
+
# The agent-server option each adapter's own-subscription runs need. The launcher greps the
# binary for it before it starts a run, so both uses read the same name.
SUBSCRIPTION_CLI_FLAGS = {"claude": "--claudeSubscription", "codex": "--codexSubscription"}
@@ -870,7 +880,7 @@ def wait_for_health_check(
from products.tasks.backend.exceptions import ProcessTaskFatalError
raise ProcessTaskFatalError(
- "The Claude token did not arrive. Open Desktop and check your token in Settings > Harness. Then start the task again.",
+ CLAUDE_CREDENTIAL_UNAVAILABLE_MESSAGE,
{"sandbox_id": sandbox_id},
RuntimeError("Claude token unavailable"),
capture=False,
diff --git a/products/tasks/backend/logic/services/tests/test_docker_sandbox.py b/products/tasks/backend/logic/services/tests/test_docker_sandbox.py
index c6f3f5688c92..35dc13acfc1a 100644
--- a/products/tasks/backend/logic/services/tests/test_docker_sandbox.py
+++ b/products/tasks/backend/logic/services/tests/test_docker_sandbox.py
@@ -15,7 +15,11 @@ from products.tasks.backend.logic.services.agent_server_launcher import (
)
from products.tasks.backend.logic.services.docker_sandbox import DockerSandbox
from products.tasks.backend.logic.services.local_skills import ENV_DISABLE_BUNDLED_SKILLS
-from products.tasks.backend.logic.services.sandbox import ExecutionResult, SandboxConfig
+from products.tasks.backend.logic.services.sandbox import (
+ CLAUDE_CREDENTIAL_UNAVAILABLE_MESSAGE,
+ ExecutionResult,
+ SandboxConfig,
+)
@pytest.fixture
@@ -93,7 +97,7 @@ def test_wait_for_agent_server_ready_fails_fast_when_credential_never_arrived(
),
patch.object(sandbox, "execute", return_value=log),
patch("products.tasks.backend.exceptions.capture_exception") as capture_exception,
- pytest.raises(ProcessTaskFatalError, match="The Claude token did not arrive") as exc,
+ pytest.raises(ProcessTaskFatalError, match=CLAUDE_CREDENTIAL_UNAVAILABLE_MESSAGE) as exc,
):
sandbox.wait_for_agent_server_ready(claude_model_access="own-subscription")
diff --git a/products/tasks/backend/logic/services/tests/test_modal_sandbox.py b/products/tasks/backend/logic/services/tests/test_modal_sandbox.py
index 6b7f320943c7..d3659580f8e5 100644
--- a/products/tasks/backend/logic/services/tests/test_modal_sandbox.py
+++ b/products/tasks/backend/logic/services/tests/test_modal_sandbox.py
@@ -83,6 +83,7 @@ from products.tasks.backend.logic.services.modal_sandbox import (
_session_init_probe_hosts,
)
from products.tasks.backend.logic.services.sandbox import (
+ CLAUDE_CREDENTIAL_UNAVAILABLE_MESSAGE,
CODEX_CREDENTIAL_UNAVAILABLE_MESSAGE,
AgentServerResult,
ExecutionResult,
@@ -1024,7 +1025,7 @@ class TestModalSandboxAgentServer:
@pytest.mark.parametrize(
"marker, message",
[
- ("claude_credential_unavailable", "The Claude token did not arrive"),
+ ("claude_credential_unavailable", CLAUDE_CREDENTIAL_UNAVAILABLE_MESSAGE),
("codex_credential_unavailable", CODEX_CREDENTIAL_UNAVAILABLE_MESSAGE),
],
)
diff --git a/products/tasks/backend/presentation/views/api.py b/products/tasks/backend/presentation/views/api.py
index a8d2f28c8803..5f98c88666ee 100644
--- a/products/tasks/backend/presentation/views/api.py
+++ b/products/tasks/backend/presentation/views/api.py
@@ -1295,7 +1295,12 @@ class TaskViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSet):
),
},
summary="Run task",
- description="Create a new task run and kick off the workflow.",
+ description=(
+ "Create a new task run and kick off the workflow. **Responds with the task, not the "
+ "run**: the new run is nested under `latest_run`, and the top-level `id` is still the "
+ "task's. Read `latest_run.id` for anything run-scoped, such as the run's stream and "
+ "command endpoints."
+ ),
include_serializer_context=True,
)
@action(detail=True, methods=["post"], url_path="run", required_scopes=["task:write"])
@@ -3101,7 +3106,12 @@ class TaskRunViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSet):
),
400: OpenApiResponse(
response=TaskRunErrorResponseSerializer,
- description="Invalid command or no active sandbox",
+ description=(
+ "Invalid command, or no active sandbox. Code `sandbox_not_ready` is transient "
+ "rather than a refusal — the run exists but its agent server is still starting, "
+ "which is the usual answer to a command sent as soon as the run asks for one. "
+ "Retry it until the request you are answering expires. Every other 400 is fatal."
+ ),
),
403: OpenApiResponse(
response=TaskRunErrorResponseSerializer,
diff --git a/products/tasks/frontend/generated/api.ts b/products/tasks/frontend/generated/api.ts
index 246fd4f85a3e..523733347f59 100644
--- a/products/tasks/frontend/generated/api.ts
+++ b/products/tasks/frontend/generated/api.ts
@@ -1589,7 +1589,7 @@ export const getTasksRunCreateUrl = (projectId: string, id: string) => {
}
/**
- * Create a new task run and kick off the workflow.
+ * Create a new task run and kick off the workflow. **Responds with the task, not the run**: the new run is nested under `latest_run`, and the top-level `id` is still the task's. Read `latest_run.id` for anything run-scoped, such as the run's stream and command endpoints.
* @summary Run task
*/
export const tasksRunCreate = async (
diff --git a/products/tasks/frontend/generated/api.zod.ts b/products/tasks/frontend/generated/api.zod.ts
index b0d3fdfb5363..ae8e24dc09c4 100644
--- a/products/tasks/frontend/generated/api.zod.ts
+++ b/products/tasks/frontend/generated/api.zod.ts
@@ -1835,7 +1835,7 @@ export const TasksPresenceCreateBody = /* @__PURE__ */ zod
)
/**
- * Create a new task run and kick off the workflow.
+ * Create a new task run and kick off the workflow. **Responds with the task, not the run**: the new run is nested under `latest_run`, and the top-level `id` is still the task's. Read `latest_run.id` for anything run-scoped, such as the run's stream and command endpoints.
* @summary Run task
*/
export const tasksRunCreateBodyOneImportedMcpServersItemNameMax = 64
diff --git a/services/mcp/src/generated/tasks/api.ts b/services/mcp/src/generated/tasks/api.ts
index 0fb642c28e4e..c9bc353ba963 100644
--- a/services/mcp/src/generated/tasks/api.ts
+++ b/services/mcp/src/generated/tasks/api.ts
@@ -1273,7 +1273,7 @@ export const TasksRetrieveParams = () => zod.object({
})
/**
- * Create a new task run and kick off the workflow.
+ * Create a new task run and kick off the workflow. **Responds with the task, not the run**: the new run is nested under `latest_run`, and the top-level `id` is still the task's. Read `latest_run.id` for anything run-scoped, such as the run's stream and command endpoints.
* @summary Run task
*/
export const tasksRunCreatePathIdRegExp = new RegExp(