:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(signals): add delete action for orphaned scout configs (#67114)
posthog[bot]43f32d63dc94
diff --git a/products/signals/backend/scout_harness/views.py b/products/signals/backend/scout_harness/views.pyindex c51255c8458f..9c4ac3e650ed 100644--- a/products/signals/backend/scout_harness/views.py+++ b/products/signals/backend/scout_harness/views.py@@ -1258,15 +1258,17 @@ def _skill_info_for(team_id: int, skill_names: list[str]) -> dict[str, _ScoutSkiclass SignalScoutConfigViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSet):- """Per-scout config: list, register, and tune each scout's schedule, enablement, and- emit posture.+ """Per-scout config: list, register, tune, and delete each scout's schedule, enablement,+ and emit posture.`list` is read (`signal_scout:read`) and side-effect free — the MCP tool is annotated- `readOnly`, so it must never write. `create` and `partial_update` are user-grantable- writes (`signal_scout:write`) — config changes drive spend, so enablement is+ `readOnly`, so it must never write. `create`, `partial_update`, and `destroy` are+ user-grantable writes (`signal_scout:write`) — config changes drive spend, so enablement isactivity-logged and `enabled_by` records who flipped it on. `create` exists so a freshlyauthored `signals-scout-*` skill can be configured immediately instead of waiting for the- coordinator tick to auto-register a row.+ coordinator tick to auto-register a row. `destroy` removes a row outright — the cleanup path+ for an orphaned config whose skill was archived/deleted, which `partial_update` can only make+ inert (`enabled=false`), not remove."""serializer_class = SignalScoutConfigSerializer@@ -1422,6 +1424,35 @@ class SignalScoutConfigViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSet):skill_info = _skill_info_for(team_id, [instance.skill_name])return Response(SignalScoutConfigSerializer(instance, context={"skill_info": skill_info}).data)+ @extend_schema(+ request=None,+ responses={+ 204: OpenApiResponse(description="Config deleted."),+ 404: OpenApiResponse(description="Config not found for this project."),+ },+ summary="Delete a scout config",+ description=(+ "Delete one scout config by its `id`, removing the per-(team, skill) schedule/emit row "+ "outright. The point is cleaning up an orphaned config whose `signals-scout-*` skill was "+ "archived or deleted — it lingers in `list` with an empty `description`, never runs (the "+ "coordinator skips it and the skill can't load), but can't otherwise be removed over the "+ "API. Deletion is activity-logged. Note: if the skill still exists, the coordinator "+ "re-creates a default-schedule config on its next tick — to retire a live scout, archive "+ "its skill (or set `enabled=false` to make it inert) rather than deleting the config."+ ),+ operation_id="signals_scout_config_destroy",+ )+ def destroy(self, request: Request, *args, **kwargs) -> Response:+ team_id = _canonical_team_id(self)+ config_id = _parse_run_id_or_404(kwargs)+ config = SignalScoutConfig.objects.unscoped().filter(team_id=team_id, id=config_id).first()+ if config is None:+ raise exceptions.NotFound()+ # Delete on the instance (not the queryset) so ModelActivityMixin's delete hook fires —+ # config changes drive spend and are activity-logged, removals included.+ config.delete()+ return Response(status=status.HTTP_204_NO_CONTENT)+@extend_schema(request=None,responses={diff --git a/products/signals/backend/test/test_scout_harness_api.py b/products/signals/backend/test/test_scout_harness_api.pyindex 3cd2a952c1a1..fa44dafa3344 100644--- a/products/signals/backend/test/test_scout_harness_api.py+++ b/products/signals/backend/test/test_scout_harness_api.py@@ -1078,6 +1078,31 @@ class TestScoutHarnessConfigAPI(APIBaseTest):response = self.client.patch(self._detail_url(str(config.id)), data={"enabled": False}, format="json")assert response.status_code == status.HTTP_404_NOT_FOUND+ def test_destroy_removes_config(self) -> None:+ # The orphan-cleanup path: a config whose skill is gone can't be made to disappear via+ # partial_update (only inert), so destroy must actually remove the row.+ config = SignalScoutConfig.objects.create(team=self.team, skill_name="signals-scout-foo")++ response = self.client.delete(self._detail_url(str(config.id)))++ assert response.status_code == status.HTTP_204_NO_CONTENT+ assert not SignalScoutConfig.all_teams.filter(id=config.id).exists()++ def test_destroy_unknown_id_returns_404(self) -> None:+ response = self.client.delete(self._detail_url("00000000-0000-0000-0000-000000000000"))+ assert response.status_code == status.HTTP_404_NOT_FOUND++ def test_destroy_other_teams_config_returns_404_and_preserves_row(self) -> None:+ # Tenant isolation: deleting must be scoped by team — another team's config is neither+ # removed nor acknowledged.+ other_team = Team.objects.create(organization=self.organization, name="other")+ config = SignalScoutConfig.all_teams.create(team=other_team, skill_name="signals-scout-foo")++ response = self.client.delete(self._detail_url(str(config.id)))++ assert response.status_code == status.HTTP_404_NOT_FOUND+ assert SignalScoutConfig.all_teams.filter(id=config.id).exists()+def _sync_url(self) -> str:return f"/api/projects/{self.team.id}/signals/scout/configs/sync/"diff --git a/products/signals/frontend/generated/api.ts b/products/signals/frontend/generated/api.tsindex 2080d9309eb3..be8370bf31e2 100644--- a/products/signals/frontend/generated/api.ts+++ b/products/signals/frontend/generated/api.ts@@ -479,6 +479,25 @@ export const signalsScoutConfigUpdate = async (})}+export const getSignalsScoutConfigDestroyUrl = (projectId: string, id: string) => {+ return `/api/projects/${projectId}/signals/scout/configs/${id}/`+}++/**+ * Delete one scout config by its `id`, removing the per-(team, skill) schedule/emit row outright. The point is cleaning up an orphaned config whose `signals-scout-*` skill was archived or deleted — it lingers in `list` with an empty `description`, never runs (the coordinator skips it and the skill can't load), but can't otherwise be removed over the API. Deletion is activity-logged. Note: if the skill still exists, the coordinator re-creates a default-schedule config on its next tick — to retire a live scout, archive its skill (or set `enabled=false` to make it inert) rather than deleting the config.+ * @summary Delete a scout config+ */+export const signalsScoutConfigDestroy = async (+ projectId: string,+ id: string,+ options?: RequestInit+): Promise<void> => {+ return apiMutator<void>(getSignalsScoutConfigDestroyUrl(projectId, id), {+ ...options,+ method: 'DELETE',+ })+}+export const getSignalsScoutConfigSyncUrl = (projectId: string) => {return `/api/projects/${projectId}/signals/scout/configs/sync/`}diff --git a/products/signals/mcp/tools.yaml b/products/signals/mcp/tools.yamlindex c6ceda9c4033..cf92ef708be0 100644--- a/products/signals/mcp/tools.yaml+++ b/products/signals/mcp/tools.yaml@@ -358,6 +358,23 @@ tools:`enabled`, and `emit` (false = dry-run) in the same call. The skill must already exist on the project(author it via the skills store first). Upsert: if a config already exists for the skill, the providedfields are applied to it. Creating an enabled config is activity-logged, since running a scout drives spend.+ signals-scout-config-delete:+ operation: signals_scout_config_destroy+ enabled: true+ scopes:+ - signal_scout:write+ annotations:+ readOnly: false+ destructive: true+ idempotent: true+ title: Delete a scout config+ description: >+ Delete one scout config by its `id`, removing the per-scout schedule/emit row outright. Use it to clean up+ an orphaned config whose `signals-scout-*` skill was archived or deleted — it lingers in+ `signals-scout-config-list` with an empty description and never runs, but can't otherwise be removed.+ Deletion is activity-logged. Note: if the skill still exists the coordinator re-creates a default-schedule+ config on its next tick — to retire a live scout, archive its skill (or set `enabled=false` via+ `signals-scout-config-update` to make it inert) rather than deleting the config.signals-scout-config-list:operation: signals_scout_config_listenabled: truediff --git a/services/mcp/schema/generated-tool-definitions.json b/services/mcp/schema/generated-tool-definitions.jsonindex c4ae1c8ec747..f579d1574469 100644--- a/services/mcp/schema/generated-tool-definitions.json+++ b/services/mcp/schema/generated-tool-definitions.json@@ -6717,6 +6717,20 @@"readOnlyHint": false}},+ "signals-scout-config-delete": {+ "description": "Delete one scout config by its `id`, removing the per-scout schedule/emit row outright. Use it to clean up an orphaned config whose `signals-scout-*` skill was archived or deleted — it lingers in `signals-scout-config-list` with an empty description and never runs, but can't otherwise be removed. Deletion is activity-logged. Note: if the skill still exists the coordinator re-creates a default-schedule config on its next tick — to retire a live scout, archive its skill (or set `enabled=false` via `signals-scout-config-update` to make it inert) rather than deleting the config.",+ "category": "Signals",+ "feature": "signals",+ "summary": "Delete a scout config",+ "title": "Delete a scout config",+ "required_scopes": ["signal_scout:write"],+ "annotations": {+ "destructiveHint": true,+ "idempotentHint": true,+ "openWorldHint": true,+ "readOnlyHint": false+ }+ },"signals-scout-config-list": {"description": "List the per-scout configs for this project — one row per `signals-scout-*` skill, each with its schedule (`run_interval_minutes`), `enabled` flag, and `emit` (dry-run) posture. A freshly authored scout appears once its config is registered — immediately via `signals-scout-config-create` (one skill) or `signals-scout-config-sync` (the whole fleet), or on the coordinator's next tick. Use this to see which scouts run, how often, and whether they emit findings to the inbox. Pair with `signals-scout-config-update` to tune them.","category": "Signals",diff --git a/services/mcp/schema/tool-definitions-all.json b/services/mcp/schema/tool-definitions-all.jsonindex d04d8d75fd09..793b6e0968b6 100644--- a/services/mcp/schema/tool-definitions-all.json+++ b/services/mcp/schema/tool-definitions-all.json@@ -7228,6 +7228,20 @@"readOnlyHint": false}},+ "signals-scout-config-delete": {+ "description": "Delete one scout config by its `id`, removing the per-scout schedule/emit row outright. Use it to clean up an orphaned config whose `signals-scout-*` skill was archived or deleted — it lingers in `signals-scout-config-list` with an empty description and never runs, but can't otherwise be removed. Deletion is activity-logged. Note: if the skill still exists the coordinator re-creates a default-schedule config on its next tick — to retire a live scout, archive its skill (or set `enabled=false` via `signals-scout-config-update` to make it inert) rather than deleting the config.",+ "category": "Signals",+ "feature": "signals",+ "summary": "Delete a scout config",+ "title": "Delete a scout config",+ "required_scopes": ["signal_scout:write"],+ "annotations": {+ "destructiveHint": true,+ "idempotentHint": true,+ "openWorldHint": true,+ "readOnlyHint": false+ }+ },"signals-scout-config-list": {"description": "List the per-scout configs for this project — one row per `signals-scout-*` skill, each with its schedule (`run_interval_minutes`), `enabled` flag, and `emit` (dry-run) posture. A freshly authored scout appears once its config is registered — immediately via `signals-scout-config-create` (one skill) or `signals-scout-config-sync` (the whole fleet), or on the coordinator's next tick. Use this to see which scouts run, how often, and whether they emit findings to the inbox. Pair with `signals-scout-config-update` to tune them.","category": "Signals",diff --git a/services/mcp/src/generated/signals/api.ts b/services/mcp/src/generated/signals/api.tsindex 3e943ff50fe2..bbe1a933cd3c 100644--- a/services/mcp/src/generated/signals/api.ts+++ b/services/mcp/src/generated/signals/api.ts@@ -3,7 +3,7 @@* MCP service uses these Zod schemas for generated tool handlers.* To regenerate: hogli build:openapi*- * PostHog API - MCP 32 enabled ops+ * PostHog API - MCP 33 enabled ops* OpenAPI spec version: 1.0.0*/import * as zod from 'zod'@@ -450,6 +450,19 @@ export const SignalsScoutConfigUpdateBody = /* @__PURE__ */ zod'Per-(team, skill) scout config: schedule, enablement, and emit posture.\n\nOne row per `signals-scout-*` skill on the team. The coordinator auto-creates a row\nwhen it discovers a scout skill; this serializer lets agents tune the row.')+/**+ * Delete one scout config by its `id`, removing the per-(team, skill) schedule/emit row outright. The point is cleaning up an orphaned config whose `signals-scout-*` skill was archived or deleted — it lingers in `list` with an empty `description`, never runs (the coordinator skips it and the skill can't load), but can't otherwise be removed over the API. Deletion is activity-logged. Note: if the skill still exists, the coordinator re-creates a default-schedule config on its next tick — to retire a live scout, archive its skill (or set `enabled=false` to make it inert) rather than deleting the config.+ * @summary Delete a scout config+ */+export const SignalsScoutConfigDestroyParams = /* @__PURE__ */ zod.object({+ id: zod.string().describe('A UUID string identifying this Signal scout config.'),+ project_id: zod+ .string()+ .describe(+ "Project ID of the project you're trying to access. To find the ID of the project, make a call to /api/projects/."+ ),+})+/*** Materialize the scout fleet for this project on demand (idempotent): seed the canonical `signals-scout-*` skills, create a default-schedule config for any scout lacking one, and return all scout configs. Normally the Temporal coordinator does this on its next tick; this action exists so setup flows (e.g. the wizard's self-driving program) can hand the user a tunable fleet immediately.* @summary Sync scout configsdiff --git a/services/mcp/src/tools/generated/signals.ts b/services/mcp/src/tools/generated/signals.tsindex f1ce92e52eff..ed4f7d48edd0 100644--- a/services/mcp/src/tools/generated/signals.ts+++ b/services/mcp/src/tools/generated/signals.ts@@ -19,6 +19,7 @@ import {SignalsReportsStateCreateBody,SignalsReportsStateCreateParams,SignalsScoutConfigCreateBody,+ SignalsScoutConfigDestroyParams,SignalsScoutConfigUpdateBody,SignalsScoutConfigUpdateParams,SignalsScoutEditReportBody,@@ -518,6 +519,21 @@ const signalsScoutConfigCreate = (): ToolBase<typeof SignalsScoutConfigCreateSch},})+const SignalsScoutConfigDeleteSchema = SignalsScoutConfigDestroyParams.omit({ project_id: true })++const signalsScoutConfigDelete = (): ToolBase<typeof SignalsScoutConfigDeleteSchema, unknown> => ({+ name: 'signals-scout-config-delete',+ schema: SignalsScoutConfigDeleteSchema,+ handler: async (context: Context, params: z.infer<typeof SignalsScoutConfigDeleteSchema>) => {+ const projectId = await context.stateManager.getProjectId()+ const result = await context.api.request<unknown>({+ method: 'DELETE',+ path: `/api/projects/${encodeURIComponent(String(projectId))}/signals/scout/configs/${encodeURIComponent(String(params.id))}/`,+ })+ return result+ },+})+const SignalsScoutConfigListSchema = z.object({})const signalsScoutConfigList = (): ToolBase<@@ -958,6 +974,7 @@ export const GENERATED_TOOLS: Record<string, () => ToolBase<ZodObjectAny>> = {'inbox-source-configs-retrieve': inboxSourceConfigsRetrieve,'inbox-source-configs-update': inboxSourceConfigsUpdate,'signals-scout-config-create': signalsScoutConfigCreate,+ 'signals-scout-config-delete': signalsScoutConfigDelete,'signals-scout-config-list': signalsScoutConfigList,'signals-scout-config-sync': signalsScoutConfigSync,'signals-scout-config-update': signalsScoutConfigUpdate,diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/signals-scout-config-delete.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/signals-scout-config-delete.jsonnew file mode 100644index 000000000000..e961e7ade226--- /dev/null+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/signals-scout-config-delete.json@@ -0,0 +1,11 @@+{+ "$schema": "https://json-schema.org/draft/2020-12/schema",+ "properties": {+ "id": {+ "description": "A UUID string identifying this Signal scout config.",+ "type": "string"+ }+ },+ "required": ["id"],+ "type": "object"+}