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.

refactor(signals): route scout report edits through the report author (#113082)

posthog[bot]495cec6644ed
diff --git a/products/signals/backend/scout_harness/tools/report.py b/products/signals/backend/scout_harness/tools/report.py
index 1f2b24a3de1d..8dc3dc1a68ec 100644
--- a/products/signals/backend/scout_harness/tools/report.py
+++ b/products/signals/backend/scout_harness/tools/report.py
@@ -95,12 +95,11 @@ from products.signals.backend.scout_harness.tools.emit import (
SOURCE_PRODUCT,
SOURCE_TYPE,
# Shared harness gates/attribution — the report channel applies the same preflight as emit.
- _assert_team_owns_run,
_preflight_emit_gates,
remediation_for_skip,
)
from products.signals.backend.scout_harness.tools.notes import MAX_NOTE_CONTENT_LENGTH
-from products.signals.backend.scout_harness.tools.report_author import ReportAuthor, ScoutRunReportAuthor
+from products.signals.backend.scout_harness.tools.report_author import ReportAuthor
from products.signals.backend.scout_harness.trial_gateway import create_trial_gateway_token, revoke_trial_gateway_token
from products.signals.backend.scout_report import (
INFERRED_REPOSITORY_REASON,
@@ -384,6 +383,11 @@ def _trial_store(run: SignalScoutRun) -> ScoutTrialStore | None:
return ScoutTrialStore(run) if is_scout_trial(run) else None
+def _author_trial_store(author: ReportAuthor) -> ScoutTrialStore | None:
+ run = author.scout_run
+ return _trial_store(run) if run is not None else None
+
+
def _reject_trial_report_links(store: ScoutTrialStore | None, links: Sequence[ReportLinkInput] | None) -> None:
if store is not None and links:
store.invalidate("Report links are not supported by private capture; this run cannot be compared.")
@@ -393,7 +397,7 @@ def _reject_trial_report_links(store: ScoutTrialStore | None, links: Sequence[Re
def _private_report_gateway(function: Callable[_Parameters, _Return]) -> Callable[_Parameters, _Return]:
@wraps(function)
def wrapped(*args: _Parameters.args, **kwargs: _Parameters.kwargs) -> _Return:
- run = getattr(kwargs.get("author"), "scout_run", kwargs.get("run"))
+ run = getattr(kwargs.get("author"), "scout_run", None)
if not isinstance(run, SignalScoutRun) or _trial_store(run) is None:
return function(*args, **kwargs)
with private_capture_context():
@@ -412,7 +416,7 @@ def _private_report_gateway_async(
) -> Callable[_Parameters, Awaitable[_Return]]:
@wraps(function)
async def wrapped(*args: _Parameters.args, **kwargs: _Parameters.kwargs) -> _Return:
- run = getattr(kwargs.get("author"), "scout_run", kwargs.get("run"))
+ run = getattr(kwargs.get("author"), "scout_run", None)
if not isinstance(run, SignalScoutRun) or _trial_store(run) is None:
return await function(*args, **kwargs)
with private_capture_context():
@@ -1808,7 +1812,7 @@ def _capture_report_emitted(
def _capture_report_edited(
*,
team: Team,
- run: SignalScoutRun,
+ author: ReportAuthor,
result: EditReportResult,
title: str | None,
summary: str | None,
@@ -1837,7 +1841,6 @@ def _capture_report_edited(
streams stay quiet rather than telling a CDP destination a report changed when it didn't."""
if not result.changed:
return None
- author = ScoutRunReportAuthor(run=run)
properties = {
**author.event_properties(),
**_report_classification_props(result.report_title),
@@ -1891,7 +1894,15 @@ def _capture_report_edited(
# title/summary/note, so two distinct reviewer corrections to the same report in one run would
# otherwise hash identically and ingestion would collapse the later routing change; key on the
# reviewer identity too (only when reviewers were set, so non-reviewer edits keep their existing uuid).
- parts: list[object] = ["edit", run.id, result.report_id, sorted(result.updated_fields), title, summary, note]
+ parts: list[object] = [
+ "edit",
+ author.idempotency_scope,
+ result.report_id,
+ sorted(result.updated_fields),
+ title,
+ summary,
+ note,
+ ]
if result.reviewers_set and suggested_reviewers:
parts.append(",".join(sorted(f"{r.github_login or ''}:{r.user_uuid or ''}" for r in suggested_reviewers)))
# Evidence is a valid sole input too, so two evidence-only edits to one report in a run share
@@ -2378,7 +2389,7 @@ def emit_report_sync(
def _do_edit_report(
*,
team: Team,
- run: SignalScoutRun,
+ author: ReportAuthor,
report_id: str,
title: str | None,
summary: str | None,
@@ -2407,10 +2418,11 @@ def _do_edit_report(
bad reviewer fails before the judge spends an LLM call and before any write. None leaves existing
reviewers untouched; a supplied set replaces them verbatim (nothing injected), with owner
provenance stamped so a picked owner can't become the autostart identity."""
- _assert_edit_gates(team, run, report_id)
+ _assert_edit_gates(team, author, report_id)
if corroboration_only and not append_note:
raise InvalidScoutReportError("corroboration_only requires append_note")
- trial_store = _trial_store(run)
+ run = author.scout_run
+ trial_store = _author_trial_store(author)
if trial_store is not None:
return _capture_trial_edit(
store=trial_store,
@@ -2428,7 +2440,7 @@ def _do_edit_report(
corroboration_only=corroboration_only,
)
- attribution = ScoutRunReportAuthor(run=run).attribution()
+ attribution = author.attribution()
updated_fields: list[str] = []
note_appended = False
repository_set = False
@@ -2453,15 +2465,16 @@ def _do_edit_report(
# Cancellation also locks the TaskRun row before terminalizing it. Lock that same row through
# the report writes so cancellation and authorship have a defined order: if cancellation wins,
# this edit sees the terminal status and fails; if this edit wins, cancellation waits for it.
- locked_run = (
- SignalScoutRun.objects.for_team(team.id)
- .select_related("task_run")
- .select_for_update(of=("task_run",))
- .filter(pk=run.pk)
- .first()
- )
- if locked_run is None or locked_run.task_run.status != tasks_facade.TaskRunStatus.IN_PROGRESS:
- raise InvalidScoutReportError("edit_report blocked because the task run is not in progress")
+ if run is not None:
+ locked_run = (
+ SignalScoutRun.objects.for_team(team.id)
+ .select_related("task_run")
+ .select_for_update(of=("task_run",))
+ .filter(pk=run.pk)
+ .first()
+ )
+ if locked_run is None or locked_run.task_run.status != tasks_facade.TaskRunStatus.IN_PROGRESS:
+ raise InvalidScoutReportError("edit_report blocked because the task run is not in progress")
if title is not None or summary is not None:
# `reviewed` only when the judge saw the whole document this save re-embeds — the
# entrypoints judged exactly the title/summary supplied. A partial edit merges with a
@@ -2488,14 +2501,14 @@ def _do_edit_report(
supersede_requested=supersedes_implementation,
updated_fields=updated_fields,
attribution=attribution,
- author=run.skill_name,
+ author=author.skill_name,
implementation_context=implementation_context,
)
# Re-stamp owner provenance from the live owner set at the write: the safety-judge call sits
# between resolution and this transaction, autostart trusts the stored stamp, and an owner
# added during that wait must not remain an identity candidate.
if reviewers is not None:
- reviewers = _stamp_owner_provenance(team, reviewers, skill_name=run.skill_name)
+ reviewers = _stamp_owner_provenance(team, reviewers, skill_name=author.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 after
# the fact. `reviewers` is None for empty/all-blank input, which leaves existing ones untouched.
@@ -2505,7 +2518,7 @@ def _do_edit_report(
report_id=report_id,
suggested_reviewers=reviewers,
attribution=attribution,
- author=run.skill_name,
+ author=author.skill_name,
)
if reviewers is not None
else False
@@ -2519,7 +2532,7 @@ def _do_edit_report(
report_id=report_id,
repository=None if repository == NO_REPO else repository,
attribution=attribution,
- author=run.skill_name,
+ author=author.skill_name,
)
# The work decision auto-start reads. In the same transaction as the content, so a rewrite
# and the judgment it supports land together or not at all.
@@ -2530,7 +2543,7 @@ def _do_edit_report(
actionability=actionability,
priority=priority,
attribution=attribution,
- author=run.skill_name,
+ author=author.skill_name,
)
if append_note is not None:
appended = append_report_note(
@@ -2538,7 +2551,7 @@ def _do_edit_report(
report_id=report_id,
note=append_note,
attribution=attribution,
- author=run.skill_name,
+ author=author.skill_name,
corroboration_only=corroboration_only,
)
note_appended = True
@@ -2551,7 +2564,7 @@ def _do_edit_report(
report_id=report_id,
signals=append_evidence,
attribution=attribution,
- author=run.skill_name,
+ author=author.skill_name,
)
# Additive like the evidence above. A link is a fact about two reports, so a later edit
# adds another rather than replacing the set, and `unlink` is how one comes back off.
@@ -2571,7 +2584,7 @@ def _do_edit_report(
report_id=report_id,
charts=charts,
attribution=attribution,
- author=run.skill_name,
+ author=author.skill_name,
)
if metrics is not None:
metrics_changed = set_report_metrics(
@@ -2579,7 +2592,7 @@ def _do_edit_report(
report_id=report_id,
metrics=metrics,
attribution=attribution,
- author=run.skill_name,
+ author=author.skill_name,
)
# Same replace-don't-append contract as the charts above: omitting the field keeps the
# report's prompts, an explicit empty list takes them down.
@@ -2589,7 +2602,7 @@ def _do_edit_report(
report_id=report_id,
suggested_prompts=suggested_prompts,
attribution=attribution,
- author=run.skill_name,
+ author=author.skill_name,
)
# `content_revision_count` is the report's running total, the number the scout reasons about
# the cap with. A revision above already set it to the report's new total; every other edit
@@ -2630,7 +2643,7 @@ def _do_edit_report(
# short as one status read. If the slow work ran first, that earlier delivery could read the freshly
# committed edit, still find no marker, and post the edited report — the same content this edit's
# own delivery then posts a second time.
- if changed:
+ if changed and run is not None:
# Mirror emit's surfaced gate: an edit to a suppressed / never-surfaced report must not push
# its content to a configured destination. The delivery worker re-checks status at send time
# (the report can be suppressed after enqueue), so this mainly keeps the two paths symmetric
@@ -2681,7 +2694,7 @@ def _do_edit_report(
report_id=report_id,
signals=append_evidence or [],
document_ids=evidence_document_ids,
- skill_name=run.skill_name,
+ skill_name=author.skill_name,
)
# A rewrite can move the report onto a different repository, and an inferred target is only ever a
# reading of that text. Outside the transaction above for the same reason autostart is: it reads
@@ -2743,7 +2756,7 @@ def _do_edit_report(
# own owners out of the exclusion. Both writes swallow their own failures, so they can't block
# autostart. The Slack delivery for this edit was already enqueued above, so a prior in-flight
# delivery sees the supersede marker rather than posting the edit a second time.
- if changed:
+ if changed and run is not None:
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.
@@ -2815,7 +2828,7 @@ def _do_edit_report(
return result
-def _assert_edit_gates(team: Team, run: SignalScoutRun, report_id: str, appended_evidence: int = 0) -> None:
+def _assert_edit_gates(team: Team, author: ReportAuthor, report_id: str, appended_evidence: int = 0) -> None:
"""The emit preflight gates, applied to an edit. Shared by the entrypoints (which must gate
before spending the safety-judge LLM call) and `_do_edit_report` (so a future caller that skips
the entrypoints still fails closed).
@@ -2824,23 +2837,29 @@ def _assert_edit_gates(team: Team, run: SignalScoutRun, report_id: str, appended
An edit blocked by a gate is the identical situation, because the scout has done the work and
the write will not land, so a bare reason code here would leave it with no next step on one
channel and a fixable one on the other."""
- preflight = _preflight_report_emission(team, run)
+ run = author.scout_run
+ trial_store = _author_trial_store(author)
+ preflight = (
+ _preflight_report_emission(team, trial_store.run)
+ if trial_store is not None
+ else author.preflight_skip_reason(team)
+ )
if preflight is not None:
remediation = remediation_for_skip(preflight)
detail = f"edit_report blocked by preflight gate: {preflight}"
raise InvalidScoutReportError(f"{detail}. {remediation}" if remediation else detail)
- task_is_in_progress = (
- SignalScoutRun.objects.for_team(team.id)
- .filter(
- pk=run.pk,
- task_run_id=run.task_run_id,
- task_run__status=tasks_facade.TaskRunStatus.IN_PROGRESS,
+ if run is not None:
+ task_is_in_progress = (
+ SignalScoutRun.objects.for_team(team.id)
+ .filter(
+ pk=run.pk,
+ task_run_id=run.task_run_id,
+ task_run__status=tasks_facade.TaskRunStatus.IN_PROGRESS,
+ )
+ .exists()
)
- .exists()
- )
- if not task_is_in_progress:
- raise InvalidScoutReportError("edit_report blocked because the task run is not in progress")
- trial_store = _trial_store(run)
+ if not task_is_in_progress:
+ raise InvalidScoutReportError("edit_report blocked because the task run is not in progress")
if trial_store is not None:
report = _trial_report_for_edit(trial_store, report_id)
count = report.document.get("signal_count", 0)
@@ -2882,7 +2901,7 @@ def _raise_if_unsafe_edit(safety: SafetyJudgment) -> None:
def _validate_edit_inputs(
team: Team,
- run: SignalScoutRun,
+ author: ReportAuthor,
title,
summary,
append_note,
@@ -2899,8 +2918,8 @@ def _validate_edit_inputs(
priority=None,
priority_explanation=None,
) -> None:
- _assert_team_owns_run(team, run)
- trial_store = _trial_store(run)
+ author.assert_owned_by(team)
+ trial_store = _author_trial_store(author)
_reject_trial_report_links(trial_store, links)
if trial_store is not None:
validate_scout_report_text("title", title)
@@ -2951,7 +2970,7 @@ def _validate_edit_inputs(
async def edit_report(
*,
team: Team,
- run: SignalScoutRun,
+ author: ReportAuthor,
report_id: str,
title: str | None = None,
summary: str | None = None,
@@ -2981,7 +3000,7 @@ async def edit_report(
had."""
await database_sync_to_async(_validate_edit_inputs, thread_sensitive=False)(
team,
- run,
+ author,
title,
summary,
append_note,
@@ -3013,12 +3032,12 @@ async def edit_report(
built_metrics = _build_edit_metrics(allowed_metrics)
# Gates before the judge, mirroring emit: a disabled or dry-run scout must not spend an LLM call.
await database_sync_to_async(_assert_edit_gates, thread_sensitive=False)(
- team, run, report_id, len(built_evidence or [])
+ team, author, report_id, len(built_evidence or [])
)
# Reviewers resolve before the judge too: resolution is the one step that rejects caller input
# (an unresolvable user_uuid 400s), so a bad reviewer must not cost a judge call first.
built_reviewers = await database_sync_to_async(_build_suggested_reviewers, thread_sensitive=False)(
- team, suggested_reviewers, skill_name=run.skill_name
+ team, suggested_reviewers, skill_name=author.skill_name
)
_raise_if_unsafe_edit(
await judge_edited_report_content(
@@ -3037,7 +3056,7 @@ async def edit_report(
)
result = await database_sync_to_async(_do_edit_report, thread_sensitive=False)(
team=team,
- run=run,
+ author=author,
report_id=report_id,
title=title,
summary=summary,
@@ -3054,11 +3073,11 @@ async def edit_report(
actionability=built_actionability,
priority=built_priority,
)
- if _trial_store(run) is not None:
+ if _author_trial_store(author) is not None:
return result
forward = await database_sync_to_async(_capture_report_edited, thread_sensitive=False)(
team=team,
- run=run,
+ author=author,
result=result,
title=title,
summary=summary,
@@ -3082,7 +3101,7 @@ async def edit_report(
def edit_report_sync(
*,
team: Team,
- run: SignalScoutRun,
+ author: ReportAuthor,
report_id: str,
title: str | None = None,
summary: str | None = None,
@@ -3105,7 +3124,7 @@ def edit_report_sync(
"""Sync entry used by the DRF view path. Same behavior as `edit_report`, on the calling thread."""
_validate_edit_inputs(
team,
- run,
+ author,
title,
summary,
append_note,
@@ -3135,10 +3154,10 @@ def edit_report_sync(
allowed_metrics = _allowed_metrics(team, metrics)
built_metrics = _build_edit_metrics(allowed_metrics)
# Gates before the judge, mirroring emit: a disabled or dry-run scout must not spend an LLM call.
- _assert_edit_gates(team, run, report_id, len(built_evidence or []))
+ _assert_edit_gates(team, author, report_id, len(built_evidence or []))
# Reviewers resolve before the judge too: resolution is the one step that rejects caller input
# (an unresolvable user_uuid 400s), so a bad reviewer must not cost a judge call first.
- built_reviewers = _build_suggested_reviewers(team, suggested_reviewers, skill_name=run.skill_name)
+ built_reviewers = _build_suggested_reviewers(team, suggested_reviewers, skill_name=author.skill_name)
_raise_if_unsafe_edit(
async_to_sync(judge_edited_report_content)(
team_id=team.id,
@@ -3156,7 +3175,7 @@ def edit_report_sync(
)
result = _do_edit_report(
team=team,
- run=run,
+ author=author,
report_id=report_id,
title=title,
summary=summary,
@@ -3173,11 +3192,11 @@ def edit_report_sync(
actionability=built_actionability,
priority=built_priority,
)
- if _trial_store(run) is not None:
+ if _author_trial_store(author) is not None:
return result
forward = _capture_report_edited(
team=team,
- run=run,
+ author=author,
result=result,
title=title,
summary=summary,
diff --git a/products/signals/backend/scout_harness/tools/report_author.py b/products/signals/backend/scout_harness/tools/report_author.py
index f73ea0a0b82a..f5168aec6e0d 100644
--- a/products/signals/backend/scout_harness/tools/report_author.py
+++ b/products/signals/backend/scout_harness/tools/report_author.py
@@ -1,9 +1,9 @@
"""Who authors a report through the report channel.
-`emit_report` reads every author-specific value through `ReportAuthor`: the idempotency scope, the
-telemetry identity, the preflight gates, and the artefact attribution. A scout run is the only author
-that exists. Another author, such as a user who calls the channel over the MCP, implements the same
-protocol, so the emit path does not fork on who wrote the report.
+`emit_report` and `edit_report` read every author-specific value through `ReportAuthor`: the
+idempotency scope, the telemetry identity, the preflight gates, and the artefact attribution. A scout
+run is the only author that exists. Another author, such as a user who calls the channel over the MCP,
+implements the same protocol, so neither path forks on who wrote the report.
"""
from __future__ import annotations
@@ -24,9 +24,10 @@ from products.signals.backend.scout_harness.tools.emit import (
class ReportAuthor(Protocol):
@property
def scout_run(self) -> SignalScoutRun | None:
- """The run behind the report. It feeds the run's report tally, the provenance note, the
- `task_run` artefact, and the scout's configured Slack destination. None when no scout run
- authors the report, which skips all four."""
+ """The run behind the report. It feeds the run's report and edit tallies, the provenance note,
+ the `task_run` artefact, the scout's configured Slack destination, private trial capture, and
+ the in-progress check that an edit runs under the run's lock. None when no scout run authors
+ the report, which skips all of them."""
...
@property
diff --git a/products/signals/backend/scout_harness/views.py b/products/signals/backend/scout_harness/views.py
index 0a4057a6d288..590f042c7ed7 100644
--- a/products/signals/backend/scout_harness/views.py
+++ b/products/signals/backend/scout_harness/views.py
@@ -1394,7 +1394,7 @@ class SignalScoutRunViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSet):
result = edit_report_sync(
# Canonical team, as in `emit_report` above — avoids a child-env `_assert_team_owns_run` trip.
team=run.team,
- run=run,
+ author=ScoutRunReportAuthor(run=run),
report_id=data["report_id"],
title=data.get("title"),
summary=data.get("summary"),
diff --git a/products/signals/backend/test/test_scout_report_api.py b/products/signals/backend/test/test_scout_report_api.py
index 816da077e14a..57538ab522ff 100644
--- a/products/signals/backend/test/test_scout_report_api.py
+++ b/products/signals/backend/test/test_scout_report_api.py
@@ -1,7 +1,7 @@
import json
from datetime import timedelta
from typing import Any
-from uuid import uuid4
+from uuid import NAMESPACE_URL, uuid4, uuid5
import pytest
from posthog.test.base import APIBaseTest
@@ -59,6 +59,7 @@ from products.signals.backend.scout_harness.tools.report import (
_wants_repo_selection,
edit_report_sync,
)
+from products.signals.backend.scout_harness.tools.report_author import ScoutRunReportAuthor
from products.signals.backend.scout_report import ScoutReportSignal
from products.signals.backend.task_run_artefacts import record_implementation_task
from products.signals.backend.temporal.report_safety_judge import SafetyJudgeResponse
@@ -1382,7 +1383,12 @@ class TestScoutReportAPI(APIBaseTest):
patch("products.signals.backend.scout_harness.tools.report._assert_edit_gates"),
pytest.raises(InvalidScoutReportError, match="not in progress"),
):
- edit_report_sync(team=self.team, run=run, report_id=created["report_id"], summary="Late rewrite")
+ edit_report_sync(
+ team=self.team,
+ author=ScoutRunReportAuthor(run=run),
+ report_id=created["report_id"],
+ summary="Late rewrite",
+ )
def _latest_artefact(self, report_id: str, artefact_type: str) -> SignalReportArtefact | None:
return (
@@ -1772,7 +1778,7 @@ class TestScoutReportAPI(APIBaseTest):
with patch(CAPTURE_PATH):
captured = _capture_report_edited(
team=self.team,
- run=run,
+ author=ScoutRunReportAuthor(run=run),
result=result,
title=None,
summary=None,
@@ -2057,6 +2063,11 @@ class TestScoutReportAPI(APIBaseTest):
assert forward.kwargs["token"] == self.team.api_token
assert forward.kwargs["process_person_profile"] is False
assert forward.kwargs["properties"]["report_url"].endswith(f"/inbox/reports/{created['report_id']}")
+ assert props["run_id"] == str(run.id)
+ assert forward.kwargs["distinct_id"] == f"signals_scout:{run.skill_name}"
+ # Ingestion dedupes on this uuid. If its key drifts, an edit retried across a deploy fires twice.
+ edit_key = f"edit|{run.id}|{created['report_id']}|['title', 'updated_at']|new title||re-validated"
+ assert forward.kwargs["event_uuid"] == str(uuid5(NAMESPACE_URL, f"signals_scout_report:{edit_key}"))
def test_self_improvement_report_classified_on_emit_and_edit(self) -> None:
# Classification must ride both lifecycle events: stamped from the authored title on emit, and
@@ -2089,7 +2100,7 @@ class TestScoutReportAPI(APIBaseTest):
with patch(CAPTURE_PATH):
captured = _capture_report_edited(
team=self.team,
- run=run,
+ author=ScoutRunReportAuthor(run=run),
result=result,
title=None,
summary=None,
@@ -2116,7 +2127,7 @@ class TestScoutReportAPI(APIBaseTest):
with patch(CAPTURE_PATH):
captured = _capture_report_edited(
team=self.team,
- run=run,
+ author=ScoutRunReportAuthor(run=run),
result=result,
title=None,
summary=None,
@@ -2159,7 +2170,7 @@ class TestScoutReportAPI(APIBaseTest):
with patch(CAPTURE_PATH):
captured = _capture_report_edited(
team=self.team,
- run=run,
+ author=ScoutRunReportAuthor(run=run),
result=result,
title=None,
summary=None,
@@ -2327,7 +2338,7 @@ class TestScoutReportAPI(APIBaseTest):
with patch(CAPTURE_PATH):
captured = _capture_report_edited(
team=self.team,
- run=run,
+ author=ScoutRunReportAuthor(run=run),
result=result,
title=None,
summary=None,
@@ -2349,7 +2360,7 @@ class TestScoutReportAPI(APIBaseTest):
with patch(CAPTURE_PATH):
chart_clear = _capture_report_edited(
team=self.team,
- run=run,
+ author=ScoutRunReportAuthor(run=run),
result=EditReportResult(
report_id=result.report_id, updated_fields=[], note_appended=False, charts_set=0
),
@@ -2373,7 +2384,7 @@ class TestScoutReportAPI(APIBaseTest):
with patch(CAPTURE_PATH):
captured = _capture_report_edited(
team=self.team,
- run=run,
+ author=ScoutRunReportAuthor(run=run),
result=EditReportResult(
report_id=report_id,
updated_fields=[],
diff --git a/products/signals/backend/test/test_scout_trial_state.py b/products/signals/backend/test/test_scout_trial_state.py
index e528128486b8..542599cf06d3 100644
--- a/products/signals/backend/test/test_scout_trial_state.py
+++ b/products/signals/backend/test/test_scout_trial_state.py
@@ -276,7 +276,7 @@ class TestScoutTrialReportCapture(APIBaseTest):
assert self.judge.call_count == 1
result = edit_report_sync(
team=self.team,
- run=self.scout_run,
+ author=ScoutRunReportAuthor(run=self.scout_run),
report_id=report_id,
summary="A revised synthetic explanation.",
append_note="A second fixture confirms it.",
@@ -318,7 +318,9 @@ class TestScoutTrialReportCapture(APIBaseTest):
with time_machine.travel("2026-09-01T12:00:00Z", tick=False):
report_id = self._emit()
with time_machine.travel("2026-09-01T13:00:00Z", tick=False):
- result = edit_report_sync(team=self.team, run=self.scout_run, report_id=report_id, **change)
+ result = edit_report_sync(
+ team=self.team, author=ScoutRunReportAuthor(run=self.scout_run), report_id=report_id, **change
+ )
assert result.changed
draft = self.store.get_report(report_id)
assert draft is not None
@@ -337,7 +339,7 @@ class TestScoutTrialReportCapture(APIBaseTest):
)
unchanged = edit_report_sync(
team=self.team,
- run=self.scout_run,
+ author=ScoutRunReportAuthor(run=self.scout_run),
report_id=str(original.id),
title=original.title,
)
@@ -347,7 +349,7 @@ class TestScoutTrialReportCapture(APIBaseTest):
assert unchanged_draft.artefacts == []
edit_report_sync(
team=self.team,
- run=self.scout_run,
+ author=ScoutRunReportAuthor(run=self.scout_run),
report_id=str(original.id),
title="Privately revised title",
append_note="Private supporting note",
@@ -369,7 +371,12 @@ class TestScoutTrialReportCapture(APIBaseTest):
)
with pytest.raises(InvalidScoutReportError, match="not found"):
- edit_report_sync(team=self.team, run=self.scout_run, report_id=str(original.id), title="Private revision")
+ edit_report_sync(
+ team=self.team,
+ author=ScoutRunReportAuthor(run=self.scout_run),
+ report_id=str(original.id),
+ title="Private revision",
+ )
assert self.store.get_report(str(original.id)) is None
self.judge.assert_not_awaited()
@@ -386,7 +393,7 @@ class TestScoutTrialReportCapture(APIBaseTest):
)
edit_report_sync(
team=self.team,
- run=self.scout_run,
+ author=ScoutRunReportAuthor(run=self.scout_run),
report_id=str(original.id),
title="Private revision",
append_evidence=[ReportEvidence(description="Private observation", source_id="private-observation")],
@@ -417,13 +424,23 @@ class TestScoutTrialReportCapture(APIBaseTest):
def test_private_evidence_cap_includes_new_production_evidence(self) -> None:
original = SignalReport.objects.create(team=self.team, title="Source report", signal_count=1)
evidence = [ReportEvidence(description="Private observation", source_id="private-observation")]
- edit_report_sync(team=self.team, run=self.scout_run, report_id=str(original.id), append_evidence=evidence)
+ edit_report_sync(
+ team=self.team,
+ author=ScoutRunReportAuthor(run=self.scout_run),
+ report_id=str(original.id),
+ append_evidence=evidence,
+ )
before = self.store.get_report(str(original.id))
SignalReport.objects.filter(pk=original.id).update(signal_count=MAX_REPORT_SIGNALS - 1)
self.judge.reset_mock()
with pytest.raises(InvalidScoutReportError, match="cap"):
- edit_report_sync(team=self.team, run=self.scout_run, report_id=str(original.id), append_evidence=evidence)
+ edit_report_sync(
+ team=self.team,
+ author=ScoutRunReportAuthor(run=self.scout_run),
+ report_id=str(original.id),
+ append_evidence=evidence,
+ )
self.judge.assert_not_awaited()
assert self.store.get_report(str(original.id)) == before
@@ -438,7 +455,7 @@ class TestScoutTrialReportCapture(APIBaseTest):
with pytest.raises(InvalidScoutReportError, match="Implementation replacement is not supported"):
edit_report_sync(
team=self.team,
- run=self.scout_run,
+ author=ScoutRunReportAuthor(run=self.scout_run),
report_id=report_id,
summary="A private revision",
supersedes_implementation=True,
@@ -480,7 +497,7 @@ class TestScoutTrialReportCapture(APIBaseTest):
):
result = edit_report_sync(
team=self.team,
- run=self.scout_run,
+ author=ScoutRunReportAuthor(run=self.scout_run),
report_id=report_id,
repository=initial_repo if explicit else None,
summary=None if explicit else "Issue traced to https://github.com/example/gadgets/pull/2",
@@ -494,7 +511,12 @@ class TestScoutTrialReportCapture(APIBaseTest):
assert selection["content"]["autostart_eligible"] is explicit
if explicit:
assert selection["content"]["reason"] == SCOUT_REPOSITORY_REASON
- retry = edit_report_sync(team=self.team, run=self.scout_run, report_id=report_id, repository=initial_repo)
+ retry = edit_report_sync(
+ team=self.team,
+ author=ScoutRunReportAuthor(run=self.scout_run),
+ report_id=report_id,
+ repository=initial_repo,
+ )
assert not retry.repository_set
retried = self.store.get_report(report_id)
assert retried is not None
@@ -546,7 +568,7 @@ class TestScoutTrialReportCapture(APIBaseTest):
with self.assertRaises(InvalidScoutReportError):
edit_report_sync(
team=self.team,
- run=self.scout_run,
+ author=ScoutRunReportAuthor(run=self.scout_run),
report_id=report_id,
title=value if field == "title" else None,
summary=value if field == "summary" else None,
@@ -559,7 +581,12 @@ class TestScoutTrialReportCapture(APIBaseTest):
self.judge.return_value = SafetyJudgeResponse(choice=False, explanation="Rejected synthetic instruction")
with self.assertRaisesMessage(InvalidScoutReportError, "rejected by the safety judge"):
- edit_report_sync(team=self.team, run=self.scout_run, report_id=report_id, summary="Rejected replacement")
+ edit_report_sync(
+ team=self.team,
+ author=ScoutRunReportAuthor(run=self.scout_run),
+ report_id=report_id,
+ summary="Rejected replacement",
+ )
draft = self.store.get_report(report_id)
assert draft is not None
assert draft.document["summary"] == "The synthetic checkout handler returns an incorrect total."
@@ -591,7 +618,9 @@ class TestScoutTrialReportCapture(APIBaseTest):
):
if operation == "edit":
assert report_id is not None
- edit_report_sync(team=self.team, run=self.scout_run, report_id=report_id, links=links)
+ edit_report_sync(
+ team=self.team, author=ScoutRunReportAuthor(run=self.scout_run), report_id=report_id, links=links
+ )
else:
self._emit(links=links)
assert self.store.invalid_reason() is not None
@@ -650,7 +679,12 @@ class TestScoutTrialReportCapture(APIBaseTest):
team=self.team, title="Source report", status=SignalReport.Status.READY, metrics=[metric]
)
report_id = str(original.id)
- edit_report_sync(team=self.team, run=self.scout_run, report_id=report_id, title="Private revision")
+ edit_report_sync(
+ team=self.team,
+ author=ScoutRunReportAuthor(run=self.scout_run),
+ report_id=report_id,
+ title="Private revision",
+ )
if mode != "source":
def set_metrics(report: TrialReport) -> None:
@@ -692,7 +726,10 @@ class TestScoutTrialReportCapture(APIBaseTest):
second = SignalReport.objects.create(team=self.team, title="Second report", summary="Original", status="ready")
private_id = self._emit()
edit_report_sync(
- team=self.team, run=self.scout_run, report_id=str(first.id), title="A synthetic checkout revision"
+ team=self.team,
+ author=ScoutRunReportAuthor(run=self.scout_run),
+ report_id=str(first.id),
+ title="A synthetic checkout revision",
)
base = f"/api/projects/{self.team.id}/signals/reports/"
with (
@@ -749,7 +786,10 @@ class TestScoutTrialReportCapture(APIBaseTest):
)
for report in (kept, dropped):
edit_report_sync(
- team=self.team, run=self.scout_run, report_id=str(report.id), title=f"Revised {report.title}"
+ team=self.team,
+ author=ScoutRunReportAuthor(run=self.scout_run),
+ report_id=str(report.id),
+ title=f"Revised {report.title}",
)
with (
patch("products.signals.backend.views.trial_store_for_request", return_value=self.store),
@@ -805,7 +845,9 @@ def test_async_report_links_invalidate_comparison(team: Team, operation: str) ->
links=links,
)
else:
- async_to_sync(edit_report)(team=team, run=run, report_id=str(uuid4()), links=links)
+ async_to_sync(edit_report)(
+ team=team, author=ScoutRunReportAuthor(run=run), report_id=str(uuid4()), links=links
+ )
assert ScoutTrialStore(run).invalid_reason() is not None
link_targets.assert_not_called()
judge.assert_not_called()