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): link scout runs to reports they author or edit (#71927)

Andrew Maguirefa613c2f6c02
diff --git a/frontend/src/scenes/inbox/components/detail/artefactTypes.ts b/frontend/src/scenes/inbox/components/detail/artefactTypes.ts
index 7c520a453097..876f43dd6e55 100644
--- a/frontend/src/scenes/inbox/components/detail/artefactTypes.ts
+++ b/frontend/src/scenes/inbox/components/detail/artefactTypes.ts
@@ -163,6 +163,9 @@ export function deriveTaskPurpose(content: TaskRunArtefactContent): DerivedPurpo
if (content.type === 'repo_selection') {
return null
}
+ if (content.type === 'scout') {
+ return { purpose: 'other', purposeLabel: 'Scout' }
+ }
return { purpose: 'other', purposeLabel: `Signals — ${identifierToHuman(content.type)}` }
}
return {
@@ -182,6 +185,7 @@ export function taskRunTypeLabel(content: TaskRunArtefactContent): string {
research: 'Research',
implementation: 'Implementation',
repo_selection: 'Repo selection',
+ scout: 'Scout',
}
return labels[content.type] ?? identifierToHuman(content.type)
}
diff --git a/products/signals/backend/artefact_schemas.py b/products/signals/backend/artefact_schemas.py
index e226d00a091a..2437cba7e6c4 100644
--- a/products/signals/backend/artefact_schemas.py
+++ b/products/signals/backend/artefact_schemas.py
@@ -362,6 +362,9 @@ TASK_RUN_TYPE_RESEARCH = "research"
TASK_RUN_TYPE_IMPLEMENTATION = "implementation"
# A discuss-the-report task started by a user from the Inbox (not the automated research run).
TASK_RUN_TYPE_DISCUSSION = "discussion"
+# The scout run that authored the report via `emit_report` (or first touched it via `edit_report`) —
+# links the report back to the scout's own run so its transcript is reachable from the work log.
+TASK_RUN_TYPE_SCOUT = "scout"
# Generic identifiers for a legacy `SignalReportTask` row with no `(product, type)` label — an
# unlabelled link from the brief link-only window before associations carried identifiers.
diff --git a/products/signals/backend/scout_harness/tools/report.py b/products/signals/backend/scout_harness/tools/report.py
index d517dc9afe12..28cb024e356a 100644
--- a/products/signals/backend/scout_harness/tools/report.py
+++ b/products/signals/backend/scout_harness/tools/report.py
@@ -63,6 +63,7 @@ from products.signals.backend.scout_report import (
create_scout_report,
get_scout_report_title,
record_report_edit,
+ record_scout_run_task_artefact,
set_scout_report_reviewers,
update_scout_report,
)
@@ -973,6 +974,9 @@ def _do_edit_report(
# title rewrite to its current value) must not claim the run touched the report.
if updated_fields or note_appended or reviewers_set:
record_report_edit(team_id=team.id, run_id=run.id, report_id=report_id)
+ # Also link the run itself on the report's work log (deduped), so the editing scout's
+ # transcript is reachable from the report — not just the run-side `edited_report_ids` tally.
+ record_scout_run_task_artefact(team_id=team.id, report_id=report_id, run=run, task_id=attribution.task_id)
return result
diff --git a/products/signals/backend/scout_report/__init__.py b/products/signals/backend/scout_report/__init__.py
index c7332ef3728a..67f07ca2ee81 100644
--- a/products/signals/backend/scout_report/__init__.py
+++ b/products/signals/backend/scout_report/__init__.py
@@ -15,6 +15,7 @@ from products.signals.backend.scout_report.persistence import (
create_scout_report,
get_scout_report_title,
record_report_edit,
+ record_scout_run_task_artefact,
set_scout_report_reviewers,
soft_delete_scout_signal,
update_scout_report,
@@ -29,6 +30,7 @@ __all__ = [
"create_scout_report",
"get_scout_report_title",
"record_report_edit",
+ "record_scout_run_task_artefact",
"set_scout_report_reviewers",
"soft_delete_scout_signal",
"update_scout_report",
diff --git a/products/signals/backend/scout_report/persistence.py b/products/signals/backend/scout_report/persistence.py
index 656e748d6293..6c5254aacb23 100644
--- a/products/signals/backend/scout_report/persistence.py
+++ b/products/signals/backend/scout_report/persistence.py
@@ -37,11 +37,14 @@ from posthog.schema import EmbeddingModelName
from posthog.api.embedding_worker import emit_embedding_request
from products.signals.backend.artefact_schemas import (
+ SIGNALS_PRODUCT,
+ TASK_RUN_TYPE_SCOUT,
ActionabilityAssessment,
NoteArtefact,
PriorityAssessment,
SafetyJudgment,
SuggestedReviewers,
+ TaskRunArtefact,
)
from products.signals.backend.models import ArtefactAttribution, SignalReport, SignalReportArtefact, SignalScoutRun
from products.signals.backend.report_generation.select_repo import RepoSelectionResult
@@ -170,6 +173,17 @@ def create_scout_report(
attribution=attribution,
reevaluate_autostart=False,
)
+ # Link the authoring scout run itself as a `task_run` artefact, so the report's Runs section
+ # and activity log can surface the scout's transcript — without it the run is only visible as
+ # an anonymous "by agent" byline on the rows above. Written in-txn for the same no-divergence
+ # reason as the note; skipped when the run isn't bridged to a resolvable task.
+ if run is not None and attribution.task_id is not None:
+ SignalReportArtefact.add_log(
+ team_id=team_id,
+ report_id=report_id,
+ content=_scout_task_run_content(run, attribution.task_id),
+ attribution=attribution,
+ )
# The judge verdicts that set `status`, recorded as the report's status artefacts so the
# decision is auditable on the report (and so the inbox derives the same actionability/safety
# state a pipeline report would). Written in-txn with the report for the same no-divergence reason.
@@ -496,6 +510,58 @@ def record_report_edit(*, team_id: int, run_id: uuid.UUID, report_id: str) -> No
logger.exception("signals_scout.edit_report: failed to record report edit for run %s", run_id)
+def record_scout_run_task_artefact(*, team_id: int, report_id: str, run: SignalScoutRun, task_id: str | None) -> None:
+ """Link the editing scout run to the report as a `task_run` artefact — the edit-channel
+ counterpart to the in-txn append in `create_scout_report`. `edit_report` can target ANY inbox
+ report (pipeline-authored included), so this is what makes the editing run's transcript reachable
+ from the report's work log rather than just an anonymous "by agent" byline.
+
+ Deduped by task: a run that edits the report it authored (or edits the same report twice) records
+ the link once — the artefact is an association, not a per-edit log entry (that detail lives in the
+ note/status artefacts the edit itself appends). Best-effort like the run tallies: the edit has
+ already committed by the time this runs, so a failure here is swallowed rather than surfaced as a
+ false edit failure. No-ops when the run isn't bridged to a resolvable task (`task_id` is None).
+ """
+ if task_id is None:
+ return
+ try:
+ with transaction.atomic():
+ # The artefact log has no uniqueness constraint, so serialize the check-then-append under
+ # the report row lock — concurrent edits from the same run would otherwise both pass the
+ # exists() check and double-write the association.
+ if not SignalReport.objects.select_for_update().filter(team_id=team_id, id=report_id).first():
+ return
+ # The `task_id` column mirrors the content's task id on every signals-pipeline `task_run`
+ # artefact (they're attributed to the task they record), so it doubles as the dedupe key.
+ if SignalReportArtefact.objects.filter(
+ team_id=team_id,
+ report_id=report_id,
+ type=SignalReportArtefact.ArtefactType.TASK_RUN,
+ task_id=task_id,
+ ).exists():
+ return
+ SignalReportArtefact.add_log(
+ team_id=team_id,
+ report_id=report_id,
+ content=_scout_task_run_content(run, task_id),
+ attribution=ArtefactAttribution.from_task(task_id),
+ )
+ except Exception:
+ logger.exception(
+ "signals_scout.edit_report: failed to record scout task_run artefact",
+ extra={"team_id": team_id, "report_id": report_id, "run_id": str(run.id)},
+ )
+
+
+def _scout_task_run_content(run: SignalScoutRun, task_id: str) -> TaskRunArtefact:
+ return TaskRunArtefact(
+ task_id=task_id,
+ run_id=str(run.task_run_id) if run.task_run_id else None,
+ product=SIGNALS_PRODUCT,
+ type=TASK_RUN_TYPE_SCOUT,
+ )
+
+
def _provenance_note_text(run: SignalScoutRun | None) -> str:
if run is not None:
return f"Authored directly by the `{run.skill_name}` Signals scout via emit_report."
diff --git a/products/signals/backend/test/test_scout_report_api.py b/products/signals/backend/test/test_scout_report_api.py
index f4962fd6174a..b61e2bfea6cc 100644
--- a/products/signals/backend/test/test_scout_report_api.py
+++ b/products/signals/backend/test/test_scout_report_api.py
@@ -14,6 +14,7 @@ from social_django.models import UserSocialAuth
from posthog.models import Organization, Team, User
from posthog.models.organization import OrganizationMembership
+from products.signals.backend.artefact_schemas import TaskRunArtefact
from products.signals.backend.models import SignalReport, SignalReportArtefact, SignalSourceConfig
from products.signals.backend.scout_harness.tools.report import (
MAX_SUGGESTED_REVIEWERS,
@@ -189,6 +190,38 @@ class TestScoutReportAPI(APIBaseTest):
assert response.status_code == status.HTTP_200_OK, response.json()
run.refresh_from_db()
assert run.edited_report_ids == [report_id]
+ # The run link on the report's work log dedupes the same way: emit linked the run once, and
+ # the two edits must not append duplicate `task_run` rows for it.
+ assert (
+ SignalReportArtefact.objects.filter(
+ report_id=report_id, type=SignalReportArtefact.ArtefactType.TASK_RUN
+ ).count()
+ == 1
+ )
+
+ def test_edit_report_links_editing_run_to_report_it_did_not_author(self) -> None:
+ # `edit_report` can target any inbox report (pipeline-authored included) — the edit must link
+ # the editing scout run on the report's work log so its transcript is reachable from the
+ # report, not just from the run-side `edited_report_ids` tally. Per-task dedupe: a second
+ # run editing the same report gets its own link.
+ report = SignalReport.objects.create(team=self.team, status=SignalReport.Status.READY, title="pipeline report")
+ first_run = _make_run(self.team)
+ second_run = _make_run(self.team)
+ for i, run in enumerate((first_run, second_run)):
+ response = self.client.post(
+ self._edit_url(str(run.id)),
+ data={"report_id": str(report.id), "append_note": f"scout context {i}"},
+ format="json",
+ )
+ assert response.status_code == status.HTTP_200_OK, response.json()
+ artefacts = SignalReportArtefact.objects.filter(
+ report_id=report.id, type=SignalReportArtefact.ArtefactType.TASK_RUN
+ ).order_by("created_at")
+ contents = [TaskRunArtefact.model_validate_json(a.content) for a in artefacts]
+ assert [(c.task_id, c.run_id) for c in contents] == [
+ (str(run.task_run.task_id), str(run.task_run_id)) for run in (first_run, second_run)
+ ]
+ assert all(c.product == "signals" and c.type == "scout" for c in contents)
def test_edit_report_fails_closed_on_cross_team_report(self) -> None:
other_org = Organization.objects.create(name="other")
diff --git a/products/signals/backend/test/test_scout_report_persistence.py b/products/signals/backend/test/test_scout_report_persistence.py
index cfb425f60768..c8d5bb32954e 100644
--- a/products/signals/backend/test/test_scout_report_persistence.py
+++ b/products/signals/backend/test/test_scout_report_persistence.py
@@ -12,7 +12,12 @@ from parameterized import parameterized
from posthog.models import Organization, Team
from posthog.models.scoping import team_scope
-from products.signals.backend.artefact_schemas import ActionabilityAssessment, ActionabilityChoice, SafetyJudgment
+from products.signals.backend.artefact_schemas import (
+ ActionabilityAssessment,
+ ActionabilityChoice,
+ SafetyJudgment,
+ TaskRunArtefact,
+)
from products.signals.backend.models import (
ArtefactAttribution,
SignalReport,
@@ -117,6 +122,18 @@ class TestScoutReportPersistence(BaseTest):
note = SignalReportArtefact.objects.get(report_id=result.report_id, type=SignalReportArtefact.ArtefactType.NOTE)
assert str(note.task_id) == task_id
+ # The authoring run itself is linked as a `task_run` artefact — without it the report's Runs
+ # section has no way to surface the scout's transcript.
+ task_run_artefact = SignalReportArtefact.objects.get(
+ report_id=result.report_id, type=SignalReportArtefact.ArtefactType.TASK_RUN
+ )
+ content = TaskRunArtefact.model_validate_json(task_run_artefact.content)
+ assert content.task_id == task_id
+ assert content.run_id == str(run.task_run_id)
+ assert content.product == "signals"
+ assert content.type == "scout"
+ assert str(task_run_artefact.task_id) == task_id
+
run.refresh_from_db()
assert run.emitted_report_ids == [result.report_id]