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.

feat(signals): stamp routed model on scout run lifecycle events (#72412)

Andrew Maguire67b63fe19818
diff --git a/products/signals/backend/scout_harness/AGENTS.md b/products/signals/backend/scout_harness/AGENTS.md
index 42696a649af9..e3d26d5d93fd 100644
--- a/products/signals/backend/scout_harness/AGENTS.md
+++ b/products/signals/backend/scout_harness/AGENTS.md
@@ -210,6 +210,9 @@ one sandbox session → zero or more emitted signals.
`_self_heal_stale_runs`). They join on `run_id`/`task_run_id` and are the event-derived
(no-warehouse-lag) basis for throughput, stall, and worker-death alerting — a `started`
with no `finished` is a run that died before finalize; a reaped run emits no `finished`.
+ When the `scouts-model-selection` gate (or a runtime pin) routes the run, `started` and
+ `finished` also carry `model` / `runtime_adapter`, so run outcomes are sliceable by model
+ without joining through `$ai_generation`; absence means the agent-server default served it.
The report channel adds `signals_scout_report_emitted` / `signals_scout_report_edited`
(plus customer-facing `$scout_report_*` copies), stamped with derived classification
properties (`report_kind` = `finding`/`self_improvement`, `is_self_improvement_report`)
diff --git a/products/signals/backend/scout_harness/runner.py b/products/signals/backend/scout_harness/runner.py
index 3547af3b486e..dffdcb78bf53 100644
--- a/products/signals/backend/scout_harness/runner.py
+++ b/products/signals/backend/scout_harness/runner.py
@@ -271,6 +271,8 @@ async def arun_signals_scout(
status=tasks_facade.TaskRunStatus.COMPLETED.value,
runtime_s=runtime_s,
emitted_count=emitted_count,
+ model=model,
+ runtime_adapter=runtime_adapter,
)
return RunResult(
run_id=str(run_id),
@@ -319,6 +321,8 @@ async def arun_signals_scout(
status=tasks_facade.TaskRunStatus.FAILED.value,
runtime_s=runtime_s,
emitted_count=emitted_count,
+ model=model,
+ runtime_adapter=runtime_adapter,
error_type=type(exc).__name__,
error_message=str(exc)[:300],
)
@@ -361,6 +365,8 @@ async def arun_signals_scout(
status=tasks_facade.TaskRunStatus.CANCELLED.value,
runtime_s=runtime_s,
emitted_count=None,
+ model=model,
+ runtime_adapter=runtime_adapter,
)
raise
@@ -489,6 +495,8 @@ async def _spawn_and_run(
skill=skill,
run_id=run_id,
task_run_id=str(task_run.id),
+ model=model,
+ runtime_adapter=runtime_adapter,
)
session, result = await MultiTurnSession.start(
@@ -697,6 +705,8 @@ def _capture_run_started(
skill: LoadedSkill,
run_id: Any,
task_run_id: str,
+ model: str | None = None,
+ runtime_adapter: str | None = None,
) -> None:
"""Emit the scout-owned run-started analytics event.
@@ -707,17 +717,19 @@ def _capture_run_started(
finalize — an event-derived stall signal with no warehouse lag. Best-effort: a capture
failure must never block the run.
"""
+ properties: dict[str, Any] = {
+ "skill_name": skill.name,
+ "skill_version": skill.version,
+ "scout_config_id": str(config.id),
+ "run_id": str(run_id),
+ "task_run_id": task_run_id,
+ }
+ _attach_model_props(properties, model=model, runtime_adapter=runtime_adapter)
try:
posthoganalytics.capture(
event="signals_scout_run_started",
distinct_id=str(team.uuid),
- properties={
- "skill_name": skill.name,
- "skill_version": skill.version,
- "scout_config_id": str(config.id),
- "run_id": str(run_id),
- "task_run_id": task_run_id,
- },
+ properties=properties,
groups=groups(team.organization, team),
)
except Exception:
@@ -766,6 +778,16 @@ def _capture_run_reaped(
)
+def _attach_model_props(properties: dict[str, Any], *, model: str | None, runtime_adapter: str | None) -> None:
+ # Only attached when the `scouts-model-selection` gate (or a runtime pin) routed the run —
+ # absence means the agent-server default served it. Makes run outcomes (timeout rate, runtime,
+ # emit volume) sliceable by model without joining through $ai_generation.
+ if model is not None:
+ properties["model"] = model
+ if runtime_adapter is not None:
+ properties["runtime_adapter"] = runtime_adapter
+
+
def _capture_run_finished(
*,
team: Team,
@@ -776,6 +798,8 @@ def _capture_run_finished(
status: str,
runtime_s: float,
emitted_count: int | None,
+ model: str | None = None,
+ runtime_adapter: str | None = None,
error_type: str | None = None,
error_message: str | None = None,
) -> None:
@@ -803,6 +827,7 @@ def _capture_run_finished(
"runtime_seconds": round(runtime_s, 1),
"emitted_count": emitted_count,
}
+ _attach_model_props(properties, model=model, runtime_adapter=runtime_adapter)
# Only attach failure context on failed runs — keeps successful / cancelled events clean
# rather than carrying explicit-null error fields on every event.
if error_type is not None:
diff --git a/products/signals/backend/test/test_scout_harness.py b/products/signals/backend/test/test_scout_harness.py
index bd16955514a0..aa2d69f7a9b3 100644
--- a/products/signals/backend/test/test_scout_harness.py
+++ b/products/signals/backend/test/test_scout_harness.py
@@ -759,6 +759,8 @@ async def test_run_pins_sandbox_to_resolved_scout_model(
# The `scouts-model-selection` gate is the per-run experiment layer and wins when it resolves a
# model; the `signals-pipeline-models` pin is the default layer beneath it. Either way one
# source supplies the whole runtime/model/effort triple.
+ # The routed model must also ride on both lifecycle events (omitted on the default path), so
+ # run outcomes are sliceable by model without joining through $ai_generation.
session, result = await database_sync_to_async(_make_fake_session, thread_sensitive=False)(ateam)
captured: dict = {}
@@ -786,12 +788,23 @@ async def test_run_pins_sandbox_to_resolved_scout_model(
"products.signals.backend.scout_harness.runner.resolve_acting_user_id_for_team",
return_value=42,
),
+ patch("products.signals.backend.scout_harness.runner.posthoganalytics.capture") as capture,
):
await arun_signals_scout(team_id=ateam.id, skill_name="signals-scout-errors")
assert captured["context"].model == expected_model
assert captured["context"].runtime_adapter == expected_runtime_adapter
assert captured["context"].reasoning_effort == expected_reasoning_effort
+ events = {c.kwargs["event"] for c in capture.call_args_list}
+ assert events == {"signals_scout_run_started", "signals_scout_run_finished"}
+ for call in capture.call_args_list:
+ props = call.kwargs["properties"]
+ if expected_model is None:
+ assert "model" not in props
+ assert "runtime_adapter" not in props
+ else:
+ assert props["model"] == expected_model
+ assert props["runtime_adapter"] == expected_runtime_adapter
@pytest.mark.asyncio
@@ -909,6 +922,16 @@ async def test_failed_run_captures_run_finished_event(ateam, aerrors_skill):
new_callable=AsyncMock,
side_effect=RuntimeError("sandbox refused to start"),
),
+ # A routed model must survive onto the failed event too — timeouts and crashes are
+ # exactly the outcomes a model trial slices by.
+ patch(
+ "products.signals.backend.scout_harness.runner.resolve_scout_model",
+ return_value=ScoutModel(model="@cf/zai-org/glm-5.2", runtime_adapter="claude"),
+ ),
+ patch(
+ "products.signals.backend.scout_harness.runner.resolve_agent_runtime",
+ return_value=AgentRuntime(),
+ ),
patch(
"products.signals.backend.scout_harness.runner.get_or_create_signals_sandbox_env",
return_value="env-id",
@@ -928,6 +951,8 @@ async def test_failed_run_captures_run_finished_event(ateam, aerrors_skill):
# No bridge row persisted (TaskRun never created), so no emit tally or join key.
assert props["emitted_count"] == 0
assert props["task_run_id"] is None
+ assert props["model"] == "@cf/zai-org/glm-5.2"
+ assert props["runtime_adapter"] == "claude"
# Failure reason rides on the event so the failure rate is breakable down by cause
# without digging into worker logs — the bulk of scout failures fail here, before the
# process-task workflow's own task_run_failed event fires.