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.

feat(signals): surface scout config origin (canonical vs custom) (#63547)

Andrew Maguiree45b1fe4003b
diff --git a/posthog/settings/web.py b/posthog/settings/web.py
index 20f9b1ed30a2..7b11fc6e6004 100644
--- a/posthog/settings/web.py
+++ b/posthog/settings/web.py
@@ -522,6 +522,7 @@ SPECTACULAR_SETTINGS = {
"workflow_variable",
],
"AssigneeTypeEnum": ["user", "role"],
+ "ScoutOriginEnum": ["canonical", "custom"],
"FileFormatEnum": ["Parquet", "JSONLines"],
"ErrorTrackingIssueOrderByEnum": ["last_seen", "first_seen", "occurrences", "users", "sessions"],
"ErrorTrackingIssueStatusEnum": ["archived", "active", "resolved", "pending_release", "suppressed", "all"],
diff --git a/products/signals/backend/scout_harness/lazy_seed.py b/products/signals/backend/scout_harness/lazy_seed.py
index 00b764d26768..7762f82126fd 100644
--- a/products/signals/backend/scout_harness/lazy_seed.py
+++ b/products/signals/backend/scout_harness/lazy_seed.py
@@ -5,6 +5,7 @@ import json
import hashlib
import logging
from dataclasses import dataclass
+from functools import lru_cache
from pathlib import Path
from django.db import IntegrityError, transaction
@@ -46,6 +47,13 @@ _MAX_SKILL_FILE_COUNT = 50
# canonical path fails with a clear error instead of a Postgres `value too long` DataError.
_MAX_SKILL_FILE_PATH_LENGTH = 500
+# Stamped on `LLMSkill.metadata.seeded_by` for every harness-managed scout row. Its presence
+# is the single source of truth for "the harness owns this row": it gates which rows
+# `sync_canonical_skills` may update/prune, AND it's what distinguishes a canonical scout
+# (shipped in products/signals/skills, seeded here) from a team's hand-authored scout when
+# classifying a config's origin downstream. Keep reads of it pointed at this constant.
+HARNESS_SEEDED_BY = "signals_scout_harness"
+
@dataclass(frozen=True)
class CanonicalSkillFile:
@@ -245,6 +253,24 @@ def discover_canonical_skills(skills_dir: Path | None = None) -> tuple[Canonical
return tuple(discovered)
+@lru_cache(maxsize=1)
+def canonical_skill_names() -> frozenset[str]:
+ """Frontmatter names of the canonical `signals-scout-*` skills shipped on disk.
+
+ The single derived source of truth for "is this a scout the harness ships". Unlike a
+ hardcoded list it tracks the on-disk fleet automatically, so it never goes stale when a
+ canonical scout is added or removed. Cached for the process — the shipped fleet only
+ changes on deploy. A malformed canonical skill degrades to an empty set (everything reads
+ `custom`) rather than 500-ing read endpoints; the parse error still fails loud on the
+ harness's own sync path. See `views._scout_origin` for the consumer.
+ """
+ try:
+ return frozenset(skill.name for skill in discover_canonical_skills())
+ except CanonicalSkillParseError:
+ logger.warning("canonical_skill_names: malformed canonical skill on disk; treating fleet as empty")
+ return frozenset()
+
+
def _compute_canonical_hash(canonical: CanonicalSkill) -> str:
"""Stable content fingerprint for a canonical skill on disk.
@@ -294,7 +320,7 @@ def _create_skill_from_canonical(team: Team, canonical: CanonicalSkill, canonica
body=canonical.body,
allowed_tools=list(canonical.allowed_tools),
metadata={
- "seeded_by": "signals_scout_harness",
+ "seeded_by": HARNESS_SEEDED_BY,
"source": "products/signals/skills",
"canonical_hash": canonical_hash,
},
@@ -338,7 +364,7 @@ def _update_skill_from_canonical(
locked.save(update_fields=["is_latest", "updated_at"])
new_metadata = dict(locked.metadata or {})
- new_metadata["seeded_by"] = "signals_scout_harness"
+ new_metadata["seeded_by"] = HARNESS_SEEDED_BY
new_metadata["source"] = "products/signals/skills"
new_metadata["canonical_hash"] = canonical_hash
@@ -424,7 +450,7 @@ def sync_canonical_skills(team: Team, *, prune: bool = False) -> SyncResult:
# Only manage rows we seeded. A team can hand-author a signals-scout-* skill that
# shares a canonical name — no seeded_by tag — and we must never touch it.
- if (live.metadata or {}).get("seeded_by") != "signals_scout_harness":
+ if (live.metadata or {}).get("seeded_by") != HARNESS_SEEDED_BY:
diverged.append(canonical.name)
continue
@@ -479,7 +505,7 @@ def sync_canonical_skills(team: Team, *, prune: bool = False) -> SyncResult:
deleted=False,
is_latest=True,
name__startswith=SIGNALS_SCOUT_SKILL_PREFIX,
- metadata__seeded_by="signals_scout_harness",
+ metadata__seeded_by=HARNESS_SEEDED_BY,
).exclude(name__in=canonical_names)
for row in orphan_rows:
stored_hash = (row.metadata or {}).get("canonical_hash")
@@ -489,7 +515,7 @@ def sync_canonical_skills(team: Team, *, prune: bool = False) -> SyncResult:
# Re-scope the soft-delete to seeded rows too, so a team-authored row sharing the
# name is never caught by the bulk update.
LLMSkill.objects.filter(
- team=team, name=row.name, deleted=False, metadata__seeded_by="signals_scout_harness"
+ team=team, name=row.name, deleted=False, metadata__seeded_by=HARNESS_SEEDED_BY
).update(deleted=True, is_latest=False)
pruned.append(row.name)
diff --git a/products/signals/backend/scout_harness/serializers.py b/products/signals/backend/scout_harness/serializers.py
index 96ebc9558a28..f5e3ee20ca56 100644
--- a/products/signals/backend/scout_harness/serializers.py
+++ b/products/signals/backend/scout_harness/serializers.py
@@ -976,6 +976,14 @@ class SignalScoutConfigSerializer(serializers.ModelSerializer):
"on the team or carries no description."
),
)
+ scout_origin = serializers.SerializerMethodField(
+ help_text=(
+ "Where this scout came from: `canonical` for a scout PostHog ships and maintains "
+ "(seeded from `products/signals/skills/`), or `custom` for one a team hand-authored "
+ "on this project. Use it to badge built-in vs custom scouts instead of a hardcoded "
+ "name list. Defaults to `custom` if the skill is not currently present on the team."
+ ),
+ )
enabled = serializers.BooleanField(
required=False,
help_text="Whether this scout runs on its schedule. Disabled scouts are skipped by the coordinator.",
@@ -998,10 +1006,17 @@ class SignalScoutConfigSerializer(serializers.ModelSerializer):
@extend_schema_field(OpenApiTypes.STR)
def get_description(self, obj: SignalScoutConfig) -> str:
- # Resolved by the view into `skill_descriptions` (skill_name -> description) so the
+ # Resolved by the view into `skill_info` (skill_name -> _ScoutSkillInfo) so the
# list endpoint stays a single LLMSkill query rather than one lookup per config row.
- descriptions = self.context.get("skill_descriptions") or {}
- return descriptions.get(obj.skill_name, "")
+ info = (self.context.get("skill_info") or {}).get(obj.skill_name)
+ return info.description if info else ""
+
+ @extend_schema_field(serializers.ChoiceField(choices=["canonical", "custom"]))
+ def get_scout_origin(self, obj: SignalScoutConfig) -> str:
+ # Same single-query `skill_info` map as `get_description`. Falls back to `custom` when
+ # the skill row is absent — a config with no skill row isn't a canonical scout.
+ info = (self.context.get("skill_info") or {}).get(obj.skill_name)
+ return info.origin if info else "custom"
class Meta:
model = SignalScoutConfig
@@ -1009,6 +1024,7 @@ class SignalScoutConfigSerializer(serializers.ModelSerializer):
"id",
"skill_name",
"description",
+ "scout_origin",
"enabled",
"emit",
"run_interval_minutes",
diff --git a/products/signals/backend/scout_harness/views.py b/products/signals/backend/scout_harness/views.py
index ba147a28e2f6..cde3c156f9f3 100644
--- a/products/signals/backend/scout_harness/views.py
+++ b/products/signals/backend/scout_harness/views.py
@@ -20,6 +20,7 @@ token is already pinned to the team.
from __future__ import annotations
import uuid
+from dataclasses import dataclass
from drf_spectacular.types import OpenApiTypes
from drf_spectacular.utils import OpenApiParameter, OpenApiResponse, extend_schema
@@ -42,6 +43,7 @@ from posthog.permissions import APIScopePermission
from products.signals.backend.models import SignalProjectProfile, SignalScoutConfig, SignalScoutEmission, SignalScoutRun
from products.signals.backend.scout_harness.config_registry import enabled_scout_count
+from products.signals.backend.scout_harness.lazy_seed import HARNESS_SEEDED_BY, canonical_skill_names
from products.signals.backend.scout_harness.limits import MAX_ENABLED_SCOUTS_PER_TEAM
from products.signals.backend.scout_harness.serializers import (
EmitFindingRequestSerializer,
@@ -592,20 +594,52 @@ def _reject_if_enabled_cap_reached(team_id: int, skill_name: str) -> None:
)
-def _skill_descriptions_for(team_id: int, skill_names: list[str]) -> dict[str, str]:
- """Map each scout `skill_name` to the latest `LLMSkill.description` on the team.
+@dataclass(frozen=True)
+class _ScoutSkillInfo:
+ """Per-skill metadata the config serializer needs but doesn't store on the config row.
- One query for the whole config list — feeds the serializer's `description` field so
- callers get a quick steer on each scout without loading the full skill body. Skills the
- team no longer has simply drop out of the map (serializer falls back to "").
+ Both fields come from the team's latest `LLMSkill` row for the scout, resolved by the
+ view in one query so the list endpoint stays a single lookup rather than one per config.
+ """
+
+ description: str
+ origin: str # "canonical" | "custom" — see `_scout_origin`.
+
+
+def _scout_origin(skill_name: str, metadata: dict | None) -> str:
+ """Classify a scout by who owns its skill row.
+
+ A scout is `canonical` when the harness seeded its skill row (tagged
+ `metadata.seeded_by=HARNESS_SEEDED_BY`) **and** its name is one the harness actually ships
+ on disk (`products/signals/skills/`); otherwise it's a team's hand-authored `custom` scout.
+ Both halves matter: `duplicate_skill()` copies a source row's metadata verbatim — including
+ `seeded_by` — so a team fork of a bundled scout inherits the seed tag, but a fork can never
+ take a canonical name (the canonical row already owns it), so the name guard reclassifies it
+ as `custom`. The name set is derived from disk, so it never goes stale the way a hardcoded
+ list would.
+ """
+ is_harness_seeded = (metadata or {}).get("seeded_by") == HARNESS_SEEDED_BY
+ return "canonical" if is_harness_seeded and skill_name in canonical_skill_names() else "custom"
+
+
+def _skill_info_for(team_id: int, skill_names: list[str]) -> dict[str, _ScoutSkillInfo]:
+ """Map each scout `skill_name` to its latest `LLMSkill` description + origin on the team.
+
+ One query for the whole config list — feeds the serializer's `description` and `origin`
+ fields so callers get a quick steer on each scout (and whether it's a canonical or
+ hand-authored scout) without loading the full skill body. Skills the team no longer has
+ simply drop out of the map (serializer falls back to "" / "custom").
"""
names = list(set(skill_names))
if not names:
return {}
rows = LLMSkill.objects.filter(team_id=team_id, name__in=names, is_latest=True, deleted=False).values_list(
- "name", "description"
+ "name", "description", "metadata"
)
- return dict(rows)
+ return {
+ name: _ScoutSkillInfo(description=description or "", origin=_scout_origin(name, metadata))
+ for name, description, metadata in rows
+ }
class SignalScoutConfigViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSet):
@@ -647,8 +681,8 @@ class SignalScoutConfigViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSet):
def list(self, request: Request, *args, **kwargs) -> Response:
team_id = _canonical_team_id(self)
configs = list(SignalScoutConfig.objects.unscoped().filter(team_id=team_id).order_by("skill_name"))
- descriptions = _skill_descriptions_for(team_id, [c.skill_name for c in configs])
- serializer = SignalScoutConfigSerializer(configs, many=True, context={"skill_descriptions": descriptions})
+ skill_info = _skill_info_for(team_id, [c.skill_name for c in configs])
+ serializer = SignalScoutConfigSerializer(configs, many=True, context={"skill_info": skill_info})
return Response(serializer.data)
@extend_schema(
@@ -718,9 +752,9 @@ class SignalScoutConfigViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSet):
if not config.enabled and update.validated_data.get("enabled"):
save_kwargs["enabled_by"] = request.user
config = update.save(**save_kwargs)
- descriptions = _skill_descriptions_for(team_id, [config.skill_name])
+ skill_info = _skill_info_for(team_id, [config.skill_name])
return Response(
- SignalScoutConfigSerializer(config, context={"skill_descriptions": descriptions}).data,
+ SignalScoutConfigSerializer(config, context={"skill_info": skill_info}).data,
status=status.HTTP_201_CREATED if created else status.HTTP_200_OK,
)
@@ -757,5 +791,5 @@ class SignalScoutConfigViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSet):
if enabling:
save_kwargs["enabled_by"] = request.user
instance = serializer.save(**save_kwargs)
- descriptions = _skill_descriptions_for(team_id, [instance.skill_name])
- return Response(SignalScoutConfigSerializer(instance, context={"skill_descriptions": descriptions}).data)
+ skill_info = _skill_info_for(team_id, [instance.skill_name])
+ return Response(SignalScoutConfigSerializer(instance, context={"skill_info": skill_info}).data)
diff --git a/products/signals/backend/test/test_scout_harness_api.py b/products/signals/backend/test/test_scout_harness_api.py
index 277ab76b0b0e..442f10bf348c 100644
--- a/products/signals/backend/test/test_scout_harness_api.py
+++ b/products/signals/backend/test/test_scout_harness_api.py
@@ -22,6 +22,7 @@ from products.signals.backend.models import (
SignalScoutRun,
SignalScratchpad,
)
+from products.signals.backend.scout_harness.lazy_seed import HARNESS_SEEDED_BY
from products.signals.backend.scout_harness.tools.profile import compute_project_profile
from products.skills.backend.models.skills import LLMSkill
from products.tasks.backend.models import Task, TaskRun
@@ -676,6 +677,45 @@ class TestScoutHarnessConfigAPI(APIBaseTest):
assert response.status_code == status.HTTP_200_OK
assert response.json()["description"] == "Foo scout."
+ # The partial_update path resolves skill_info independently of list — assert origin too.
+ assert response.json()["scout_origin"] == "custom"
+
+ @parameterized.expand(
+ [
+ # (label, skill_name, metadata, expected). `signals-scout-general` is a real on-disk
+ # canonical scout; `signals-scout-my-fork` is a name the harness never ships.
+ (
+ "harness_seeded_canonical_name",
+ "signals-scout-general",
+ {"seeded_by": HARNESS_SEEDED_BY, "source": "products/signals/skills"},
+ "canonical",
+ ),
+ ("hand_authored_no_metadata", "signals-scout-general", {}, "custom"),
+ ("hand_authored_other_seed", "signals-scout-general", {"seeded_by": "some_other_thing"}, "custom"),
+ # A fork via duplicate_skill() inherits the source row's seeded_by tag, but a fork can
+ # never take a canonical name — so the name guard reclassifies it as custom.
+ ("seeded_tag_but_non_canonical_name", "signals-scout-my-fork", {"seeded_by": HARNESS_SEEDED_BY}, "custom"),
+ ]
+ )
+ def test_list_classifies_origin_from_skill_metadata(
+ self, _name: str, skill_name: str, metadata: dict, expected_origin: str
+ ) -> None:
+ SignalScoutConfig.objects.create(team=self.team, skill_name=skill_name)
+ LLMSkill.objects.create(team=self.team, name=skill_name, description="d", body="...", metadata=metadata)
+
+ response = self.client.get(self._list_url())
+
+ assert response.status_code == status.HTTP_200_OK
+ assert response.json()[0]["scout_origin"] == expected_origin
+
+ def test_list_origin_defaults_to_custom_when_skill_absent(self) -> None:
+ # A config with no live skill row isn't a canonical scout.
+ SignalScoutConfig.objects.create(team=self.team, skill_name="signals-scout-errors")
+
+ response = self.client.get(self._list_url())
+
+ assert response.status_code == status.HTTP_200_OK
+ assert response.json()[0]["scout_origin"] == "custom"
def test_partial_update_changes_schedule_emit_and_records_enabled_by(self) -> None:
config = SignalScoutConfig.objects.create(team=self.team, skill_name="signals-scout-foo", enabled=False)
diff --git a/products/signals/frontend/generated/api.schemas.ts b/products/signals/frontend/generated/api.schemas.ts
index 94dc210fb622..9ffd0a8d4e75 100644
--- a/products/signals/frontend/generated/api.schemas.ts
+++ b/products/signals/frontend/generated/api.schemas.ts
@@ -141,6 +141,13 @@ export interface SignalReportStateRequestApi {
snooze_for?: number
}
+export type ScoutOriginEnumApi = (typeof ScoutOriginEnumApi)[keyof typeof ScoutOriginEnumApi]
+
+export const ScoutOriginEnumApi = {
+ Canonical: 'canonical',
+ Custom: 'custom',
+} as const
+
/**
* Per-(team, skill) scout config: schedule, enablement, and emit posture.
*
@@ -153,6 +160,8 @@ export interface SignalScoutConfigApi {
readonly skill_name: string
/** Human-readable summary of what this scout investigates, sourced from the scout skill's `description` metadata. Use it for a quick steer on the scout's focus without loading the full skill body. Empty if the skill is not currently present on the team or carries no description. */
readonly description: string
+ /** Where this scout came from: `canonical` for a scout PostHog ships and maintains (seeded from `products/signals/skills/`), or `custom` for one a team hand-authored on this project. Use it to badge built-in vs custom scouts instead of a hardcoded name list. Defaults to `custom` if the skill is not currently present on the team. */
+ readonly scout_origin: ScoutOriginEnumApi
/** Whether this scout runs on its schedule. Disabled scouts are skipped by the coordinator. */
enabled?: boolean
/** Whether the scout writes findings to the inbox. False = dry-run: it runs and logs but emits nothing. */
@@ -207,6 +216,8 @@ export interface PatchedSignalScoutConfigApi {
readonly skill_name?: string
/** Human-readable summary of what this scout investigates, sourced from the scout skill's `description` metadata. Use it for a quick steer on the scout's focus without loading the full skill body. Empty if the skill is not currently present on the team or carries no description. */
readonly description?: string
+ /** Where this scout came from: `canonical` for a scout PostHog ships and maintains (seeded from `products/signals/skills/`), or `custom` for one a team hand-authored on this project. Use it to badge built-in vs custom scouts instead of a hardcoded name list. Defaults to `custom` if the skill is not currently present on the team. */
+ readonly scout_origin?: ScoutOriginEnumApi
/** Whether this scout runs on its schedule. Disabled scouts are skipped by the coordinator. */
enabled?: boolean
/** Whether the scout writes findings to the inbox. False = dry-run: it runs and logs but emits nothing. */
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index 6c7d00847620..49618a732d76 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -33722,6 +33722,14 @@ export namespace Schemas {
custom_tags?: PatchedSessionSummariesConfigCustomTags;
}
+ export type ScoutOriginEnum = typeof ScoutOriginEnum[keyof typeof ScoutOriginEnum];
+
+
+ export const ScoutOriginEnum = {
+ Canonical: 'canonical',
+ Custom: 'custom',
+ } as const;
+
/**
* Per-(team, skill) scout config: schedule, enablement, and emit posture.
*
@@ -33734,6 +33742,8 @@ export namespace Schemas {
readonly skill_name?: string;
/** Human-readable summary of what this scout investigates, sourced from the scout skill's `description` metadata. Use it for a quick steer on the scout's focus without loading the full skill body. Empty if the skill is not currently present on the team or carries no description. */
readonly description?: string;
+ /** Where this scout came from: `canonical` for a scout PostHog ships and maintains (seeded from `products/signals/skills/`), or `custom` for one a team hand-authored on this project. Use it to badge built-in vs custom scouts instead of a hardcoded name list. Defaults to `custom` if the skill is not currently present on the team. */
+ readonly scout_origin?: ScoutOriginEnum;
/** Whether this scout runs on its schedule. Disabled scouts are skipped by the coordinator. */
enabled?: boolean;
/** Whether the scout writes findings to the inbox. False = dry-run: it runs and logs but emits nothing. */
@@ -40348,6 +40358,8 @@ export namespace Schemas {
readonly skill_name: string;
/** Human-readable summary of what this scout investigates, sourced from the scout skill's `description` metadata. Use it for a quick steer on the scout's focus without loading the full skill body. Empty if the skill is not currently present on the team or carries no description. */
readonly description: string;
+ /** Where this scout came from: `canonical` for a scout PostHog ships and maintains (seeded from `products/signals/skills/`), or `custom` for one a team hand-authored on this project. Use it to badge built-in vs custom scouts instead of a hardcoded name list. Defaults to `custom` if the skill is not currently present on the team. */
+ readonly scout_origin: ScoutOriginEnum;
/** Whether this scout runs on its schedule. Disabled scouts are skipped by the coordinator. */
enabled?: boolean;
/** Whether the scout writes findings to the inbox. False = dry-run: it runs and logs but emits nothing. */