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): Spawn fresh report on recurrence (#71981)

Michael Matloka1de7ec967808
diff --git a/frontend/src/scenes/inbox/components/detail/artefactTypes.ts b/frontend/src/scenes/inbox/components/detail/artefactTypes.ts
index 876f43dd6e55..9b06035ba132 100644
--- a/frontend/src/scenes/inbox/components/detail/artefactTypes.ts
+++ b/frontend/src/scenes/inbox/components/detail/artefactTypes.ts
@@ -87,6 +87,7 @@ export const ARTEFACT_TYPE_LABELS: Record<string, string> = {
video_segment: 'Video segment',
title_change: 'Title edited',
summary_change: 'Summary edited',
+ related_to: 'Related report',
}
export function artefactTypeLabel(type: string): string {
diff --git a/products/signals/backend/artefact_schemas.py b/products/signals/backend/artefact_schemas.py
index 2437cba7e6c4..2cfa3cb83169 100644
--- a/products/signals/backend/artefact_schemas.py
+++ b/products/signals/backend/artefact_schemas.py
@@ -450,6 +450,25 @@ class SummaryChange(BaseModel):
return v
+class RelatedTo(BaseModel):
+ """Content schema for a `related_to` artefact: an untyped link from this report to another
+ `SignalReport`. Written symmetrically (both reports get an entry pointing at the other), so the
+ link is discoverable from either side without a model change and the grouping dataset can be
+ reconstructed later. Direction isn't tracked — the two rows' `created_at` order captures it. The
+ grouping pipeline writes this pair when a signal that would have grouped into an already-resolved
+ report spawns a fresh report instead (resolved reports never reopen).
+ """
+
+ report_id: str = Field(description="UUID of the related SignalReport.")
+
+ @field_validator("report_id")
+ @classmethod
+ def report_id_must_not_be_empty(cls, v: str) -> str:
+ if not v.strip():
+ raise ValueError("must not be empty or whitespace-only")
+ return v
+
+
class CodeReviewCounts(BaseModel):
"""One review turn's valid findings by effective priority (threshold-independent)."""
@@ -496,7 +515,9 @@ class CodeReview(BaseModel):
StatusArtefactContent = (
SafetyJudgment | ActionabilityAssessment | PriorityAssessment | RepoSelectionResult | SuggestedReviewers
)
-LogArtefactContent = CodeReference | Commit | TaskRunArtefact | NoteArtefact | TitleChange | SummaryChange | CodeReview
+LogArtefactContent = (
+ CodeReference | Commit | TaskRunArtefact | NoteArtefact | TitleChange | SummaryChange | CodeReview | RelatedTo
+)
ArtefactContent = StatusArtefactContent | LogArtefactContent | SignalFinding | Dismissal | VideoSegment
# Keys are `SignalReportArtefact.ArtefactType` values, kept as plain strings so this module stays
@@ -517,6 +538,7 @@ ARTEFACT_CONTENT_SCHEMAS: Mapping[str, type[BaseModel]] = {
"title_change": TitleChange,
"summary_change": SummaryChange,
"code_review": CodeReview,
+ "related_to": RelatedTo,
}
_ARTEFACT_TYPE_BY_MODEL: Mapping[type[BaseModel], str] = {model: t for t, model in ARTEFACT_CONTENT_SCHEMAS.items()}
diff --git a/products/signals/backend/migrations/0063_alter_signalreportartefact_type.py b/products/signals/backend/migrations/0063_alter_signalreportartefact_type.py
new file mode 100644
index 000000000000..2e8e88a500e9
--- /dev/null
+++ b/products/signals/backend/migrations/0063_alter_signalreportartefact_type.py
@@ -0,0 +1,35 @@
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("signals", "0062_add_analytics_anomaly_investigation_source"),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name="signalreportartefact",
+ name="type",
+ field=models.CharField(
+ choices=[
+ ("video_segment", "Video Segment"),
+ ("safety_judgment", "Safety Judgment"),
+ ("actionability_judgment", "Actionability Judgment"),
+ ("priority_judgment", "Priority Judgment"),
+ ("signal_finding", "Signal Finding"),
+ ("repo_selection", "Repo Selection"),
+ ("suggested_reviewers", "Suggested Reviewers"),
+ ("dismissal", "Dismissal"),
+ ("code_reference", "Code Reference"),
+ ("commit", "Commit"),
+ ("task_run", "Task Run"),
+ ("note", "Note"),
+ ("title_change", "Title Change"),
+ ("summary_change", "Summary Change"),
+ ("code_review", "Code Review"),
+ ("related_to", "Related To"),
+ ],
+ max_length=100,
+ ),
+ ),
+ ]
diff --git a/products/signals/backend/migrations/max_migration.txt b/products/signals/backend/migrations/max_migration.txt
index cffd562e9d60..c7502931a40f 100644
--- a/products/signals/backend/migrations/max_migration.txt
+++ b/products/signals/backend/migrations/max_migration.txt
@@ -1 +1 @@
-0062_add_analytics_anomaly_investigation_source
+0063_alter_signalreportartefact_type
diff --git a/products/signals/backend/models.py b/products/signals/backend/models.py
index 7e1232ae2ccf..3e9c6175e400 100644
--- a/products/signals/backend/models.py
+++ b/products/signals/backend/models.py
@@ -23,6 +23,7 @@ from products.signals.backend.artefact_schemas import (
ArtefactContentValidationError,
Dismissal,
LogArtefactContent,
+ RelatedTo,
SignalFinding,
StatusArtefactContent,
TaskRunArtefact,
@@ -275,9 +276,11 @@ class SignalReport(UUIDModel):
match (self.status, new_status):
# Pipeline transitions
# - POTENTIAL -> CANDIDATE when the report is selected for summary generation
- # - READY | RESOLVED -> CANDIDATE when new matching signals reopen the report for
- # summary / agentic research (READY: every signal; resolved: recurrence of the issue)
- case (S.POTENTIAL | S.READY | S.RESOLVED, S.CANDIDATE):
+ # - READY -> CANDIDATE when new matching signals reopen the report for summary / agentic
+ # research. RESOLVED is terminal and never reopens: a recurring issue starts a fresh
+ # report, linked to the resolved one via related_to artefacts (see
+ # assign_and_emit_signal_activity).
+ case (S.POTENTIAL | S.READY, S.CANDIDATE):
self.promoted_at = timezone.now()
updated_fields.add("promoted_at")
@@ -704,6 +707,7 @@ class SignalReportArtefact(UUIDModel):
TITLE_CHANGE = "title_change"
SUMMARY_CHANGE = "summary_change"
CODE_REVIEW = "code_review"
+ RELATED_TO = "related_to"
# Every artefact is an append-only, point-in-time log entry — nothing is mutated in place by
# the producers. The two sets below classify *what an entry means*, not how it is written:
@@ -734,6 +738,7 @@ class SignalReportArtefact(UUIDModel):
ArtefactType.TITLE_CHANGE,
ArtefactType.SUMMARY_CHANGE,
ArtefactType.CODE_REVIEW,
+ ArtefactType.RELATED_TO,
}
)
@@ -870,10 +875,24 @@ class SignalReportArtefact(UUIDModel):
"""Append a log artefact (see `LOG_ARTEFACT_TYPES`) to a report and return it.
Log artefacts accumulate — each call creates a new row.
+
+ `related_to` links are symmetric: writing A→B here also records B→A on the other report, so
+ the link is maintained on the common write path and stays discoverable from either side. The
+ reverse row goes through `_create` (not `add_log`) so it doesn't recurse.
"""
if artefact_type_for(content) not in cls.LOG_ARTEFACT_TYPES:
raise ValueError(f"{type(content).__name__} is not a log artefact content model")
- return cls._create(team_id=team_id, report_id=report_id, content=content, attribution=attribution)
+ artefact = cls._create(team_id=team_id, report_id=report_id, content=content, attribution=attribution)
+ if isinstance(content, RelatedTo):
+ # Same team_id: reports link only within a team (grouping is per-team), so the reverse
+ # row belongs to the same tenant.
+ cls._create(
+ team_id=team_id,
+ report_id=content.report_id,
+ content=RelatedTo(report_id=str(report_id)),
+ attribution=attribution,
+ )
+ return artefact
@classmethod
def append(
@@ -893,6 +912,9 @@ class SignalReportArtefact(UUIDModel):
an agent can append a new status version just like the pipeline, and the newest row of a
status type is the report's canonical status. (The HTTP write API additionally refuses
legacy read-only types such as `video_segment` — see `NON_WRITABLE_ARTEFACT_TYPES`.)
+
+ Log types route through `add_log` (not straight to `_create`) so its side effects — e.g. the
+ symmetric `related_to` back-link — are maintained no matter which write path is used.
"""
artefact_type = artefact_type_for(content)
if artefact_type in cls.STATUS_ARTEFACT_TYPES:
@@ -903,6 +925,10 @@ class SignalReportArtefact(UUIDModel):
attribution=attribution,
reevaluate_autostart=reevaluate_autostart,
)
+ if artefact_type in cls.LOG_ARTEFACT_TYPES:
+ return cls.add_log(
+ team_id=team_id, report_id=report_id, content=cast(LogArtefactContent, content), attribution=attribution
+ )
return cls._create(team_id=team_id, report_id=report_id, content=content, attribution=attribution)
def update_content(self, content: str | dict | list) -> None:
diff --git a/products/signals/backend/report_generation/AGENTS.md b/products/signals/backend/report_generation/AGENTS.md
index f55a32d28536..0b153307afb4 100644
--- a/products/signals/backend/report_generation/AGENTS.md
+++ b/products/signals/backend/report_generation/AGENTS.md
@@ -53,6 +53,13 @@ the safety judge first, then calls into this flow via a Temporal activity if the
and the caller activity persists the new ones unconditionally; read the report's effective state
via the `effective_*` accessors
+When a report was spawned because a signal would have grouped into an already-**resolved**
+report (resolved reports are terminal and never reopen), the grouping pipeline links the two with
+symmetric `related_to` artefacts (one on each, pointing at the other). The caller activity finds the
+linked report that is resolved and passes `resolved_report_title` / `resolved_report_summary`. The
+initial research prompt then includes a `## Previously resolved report` block so the agent can judge
+whether the recurrence is a regression, a new dimension of the same issue, or distinct.
+
In production, the `update` path is triggered automatically when a `ready` report is
re-promoted after accumulating enough new signals. The caller activity (`temporal/agentic/report.py`)
reconstructs the previous `ReportResearchOutput` from stored artefacts and the report's
diff --git a/products/signals/backend/report_generation/research.py b/products/signals/backend/report_generation/research.py
index d2766113fa83..ded99aac3e9f 100644
--- a/products/signals/backend/report_generation/research.py
+++ b/products/signals/backend/report_generation/research.py
@@ -218,6 +218,27 @@ def _render_existing_report_context(previous_report_id: str | None) -> str:
)
+def _render_resolved_report_context(resolved_title: str | None, resolved_summary: str | None) -> str:
+ if not resolved_title and not resolved_summary:
+ return ""
+
+ parts = [
+ "\n---\n\n## Previously resolved report",
+ "",
+ "A very similar issue was covered by an earlier report that has already been **resolved** — its fix was "
+ "shipped. This signal is a recurrence, so it's a fresh report rather than a reopening of that one. Take the "
+ "prior resolution into account: figure out whether this is a regression of that fix, a new dimension of the "
+ "same underlying issue, or a genuinely distinct problem, and say which in your findings.",
+ "",
+ "The resolved report was:",
+ ]
+ if resolved_title:
+ parts.append(f"- **Title:** {resolved_title}")
+ if resolved_summary:
+ parts.append(f"- **Summary:** {resolved_summary}")
+ return "\n".join(parts) + "\n"
+
+
def _render_previous_finding_context(previous_finding: SignalFinding | None) -> str:
if previous_finding is None:
return ""
@@ -393,6 +414,8 @@ def build_initial_research_prompt(
previous_report_id: str | None = None,
previous_finding: SignalFinding | None = None,
has_business_knowledge: bool = False,
+ resolved_report_title: str | None = None,
+ resolved_report_summary: str | None = None,
) -> str:
"""Build the opening prompt for the first signal in a multi-turn research session."""
signal_block = _render_signal_for_research(first_signal, 1, total_signals)
@@ -410,6 +433,7 @@ def build_initial_research_prompt(
report_context += f"**Summary:** {summary}\n\n"
existing_report_context = _render_existing_report_context(previous_report_id)
+ resolved_report_context = _render_resolved_report_context(resolved_report_title, resolved_report_summary)
previous_finding_context = _render_previous_finding_context(previous_finding)
investigation_instruction = (
"You will investigate **{total_signals} signal(s)** one at a time. I will send each signal in a separate "
@@ -428,6 +452,7 @@ def build_initial_research_prompt(
{investigation_instruction.format(total_signals=total_signals)}
{report_context}
{existing_report_context}
+{resolved_report_context}
---
{_RESEARCH_PROTOCOL}
@@ -639,6 +664,8 @@ async def run_multi_turn_research(
output_fn: OutputFn = None,
signal_report_id: str | None = None,
has_business_knowledge: bool = False,
+ resolved_report_title: str | None = None,
+ resolved_report_summary: str | None = None,
) -> ReportResearchOutput:
"""Orchestrate a multi-turn sandbox session that investigates each signal individually."""
from products.tasks.backend.facade import api as tasks_facade
@@ -670,6 +697,8 @@ async def run_multi_turn_research(
previous_report_id=previous_report_id,
previous_finding=first_previous,
has_business_knowledge=has_business_knowledge,
+ resolved_report_title=resolved_report_title,
+ resolved_report_summary=resolved_report_summary,
)
first_schema: type[SignalFinding] | type[SignalFindingUpdate] = (
SignalFindingUpdate if first_previous else SignalFinding
diff --git a/products/signals/backend/temporal/agentic/report.py b/products/signals/backend/temporal/agentic/report.py
index 5bf2cf190086..154bb974d409 100644
--- a/products/signals/backend/temporal/agentic/report.py
+++ b/products/signals/backend/temporal/agentic/report.py
@@ -16,7 +16,7 @@ from posthog.temporal.common.utils import close_db_connections
from products.business_knowledge.backend.logic import is_available_for_team
from products.signals.backend.agent_runtime import STEP_RESEARCH, resolve_agent_runtime
-from products.signals.backend.artefact_schemas import ArtefactContent, SuggestedReviewers
+from products.signals.backend.artefact_schemas import ArtefactContent, RelatedTo, SuggestedReviewers
from products.signals.backend.auto_start import ReviewerContent, maybe_autostart_implementation_task
from products.signals.backend.models import ArtefactAttribution, SignalReport, SignalReportArtefact
from products.signals.backend.report_generation.research import (
@@ -137,6 +137,35 @@ async def _load_previous_research(report_id: str) -> ReportResearchOutput | None
)
+async def _load_resolved_report_context(team_id: int, report_id: str) -> tuple[str | None, str | None]:
+ """Title/summary of the resolved report this one recurred from, if any.
+
+ When a signal that would have grouped into an already-resolved report spawns a fresh report
+ instead (resolved reports never reopen), the grouping pipeline links the two with symmetric
+ `related_to` artefacts. The recurrence source is whichever linked report is resolved — handing it
+ to the research agent lets it judge regression vs. new dimension vs. distinct.
+ """
+ related_ids: list[str] = []
+ async for artefact in SignalReportArtefact.objects.filter(
+ team_id=team_id, report_id=report_id, type=SignalReportArtefact.ArtefactType.RELATED_TO
+ ).order_by("created_at"):
+ try:
+ related_ids.append(RelatedTo.model_validate_json(artefact.content).report_id)
+ except ValidationError:
+ continue
+ if not related_ids:
+ return None, None
+ resolved = (
+ await SignalReport.objects.filter(id__in=related_ids, team_id=team_id, status=SignalReport.Status.RESOLVED)
+ .only("title", "summary")
+ .order_by("-created_at")
+ .afirst()
+ )
+ if resolved is None:
+ return None, None
+ return resolved.title, resolved.summary
+
+
_AGENTIC_ARTEFACT_TYPES = [
SignalReportArtefact.ArtefactType.REPO_SELECTION,
SignalReportArtefact.ArtefactType.SIGNAL_FINDING,
@@ -351,6 +380,10 @@ async def run_agentic_report_activity(input: RunAgenticReportInput) -> RunAgenti
has_bk = await database_sync_to_async(_team_has_business_knowledge, thread_sensitive=False)(input.team_id)
# 2. Load previous research if this is a re-promoted report
previous_research = await _load_previous_research(input.report_id)
+ # 2b. Load the resolved report this one recurred from, if any, as extra research context
+ resolved_report_title, resolved_report_summary = await _load_resolved_report_context(
+ input.team_id, input.report_id
+ )
# 3. Run the agentic research in the sandbox
result = await run_multi_turn_research(
input.signals,
@@ -359,6 +392,8 @@ async def run_agentic_report_activity(input: RunAgenticReportInput) -> RunAgenti
previous_report_research=previous_research,
signal_report_id=input.report_id,
has_business_knowledge=has_bk,
+ resolved_report_title=resolved_report_title,
+ resolved_report_summary=resolved_report_summary,
)
# 4. Persist artefacts, avoid partial data from failed runs
await _persist_agentic_report_artefacts(
diff --git a/products/signals/backend/temporal/grouping.py b/products/signals/backend/temporal/grouping.py
index a709d281316e..f32ca7c29429 100644
--- a/products/signals/backend/temporal/grouping.py
+++ b/products/signals/backend/temporal/grouping.py
@@ -29,8 +29,10 @@ from posthog.sync import database_sync_to_async
from posthog.temporal.common.scoped import scoped_temporal
from posthog.temporal.common.utils import close_db_connections
+from products.signals.backend.artefact_attribution import ArtefactAttribution
+from products.signals.backend.artefact_schemas import RelatedTo
from products.signals.backend.billing import BILLING_EXEMPT_SOURCE_PRODUCTS
-from products.signals.backend.models import SignalReport
+from products.signals.backend.models import SignalReport, SignalReportArtefact
from products.signals.backend.signal_metadata import EMBEDDING_MODEL
from products.signals.backend.temporal import metrics
from products.signals.backend.temporal.drop_telemetry import capture_signal_dropped
@@ -725,13 +727,37 @@ async def assign_and_emit_signal_activity(input: AssignAndEmitSignalInput) -> As
metadata=metadata,
)
return report_id, False, ts, True, report.run_count, False, report.status, report.signal_count
- report.total_weight += input.weight
- report.signal_count += 1
- update_fields = ["total_weight", "signal_count", "updated_at"]
- if input.updated_title:
- report.title = input.updated_title
- update_fields.append("title")
- report.save(update_fields=update_fields)
+ # Resolved reports are terminal — never reopen them. When a signal would have grouped
+ # into an already-resolved report, the issue it fixed has recurred (or a related one
+ # has), so we start a fresh report and link it to the resolved report via a
+ # `related_to` artefact. add_log writes the symmetric back-link automatically, so the
+ # link is discoverable from either side. The research agent is later handed that
+ # resolved report as context (see report.py).
+ if report.status == SignalReport.Status.RESOLVED:
+ resolved_report = report
+ report = SignalReport.objects.create(
+ team_id=input.team_id,
+ status=SignalReport.Status.POTENTIAL,
+ total_weight=input.weight,
+ signal_count=1,
+ title=resolved_report.title,
+ summary=resolved_report.summary,
+ billing_exempt_reason=BILLING_EXEMPT_SOURCE_PRODUCTS.get(input.source_product),
+ )
+ SignalReportArtefact.add_log(
+ team_id=input.team_id,
+ report_id=str(report.id),
+ content=RelatedTo(report_id=str(resolved_report.id)),
+ attribution=ArtefactAttribution.system(),
+ )
+ else:
+ report.total_weight += input.weight
+ report.signal_count += 1
+ update_fields = ["total_weight", "signal_count", "updated_at"]
+ if input.updated_title:
+ report.title = input.updated_title
+ update_fields.append("title")
+ report.save(update_fields=update_fields)
else:
report = SignalReport.objects.create(
team_id=input.team_id,
@@ -748,12 +774,13 @@ async def assign_and_emit_signal_activity(input: AssignAndEmitSignalInput) -> As
# Promotion rules by status:
# - SUPPRESSED: never promoted.
+ # - RESOLVED: terminal — never receives new signals (a recurrence spawns a fresh report above).
# - POTENTIAL: promote once total_weight >= WEIGHT_THRESHOLD and signal_count >= signals_at_run
# (snooze gate, defaults to 0). Uncapped — a report's first research always runs.
- # - READY / RESOLVED: re-research on every new signal (resolved = issue recurred), but only
- # while signal_count <= RERESEARCH_MAX_SIGNALS; past the cap, signals are collected, not researched.
+ # - READY: re-research on every new signal, but only while signal_count <= RERESEARCH_MAX_SIGNALS;
+ # past the cap, signals are collected, not researched.
# - CANDIDATE: re-promote to self-heal failed spawns (uncapped; concurrent runs blocked by Temporal).
- is_reresearch = report.status == SignalReport.Status.READY or report.status == SignalReport.Status.RESOLVED
+ is_reresearch = report.status == SignalReport.Status.READY
reresearch_capped = is_reresearch and report.signal_count > RERESEARCH_MAX_SIGNALS
if (
(is_reresearch and not reresearch_capped)
diff --git a/products/signals/backend/test/test_assign_and_emit_signal.py b/products/signals/backend/test/test_assign_and_emit_signal.py
index 3e96c9b1814c..ba6a6a010fcb 100644
--- a/products/signals/backend/test/test_assign_and_emit_signal.py
+++ b/products/signals/backend/test/test_assign_and_emit_signal.py
@@ -13,7 +13,8 @@ from asgiref.sync import sync_to_async
from posthog.models import Organization, Team
from posthog.sync import database_sync_to_async
-from products.signals.backend.models import SignalReport
+from products.signals.backend.artefact_schemas import RelatedTo
+from products.signals.backend.models import SignalReport, SignalReportArtefact
from products.signals.backend.temporal.grouping import (
WEIGHT_THRESHOLD,
AssignAndEmitSignalInput,
@@ -350,15 +351,11 @@ async def test_candidate_repromotion_does_not_advance_run_count(ateam):
@pytest.mark.asyncio
@pytest.mark.django_db
- "starting_status",
- [SignalReport.Status.READY, SignalReport.Status.RESOLVED],
-)
-async def test_ready_and_resolved_repromote_to_candidate_on_any_signal(ateam, starting_status):
- """READY and RESOLVED re-promote on every signal regardless of weight thresholds."""
+async def test_ready_repromotes_to_candidate_on_any_signal(ateam):
+ """A READY report re-promotes on every signal regardless of weight thresholds."""
report = await database_sync_to_async(SignalReport.objects.create)(
team=ateam,
- status=starting_status,
+ status=SignalReport.Status.READY,
total_weight=1.5,
signal_count=2,
title="original title",
@@ -377,6 +374,49 @@ async def test_ready_and_resolved_repromote_to_candidate_on_any_signal(ateam, st
assert refreshed.summary == "original summary"
+async def test_resolved_match_spawns_new_report_and_leaves_resolved_untouched(ateam):
+ """A signal that would group into a RESOLVED report must not reopen it. Instead a fresh
+ POTENTIAL report is created and symmetrically linked to the resolved one via related_to
+ artefacts, and the resolved report keeps its status and signal count."""
+ resolved = await database_sync_to_async(SignalReport.objects.create)(
+ team=ateam,
+ status=SignalReport.Status.RESOLVED,
+ total_weight=1.5,
+ signal_count=2,
+ title="original title",
+ summary="original summary",
+ )
+ input_ = _build_input(ateam.id, _existing_match(str(resolved.id)), weight=WEIGHT_THRESHOLD)
+
+ result = await assign_and_emit_signal_activity(input_)
+
+ # A brand-new report was created, not the resolved one.
+ assert result.report_id != str(resolved.id)
+ new_report = await database_sync_to_async(SignalReport.objects.get)(id=result.report_id)
+ assert new_report.status == SignalReport.Status.CANDIDATE # weight at threshold promotes it
+ assert new_report.signal_count == 1
+ # Placeholder title/summary carried over from the resolved report until research rewrites them.
+ assert new_report.title == "original title"
+ assert new_report.summary == "original summary"
+
+ # The two reports are symmetrically linked via related_to artefacts, each pointing at the other.
+ new_link = await database_sync_to_async(
+ lambda: SignalReportArtefact.objects.get(report=new_report, type=SignalReportArtefact.ArtefactType.RELATED_TO)
+ )()
+ assert RelatedTo.model_validate_json(new_link.content) == RelatedTo(report_id=str(resolved.id))
+ resolved_link = await database_sync_to_async(
+ lambda: SignalReportArtefact.objects.get(report=resolved, type=SignalReportArtefact.ArtefactType.RELATED_TO)
+ )()
+ assert RelatedTo.model_validate_json(resolved_link.content) == RelatedTo(report_id=str(new_report.id))
+
+ # The resolved report is untouched — not reopened, no new signal counted.
+ refreshed_resolved = await database_sync_to_async(SignalReport.objects.get)(id=resolved.id)
+ assert refreshed_resolved.status == SignalReport.Status.RESOLVED
+ assert refreshed_resolved.signal_count == 2
+
+
# ---------------------------------------------------------------------------
# Re-research cap: already-researched reports stop re-researching past RERESEARCH_MAX_SIGNALS
# ---------------------------------------------------------------------------
@@ -384,16 +424,12 @@ async def test_ready_and_resolved_repromote_to_candidate_on_any_signal(ateam, st
@pytest.mark.asyncio
@pytest.mark.django_db
- "starting_status",
- [SignalReport.Status.READY, SignalReport.Status.RESOLVED],
-)
-async def test_reresearch_allowed_up_to_cap(ateam, starting_status):
+async def test_reresearch_allowed_up_to_cap(ateam):
"""At the boundary (the new signal brings signal_count exactly to RERESEARCH_MAX_SIGNALS), a
- READY/RESOLVED report still re-promotes — the cap only bites once signal_count exceeds it."""
+ READY report still re-promotes — the cap only bites once signal_count exceeds it."""
report = await database_sync_to_async(SignalReport.objects.create)(
team=ateam,
- status=starting_status,
+ status=SignalReport.Status.READY,
total_weight=1.5,
signal_count=RERESEARCH_MAX_SIGNALS - 1,
)
@@ -409,16 +445,12 @@ async def test_reresearch_allowed_up_to_cap(ateam, starting_status):
@pytest.mark.asyncio
@pytest.mark.django_db
- "starting_status",
- [SignalReport.Status.READY, SignalReport.Status.RESOLVED],
-)
-async def test_reresearch_capped_past_threshold_still_assigns_signal(ateam, patch_side_effects, starting_status):
- """Past the cap, a READY/RESOLVED report stops re-researching: promoted=False and status is
- unchanged, but the signal is still counted, weighted, and emitted (not marked deleted)."""
+async def test_reresearch_capped_past_threshold_still_assigns_signal(ateam, patch_side_effects):
+ """Past the cap, a READY report stops re-researching: promoted=False and status is unchanged,
+ but the signal is still counted, weighted, and emitted (not marked deleted)."""
report = await database_sync_to_async(SignalReport.objects.create)(
team=ateam,
- status=starting_status,
+ status=SignalReport.Status.READY,
total_weight=2.0,
signal_count=RERESEARCH_MAX_SIGNALS, # post-increment lands at cap + 1
title="original title",
@@ -430,7 +462,7 @@ async def test_reresearch_capped_past_threshold_still_assigns_signal(ateam, patc
assert result.promoted is False
refreshed = await database_sync_to_async(SignalReport.objects.get)(id=report.id)
- assert refreshed.status == starting_status
+ assert refreshed.status == SignalReport.Status.READY
assert refreshed.promoted_at is None
assert refreshed.signal_count == RERESEARCH_MAX_SIGNALS + 1
assert refreshed.total_weight == pytest.approx(2.5)
diff --git a/products/signals/backend/test/test_research_prompt.py b/products/signals/backend/test/test_research_prompt.py
index 6719bb2a4a5b..1455f4c2b5fe 100644
--- a/products/signals/backend/test/test_research_prompt.py
+++ b/products/signals/backend/test/test_research_prompt.py
@@ -85,3 +85,20 @@ class TestBuildInitialResearchPrompt:
assert ("## Business knowledge" in prompt) == expected_present
for snippet in extra_checks:
assert snippet in prompt
+
+ def test_resolved_report_context_present_when_provided(self):
+ signal = _make_signal({})
+ prompt = build_initial_research_prompt(
+ signal,
+ 1,
+ resolved_report_title="fix(funnel): drop off after step 2",
+ resolved_report_summary="Users were falling out of the funnel.",
+ )
+ assert "## Previously resolved report" in prompt
+ assert "fix(funnel): drop off after step 2" in prompt
+ assert "Users were falling out of the funnel." in prompt
+
+ def test_resolved_report_context_absent_by_default(self):
+ signal = _make_signal({})
+ prompt = build_initial_research_prompt(signal, 1)
+ assert "## Previously resolved report" not in prompt
diff --git a/products/signals/backend/test/test_signal_report_artefact_model.py b/products/signals/backend/test/test_signal_report_artefact_model.py
index 3351937e0123..3c4b354f6074 100644
--- a/products/signals/backend/test/test_signal_report_artefact_model.py
+++ b/products/signals/backend/test/test_signal_report_artefact_model.py
@@ -10,6 +10,7 @@ from products.signals.backend.artefact_schemas import (
NoteArtefact,
Priority,
PriorityAssessment,
+ RelatedTo,
SignalFinding,
)
from products.signals.backend.models import ArtefactAttribution, SignalReport, SignalReportArtefact
@@ -132,6 +133,31 @@ class TestSignalReportArtefactHelpers(BaseTest):
attribution=ArtefactAttribution.system(),
)
+ @parameterized.expand([("add_log",), ("append",)])
+ def test_related_to_writes_symmetric_backlink(self, write_method):
+ # A related_to link must be maintained on both reports from either write entry point, and
+ # must not recurse (exactly one row per side).
+ report_a = self._report()
+ report_b = self._report()
+ writer = getattr(SignalReportArtefact, write_method)
+ writer(
+ team_id=self.team.id,
+ report_id=str(report_a.id),
+ content=RelatedTo(report_id=str(report_b.id)),
+ attribution=ArtefactAttribution.system(),
+ )
+
+ def links_of(report: SignalReport) -> list[str]:
+ return [
+ RelatedTo.model_validate_json(a.content).report_id
+ for a in SignalReportArtefact.objects.filter(
+ report=report, type=SignalReportArtefact.ArtefactType.RELATED_TO
+ )
+ ]
+
+ assert links_of(report_a) == [str(report_b.id)]
+ assert links_of(report_b) == [str(report_a.id)]
+
# --- append_status ---
def test_append_status_appends_each_version(self):
diff --git a/products/signals/frontend/generated/api.schemas.ts b/products/signals/frontend/generated/api.schemas.ts
index f77cac72b1c9..3fc2795c471c 100644
--- a/products/signals/frontend/generated/api.schemas.ts
+++ b/products/signals/frontend/generated/api.schemas.ts
@@ -831,6 +831,7 @@ export interface SignalReportStateRequestApi {
* * `title_change` - Title Change
* * `summary_change` - Summary Change
* * `code_review` - Code Review
+ * * `related_to` - Related To
*/
export type SignalReportArtefactTypeEnumApi =
(typeof SignalReportArtefactTypeEnumApi)[keyof typeof SignalReportArtefactTypeEnumApi]
@@ -851,6 +852,7 @@ export const SignalReportArtefactTypeEnumApi = {
TitleChange: 'title_change',
SummaryChange: 'summary_change',
CodeReview: 'code_review',
+ RelatedTo: 'related_to',
} as const
export interface _UserApi {
@@ -896,7 +898,7 @@ export interface PaginatedSignalReportArtefactListApi {
* against the type's schema (see `products/signals/backend/artefact_schemas.py`).
*/
export interface SignalReportArtefactLogCreateApi {
- /** The artefact type. One of: actionability_judgment, code_reference, commit, dismissal, note, priority_judgment, repo_selection, safety_judgment, signal_finding, suggested_reviewers, task_run. Log types accumulate; status types (safety_judgment, actionability_judgment, priority_judgment, repo_selection, suggested_reviewers) are latest-wins — appending a new version supersedes the previous one as the report's canonical status. */
+ /** The artefact type. One of: actionability_judgment, code_reference, commit, dismissal, note, priority_judgment, related_to, repo_selection, safety_judgment, signal_finding, suggested_reviewers, task_run. Log types accumulate; status types (safety_judgment, actionability_judgment, priority_judgment, repo_selection, suggested_reviewers) are latest-wins — appending a new version supersedes the previous one as the report's canonical status. */
artefact_type: string
/** The artefact payload as a JSON object or array; shape depends on artefact_type and is validated against its schema. */
content: unknown
diff --git a/products/signals/frontend/generated/api.zod.ts b/products/signals/frontend/generated/api.zod.ts
index 074c26fcc651..c3075354c3e2 100644
--- a/products/signals/frontend/generated/api.zod.ts
+++ b/products/signals/frontend/generated/api.zod.ts
@@ -139,7 +139,7 @@ export const SignalsReportArtefactsCreateBody = /* @__PURE__ */ zod
artefact_type: zod
.string()
.describe(
- "The artefact type. One of: actionability_judgment, code_reference, commit, dismissal, note, priority_judgment, repo_selection, safety_judgment, signal_finding, suggested_reviewers, task_run. Log types accumulate; status types (safety_judgment, actionability_judgment, priority_judgment, repo_selection, suggested_reviewers) are latest-wins — appending a new version supersedes the previous one as the report's canonical status."
+ "The artefact type. One of: actionability_judgment, code_reference, commit, dismissal, note, priority_judgment, related_to, repo_selection, safety_judgment, signal_finding, suggested_reviewers, task_run. Log types accumulate; status types (safety_judgment, actionability_judgment, priority_judgment, repo_selection, suggested_reviewers) are latest-wins — appending a new version supersedes the previous one as the report's canonical status."
),
content: zod
.unknown()
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index bd0e68b4542f..b144beac85d5 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -39603,6 +39603,7 @@ export namespace Schemas {
* * `title_change` - Title Change
* * `summary_change` - Summary Change
* * `code_review` - Code Review
+ * * `related_to` - Related To
*/
export type SignalReportArtefactTypeEnum = typeof SignalReportArtefactTypeEnum[keyof typeof SignalReportArtefactTypeEnum];
@@ -39623,6 +39624,7 @@ export namespace Schemas {
TitleChange: 'title_change',
SummaryChange: 'summary_change',
CodeReview: 'code_review',
+ RelatedTo: 'related_to',
} as const;
export interface _User {
@@ -56521,7 +56523,7 @@ export namespace Schemas {
* against the type's schema (see `products/signals/backend/artefact_schemas.py`).
*/
export interface SignalReportArtefactLogCreate {
- /** The artefact type. One of: actionability_judgment, code_reference, commit, dismissal, note, priority_judgment, repo_selection, safety_judgment, signal_finding, suggested_reviewers, task_run. Log types accumulate; status types (safety_judgment, actionability_judgment, priority_judgment, repo_selection, suggested_reviewers) are latest-wins — appending a new version supersedes the previous one as the report's canonical status. */
+ /** The artefact type. One of: actionability_judgment, code_reference, commit, dismissal, note, priority_judgment, related_to, repo_selection, safety_judgment, signal_finding, suggested_reviewers, task_run. Log types accumulate; status types (safety_judgment, actionability_judgment, priority_judgment, repo_selection, suggested_reviewers) are latest-wins — appending a new version supersedes the previous one as the report's canonical status. */
artefact_type: string;
/** The artefact payload as a JSON object or array; shape depends on artefact_type and is validated against its schema. */
content: unknown;
diff --git a/services/mcp/src/generated/signals/api.ts b/services/mcp/src/generated/signals/api.ts
index da1f5b840f95..8f6ae2661a10 100644
--- a/services/mcp/src/generated/signals/api.ts
+++ b/services/mcp/src/generated/signals/api.ts
@@ -236,7 +236,7 @@ export const SignalsReportArtefactsCreateBody = /* @__PURE__ */ zod
artefact_type: zod
.string()
.describe(
- "The artefact type. One of: actionability_judgment, code_reference, commit, dismissal, note, priority_judgment, repo_selection, safety_judgment, signal_finding, suggested_reviewers, task_run. Log types accumulate; status types (safety_judgment, actionability_judgment, priority_judgment, repo_selection, suggested_reviewers) are latest-wins — appending a new version supersedes the previous one as the report's canonical status."
+ "The artefact type. One of: actionability_judgment, code_reference, commit, dismissal, note, priority_judgment, related_to, repo_selection, safety_judgment, signal_finding, suggested_reviewers, task_run. Log types accumulate; status types (safety_judgment, actionability_judgment, priority_judgment, repo_selection, suggested_reviewers) are latest-wins — appending a new version supersedes the previous one as the report's canonical status."
),
content: zod
.unknown()
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/inbox-report-artefacts-create.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/inbox-report-artefacts-create.json
index 6944179ef6d3..aab36543eae9 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/inbox-report-artefacts-create.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/inbox-report-artefacts-create.json
@@ -2,7 +2,7 @@
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {
"artefact_type": {
- "description": "The artefact type. One of: actionability_judgment, code_reference, commit, dismissal, note, priority_judgment, repo_selection, safety_judgment, signal_finding, suggested_reviewers, task_run. Log types accumulate; status types (safety_judgment, actionability_judgment, priority_judgment, repo_selection, suggested_reviewers) are latest-wins — appending a new version supersedes the previous one as the report's canonical status.",
+ "description": "The artefact type. One of: actionability_judgment, code_reference, commit, dismissal, note, priority_judgment, related_to, repo_selection, safety_judgment, signal_finding, suggested_reviewers, task_run. Log types accumulate; status types (safety_judgment, actionability_judgment, priority_judgment, repo_selection, suggested_reviewers) are latest-wins — appending a new version supersedes the previous one as the report's canonical status.",
"type": "string"
},
"content": {