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(evals): route eval tasks through the posthog_ai gateway product (#117846)

Daniel Parker5ea8d1fec06f
diff --git a/products/posthog_ai/eval_harness/harness/cli.py b/products/posthog_ai/eval_harness/harness/cli.py
index c58a1ab56738..391a18d51324 100644
--- a/products/posthog_ai/eval_harness/harness/cli.py
+++ b/products/posthog_ai/eval_harness/harness/cli.py
@@ -10,8 +10,7 @@ from .retries import DEFAULT_INFRA_RETRIES
# Bare model ids, no "anthropic/"/"openai/" prefix: the LLM gateway checks the model against a
# bare-id allowlist with startswith, so the prefixed form is rejected with a 403 and the agent
-# finishes without doing anything. `start_llm_gateway` declares this exact id free-tier on the
-# harness's own gateway, and a run that dies at the gate anyway now fails as an error rather than
+# finishes without doing anything. A run that dies at the gate fails as an error rather than
# scoring zero on every outcome scorer.
DEFAULT_AGENT_MODEL = "claude-opus-5"
DEFAULT_CODEX_AGENT_MODEL = "gpt-5.5"
diff --git a/products/posthog_ai/eval_harness/harness/demo_data.py b/products/posthog_ai/eval_harness/harness/demo_data.py
index 83670d0639fb..34de0358ebd2 100644
--- a/products/posthog_ai/eval_harness/harness/demo_data.py
+++ b/products/posthog_ai/eval_harness/harness/demo_data.py
@@ -1,8 +1,11 @@
from __future__ import annotations
+import io
import logging
from datetime import timedelta
+from django.core.management import call_command
+
from posthog.clickhouse.client import sync_execute
from products.posthog_ai.eval_harness.data_setup import (
@@ -115,6 +118,10 @@ def ensure_demo_ready(
) -> SandboxedDemoData:
"""Seed the master Hedgebox team (once) and expose a per-case context factory."""
master_team_id = ensure_master_demo_team(blocker)
+ with blocker.unblock():
+ # Eval tasks use the posthog_ai origin, which mints sandbox tokens under the PostHog AI
+ # OAuth app. Demo data creates only the Array app, so without this every case fails to start.
+ call_command("setup_tasks_oauth", stdout=io.StringIO())
_ensure_event_search_columns_materialized(blocker)
with blocker.unblock():
rows = sync_execute(
diff --git a/products/posthog_ai/eval_harness/harness/lifecycle.py b/products/posthog_ai/eval_harness/harness/lifecycle.py
index c8dcb31d2152..ed7b03e643c4 100644
--- a/products/posthog_ai/eval_harness/harness/lifecycle.py
+++ b/products/posthog_ai/eval_harness/harness/lifecycle.py
@@ -277,7 +277,7 @@ class SandboxedEvalHarness:
if Infra.LLM_GATEWAY in required:
assert self._live_server is not None
- self._stack.callback(start_llm_gateway(self._live_server.url, self.options.agent_model))
+ self._stack.callback(start_llm_gateway(self._live_server.url))
if Infra.MCP_SERVER in required:
assert self._live_server is not None
diff --git a/products/posthog_ai/eval_harness/harness/services.py b/products/posthog_ai/eval_harness/harness/services.py
index 8ff4ffb7bc55..db893d48a517 100644
--- a/products/posthog_ai/eval_harness/harness/services.py
+++ b/products/posthog_ai/eval_harness/harness/services.py
@@ -30,16 +30,12 @@ LONG_LIVED_SUBPROCESSES = LongLivedSubprocessManager()
_ZIP_FIXED_TIME = (2020, 1, 1, 0, 0, 0)
-def start_llm_gateway(live_server_url: str, agent_model: str) -> Callable[[], None]:
+def start_llm_gateway(live_server_url: str) -> Callable[[], None]:
"""Start the LLM gateway as a subprocess.
Mirrors ``bin/start-llm-gateway``: runs uvicorn on a non-default port.
- The sandbox's agent-server uses this to proxy LLM calls to Anthropic.
-
- ``agent_model`` is declared free-tier on this gateway, because the gate it would otherwise hit
- cannot mean anything here: every case runs as a freshly minted team that has never been billed,
- so ``check_free_tier_model_access`` sees ``code_usage_billed=False`` and rejects the run's model
- with a 403 before the agent sends its first message.
+ The sandbox's agent-server uses this to proxy LLM calls to Anthropic, through the
+ ``posthog_ai`` product that eval tasks select with their origin.
"""
gateway_dir = Path(settings.BASE_DIR) / "services" / "llm-gateway"
venv_dir = gateway_dir / ".venv"
@@ -73,9 +69,6 @@ def start_llm_gateway(live_server_url: str, agent_model: str) -> Callable[[], No
"LLM_GATEWAY_DATABASE_URL": test_db_url,
"LLM_GATEWAY_DEBUG": "true",
"LLM_GATEWAY_POSTHOG_HOST": live_server_url,
- # Only the model this run uses, so the gate still rejects a typo rather than waving through
- # anything the agent-server happens to ask for.
- "LLM_GATEWAY_POSTHOG_CODE_FREE_TIER_MODELS": json.dumps([agent_model]),
}
logger.info("Starting LLM gateway on port %d", LLM_GATEWAY_PORT)
diff --git a/products/posthog_ai/eval_harness/runner.py b/products/posthog_ai/eval_harness/runner.py
index a7563b8c41df..bdd8b85a0a90 100644
--- a/products/posthog_ai/eval_harness/runner.py
+++ b/products/posthog_ai/eval_harness/runner.py
@@ -21,6 +21,7 @@ from products.tasks.backend.facade.agents import (
create_task_and_trigger,
poll_for_turn,
)
+from products.tasks.backend.facade.api import TaskOriginProduct
from products.tasks.backend.facade.temporal import ProcessTaskWorkflow
from .config import AgentArtifacts, SandboxedEvalCase
@@ -41,6 +42,8 @@ __all__ = ["run_eval_case"]
TEST_TITLE_RE = re.compile(r"\b(pytest|tests?)\b")
LINT_TITLE_RE = re.compile(r"\b(ruff|lint)\b")
+EVAL_ORIGIN_PRODUCT = TaskOriginProduct.POSTHOG_AI
+
WORKFLOW_COMPLETION_GRACE_SECONDS = 60
WORKFLOW_CANCELLATION_GRACE_SECONDS = 30
CASE_FINALIZATION_RESERVE_SECONDS = 120
@@ -239,7 +242,9 @@ async def _run_single_turn_case(
poll_deadline: float | None = None,
) -> tuple[str, list[str] | None]:
"""The historical one-prompt path: create, poll once, return the full log."""
- task_run = await create_task_and_trigger(case.prompt, context, step_name=case.name)
+ task_run = await create_task_and_trigger(
+ case.prompt, context, step_name=case.name, origin_product=EVAL_ORIGIN_PRODUCT
+ )
state.task_id = task_run.task_id
provider.register_task(str(task_run.task_id))
# Handle to the case's workflow so a timeout/error can shut the agent down.
@@ -280,6 +285,7 @@ async def _run_multi_turn_case(
prompt=case.prompt,
context=context,
step_name=case.name,
+ origin_product=EVAL_ORIGIN_PRODUCT,
verbose=True,
output_fn=lambda msg: logger.info("agent: %s", msg),
poll_deadline=poll_deadline,