Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

refactor(signals): slim anomaly-detection report-contract to its notebook recipe (#67154)

Andrew Maguire6da92d0a011c
diff --git a/products/signals/backend/scout_harness/prompt.py b/products/signals/backend/scout_harness/prompt.py
index 8926050d8680..c93b002beb7a 100644
--- a/products/signals/backend/scout_harness/prompt.py
+++ b/products/signals/backend/scout_harness/prompt.py
@@ -264,10 +264,11 @@ main failure mode here, so the discipline is **search, then decide**:
as genuinely new (author a fresh report and repoint your `report:` pointer at it).
- **Author only when it's genuinely new.** A materially new issue — or a known one with
new evidence that changes the verdict, or a relapse whose prior report is no longer
- live — warrants a fresh report. Never retry an `emit_report` that looked like it
- failed: a retry that actually succeeded the first time silently doubles the report.
- If unsure whether it landed, look it up with `inbox-reports-list` rather than
- re-emitting."""
+ live — warrants a fresh report. Neither `emit_report` nor `edit_report` is idempotent —
+ never retry a call that looked like it failed: a retried `emit_report` that actually
+ landed silently doubles the report, and a retried `edit_report(append_note=...)` appends
+ a second note. If unsure whether it landed, re-read with `inbox-reports-list` /
+ `inbox-reports-retrieve` rather than re-sending."""
_AUTHORING_REPORT_EMIT_ONLY = """# Authoring reports: search the inbox first
@@ -312,8 +313,9 @@ report your evidence bears on, then keep it current:
Rewrite `title`/`summary` only on a report you own, and only when the framing is
genuinely stale; lead the summary with the verdict (see *Writing the summary*).
- **Route an unrouted report.** If a report surfaced assigned to no one, set
- `suggested_reviewers` to route it to an owner — each reviewer a bare lowercase
- `github_login`, or a PostHog `user_uuid` the server resolves for you. If the owner
+ `suggested_reviewers` to route it to an owner — each reviewer an object, `{github_login}`
+ (a bare lowercase login, no `@`) or `{user_uuid}` (the server resolves it for you), never
+ a bare string. If the owner
isn't already named in the report, call `signals-scout-members-list` to look up this
project's members (each carries a resolved `github_login`; the org-scoped
`org-member-get-github-login` / `org-members-list` tools aren't available in a scout
@@ -349,7 +351,7 @@ Treat it as an **index into the inbox, never a copy of the report**:
_SUGGESTED_REVIEWERS_REPORT = """# Suggested reviewers route the report
This is the single highest-leverage field you set. `suggested_reviewers` (a list of
-reviewers, each a `github_login` and/or a PostHog `user_uuid`) is what actually
+reviewer **objects**, each `{github_login}` and/or `{user_uuid}` — never a bare string) is what actually
**routes** a report to the people who can act on it — and, paired with `priority` +
`repository`, is what lets an immediately-actionable report open a draft PR
automatically (autostart). A report with no suggested reviewers still surfaces in the
@@ -358,10 +360,11 @@ inbox, but it routes to no one, so it tends to sit unactioned.
- **Always try to set `suggested_reviewers`.** Spend real effort identifying who
owns the affected area — lean on the evidence you already gathered (code owners,
recent authors on the relevant surface, the team that owns the product) to name
- the right owner. You can identify each reviewer two ways: a bare lowercase
- `github_login`, or — when your evidence already names a PostHog user (an account
- owner, an entity's creator) — that user's `user_uuid`, which the server resolves to
- their linked GitHub login for you. Treat "I couldn't find an owner" as a last
+ the right owner. Each reviewer is an object, identifiable two ways: by `github_login`
+ (a bare lowercase login — `{github_login: "octocat"}`, no `@`, no display name), or —
+ when your evidence already names a PostHog user (an account owner, an entity's
+ creator) — by `user_uuid` (`{user_uuid: "..."}`), which the server resolves to their
+ linked GitHub login for you. Treat "I couldn't find an owner" as a last
resort, not a default.
- **Don't guess a `github_login`.** The inbox routes by matching it exactly, so a
guessed, mis-cased, or display-name handle reaches no one. When you only know the
diff --git a/products/signals/skills/signals-scout-anomaly-detection/references/report-contract.md b/products/signals/skills/signals-scout-anomaly-detection/references/report-contract.md
index acd475e816ec..ec01db615b64 100644
--- a/products/signals/skills/signals-scout-anomaly-detection/references/report-contract.md
+++ b/products/signals/skills/signals-scout-anomaly-detection/references/report-contract.md
@@ -27,18 +27,18 @@ Below that bar, write a `baseline:` / `noise:` scratchpad entry instead — don'
## `emit_report` — author a full report
-| Field | Type | Notes |
-| --------------------------- | ------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
-| `title` | string, ≤300, non-empty | The inbox headline. One specific, quantified line (see below). |
-| `summary` | string | The report body prose — hook → pattern → hypothesis → lineage → recommendation (see below). |
-| `evidence` | list, 1–50 | Each `{description, source_id}`. Becomes a bound signal row backing the report. |
-| `actionability_explanation` | string | One sentence justifying the actionability call. |
-| `actionability` | enum | `immediately_actionable` / `requires_human_input` / `not_actionable`. You make the call. |
-| `already_addressed` | bool, default `false` | Set when the move is already handled and you're filing for the record. |
-| `suggested_reviewers` | list of `{github_login}` | Who owns the metric/dashboard — routes the report. Each entry is an object (`{github_login: "octocat"}`), not a bare string. Optional but high-leverage. |
-| `priority` | `P0`–`P4` | Optional; pair with `priority_explanation`. Needed for an autostart draft PR. |
-| `priority_explanation` | string | Required when `priority` is set. |
-| `repository` | string | `owner/repo` for a code fix, the `NO_REPO` sentinel for a pure metric move, omitted for free-form. |
+| Field | Type | Notes |
+| --------------------------- | ----------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| `title` | string, ≤300, non-empty | The inbox headline. One specific, quantified line (see below). |
+| `summary` | string | The report body prose — hook → pattern → hypothesis → lineage → recommendation (see below). |
+| `evidence` | list, 1–50 | Each `{description, source_id}`. Becomes a bound signal row backing the report. |
+| `actionability_explanation` | string | One sentence justifying the actionability call. |
+| `actionability` | enum | `immediately_actionable` / `requires_human_input` / `not_actionable`. You make the call. |
+| `already_addressed` | bool, default `false` | Set when the move is already handled and you're filing for the record. |
+| `suggested_reviewers` | list of objects | Who owns the metric/dashboard — routes the report. Each entry is `{github_login}` and/or `{user_uuid}` (not a bare string). High-leverage — set it (see below). |
+| `priority` | `P0`–`P4` | Optional; pair with `priority_explanation`. Needed for an autostart draft PR. |
+| `priority_explanation` | string | Required when `priority` is set. |
+| `repository` | string | `owner/repo` for a code fix, the `NO_REPO` sentinel for a pure metric move, omitted for free-form. |
The result carries `report_id` (always set when a report was persisted — even when suppressed,
so you can edit / dedup against it), `report_status`, `emitted` (true only when it surfaced as
@@ -108,11 +108,12 @@ the durable artifact the human opens.
### Suggested reviewers
-The single highest-leverage field — it **routes** the report to whoever owns the metric. Resolve
-the login cheapest-source-first (a `reviewer:anomaly_detection:<area>` scratchpad entry you cached
-before; inbox precedent via `inbox-reports-list` on the same dashboard/surface), and cache it back
-for next run. Each entry is a bare, lowercase GitHub login. If you can't resolve a confident login,
-leave it empty — the report still surfaces — but never guess a handle.
+The single highest-leverage field — it **routes** the report to whoever owns the metric. The
+harness prompt covers resolution in full (resolve via `signals-scout-members-list`, each entry an
+object `{github_login}` and/or `{user_uuid}`, and `edit_report` can route an orphaned report). The
+anomaly specifics: cache the owner under a `reviewer:anomaly_detection:<area>` key, and reuse inbox
+precedent (`inbox-reports-list` on the same dashboard/surface, then `inbox-report-artefacts-list`)
+for who has owned that metric before. Never guess a handle.
## `edit_report` — update on a recurrence
@@ -136,24 +137,16 @@ building the notebook until the edit is about to commit.
A genuinely distinct anomaly (a different insight, or a new move on the same one after the prior
was resolved) is a new `emit_report`, with a `summary` lineage line citing the prior report.
-## Dedup: the channel is NOT idempotent
+## Dedup
-`emit_report` has no server-side dedup key — a retried call authors a **second** report. The
-dedup is yours, two-sided:
-
-1. **Before authoring**, `inbox-reports-list` (search by the insight / metric / dashboard) and
- check your `report:anomaly_detection:insight:<short_id>` pointer. Found one? Check whether it
- is **live** before editing: if the pointer is flagged suppressed, or `inbox-reports-retrieve`
- shows the report is suppressed / already resolved, `edit_report` can't resurface it — author a
- fresh report (with a `summary` lineage line citing the prior `report_id`) instead. Only
- `edit_report` a report that is still surfaced.
-2. **After authoring**, write the `report:` pointer with the `report_id` (and its status, so the
- next run applies the live-check above).
-
-**Never retry an `emit_report` / `edit_report` that may have landed** — if unsure, `inbox-reports-list`
-to check before re-sending. The pipeline may later re-research and rewrite a report you authored;
-that's accepted — your durable record of "I filed this" is the `report_id` in the pointer, not the
-title text.
+The channel isn't idempotent, and the harness prompt covers the general discipline (search the
+inbox first with `ordering=-updated_at`, edit over a near-duplicate, never retry a call that may
+have landed, and the accepted caveat that the pipeline may later rewrite a report you authored).
+The anomaly specifics: dedup by the insight via your
+`report:anomaly_detection:insight:<short_id>` pointer (and `inbox-reports-list` on the insight /
+metric / dashboard), and **live-check before editing** — a suppressed or resolved report can't be
+resurfaced by `edit_report`, so re-author with a `summary` lineage line citing the prior
+`report_id` instead of editing the invisible one.
## The notebook write-up