: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(data-warehouse): resume a suspended view from mcp, per engine (#126202)
Jovan Sakovic0298a8547b74
diff --git a/products/data_modeling/backend/logic/node_suspension.py b/products/data_modeling/backend/logic/node_suspension.pyindex 00cb4aa07f92..64c5fe36fc35 100644--- a/products/data_modeling/backend/logic/node_suspension.py+++ b/products/data_modeling/backend/logic/node_suspension.py@@ -13,6 +13,8 @@ from django.db import transactionimport structlog+from products.data_modeling.backend.facade.contracts import MaterializationEngine+from products.data_modeling.backend.models.data_modeling_job import DataModelingJobEnginefrom products.data_modeling.backend.models.node import Nodeif TYPE_CHECKING:@@ -174,12 +176,22 @@ def suspended_saved_query_ids_by_team(engine: str) -> dict[int, list[str]]:return {team_id: sorted(ids) for team_id, ids in by_team.items()}-def unsuspend_saved_query(saved_query: "DataWarehouseSavedQuery", *, by: str = "api") -> int:+_SUSPENSION_ENGINES = {+ MaterializationEngine.CLICKHOUSE: DataModelingJobEngine.CLICKHOUSE,+ MaterializationEngine.TRINO: DataModelingJobEngine.MANAGED_WAREHOUSE,+}+++def unsuspend_saved_query(+ saved_query: "DataWarehouseSavedQuery", *, by: str = "api", engine: MaterializationEngine | None = None+) -> int:"""Clears the marker on every node the query backs, which is more than one when it landed in- duplicate DAGs. Schedules nothing: the next tier fire runs the node because no marker stops it."""+ duplicate DAGs. Schedules nothing: the next tier fire runs the node because no marker stops it.+ Without an engine, every engine's marker is cleared."""return unsuspend_nodes(Node.objects.filter(team_id=saved_query.team_id, saved_query_id=saved_query.id),by=by,+ engine=_SUSPENSION_ENGINES[engine].value if engine is not None else None,)diff --git a/products/data_warehouse/backend/presentation/views/saved_query/viewset.py b/products/data_warehouse/backend/presentation/views/saved_query/viewset.pyindex 91752aa5b991..eee6f8ece24b 100644--- a/products/data_warehouse/backend/presentation/views/saved_query/viewset.py+++ b/products/data_warehouse/backend/presentation/views/saved_query/viewset.py@@ -79,6 +79,19 @@ class DataWarehouseSavedQueryPagination(PageNumberPagination):page_size = 1000+class SavedQueryResumeRequestSerializer(serializers.Serializer):+ """Body of the `resume` action."""++ engine = serializers.ChoiceField(+ choices=MaterializationEngine.choices,+ required=False,+ help_text=(+ "Resume only this engine's materialization: 'clickhouse' or 'trino' (the managed warehouse). "+ "Omit it to resume every engine the query is suspended on."+ ),+ )++class SavedQueryResumeSerializer(serializers.Serializer):resumed = serializers.BooleanField(help_text="False when the query's materialization was not suspended.")@@ -444,7 +457,7 @@ class DataWarehouseSavedQueryViewSet(TeamAndOrgViewSetMixin, AccessControlViewSestatus=status.HTTP_200_OK,)- @extend_schema(request=None, responses={200: SavedQueryResumeSerializer})+ @extend_schema(request=SavedQueryResumeRequestSerializer, responses={200: SavedQueryResumeSerializer})@action(methods=["POST"], detail=True, required_scopes=["warehouse_view:write"])def resume(self, request: request.Request, *args, **kwargs) -> response.Response:"""Resume materialization suspended after repeated failures.@@ -454,7 +467,9 @@ class DataWarehouseSavedQueryViewSet(TeamAndOrgViewSetMixin, AccessControlViewSe"""from products.data_modeling.backend.facade.api import unsuspend_saved_query- resumed = unsuspend_saved_query(self.get_object())+ body = SavedQueryResumeRequestSerializer(data=request.data)+ body.is_valid(raise_exception=True)+ resumed = unsuspend_saved_query(self.get_object(), engine=body.validated_data.get("engine"))return response.Response({"resumed": bool(resumed)}, status=status.HTTP_200_OK)diff --git a/products/data_warehouse/backend/tests/api/test_saved_query.py b/products/data_warehouse/backend/tests/api/test_saved_query.pyindex e2d8b394a9fa..039d06ff9aad 100644--- a/products/data_warehouse/backend/tests/api/test_saved_query.py+++ b/products/data_warehouse/backend/tests/api/test_saved_query.py@@ -2603,6 +2603,33 @@ class TestSavedQuery(APIBaseTest):node.refresh_from_db()self.assertEqual(suspension_state(node), {})+ def test_resume_with_an_engine_clears_only_that_engine(self):+ saved_query = DataWarehouseSavedQuery.objects.create(+ team=self.team,+ name="suspended_on_both",+ query={"kind": "HogQLQuery", "query": "select event as event from events LIMIT 100"},+ created_by=self.user,+ )+ node = Node.objects.create(+ team=self.team,+ dag=DAG.objects.create(team=self.team, name="dag"),+ saved_query=saved_query,+ type=NodeType.MAT_VIEW,+ )+ for engine in ("clickhouse", "managed_warehouse"):+ mark_node_suspended(node, engine=engine, reason="boom", job_id=str(uuid.uuid4()))+ node.save()++ response = self.client.post(+ f"/api/environments/{self.team.id}/warehouse_saved_queries/{saved_query.id}/resume/",+ {"engine": "trino"},+ )++ self.assertEqual(response.status_code, 200)+ self.assertEqual(response.json(), {"resumed": True})+ node.refresh_from_db()+ self.assertEqual(list(suspension_state(node)), ["clickhouse"])+def test_resume_schedules_clears_suspension_for_every_listed_query(self):saved_queries = [DataWarehouseSavedQuery.objects.create(diff --git a/products/data_warehouse/frontend/generated/api.schemas.ts b/products/data_warehouse/frontend/generated/api.schemas.tsindex 45068ef93678..4e68f4da5895 100644--- a/products/data_warehouse/frontend/generated/api.schemas.ts+++ b/products/data_warehouse/frontend/generated/api.schemas.ts@@ -2171,6 +2171,29 @@ export interface SavedQueryMaterializeApi {sync_frequency?: MaterializeSyncFrequencyEnumApi}+/**+ * * `clickhouse` - ClickHouse+ * * `trino` - Trino+ */+export type MaterializationEngineEnumApi =+ (typeof MaterializationEngineEnumApi)[keyof typeof MaterializationEngineEnumApi]++export const MaterializationEngineEnumApi = {+ Clickhouse: 'clickhouse',+ Trino: 'trino',+} as const++/**+ * Body of the `resume` action.+ */+export interface SavedQueryResumeRequestApi {+ /** Resume only this engine's materialization: 'clickhouse' or 'trino' (the managed warehouse). Omit it to resume every engine the query is suspended on.+ *+ * * `clickhouse` - ClickHouse+ * * `trino` - Trino */+ engine?: MaterializationEngineEnumApi+}+export interface SavedQueryResumeApi {/** False when the query's materialization was not suspended. */resumed: boolean@@ -2188,18 +2211,6 @@ export const MaterializationRunDirectionEnumApi = {Downstream: 'downstream',} as const-/**- * * `clickhouse` - ClickHouse- * * `trino` - Trino- */-export type MaterializationEngineEnumApi =- (typeof MaterializationEngineEnumApi)[keyof typeof MaterializationEngineEnumApi]--export const MaterializationEngineEnumApi = {- Clickhouse: 'clickhouse',- Trino: 'trino',-} as const-/*** Body of the `run` action.*/diff --git a/products/data_warehouse/frontend/generated/api.ts b/products/data_warehouse/frontend/generated/api.tsindex 25ff2921fa40..345c450ec718 100644--- a/products/data_warehouse/frontend/generated/api.ts+++ b/products/data_warehouse/frontend/generated/api.ts@@ -84,6 +84,7 @@ import type {SavedQueryLineageRequestApi,SavedQueryMaterializeApi,SavedQueryResumeApi,+ SavedQueryResumeRequestApi,SavedQueryResumeSchedulesRequestApi,SavedQueryRunApi,SavedQueryRunResponseApi,@@ -1872,11 +1873,14 @@ export const getWarehouseSavedQueriesResumeCreateUrl = (projectId: string, id: sexport const warehouseSavedQueriesResumeCreate = async (projectId: string,id: string,+ savedQueryResumeRequestApi?: SavedQueryResumeRequestApi,options?: RequestInit): Promise<SavedQueryResumeApi> => {return apiMutator<SavedQueryResumeApi>(getWarehouseSavedQueriesResumeCreateUrl(projectId, id), {...options,method: 'POST',+ headers: { 'Content-Type': 'application/json', ...options?.headers },+ body: JSON.stringify(savedQueryResumeRequestApi),})}diff --git a/products/data_warehouse/frontend/generated/api.zod.ts b/products/data_warehouse/frontend/generated/api.zod.tsindex 7d2c59f83e8d..15264c7217dd 100644--- a/products/data_warehouse/frontend/generated/api.zod.ts+++ b/products/data_warehouse/frontend/generated/api.zod.ts@@ -905,6 +905,24 @@ export const WarehouseSavedQueriesMaterializeCreateBody = /* @__PURE__ */ zod}).describe('Body of the `materialize` action: which cadence to enable materialization at.')+/**+ * Resume materialization suspended after repeated failures.+ *+ * Scheduled runs skip a suspended model and everything downstream of it, so it cannot succeed+ * its way back on its own.+ */+export const WarehouseSavedQueriesResumeCreateBody = /* @__PURE__ */ zod+ .object({+ engine: zod+ .enum(['clickhouse', 'trino'])+ .describe('\* `clickhouse` - ClickHouse\n\* `trino` - Trino')+ .optional()+ .describe(+ "Resume only this engine's materialization: 'clickhouse' or 'trino' (the managed warehouse). Omit it to resume every engine the query is suspended on.\n\n\* `clickhouse` - ClickHouse\n\* `trino` - Trino"+ ),+ })+ .describe('Body of the `resume` action.')+/*** Undo materialization, revert back to the original view.* (i.e. delete the materialized table and the schedule)diff --git a/products/data_warehouse/mcp/tools.yaml b/products/data_warehouse/mcp/tools.yamlindex 7adbbd89d8a1..a5cd64832dc7 100644--- a/products/data_warehouse/mcp/tools.yaml+++ b/products/data_warehouse/mcp/tools.yaml@@ -269,6 +269,23 @@ tools:rejected when the view's lineage cannot support it: no more often than its sources deliver new data, and noless often than a downstream view or endpoint needs. Materialized views are faster to query but use storage.Use 'view-unmaterialize' to undo. Rate limited.+ view-resume:+ operation: warehouse_saved_queries_resume_create+ enabled: true+ scopes:+ - warehouse_view:write+ annotations:+ readOnly: false+ destructive: false+ idempotent: true+ enrich_url: ?open_view={params.id}+ title: Resume suspended materialization+ description: >+ Resume a saved query whose materialization was suspended after repeated failures. Scheduled runs skip a+ suspended view and everything downstream of it until it is resumed. Set engine to 'clickhouse' or 'trino' to+ resume only that engine; omit it to resume all. The view runs again at its next scheduled run; use+ 'view-run' to run it now. Returns resumed=false when the view was not suspended. Check the 'suspended' field+ from 'view-get' to see which engines are suspended and why.view-run:operation: warehouse_saved_queries_run_createenabled: truediff --git a/services/mcp/schema/generated-tool-definitions.json b/services/mcp/schema/generated-tool-definitions.jsonindex e347faabb27f..5d9c106119de 100644--- a/services/mcp/schema/generated-tool-definitions.json+++ b/services/mcp/schema/generated-tool-definitions.json@@ -15121,6 +15121,21 @@"readOnlyHint": false}},+ "view-resume": {+ "description": "Resume a saved query whose materialization was suspended after repeated failures. Scheduled runs skip a suspended view and everything downstream of it until it is resumed. Set engine to 'clickhouse' or 'trino' to resume only that engine; omit it to resume all. The view runs again at its next scheduled run; use 'view-run' to run it now. Returns resumed=false when the view was not suspended. Check the 'suspended' field from 'view-get' to see which engines are suspended and why.",+ "category": "Data warehouse",+ "feature": "data_warehouse",+ "summary": "Resume suspended materialization",+ "title": "Resume suspended materialization",+ "required_scopes": ["warehouse_view:write"],+ "api_operations": ["POST /api/projects/{project_id}/warehouse_saved_queries/{id}/resume/"],+ "annotations": {+ "destructiveHint": false,+ "idempotentHint": true,+ "openWorldHint": true,+ "readOnlyHint": false+ }+ },"view-run": {"description": "Trigger a manual materialization run for a saved query. By default, this refreshes only the selected view. Set direction to upstream to also run all dependencies. Set direction to downstream to also run all dependents. Both options include the selected view and run the views in dependency order. Do not set full_refresh when you set direction. Use 'view-run-history' to check each view's status.","category": "Data warehouse",diff --git a/services/mcp/schema/tool-definitions-all.json b/services/mcp/schema/tool-definitions-all.jsonindex d475a22f625f..de6f2e0a0dd1 100644--- a/services/mcp/schema/tool-definitions-all.json+++ b/services/mcp/schema/tool-definitions-all.json@@ -15897,6 +15897,21 @@"readOnlyHint": false}},+ "view-resume": {+ "description": "Resume a saved query whose materialization was suspended after repeated failures. Scheduled runs skip a suspended view and everything downstream of it until it is resumed. Set engine to 'clickhouse' or 'trino' to resume only that engine; omit it to resume all. The view runs again at its next scheduled run; use 'view-run' to run it now. Returns resumed=false when the view was not suspended. Check the 'suspended' field from 'view-get' to see which engines are suspended and why.",+ "category": "Data warehouse",+ "feature": "data_warehouse",+ "summary": "Resume suspended materialization",+ "title": "Resume suspended materialization",+ "required_scopes": ["warehouse_view:write"],+ "api_operations": ["POST /api/projects/{project_id}/warehouse_saved_queries/{id}/resume/"],+ "annotations": {+ "destructiveHint": false,+ "idempotentHint": true,+ "openWorldHint": true,+ "readOnlyHint": false+ }+ },"view-run": {"description": "Trigger a manual materialization run for a saved query. By default, this refreshes only the selected view. Set direction to upstream to also run all dependencies. Set direction to downstream to also run all dependents. Both options include the selected view and run the views in dependency order. Do not set full_refresh when you set direction. Use 'view-run-history' to check each view's status.","category": "Data warehouse",diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex 0986b8e912a3..0bcd2617d3e1 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -107953,6 +107953,17 @@ export namespace Schemas {resumed: boolean;}+ /**+ * Body of the `resume` action.+ */+ export interface SavedQueryResumeRequest {+ /** Resume only this engine's materialization: 'clickhouse' or 'trino' (the managed warehouse). Omit it to resume every engine the query is suspended on.+ *+ * * `clickhouse` - ClickHouse+ * * `trino` - Trino */+ engine?: MaterializationEngineEnum;+ }+/*** Body of the `resume_schedules` action.*/diff --git a/services/mcp/src/generated/data_warehouse/api.ts b/services/mcp/src/generated/data_warehouse/api.tsindex c1a9bf84a574..ae3e868fa95c 100644--- a/services/mcp/src/generated/data_warehouse/api.ts+++ b/services/mcp/src/generated/data_warehouse/api.ts@@ -3,7 +3,7 @@* MCP service uses these Zod schemas for generated tool handlers.* To regenerate: hogli build:openapi*- * PostHog API - MCP 24 enabled ops+ * PostHog API - MCP 25 enabled ops* OpenAPI spec version: 1.0.0*/import * as zod from 'zod'@@ -615,6 +615,33 @@ export const WarehouseSavedQueriesMaterializeCreateBody = () => zod}).describe('Body of the `materialize` action: which cadence to enable materialization at.')+/**+ * Resume materialization suspended after repeated failures.+ *+ * Scheduled runs skip a suspended model and everything downstream of it, so it cannot succeed+ * its way back on its own.+ */+export const WarehouseSavedQueriesResumeCreateParams = () => zod.object({+ id: zod.string().describe('A UUID string identifying this data warehouse saved query.'),+ 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\/."+ ),+})++export const WarehouseSavedQueriesResumeCreateBody = () => zod+ .object({+ engine: zod+ .enum(['clickhouse', 'trino'])+ .describe('\* `clickhouse` - ClickHouse\n\* `trino` - Trino')+ .optional()+ .describe(+ "Resume only this engine's materialization: 'clickhouse' or 'trino' (the managed warehouse). Omit it to resume every engine the query is suspended on.\n\n\* `clickhouse` - ClickHouse\n\* `trino` - Trino"+ ),+ })+ .describe('Body of the `resume` action.')+/*** Undo materialization, revert back to the original view.* (i.e. delete the materialized table and the schedule)diff --git a/services/mcp/src/tools/generated/data_warehouse.ts b/services/mcp/src/tools/generated/data_warehouse.tsindex 6365d236d25e..2466a4814fb0 100644--- a/services/mcp/src/tools/generated/data_warehouse.ts+++ b/services/mcp/src/tools/generated/data_warehouse.ts@@ -457,6 +457,32 @@ const viewMaterialize = (): ToolBase<ReturnType<typeof ViewMaterializeSchema>, u},})+const ViewResumeSchema = () => {+ const WarehouseSavedQueriesResumeCreateBody = orvalSchemas.WarehouseSavedQueriesResumeCreateBody()+ const WarehouseSavedQueriesResumeCreateParams = orvalSchemas.WarehouseSavedQueriesResumeCreateParams()+ return WarehouseSavedQueriesResumeCreateParams.omit({ project_id: true }).extend(+ WarehouseSavedQueriesResumeCreateBody.shape+ )+}++const viewResume = (): ToolBase<ReturnType<typeof ViewResumeSchema>, WithPostHogUrl<Schemas.SavedQueryResume>> => ({+ name: 'view-resume',+ schema: ViewResumeSchema(),+ handler: async (context: Context, params: z.infer<ReturnType<typeof ViewResumeSchema>>) => {+ const projectId = await context.stateManager.getProjectId()+ const body: Record<string, unknown> = {}+ if (params.engine !== undefined) {+ body['engine'] = params.engine+ }+ const result = await context.api.request<Schemas.SavedQueryResume>({+ method: 'POST',+ path: `/api/projects/${encodeURIComponent(String(projectId))}/warehouse_saved_queries/${encodeURIComponent(String(params.id))}/resume/`,+ body,+ })+ return await withPostHogUrl(context, result, `/sql?open_view=${params.id}`)+ },+})+const ViewRunSchema = () => {const WarehouseSavedQueriesRunCreateBody = orvalSchemas.WarehouseSavedQueriesRunCreateBody()const WarehouseSavedQueriesRunCreateParams = orvalSchemas.WarehouseSavedQueriesRunCreateParams()@@ -823,6 +849,7 @@ export const GENERATED_TOOLS: Record<string, () => ToolBase<ZodObjectAny>> = {'view-get': viewGet,'view-list': viewList,'view-materialize': viewMaterialize,+ 'view-resume': viewResume,'view-run': viewRun,'view-run-history': viewRunHistory,'view-unmaterialize': viewUnmaterialize,diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/view-resume.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/view-resume.jsonnew file mode 100644index 000000000000..01af5e1285c4--- /dev/null+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/view-resume.json@@ -0,0 +1,16 @@+{+ "$schema": "https://json-schema.org/draft/2020-12/schema",+ "properties": {+ "engine": {+ "description": "Resume only this engine's materialization: 'clickhouse' or 'trino' (the managed warehouse). Omit it to resume every engine the query is suspended on.\n\n* `clickhouse` - ClickHouse\n* `trino` - Trino",+ "enum": ["clickhouse", "trino"],+ "type": "string"+ },+ "id": {+ "description": "A UUID string identifying this data warehouse saved query.",+ "type": "string"+ }+ },+ "required": ["id"],+ "type": "object"+}