:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(signals): document the report-check query rules (#103045)
posthog[bot]011ac42e291e
diff --git a/.agents/skills/implementing-mcp-tools/SKILL.md b/.agents/skills/implementing-mcp-tools/SKILL.mdindex f3a7ff781d6c..44d6f174ab36 100644--- a/.agents/skills/implementing-mcp-tools/SKILL.md+++ b/.agents/skills/implementing-mcp-tools/SKILL.md@@ -185,6 +185,21 @@ Reusing the same flag key with both behaviors performs an atomic swap: flag onFlags are evaluated in parallel at init via `evaluateFeatureFlags`. If a flag can't be evaluated (service error, missing flag), `enable`-gated tools are excluded and `disable`-gated tools are included — fail-closed for new tools, fail-open for existing ones.+### Enabling or renaming a tool++The MCP server and Django deploy separately.+A tool that reaches clients before its route lands returns 404 on every call until the Django deploy catches up.+That hits a whole agent fleet at once.++- **Land the route first.** Ship the endpoint, then enable the tool in a later change. A tool with+ `enabled: true` in the same commit as a brand-new route is live in clients as soon as the MCP+ server deploys.+- **Or gate it.** Add `feature_flag` with `feature_flag_behavior: enable` and turn the flag on once+ the route is serving.+- **Keep the old name on a rename.** Leave the previous tool name in the YAML, pointing at the same+ operation, until the new name has deployed everywhere. Sunset it with+ `feature_flag_behavior: disable` on the same flag key, which swaps the two atomically.+### Syncing after endpoint changes```shdiff --git a/products/signals/backend/report_checks.py b/products/signals/backend/report_checks.pyindex 134dcdda818f..54537fd533ea 100644--- a/products/signals/backend/report_checks.py+++ b/products/signals/backend/report_checks.py@@ -147,7 +147,12 @@ class MetricThresholdConfig(BaseModel):default=None,description=("Live InsightVizNode wrapping one TrendsQuery: supplied by the caller, or copied from the named "- "metric when the check is created."+ "metric when the check is created. `dateRange.date_from` must be a relative window such as `-13d`, "+ "and `date_to` must be empty, so the check measures the days before each run rather than the days "+ "before it was written. 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."),)comparison: CheckComparison = Field(description="What the measured value must satisfy to pass.")diff --git a/products/signals/backend/report_generation/research.py b/products/signals/backend/report_generation/research.pyindex 0af600177ca3..5c5555dd0d9a 100644--- a/products/signals/backend/report_generation/research.py+++ b/products/signals/backend/report_generation/research.py@@ -551,7 +551,7 @@ _REPORT_CHARTS_GUIDANCE = f"""## Attaching charts- **Place it from the summary.** A markdown link with a `chart:` target — `[Daily signups](chart:signups-drop)` — draws the chart at that point in the body; reference it once. A chart you never reference still renders, after the prose. Two references in one paragraph sit side by side.- **Prose must stand on its own.** The report is also delivered to Slack, where nothing draws a chart and a reference degrades to its plain label. State the finding in words and let the chart corroborate it — never "the chart below shows the drop".- **Let the chart carry the series.** The prose keeps the finding and the one or two numbers that size it, so a Slack reader still gets it; what the chart takes over is the interval-by-interval recital. "Step-2 conversion fell from 62% to 48% over the week" beside a chart beats a sentence listing every day.-- **Pin the window** to absolute dates wherever the node supports it, so the reader sees the data you wrote about rather than whatever a relative range resolves to days later.+- **Pin the window** to absolute dates wherever the node supports it, so the reader sees the data you wrote about rather than whatever a relative range resolves to days later. This holds for charts alone. A metric and a follow-up check measure the period before each run, so each one needs a relative `dateRange.date_from` and an empty `date_to`. An absolute window is refused there.- **At most {MAX_REPORT_CHARTS} per report**, far more than any report should use — three charts a reader studies beat a dozen they scroll past.- **`charts` is the report's whole set.** It replaces whatever the report showed before, the way title and summary do. To keep a chart across a re-research, send it again; drop one by leaving it out."""diff --git a/products/signals/backend/report_metrics.py b/products/signals/backend/report_metrics.pyindex bbde9f334326..1d2fa6d77354 100644--- a/products/signals/backend/report_metrics.py+++ b/products/signals/backend/report_metrics.py@@ -199,6 +199,9 @@ def validate_live_metric_query(value: dict[str, Any]) -> dict[str, Any]:advances with time, an allowlisted node set, event or action sources only, and an estimatedpoint count a reader can afford. A check rides the same rules as a metric because both end upin the same query runner.++ The Metric display's change pill is switched off rather than refused, because the stored display+ is not authoritative and no author intent is lost."""validate_report_query(value, allowed_kinds=_LIVE_METRIC_QUERY_KINDS)@@ -257,10 +260,11 @@ def validate_live_metric_query(value: dict[str, Any]) -> dict[str, Any]:and trends_filter.get("metricShowChange", True) is not Falseand trends_filter.get("metricSummary", "total") != "latest"):- raise ValueError(- "a live metric query using the Metric display must disable metricShowChange or use the latest "- "summary so the Trends runner does not enable compare mode"- )+ # The Metric display turns compare mode on implicitly, which would multiply the output+ # series past the one this contract allows.+ trends_filter = {**trends_filter, "metricShowChange": False}+ source = {**source, "trendsFilter": trends_filter}+ value = {**value, "source": source}date_range = source.get("dateRange")if not isinstance(date_range, dict):raise ValueError("query.source.dateRange.date_from must be a relative time window such as `-30d`")diff --git a/products/signals/backend/test/test_report_metrics.py b/products/signals/backend/test/test_report_metrics.pyindex 95d8b92ad269..6a6c8acffed2 100644--- a/products/signals/backend/test/test_report_metrics.py+++ b/products/signals/backend/test/test_report_metrics.py@@ -91,7 +91,6 @@ class TestReportMetric(SimpleTestCase):for source_patch, error in (({"breakdownFilter": {"breakdown": "$browser"}}, "must not use a breakdown"),({"compareFilter": {"compare": True}}, "must not use compare mode"),- ({"trendsFilter": {"display": "Metric"}}, "Metric display must disable metricShowChange"),):with self.subTest(source_patch=source_patch):content = _affected_users_metric().model_dump(mode="json")@@ -112,6 +111,15 @@ class TestReportMetric(SimpleTestCase):content["query"]["source"]["trendsFilter"] = trends_filterassert ReportMetric.model_validate(content).query is not None+ def test_live_query_switches_off_the_metric_display_change_pill(self) -> None:+ content = _affected_users_metric().model_dump(mode="json")+ content["query"]["source"]["trendsFilter"] = {"display": "Metric"}++ metric = ReportMetric.model_validate(content)++ assert metric.query is not None+ assert metric.query["source"]["trendsFilter"] == {"display": "Metric", "metricShowChange": False}+def test_live_query_rejects_a_sampling_factor_outside_the_valid_range(self) -> None:for sampling_factor in (0, -0.5, 1.5, "0.5"):with self.subTest(sampling_factor=sampling_factor):diff --git a/products/signals/frontend/generated/api.schemas.ts b/products/signals/frontend/generated/api.schemas.tsindex 547b7086383f..d43cdbdfe2fe 100644--- a/products/signals/frontend/generated/api.schemas.ts+++ b/products/signals/frontend/generated/api.schemas.ts@@ -2344,7 +2344,7 @@ export interface CheckComparisonApi {}/**- * Live InsightVizNode wrapping one TrendsQuery: supplied by the caller, or copied from the named metric when the check is created.+ * Live InsightVizNode wrapping one TrendsQuery: supplied by the caller, or copied from the named metric when the check is created. `dateRange.date_from` must be a relative window such as `-13d`, and `date_to` must be empty, so the check measures the days before each run rather than the days before it was written. 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.*/export type MetricThresholdConfigApiQuery = { [key: string]: unknown } | null@@ -2365,7 +2365,7 @@ export type MetricThresholdConfigApiQuery = { [key: string]: unknown } | nullexport interface MetricThresholdConfigApi {/** Identifier of a metric on the report whose query this check measures. The metric's query is copied into `query` when the check is created. */metric_id?: string | null- /** Live InsightVizNode wrapping one TrendsQuery: supplied by the caller, or copied from the named metric when the check is created. */+ /** Live InsightVizNode wrapping one TrendsQuery: supplied by the caller, or copied from the named metric when the check is created. `dateRange.date_from` must be a relative window such as `-13d`, and `date_to` must be empty, so the check measures the days before each run rather than the days before it was written. 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. */query?: MetricThresholdConfigApiQuery/** What the measured value must satisfy to pass. */comparison: CheckComparisonApidiff --git a/products/signals/frontend/generated/api.zod.ts b/products/signals/frontend/generated/api.zod.tsindex 40caf0a82dd8..7616c13acced 100644--- a/products/signals/frontend/generated/api.zod.ts+++ b/products/signals/frontend/generated/api.zod.ts@@ -1970,7 +1970,7 @@ export const SignalsScoutReportCheckCreateBody = /* @__PURE__ */ zod.union([zod.record(zod.string(), zod.unknown()), zod.null()]).optional().describe(- 'Live InsightVizNode wrapping one TrendsQuery: supplied by the caller, or copied from the named metric when the check is created.'+ 'Live InsightVizNode wrapping one TrendsQuery: supplied by the caller, or copied from the named metric when the check is created. `dateRange.date_from` must be a relative window such as `-13d`, and `date_to` must be empty, so the check measures the days before each run rather than the days before it was written. 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.'),comparison: zod.object({diff --git a/products/signals/mcp/tools.yaml b/products/signals/mcp/tools.yamlindex 6be06a141303..18f8ca2779d9 100644--- a/products/signals/mcp/tools.yaml+++ b/products/signals/mcp/tools.yaml@@ -882,15 +882,21 @@ tools:description: >Schedule a re-measurement of a report's claim, so "did the fix hold?" becomes a stored fact instead ofsomething a future run has to remember to look for. Write one when this run surfaces something whose fix- would show up in data later. 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. 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.+ 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.scout-report-check-list:operation: signals_scout_report_checks_listenabled: true@@ -902,7 +908,8 @@ tools:idempotent: truetitle: List a report's follow-up checksdescription: >- Every follow-up check on one report, newest first, with its kind, status, next run and last verdict. Read+ Every follow-up check on one report, newest first, with its kind, status, next run and last verdict. Pass+ the `run_id` of your own in-progress run and the `report_id` of the report to read; both are required. Readthis before writing a check: a report already carrying one for the same claim needs no second, and a reportholds at most five open checks at a time. A `pending` check is waiting for the report to resolve before itsclock starts; every status other than `pending` and `active` is terminal.diff --git a/services/mcp/schema/generated-tool-definitions.json b/services/mcp/schema/generated-tool-definitions.jsonindex 5c20bf5f5c8c..29a47d14a1ee 100644--- a/services/mcp/schema/generated-tool-definitions.json+++ b/services/mcp/schema/generated-tool-definitions.json@@ -10135,7 +10135,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. 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. 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. 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",@@ -10149,7 +10149,7 @@}},"scout-report-check-list": {- "description": "Every follow-up check on one report, newest first, with its kind, status, next run and last verdict. Read this before writing a check: a report already carrying one for the same claim needs no second, and a report holds at most five open checks at a time. A `pending` check is waiting for the report to resolve before its clock starts; every status other than `pending` and `active` is terminal.",+ "description": "Every follow-up check on one report, newest first, with its kind, status, next run and last verdict. Pass the `run_id` of your own in-progress run and the `report_id` of the report to read; both are required. Read this before writing a check: a report already carrying one for the same claim needs no second, and a report holds at most five open checks at a time. A `pending` check is waiting for the report to resolve before its clock starts; every status other than `pending` and `active` is terminal.","category": "Signals","feature": "signals","summary": "List a report's follow-up checks",diff --git a/services/mcp/schema/tool-definitions-all.json b/services/mcp/schema/tool-definitions-all.jsonindex cf63b3bdbe78..5546e7e14d78 100644--- a/services/mcp/schema/tool-definitions-all.json+++ b/services/mcp/schema/tool-definitions-all.json@@ -10707,7 +10707,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. 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. 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. 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",@@ -10721,7 +10721,7 @@}},"scout-report-check-list": {- "description": "Every follow-up check on one report, newest first, with its kind, status, next run and last verdict. Read this before writing a check: a report already carrying one for the same claim needs no second, and a report holds at most five open checks at a time. A `pending` check is waiting for the report to resolve before its clock starts; every status other than `pending` and `active` is terminal.",+ "description": "Every follow-up check on one report, newest first, with its kind, status, next run and last verdict. Pass the `run_id` of your own in-progress run and the `report_id` of the report to read; both are required. Read this before writing a check: a report already carrying one for the same claim needs no second, and a report holds at most five open checks at a time. A `pending` check is waiting for the report to resolve before its clock starts; every status other than `pending` and `active` is terminal.","category": "Signals","feature": "signals","summary": "List a report's follow-up checks",diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex 28684bf57ce8..fe7d1dc716d8 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -21688,7 +21688,7 @@ export namespace Schemas {} as const;/**- * Live InsightVizNode wrapping one TrendsQuery: supplied by the caller, or copied from the named metric when the check is created.+ * Live InsightVizNode wrapping one TrendsQuery: supplied by the caller, or copied from the named metric when the check is created. `dateRange.date_from` must be a relative window such as `-13d`, and `date_to` must be empty, so the check measures the days before each run rather than the days before it was written. 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.*/export type MetricThresholdConfigQuery = { [key: string]: unknown } | null;@@ -21709,7 +21709,7 @@ export namespace Schemas {export interface MetricThresholdConfig {/** Identifier of a metric on the report whose query this check measures. The metric's query is copied into `query` when the check is created. */metric_id?: string | null;- /** Live InsightVizNode wrapping one TrendsQuery: supplied by the caller, or copied from the named metric when the check is created. */+ /** Live InsightVizNode wrapping one TrendsQuery: supplied by the caller, or copied from the named metric when the check is created. `dateRange.date_from` must be a relative window such as `-13d`, and `date_to` must be empty, so the check measures the days before each run rather than the days before it was written. 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. */query?: MetricThresholdConfigQuery;/** What the measured value must satisfy to pass. */comparison: CheckComparison;diff --git a/services/mcp/src/generated/signals/api.ts b/services/mcp/src/generated/signals/api.tsindex f3420f87b170..3bfd34e7fa21 100644--- a/services/mcp/src/generated/signals/api.ts+++ b/services/mcp/src/generated/signals/api.ts@@ -2533,7 +2533,7 @@ export const SignalsScoutReportCheckCreateBody = () => zod.union([zod.record(zod.string(), zod.unknown()), zod.null()]).optional().describe(- 'Live InsightVizNode wrapping one TrendsQuery: supplied by the caller, or copied from the named metric when the check is created.'+ 'Live InsightVizNode wrapping one TrendsQuery: supplied by the caller, or copied from the named metric when the check is created. `dateRange.date_from` must be a relative window such as `-13d`, and `date_to` must be empty, so the check measures the days before each run rather than the days before it was written. 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.'),comparison: zod.object({