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.

fix(signals): keep report checks pending until the report resolves (#103499)

posthog[bot]5128782a02ca
diff --git a/products/signals/backend/models.py b/products/signals/backend/models.py
index fb065aa72dbc..bd48e0097290 100644
--- a/products/signals/backend/models.py
+++ b/products/signals/backend/models.py
@@ -1727,9 +1727,10 @@ class SignalReportCheck(UUIDModel):
days, and the check carries its own `next_run_at` rather than deriving one from a merged pull
request — plenty of fixes land with no pull request to date the window from.
- A check written before the fix exists has no date to carry, so it is stored PENDING with a
- `soak_minutes` window and the report's transition to RESOLVED sets its `next_run_at`. That makes
- the resolve the clock for every kind of fix, including the ones that never had a pull request.
+ A check on a report that has not resolved has no date worth carrying, because the fix it tests is
+ not live yet. Such a check is stored PENDING with a `soak_minutes` window, and the report's
+ transition to RESOLVED sets its `next_run_at`. That makes the resolve the clock for every kind of
+ fix, including the ones that never had a pull request.
Terminal statuses are final. A check that passed, failed, errored out, expired, or was cancelled
is never rescheduled; the author writes a new check instead, so a result artefact always refers
@@ -1745,8 +1746,8 @@ class SignalReportCheck(UUIDModel):
AGENT = "agent"
class Status(models.TextChoices):
- # Written before the fix it checks exists, so it carries a soak rather than a date and
- # waits for its report to resolve. Not due, not expired, and not terminal: the resolve
+ # Written while its report was still open, so it carries a soak rather than a date and
+ # waits for the report to resolve. Not due, not expired, and not terminal: the resolve
# transition arms it into ACTIVE (`report_check_authoring.arm_pending_checks`).
PENDING = "pending"
ACTIVE = "active"
diff --git a/products/signals/backend/report_check_authoring.py b/products/signals/backend/report_check_authoring.py
index 531f1f59c6db..32909a970472 100644
--- a/products/signals/backend/report_check_authoring.py
+++ b/products/signals/backend/report_check_authoring.py
@@ -5,11 +5,11 @@ they must agree on what a check row means, so the cap, the metric-query copy, an
live here rather than three times over. `report_checks.py` still owns the shapes and the bounds;
this module owns the write.
-A check written after the fix shipped names the date to look on. A check written *before* it cannot:
-the research turn authors its check in the same pass that writes the report, and many fixes never
-get a merged pull request to date a soak window from. Such a check is stored `pending` with a soak
-duration and armed by the report's transition to `resolved`, whatever caused it. That makes the
-resolve the clock for every kind of fix.
+The report's own state decides when a check first runs. A check on a resolved report names the date
+to look on. A check on a report that is still open cannot: the fix it re-measures has not shipped,
+and many fixes never get a merged pull request to date a soak window from. Such a check is stored
+`pending` with a soak duration and armed by the report's transition to `resolved`, whatever caused
+it. That makes the resolve the clock for every kind of fix.
"""
from __future__ import annotations
@@ -31,6 +31,8 @@ from products.signals.backend.report_checks import (
DEFAULT_CHECK_EXPIRY_AFTER_LAST_RUN,
MAX_ACTIVE_CHECKS_PER_REPORT,
MAX_CHECK_HORIZON,
+ MAX_CHECK_SOAK_HOURS,
+ MIN_CHECK_SOAK_HOURS,
CheckConfigValidationError,
CheckSpec,
MetricThresholdConfig,
@@ -60,12 +62,18 @@ def create_check(
) -> SignalReportCheck:
"""Write one check on a report, armed or pending.
- Pass `next_run_at` and `expires_at` for a check that already knows when to look. Pass
- `soak_minutes` instead for one that waits on the report resolving; the row is stored `pending`
- and its dates are provisional until `arm_pending_checks` rewrites them.
+ Pass `next_run_at` and `expires_at` for a check that names when to look. Pass `soak_minutes`
+ instead for one that names how long to wait after the report resolves.
+
+ Which of the two the row uses is the report's call, not the caller's. A report that has not
+ resolved has no fix live yet, so a check on it is stored `pending` with a soak, and its dates
+ stay provisional until `arm_pending_checks` rewrites them at the resolve. A dated check keeps
+ the gap its author left as that soak. Only a resolved report takes a date as written.
The report row is locked for the same reason the REST path locks it: the per-report cap is a
- count followed by an insert, which only holds if concurrent creates serialize.
+ count followed by an insert, which only holds if concurrent creates serialize. The status
+ decision is read under the same lock, so a resolve landing mid-write either precedes the row
+ or arms it.
"""
if (next_run_at is None) == (soak_minutes is None):
raise CheckCreationError("a check names either a next_run_at or a soak_minutes, not both and not neither")
@@ -90,20 +98,6 @@ def create_check(
raise CheckCreationError(f"This check cannot run: {error}.") from None
now = timezone.now()
- if soak_minutes is not None:
- status = SignalReportCheck.Status.PENDING
- # Provisional, and rewritten at arm time. The horizon is real though: a report that never
- # resolves retires its pending checks rather than holding them forever.
- next_run_at = now + timedelta(minutes=soak_minutes)
- expires_at = now + MAX_CHECK_HORIZON
- else:
- status = SignalReportCheck.Status.ACTIVE
- assert next_run_at is not None
- if expires_at is None:
- expires_at = min(
- _last_run_at(next_run_at, run_interval_minutes, runs_remaining) + DEFAULT_CHECK_EXPIRY_AFTER_LAST_RUN,
- now + MAX_CHECK_HORIZON,
- )
with transaction.atomic():
locked_report = SignalReport.objects.select_for_update().filter(id=report.id, team_id=report.team_id).first()
@@ -114,6 +108,26 @@ def create_check(
)
if open_checks.count() >= MAX_ACTIVE_CHECKS_PER_REPORT:
raise CheckCreationError(f"A report may carry at most {MAX_ACTIVE_CHECKS_PER_REPORT} active checks.")
+ if locked_report.status == SignalReport.Status.RESOLVED:
+ status = SignalReportCheck.Status.ACTIVE
+ if next_run_at is None:
+ assert soak_minutes is not None
+ next_run_at = now + timedelta(minutes=soak_minutes)
+ if expires_at is None:
+ expires_at = min(
+ _last_run_at(next_run_at, run_interval_minutes, runs_remaining)
+ + DEFAULT_CHECK_EXPIRY_AFTER_LAST_RUN,
+ now + MAX_CHECK_HORIZON,
+ )
+ else:
+ status = SignalReportCheck.Status.PENDING
+ if soak_minutes is None:
+ assert next_run_at is not None
+ soak_minutes = _soak_from_first_run(next_run_at, now)
+ # Provisional, and rewritten at arm time. The horizon is real though: a report that
+ # never resolves retires its pending checks rather than holding them forever.
+ next_run_at = now + timedelta(minutes=soak_minutes)
+ expires_at = now + MAX_CHECK_HORIZON
check = SignalReportCheck.objects.for_team(locked_report.team_id).create(
# The report's own environment team, never a canonicalized one: the report's reads and
# its artefact log filter by it.
@@ -149,10 +163,10 @@ def create_checks_from_specs(
) -> list[SignalReportCheck]:
"""Write a research run's check specs on the report it just finished.
- The specs replace the report's pending checks rather than joining them. Only research writes a
- pending check, so every pending row came from an earlier pass over an older version of this
- report. Left in place, those rows would fill the per-report cap, and the resolve would arm them
- against prose they were not written for. A pass that returns no specs leaves them alone, because
+ The specs replace the report's pending checks rather than joining them. Every pending row on the
+ report was written against an older version of this prose, which this pass has just rewritten.
+ Left in place, those rows would fill the per-report cap, and the resolve would arm them against
+ prose they were not written for. A pass that returns no specs leaves them alone, because
the verification turn is best-effort and an empty result can be a failed turn.
A spec the report cannot carry is dropped with a log rather than failing the run, the way an
@@ -223,6 +237,16 @@ def arm_pending_checks(*, team_id: int, report_id: str | uuid.UUID, resolved_at:
return armed
+def _soak_from_first_run(next_run_at: datetime, now: datetime) -> int:
+ """The soak a dated check keeps when its report has not resolved yet.
+
+ The author left a gap before the first run to allow for deploy and soak time, so that gap is
+ what the check waits out once the report resolves, bounded by what a soak may be.
+ """
+ minutes = round((next_run_at - now).total_seconds() / 60)
+ return max(MIN_CHECK_SOAK_HOURS * 60, min(minutes, MAX_CHECK_SOAK_HOURS * 60))
+
+
def _last_run_at(next_run_at: datetime, run_interval_minutes: int | None, runs_remaining: int) -> datetime:
if not run_interval_minutes:
return next_run_at
diff --git a/products/signals/backend/report_checks.py b/products/signals/backend/report_checks.py
index 54537fd533ea..8cc6545746d4 100644
--- a/products/signals/backend/report_checks.py
+++ b/products/signals/backend/report_checks.py
@@ -9,11 +9,13 @@ The soak window is the check's own clock. A fix does not always arrive as a merg
plenty land in the skills store with nothing to date the window from — so the author says when the
check runs rather than the system reading it off a merge.
-An author who writes the check *before* the fix exists has no date to name at all. The research
-turn is the case: it writes its check while the report is still being authored. Such a check names
-a soak duration instead and is stored `pending`, and the report's own transition to `resolved`
-starts its clock — whatever caused the transition, a merged pull request, a manual resolve, or an
-MCP state write. See ``CheckSpec`` and ``report_check_authoring.arm_pending_checks``.
+A check on a report that has not resolved cannot name a useful date, because the fix it tests is
+not live yet. The research turn is the clearest case: it writes its check while the report is still
+being authored, so it names a soak duration instead. Such a check is stored `pending`, and the
+report's own transition to `resolved` starts its clock — whatever caused the transition, a merged
+pull request, a manual resolve, or an MCP state write. A scout that names a date on an open report
+gets the same treatment, with the gap it left as the soak. See ``CheckSpec`` and
+``report_check_authoring.arm_pending_checks``.
This module stays Django-free and schema-free for the same reason as ``report_metrics``: model and
Temporal payload modules import it during process setup.
diff --git a/products/signals/backend/test/test_report_checks.py b/products/signals/backend/test/test_report_checks.py
index 5dc53ca127ec..20989657c085 100644
--- a/products/signals/backend/test/test_report_checks.py
+++ b/products/signals/backend/test/test_report_checks.py
@@ -56,6 +56,7 @@ from products.signals.backend.report_checks import (
MAX_CHECK_PROBE_HINT_LENGTH,
MAX_CHECK_PROBE_HINTS,
MAX_CHECK_RUNS,
+ MAX_CHECK_SOAK_HOURS,
MAX_CONSECUTIVE_CHECK_ERRORS,
MIN_CHECK_INTERVAL_MINUTES,
AgentCheckConfig,
@@ -1309,9 +1310,51 @@ class TestScoutCheckTools(APIBaseTest):
check = SignalReportCheck.objects.for_team(self.team.id).get(id=summary.check_id)
assert check.task_id == self.task.id
- assert check.status == SignalReportCheck.Status.ACTIVE
assert check.report_id == self.report.id
+ @parameterized.expand([(SignalReport.Status.READY,), (SignalReport.Status.SUPPRESSED,)])
+ def test_a_check_on_an_unresolved_report_waits_for_the_resolve(self, report_status: str) -> None:
+ self.report.status = report_status
+ self.report.save(update_fields=["status"])
+
+ check = SignalReportCheck.objects.for_team(self.team.id).get(id=self._create().check_id)
+
+ assert check.status == SignalReportCheck.Status.PENDING
+ # The gap the run left before its date is what the check waits out after the resolve.
+ assert check.soak_minutes == 3 * 24 * 60
+ assert collect_due_checks(timezone.now() + timedelta(days=7)) == []
+
+ def test_the_resolve_starts_the_clock_on_a_check_a_run_dated(self) -> None:
+ check = SignalReportCheck.objects.for_team(self.team.id).get(id=self._create().check_id)
+ before = timezone.now()
+
+ with self.captureOnCommitCallbacks(execute=True):
+ self.report.status = SignalReport.Status.RESOLVED
+ self.report.save(update_fields=["status"])
+
+ check.refresh_from_db()
+ soak = timedelta(days=3)
+ assert check.status == SignalReportCheck.Status.ACTIVE
+ assert before + soak <= check.next_run_at <= timezone.now() + soak
+
+ def test_a_check_on_a_resolved_report_runs_on_the_date_the_run_named(self) -> None:
+ self.report.status = SignalReport.Status.RESOLVED
+ self.report.save(update_fields=["status"])
+ first_run = timezone.now() + timedelta(days=3)
+
+ check = SignalReportCheck.objects.for_team(self.team.id).get(id=self._create(next_run_at=first_run).check_id)
+
+ assert check.status == SignalReportCheck.Status.ACTIVE
+ assert check.next_run_at == first_run
+ assert check.soak_minutes is None
+
+ def test_a_date_beyond_the_longest_soak_becomes_the_longest_soak(self) -> None:
+ check = SignalReportCheck.objects.for_team(self.team.id).get(
+ id=self._create(next_run_at=timezone.now() + timedelta(days=60)).check_id
+ )
+
+ assert check.soak_minutes == MAX_CHECK_SOAK_HOURS * 60
+
def test_a_run_reads_back_the_checks_it_would_otherwise_duplicate(self) -> None:
written = self._create()
@@ -1339,7 +1382,7 @@ class TestScoutCheckTools(APIBaseTest):
cancel_report_check(team=self.team, run=self.scout_run, check_id=written.check_id)
check = SignalReportCheck.objects.for_team(self.team.id).get()
- assert check.status == SignalReportCheck.Status.ACTIVE
+ assert check.status == SignalReportCheck.Status.PENDING
def test_another_projects_report_is_not_reachable(self) -> None:
other_team = Team.objects.create(organization=self.organization, name="other")
@@ -1414,6 +1457,20 @@ class TestResearchAuthoredChecks(APIBaseTest):
assert written == []
assert not SignalReportCheck.objects.for_team(self.team.id).filter(report=self.report).exists()
+ def test_a_spec_written_after_the_report_resolved_starts_its_soak_at_once(self) -> None:
+ self.report.status = SignalReport.Status.RESOLVED
+ self.report.save(update_fields=["status"])
+ before = timezone.now()
+
+ written = create_checks_from_specs(
+ report=self.report, specs=[self._spec()], attribution=ArtefactAttribution.system()
+ )
+
+ # Nothing left to wait for, so the check is armed rather than held for a resolve that already happened.
+ soak = timedelta(hours=DEFAULT_CHECK_SOAK_HOURS)
+ assert written[0].status == SignalReportCheck.Status.ACTIVE
+ assert before + soak <= written[0].next_run_at <= timezone.now() + soak
+
def test_a_longer_soak_is_honoured_for_a_fix_that_reaches_users_slowly(self) -> None:
written = create_checks_from_specs(
report=self.report, specs=[self._spec(soak_hours=72)], attribution=ArtefactAttribution.system()
diff --git a/products/signals/mcp/tools.yaml b/products/signals/mcp/tools.yaml
index c5faf7f0dffa..b3cbb4307129 100644
--- a/products/signals/mcp/tools.yaml
+++ b/products/signals/mcp/tools.yaml
@@ -908,9 +908,11 @@ tools:
which keeps compare mode off already. Use `agent` for a claim no single number settles: pass `instructions`
saying what a later run must establish and `probe_hints` naming the issue ids, services, or queries to look
at; it runs on the scout you name in `skill_name`, or on the fleet's follow-up scout when you name none.
- `next_run_at` is when to first look, so allow deploy and soak time. The verdict lands on the report as a
- `check_result` entry people read in the inbox. Check `scout-report-check-list` first: a report holds at most
- five open checks, and a second check for the same claim is noise.
+ `next_run_at` is when to first look, so allow deploy and soak time. On a report that has not resolved yet,
+ the check is stored `pending` instead of running on that date. The gap you left becomes the wait that starts
+ when the report resolves, so a check never measures the days before the fix shipped. The verdict lands on
+ the report as a `check_result` entry people read in the inbox. Check `scout-report-check-list` first: a
+ report holds at most five open checks, and a second check for the same claim is noise.
scout-report-check-list:
operation: signals_scout_report_checks_list
enabled: true
diff --git a/services/mcp/schema/generated-tool-definitions.json b/services/mcp/schema/generated-tool-definitions.json
index 4c376a21600e..901351b8a033 100644
--- a/services/mcp/schema/generated-tool-definitions.json
+++ b/services/mcp/schema/generated-tool-definitions.json
@@ -10163,7 +10163,7 @@
}
},
"scout-report-check-create": {
- "description": "Schedule a re-measurement of a report's claim, so \"did the fix hold?\" becomes a stored fact instead of something a future run has to remember to look for. Write one when this run surfaces something whose fix would show up in data later. Pass the `run_id` of your own in-progress run and the `report_id` of the report the check belongs to. Use `metric_threshold` when a bounded query and a baseline exist: pass a `config` with a `metric_id` naming one of the report's own metrics (or your own bounded Trends `query`), a `comparison` (`lte` / `gte` / `between`) saying what the value must satisfy, and the `baseline_value` you measured now. A `query` you supply must keep `dateRange.date_from` relative (`-13d`) and `date_to` empty, so each run measures the days before it rather than the days before the check was written — absolute dates are refused. The query must produce exactly one output series: use one event or action series, or combine up to ten of them with exactly one formula. Use no breakdown and no compare mode. A `trendsFilter.display` of `Metric` turns compare mode on, so `metricShowChange` is switched off for you unless `metricSummary` is `latest`, which keeps compare mode off already. Use `agent` for a claim no single number settles: pass `instructions` saying what a later run must establish and `probe_hints` naming the issue ids, services, or queries to look at; it runs on the scout you name in `skill_name`, or on the fleet's follow-up scout when you name none. `next_run_at` is when to first look, so allow deploy and soak time. The verdict lands on the report as a `check_result` entry people read in the inbox. Check `scout-report-check-list` first: a report holds at most five open checks, and a second check for the same claim is noise.",
+ "description": "Schedule a re-measurement of a report's claim, so \"did the fix hold?\" becomes a stored fact instead of something a future run has to remember to look for. Write one when this run surfaces something whose fix would show up in data later. Pass the `run_id` of your own in-progress run and the `report_id` of the report the check belongs to. Use `metric_threshold` when a bounded query and a baseline exist: pass a `config` with a `metric_id` naming one of the report's own metrics (or your own bounded Trends `query`), a `comparison` (`lte` / `gte` / `between`) saying what the value must satisfy, and the `baseline_value` you measured now. A `query` you supply must keep `dateRange.date_from` relative (`-13d`) and `date_to` empty, so each run measures the days before it rather than the days before the check was written — absolute dates are refused. The query must produce exactly one output series: use one event or action series, or combine up to ten of them with exactly one formula. Use no breakdown and no compare mode. A `trendsFilter.display` of `Metric` turns compare mode on, so `metricShowChange` is switched off for you unless `metricSummary` is `latest`, which keeps compare mode off already. Use `agent` for a claim no single number settles: pass `instructions` saying what a later run must establish and `probe_hints` naming the issue ids, services, or queries to look at; it runs on the scout you name in `skill_name`, or on the fleet's follow-up scout when you name none. `next_run_at` is when to first look, so allow deploy and soak time. On a report that has not resolved yet, the check is stored `pending` instead of running on that date. The gap you left becomes the wait that starts when the report resolves, so a check never measures the days before the fix shipped. The verdict lands on the report as a `check_result` entry people read in the inbox. Check `scout-report-check-list` first: a report holds at most five open checks, and a second check for the same claim is noise.",
"category": "Signals",
"feature": "signals",
"summary": "Write a follow-up check on a report",
diff --git a/services/mcp/schema/tool-definitions-all.json b/services/mcp/schema/tool-definitions-all.json
index 3109a822ad96..de558c229405 100644
--- a/services/mcp/schema/tool-definitions-all.json
+++ b/services/mcp/schema/tool-definitions-all.json
@@ -10735,7 +10735,7 @@
}
},
"scout-report-check-create": {
- "description": "Schedule a re-measurement of a report's claim, so \"did the fix hold?\" becomes a stored fact instead of something a future run has to remember to look for. Write one when this run surfaces something whose fix would show up in data later. Pass the `run_id` of your own in-progress run and the `report_id` of the report the check belongs to. Use `metric_threshold` when a bounded query and a baseline exist: pass a `config` with a `metric_id` naming one of the report's own metrics (or your own bounded Trends `query`), a `comparison` (`lte` / `gte` / `between`) saying what the value must satisfy, and the `baseline_value` you measured now. A `query` you supply must keep `dateRange.date_from` relative (`-13d`) and `date_to` empty, so each run measures the days before it rather than the days before the check was written — absolute dates are refused. The query must produce exactly one output series: use one event or action series, or combine up to ten of them with exactly one formula. Use no breakdown and no compare mode. A `trendsFilter.display` of `Metric` turns compare mode on, so `metricShowChange` is switched off for you unless `metricSummary` is `latest`, which keeps compare mode off already. Use `agent` for a claim no single number settles: pass `instructions` saying what a later run must establish and `probe_hints` naming the issue ids, services, or queries to look at; it runs on the scout you name in `skill_name`, or on the fleet's follow-up scout when you name none. `next_run_at` is when to first look, so allow deploy and soak time. The verdict lands on the report as a `check_result` entry people read in the inbox. Check `scout-report-check-list` first: a report holds at most five open checks, and a second check for the same claim is noise.",
+ "description": "Schedule a re-measurement of a report's claim, so \"did the fix hold?\" becomes a stored fact instead of something a future run has to remember to look for. Write one when this run surfaces something whose fix would show up in data later. Pass the `run_id` of your own in-progress run and the `report_id` of the report the check belongs to. Use `metric_threshold` when a bounded query and a baseline exist: pass a `config` with a `metric_id` naming one of the report's own metrics (or your own bounded Trends `query`), a `comparison` (`lte` / `gte` / `between`) saying what the value must satisfy, and the `baseline_value` you measured now. A `query` you supply must keep `dateRange.date_from` relative (`-13d`) and `date_to` empty, so each run measures the days before it rather than the days before the check was written — absolute dates are refused. The query must produce exactly one output series: use one event or action series, or combine up to ten of them with exactly one formula. Use no breakdown and no compare mode. A `trendsFilter.display` of `Metric` turns compare mode on, so `metricShowChange` is switched off for you unless `metricSummary` is `latest`, which keeps compare mode off already. Use `agent` for a claim no single number settles: pass `instructions` saying what a later run must establish and `probe_hints` naming the issue ids, services, or queries to look at; it runs on the scout you name in `skill_name`, or on the fleet's follow-up scout when you name none. `next_run_at` is when to first look, so allow deploy and soak time. On a report that has not resolved yet, the check is stored `pending` instead of running on that date. The gap you left becomes the wait that starts when the report resolves, so a check never measures the days before the fix shipped. The verdict lands on the report as a `check_result` entry people read in the inbox. Check `scout-report-check-list` first: a report holds at most five open checks, and a second check for the same claim is noise.",
"category": "Signals",
"feature": "signals",
"summary": "Write a follow-up check on a report",