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(scouts): expose the priority_explanation requirement in the emit-report schema (#108208)

posthog[bot]89232a0717dd
diff --git a/products/signals/backend/scout_harness/serializers.py b/products/signals/backend/scout_harness/serializers.py
index d0bba0f5f698..c358345b289e 100644
--- a/products/signals/backend/scout_harness/serializers.py
+++ b/products/signals/backend/scout_harness/serializers.py
@@ -1659,6 +1659,18 @@ class EmitReportRequestSerializer(serializers.Serializer):
),
)
+ def validate(self, attrs: dict) -> dict:
+ if attrs.get("priority") and not attrs.get("priority_explanation"):
+ raise serializers.ValidationError(
+ {
+ "priority_explanation": (
+ "Required when `priority` is set. Add a 2-3 sentence justification for the priority, "
+ "or omit `priority`."
+ )
+ }
+ )
+ return attrs
+
class EmitReportResponseSerializer(serializers.Serializer):
report_id = serializers.CharField(
diff --git a/products/signals/backend/test/test_scout_report_api.py b/products/signals/backend/test/test_scout_report_api.py
index 2e7fa6cfa8a7..244e6f8043e0 100644
--- a/products/signals/backend/test/test_scout_report_api.py
+++ b/products/signals/backend/test/test_scout_report_api.py
@@ -2458,15 +2458,21 @@ class TestScoutReportAPI(APIBaseTest):
@parameterized.expand(
[
- ("invalid_priority", {"priority": "P9", "priority_explanation": "x"}),
- ("priority_without_explanation", {"priority": "P1"}),
+ ("invalid_priority", {"priority": "P9", "priority_explanation": "x"}, "priority"),
+ ("priority_without_explanation", {"priority": "P1"}, "priority_explanation"),
+ (
+ "priority_with_null_explanation",
+ {"priority": "P1", "priority_explanation": None},
+ "priority_explanation",
+ ),
]
)
- def test_emit_report_rejects_bad_priority(self, _name: str, overrides: dict) -> None:
+ def test_emit_report_rejects_bad_priority(self, _name: str, overrides: dict, expected_attr: str) -> None:
run = _make_run(self.team)
with _safe_judge(), patch(EMBED_PATH), patch(AUTOSTART_PATH, new=AsyncMock()):
response = self.client.post(self._emit_url(str(run.id)), data=self._payload(**overrides), format="json")
assert response.status_code == status.HTTP_400_BAD_REQUEST, response.json()
+ assert response.json()["attr"] == expected_attr, response.json()
class TestBuildSuggestedReviewers(APIBaseTest):
diff --git a/products/signals/mcp/tools.yaml b/products/signals/mcp/tools.yaml
index d1b8d0baf689..6bcc4d833a08 100644
--- a/products/signals/mcp/tools.yaml
+++ b/products/signals/mcp/tools.yaml
@@ -721,18 +721,22 @@ tools:
authoring a near-duplicate. `suggested_reviewers` is the primary way a report reaches a human (each a
`github_login` and/or a PostHog `user_uuid` resolved server-side); for a concrete, fixable issue, passing
`repository` + `priority` + `suggested_reviewers` also opens a draft PR automatically (autostart,
- custom_agent parity); omit them to just surface the report. Optional `charts` attach queries the inbox
- renders inline — reference one from `summary` as `[label](chart:<chart_id>)` to place it in the body, or
- leave it unreferenced and it renders below. Optional `metrics` adds at most six typed impact measurements:
- one primary metric for the key observation and supporting facts around it. Every metric requires a bounded
- live InsightVizNode/TrendsQuery built only from EventsNode or ActionsNode sources, with no more than 1,000
- estimated longitudinal points; its snapshot is only an optional cached fallback. An affected-users metric
- counts distinct people through one series with `math: dau`. Consumers derive a `BoldNumber` query for each
- metric's whole-window `aggregated_value` and an `ActionsBar` query for its longitudinal buckets; never sum
- affected-user buckets. Optional `links` records how the new report relates to existing reports
- (`duplicate_of`, `depends_on`, `part_of`, `follow_up_of`, `recurrence_of`). Send them here rather than in a
- later `scout-edit-report`, because autostart reads them when the report is created. Opt-in: only available
- to scouts that list `emit_report` in their skill's `allowed_tools`.
+ custom_agent parity); omit them to just surface the report. A `priority` requires a `priority_explanation`.
+ Optional `charts` attach queries the inbox renders inline — reference one from `summary` as
+ `[label](chart:<chart_id>)` to place it in the body, or leave it unreferenced and it renders below. Optional
+ `metrics` adds at most six typed impact measurements: one primary metric for the key observation and
+ supporting facts around it. Every metric requires a bounded live InsightVizNode/TrendsQuery built only from
+ EventsNode or ActionsNode sources, with no more than 1,000 estimated longitudinal points; its snapshot is
+ only an optional cached fallback. An affected-users metric counts distinct people through one series with
+ `math: dau`. Consumers derive a `BoldNumber` query for each metric's whole-window `aggregated_value` and an
+ `ActionsBar` query for its longitudinal buckets; never sum affected-user buckets. Optional `links` records
+ how the new report relates to existing reports (`duplicate_of`, `depends_on`, `part_of`, `follow_up_of`,
+ `recurrence_of`). Send them here rather than in a later `scout-edit-report`, because autostart reads them
+ when the report is created. Opt-in: only available to scouts that list `emit_report` in their skill's
+ `allowed_tools`.
+ required_when_set:
+ priority:
+ - priority_explanation
scout-emit-signal:
operation: signals_scout_emit_signal
enabled: true
@@ -1366,6 +1370,9 @@ tools:
description:
'DEPRECATED: renamed to scout-emit-report. This alias forwards to the same endpoint and will be removed.
Call scout-emit-report directly with the same arguments.'
+ required_when_set:
+ priority:
+ - priority_explanation
signals-scout-emit-signal:
operation: signals_scout_emit_signal
enabled: true
diff --git a/services/mcp/schema/generated-tool-definitions.json b/services/mcp/schema/generated-tool-definitions.json
index f12093b40eaa..83ffaf2dec58 100644
--- a/services/mcp/schema/generated-tool-definitions.json
+++ b/services/mcp/schema/generated-tool-definitions.json
@@ -10757,7 +10757,7 @@
}
},
"scout-emit-report": {
- "description": "The report channel: author a complete `SignalReport` directly instead of emitting a weak signal, when you've already done the research and want 1:1 control over the report rather than letting the pipeline cluster it. The report passes the safety judge, then surfaces at the status your `actionability` call implies (`immediately_actionable` → READY, `requires_human_input` → PENDING_INPUT, `not_actionable` → suppressed); an unsafe report is suppressed regardless. Backing `evidence` is written as bound signals so the report behaves like a pipeline report. Safe to retry: resending an emission returns the report the first call authored (`idempotent_replay` true) rather than a second one, keyed on `idempotency_key` or, without one, on the report's content — so a call that timed out is worth sending again. That is not cross-run dedup: use `inbox-reports-list` to find a report from an earlier run and `scout-edit-report` to update it instead of authoring a near-duplicate. `suggested_reviewers` is the primary way a report reaches a human (each a `github_login` and/or a PostHog `user_uuid` resolved server-side); for a concrete, fixable issue, passing `repository` + `priority` + `suggested_reviewers` also opens a draft PR automatically (autostart, custom_agent parity); omit them to just surface the report. Optional `charts` attach queries the inbox renders inline — reference one from `summary` as `[label](chart:<chart_id>)` to place it in the body, or leave it unreferenced and it renders below. Optional `metrics` adds at most six typed impact measurements: one primary metric for the key observation and supporting facts around it. Every metric requires a bounded live InsightVizNode/TrendsQuery built only from EventsNode or ActionsNode sources, with no more than 1,000 estimated longitudinal points; its snapshot is only an optional cached fallback. An affected-users metric counts distinct people through one series with `math: dau`. Consumers derive a `BoldNumber` query for each metric's whole-window `aggregated_value` and an `ActionsBar` query for its longitudinal buckets; never sum affected-user buckets. Optional `links` records how the new report relates to existing reports (`duplicate_of`, `depends_on`, `part_of`, `follow_up_of`, `recurrence_of`). Send them here rather than in a later `scout-edit-report`, because autostart reads them when the report is created. Opt-in: only available to scouts that list `emit_report` in their skill's `allowed_tools`.",
+ "description": "The report channel: author a complete `SignalReport` directly instead of emitting a weak signal, when you've already done the research and want 1:1 control over the report rather than letting the pipeline cluster it. The report passes the safety judge, then surfaces at the status your `actionability` call implies (`immediately_actionable` → READY, `requires_human_input` → PENDING_INPUT, `not_actionable` → suppressed); an unsafe report is suppressed regardless. Backing `evidence` is written as bound signals so the report behaves like a pipeline report. Safe to retry: resending an emission returns the report the first call authored (`idempotent_replay` true) rather than a second one, keyed on `idempotency_key` or, without one, on the report's content — so a call that timed out is worth sending again. That is not cross-run dedup: use `inbox-reports-list` to find a report from an earlier run and `scout-edit-report` to update it instead of authoring a near-duplicate. `suggested_reviewers` is the primary way a report reaches a human (each a `github_login` and/or a PostHog `user_uuid` resolved server-side); for a concrete, fixable issue, passing `repository` + `priority` + `suggested_reviewers` also opens a draft PR automatically (autostart, custom_agent parity); omit them to just surface the report. A `priority` requires a `priority_explanation`. Optional `charts` attach queries the inbox renders inline — reference one from `summary` as `[label](chart:<chart_id>)` to place it in the body, or leave it unreferenced and it renders below. Optional `metrics` adds at most six typed impact measurements: one primary metric for the key observation and supporting facts around it. Every metric requires a bounded live InsightVizNode/TrendsQuery built only from EventsNode or ActionsNode sources, with no more than 1,000 estimated longitudinal points; its snapshot is only an optional cached fallback. An affected-users metric counts distinct people through one series with `math: dau`. Consumers derive a `BoldNumber` query for each metric's whole-window `aggregated_value` and an `ActionsBar` query for its longitudinal buckets; never sum affected-user buckets. Optional `links` records how the new report relates to existing reports (`duplicate_of`, `depends_on`, `part_of`, `follow_up_of`, `recurrence_of`). Send them here rather than in a later `scout-edit-report`, because autostart reads them when the report is created. Opt-in: only available to scouts that list `emit_report` in their skill's `allowed_tools`.",
"category": "Signals",
"feature": "signals",
"summary": "Author a full report for a run",
diff --git a/services/mcp/schema/tool-definitions-all.json b/services/mcp/schema/tool-definitions-all.json
index 0b7ef0efcc39..15bea546b625 100644
--- a/services/mcp/schema/tool-definitions-all.json
+++ b/services/mcp/schema/tool-definitions-all.json
@@ -11362,7 +11362,7 @@
}
},
"scout-emit-report": {
- "description": "The report channel: author a complete `SignalReport` directly instead of emitting a weak signal, when you've already done the research and want 1:1 control over the report rather than letting the pipeline cluster it. The report passes the safety judge, then surfaces at the status your `actionability` call implies (`immediately_actionable` → READY, `requires_human_input` → PENDING_INPUT, `not_actionable` → suppressed); an unsafe report is suppressed regardless. Backing `evidence` is written as bound signals so the report behaves like a pipeline report. Safe to retry: resending an emission returns the report the first call authored (`idempotent_replay` true) rather than a second one, keyed on `idempotency_key` or, without one, on the report's content — so a call that timed out is worth sending again. That is not cross-run dedup: use `inbox-reports-list` to find a report from an earlier run and `scout-edit-report` to update it instead of authoring a near-duplicate. `suggested_reviewers` is the primary way a report reaches a human (each a `github_login` and/or a PostHog `user_uuid` resolved server-side); for a concrete, fixable issue, passing `repository` + `priority` + `suggested_reviewers` also opens a draft PR automatically (autostart, custom_agent parity); omit them to just surface the report. Optional `charts` attach queries the inbox renders inline — reference one from `summary` as `[label](chart:<chart_id>)` to place it in the body, or leave it unreferenced and it renders below. Optional `metrics` adds at most six typed impact measurements: one primary metric for the key observation and supporting facts around it. Every metric requires a bounded live InsightVizNode/TrendsQuery built only from EventsNode or ActionsNode sources, with no more than 1,000 estimated longitudinal points; its snapshot is only an optional cached fallback. An affected-users metric counts distinct people through one series with `math: dau`. Consumers derive a `BoldNumber` query for each metric's whole-window `aggregated_value` and an `ActionsBar` query for its longitudinal buckets; never sum affected-user buckets. Optional `links` records how the new report relates to existing reports (`duplicate_of`, `depends_on`, `part_of`, `follow_up_of`, `recurrence_of`). Send them here rather than in a later `scout-edit-report`, because autostart reads them when the report is created. Opt-in: only available to scouts that list `emit_report` in their skill's `allowed_tools`.",
+ "description": "The report channel: author a complete `SignalReport` directly instead of emitting a weak signal, when you've already done the research and want 1:1 control over the report rather than letting the pipeline cluster it. The report passes the safety judge, then surfaces at the status your `actionability` call implies (`immediately_actionable` → READY, `requires_human_input` → PENDING_INPUT, `not_actionable` → suppressed); an unsafe report is suppressed regardless. Backing `evidence` is written as bound signals so the report behaves like a pipeline report. Safe to retry: resending an emission returns the report the first call authored (`idempotent_replay` true) rather than a second one, keyed on `idempotency_key` or, without one, on the report's content — so a call that timed out is worth sending again. That is not cross-run dedup: use `inbox-reports-list` to find a report from an earlier run and `scout-edit-report` to update it instead of authoring a near-duplicate. `suggested_reviewers` is the primary way a report reaches a human (each a `github_login` and/or a PostHog `user_uuid` resolved server-side); for a concrete, fixable issue, passing `repository` + `priority` + `suggested_reviewers` also opens a draft PR automatically (autostart, custom_agent parity); omit them to just surface the report. A `priority` requires a `priority_explanation`. Optional `charts` attach queries the inbox renders inline — reference one from `summary` as `[label](chart:<chart_id>)` to place it in the body, or leave it unreferenced and it renders below. Optional `metrics` adds at most six typed impact measurements: one primary metric for the key observation and supporting facts around it. Every metric requires a bounded live InsightVizNode/TrendsQuery built only from EventsNode or ActionsNode sources, with no more than 1,000 estimated longitudinal points; its snapshot is only an optional cached fallback. An affected-users metric counts distinct people through one series with `math: dau`. Consumers derive a `BoldNumber` query for each metric's whole-window `aggregated_value` and an `ActionsBar` query for its longitudinal buckets; never sum affected-user buckets. Optional `links` records how the new report relates to existing reports (`duplicate_of`, `depends_on`, `part_of`, `follow_up_of`, `recurrence_of`). Send them here rather than in a later `scout-edit-report`, because autostart reads them when the report is created. Opt-in: only available to scouts that list `emit_report` in their skill's `allowed_tools`.",
"category": "Signals",
"feature": "signals",
"summary": "Author a full report for a run",
diff --git a/services/mcp/scripts/generate-tools.ts b/services/mcp/scripts/generate-tools.ts
index 0455780f0041..dc7ef8aa51c6 100644
--- a/services/mcp/scripts/generate-tools.ts
+++ b/services/mcp/scripts/generate-tools.ts
@@ -967,6 +967,18 @@ function buildResponseFilter(config: ToolConfig): {
}
}
+/**
+ * When `required_when_set` is set, attach it as the `x-required-when-set` schema annotation.
+ * zod 4 copies `.meta()` keys into `toJSONSchema` output, so the advertised schema and the
+ * compact exec summary both carry it. Returns the expression unchanged otherwise.
+ */
+function withRequiredWhenSet(schemaExpr: string, config: ToolConfig): string {
+ if (!config.required_when_set || Object.keys(config.required_when_set).length === 0) {
+ return schemaExpr
+ }
+ return `(${schemaExpr}).meta({ 'x-required-when-set': ${JSON.stringify(config.required_when_set)} })`
+}
+
/**
* When `response.selectable` is set, emit a `.extend({ fields: ... })` clause adding an optional
* `fields` request param constrained (via `z.enum`) to the `include` allowlist. Returns '' when the
@@ -1120,6 +1132,7 @@ function generateToolCode(
composition.toolInputsImports.push(fn)
}
}
+ schemaExpr = withRequiredWhenSet(schemaExpr, config)
// `param_overrides.<param>.aliases` — normalize alias keys to the canonical
// param before validation. Outermost wrapper so the rename happens before any
@@ -1629,6 +1642,7 @@ function generateCustomSchemaToolCode(
toolInputsImports.push(fn)
}
}
+ baseSchemaExpr = withRequiredWhenSet(baseSchemaExpr, config)
const hasAgentNote = !!config.agent_note
const needsWithAgentNote = hasAgentNote && !!responseType
diff --git a/services/mcp/scripts/yaml-config-schema.ts b/services/mcp/scripts/yaml-config-schema.ts
index db3cb63c99e4..bc1672c6c98b 100644
--- a/services/mcp/scripts/yaml-config-schema.ts
+++ b/services/mcp/scripts/yaml-config-schema.ts
@@ -142,6 +142,15 @@ export const ToolConfigSchema = z
* two optional fields).
*/
validators: z.array(z.string()).optional(),
+ /**
+ * Conditional requirements: when the key param has a non-null value, each listed param
+ * needs a non-null value too. Codegen adds them to the advertised schema as the
+ * `x-required-when-set` annotation, and the compact `info` / `schema` summary lists them
+ * next to `required`, so a caller sees them even when the full schema overflows the
+ * budget. The annotation does not validate anything, so the backend enforces the rule.
+ * Standard `dependentRequired` does not fit: it fires on a present key, even a null one.
+ */
+ required_when_set: z.record(z.string(), z.array(z.string())).optional(),
/** References a key in ui_apps. */
ui_app: z.string().optional(),
/**
diff --git a/services/mcp/src/tools/generated/signals.ts b/services/mcp/src/tools/generated/signals.ts
index e01f2a83ab7e..f4221eb7e3a7 100644
--- a/services/mcp/src/tools/generated/signals.ts
+++ b/services/mcp/src/tools/generated/signals.ts
@@ -1063,7 +1063,9 @@ const scoutEditReport = (): ToolBase<ReturnType<typeof ScoutEditReportSchema>, S
const ScoutEmitReportSchema = () => {
const SignalsScoutEmitReportBody = orvalSchemas.SignalsScoutEmitReportBody()
const SignalsScoutEmitReportParams = orvalSchemas.SignalsScoutEmitReportParams()
- return SignalsScoutEmitReportParams.omit({ project_id: true }).extend(SignalsScoutEmitReportBody.shape)
+ return SignalsScoutEmitReportParams.omit({ project_id: true })
+ .extend(SignalsScoutEmitReportBody.shape)
+ .meta({ 'x-required-when-set': { priority: ['priority_explanation'] } })
}
const scoutEmitReport = (): ToolBase<ReturnType<typeof ScoutEmitReportSchema>, Schemas.EmitReportResponse> => ({
@@ -2006,7 +2008,9 @@ const signalsScoutEditReport = (): ToolBase<
const SignalsScoutEmitReportSchema = () => {
const SignalsScoutEmitReportBody = orvalSchemas.SignalsScoutEmitReportBody()
const SignalsScoutEmitReportParams = orvalSchemas.SignalsScoutEmitReportParams()
- return SignalsScoutEmitReportParams.omit({ project_id: true }).extend(SignalsScoutEmitReportBody.shape)
+ return SignalsScoutEmitReportParams.omit({ project_id: true })
+ .extend(SignalsScoutEmitReportBody.shape)
+ .meta({ 'x-required-when-set': { priority: ['priority_explanation'] } })
}
const signalsScoutEmitReport = (): ToolBase<
diff --git a/services/mcp/src/tools/schema-utils.ts b/services/mcp/src/tools/schema-utils.ts
index f4ae506749d0..81afa6996721 100644
--- a/services/mcp/src/tools/schema-utils.ts
+++ b/services/mcp/src/tools/schema-utils.ts
@@ -42,6 +42,7 @@ interface NodeSummary extends ScalarConstraints {
type: string
title?: string
required?: string[]
+ requiredWhenSet?: Record<string, string[]>
properties: Record<string, SummarizedProperty>
items?: NodeSummary
variants?: NodeSummary[]
@@ -344,6 +345,10 @@ function summarizeObject(schema: JSONSchema, toolName: string, fieldPath?: strin
const summary: NodeSummary = {
type: (schema.type as string) || 'object',
...(requiredFields.length > 0 ? { required: requiredFields } : {}),
+ // Before `properties`, so a caller whose output gets cut off still sees the conditional rule.
+ ...(schema['x-required-when-set']
+ ? { requiredWhenSet: schema['x-required-when-set'] as Record<string, string[]> }
+ : {}),
properties: result,
}
if (typeof schema.title === 'string') {
diff --git a/services/mcp/tests/unit/signals-emit-report-schema.test.ts b/services/mcp/tests/unit/signals-emit-report-schema.test.ts
new file mode 100644
index 000000000000..85875609111c
--- /dev/null
+++ b/services/mcp/tests/unit/signals-emit-report-schema.test.ts
@@ -0,0 +1,23 @@
+import { describe, expect, it } from 'vitest'
+import { z } from 'zod'
+
+import { GENERATED_TOOLS } from '@/tools/generated/signals'
+import { summarizeSchema } from '@/tools/schema-utils'
+
+// The emit-report schema overflows the exec output budget, so callers read the compact summary.
+// A long summary gets cut off, so the conditional rule must sit before the per-field properties.
+describe('scout-emit-report schema summary', () => {
+ it.each(['scout-emit-report', 'signals-scout-emit-report'])(
+ 'lists priority_explanation as required with priority before the properties in %s',
+ (toolName) => {
+ const tool = GENERATED_TOOLS[toolName]!()
+ const jsonSchema = z.toJSONSchema(tool.schema, { io: 'input' }) as Record<string, unknown>
+
+ const summary = summarizeSchema(jsonSchema, toolName)
+
+ expect(summary.requiredWhenSet).toEqual({ priority: ['priority_explanation'] })
+ const keys = Object.keys(summary)
+ expect(keys.indexOf('requiredWhenSet')).toBeLessThan(keys.indexOf('properties'))
+ }
+ )
+})