: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
fix(signals): write scout title and summary edits as typed artefacts (#89716)
posthog[bot]d3598eddcf81
diff --git a/products/signals/backend/scout_harness/tools/report.py b/products/signals/backend/scout_harness/tools/report.pyindex b48f05751975..97eb05236cf4 100644--- a/products/signals/backend/scout_harness/tools/report.py+++ b/products/signals/backend/scout_harness/tools/report.py@@ -1349,7 +1349,6 @@ def _do_edit_report(title=title,summary=summary,attribution=attribution,- author=run.skill_name,)# Replace the report's `suggested_reviewers` status artefact (latest-wins). This is the routing# fix — a report authored without a reviewer (so it routes to no one) can have one added afterdiff --git a/products/signals/backend/scout_report/persistence.py b/products/signals/backend/scout_report/persistence.pyindex 8c8d4861e978..c969c3ce8717 100644--- a/products/signals/backend/scout_report/persistence.py+++ b/products/signals/backend/scout_report/persistence.py@@ -49,7 +49,9 @@ from products.signals.backend.artefact_schemas import (SafetyJudgment,SuggestedReviewerEntry,SuggestedReviewers,+ SummaryChange,TaskRunArtefact,+ TitleChange,)from products.signals.backend.models import ArtefactAttribution, SignalReport, SignalReportArtefact, SignalScoutRunfrom products.signals.backend.report_charts import ReportChart, chart_batch_error@@ -310,7 +312,6 @@ def update_scout_report(title: str | None = None,summary: str | None = None,attribution: ArtefactAttribution | None = None,- author: str | None = None,) -> list[str]:"""Rewrite an existing report's `title`/`summary` in place (the `edit_report` content path).@@ -318,10 +319,11 @@ def update_scout_report(the modified field names. Title/summary edits are best-effort authorship — the pipeline may laterre-research and overwrite them (decision #6); that is documented in the scout-facing contract.- When `attribution` is supplied and the content actually changes, an audit note is appended to the- report's work log recording who rewrote what — `edit_report` can target ANY inbox report (pipeline-- authored included), so a core-content rewrite must leave a durable, attributable trail, not just a- silent field mutation.+ When `attribution` is supplied and the content actually changes, a typed `title_change` /+ `summary_change` artefact is appended to the report's work log for each edited field, recording the+ value before and after — the same shape the human PATCH path writes. `edit_report` can target ANY+ inbox report (pipeline-authored included), so a core-content rewrite must leave a durable,+ attributable, machine-readable trail, not just a silent field mutation."""if title is None and summary is None:return []@@ -333,6 +335,8 @@ def update_scout_report(report = SignalReport.objects.select_for_update().filter(team_id=team_id, id=report_id).first()if report is None:raise InvalidScoutReportError(f"report {report_id} not found for team {team_id}")+ # Captured before the in-place mutation so each edit artefact carries the value before and after.+ old_title, old_summary = report.title, report.summaryupdated_fields = report.update_authored_content(title=title, summary=summary)if updated_fields:# Agent-authored text that the safety judge has not seen; the report's existing verdict was@@ -341,12 +345,18 @@ def update_scout_report(report._unreviewed_edit = True # type: ignore[attr-defined]report.save(update_fields=updated_fields)if attribution is not None:- SignalReportArtefact.add_log(- team_id=team_id,- report_id=report_id,- content=NoteArtefact(note=_content_edit_note(updated_fields), author=author),- attribution=attribution,- )+ edit_artefacts: list[TitleChange | SummaryChange] = []+ if "title" in updated_fields:+ edit_artefacts.append(TitleChange(old_title=old_title, new_title=report.title))+ if "summary" in updated_fields:+ edit_artefacts.append(SummaryChange(old_summary=old_summary, new_summary=report.summary))+ for content in edit_artefacts:+ SignalReportArtefact.add_log(+ team_id=team_id,+ report_id=report_id,+ content=content,+ attribution=attribution,+ )logger.info("signals_scout.edit_report: content updated",@@ -884,10 +894,6 @@ def _validate_optional_text(field_name: str, value: str | None) -> None:raise InvalidScoutReportError(f"{field_name} must not be empty when provided")-def _content_edit_note(updated_fields: list[str]) -> str:- return f"Edited report {' and '.join(updated_fields)} via edit_report."--def _chart_edit_note(count: int) -> str:if count == 0:return "Removed the report's charts via edit_report."diff --git a/products/signals/backend/test/test_scout_report_persistence.py b/products/signals/backend/test/test_scout_report_persistence.pyindex 0805669044df..f2eb60f3e196 100644--- a/products/signals/backend/test/test_scout_report_persistence.py+++ b/products/signals/backend/test/test_scout_report_persistence.py@@ -18,7 +18,9 @@ from products.signals.backend.artefact_schemas import (SafetyJudgment,SuggestedReviewerEntry,SuggestedReviewers,+ SummaryChange,TaskRunArtefact,+ TitleChange,)from products.signals.backend.models import (ArtefactAttribution,@@ -243,13 +245,39 @@ class TestScoutReportPersistence(BaseTest):attribution=ArtefactAttribution.system(),)updated = update_scout_report(- team_id=self.team.id, report_id=result.report_id, title="new title", summary="new summary"+ team_id=self.team.id,+ report_id=result.report_id,+ title="new title",+ summary="new summary",+ attribution=ArtefactAttribution.system(),)assert set(updated) == {"title", "summary", "updated_at"}report = SignalReport.objects.get(id=result.report_id)assert report.title == "new title"assert report.summary == "new summary"+ # The edit is logged as typed title_change / summary_change artefacts carrying the value before+ # and after — the same machine-readable shape the human PATCH path writes, not a prose note.+ title_change = SignalReportArtefact.objects.get(+ report_id=result.report_id, type=SignalReportArtefact.ArtefactType.TITLE_CHANGE+ )+ assert TitleChange.model_validate_json(title_change.content) == TitleChange(+ old_title="old title", new_title="new title"+ )+ summary_change = SignalReportArtefact.objects.get(+ report_id=result.report_id, type=SignalReportArtefact.ArtefactType.SUMMARY_CHANGE+ )+ assert SummaryChange.model_validate_json(summary_change.content) == SummaryChange(+ old_summary="old summary", new_summary="new summary"+ )+ # The edit adds no prose note — only the one provenance note the create path wrote survives.+ assert (+ SignalReportArtefact.objects.filter(+ report_id=result.report_id, type=SignalReportArtefact.ArtefactType.NOTE+ ).count()+ == 1+ )+def test_update_fails_closed_on_cross_team_report(self) -> None:# edit_report can target any inbox report (decision #2) — so the team scope is the only thing# standing between a scout and another team's report. A cross-team id must raise, not no-op.