: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): link scout inbox card task run to its task (#64798)
Andrew Maguire9de4d68375fe
diff --git a/frontend/src/queries/schema.json b/frontend/src/queries/schema.jsonindex 438ba41e5195..51d1f428ba63 100644--- a/frontend/src/queries/schema.json+++ b/frontend/src/queries/schema.json@@ -40555,6 +40555,10 @@},"type": "array"},+ "task_id": {+ "description": "The `tasks.Task` id owning `task_run_id`. Pairs with it to deep-link the inbox card to the run in the Tasks UI. Absent on emissions made before this linkage was captured.",+ "type": "string"+ },"task_run_id": {"description": "The `tasks.TaskRun` id the scout span ran inside. Join key into the `signals_scouts_runs` LLM-analytics view, which is keyed on `task_run_id` (the `scout_run_id` bridge row is not).","type": "string"diff --git a/frontend/src/queries/schema/schema-signals.ts b/frontend/src/queries/schema/schema-signals.tsindex 9afe31fc2e55..3dd4747a4954 100644--- a/frontend/src/queries/schema/schema-signals.ts+++ b/frontend/src/queries/schema/schema-signals.ts@@ -332,6 +332,9 @@ export interface SignalsScoutSignalExtra extends SignalExtraBase {/** The `tasks.TaskRun` id the scout span ran inside. Join key into the `signals_scouts_runs`* LLM-analytics view, which is keyed on `task_run_id` (the `scout_run_id` bridge row is not). */task_run_id: string+ /** The `tasks.Task` id owning `task_run_id`. Pairs with it to deep-link the inbox card to the+ * run in the Tasks UI. Absent on emissions made before this linkage was captured. */+ task_id?: stringfinding_id: stringskill_name: stringskill_version: numberdiff --git a/frontend/src/scenes/inbox/components/signalCards/SignalCardShell.tsx b/frontend/src/scenes/inbox/components/signalCards/SignalCardShell.tsxindex e7d44edbb9b2..35a674fee4ed 100644--- a/frontend/src/scenes/inbox/components/signalCards/SignalCardShell.tsx+++ b/frontend/src/scenes/inbox/components/signalCards/SignalCardShell.tsx@@ -13,12 +13,15 @@ export function SignalCardHeader({signal,label,rightSlot,+ hideWeight,}: {signal: SignalNode/** Optional bold title shown after the source line (e.g. an entity name). */label?: React.ReactNode/** Optional content rendered before the weight tag (e.g. a severity badge). */rightSlot?: React.ReactNode+ /** Hide the weight tag — weight is an internal pipeline knob, not user-facing for every source. */+ hideWeight?: boolean}): JSX.Element {const meta = getSourceProductMeta(signal.source_product)const Icon = meta?.Icon@@ -41,9 +44,11 @@ export function SignalCardHeader({{label && <span className="text-xs font-medium text-primary flex-1 truncate">{label}</span>}<span className="flex-1" />{rightSlot}- <LemonTag size="small" className="shrink-0">- Weight: {signal.weight.toFixed(1)}- </LemonTag>+ {!hideWeight && (+ <LemonTag size="small" className="shrink-0">+ Weight: {signal.weight.toFixed(1)}+ </LemonTag>+ )}</div>)}@@ -53,16 +58,18 @@ export function SignalCardShell({signal,label,rightSlot,+ hideWeight,children,}: {signal: SignalNodelabel?: React.ReactNoderightSlot?: React.ReactNode+ hideWeight?: booleanchildren: React.ReactNode}): JSX.Element {return (<div className="border rounded p-3 bg-surface-primary">- <SignalCardHeader signal={signal} label={label} rightSlot={rightSlot} />+ <SignalCardHeader signal={signal} label={label} rightSlot={rightSlot} hideWeight={hideWeight} />{children}</div>)diff --git a/frontend/src/scenes/inbox/components/signalCards/SignalsScoutSignalCard.tsx b/frontend/src/scenes/inbox/components/signalCards/SignalsScoutSignalCard.tsxindex b0606cf68d94..29552bc2fabd 100644--- a/frontend/src/scenes/inbox/components/signalCards/SignalsScoutSignalCard.tsx+++ b/frontend/src/scenes/inbox/components/signalCards/SignalsScoutSignalCard.tsx@@ -1,3 +1,4 @@+import { combineUrl } from 'kea-router'import { useState } from 'react'import { IconExternal, IconList } from '@posthog/icons'@@ -88,12 +89,22 @@ function EvidenceRow({ entry }: { entry: SignalsScoutEvidenceEntry }): JSX.Eleme)}-/** Truncated mono identifier rendering for footer run/finding ids. */-function MonoId({ label, value }: { label: string; value: string }): JSX.Element {+/** Truncated mono identifier for footer run/finding ids. Becomes a deep link when `to` is set. */+function MonoId({ label, value, to }: { label: string; value: string; to?: string }): JSX.Element {+ const display = value.length > 12 ? `${value.slice(0, 12)}…` : value+ if (to) {+ return (+ <Link to={to} className="inline-flex items-center gap-1 font-medium">+ <span>{label}</span>+ <span className="font-mono">{display}</span>+ <IconExternal className="size-3" />+ </Link>+ )+ }return (<span className="inline-flex items-center gap-1"><span>{label}</span>- <span className="font-mono">{value.length > 12 ? `${value.slice(0, 12)}…` : value}</span>+ <span className="font-mono">{display}</span></span>)}@@ -114,6 +125,12 @@ export function SignalsScoutSignalCard({ signal }: SignalCardProps): JSX.Elementconst tags = extra.tags ?? []const timeRange = extra.time_range+ // Deep link the run id straight to its Tasks run tab — only resolvable when the task id was+ // captured at emit time (absent on older emissions).+ const taskRunUrl = extra.task_id+ ? combineUrl(urls.taskDetail(extra.task_id), { runId: extra.task_run_id }).url+ : undefined+return (<SignalCardShellsignal={signal}@@ -124,6 +141,7 @@ export function SignalsScoutSignalCard({ signal }: SignalCardProps): JSX.Element</span>}rightSlot={<SignalReportPriorityBadge priority={extra.severity} />}+ hideWeight>{/* Confidence meter. */}<div className="mb-2">@@ -185,7 +203,7 @@ export function SignalsScoutSignalCard({ signal }: SignalCardProps): JSX.Element<div className="flex items-center flex-wrap gap-x-3 gap-y-1 border-t pt-2 mt-2 text-xs text-tertiary"><MonoId label="Finding" value={extra.finding_id} /><MonoId label="Scout run" value={extra.scout_run_id} />- <MonoId label="Task run" value={extra.task_run_id} />+ <MonoId label="Task run" value={extra.task_run_id} to={taskRunUrl} />{extra.mcp_trace_id && (<><span className="flex-1" />diff --git a/posthog/schema.py b/posthog/schema.pyindex cab16fb0d8a9..4b49000be899 100644--- a/posthog/schema.py+++ b/posthog/schema.py@@ -2682,6 +2682,14 @@ class SignalsScoutSignalExtra(BaseModel):" the harness normalizes and caps these at emit."),)+ task_id: str | None = Field(+ default=None,+ description=(+ "The `tasks.Task` id owning `task_run_id`. Pairs with it to deep-link the"+ " inbox card to the run in the Tasks UI. Absent on emissions made before"+ " this linkage was captured."+ ),+ )task_run_id: str = Field(...,description=(diff --git a/products/signals/backend/scout_harness/tools/emit.py b/products/signals/backend/scout_harness/tools/emit.pyindex 6b4ff048a645..4d8fbfc0a962 100644--- a/products/signals/backend/scout_harness/tools/emit.py+++ b/products/signals/backend/scout_harness/tools/emit.py@@ -37,6 +37,7 @@ from posthog.models import Teamfrom posthog.sync import database_sync_to_asyncfrom products.signals.backend.models import SignalScoutConfig, SignalScoutEmission, SignalScoutRun, SignalSourceConfig+from products.tasks.backend.models import TaskRunlogger = logging.getLogger(__name__)@@ -132,9 +133,11 @@ async def emit_finding(_validate_inputs(description, confidence, evidence, finding_id)finding_id = finding_id or _new_finding_id()tags = normalize_tags(tags)+ task_id = await database_sync_to_async(_resolve_task_id, thread_sensitive=False)(run)extra = _build_extra(run_id=str(run.id),task_run_id=str(run.task_run_id),+ task_id=task_id,finding_id=finding_id,skill_name=run.skill_name,skill_version=run.skill_version,@@ -224,9 +227,11 @@ def emit_finding_sync(_validate_inputs(description, confidence, evidence, finding_id)finding_id = finding_id or _new_finding_id()tags = normalize_tags(tags)+ task_id = _resolve_task_id(run)extra = _build_extra(run_id=str(run.id),task_run_id=str(run.task_run_id),+ task_id=task_id,finding_id=finding_id,skill_name=run.skill_name,skill_version=run.skill_version,@@ -352,10 +357,22 @@ def _validate_inputs(raise InvalidEmitError(f"finding_id exceeds {MAX_FINDING_ID_LENGTH} chars ({len(finding_id)})")+def _resolve_task_id(run: SignalScoutRun) -> str | None:+ """The parent `tasks.Task` id for this run's `TaskRun`, used to deep-link the inbox card to the+ run. None when the run isn't bridged to a TaskRun yet. Sync-only — wrap callers in async paths."""+ if not run.task_run_id:+ return None+ # Team-scope the lookup: the bridge run is already team-owned, but scoping the TaskRun query keeps+ # the resolution fail-closed against cross-team ids.+ task_id = TaskRun.objects.filter(id=run.task_run_id, team_id=run.team_id).values_list("task_id", flat=True).first()+ return str(task_id) if task_id else None++def _build_extra(*,run_id: str,task_run_id: str,+ task_id: str | None,finding_id: str,skill_name: str,skill_version: int,@@ -380,6 +397,8 @@ def _build_extra("confidence": confidence,"evidence": [asdict(e) for e in evidence],}+ if task_id is not None:+ extra["task_id"] = task_idif hypothesis is not None:extra["hypothesis"] = hypothesisif severity is not None:diff --git a/products/signals/backend/test/test_scout_harness_tools.py b/products/signals/backend/test/test_scout_harness_tools.pyindex c579cf9c1251..9bce6bb99526 100644--- a/products/signals/backend/test/test_scout_harness_tools.py+++ b/products/signals/backend/test/test_scout_harness_tools.py@@ -532,6 +532,7 @@ class TestBuildEmitExtra:return _build_extra(run_id="run-uuid",task_run_id="task-run-uuid",+ task_id=None,finding_id="finding-uuid",skill_name="signals-scout-errors",skill_version=2,@@ -558,7 +559,7 @@ class TestBuildEmitExtra:]# Optional fields omitted, not None — pydantic with extra="forbid" tolerates absence# but rejects unexpected keys, so omission is the right shape.- for opt in ("hypothesis", "severity", "dedupe_keys", "time_range", "mcp_trace_id", "tags"):+ for opt in ("task_id", "hypothesis", "severity", "dedupe_keys", "time_range", "mcp_trace_id", "tags"):assert opt not in extradef test_skill_version_cast_to_float(self) -> None:@@ -571,6 +572,7 @@ class TestBuildEmitExtra:extra = _build_extra(run_id="run-uuid",task_run_id="task-run-uuid",+ task_id="task-uuid",finding_id="finding-uuid",skill_name="signals-scout-errors",skill_version=1,@@ -583,6 +585,7 @@ class TestBuildEmitExtra:mcp_trace_id="trace-abc",tags=["cost-spike", "post-deploy-regression"],)+ assert extra["task_id"] == "task-uuid"assert extra["hypothesis"] == "checkout post-deploy regression"assert extra["severity"] == "P1"assert extra["dedupe_keys"] == ["checkout-500-spike"]