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): tag scout runs with ai_stage="scout" (#64483)

Andrew Maguireed2096ecf813
diff --git a/products/signals/backend/scout_harness/runner.py b/products/signals/backend/scout_harness/runner.py
index 9955725494eb..88f802f7e24a 100644
--- a/products/signals/backend/scout_harness/runner.py
+++ b/products/signals/backend/scout_harness/runner.py
@@ -332,6 +332,11 @@ async def _spawn_and_run(
step_name=_step_name(skill),
verbose=verbose,
origin_product=Task.OriginProduct.SIGNALS_SCOUT,
+ # Tag every scout $ai_generation with a coarse pipeline stage so scout spend is
+ # splittable out of the ai_product='signals' bucket (scouts carry no signal_report_id).
+ # Constant 'scout' keeps ai_stage a low-cardinality stage enum (peer of research /
+ # repo_selection / implementation); per-scout granularity comes from scout_name (task_title).
+ ai_stage="scout",
on_task_run_created=_create_bridge_row,
# Keep the per-turn poll budget at the run's runtime cap so the dropped-finalization
# salvage fires before the activity's `start_to_close_timeout` (DEFAULT_MAX_RUNTIME_S +
diff --git a/products/signals/backend/test/test_scout_harness.py b/products/signals/backend/test/test_scout_harness.py
index 24543c6b653d..fbbb8f8835f5 100644
--- a/products/signals/backend/test/test_scout_harness.py
+++ b/products/signals/backend/test/test_scout_harness.py
@@ -258,6 +258,36 @@ async def test_successful_run_creates_bridge_row_pointing_at_task_run(ateam, aer
assert bridge.scout_config_id == config.id
+async def test_run_tags_session_with_scout_ai_stage(ateam, aerrors_skill):
+ # Scouts pass ai_stage='scout' to the sandbox session so every $ai_generation carries it,
+ # letting scout spend be split out of the ai_product='signals' bucket (scouts have no report id).
+ session, result = await database_sync_to_async(_make_fake_session, thread_sensitive=False)(ateam)
+ captured: dict = {}
+
+ async def _capture_start(*args, on_task_run_created=None, **kwargs):
+ captured.update(kwargs)
+ if on_task_run_created is not None:
+ await on_task_run_created(session.task_run)
+ return session, result
+
+ with (
+ patch("products.signals.backend.scout_harness.runner.MultiTurnSession.start", new=_capture_start),
+ patch(
+ "products.signals.backend.scout_harness.runner.get_or_create_signals_sandbox_env",
+ return_value="env-id",
+ ),
+ patch(
+ "products.signals.backend.scout_harness.runner.resolve_user_id_for_team",
+ return_value=42,
+ ),
+ ):
+ await arun_signals_scout(team_id=ateam.id, skill_name="signals-scout-errors")
+
+ assert captured["ai_stage"] == "scout"
+
+
@pytest.mark.asyncio
@pytest.mark.django_db
async def test_failed_run_returns_failed_outcome_and_skips_bridge_insert(ateam, aerrors_skill):