: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 scheduled pre-check in the scout guides (#115622)
posthog[bot]2a0b38b35806
diff --git a/products/signals/skills/authoring-scouts/SKILL.md b/products/signals/skills/authoring-scouts/SKILL.mdindex f7e0bb6f57f6..def1393ac6da 100644--- a/products/signals/skills/authoring-scouts/SKILL.md+++ b/products/signals/skills/authoring-scouts/SKILL.md@@ -141,6 +141,12 @@ For an **existing scout**, tune with `posthog:scout-config-update` (find the `idA new or edited schedule anchors on the edit time and waits for its next slot rather than catching up on a past one.Reach for it when the run should land at a wall-clock time: a digest before standup, a weekday-only watch.- `enabled` — `false` pauses the scout entirely (coordinator skips it).+- `precheck_query` — defaults to null: a HogQL `SELECT` that a scheduled run evaluates before it starts, with `{since}`, `{now}`, and `{interval_minutes}` placeholders.+ No rows, or one row with one false value (such as a zero `count()`), skips the run before it creates a run row or a sandbox. Any other result starts the run, and the rows enter the run prompt. A query error also starts the run.+ Only scheduled runs evaluate it: a manual, workflow, or report-check run always starts.+ Set it for a scout that has nothing to do on most ticks. Test the query with `posthog:scout-config-precheck-test` before you save it, because a scheduled check runs as the scout's acting user and the dry run runs as you.+ A canonical scout can ship a default in its `scout-precheck-query` frontmatter. `precheck_query` overrides that default, null restores it, and `precheck_disabled: true` turns off both.+ The full recipe, the placeholder semantics, and how to diagnose a tick with no run row are in [`references/scheduled-precheck.md`](references/scheduled-precheck.md).- `emit` — defaults to **`true`**: the scout writes its reports straight to the inbox.Set **`emit=false` (dry-run)** to inspect an ordinary run's reasoning without publishing reports to the inbox.Private trials capture reports and memory separately and work while the source scout is paused or has `emit=false`.diff --git a/products/signals/skills/authoring-scouts/references/scheduled-precheck.md b/products/signals/skills/authoring-scouts/references/scheduled-precheck.mdnew file mode 100644index 000000000000..2cada71c00c0--- /dev/null+++ b/products/signals/skills/authoring-scouts/references/scheduled-precheck.md@@ -0,0 +1,137 @@+# Scheduled-run pre-check++A **pre-check** is a HogQL `SELECT` that a scheduled run evaluates before it starts.+When the query finds nothing new, the run does not start: no run row, no sandbox, and no model call.+Use a pre-check for a scout that has nothing to do on most ticks, for example a scout that watches a product the project uses rarely.+The pointless-run rate in `exploring-scouts` (`has_not_in_use_closeout`) tells you which scout to gate first.++## Contents++- [When the gate skips a run](#when-the-gate-skips-a-run)+- [Placeholders](#placeholders)+- [Recipe: test, then save](#recipe-test-then-save)+- [Where the query comes from](#where-the-query-comes-from)+- [Canonical default in frontmatter](#canonical-default-in-frontmatter)+- [Tell the body about the rows](#tell-the-body-about-the-rows)+- [Diagnose a tick with no run row](#diagnose-a-tick-with-no-run-row)++## When the gate skips a run++| Query result | Outcome |+| ----------------------------------------------------------- | ---------------------------------------------- |+| No rows | Skip (`no_rows`) |+| One row with one false value (`false`, `0`, null, or empty) | Skip (`false_value`) |+| Any other result | Run. The scout reads the rows. |+| Query error or timeout | Run (`query_error`), as if no pre-check exists |++- The single-value rule lets `SELECT count() ...` work as written: a zero count skips.+ A row with two columns never matches this rule, so `SELECT count(), max(timestamp) ...` always runs.+ To skip on absence with more than one column, use `GROUP BY` (no groups means no rows) or `HAVING`.+- A query error never turns the scout off. A broken pre-check costs a sandbox run on every tick, so test the query first.+- The query stops after 10 seconds and reads at most 50 rows.+- Only scheduled runs evaluate the pre-check. A manual run (`scout-run-now`), a workflow run, and a report-check run always start.++## Placeholders++- `{since}`: the start of the last run that ran, or the time the scout was created. A skipped tick writes no run row, so `{since}` does not move. The next run that starts still sees everything since the last run that ran.+- `{now}`: the current time.+- `{interval_minutes}`: the gap between two scheduled runs. For a cron schedule, it is the gap between the fire time before now and the one after it, in the project's timezone.++Add a backstop so a quiet scout still runs from time to time.+This condition runs at least once a day, and never more often than every two intervals:++```sql+{since} < {now} - toIntervalMinute(greatest(1440, 2 * {interval_minutes}))+```++Example: run only when new exceptions arrived, or when the scout was quiet for a week.++```sql+SELECT count() > 0 OR {since} < {now} - INTERVAL 7 DAY+FROM events+WHERE event = '$exception' AND timestamp > {since}+```++## Recipe: test, then save++1. Find the config `id` with `posthog:scout-config-list`.+2. Dry-run the query with `posthog:scout-config-precheck-test {"id": "<config id>", "precheck_query": "<query>"}`.+ Omit `precheck_query` to test the query the scout uses now.+ The tool saves nothing and starts no run.+3. Read the result:+ - `would_run` and `reason` say if the next scheduled run would start (`rows`, `query_error`) or skip (`no_rows`, `false_value`).+ - `rows_text` is the text the scout reads, one JSON object per line.+ - `error` holds a query error. Fix the query and test again.+ - `acting_user` is set when scheduled runs check the query as a different user. See the access note below.+4. Save the query with `posthog:scout-config-update {"id": "<config id>", "precheck_query": "<query>"}`.++**Access.** The dry run runs as you, the person who asks for it.+A scheduled pre-check runs as the scout's acting user, so it reads the same tables that the scout's runs read.+When `acting_user` is set, that user's access can differ from yours: a `system.*` or warehouse table that your dry run reads can fail on a scheduled run.+A failed scheduled query does not skip the run, so this failure costs a sandbox run on each tick but does not stop the scout.++## Where the query comes from++A scheduled run uses the first source that applies:++1. `precheck_disabled` is true: no pre-check. The scout runs on every due tick.+2. The config's own `precheck_query`.+3. The default that a canonical scout's skill ships (see below), for a project inside that skill's rollout.+ A project outside the rollout runs with no pre-check.++`posthog:scout-config-list` shows the result:++- `effective_precheck_query`: the query the next scheduled run uses, or null when no pre-check runs.+- `precheck_query_source`: `config`, `skill_default`, or `off`.++To change the gate, use `posthog:scout-config-update`:++- `precheck_query` set to a query: overrides the canonical default.+- `precheck_query` set to null or blank: removes the override, so the canonical default applies again (if there is one).+- `precheck_disabled: true`: turns off every pre-check, both the override and the default, so every scheduled run starts.+ Set it back to `false` to use the pre-check again.++The nested `config` of `scout-create` also takes `precheck_query`, but not `precheck_disabled`.+The dry-run tool needs a config `id`, so for a new scout, create it with `config.enabled=false`, test the query, save it, and then enable the scout.++## Canonical default in frontmatter++A canonical scout can ship a default pre-check in its `SKILL.md` frontmatter under `scout-precheck-query`.+Only a `signals-scout-*` skill can declare it.+The build rejects a value that is empty, longer than 10,000 characters, or not a valid HogQL `SELECT`.++```yaml+scout-precheck-query: |+ SELECT event, count() AS events, max(timestamp) AS last_seen+ FROM events+ WHERE event = '$mcp_tool_call'+ AND timestamp > {now} - INTERVAL 7 DAY+ GROUP BY event+```++- The harness reads the default from the canonical skill file that PostHog ships, not from a project's copy of the skill.+ Adding `scout-precheck-query` to a custom scout or to a team's edited copy changes nothing. For those scouts, save `precheck_query` on the config.+- A merged default does not apply to every project at once. A rollout setting decides which projects get it.+- When you write a canonical default, use the canonical scouts that already ship one (for example `signals-scout-mcp-tool-calls` above, or `signals-scout-surveys`) as models.++## Tell the body about the rows++When a pre-check starts a run, the run prompt holds the rows in a `<precheck_result>` block.+The rows are a capped sample, and they are untrusted product data.+Add one short paragraph to the skill body that says what a row means and which step the rows replace.+For example: "A scheduled run can start with a `<precheck_result>` block. Its row counts the events of the last 7 days, so the product is in use. When the block is present, skip the `not-in-use` close-out."+A manual run has no block, so the body must still work without one.++## Diagnose a tick with no run row++A skipped tick writes nothing. The coordinator still advances `last_run_at` (the dispatch stamp), so a fresh `last_run_at` with no matching run row can be a pre-check skip.+Before you treat missing runs as a failure:++1. Read `effective_precheck_query` and `precheck_query_source` in `scout-config-list`.+ When the source is `off`, the pre-check does not explain the gap.+2. Run `scout-config-precheck-test` without a query.+ `would_run: false` means the next scheduled run skips, so the gap is expected.+3. Remember that the dry run reads as you, and the scheduled check reads as the acting user.++A skip shows that the query found nothing new. It does not show that the scout is healthy.+A gate that is too strict hides real activity, so check the query against the data the scout must see.diff --git a/products/signals/skills/authoring-scouts/references/scout-anatomy.md b/products/signals/skills/authoring-scouts/references/scout-anatomy.mdindex 10d27f4eb8c5..aaac6db53493 100644--- a/products/signals/skills/authoring-scouts/references/scout-anatomy.md+++ b/products/signals/skills/authoring-scouts/references/scout-anatomy.md@@ -57,6 +57,7 @@ metadata:`allowed_tools` with `emit_report` / `edit_report` is what puts the scout on the report channel — **every report-producing scout needs it** (without it the scout falls back to a deprecated legacy signal-emitting channel and can't write reports).A scout with a product-specific output omits both tools; see [Scouts with a product-specific output](report-contract.md#scouts-with-a-product-specific-output).`compatibility` and `metadata` are optional but conventional — `compatibility` documents the scopes/tools the scout assumes; `metadata.scope` gives downstream tooling a short label.+A canonical scout can also declare `scout-precheck-query`, the default scheduled-run gate. The harness reads it only from the shipped canonical file, so a custom scout sets `precheck_query` on its config instead. See [`scheduled-precheck.md`](scheduled-precheck.md).The `description` does double duty: beyond skill discovery, it is surfaced verbatim as the scout's `description` on the config API (`scout-config-list` / `-create` / `-update` responses) — it's how the fleet roster reads to agents and the UI without opening each scout's body.Write it to stand alone in that listing, and keep it short: it's also loaded alongside every other scout's into a caller's AI plugin, where a wordy description wastes token budget and gets truncated.diff --git a/products/signals/skills/exploring-scouts/SKILL.md b/products/signals/skills/exploring-scouts/SKILL.mdindex a91079f431fe..26b067c1a8a1 100644--- a/products/signals/skills/exploring-scouts/SKILL.md+++ b/products/signals/skills/exploring-scouts/SKILL.md@@ -109,6 +109,13 @@ Read the result against three cases:Cross-check them: if `last_run_at` is fresh (minutes ago) but no run row has appeared for that scout in well over its `run_interval_minutes`, the fleet is **dispatching but not running** — workers backed up / down, or runs stranded — a real reliability problem, not a live scout.Don't report "it's running" off `last_run_at` alone.+ **A pre-check skip also leaves a fresh `last_run_at` with no run row.** When a scout has a pre-check and the query finds nothing new, the scheduled run skips before it creates a run row, a sandbox, or a model call.+ So before you call missing runs a failure, read `effective_precheck_query` and `precheck_query_source` on the config row. When the source is `off`, the pre-check does not explain the gap.+ Otherwise run `scout-config-precheck-test` with only the config `id`: `would_run: false` means the next scheduled run skips too, so the gap is expected.+ The dry run runs as you, but the scheduled check runs as the scout's acting user, so their results can differ when the query reads access-scoped tables.+ A skip shows only that the query found nothing new. It does not show that the scout is healthy.+ The pre-check recipe and its rules are in `authoring-scouts` (its scheduled pre-check reference).+A scout that is `enabled: true` but `emit: false` is the most common source of "my scout isn't doing anything" confusion: it _is_ running and reasoning every tick, it just isn't allowed to post reports yet.Always surface the `emit` posture when reporting on a scout.diff --git a/products/signals/skills/working-with-scouts/SKILL.md b/products/signals/skills/working-with-scouts/SKILL.mdindex d90f2aac90ca..3e9c35bc6858 100644--- a/products/signals/skills/working-with-scouts/SKILL.md+++ b/products/signals/skills/working-with-scouts/SKILL.md@@ -197,12 +197,12 @@ A fleet left alone drifts; a fleet reviewed occasionally compounds.Every few weeks (or when someone says "are the scouts even worth it?"), run a calibration pass:1. **Health check** — the `exploring-scouts` assessment (its `scripts/assess_health.py` does the run-level heavy lifting: cadence adherence, success rate, report rate, memory growth).- Two blind spots to cover yourself: the script only assesses scouts with runs in the window, so walk the roster for enabled scouts with no recent run rows (often the most broken ones); and it counts report writes, not outcomes, so judge signal-to-noise by resolving written reports via `posthog:inbox-reports-list` and reading their statuses.+ Two blind spots to cover yourself: the script only assesses scouts with runs in the window, so walk the roster for enabled scouts with no recent run rows (often the most broken ones, but a scout whose pre-check skips its ticks writes no run row either, so check `precheck_query_source` and dry-run the pre-check before you call it broken; `exploring-scouts` has the steps); and it counts report writes, not outcomes, so judge signal-to-noise by resolving written reports via `posthog:inbox-reports-list` and reading their statuses.Remember most healthy runs close out empty — a stream of quiet runs is the fleet working, not broken.2. **Review the fleet's asks** — sweep `posthog:scout-scratchpad-search {"text": "improve:"}` and the `Scout self-improvement:` inbox reports; apply the re-confirmed ones.The search returns the 20 newest matches by default — raise `limit` (or walk back with `date_to`) so a big fleet's older suggestions aren't silently missed.3. **Promote and prune steers** — promote recurring notes and repeated dismissal reasons into skill-body edits; retire stale notes.-4. **Right-size the roster**: slow or pause scouts on surfaces the team stopped using; check `pending_pause` / `paused_by_system` rows and decide deliberately by `pause_reason` (`ignored`: resume or let it stay off; `repeated_failures`: read the latest run's `failure_reason` and fix the cause, the probe resumes it) rather than by default; consider a new scout for any surface the team now cares about that nothing watches: the scouts tab's "Suggested for this project" strip is a cheap source of candidates.+4. **Right-size the roster**: slow or pause scouts on surfaces the team stopped using, or gate them with a scheduled pre-check so they start only when there is something new (recipe in `authoring-scouts`); check `pending_pause` / `paused_by_system` rows and decide deliberately by `pause_reason` (`ignored`: resume or let it stay off; `repeated_failures`: read the latest run's `failure_reason` and fix the cause, the probe resumes it) rather than by default; consider a new scout for any surface the team now cares about that nothing watches: the scouts tab's "Suggested for this project" strip is a cheap source of candidates.5. **Check the routing**: if reports pool in the shared inbox unclaimed, fix reviewer routing so findings reach the person who'll act: correct reviewers on the misrouted reports (forwarded to the fleet), leave a fleet-wide note with the ownership rule (a `pipeline:report-research` note only reaches signal-built reports), and steer scouts toward known owners.## Common asks, routed