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 scout source toggle to inbox troop section (#64947)

Andrew Maguire3ef023f38f85
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index f9ccc9f30b78..2367b1f0316c 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -4841,7 +4841,7 @@ snapshots:
scenes-app-dashboards--access-control-dashboard--light:
hash: v1.k794b7964.8750e411634aabaec37428088a6c2ff338b30103628b3358ec1aa9303e7bc6a4.QHf7vvPUacMgAWbJiWSEEWZ5xEhNe-apEwxD59eg29o
scenes-app-dashboards--edit--dark:
- hash: v1.k794b7964.9f5c9d9b55e8ee6701b1492cc80840f5c385d6a2b566e857dafd4616d0e03520.qT8LsD9-4a-wmd4KCQmG0l5q6pLsOJwuXw98Rq18_N8
+ hash: v1.k794b7964.77a03f7c6aef36f12b2eff445c072046a811be333172a731bb86ae353e047544.YlLoJRLu6tNMUvkmYZH8wVJzRVUqWFZtV-BhpSz5aTo
scenes-app-dashboards--edit--light:
hash: v1.k794b7964.3b2874181e936c6709d7c67db69bba087f600c2bd33835bce8e0e3a73964e948.pJ537ZFActzJzjSYe4aRQKCKH1DFgA32qSl7v9VUWIQ
scenes-app-dashboards--erroring--dark:
diff --git a/frontend/src/scenes/inbox/components/config/scouts/ScoutsFleetSection.tsx b/frontend/src/scenes/inbox/components/config/scouts/ScoutsFleetSection.tsx
index 12e73a3601db..ccea61fa4aa7 100644
--- a/frontend/src/scenes/inbox/components/config/scouts/ScoutsFleetSection.tsx
+++ b/frontend/src/scenes/inbox/components/config/scouts/ScoutsFleetSection.tsx
@@ -2,13 +2,14 @@ import { useActions, useValues } from 'kea'
import { useEffect } from 'react'
import { IconChevronDown, IconCompass, IconPlus, IconSparkles } from '@posthog/icons'
-import { LemonButton, LemonSkeleton } from '@posthog/lemon-ui'
+import { LemonButton, LemonSkeleton, LemonSwitch } from '@posthog/lemon-ui'
import { TZLabel } from 'lib/components/TZLabel'
import { percentage } from 'lib/utils/numbers'
import { pluralize } from 'lib/utils/strings'
import { scoutFleetLogic } from '../../../logics/scoutFleetLogic'
+import { signalSourcesLogic } from '../../../signalSourcesLogic'
import { SignalScoutConfig } from '../../../types'
import {
FleetSummary,
@@ -63,6 +64,7 @@ export function ScoutsFleetSection(): JSX.Element {
return (
<div className="flex flex-col gap-3">
+ <ScoutsSourceGate />
<button
type="button"
onClick={() => setExpanded(!expanded)}
@@ -93,6 +95,51 @@ export function ScoutsFleetSection(): JSX.Element {
)
}
+/**
+ * Team-level gate that decides whether scout findings emit to the inbox. Backed by the single
+ * `signals_scout` / `cross_source_issue` source config row — the same gate the backend emit
+ * preflight requires and the Code app toggles — so there is one source of truth, not a parallel
+ * control. It governs emit only: scouts still run on their schedule when this is off, so the copy
+ * is deliberately about findings reaching the inbox rather than "running scouts".
+ *
+ * This is also the natural home for a future unified switch that drives enrolment (run + emit)
+ * from one user action, retiring the manual coordinator allowlist — keep new scout on/off wiring
+ * here rather than adding a second control elsewhere.
+ */
+function ScoutsSourceGate(): JSX.Element {
+ const { scoutsSourceConfig, isScoutsSourceToggling, sourceConfigs, sourceConfigsLoading } =
+ useValues(signalSourcesLogic)
+ const { toggleScoutsSource, loadSourceConfigs } = useActions(signalSourcesLogic)
+
+ useEffect(() => {
+ loadSourceConfigs()
+ }, [loadSourceConfigs])
+
+ const enabled = scoutsSourceConfig?.enabled ?? false
+ const initialLoading = sourceConfigsLoading && sourceConfigs === null
+
+ return (
+ <div className="flex items-center gap-3 rounded border border-primary bg-bg-light px-4 py-3.5">
+ <div className="flex flex-col min-w-0">
+ <span className="font-medium text-sm text-default">Surface findings in your inbox</span>
+ <span className="text-xs text-secondary leading-snug">
+ Scouts run on their schedule regardless; this controls whether their findings reach your inbox.
+ </span>
+ </div>
+ <span className="flex-1" />
+ <LemonSwitch
+ aria-label="Surface scout findings in your inbox"
+ checked={enabled}
+ onChange={() => toggleScoutsSource()}
+ loading={isScoutsSourceToggling}
+ disabledReason={
+ initialLoading || (!isScoutsSourceToggling && sourceConfigs === null) ? 'Loading…' : undefined
+ }
+ />
+ </div>
+ )
+}
+
/** One-line fleet pulse: running, success rate, signals emitted + emit rate. */
function summarize(summary: FleetSummary | null): string {
if (!summary) {
diff --git a/frontend/src/scenes/inbox/signalSourcesLogic.ts b/frontend/src/scenes/inbox/signalSourcesLogic.ts
index 2f70af7245fc..70226bbbfe92 100644
--- a/frontend/src/scenes/inbox/signalSourcesLogic.ts
+++ b/frontend/src/scenes/inbox/signalSourcesLogic.ts
@@ -139,6 +139,7 @@ export const signalSourcesLogic = kea<signalSourcesLogicType>([
toggleErrorTrackingComplete: true,
toggleHealthChecks: true,
toggleConversations: true,
+ toggleScoutsSource: true,
saveSessionAnalysisFilters: (filters: RecordingUniversalFilters) => ({ filters }),
clearSessionAnalysisFilters: true,
}),
@@ -194,6 +195,8 @@ export const signalSourcesLogic = kea<signalSourcesLogicType>([
toggleSourceConfigState(state, SignalSourceProduct.HEALTH_CHECKS, SignalSourceType.HEALTH_ISSUE),
toggleConversations: (state: SignalSourceConfig[] | null) =>
toggleSourceConfigState(state, SignalSourceProduct.CONVERSATIONS, SignalSourceType.TICKET),
+ toggleScoutsSource: (state: SignalSourceConfig[] | null) =>
+ toggleSourceConfigState(state, SignalSourceProduct.SIGNALS_SCOUT, SignalSourceType.CROSS_SOURCE_ISSUE),
},
togglingSourceKeys: [
new Set<string>(),
@@ -318,6 +321,23 @@ export const signalSourcesLogic = kea<signalSourcesLogicType>([
(keys: Set<string>): boolean =>
keys.has(`${SignalSourceProduct.HEALTH_CHECKS}_${SignalSourceType.HEALTH_ISSUE}`),
],
+ // The scout source gate: a single team-level on/off that decides whether scout findings
+ // emit to the inbox at all. It is NOT a per-scout toggle (those live on SignalScoutConfig)
+ // and does not control whether scouts run — only whether what they find reaches the inbox.
+ scoutsSourceConfig: [
+ (s) => [s.sourceConfigs],
+ (sourceConfigs: SignalSourceConfig[] | null): SignalSourceConfig | null =>
+ sourceConfigs?.find(
+ (c) =>
+ c.source_product === SignalSourceProduct.SIGNALS_SCOUT &&
+ c.source_type === SignalSourceType.CROSS_SOURCE_ISSUE
+ ) ?? null,
+ ],
+ isScoutsSourceToggling: [
+ (s) => [s.togglingSourceKeys],
+ (keys: Set<string>): boolean =>
+ keys.has(`${SignalSourceProduct.SIGNALS_SCOUT}_${SignalSourceType.CROSS_SOURCE_ISSUE}`),
+ ],
errorTrackingIsFullyEnabled: [
(s) => [s.sourceConfigs],
(sourceConfigs: SignalSourceConfig[] | null): boolean => {
@@ -339,7 +359,18 @@ export const signalSourcesLogic = kea<signalSourcesLogicType>([
],
enabledSourcesCount: [
(s) => [s.sourceConfigs],
- (sourceConfigs: SignalSourceConfig[] | null): number => sourceConfigs?.filter((c) => c.enabled).length ?? 0,
+ // The scout gate is a meta-toggle surfaced in the Scout troop section, not a generic
+ // signal source — exclude it so a scout-only project doesn't show the "Signal sources"
+ // setup card as done with a phantom "1 watching".
+ (sourceConfigs: SignalSourceConfig[] | null): number =>
+ sourceConfigs?.filter(
+ (c) =>
+ c.enabled &&
+ !(
+ c.source_product === SignalSourceProduct.SIGNALS_SCOUT &&
+ c.source_type === SignalSourceType.CROSS_SOURCE_ISSUE
+ )
+ ).length ?? 0,
],
hasNoSources: [
(s) => [s.sourceConfigs, s.enabledSourcesCount],
@@ -500,6 +531,17 @@ export const signalSourcesLogic = kea<signalSourcesLogicType>([
enabled: desiredEnabled,
})
},
+ toggleScoutsSource: () => {
+ // The optimistic reducer flips the config before this listener runs,
+ // so config.enabled already reflects the desired state.
+ const config = values.scoutsSourceConfig
+ const desiredEnabled = config?.enabled ?? true
+ actions.toggleSignalSource({
+ sourceProduct: SignalSourceProduct.SIGNALS_SCOUT,
+ sourceType: SignalSourceType.CROSS_SOURCE_ISSUE,
+ enabled: desiredEnabled,
+ })
+ },
toggleDataWarehouseSource: ({ dwSource }) => {
const { sourceProduct, sourceType } = DATA_WAREHOUSE_SOURCE_CONFIG[dwSource]
const config = getDataWarehouseSourceConfig(values, dwSource)
diff --git a/products/signals/backend/test/test_signal_source_config_api.py b/products/signals/backend/test/test_signal_source_config_api.py
index 86fa6797c394..b0787a35c905 100644
--- a/products/signals/backend/test/test_signal_source_config_api.py
+++ b/products/signals/backend/test/test_signal_source_config_api.py
@@ -304,23 +304,19 @@ class TestSignalSourceConfigAPI(APIBaseTest):
assert response.status_code == status.HTTP_400_BAD_REQUEST
assert "recording_filters must be a JSON object" in str(response.json())
- def test_update_source_type_is_not_writable(self):
+ def test_update_source_keys_are_immutable(self):
config = SignalSourceConfig.objects.create(
team=self.team,
source_product="session_replay",
source_type="session_analysis_cluster",
created_by=self.user,
)
- response = self.client.patch(
- self._url(str(config.id)),
- data={"source_type": "nonexistent_type"},
- format="json",
- )
- # source_type is not read_only in serializer, so this may succeed
- # but the value is validated
+ for field, value in (("source_type", "issue_created"), ("source_product", "error_tracking")):
+ response = self.client.patch(self._url(str(config.id)), data={field: value}, format="json")
+ assert response.status_code == status.HTTP_400_BAD_REQUEST, response.json()
config.refresh_from_db()
- # Should either be rejected or keep original value
- assert config.source_type == "session_analysis_cluster" or response.status_code == status.HTTP_400_BAD_REQUEST
+ assert config.source_product == "session_replay"
+ assert config.source_type == "session_analysis_cluster"
def test_delete_other_teams_config_forbidden(self):
other_team = Team.objects.create(organization=self.organization, name="Other Team")
@@ -370,6 +366,94 @@ class TestSignalSourceConfigAPI(APIBaseTest):
assert response.status_code in (status.HTTP_401_UNAUTHORIZED, status.HTTP_403_FORBIDDEN)
+class TestScoutSourceCanonicalization(APIBaseTest):
+ """The scout source config is a project-level singleton: the scout fleet canonicalizes child
+ environments to the parent team and the emit preflight gates on the parent team's row, so the
+ inbox toggle must read and write that same canonical row from any environment in the project."""
+
+ def setUp(self) -> None:
+ super().setUp()
+ # A second environment within the same project, parented to the default team.
+ self.child_team = Team.objects.create(
+ organization=self.organization, project=self.project, parent_team=self.team, name="Child env"
+ )
+
+ def _child_url(self, config_id: str | None = None) -> str:
+ base = f"/api/projects/{self.child_team.id}/signals/source_configs/"
+ return f"{base}{config_id}/" if config_id else base
+
+ def test_create_from_child_env_writes_canonical_team(self):
+ response = self.client.post(
+ self._child_url(),
+ data={"source_product": "signals_scout", "source_type": "cross_source_issue", "enabled": True},
+ format="json",
+ )
+ assert response.status_code == status.HTTP_201_CREATED, response.json()
+ config = SignalSourceConfig.objects.get(id=response.json()["id"])
+ # Written to the parent team, so the emit preflight (which canonicalizes) finds it.
+ assert config.team_id == self.team.id
+ assert SignalSourceConfig.is_source_enabled(self.team.id, "signals_scout", "cross_source_issue") is True
+
+ def test_child_env_lists_canonical_scout_row(self):
+ config = SignalSourceConfig.objects.create(
+ team=self.team,
+ source_product="signals_scout",
+ source_type="cross_source_issue",
+ enabled=True,
+ )
+ results = self.client.get(self._child_url()).json()["results"]
+ assert [r["id"] for r in results] == [str(config.id)]
+
+ def test_child_env_updates_canonical_scout_row(self):
+ config = SignalSourceConfig.objects.create(
+ team=self.team,
+ source_product="signals_scout",
+ source_type="cross_source_issue",
+ enabled=True,
+ )
+ response = self.client.patch(self._child_url(str(config.id)), data={"enabled": False}, format="json")
+ assert response.status_code == status.HTTP_200_OK, response.json()
+ config.refresh_from_db()
+ assert config.enabled is False
+
+ def test_child_env_cannot_retag_config_into_scout_source(self):
+ # A child-environment row retagged to the scout source would otherwise stay on the child
+ # team, hidden by the read filter while the emit gate checks the parent — a hidden, broken
+ # scout config. Source keys are immutable on update, so the retag is rejected outright.
+ config = SignalSourceConfig.objects.create(
+ team=self.child_team,
+ source_product="session_replay",
+ source_type="session_analysis_cluster",
+ enabled=True,
+ )
+ response = self.client.patch(
+ self._child_url(str(config.id)),
+ data={"source_product": "signals_scout", "source_type": "cross_source_issue"},
+ format="json",
+ )
+ assert response.status_code == status.HTTP_400_BAD_REQUEST, response.json()
+ config.refresh_from_db()
+ assert config.team_id == self.child_team.id
+ assert config.source_product == "session_replay"
+ assert config.source_type == "session_analysis_cluster"
+ # No stranded scout row exists on either team.
+ assert not SignalSourceConfig.objects.filter(
+ team_id__in=[self.team.id, self.child_team.id],
+ source_product="signals_scout",
+ source_type="cross_source_issue",
+ ).exists()
+
+ def test_non_scout_source_stays_environment_scoped(self):
+ # A parent-team session-analysis row must not leak into the child environment's list.
+ SignalSourceConfig.objects.create(
+ team=self.team,
+ source_product="session_replay",
+ source_type="session_analysis_cluster",
+ enabled=True,
+ )
+ assert self.client.get(self._child_url()).json()["results"] == []
+
+
class TestIsSourceEnabledGating(APIBaseTest):
"""Source-level gating quirks: session_problem routes through the session_analysis_cluster
config rather than requiring its own SignalSourceConfig row."""
diff --git a/products/signals/backend/views.py b/products/signals/backend/views.py
index d0fb0b671f25..36a7a52d9f7b 100644
--- a/products/signals/backend/views.py
+++ b/products/signals/backend/views.py
@@ -187,9 +187,41 @@ class SignalSourceConfigViewSet(TeamAndOrgViewSetMixin, viewsets.ModelViewSet):
scope_object = "task"
queryset = SignalSourceConfig.objects.all().order_by("-updated_at")
+ def _is_scout_source(self, source_product: str | None, source_type: str | None) -> bool:
+ return (
+ source_product == SignalSourceConfig.SourceProduct.SIGNALS_SCOUT
+ and source_type == SignalSourceConfig.SourceType.CROSS_SOURCE_ISSUE
+ )
+
+ def _config_team_id(self, source_product: str | None, source_type: str | None) -> int:
+ # The scout source config is a project-level singleton: the scout fleet canonicalizes
+ # child environments to the parent team, and the emit preflight gates on the parent
+ # team's row (see scout_harness/views.py `_canonical_team_id` and tools/emit.py). Writing
+ # it to the canonical team keeps the inbox toggle and the emit gate on the same row from
+ # any environment. All other sources stay environment-scoped.
+ if self._is_scout_source(source_product, source_type):
+ return self.team.parent_team_id or self.team_id
+ return self.team_id
+
+ def _filter_queryset_by_parents_lookups(self, queryset):
+ # Mirror of `_config_team_id` on the read side: surface the scout row from the canonical
+ # (parent) team while every other source stays scoped to the URL environment, so the
+ # toggle reads and updates the same project-level row the emit gate checks.
+ canonical_team_id = self.team.parent_team_id or self.team_id
+ scout_source = Q(
+ source_product=SignalSourceConfig.SourceProduct.SIGNALS_SCOUT,
+ source_type=SignalSourceConfig.SourceType.CROSS_SOURCE_ISSUE,
+ )
+ return queryset.filter(
+ (Q(team_id=self.team_id) & ~scout_source) | (Q(team_id=canonical_team_id) & scout_source)
+ )
+
def perform_create(self, serializer):
+ team_id = self._config_team_id(
+ serializer.validated_data.get("source_product"), serializer.validated_data.get("source_type")
+ )
try:
- instance = serializer.save(team_id=self.team_id, created_by=self.request.user)
+ instance = serializer.save(team_id=team_id, created_by=self.request.user)
except IntegrityError:
raise serializers.ValidationError(
{"source_product": "A configuration for this source product and type already exists for this team."}
@@ -236,6 +268,17 @@ class SignalSourceConfigViewSet(TeamAndOrgViewSetMixin, viewsets.ModelViewSet):
def perform_update(self, serializer):
instance = cast(SignalSourceConfig, serializer.instance)
was_enabled = instance.enabled
+
+ # The source keys are the row's identity and decide its canonical team_id on create
+ # (`_config_team_id`); retagging them in place would strand the row on the wrong team —
+ # e.g. a child-environment row retagged to the scout source would stay on the child team,
+ # hidden by the read filter while the emit gate checks the parent. There is no legitimate
+ # reason to change a config's source identity, so reject it rather than re-deriving team_id.
+ for field in ("source_product", "source_type"):
+ new_value = serializer.validated_data.get(field)
+ if new_value is not None and new_value != getattr(instance, field):
+ raise serializers.ValidationError({field: f"{field} cannot be changed after creation."})
+
try:
instance = serializer.save()
except IntegrityError: