: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
feat(signals): stamp routed model metadata on scout run rows (#72942)
Andrew Maguire24f2fc00429b
diff --git a/products/signals/backend/migrations/0068_signalscoutrun_metadata.py b/products/signals/backend/migrations/0068_signalscoutrun_metadata.pynew file mode 100644index 000000000000..6c8a43232031--- /dev/null+++ b/products/signals/backend/migrations/0068_signalscoutrun_metadata.py@@ -0,0 +1,17 @@+# Generated by Django 5.2.14 on 2026-07-22 16:32++from django.db import migrations, models+++class Migration(migrations.Migration):+ dependencies = [+ ("signals", "0067_signalscoutconfig_run_cron_schedule"),+ ]++ operations = [+ migrations.AddField(+ model_name="signalscoutrun",+ name="metadata",+ field=models.JSONField(blank=True, db_default={}, default=dict, null=True),+ ),+ ]diff --git a/products/signals/backend/migrations/max_migration.txt b/products/signals/backend/migrations/max_migration.txtindex db8d5db9d7f3..e66f751fb339 100644--- a/products/signals/backend/migrations/max_migration.txt+++ b/products/signals/backend/migrations/max_migration.txt@@ -1 +1 @@-0067_signalscoutconfig_run_cron_schedule+0068_signalscoutrun_metadatadiff --git a/products/signals/backend/models.py b/products/signals/backend/models.pyindex d7e2c2ee88f6..3298e89e02d9 100644--- a/products/signals/backend/models.py+++ b/products/signals/backend/models.py@@ -1249,6 +1249,14 @@ class SignalScoutRun(TeamScopedRootMixin, UUIDModel):# report (pipeline-authored included), so an edited id is generally NOT one the run authored. Nullable# with a `[]` db_default so the AddField stays non-blocking on the populated table.edited_report_ids = models.JSONField(null=True, blank=True, default=list, db_default=[])+ # Scout-owned per-run context stamped once at run creation — the native home for run+ # dimensions that matter operationally but don't each warrant a dedicated column. Known keys+ # today: `model` / `runtime_adapter` / `reasoning_effort`, the triple the run was routed on+ # when the `scouts-model-selection` gate (or a runtime pin) overrode the agent-server default;+ # empty for default-model runs. Write-once at creation, not a mutable grab-bag — new keys+ # (e.g. a future config-level model) should also be stamped by the runner at run start.+ # Nullable with a `{}` db_default so the AddField stays non-blocking on the populated table.+ metadata = models.JSONField(null=True, blank=True, default=dict, db_default={})created_at = models.DateTimeField(auto_now_add=True)class Meta:diff --git a/products/signals/backend/scout_harness/AGENTS.md b/products/signals/backend/scout_harness/AGENTS.mdindex 06fc256ef8ab..890f5fb071f1 100644--- a/products/signals/backend/scout_harness/AGENTS.md+++ b/products/signals/backend/scout_harness/AGENTS.md@@ -204,6 +204,13 @@ one sandbox session → zero or more emitted signals.(`/project/{team_id}/tasks/{task_id}?runId={task_run_id}`) and is the join key for theLLM-analytics token / cost roll-up. Failure context (status, error, full chat log viaLLMA) lives on the `TaskRun`; the harness persists no run state on the bridge row.+ The bridge row does carry a write-once `metadata` JSON column stamped at creation — the+ API-native record of run context that isn't worth a dedicated column. Known keys today:+ `model` / `runtime_adapter` / `reasoning_effort`, the triple the run was routed on when the+ `scouts-model-selection` gate (or a runtime pin) overrode the agent-server default (`{}` on the+ default path). Surfaced verbatim on the run serializers / `scout-runs-*` MCP tools; new+ operationally-relevant run dimensions should be stamped there by `_create_run_row`, not grown+ as ad-hoc columns.- Each run emits scout-owned lifecycle analytics events (best-effort, keyed on the team):`signals_scout_run_started` (the run cleared the guards and a TaskRun exists),`signals_scout_run_finished` (terminal: `completed`/`failed`/`cancelled` + runtime + emitdiff --git a/products/signals/backend/scout_harness/runner.py b/products/signals/backend/scout_harness/runner.pyindex dffdcb78bf53..178a55d03baf 100644--- a/products/signals/backend/scout_harness/runner.py+++ b/products/signals/backend/scout_harness/runner.py@@ -483,6 +483,9 @@ async def _spawn_and_run(team=team,config=config,skill=skill,+ model=model,+ runtime_adapter=runtime_adapter,+ reasoning_effort=reasoning_effort,)# Lifecycle start marker. The row + TaskRun now exist and the run has cleared the# reap + single-flight guards, so this counts exactly the runs that actually start —@@ -665,7 +668,22 @@ def _create_run_row(team: Team,config: SignalScoutConfig,skill: LoadedSkill,+ model: str | None = None,+ runtime_adapter: str | None = None,+ reasoning_effort: str | None = None,) -> SignalScoutRun:+ # Stamp the routed model triple onto the row's `metadata` so "which model ran this?" is a+ # column read on the run API, not an analytics-event join. Keys are omitted (not null-valued)+ # on the default path, so an empty dict means the agent-server default served the run.+ metadata = {+ key: value+ for key, value in (+ ("model", model),+ ("runtime_adapter", runtime_adapter),+ ("reasoning_effort", reasoning_effort),+ )+ if value is not None+ }return SignalScoutRun.objects.unscoped().create(id=run_id,task_run=task_run,@@ -673,6 +691,7 @@ def _create_run_row(scout_config=config,skill_name=skill.name,skill_version=skill.version,+ metadata=metadata,)diff --git a/products/signals/backend/scout_harness/serializers.py b/products/signals/backend/scout_harness/serializers.pyindex 287d6e08a31d..ee85e717296f 100644--- a/products/signals/backend/scout_harness/serializers.py+++ b/products/signals/backend/scout_harness/serializers.py@@ -130,6 +130,15 @@ class SignalScoutRunSummarySerializer(serializers.Serializer):"edited no report."),)+ metadata = serializers.DictField(+ child=serializers.CharField(),+ help_text=(+ "Scout-owned per-run context stamped at run start. Known keys today: `model`, "+ "`runtime_adapter`, and `reasoning_effort` — the triple the run was routed on when the "+ "`scouts-model-selection` gate (or a runtime pin) overrode the agent-server default. "+ "Empty object when the run rode the default model, or for runs predating the field."+ ),+ )class SignalScoutRunDetailSerializer(SignalScoutRunSummarySerializer):diff --git a/products/signals/backend/scout_harness/tools/runs.py b/products/signals/backend/scout_harness/tools/runs.pyindex bf95b0cb33c8..d6c6a1ab66ac 100644--- a/products/signals/backend/scout_harness/tools/runs.py+++ b/products/signals/backend/scout_harness/tools/runs.py@@ -81,6 +81,10 @@ class RunSummary:# one-liner. Both are surfaced only for failed/cancelled runs — null otherwise (incl. success).error: str | None = Nonefailure_reason: str | None = None+ # Scout-owned per-run context stamped at run creation (today: the routed model triple —+ # `model` / `runtime_adapter` / `reasoning_effort`). Empty for default-model runs and rows+ # predating the column.+ metadata: dict[str, Any] = field(default_factory=dict)def as_dict(self) -> dict[str, Any]:return asdict(self)@@ -120,6 +124,10 @@ class RunDetail:# one-liner. Both are surfaced only for failed/cancelled runs — null otherwise (incl. success).error: str | None = Nonefailure_reason: str | None = None+ # Scout-owned per-run context stamped at run creation (today: the routed model triple —+ # `model` / `runtime_adapter` / `reasoning_effort`). Empty for default-model runs and rows+ # predating the column.+ metadata: dict[str, Any] = field(default_factory=dict)def as_dict(self) -> dict[str, Any]:return asdict(self)@@ -303,6 +311,7 @@ def _to_summary(row: SignalScoutRun, *, team_id: int) -> RunSummary:task_url=_build_task_url(team_id=team_id, task_id=task_id, task_run_id=task_run_id),error=error,failure_reason=failure_reason,+ metadata=dict(row.metadata or {}),)diff --git a/products/signals/backend/test/test_scout_harness.py b/products/signals/backend/test/test_scout_harness.pyindex aa2d69f7a9b3..925cfb5815d7 100644--- a/products/signals/backend/test/test_scout_harness.py+++ b/products/signals/backend/test/test_scout_harness.py@@ -795,6 +795,19 @@ async def test_run_pins_sandbox_to_resolved_scout_model(assert captured["context"].model == expected_modelassert captured["context"].runtime_adapter == expected_runtime_adapterassert captured["context"].reasoning_effort == expected_reasoning_effort+ # The routed triple is also stamped on the bridge row's `metadata` (keys omitted when unset,+ # `{}` on the default path) — the native API-side record of which model served the run.+ bridge = await database_sync_to_async(SignalScoutRun.objects.get)(team=ateam)+ expected_metadata = {+ key: value+ for key, value in (+ ("model", expected_model),+ ("runtime_adapter", expected_runtime_adapter),+ ("reasoning_effort", expected_reasoning_effort),+ )+ if value is not None+ }+ assert bridge.metadata == expected_metadataevents = {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:diff --git a/products/signals/backend/test/test_scout_harness_tools.py b/products/signals/backend/test/test_scout_harness_tools.pyindex 60cf1e0a3134..11173e2ffa6f 100644--- a/products/signals/backend/test/test_scout_harness_tools.py+++ b/products/signals/backend/test/test_scout_harness_tools.py@@ -145,6 +145,17 @@ class TestSearchRecentRuns(BaseTest):assert len(hits) == MAX_RUN_SEARCH_LIMIT+ def test_summary_surfaces_run_metadata(self) -> None:+ # `metadata` carries the routed model triple stamped at run creation; a pre-column row+ # (NULL) and a default-model run ({}) must both project as an empty dict, not None/crash.+ routed = _create_run(self.team, metadata={"model": "@cf/zai-org/glm-5.2", "runtime_adapter": "claude"})+ legacy = _create_run(self.team, metadata=None)++ by_run_id = {hit.run_id: hit for hit in search_recent_runs(team_id=self.team.id)}++ assert by_run_id[str(routed.id)].metadata == {"model": "@cf/zai-org/glm-5.2", "runtime_adapter": "claude"}+ assert by_run_id[str(legacy.id)].metadata == {}+def test_summary_surfaces_status_from_linked_task_run(self) -> None:TaskRun = apps.get_model("tasks", "TaskRun")run = _create_run(self.team, task_run_status=TaskRun.Status.COMPLETED)diff --git a/products/signals/frontend/generated/api.schemas.ts b/products/signals/frontend/generated/api.schemas.tsindex f16a9bd43eec..6176c020859a 100644--- a/products/signals/frontend/generated/api.schemas.ts+++ b/products/signals/frontend/generated/api.schemas.ts@@ -2246,6 +2246,11 @@ export interface ProjectProfileApi {payload: ProjectProfilePayloadApi}+/**+ * Scout-owned per-run context stamped at run start. Known keys today: `model`, `runtime_adapter`, and `reasoning_effort` — the triple the run was routed on when the `scouts-model-selection` gate (or a runtime pin) overrode the agent-server default. Empty object when the run rode the default model, or for runs predating the field.+ */+export type SignalScoutRunSummaryApiMetadata = { [key: string]: string }+/*** Lightweight projection of a `SignalScoutRun` row used by `search-recent-runs`.*@@ -2304,8 +2309,15 @@ export interface SignalScoutRunSummaryApi {emitted_report_ids: string[]/** The `SignalReport` ids this run mutated via the `edit_report` channel (rewrote title/summary and/or appended a note), deduped. Distinct from `emitted_report_ids`: edit can target any inbox report, so these are generally not reports the run authored. Empty for runs that edited no report. */edited_report_ids: string[]+ /** Scout-owned per-run context stamped at run start. Known keys today: `model`, `runtime_adapter`, and `reasoning_effort` — the triple the run was routed on when the `scouts-model-selection` gate (or a runtime pin) overrode the agent-server default. Empty object when the run rode the default model, or for runs predating the field. */+ metadata: SignalScoutRunSummaryApiMetadata}+/**+ * Scout-owned per-run context stamped at run start. Known keys today: `model`, `runtime_adapter`, and `reasoning_effort` — the triple the run was routed on when the `scouts-model-selection` gate (or a runtime pin) overrode the agent-server default. Empty object when the run rode the default model, or for runs predating the field.+ */+export type SignalScoutRunDetailApiMetadata = { [key: string]: string }+/*** Full `SignalScoutRun` projection used by `get-run`. Same shape as the summary* today; kept distinct so future detail-only extensions (linked Signal rows,@@ -2364,6 +2376,8 @@ export interface SignalScoutRunDetailApi {emitted_report_ids: string[]/** The `SignalReport` ids this run mutated via the `edit_report` channel (rewrote title/summary and/or appended a note), deduped. Distinct from `emitted_report_ids`: edit can target any inbox report, so these are generally not reports the run authored. Empty for runs that edited no report. */edited_report_ids: string[]+ /** Scout-owned per-run context stamped at run start. Known keys today: `model`, `runtime_adapter`, and `reasoning_effort` — the triple the run was routed on when the `scouts-model-selection` gate (or a runtime pin) overrode the agent-server default. Empty object when the run rode the default model, or for runs predating the field. */+ metadata: SignalScoutRunDetailApiMetadata}/**diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex 8760b33484a4..d404636898a1 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -61296,6 +61296,11 @@ export namespace Schemas {started: boolean;}+ /**+ * Scout-owned per-run context stamped at run start. Known keys today: `model`, `runtime_adapter`, and `reasoning_effort` — the triple the run was routed on when the `scouts-model-selection` gate (or a runtime pin) overrode the agent-server default. Empty object when the run rode the default model, or for runs predating the field.+ */+ export type SignalScoutRunDetailMetadata = {[key: string]: string};+/*** Full `SignalScoutRun` projection used by `get-run`. Same shape as the summary* today; kept distinct so future detail-only extensions (linked Signal rows,@@ -61354,8 +61359,15 @@ export namespace Schemas {emitted_report_ids: string[];/** The `SignalReport` ids this run mutated via the `edit_report` channel (rewrote title/summary and/or appended a note), deduped. Distinct from `emitted_report_ids`: edit can target any inbox report, so these are generally not reports the run authored. Empty for runs that edited no report. */edited_report_ids: string[];+ /** Scout-owned per-run context stamped at run start. Known keys today: `model`, `runtime_adapter`, and `reasoning_effort` — the triple the run was routed on when the `scouts-model-selection` gate (or a runtime pin) overrode the agent-server default. Empty object when the run rode the default model, or for runs predating the field. */+ metadata: SignalScoutRunDetailMetadata;}+ /**+ * Scout-owned per-run context stamped at run start. Known keys today: `model`, `runtime_adapter`, and `reasoning_effort` — the triple the run was routed on when the `scouts-model-selection` gate (or a runtime pin) overrode the agent-server default. Empty object when the run rode the default model, or for runs predating the field.+ */+ export type SignalScoutRunSummaryMetadata = {[key: string]: string};+/*** Lightweight projection of a `SignalScoutRun` row used by `search-recent-runs`.*@@ -61414,6 +61426,8 @@ export namespace Schemas {emitted_report_ids: string[];/** The `SignalReport` ids this run mutated via the `edit_report` channel (rewrote title/summary and/or appended a note), deduped. Distinct from `emitted_report_ids`: edit can target any inbox report, so these are generally not reports the run authored. Empty for runs that edited no report. */edited_report_ids: string[];+ /** Scout-owned per-run context stamped at run start. Known keys today: `model`, `runtime_adapter`, and `reasoning_effort` — the triple the run was routed on when the `scouts-model-selection` gate (or a runtime pin) overrode the agent-server default. Empty object when the run rode the default model, or for runs predating the field. */+ metadata: SignalScoutRunSummaryMetadata;}export interface SignalUserAutonomyConfig {