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): add per-scout holdback denylist for the scout fleet (#65255)

Andrew Maguire0bbbdb218e16
diff --git a/products/signals/ARCHITECTURE.md b/products/signals/ARCHITECTURE.md
index 0ca5859f2af2..dc921240dcc8 100644
--- a/products/signals/ARCHITECTURE.md
+++ b/products/signals/ARCHITECTURE.md
@@ -304,6 +304,8 @@ Defined in `backend/temporal/agentic/scout_coordinator.py`.
The coordinator's lifetime is seconds regardless of fan-out width; throttling happens at the Temporal task queue + worker concurrency layer. Pausing a scout is `enabled=False` on its config; slowing it is a larger `run_interval_minutes` — both tunable via the `signals-scout-config-update` MCP tool.
+**Per-scout holdback (`withheld_skills`).** The same flag payload carries a hard denylist for keeping an unreleased scout off the fleet while dogfooding it on a single project. A `withheld_skills` list (a `default_team_config` fleet-wide default, overridable per team via `team_configs[<id>].withheld_skills` with replace-not-merge semantics — set `[]` to release the full fleet to one team) names scouts that, for a held-back team, are never seeded into its `LLMSkill` rows (`sync_canonical_skills` skips them), never get a `SignalScoutConfig` (`register_missing_configs` drops them from its return), and are never dispatched. Resolved by `_resolve_withheld_skills`, most-specific-layer-first like the run caps. Unlike the soft `enabled_skills` seed allowlist (a default a user can still toggle on), this is a hard gate at the seed + dispatch layer — e.g. `default_team_config.withheld_skills = ["signals-scout-error-tracking"]` with `team_configs["2"].withheld_skills = []` dogfoods error tracking on project 2 only.
+
### `RunSignalsScoutWorkflow`
Child workflow per planned run. Defined in `backend/temporal/agentic/scout_scheduler.py`.
diff --git a/products/signals/backend/management/commands/sync_signals_scout_skills.py b/products/signals/backend/management/commands/sync_signals_scout_skills.py
index e97b790aec35..8b9fea4d0ea9 100644
--- a/products/signals/backend/management/commands/sync_signals_scout_skills.py
+++ b/products/signals/backend/management/commands/sync_signals_scout_skills.py
@@ -22,6 +22,7 @@ from posthog.models.team.team import Team
from products.signals.backend.models import SignalScoutConfig
from products.signals.backend.scout_harness.lazy_seed import sync_canonical_skills
+from products.signals.backend.scout_harness.team_limits import withheld_skills_for_team
class Command(BaseCommand):
@@ -80,7 +81,10 @@ class Command(BaseCommand):
}
for team in teams:
# Explicit reconciliation path → prune orphaned rows (canonical removed from disk).
- result = sync_canonical_skills(team, prune=True)
+ # Honor the per-scout holdback denylist so this impatient fan-out can't seed a
+ # withheld scout's LLMSkill rows onto a held-back team (the coordinator gates the
+ # scheduled path the same way).
+ result = sync_canonical_skills(team, prune=True, withheld_skill_names=withheld_skills_for_team(team.id))
totals["created"] += len(result.created_skill_names)
totals["updated"] += len(result.updated_skill_names)
totals["diverged"] += len(result.diverged_skill_names)
@@ -131,7 +135,8 @@ class Command(BaseCommand):
with transaction.atomic():
for team in teams:
# Preview prune too (rolled back below), so the dry-run shows what would be reaped.
- result = sync_canonical_skills(team, prune=True)
+ # Same holdback resolution as the real run so the preview matches what would seed.
+ result = sync_canonical_skills(team, prune=True, withheld_skill_names=withheld_skills_for_team(team.id))
self._print_team_result(team, result, prefix="[dry-run] ")
transaction.set_rollback(True)
diff --git a/products/signals/backend/scout_harness/config_registry.py b/products/signals/backend/scout_harness/config_registry.py
index 6a100542d6f4..f48bea530694 100644
--- a/products/signals/backend/scout_harness/config_registry.py
+++ b/products/signals/backend/scout_harness/config_registry.py
@@ -98,7 +98,11 @@ def _resolve_seed_posture(seed_config_layers: list[dict] | None) -> tuple[set[st
return enabled_skills, enabled_interval
-def register_missing_configs(team_id: int, seed_config_layers: list[dict] | None = None) -> set[str]:
+def register_missing_configs(
+ team_id: int,
+ seed_config_layers: list[dict] | None = None,
+ withheld_skill_names: frozenset[str] | set[str] | None = None,
+) -> set[str]:
"""Auto-create a config for each scout skill lacking a row, honouring an optional seed posture.
Idempotent — `get_or_create` keyed on the `(team, skill_name)` unique constraint, so
@@ -106,6 +110,14 @@ def register_missing_configs(team_id: int, seed_config_layers: list[dict] | None
the set of live `signals-scout-*` skill names for the team, so the caller can skip
dispatching configs whose skill is gone.
+ `withheld_skill_names` is the per-team holdback denylist (resolved by the coordinator from
+ the `signals-scout` flag's `withheld_skills` key). Withheld skills are dropped from the
+ returned set before any work, so no config is seeded for them AND the coordinator (which
+ dispatches only configs whose skill is in this return) never runs them — the second and
+ third enforcement points of the holdback, after `sync_canonical_skills` keeps the skill row
+ from being seeded at all. Belt-and-suspenders for the case where a row already exists (a team
+ that was previously allowed): the scout stays visible but is never enabled or dispatched here.
+
`seed_config_layers` are the team's flag config layers, most-specific first (its `team_configs`
override, then the fleet `default_team_config`); `_resolve_seed_posture` resolves them per key.
When an `enabled_skills` allowlist is in force, only those **canonical** (harness-seeded)
@@ -134,6 +146,12 @@ def register_missing_configs(team_id: int, seed_config_layers: list[dict] | None
).values_list("name", "metadata")
)
skill_names = {name for name, _ in rows}
+ # Drop held-back scouts up front: no config is seeded for them, and the returned set the
+ # coordinator dispatches from never includes them. `sync_canonical_skills` already keeps
+ # withheld skills from being seeded as `LLMSkill` rows, so this is mostly belt-and-suspenders
+ # — it also covers a team that was previously allowed and still has the row.
+ if withheld_skill_names:
+ skill_names -= set(withheld_skill_names)
# Keep the skills UI's Scouts tab in sync: stamp `category="scout"` on any scout skill rows
# not yet categorized (custom scouts authored via the skills API). Runs every reconcile tick.
ensure_scout_category(team_id)
diff --git a/products/signals/backend/scout_harness/lazy_seed.py b/products/signals/backend/scout_harness/lazy_seed.py
index 8584b88f7095..9eb6d598f1a9 100644
--- a/products/signals/backend/scout_harness/lazy_seed.py
+++ b/products/signals/backend/scout_harness/lazy_seed.py
@@ -425,7 +425,9 @@ def _update_skill_from_canonical(
)
-def sync_canonical_skills(team: Team, *, prune: bool = False) -> SyncResult:
+def sync_canonical_skills(
+ team: Team, *, prune: bool = False, withheld_skill_names: frozenset[str] | set[str] | None = None
+) -> SyncResult:
"""Reconcile a team's rows with the canonical skills on disk — the `signals-scout-*`
fleet plus the `_COMPANION_SKILL_DIRS` companions.
@@ -441,6 +443,14 @@ def sync_canonical_skills(team: Team, *, prune: bool = False) -> SyncResult:
cold-start sync leaves it off: a single ad-hoc run should only ensure its own skill exists
and is current, not reap the rest of the team's fleet.
+ `withheld_skill_names` is the per-team holdback denylist (resolved by the coordinator from
+ the `signals-scout` flag's `withheld_skills` key). A canonical skill named here is skipped
+ entirely for this team — not created, not updated — so an unreleased scout stays invisible
+ to every team not on its allowlist. Existing rows (a team previously allowed) are left
+ untouched rather than tombstoned: the coordinator's dispatch gate stops them running, and we
+ don't rewrite skill history on a flag flip. Withheld skills are still on disk, so the `prune`
+ pass never reaps them as orphans.
+
Idempotent and safe to call on every coordinator tick — the only DB writes happen when
something actually needs to change, and IntegrityError on races is logged-and-swallowed.
"""
@@ -448,6 +458,7 @@ def sync_canonical_skills(team: Team, *, prune: bool = False) -> SyncResult:
if not canonicals:
return SyncResult(skipped_reason="no canonical signals-scout-* skills on disk")
+ withheld = withheld_skill_names or frozenset()
created: list[str] = []
updated: list[str] = []
diverged: list[str] = []
@@ -455,6 +466,8 @@ def sync_canonical_skills(team: Team, *, prune: bool = False) -> SyncResult:
pruned: list[str] = []
for canonical in canonicals:
+ if canonical.name in withheld:
+ continue
canonical_hash = _compute_canonical_hash(canonical)
# Pull every row for this (team, name), live or tombstoned. Existence of any row —
diff --git a/products/signals/backend/scout_harness/runner.py b/products/signals/backend/scout_harness/runner.py
index ad59671c206e..d066613b694c 100644
--- a/products/signals/backend/scout_harness/runner.py
+++ b/products/signals/backend/scout_harness/runner.py
@@ -21,6 +21,7 @@ from products.signals.backend.scout_harness.lazy_seed import sync_canonical_skil
from products.signals.backend.scout_harness.limits import DEFAULT_MAX_RUNTIME_S, STALE_RUN_CUTOFF_S
from products.signals.backend.scout_harness.prompt import SignalScoutRunSummary, build_run_prompt
from products.signals.backend.scout_harness.skill_loader import LoadedSkill, load_skill_for_run
+from products.signals.backend.scout_harness.team_limits import withheld_skills_for_team
from products.signals.backend.temporal.agentic import (
SIGNALS_REPORT_RESEARCH_ENV_NAME,
get_or_create_signals_sandbox_env,
@@ -93,12 +94,37 @@ async def arun_signals_scout(
) -> RunResult:
"""Async core. Safe to call from inside a running event loop (Temporal activity)."""
team = await database_sync_to_async(_get_team, thread_sensitive=False)(team_id)
+
+ # Honor the per-scout holdback denylist, resolved against the canonical project. Two effects:
+ # (1) a direct run of a held-back scout is refused up front (so this manual path can't seed or
+ # run a scout the flag withholds), and (2) the canonical sync below is passed the denylist so
+ # running *any* scout on a held-back team can't seed the other withheld scouts' rows as a side
+ # effect. In local dev there's no flag payload, so this resolves empty and nothing is blocked.
+ withheld = await database_sync_to_async(withheld_skills_for_team, thread_sensitive=False)(
+ team.parent_team_id or team.id
+ )
+ if skill_name in withheld:
+ logger.info(
+ "signals_scout: skipping run, scout is withheld from this team",
+ extra={"team_id": team_id, "skill_name": skill_name},
+ )
+ return RunResult(
+ run_id=None,
+ task_run_id=None,
+ status=None,
+ last_message=None,
+ runtime_s=0.0,
+ skill_name=skill_name,
+ skill_version=skill_version or 0,
+ skip_reason="scout is withheld from this team",
+ )
+
# Sync canonical signals-scout-* skills before we resolve the skill the run asked for.
# Creates rows for newly-shipped specialists, updates harness-seeded rows the team
# hasn't edited, and leaves forked / tombstoned rows alone. Failures here should not
# crash the run — we log and continue with whatever skills the team already has.
try:
- await database_sync_to_async(sync_canonical_skills, thread_sensitive=False)(team)
+ await database_sync_to_async(sync_canonical_skills, thread_sensitive=False)(team, withheld_skill_names=withheld)
except Exception:
logger.exception(
"signals_scout: canonical skill sync failed; continuing with existing team skills",
diff --git a/products/signals/backend/scout_harness/team_limits.py b/products/signals/backend/scout_harness/team_limits.py
index 46cb5e1255f5..3a7b904e1e35 100644
--- a/products/signals/backend/scout_harness/team_limits.py
+++ b/products/signals/backend/scout_harness/team_limits.py
@@ -76,6 +76,22 @@ MAX_RUNS_PER_TEAM_PER_DAY: int | None = None
# Key inside `team_configs` / `default_team_config` that overrides `MAX_RUNS_PER_TEAM_PER_DAY`.
TEAM_CONFIG_MAX_RUNS_PER_DAY = "max_runs_per_day"
+# Per-scout holdback denylist. A list of canonical scout skill names a team must NOT get: the
+# scout is never seeded into that team's skill namespace, never config-enabled, and never
+# dispatched to it. The knob for dogfooding an unreleased scout on a single project (e.g. error
+# tracking on project 2) without exposing it fleet-wide.
+#
+# Lives inside the same `team_configs` / `default_team_config` blobs as the run caps, and resolves
+# the same most-specific-first way (`_resolve_withheld_skills`): a fleet-wide default list in
+# `default_team_config.withheld_skills` holds a scout back from EVERY team, and a per-team
+# `team_configs[<id>].withheld_skills` REPLACES that list for one team (set it to `[]` to release
+# the full fleet to a dogfooder). Same replace-not-merge semantics as `enabled_skills`. Absent at
+# both layers → nothing withheld (unchanged behaviour).
+#
+# Unlike `enabled_skills` (a soft seed default a user can still toggle on), this is a HARD gate at
+# the seed + dispatch layer — a withheld scout can't be self-enabled into running.
+TEAM_CONFIG_WITHHELD_SKILLS = "withheld_skills"
+
# Rolling window the per-team daily budget is counted over.
DAILY_BUDGET_WINDOW = timedelta(hours=24)
@@ -223,6 +239,38 @@ def _resolve_max_runs_per_day(team_id: int, team_configs: dict[int, dict], defau
return MAX_RUNS_PER_TEAM_PER_DAY
+def _resolve_withheld_skills(team_id: int, team_configs: dict[int, dict], default_team_config: dict) -> set[str]:
+ """Skill names held back from a team, resolved most-specific layer first.
+
+ `team_configs[team_id].withheld_skills` (per-team override) → `default_team_config.withheld_skills`
+ (fleet-wide default) → none. Replace-not-merge, same as `enabled_skills`: the first layer
+ carrying a valid `list[str]` wins outright, so a team can override the fleet default with its
+ own list — or with `[]` to release the full fleet (withhold nothing). A malformed value at a
+ layer (not a list of strings) falls through to the next, so a typo can't silently un-withhold a
+ scout. Absent at both layers → empty set (nothing withheld, unchanged behaviour).
+ """
+ for source in ((team_configs.get(team_id) or {}), default_team_config):
+ raw = source.get(TEAM_CONFIG_WITHHELD_SKILLS)
+ if isinstance(raw, list) and all(isinstance(name, str) for name in raw):
+ return {name for name in raw if isinstance(name, str)}
+ return set()
+
+
+def withheld_skills_for_team(canonical_team_id: int) -> set[str]:
+ """Resolve the holdback denylist for one (canonical) team in a single flag-payload read.
+
+ The coordinator resolves withholding from a payload it already read for the tick; this is the
+ one-shot equivalent for request-context callers (the on-demand `signals-scout-config-sync`
+ endpoint), so the HTTP path enforces the same holdback as the scheduled path and a held-back
+ scout can't be seeded/enabled by a manual fleet materialization. `canonical_team_id` must be
+ the parent/project id; `team_configs` keys are canonicalized so a child-keyed override still
+ resolves. A missing/unreadable payload yields an empty set (nothing withheld).
+ """
+ payload = _read_flag_payload()
+ team_configs = _canonicalize_team_config_keys(_team_configs(payload))
+ return _resolve_withheld_skills(canonical_team_id, team_configs, _default_team_config(payload))
+
+
def _runs_today_by_team(team_ids: set[int], window_start: datetime) -> dict[int, int]:
"""Scout runs dispatched per team within the trailing daily-budget window.
diff --git a/products/signals/backend/scout_harness/views.py b/products/signals/backend/scout_harness/views.py
index 977dc842a95e..56944c2e826c 100644
--- a/products/signals/backend/scout_harness/views.py
+++ b/products/signals/backend/scout_harness/views.py
@@ -81,7 +81,7 @@ from products.signals.backend.scout_harness.serializers import (
SignalScoutRunDetailSerializer,
SignalScoutRunSummarySerializer,
)
-from products.signals.backend.scout_harness.team_limits import resolve_team_metadata
+from products.signals.backend.scout_harness.team_limits import resolve_team_metadata, withheld_skills_for_team
from products.signals.backend.scout_harness.tools.emit import EvidenceEntry, InvalidEmitError, emit_finding_sync
from products.signals.backend.scout_harness.tools.profile import get_project_profile
from products.signals.backend.scout_harness.tools.runs import get_run, search_recent_runs
@@ -837,7 +837,17 @@ 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"))
+ # Don't surface held-back scouts here either — keeps the config read surface consistent
+ # with the sync response and the seeding gate, so a withheld scout stays invisible to a
+ # held-back team across the whole config API. Storage is untouched; the row reappears if
+ # the team is later un-withheld.
+ withheld = withheld_skills_for_team(team_id)
+ configs = list(
+ SignalScoutConfig.objects.unscoped()
+ .filter(team_id=team_id)
+ .exclude(skill_name__in=withheld)
+ .order_by("skill_name")
+ )
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)
@@ -987,8 +997,21 @@ class SignalScoutConfigViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSet):
# seed and register against that team so child-environment requests don't fork
# a second fleet.
team = self.team if self.team.parent_team_id is None else Team.objects.get(id=self.team.parent_team_id)
- sync_canonical_skills(team)
- register_missing_configs(team.id)
- configs = SignalScoutConfig.objects.unscoped().filter(team_id=team.id).order_by("skill_name")
+ # Honor the per-scout holdback denylist on this on-demand path too, so a held-back scout
+ # can't be seeded/enabled by a manual fleet materialization (the coordinator already gates
+ # the scheduled path).
+ withheld = withheld_skills_for_team(team.id)
+ sync_canonical_skills(team, withheld_skill_names=withheld)
+ register_missing_configs(team.id, withheld_skill_names=withheld)
+ # Exclude held-back scouts from the materialized fleet response too: a scout that was
+ # previously seeded and later withheld still has a row, and surfacing it here would
+ # advertise an unreleased scout despite the holdback. Storage is left untouched (no
+ # tombstone/disable) — the row reappears if the team is later un-withheld.
+ configs = (
+ SignalScoutConfig.objects.unscoped()
+ .filter(team_id=team.id)
+ .exclude(skill_name__in=withheld)
+ .order_by("skill_name")
+ )
skill_info = _skill_info_for(team.id, [c.skill_name for c in configs])
return Response(SignalScoutConfigSerializer(configs, many=True, context={"skill_info": skill_info}).data)
diff --git a/products/signals/backend/temporal/agentic/scout_coordinator.py b/products/signals/backend/temporal/agentic/scout_coordinator.py
index 7c91f0bce36d..02341e8adc2a 100644
--- a/products/signals/backend/temporal/agentic/scout_coordinator.py
+++ b/products/signals/backend/temporal/agentic/scout_coordinator.py
@@ -32,6 +32,7 @@ from products.signals.backend.scout_harness.team_limits import (
_read_flag_payload,
_resolve_max_runs_per_day,
_resolve_max_runs_per_tick,
+ _resolve_withheld_skills,
_runs_today_by_team,
_team_configs,
)
@@ -172,6 +173,10 @@ def _collect_planned_runs(
default_team_config = default_team_config or {}
due: list[_DueRun] = []
for team in _participating_teams(enrolled_team_ids):
+ # Scouts held back from this team via the `withheld_skills` denylist (resolved most-
+ # specific-first from this team's `team_configs` entry, then the fleet `default_team_config`):
+ # skip seeding the skill, skip seeding/enabling a config, and skip dispatch.
+ withheld_for_team = _resolve_withheld_skills(team.id, team_configs, default_team_config)
# Sync canonical scouts so a freshly-enrolled team has skills to register on.
# `prune=True`: the periodic tick is a deliberate reconciliation path, so it also
# tombstones rows whose canonical was removed from disk (the runner cold-start sync
@@ -179,7 +184,7 @@ def _collect_planned_runs(
# harness-seeded row the team hasn't edited, so a merged SKILL.md change rolls out
# within one coordinator tick. Idempotent; a failure here doesn't abort the tick.
try:
- sync_canonical_skills(team, prune=True)
+ sync_canonical_skills(team, prune=True, withheld_skill_names=withheld_for_team)
except Exception:
logger.exception(
"signals_scout coordinator: canonical skill sync failed for team; continuing",
@@ -190,7 +195,9 @@ def _collect_planned_runs(
# layers (not a shallow merge) lets `_resolve_seed_posture` fall back per key, so a
# malformed per-team value doesn't clobber a valid fleet default.
seed_config_layers = [team_configs.get(team.id) or {}, default_team_config]
- live_skills = register_missing_configs(team.id, seed_config_layers)
+ # `register_missing_configs` drops withheld skills from its return, so they're already
+ # excluded from `live_skills` (and thus from dispatch below) as well as from seeding.
+ live_skills = register_missing_configs(team.id, seed_config_layers, withheld_skill_names=withheld_for_team)
# Skip enabled configs whose `signals-scout-*` skill was deleted or is no longer the
# latest version: dispatching them would spawn a child workflow that fails fast in
# load_skill_for_run on every tick.
diff --git a/products/signals/backend/test/test_management_sync_signals_scout_skills.py b/products/signals/backend/test/test_management_sync_signals_scout_skills.py
index 14caeab9c352..db672bedf207 100644
--- a/products/signals/backend/test/test_management_sync_signals_scout_skills.py
+++ b/products/signals/backend/test/test_management_sync_signals_scout_skills.py
@@ -64,6 +64,24 @@ class TestSyncSignalsScoutSkillsCommand(BaseTest):
assert "+created" in output
assert "signals-scout-alpha" in output
+ def test_honors_withheld_skills_holdback(self) -> None:
+ # The impatient fan-out must not seed a held-back scout's LLMSkill rows — same hard gate
+ # the coordinator enforces on the scheduled path.
+ allowed = _fake_canonical("signals-scout-alpha")
+ withheld = _fake_canonical("signals-scout-error-tracking")
+ payload_path = "products.signals.backend.scout_harness.team_limits.posthoganalytics.get_feature_flag_payload"
+ with (
+ self._patch_canonicals((allowed, withheld)),
+ patch(
+ payload_path,
+ return_value={"default_team_config": {"withheld_skills": ["signals-scout-error-tracking"]}},
+ ),
+ ):
+ call_command("sync_signals_scout_skills", "--team-id", str(self.team.id), stdout=StringIO())
+
+ assert LLMSkill.objects.filter(team=self.team, name="signals-scout-alpha", deleted=False).exists()
+ assert not LLMSkill.objects.filter(team=self.team, name="signals-scout-error-tracking").exists()
+
def test_all_enabled_iterates_only_enabled_configs(self) -> None:
# Two teams; only one has enabled config.
from posthog.models import Team
diff --git a/products/signals/backend/test/test_scout_coordinator.py b/products/signals/backend/test/test_scout_coordinator.py
index 9b05245d5862..ff37e32323e6 100644
--- a/products/signals/backend/test/test_scout_coordinator.py
+++ b/products/signals/backend/test/test_scout_coordinator.py
@@ -32,6 +32,7 @@ from products.signals.backend.scout_harness.team_limits import (
_enrolled_team_ids,
_read_flag_payload,
_resolve_max_runs_per_day,
+ _resolve_withheld_skills,
_team_configs,
)
from products.signals.backend.temporal.agentic.scout_coordinator import (
@@ -802,6 +803,78 @@ async def test_seed_launch_cadence_stamped_on_disabled_canonical(ateam):
assert rows["signals-scout-error-tracking"] == (False, 720)
+# ── Per-scout holdback denylist (withheld_skills) ─────────────────────────────────
+
+
+async def test_withheld_scout_not_seeded_or_planned(ateam):
+ # A scout on the fleet-wide `withheld_skills` default is never seeded a config and never
+ # planned for a non-allowlisted team — the hard holdback. general is unaffected.
+ await database_sync_to_async(_create_skill)(ateam, "signals-scout-general")
+ await database_sync_to_async(_create_skill)(ateam, "signals-scout-error-tracking")
+
+ def _payload(*_a, **_k):
+ return {
+ "guaranteed_team_ids": [int(t) for t in _FLAGGED_TEAM_IDS],
+ "default_team_config": {"withheld_skills": ["signals-scout-error-tracking"]},
+ }
+
+ with patch(_PAYLOAD_PATH, side_effect=_payload):
+ planned = await _run_activity()
+
+ seeded = await database_sync_to_async(
+ lambda: set(SignalScoutConfig.all_teams.filter(team_id=ateam.id).values_list("skill_name", flat=True))
+ )()
+ assert "signals-scout-error-tracking" not in seeded
+ assert "signals-scout-general" in seeded
+ assert {p.skill_name for p in planned if p.team_id == ateam.id} == {"signals-scout-general"}
+
+
+async def test_withheld_scout_not_planned_even_when_config_enabled(ateam):
+ # Belt-and-suspenders: a team that already has the scout enabled (e.g. previously allowed, or
+ # self-enabled) still doesn't dispatch it once withheld — the dispatch gate, not just seeding.
+ await database_sync_to_async(_create_skill)(ateam, "signals-scout-error-tracking")
+ await database_sync_to_async(_create_config)(ateam, "signals-scout-error-tracking", enabled=True)
+
+ def _payload(*_a, **_k):
+ return {
+ "guaranteed_team_ids": [int(t) for t in _FLAGGED_TEAM_IDS],
+ "default_team_config": {"withheld_skills": ["signals-scout-error-tracking"]},
+ }
+
+ with patch(_PAYLOAD_PATH, side_effect=_payload):
+ planned = await _run_activity()
+
+ assert all(p.skill_name != "signals-scout-error-tracking" for p in planned)
+
+
+async def test_team_override_releases_withheld_scout(ateam):
+ # The dogfood case: error-tracking is withheld fleet-wide, but this team's `team_configs`
+ # override sets `withheld_skills: []`, so the scout seeds, enables, and plans for it.
+ await database_sync_to_async(_create_skill)(ateam, "signals-scout-error-tracking")
+
+ def _payload(*_a, **_k):
+ return {
+ "guaranteed_team_ids": [int(t) for t in _FLAGGED_TEAM_IDS],
+ "default_team_config": {"withheld_skills": ["signals-scout-error-tracking"]},
+ "team_configs": {str(ateam.id): {"withheld_skills": []}},
+ }
+
+ with patch(_PAYLOAD_PATH, side_effect=_payload):
+ planned = await _run_activity()
+
+ config = await database_sync_to_async(
+ lambda: SignalScoutConfig.all_teams.get(team_id=ateam.id, skill_name="signals-scout-error-tracking")
+ )()
+ assert config.enabled is True
+ assert {p.skill_name for p in planned if p.team_id == ateam.id} == {"signals-scout-error-tracking"}
+
+
# ── Per-team daily run budget (max_runs_per_day) ──────────────────────────────────
@@ -820,6 +893,36 @@ def test_resolve_max_runs_per_day(team_configs, default_cfg, expected):
assert _resolve_max_runs_per_day(7, team_configs, default_cfg) == expected
+ "team_configs,default_cfg,expected",
+ [
+ ({}, {}, set()), # nothing set → nothing withheld
+ ({}, {"withheld_skills": ["signals-scout-error-tracking"]}, {"signals-scout-error-tracking"}), # fleet default
+ # per-team override REPLACES the default list (here: release the full fleet to a dogfooder)
+ ({7: {"withheld_skills": []}}, {"withheld_skills": ["signals-scout-error-tracking"]}, set()),
+ # per-team override can withhold a different scout than the default
+ (
+ {7: {"withheld_skills": ["signals-scout-logs"]}},
+ {"withheld_skills": ["signals-scout-error-tracking"]},
+ {"signals-scout-logs"},
+ ),
+ # malformed team value (not a list of strings) falls through to the fleet default
+ (
+ {7: {"withheld_skills": "nope"}},
+ {"withheld_skills": ["signals-scout-error-tracking"]},
+ {"signals-scout-error-tracking"},
+ ),
+ (
+ {7: {"withheld_skills": [1, 2]}},
+ {"withheld_skills": ["signals-scout-error-tracking"]},
+ {"signals-scout-error-tracking"},
+ ),
+ ],
+)
+def test_resolve_withheld_skills(team_configs, default_cfg, expected):
+ assert _resolve_withheld_skills(7, team_configs, default_cfg) == expected
+
+
def _due_run(team_id: int, skill_name: str, overdue_s: float) -> _DueRun:
return _DueRun(overdue_s=overdue_s, config_pk=skill_name, team_id=team_id, skill_name=skill_name)
diff --git a/products/signals/backend/test/test_scout_harness.py b/products/signals/backend/test/test_scout_harness.py
index 54baaa087c49..92543f999f8b 100644
--- a/products/signals/backend/test/test_scout_harness.py
+++ b/products/signals/backend/test/test_scout_harness.py
@@ -498,6 +498,28 @@ async def test_skip_if_running_prevents_concurrent_runs(ateam, aerrors_skill):
assert count == 1
+async def test_withheld_scout_is_not_run(ateam, aerrors_skill):
+ # A direct `run_signals_scout` of a held-back scout is refused up front — no sandbox session,
+ # no run row — so the manual path can't run a scout the `signals-scout` flag withholds.
+ payload_path = "products.signals.backend.scout_harness.team_limits.posthoganalytics.get_feature_flag_payload"
+ with (
+ patch(payload_path, return_value={"default_team_config": {"withheld_skills": ["signals-scout-errors"]}}),
+ patch(
+ "products.signals.backend.scout_harness.runner.MultiTurnSession.start",
+ new_callable=AsyncMock,
+ side_effect=AssertionError("session.start should not run for a withheld scout"),
+ ),
+ ):
+ result = await arun_signals_scout(team_id=ateam.id, skill_name="signals-scout-errors")
+
+ assert result.run_id is None
+ assert result.skip_reason == "scout is withheld from this team"
+ has_runs = await database_sync_to_async(SignalScoutRun.objects.filter(team=ateam).exists)()
+ assert not has_runs
+
+
@pytest.mark.asyncio
@pytest.mark.django_db
async def test_skip_if_running_lock_keys_on_team_and_skill_not_just_team(ateam, aerrors_skill):
diff --git a/products/signals/backend/test/test_scout_harness_api.py b/products/signals/backend/test/test_scout_harness_api.py
index a296d5963682..d93365c8120c 100644
--- a/products/signals/backend/test/test_scout_harness_api.py
+++ b/products/signals/backend/test/test_scout_harness_api.py
@@ -738,6 +738,21 @@ class TestScoutHarnessConfigAPI(APIBaseTest):
assert body[0]["emit"] is True
assert body[0]["run_interval_minutes"] == 1440
+ def test_list_excludes_withheld_config(self) -> None:
+ # A held-back scout that still has a row (previously seeded, then withheld) is not surfaced
+ # in the config list — the read surface stays consistent with the seeding + dispatch gates.
+ SignalScoutConfig.objects.create(team=self.team, skill_name="signals-scout-alpha")
+ SignalScoutConfig.objects.create(team=self.team, skill_name="signals-scout-error-tracking")
+ payload_path = "products.signals.backend.scout_harness.team_limits.posthoganalytics.get_feature_flag_payload"
+ with patch(
+ payload_path,
+ return_value={"default_team_config": {"withheld_skills": ["signals-scout-error-tracking"]}},
+ ):
+ response = self.client.get(self._list_url())
+
+ assert response.status_code == status.HTTP_200_OK
+ assert [c["skill_name"] for c in response.json()] == ["signals-scout-alpha"]
+
@parameterized.expand(
[
("skill_present", "Watches error tracking for new and spiking issues."),
@@ -899,6 +914,41 @@ class TestScoutHarnessConfigAPI(APIBaseTest):
== canonical_names
)
+ def test_sync_respects_withheld_skills_holdback(self) -> None:
+ # A scout held back via the `signals-scout` flag denylist must not be seeded or
+ # config-materialized by the on-demand sync endpoint, the same as the scheduled path. The
+ # holdback resolves through `team_limits.withheld_skills_for_team`, so patch the flag read
+ # there (same module `_METADATA_PAYLOAD_PATH` points at).
+ payload_path = "products.signals.backend.scout_harness.team_limits.posthoganalytics.get_feature_flag_payload"
+ with patch(
+ payload_path,
+ return_value={"default_team_config": {"withheld_skills": ["signals-scout-error-tracking"]}},
+ ):
+ response = self.client.post(self._sync_url())
+
+ assert response.status_code == status.HTTP_200_OK
+ skill_names = {c["skill_name"] for c in response.json()}
+ assert "signals-scout-error-tracking" not in skill_names
+ assert "signals-scout-general" in skill_names
+ assert not SignalScoutConfig.objects.filter(team=self.team, skill_name="signals-scout-error-tracking").exists()
+ assert not LLMSkill.objects.filter(team=self.team, name="signals-scout-error-tracking", deleted=False).exists()
+
+ def test_sync_excludes_previously_seeded_withheld_config(self) -> None:
+ # A config seeded before the scout was withheld still exists in storage; the sync response
+ # must not surface it (visibility boundary), even though we don't tombstone the row.
+ SignalScoutConfig.objects.create(team=self.team, skill_name="signals-scout-error-tracking")
+ payload_path = "products.signals.backend.scout_harness.team_limits.posthoganalytics.get_feature_flag_payload"
+ with patch(
+ payload_path,
+ return_value={"default_team_config": {"withheld_skills": ["signals-scout-error-tracking"]}},
+ ):
+ response = self.client.post(self._sync_url())
+
+ assert response.status_code == status.HTTP_200_OK
+ assert "signals-scout-error-tracking" not in {c["skill_name"] for c in response.json()}
+ # Storage is untouched — the row is hidden from the response, not deleted.
+ assert SignalScoutConfig.objects.filter(team=self.team, skill_name="signals-scout-error-tracking").exists()
+
def test_sync_rejects_read_only_scope(self) -> None:
from posthog.models.personal_api_key import PersonalAPIKey
from posthog.models.utils import generate_random_token_personal, hash_key_value
diff --git a/products/signals/backend/test/test_scout_harness_lazy_seed.py b/products/signals/backend/test/test_scout_harness_lazy_seed.py
index e7b7cb2ba0d3..a29d267e2e7a 100644
--- a/products/signals/backend/test/test_scout_harness_lazy_seed.py
+++ b/products/signals/backend/test/test_scout_harness_lazy_seed.py
@@ -817,6 +817,60 @@ class TestSyncCanonicalSkills(BaseTest):
assert hasattr(result, "diverged_skill_names")
assert hasattr(result, "tombstoned_skill_names")
+ def test_withheld_skill_is_not_seeded(self) -> None:
+ # A scout on the per-team holdback denylist never materializes a row for that team.
+ allowed = _make_canonical("signals-scout-alpha", body="x")
+ withheld = _make_canonical("signals-scout-error-tracking", body="y")
+ with self._patch_canonicals((allowed, withheld)):
+ result = sync_canonical_skills(self.team, withheld_skill_names={"signals-scout-error-tracking"})
+
+ assert result.created_skill_names == ("signals-scout-alpha",)
+ assert LLMSkill.objects.filter(team=self.team, name="signals-scout-alpha", deleted=False).exists()
+ assert not LLMSkill.objects.filter(team=self.team, name="signals-scout-error-tracking").exists()
+
+ def test_withheld_skill_does_not_update_existing_row(self) -> None:
+ # Seed a row, then withhold the skill and change canonical content: the existing row is
+ # left untouched (no update, no version bump) rather than tombstoned.
+ v1 = _make_canonical("signals-scout-error-tracking", body="v1")
+ with self._patch_canonicals((v1,)):
+ sync_canonical_skills(self.team)
+ v2 = _make_canonical("signals-scout-error-tracking", body="v2")
+ with self._patch_canonicals((v2,)):
+ result = sync_canonical_skills(self.team, withheld_skill_names={"signals-scout-error-tracking"})
+
+ assert result.updated_skill_names == ()
+ row = LLMSkill.objects.get(team=self.team, name="signals-scout-error-tracking", is_latest=True, deleted=False)
+ assert row.body == "v1"
+
+ def test_withheld_skill_not_pruned_as_orphan(self) -> None:
+ # A withheld skill is still on disk, so the prune pass must not reap it as an orphan.
+ v1 = _make_canonical("signals-scout-error-tracking", body="v1")
+ with self._patch_canonicals((v1,)):
+ sync_canonical_skills(self.team)
+ with self._patch_canonicals((v1,)):
+ result = sync_canonical_skills(self.team, prune=True, withheld_skill_names={"signals-scout-error-tracking"})
+
+ assert result.pruned_skill_names == ()
+ row = LLMSkill.objects.get(team=self.team, name="signals-scout-error-tracking", is_latest=True)
+ assert row.deleted is False
+
+ def test_register_missing_configs_excludes_withheld(self) -> None:
+ # Even if a withheld scout's skill row exists (e.g. a team previously allowed), no config
+ # is seeded for it and it's dropped from the returned live-skill set the coordinator
+ # dispatches from — so it can never run.
+ allowed = _make_canonical("signals-scout-alpha")
+ withheld = _make_canonical("signals-scout-error-tracking")
+ with self._patch_canonicals((allowed, withheld)):
+ sync_canonical_skills(self.team) # no withholding at seed: both rows exist
+
+ live = register_missing_configs(self.team.id, withheld_skill_names={"signals-scout-error-tracking"})
+
+ assert live == {"signals-scout-alpha"}
+ assert SignalScoutConfig.all_teams.filter(team=self.team, skill_name="signals-scout-alpha").exists()
+ assert not SignalScoutConfig.all_teams.filter(
+ team=self.team, skill_name="signals-scout-error-tracking"
+ ).exists()
+
class TestSeedCanonicalSkillsAlias(BaseTest):
"""`seed_canonical_skills` is kept as a thin alias for `sync_canonical_skills` so older