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): Cap re-research of large reports past 10 signals (#64354)

Alex Lebedevba243fbaa395
diff --git a/products/signals/ARCHITECTURE.md b/products/signals/ARCHITECTURE.md
index d5a80e448cf9..ee2c80a0a3f7 100644
--- a/products/signals/ARCHITECTURE.md
+++ b/products/signals/ARCHITECTURE.md
@@ -205,7 +205,11 @@ Bulk sync (`sync_full_cache`) fans the per-repo sync out via `run_parallel_with_
#### Re-promotion
-Reports are re-promoted when new evidence arrives, but not on every single signal forever. `signals_at_run` is advanced when a run starts, and the grouping logic only re-promotes when `signal_count >= signals_at_run`.
+Reports are re-promoted when new evidence arrives. A `READY` / `RESOLVED` report re-promotes on every new matching signal (so research reruns with the latest evidence), and a report reset to `potential` re-promotes once it clears the `signals_at_run` snooze gate again.
+
+**Re-research cap.** The research activity reads every non-deleted signal, so re-research cost scales with report size. Once an already-researched report exceeds `RERESEARCH_MAX_SIGNALS` (`SIGNAL_RERESEARCH_MAX_SIGNALS`, default 10), `READY` / `RESOLVED` re-promotion is suppressed: new signals are still assigned, weighted, and emitted, but no new summary run spawns. The cap is enforced in two places: the grouping promotion gate (`assign_and_emit_signal_activity`), which fires the `signal_report_reresearch_skipped` event per suppressed signal so the saved volume is trackable, and the summary self-loop (`mark_report_ready_activity`), which stops an in-flight run from looping into another research pass (no event — this is a rare mid-run edge).
+
+The cap covers **only** the `READY` / `RESOLVED` path (the one that re-promotes on every signal). Re-promotions through the `potential` gate stay uncapped — first research, `candidate` self-heal, snooze return, and a not-actionable reset re-accumulating weight — because they are weight / `signals_at_run`-gated rather than per-signal, so strong new evidence can still resurface a large report.
On re-promotion:
@@ -343,9 +347,9 @@ potential → candidate → in_progress → ready
→ failed
→ potential (reset by actionability judge)
-# Re-promotion: READY reports are re-promoted to candidate when enough new signals
-# accumulate (signal_count >= signals_at_run), triggering a new summary run that
-# reuses the previous repo selection and findings for already-seen signals.
+# Re-promotion: READY reports are re-promoted to candidate on each new matching signal,
+# triggering a new summary run that reuses the previous repo selection and findings for
+# already-seen signals. Suppressed once signal_count > RERESEARCH_MAX_SIGNALS (see Re-research cap).
ready → candidate
# Transitions enforced by SignalReport.transition_to():
@@ -839,6 +843,7 @@ All events use `distinct_id = team.uuid` and `groups(organization, team)`. Per-s
- `signal_emission_started` — `emit_signal()` past validation
- `signal_emitted` — `emit_signal()` after Temporal dispatch succeeds
- `signal_assigned_to_report` — grouping assigned the signal (+ `report_id`, `is_new_report`, `promoted`)
+- `signal_report_reresearch_skipped` — signal hit an already-researched report past the re-research cap, so no new run spawned (+ `report_id`, `signal_count`, `status`, `threshold`). Fires per suppressed signal
- `signal_report_started` — report run began (+ `report_id`, `signal_count`, `run_count`, `source_products`)
- `signals_repo_research_started` / `signals_repo_research_completed` — repo selection stage (+ `report_id`, `result`: `reused` | `selected` | `no_repo` | `failed`, optional `failure_reason`: `no_github_integration` | `agentic_activity_error`)
- `signal_report_completed` — terminal per run (+ `result`: `ready` | `failed` | `pending_input` | `not_actionable`, optional `failure_reason`)
diff --git a/products/signals/backend/temporal/grouping.py b/products/signals/backend/temporal/grouping.py
index 8911e8e138c4..bf8fc37e0766 100644
--- a/products/signals/backend/temporal/grouping.py
+++ b/products/signals/backend/temporal/grouping.py
@@ -50,6 +50,7 @@ from products.signals.backend.temporal.signal_queries import (
)
from products.signals.backend.temporal.summary import SignalReportSummaryWorkflow
from products.signals.backend.temporal.types import (
+ RERESEARCH_MAX_SIGNALS,
EmitSignalInputs,
ExistingReportMatch,
MatchedMetadata,
@@ -678,8 +679,9 @@ class AssignAndEmitSignalOutput:
async def assign_and_emit_signal_activity(input: AssignAndEmitSignalInput) -> AssignAndEmitSignalOutput:
match_result = input.match_result
- def do_assign_and_emit() -> tuple[str, bool, datetime, bool, int]:
- """Returns (report_id, promoted, timestamp, matched_deleted_report, run_count)."""
+ def do_assign_and_emit() -> tuple[str, bool, datetime, bool, int, bool, str, int]:
+ """Returns (report_id, promoted, timestamp, matched_deleted_report, run_count,
+ reresearch_capped, report_status, report_signal_count)."""
with transaction.atomic():
promoted = False
@@ -720,7 +722,7 @@ async def assign_and_emit_signal_activity(input: AssignAndEmitSignalInput) -> As
timestamp=ts,
metadata=metadata,
)
- return report_id, False, ts, True, report.run_count
+ 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"]
@@ -738,15 +740,17 @@ async def assign_and_emit_signal_activity(input: AssignAndEmitSignalInput) -> As
summary=match_result.summary,
)
- # - SUPPRESSED reports gather signals indefinitely but are never promoted.
- # - POTENTIAL reports are promoted once signal_count >= signals_at_run (snooze gate;
- # signals_at_run defaults to 0 so fresh reports always pass) and weight threshold is met.
- # - READY and RESOLVED reports are re-promoted on every new signal so the pipeline
- # reruns with latest evidence (resolved: issue recurred post-merge fix).
- # - CANDIDATE re-promotes on every new signal to self-heal from failed spawn attempts. Concurrent runs blocked by Temporal.
+ # Promotion rules by status:
+ # - SUPPRESSED: never promoted.
+ # - 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.
+ # - 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
+ reresearch_capped = is_reresearch and report.signal_count > RERESEARCH_MAX_SIGNALS
if (
- report.status == SignalReport.Status.READY
- or report.status == SignalReport.Status.RESOLVED
+ (is_reresearch and not reresearch_capped)
or report.status == SignalReport.Status.CANDIDATE
or (
report.status == SignalReport.Status.POTENTIAL
@@ -788,13 +792,28 @@ async def assign_and_emit_signal_activity(input: AssignAndEmitSignalInput) -> As
timestamp=ts,
metadata=metadata,
)
-
- return report_id, promoted, ts, False, report.run_count
+ return (
+ report_id,
+ promoted,
+ ts,
+ False,
+ report.run_count,
+ reresearch_capped,
+ report.status,
+ report.signal_count,
+ )
try:
- report_id, promoted, ts, matched_deleted, run_count = await database_sync_to_async(
- do_assign_and_emit, thread_sensitive=False
- )()
+ (
+ report_id,
+ promoted,
+ ts,
+ matched_deleted,
+ run_count,
+ reresearch_capped,
+ report_status,
+ report_signal_count,
+ ) = await database_sync_to_async(do_assign_and_emit, thread_sensitive=False)()
team = await Team.objects.select_related("organization").aget(pk=input.team_id)
@@ -858,7 +877,32 @@ async def assign_and_emit_signal_activity(input: AssignAndEmitSignalInput) -> As
team_id=input.team_id,
source_id=input.source_id,
)
-
+ # Over-cap signal on an already-researched report: assigned/emitted but no re-research
+ # spawned. Emitted so the saved re-research volume is trackable.
+ if reresearch_capped:
+ try:
+ posthoganalytics.capture(
+ event="signal_report_reresearch_skipped",
+ distinct_id=str(team.uuid),
+ properties={
+ "report_id": report_id,
+ "signal_count": report_signal_count,
+ "status": report_status,
+ "source_product": input.source_product,
+ "source_type": input.source_type,
+ "source_id": input.source_id,
+ "threshold": RERESEARCH_MAX_SIGNALS,
+ },
+ groups=groups(team.organization, team),
+ )
+ except Exception as e:
+ posthoganalytics.capture_exception(e)
+ logger.exception(
+ "Failed to capture signal_report_reresearch_skipped event",
+ report_id=report_id,
+ team_id=input.team_id,
+ source_id=input.source_id,
+ )
logger.debug(
f"Assigned and emitted signal to report {report_id}",
report_id=report_id,
diff --git a/products/signals/backend/temporal/summary.py b/products/signals/backend/temporal/summary.py
index b08dcb669f03..ff5000a6d2c8 100644
--- a/products/signals/backend/temporal/summary.py
+++ b/products/signals/backend/temporal/summary.py
@@ -44,7 +44,11 @@ from products.signals.backend.temporal.signal_queries import (
FetchSignalsForReportOutput,
fetch_signals_for_report_activity,
)
-from products.signals.backend.temporal.types import SignalData, SignalReportSummaryWorkflowInputs
+from products.signals.backend.temporal.types import (
+ RERESEARCH_MAX_SIGNALS,
+ SignalData,
+ SignalReportSummaryWorkflowInputs,
+)
logger = structlog.get_logger(__name__)
@@ -474,7 +478,9 @@ async def mark_report_ready_activity(input: MarkReportReadyInput) -> bool:
return True, report.run_count, True
updated_fields = report.transition_to(SignalReport.Status.READY, title=input.title, summary=input.summary)
report.save(update_fields=updated_fields)
- has_new_signals = report.signal_count > input.processed_signal_count
+ # Loop to re-research only if new signals arrived and we're within the cap; past
+ # RERESEARCH_MAX_SIGNALS the report stays READY instead of re-running over a large set.
+ has_new_signals = input.processed_signal_count < report.signal_count <= RERESEARCH_MAX_SIGNALS
if has_new_signals:
# If more signals arrived while the report was being processed, we want to
# re-promote it back to candidate and loop to also process new signals
diff --git a/products/signals/backend/temporal/types.py b/products/signals/backend/temporal/types.py
index 8f8bcc112305..9f9b998abb0b 100644
--- a/products/signals/backend/temporal/types.py
+++ b/products/signals/backend/temporal/types.py
@@ -1,7 +1,12 @@
+import os
from dataclasses import dataclass, field
from datetime import datetime
from typing import Any, Optional
+# Above this many assigned signals, an already-researched (READY/RESOLVED) report stops
+# re-researching on new signals; signals are still assigned. See assign_and_emit_signal_activity.
+RERESEARCH_MAX_SIGNALS = int(os.getenv("SIGNAL_RERESEARCH_MAX_SIGNALS", "10"))
+
@dataclass
class EmitSignalInputs:
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 9c662b5426d9..17c971bde23b 100644
--- a/products/signals/backend/test/test_assign_and_emit_signal.py
+++ b/products/signals/backend/test/test_assign_and_emit_signal.py
@@ -20,6 +20,7 @@ from products.signals.backend.temporal.grouping import (
assign_and_emit_signal_activity,
)
from products.signals.backend.temporal.types import (
+ RERESEARCH_MAX_SIGNALS,
ExistingReportMatch,
MatchedMetadata,
NewReportMatch,
@@ -330,6 +331,138 @@ async def test_ready_and_resolved_repromote_to_candidate_on_any_signal(ateam, st
assert refreshed.summary == "original summary"
+# ---------------------------------------------------------------------------
+# Re-research cap: already-researched reports stop re-researching past RERESEARCH_MAX_SIGNALS
+# ---------------------------------------------------------------------------
+
+
+ "starting_status",
+ [SignalReport.Status.READY, SignalReport.Status.RESOLVED],
+)
+async def test_reresearch_allowed_up_to_cap(ateam, starting_status):
+ """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."""
+ report = await database_sync_to_async(SignalReport.objects.create)(
+ team=ateam,
+ status=starting_status,
+ total_weight=1.5,
+ signal_count=RERESEARCH_MAX_SIGNALS - 1,
+ )
+ input_ = _build_input(ateam.id, _existing_match(str(report.id)), weight=0.1)
+
+ result = await assign_and_emit_signal_activity(input_)
+
+ assert result.promoted is True
+ refreshed = await database_sync_to_async(SignalReport.objects.get)(id=report.id)
+ assert refreshed.status == SignalReport.Status.CANDIDATE
+ assert refreshed.signal_count == RERESEARCH_MAX_SIGNALS
+
+
+ "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)."""
+ report = await database_sync_to_async(SignalReport.objects.create)(
+ team=ateam,
+ status=starting_status,
+ total_weight=2.0,
+ signal_count=RERESEARCH_MAX_SIGNALS, # post-increment lands at cap + 1
+ title="original title",
+ summary="original summary",
+ )
+ input_ = _build_input(ateam.id, _existing_match(str(report.id)), weight=0.5)
+
+ result = await assign_and_emit_signal_activity(input_)
+
+ assert result.promoted is False
+ refreshed = await database_sync_to_async(SignalReport.objects.get)(id=report.id)
+ assert refreshed.status == starting_status
+ assert refreshed.promoted_at is None
+ assert refreshed.signal_count == RERESEARCH_MAX_SIGNALS + 1
+ assert refreshed.total_weight == pytest.approx(2.5)
+ emit_kwargs = patch_side_effects["emit"].call_args.kwargs
+ assert emit_kwargs["metadata"].get("deleted") is not True
+
+
+async def test_reresearch_capped_emits_skipped_event(ateam, patch_side_effects):
+ """Crossing the cap fires signal_report_reresearch_skipped (after signal_assigned_to_report) so
+ the saved re-research volume is trackable as an insight."""
+ report = await database_sync_to_async(SignalReport.objects.create)(
+ team=ateam,
+ status=SignalReport.Status.READY,
+ total_weight=2.0,
+ signal_count=RERESEARCH_MAX_SIGNALS,
+ )
+ input_ = _build_input(ateam.id, _existing_match(str(report.id)), weight=0.5)
+
+ result = await assign_and_emit_signal_activity(input_)
+
+ # The report was genuinely capped (not re-promoted), and the event reflects that.
+ assert result.promoted is False
+ refreshed = await database_sync_to_async(SignalReport.objects.get)(id=report.id)
+ assert refreshed.status == SignalReport.Status.READY
+ events = [call.kwargs["event"] for call in patch_side_effects["capture"].call_args_list]
+ assert events == ["signal_assigned_to_report", "signal_report_reresearch_skipped"]
+ skipped = next(
+ c.kwargs["properties"]
+ for c in patch_side_effects["capture"].call_args_list
+ if c.kwargs["event"] == "signal_report_reresearch_skipped"
+ )
+ assert skipped["report_id"] == str(report.id)
+ assert skipped["signal_count"] == RERESEARCH_MAX_SIGNALS + 1
+ assert skipped["status"] == SignalReport.Status.READY
+ assert skipped["threshold"] == RERESEARCH_MAX_SIGNALS
+ assert skipped["source_id"] == input_.source_id
+
+
+async def test_reresearch_within_cap_does_not_emit_skipped_event(ateam, patch_side_effects):
+ """A READY report within the cap re-promotes normally and fires only signal_assigned_to_report."""
+ report = await database_sync_to_async(SignalReport.objects.create)(
+ team=ateam,
+ status=SignalReport.Status.READY,
+ total_weight=1.5,
+ signal_count=2,
+ )
+ input_ = _build_input(ateam.id, _existing_match(str(report.id)), weight=0.5)
+
+ await assign_and_emit_signal_activity(input_)
+
+ events = [call.kwargs["event"] for call in patch_side_effects["capture"].call_args_list]
+ assert events == ["signal_assigned_to_report"]
+
+
+async def test_potential_promotes_past_cap_for_first_research(ateam):
+ """The cap only applies to re-research. A POTENTIAL report that grew past RERESEARCH_MAX_SIGNALS
+ without ever being researched still promotes for its first research."""
+ report = await database_sync_to_async(SignalReport.objects.create)(
+ team=ateam,
+ status=SignalReport.Status.POTENTIAL,
+ total_weight=WEIGHT_THRESHOLD,
+ signal_count=RERESEARCH_MAX_SIGNALS + 5,
+ )
+ input_ = _build_input(ateam.id, _existing_match(str(report.id)), weight=0.5)
+
+ result = await assign_and_emit_signal_activity(input_)
+
+ assert result.promoted is True
+ refreshed = await database_sync_to_async(SignalReport.objects.get)(id=report.id)
+ assert refreshed.status == SignalReport.Status.CANDIDATE
+
+
# ---------------------------------------------------------------------------
# States that should NOT promote
# ---------------------------------------------------------------------------
diff --git a/products/signals/backend/test/test_report_telemetry.py b/products/signals/backend/test/test_report_telemetry.py
index e50fc5a7144d..6bea39f86b3a 100644
--- a/products/signals/backend/test/test_report_telemetry.py
+++ b/products/signals/backend/test/test_report_telemetry.py
@@ -16,6 +16,7 @@ from products.signals.backend.temporal.summary import (
mark_report_ready_activity,
reset_report_to_potential_activity,
)
+from products.signals.backend.temporal.types import RERESEARCH_MAX_SIGNALS
PIPELINE_MODULE_PATH = "products.signals.backend.temporal.summary"
@@ -261,3 +262,62 @@ async def test_reset_to_potential_is_idempotent_when_already_potential(ateam):
assert refreshed.status == SignalReport.Status.POTENTIAL
assert refreshed.error == "Original reset reason"
assert refreshed.total_weight == 0.0
+
+
+async def test_ready_loops_when_new_signals_within_cap(ateam):
+ """New signals arrived mid-run and the report is within the cap: re-promote to CANDIDATE and loop."""
+ report = await database_sync_to_async(SignalReport.objects.create)(
+ team=ateam,
+ status=SignalReport.Status.IN_PROGRESS,
+ signal_count=RERESEARCH_MAX_SIGNALS,
+ total_weight=2.0,
+ )
+ report_id = str(report.id)
+
+ with patch(f"{PIPELINE_MODULE_PATH}.posthoganalytics.capture"):
+ has_new_signals = await mark_report_ready_activity(
+ MarkReportReadyInput(
+ team_id=ateam.id,
+ report_id=report_id,
+ title="title",
+ summary="summary",
+ processed_signal_count=1,
+ source_products=["zendesk"],
+ )
+ )
+
+ assert has_new_signals is True
+ refreshed = await database_sync_to_async(SignalReport.objects.get)(id=report_id)
+ assert refreshed.status == SignalReport.Status.CANDIDATE
+
+
+async def test_ready_does_not_loop_when_new_signals_past_cap(ateam):
+ """New signals arrived mid-run but the report is past the cap: stay READY rather than looping
+ into another full research run."""
+ report = await database_sync_to_async(SignalReport.objects.create)(
+ team=ateam,
+ status=SignalReport.Status.IN_PROGRESS,
+ signal_count=RERESEARCH_MAX_SIGNALS + 5,
+ total_weight=2.0,
+ )
+ report_id = str(report.id)
+
+ with patch(f"{PIPELINE_MODULE_PATH}.posthoganalytics.capture"):
+ has_new_signals = await mark_report_ready_activity(
+ MarkReportReadyInput(
+ team_id=ateam.id,
+ report_id=report_id,
+ title="title",
+ summary="summary",
+ processed_signal_count=RERESEARCH_MAX_SIGNALS,
+ source_products=["zendesk"],
+ )
+ )
+
+ assert has_new_signals is False
+ refreshed = await database_sync_to_async(SignalReport.objects.get)(id=report_id)
+ assert refreshed.status == SignalReport.Status.READY