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(data-modeling): record skipped runs when an upstream view fails (#79751)

Jovan Sakovic65463661bf86
diff --git a/frontend/src/scenes/data-warehouse/saved_queries/MaterializationStatusPanel.tsx b/frontend/src/scenes/data-warehouse/saved_queries/MaterializationStatusPanel.tsx
index c443d0a88d37..25159fcad0bc 100644
--- a/frontend/src/scenes/data-warehouse/saved_queries/MaterializationStatusPanel.tsx
+++ b/frontend/src/scenes/data-warehouse/saved_queries/MaterializationStatusPanel.tsx
@@ -386,6 +386,7 @@ export function MaterializationStatusPanel({ viewId, kind = 'view' }: Materializ
Completed: 'success',
Failed: 'danger',
Running: 'warning',
+ Skipped: 'muted',
}
const type = statusToType[status] || 'warning'
@@ -424,7 +425,8 @@ export function MaterializationStatusPanel({ viewId, kind = 'view' }: Materializ
title: 'Rows',
dataIndex: 'rows_materialized',
render: (_, { rows_materialized, status }: DataModelingJob) =>
- (status === 'Running' || status === 'Cancelled') && rows_materialized === 0
+ (status === 'Running' || status === 'Cancelled' || status === 'Skipped') &&
+ rows_materialized === 0
? '~'
: humanFriendlyNumber(rows_materialized),
},
diff --git a/frontend/src/scenes/data-warehouse/saved_queries/materializationJobsLogic.ts b/frontend/src/scenes/data-warehouse/saved_queries/materializationJobsLogic.ts
index f3e994633680..2cc96c5362af 100644
--- a/frontend/src/scenes/data-warehouse/saved_queries/materializationJobsLogic.ts
+++ b/frontend/src/scenes/data-warehouse/saved_queries/materializationJobsLogic.ts
@@ -227,7 +227,7 @@ export const materializationJobsLogic = kea<materializationJobsLogicType>([
const currentJobStatus = dataModelingJobs?.results?.[0]?.status
if (
currentJobStatus &&
- ['Running', 'Completed', 'Failed', 'Cancelled'].includes(currentJobStatus)
+ ['Running', 'Completed', 'Failed', 'Cancelled', 'Skipped'].includes(currentJobStatus)
) {
return false
}
diff --git a/frontend/src/types.ts b/frontend/src/types.ts
index 34452449e95c..2b163978349f 100644
--- a/frontend/src/types.ts
+++ b/frontend/src/types.ts
@@ -6088,7 +6088,7 @@ export interface DataWarehouseTable {
export type DataWarehouseTableTypes = 'CSV' | 'Parquet' | 'JSON' | 'CSVWithNames'
-export type DataModelingJobStatus = 'Running' | 'Completed' | 'Failed' | 'Cancelled'
+export type DataModelingJobStatus = 'Running' | 'Completed' | 'Failed' | 'Cancelled' | 'Skipped'
export interface DataWarehouseSavedQueryRunHistory {
status: DataModelingJobStatus
@@ -6335,7 +6335,7 @@ export interface WebhookInfo {
export interface DataModelingJob {
id: string
saved_query_id: string
- status: 'Running' | 'Completed' | 'Failed' | 'Cancelled'
+ status: DataModelingJobStatus
rows_materialized: number
rows_expected: number | null
error: string | null
diff --git a/posthog/tasks/test/test_email.py b/posthog/tasks/test/test_email.py
index 57b3a1266bc7..32568617d225 100644
--- a/posthog/tasks/test/test_email.py
+++ b/posthog/tasks/test/test_email.py
@@ -2111,6 +2111,16 @@ class TestEmail(APIBaseTest, ClickhouseTestMixin):
[("FAILED", dt.timedelta(hours=1), "Some error")],
True,
),
+ (
+ # the broken parent is the one reported; mailing every descendant would bury it
+ "view_blocked_by_a_broken_parent",
+ {"sync_frequency_interval": None},
+ [
+ ("FAILED", dt.timedelta(hours=3), "Some error"),
+ ("SKIPPED", dt.timedelta(hours=1), "Skipped because upstream view orders_daily is failing."),
+ ],
+ False,
+ ),
]
)
def test_send_matview_failure_digest_scenarios(
diff --git a/posthog/temporal/data_modeling/__init__.py b/posthog/temporal/data_modeling/__init__.py
index 918a8a321a8b..8dbdda449d5b 100644
--- a/posthog/temporal/data_modeling/__init__.py
+++ b/posthog/temporal/data_modeling/__init__.py
@@ -8,6 +8,7 @@ from posthog.temporal.data_modeling.activities import (
materialize_view_duckgres_activity,
preempt_dag_run_activity,
prepare_queryable_table_activity,
+ record_skipped_data_modeling_jobs_activity,
succeed_materialization_activity,
)
from posthog.temporal.data_modeling.run_workflow import (
@@ -37,6 +38,7 @@ SEMANTIC_ENRICHMENT_ACTIVITIES = [enrich_view_semantics_activity]
ACTIVITIES = [
check_duckgres_shadow_enabled_activity,
create_data_modeling_job_activity,
+ record_skipped_data_modeling_jobs_activity,
get_dag_structure_activity,
fail_materialization_activity,
materialize_view_activity,
diff --git a/posthog/temporal/data_modeling/activities/__init__.py b/posthog/temporal/data_modeling/activities/__init__.py
index 7fd3f93488ba..fcc455e7e2e0 100644
--- a/posthog/temporal/data_modeling/activities/__init__.py
+++ b/posthog/temporal/data_modeling/activities/__init__.py
@@ -1,4 +1,11 @@
-from .create_data_modeling_job import CreateDataModelingJobInputs, create_data_modeling_job_activity
+from .create_data_modeling_job import (
+ UPSTREAM_NAMES_IN_SKIP_REASON,
+ CreateDataModelingJobInputs,
+ RecordSkippedDataModelingJobsInputs,
+ SkippedDataModelingNode,
+ create_data_modeling_job_activity,
+ record_skipped_data_modeling_jobs_activity,
+)
from .enrich_view_semantics import EnrichViewSemanticsInputs, enrich_view_semantics_activity
from .fail_materialization import FailMaterializationInputs, fail_materialization_activity
from .get_dag_structure import GetDAGStructureInputs, get_dag_structure_activity
@@ -22,7 +29,10 @@ from .succeed_materialization import (
)
__all__ = [
+ "UPSTREAM_NAMES_IN_SKIP_REASON",
"CreateDataModelingJobInputs",
+ "RecordSkippedDataModelingJobsInputs",
+ "SkippedDataModelingNode",
"EnrichViewSemanticsInputs",
"DuckgresShadowInputs",
"DuckgresShadowResult",
@@ -37,6 +47,7 @@ __all__ = [
"SucceedMaterializationResult",
"check_duckgres_shadow_enabled_activity",
"create_data_modeling_job_activity",
+ "record_skipped_data_modeling_jobs_activity",
"enrich_view_semantics_activity",
"fail_materialization_activity",
"materialize_view_activity",
diff --git a/posthog/temporal/data_modeling/activities/create_data_modeling_job.py b/posthog/temporal/data_modeling/activities/create_data_modeling_job.py
index 586bf9dd03d8..fb5f4b0c974c 100644
--- a/posthog/temporal/data_modeling/activities/create_data_modeling_job.py
+++ b/posthog/temporal/data_modeling/activities/create_data_modeling_job.py
@@ -27,6 +27,29 @@ class CreatedDataModelingJob:
saved_query_id: str | None
+UPSTREAM_NAMES_IN_SKIP_REASON = 3
+
+
[email protected](frozen=True, kw_only=True)
+class SkippedDataModelingNode:
+ node_id: str
+ # Only the ids the reason can name, plus how many there were. A node in a dense graph can
+ # sit downstream of hundreds of broken ancestors, and the whole payload has to fit in one
+ # Temporal activity argument.
+ failed_upstream_node_ids: list[str] = dataclasses.field(default_factory=list)
+ failed_upstream_total: int = 0
+ suspended_upstream_node_ids: list[str] = dataclasses.field(default_factory=list)
+ suspended_upstream_total: int = 0
+
+
[email protected](frozen=True, kw_only=True)
+class RecordSkippedDataModelingJobsInputs:
+ team_id: int
+ dag_id: str
+ engine: str
+ skipped_nodes: list[SkippedDataModelingNode]
+
+
@database_sync_to_async_pool
def _create_data_modeling_job(
inputs: CreateDataModelingJobInputs, workflow_id: str, workflow_run_id: str
@@ -68,3 +91,95 @@ async def create_data_modeling_job_activity(inputs: CreateDataModelingJobInputs)
bind_data_modeling_log_context(inputs.team_id, created.saved_query_id)
await logger.ainfo(f"Created DataModelingJob {created.job_id} for node {inputs.node_id}")
return created.job_id
+
+
+def _subject(names: list[str], total: int) -> str:
+ """Name at most three upstreams and count the rest, so one broken source feeding a wide
+ graph stays readable. Names can be missing if a node was deleted mid-run; the count still
+ tells the truth about how many blocked this one."""
+ shown = names[:UPSTREAM_NAMES_IN_SKIP_REASON]
+ if not shown:
+ return "an upstream view" if total <= 1 else f"{total} upstream views"
+ noun = "upstream view" if total == 1 else "upstream views"
+ extra = total - len(shown)
+ if extra > 0:
+ return f"{noun} {', '.join(shown)} and {extra} more"
+ if len(shown) > 1:
+ return f"{noun} {', '.join(shown[:-1])} and {shown[-1]}"
+ return f"{noun} {shown[0]}"
+
+
+def _skip_reason(*, failed: list[str], failed_total: int, suspended: list[str], suspended_total: int) -> str:
+ if failed_total and suspended_total:
+ subject = _subject(failed + suspended, failed_total + suspended_total)
+ return f"Skipped because {subject} are failing or paused."
+ if failed_total:
+ verb = "is" if failed_total == 1 else "are"
+ return f"Skipped because {_subject(failed, failed_total)} {verb} failing."
+ if suspended_total:
+ verb = "was" if suspended_total == 1 else "were"
+ return f"Skipped because {_subject(suspended, suspended_total)} {verb} paused after repeated failures."
+ return "Skipped because an upstream view failed."
+
+
+@database_sync_to_async_pool
+def _record_skipped_data_modeling_jobs(
+ inputs: RecordSkippedDataModelingJobsInputs, workflow_id: str, workflow_run_id: str
+) -> None:
+ node_ids = {skipped.node_id for skipped in inputs.skipped_nodes} | {
+ upstream_id
+ for skipped in inputs.skipped_nodes
+ for upstream_id in skipped.failed_upstream_node_ids + skipped.suspended_upstream_node_ids
+ }
+ nodes = {
+ str(node.id): node
+ for node in Node.objects.filter(team_id=inputs.team_id, dag_id=inputs.dag_id, id__in=node_ids).select_related(
+ "saved_query"
+ )
+ }
+ skipped_nodes = [nodes[skipped.node_id] for skipped in inputs.skipped_nodes if skipped.node_id in nodes]
+ saved_query_ids = {node.saved_query_id for node in skipped_nodes if node.saved_query_id is not None}
+ existing_saved_query_ids = set(
+ DataModelingJob.objects.filter(
+ team_id=inputs.team_id,
+ engine=inputs.engine,
+ parent_workflow_id=workflow_id,
+ saved_query_id__in=saved_query_ids,
+ ).values_list("saved_query_id", flat=True)
+ )
+
+ jobs = []
+ for skipped in inputs.skipped_nodes:
+ node = nodes.get(skipped.node_id)
+ if node is None or node.saved_query_id is None or node.saved_query_id in existing_saved_query_ids:
+ continue
+ jobs.append(
+ DataModelingJob(
+ team_id=inputs.team_id,
+ saved_query_id=node.saved_query_id,
+ status=DataModelingJob.Status.SKIPPED,
+ engine=inputs.engine,
+ rows_materialized=0,
+ error=_skip_reason(
+ failed=[nodes[i].name for i in skipped.failed_upstream_node_ids if i in nodes],
+ failed_total=skipped.failed_upstream_total,
+ suspended=[nodes[i].name for i in skipped.suspended_upstream_node_ids if i in nodes],
+ suspended_total=skipped.suspended_upstream_total,
+ ),
+ workflow_id=workflow_id,
+ workflow_run_id=workflow_run_id,
+ parent_workflow_id=workflow_id,
+ created_by_id=node.saved_query.created_by_id if node.saved_query else None,
+ )
+ )
+ existing_saved_query_ids.add(node.saved_query_id)
+ DataModelingJob.objects.bulk_create(jobs)
+
+
+async def record_skipped_data_modeling_jobs_activity(inputs: RecordSkippedDataModelingJobsInputs) -> None:
+ workflow_id = activity.info().workflow_id
+ workflow_run_id = activity.info().workflow_run_id
+ assert workflow_id
+ assert workflow_run_id
+ await _record_skipped_data_modeling_jobs(inputs, workflow_id, workflow_run_id)
diff --git a/posthog/temporal/data_modeling/activities/fail_materialization.py b/posthog/temporal/data_modeling/activities/fail_materialization.py
index 889145c10b46..a3376a7418a1 100644
--- a/posthog/temporal/data_modeling/activities/fail_materialization.py
+++ b/posthog/temporal/data_modeling/activities/fail_materialization.py
@@ -43,6 +43,9 @@ def _get_previous_jobs(saved_query_id: UUID, current_job_id: UUID, count: int) -
return (
DataModelingJob.objects.filter(saved_query_id=saved_query_id, engine=DataModelingJobEngine.CLICKHOUSE)
.exclude(id=current_job_id)
+ # a skipped run never executed, so it is evidence of neither health nor failure. Leaving it
+ # in lets one upstream outage clear a timeout streak that is about to pause the schedule.
+ .exclude(status=DataModelingJobStatus.SKIPPED)
.order_by("-created_at")[:count]
)
diff --git a/posthog/temporal/data_modeling/activities/utils.py b/posthog/temporal/data_modeling/activities/utils.py
index a4dac623ea2e..77d65c1476c6 100644
--- a/posthog/temporal/data_modeling/activities/utils.py
+++ b/posthog/temporal/data_modeling/activities/utils.py
@@ -102,7 +102,11 @@ def update_node_system_properties(
def _count_leading_failures(saved_query_id: UUID, engine: str, *, since: str | None = None) -> int:
- jobs = DataModelingJob.objects.filter(saved_query_id=saved_query_id, engine=str(engine))
+ jobs = DataModelingJob.objects.filter(saved_query_id=saved_query_id, engine=str(engine)).exclude(
+ # a skipped node never ran, so it is evidence of neither health nor failure. Counting it
+ # either way lets an upstream outage decide whether a broken node ever gets suspended.
+ status=DataModelingJobStatus.SKIPPED
+ )
if since is not None:
# Otherwise the failures that caused the suspension are still the most recent jobs, and one
# new failure re-suspends the node we just resumed.
diff --git a/posthog/temporal/data_modeling/workflows/execute_dag.py b/posthog/temporal/data_modeling/workflows/execute_dag.py
index a0a5491da09d..b8832b8b9a7c 100644
--- a/posthog/temporal/data_modeling/workflows/execute_dag.py
+++ b/posthog/temporal/data_modeling/workflows/execute_dag.py
@@ -12,10 +12,14 @@ from temporalio.workflow import ParentClosePolicy
from posthog.exceptions_capture import capture_exception
from posthog.temporal.common.base import PostHogWorkflow
from posthog.temporal.data_modeling.activities import (
+ UPSTREAM_NAMES_IN_SKIP_REASON,
GetDAGStructureInputs,
PreemptDAGRunInputs,
+ RecordSkippedDataModelingJobsInputs,
+ SkippedDataModelingNode,
get_dag_structure_activity,
preempt_dag_run_activity,
+ record_skipped_data_modeling_jobs_activity,
)
from posthog.temporal.data_modeling.activities.utils import strip_hostname_from_error
from posthog.temporal.data_modeling.metrics import (
@@ -273,6 +277,7 @@ class ExecuteDAGWorkflow(PostHogWorkflow):
).value
suspended_node_set: set[str] = set(dag_structure.suspended_nodes.get(serving_engine, []))
downstreams = _get_downstream_lookup(edge_lookup)
+ skipped_jobs: list[SkippedDataModelingNode] = []
# execute child workflows with bounded concurrency using a sliding window;
# the semaphore limits how many child workflows run simultaneously across
# all levels to be a friendlier neighbor to duckgres and clickhouse infrastructure
@@ -285,23 +290,39 @@ class ExecuteDAGWorkflow(PostHogWorkflow):
execute_nodes = []
skip_nodes = []
ephemeral_nodes = []
- # failed_node_set only grows between levels, so the blocked set is stable within one
- blocked_node_set = failed_node_set | suspended_node_set
for node_id in level:
should_skip = False
skip_reason = None
+ failed_upstream: list[str] = []
+ suspended_upstream: list[str] = []
if node_id in suspended_node_set:
+ # a node paused for its own failures keeps its Failed job as the latest one, which
+ # is what the resume banner and the failure digest both read
should_skip = True
skip_reason = "Node suspended after repeated materialization failures"
else:
- for blocked_id in blocked_node_set:
- if node_id in downstreams[blocked_id]:
+ for blocked_id in sorted(failed_node_set) + sorted(suspended_node_set):
+ if node_id not in downstreams[blocked_id]:
+ continue
+ suspended = blocked_id in suspended_node_set
+ if blocked_id in (suspended_upstream if suspended else failed_upstream):
+ continue
+ (suspended_upstream if suspended else failed_upstream).append(blocked_id)
+ if not should_skip:
should_skip = True
- verb = "suspended" if blocked_id in suspended_node_set else "failed"
- skip_reason = f"Upstream node {blocked_id} {verb}"
- break
+ skip_reason = f"Upstream node {blocked_id} {'suspended' if suspended else 'failed'}"
if should_skip:
skip_nodes.append((node_id, skip_reason))
+ if node_id not in ephemeral_node_set and (failed_upstream or suspended_upstream):
+ skipped_jobs.append(
+ SkippedDataModelingNode(
+ node_id=node_id,
+ failed_upstream_node_ids=failed_upstream[:UPSTREAM_NAMES_IN_SKIP_REASON],
+ failed_upstream_total=len(failed_upstream),
+ suspended_upstream_node_ids=suspended_upstream[:UPSTREAM_NAMES_IN_SKIP_REASON],
+ suspended_upstream_total=len(suspended_upstream),
+ )
+ )
elif node_id in ephemeral_node_set:
ephemeral_nodes.append(node_id)
else:
@@ -390,6 +411,21 @@ class ExecuteDAGWorkflow(PostHogWorkflow):
if not nr.success:
failed_node_set.add(nr.node_id)
+ # Safe to add without a workflow patch: this is the last command before the workflow
+ # returns, so a replayed history either stops short of it or has already completed.
+ if skipped_jobs:
+ await temporalio.workflow.execute_activity(
+ record_skipped_data_modeling_jobs_activity,
+ RecordSkippedDataModelingJobsInputs(
+ team_id=inputs.team_id,
+ dag_id=inputs.dag_id,
+ engine=serving_engine,
+ skipped_nodes=skipped_jobs,
+ ),
+ start_to_close_timeout=dt.timedelta(minutes=5),
+ retry_policy=temporalio.common.RetryPolicy(maximum_attempts=3),
+ )
+
# compute summary
end_time = temporalio.workflow.now()
duration_seconds = (end_time - start_time).total_seconds()
diff --git a/posthog/temporal/tests/data_modeling/test_execute_dag_workflow.py b/posthog/temporal/tests/data_modeling/test_execute_dag_workflow.py
index 6933819cadfd..2aa2d48eb2d0 100644
--- a/posthog/temporal/tests/data_modeling/test_execute_dag_workflow.py
+++ b/posthog/temporal/tests/data_modeling/test_execute_dag_workflow.py
@@ -17,6 +17,7 @@ from posthog.sync import database_sync_to_async
from posthog.temporal.data_modeling.activities import (
GetDAGStructureInputs,
PreemptDAGRunInputs,
+ RecordSkippedDataModelingJobsInputs,
get_dag_structure_activity,
)
from posthog.temporal.data_modeling.activities.get_dag_structure import DAG as DAGPlan
@@ -449,7 +450,7 @@ class TestExecuteDAGWorkflow:
env.client,
task_queue="test-queue",
workflows=[ExecuteDAGWorkflow],
- activities=[stub_preempt_dag_run, stub_get_dag_structure],
+ activities=[stub_preempt_dag_run, stub_get_dag_structure, stub_record_skipped_data_modeling_jobs],
workflow_runner=temporalio.worker.UnsandboxedWorkflowRunner(),
):
result: ExecuteDAGResult = await env.client.execute_workflow(
@@ -468,6 +469,12 @@ class TestExecuteDAGWorkflow:
_mock_workflow_calls: list[str] = []
_mock_workflow_should_fail: set[str] = set()
+_recorded_skipped_nodes: list[RecordSkippedDataModelingJobsInputs] = []
+
+
+@temporal_activity.defn(name="record_skipped_data_modeling_jobs_activity")
+async def stub_record_skipped_data_modeling_jobs(inputs: RecordSkippedDataModelingJobsInputs) -> None:
+ _recorded_skipped_nodes.append(inputs)
@temporal_workflow.defn(name="data-modeling-materialize-view")
@@ -492,9 +499,11 @@ class TestExecuteDAGWorkflowWithMocks:
def reset_mock_state(self):
_mock_workflow_calls.clear()
_mock_workflow_should_fail.clear()
+ _recorded_skipped_nodes.clear()
yield
_mock_workflow_calls.clear()
_mock_workflow_should_fail.clear()
+ _recorded_skipped_nodes.clear()
async def test_skips_downstream_on_failure(self):
"""Test that downstream nodes are skipped when an upstream node fails."""
@@ -519,7 +528,7 @@ class TestExecuteDAGWorkflowWithMocks:
env.client,
task_queue="test-queue",
workflows=[ExecuteDAGWorkflow, MockMaterializeViewWorkflow],
- activities=[stub_preempt_dag_run, stub_get_dag_structure],
+ activities=[stub_preempt_dag_run, stub_get_dag_structure, stub_record_skipped_data_modeling_jobs],
workflow_runner=temporalio.worker.UnsandboxedWorkflowRunner(),
):
result: ExecuteDAGResult = await env.client.execute_workflow(
@@ -537,6 +546,48 @@ class TestExecuteDAGWorkflowWithMocks:
assert node_a_id in _mock_workflow_calls
assert node_b_id not in _mock_workflow_calls
assert node_c_id not in _mock_workflow_calls
+ assert [skipped.node_id for skipped in _recorded_skipped_nodes[0].skipped_nodes] == [node_b_id, node_c_id]
+ assert all(
+ skipped.failed_upstream_node_ids == [node_a_id] for skipped in _recorded_skipped_nodes[0].skipped_nodes
+ )
+
+ async def test_records_every_failed_parent_on_one_skip_row(self):
+ dag_id = "test-dag"
+ node_a_id, node_b_id = sorted([str(uuid.uuid4()), str(uuid.uuid4())])
+ node_c_id = str(uuid.uuid4())
+
+ @temporal_activity.defn(name="get_dag_structure_activity")
+ async def stub_get_dag_structure(_: GetDAGStructureInputs) -> DAGPlan:
+ return DAGPlan(
+ nodes=[node_a_id, node_b_id, node_c_id],
+ executable_nodes=[node_a_id, node_b_id, node_c_id],
+ edges=[(node_a_id, node_c_id), (node_b_id, node_c_id)],
+ )
+
+ _mock_workflow_should_fail.update({node_a_id, node_b_id})
+
+ async with await WorkflowEnvironment.start_time_skipping() as env:
+ async with temporalio.worker.Worker(
+ env.client,
+ task_queue="test-queue",
+ workflows=[ExecuteDAGWorkflow, MockMaterializeViewWorkflow],
+ activities=[stub_preempt_dag_run, stub_get_dag_structure, stub_record_skipped_data_modeling_jobs],
+ workflow_runner=temporalio.worker.UnsandboxedWorkflowRunner(),
+ ):
+ result: ExecuteDAGResult = await env.client.execute_workflow(
+ ExecuteDAGWorkflow.run,
+ ExecuteDAGInputs(team_id=1, dag_id=dag_id),
+ id=f"test-skip-two-parents-{uuid.uuid4()}",
+ task_queue="test-queue",
+ execution_timeout=dt.timedelta(seconds=30),
+ )
+
+ assert result.failed_nodes == 2
+ assert result.skipped_nodes == 1
+ # one row for the child, naming both broken parents rather than an arbitrary one
+ skipped = _recorded_skipped_nodes[0].skipped_nodes
+ assert [s.node_id for s in skipped] == [node_c_id]
+ assert skipped[0].failed_upstream_node_ids == [node_a_id, node_b_id]
async def test_skips_suspended_node_and_downstream(self):
dag_id = "test-dag"
@@ -558,7 +609,7 @@ class TestExecuteDAGWorkflowWithMocks:
env.client,
task_queue="test-queue",
workflows=[ExecuteDAGWorkflow, MockMaterializeViewWorkflow],
- activities=[stub_preempt_dag_run, stub_get_dag_structure],
+ activities=[stub_preempt_dag_run, stub_get_dag_structure, stub_record_skipped_data_modeling_jobs],
workflow_runner=temporalio.worker.UnsandboxedWorkflowRunner(),
):
result: ExecuteDAGResult = await env.client.execute_workflow(
@@ -573,6 +624,10 @@ class TestExecuteDAGWorkflowWithMocks:
assert result.successful_nodes == 0
assert result.failed_nodes == 0
assert _mock_workflow_calls == []
+ # the suspended node itself gets no skip row — its own failures are the story there
+ skipped = _recorded_skipped_nodes[0].skipped_nodes
+ assert [s.node_id for s in skipped] == [node_b_id, node_c_id]
+ assert all(s.suspended_upstream_node_ids == [node_a_id] for s in skipped)
async def test_serving_engine_determines_suspension(self):
dag_id = "test-dag"
@@ -593,7 +648,7 @@ class TestExecuteDAGWorkflowWithMocks:
env.client,
task_queue="test-queue",
workflows=[ExecuteDAGWorkflow, MockMaterializeViewWorkflow],
- activities=[stub_preempt_dag_run, stub_get_dag_structure],
+ activities=[stub_preempt_dag_run, stub_get_dag_structure, stub_record_skipped_data_modeling_jobs],
workflow_runner=temporalio.worker.UnsandboxedWorkflowRunner(),
):
result: ExecuteDAGResult = await env.client.execute_workflow(
@@ -668,7 +723,7 @@ class TestExecuteDAGWorkflowWithMocks:
env.client,
task_queue="test-queue",
workflows=[ExecuteDAGWorkflow, MockMaterializeViewWorkflow],
- activities=[stub_preempt_dag_run, stub_get_dag_structure],
+ activities=[stub_preempt_dag_run, stub_get_dag_structure, stub_record_skipped_data_modeling_jobs],
workflow_runner=temporalio.worker.UnsandboxedWorkflowRunner(),
):
result: ExecuteDAGResult = await env.client.execute_workflow(
diff --git a/posthog/temporal/tests/data_modeling/test_materialize_view_activities.py b/posthog/temporal/tests/data_modeling/test_materialize_view_activities.py
index 072bf64593ab..65e207f893f9 100644
--- a/posthog/temporal/tests/data_modeling/test_materialize_view_activities.py
+++ b/posthog/temporal/tests/data_modeling/test_materialize_view_activities.py
@@ -394,6 +394,46 @@ class TestShouldPauseScheduleForTimeout:
for job in previous_jobs:
await database_sync_to_async(job.delete)()
+ async def test_streak_survives_a_run_skipped_for_an_upstream_failure(self, ateam, asaved_query):
+ from posthog.temporal.data_modeling.activities.fail_materialization import should_pause_schedule_for_timeout
+
+ previous_jobs = []
+ for i in range(5):
+ job = await database_sync_to_async(DataModelingJob.objects.create)(
+ team=ateam,
+ saved_query=asaved_query,
+ status=DataModelingJob.Status.FAILED,
+ error="Timeout exceeded",
+ workflow_id=f"prev-workflow-{i}",
+ )
+ previous_jobs.append(job)
+
+ skipped = await database_sync_to_async(DataModelingJob.objects.create)(
+ team=ateam,
+ saved_query=asaved_query,
+ status=DataModelingJob.Status.SKIPPED,
+ error="Skipped because upstream view orders_daily is failing.",
+ workflow_id="skipped-workflow",
+ )
+ previous_jobs.append(skipped)
+
+ current_job = await database_sync_to_async(DataModelingJob.objects.create)(
+ team=ateam,
+ saved_query=asaved_query,
+ status=DataModelingJob.Status.RUNNING,
+ workflow_id="current-workflow",
+ )
+
+ should_pause, count = await database_sync_to_async(should_pause_schedule_for_timeout)(
+ asaved_query.id, current_job.id
+ )
+ assert should_pause is True
+ assert count == 5
+
+ await database_sync_to_async(current_job.delete)()
+ for job in previous_jobs:
+ await database_sync_to_async(job.delete)()
+
async def test_streak_ignores_jobs_from_other_engines(self, ateam, asaved_query):
from posthog.temporal.data_modeling.activities.fail_materialization import should_pause_schedule_for_timeout
@@ -519,6 +559,40 @@ class TestNodeSuspension:
for job in jobs:
await database_sync_to_async(job.delete)()
+ async def test_skipped_runs_do_not_break_the_failure_streak(self, ateam, anode, asaved_query, adag):
+ from posthog.temporal.data_modeling.activities.utils import (
+ CONSECUTIVE_FAILURES_TO_SUSPEND,
+ is_node_suspended,
+ maybe_suspend_node_for_engine,
+ )
+
+ jobs = [
+ await _make_job(ateam, asaved_query, DataModelingJob.Status.FAILED, error="boom")
+ for _ in range(CONSECUTIVE_FAILURES_TO_SUSPEND - 1)
+ ]
+ # an upstream failure parks this node for one run; it never got to succeed
+ jobs.append(await _make_job(ateam, asaved_query, DataModelingJob.Status.SKIPPED, error="upstream failed"))
+ job = await _make_job(ateam, asaved_query, DataModelingJob.Status.FAILED, error="boom")
+ jobs.append(job)
+
+ suspended = await maybe_suspend_node_for_engine(
+ node_id=str(anode.id),
+ team_id=ateam.pk,
+ dag_id=str(adag.id),
+ saved_query_id=asaved_query.id,
+ engine=DataModelingJobEngine.CLICKHOUSE,
+ reason="boom",
+ job_id=str(job.id),
+ )
+
+ assert suspended is True
+ await database_sync_to_async(anode.refresh_from_db)()
+ assert is_node_suspended(anode, DataModelingJobEngine.CLICKHOUSE) is True
+
+ # DataModelingJob.team is SET_NULL, so it survives the ateam fixture's team teardown.
+ for j in jobs:
+ await database_sync_to_async(j.delete)()
+
async def test_does_not_resuspend_on_failures_from_before_a_resume(self, ateam, anode, asaved_query, adag):
from posthog.temporal.data_modeling.activities.utils import is_node_suspended, maybe_suspend_node_for_engine
diff --git a/posthog/temporal/tests/data_modeling/test_record_skipped_jobs.py b/posthog/temporal/tests/data_modeling/test_record_skipped_jobs.py
new file mode 100644
index 000000000000..aba5432dea79
--- /dev/null
+++ b/posthog/temporal/tests/data_modeling/test_record_skipped_jobs.py
@@ -0,0 +1,127 @@
+import dataclasses
+
+import pytest
+
+import pytest_asyncio
+from temporalio.testing import ActivityEnvironment
+
+from posthog.sync import database_sync_to_async
+from posthog.temporal.data_modeling.activities.create_data_modeling_job import (
+ RecordSkippedDataModelingJobsInputs,
+ SkippedDataModelingNode,
+ record_skipped_data_modeling_jobs_activity,
+)
+
+from products.data_modeling.backend.facade.models import (
+ DAG,
+ DataModelingJob,
+ DataModelingJobEngine,
+ DataModelingJobStatus,
+ DataWarehouseSavedQuery,
+ Node,
+ NodeType,
+)
+
+pytestmark = [pytest.mark.asyncio, pytest.mark.django_db]
+
+WORKFLOW_ID = "execute-dag-019e4b57-31b8-7c8a-9d0e-5edaf66fa0ca:900-2026-08-07T11:17:00Z"
+
+
+async def _make_node(team, dag, name):
+ saved_query = await database_sync_to_async(DataWarehouseSavedQuery.objects.create)(
+ team=team, name=name, query={"query": "SELECT 1", "kind": "HogQLQuery"}
+ )
+ node = await database_sync_to_async(Node.objects.create)(
+ team=team, saved_query=saved_query, dag=dag, name=name, type=NodeType.MAT_VIEW
+ )
+ return node, saved_query
+
+
+async def _run(team, dag, skipped_nodes):
+ env = ActivityEnvironment()
+ env.info = dataclasses.replace(env.info, workflow_id=WORKFLOW_ID, workflow_run_id="run-1")
+ await env.run(
+ record_skipped_data_modeling_jobs_activity,
+ RecordSkippedDataModelingJobsInputs(
+ team_id=team.pk,
+ dag_id=str(dag.id),
+ engine=DataModelingJobEngine.CLICKHOUSE,
+ skipped_nodes=skipped_nodes,
+ ),
+ )
+
+
+@pytest_asyncio.fixture
+async def adag_local(ateam):
+ dag = await database_sync_to_async(DAG.objects.create)(team=ateam, name="skip-test-dag")
+ yield dag
+ await database_sync_to_async(dag.delete)()
+
+
+class TestRecordSkippedDataModelingJobs:
+ async def test_writes_a_skip_row_naming_every_blocking_upstream(self, ateam, adag_local):
+ blocked, blocked_query = await _make_node(ateam, adag_local, "rollup_daily")
+ parent_a, _ = await _make_node(ateam, adag_local, "orders_daily")
+ parent_b, _ = await _make_node(ateam, adag_local, "customers_daily")
+
+ await _run(
+ ateam,
+ adag_local,
+ [
+ SkippedDataModelingNode(
+ node_id=str(blocked.id),
+ failed_upstream_node_ids=[str(parent_a.id), str(parent_b.id)],
+ failed_upstream_total=2,
+ )
+ ],
+ )
+
+ job = await database_sync_to_async(
+ lambda: DataModelingJob.objects.filter(saved_query_id=blocked_query.id).first()
+ )()
+ assert job is not None
+ assert job.status == DataModelingJobStatus.SKIPPED
+ assert job.rows_materialized == 0
+ assert job.parent_workflow_id == WORKFLOW_ID
+ assert job.error == "Skipped because upstream views orders_daily and customers_daily are failing."
+
+ async def test_counts_the_upstreams_it_cannot_name(self, ateam, adag_local):
+ blocked, blocked_query = await _make_node(ateam, adag_local, "rollup_daily")
+ named = [(await _make_node(ateam, adag_local, f"source_{i}"))[0] for i in range(3)]
+
+ await _run(
+ ateam,
+ adag_local,
+ [
+ SkippedDataModelingNode(
+ node_id=str(blocked.id),
+ failed_upstream_node_ids=[str(n.id) for n in named],
+ failed_upstream_total=17,
+ )
+ ],
+ )
+
+ job = await database_sync_to_async(
+ lambda: DataModelingJob.objects.filter(saved_query_id=blocked_query.id).first()
+ )()
+ assert job is not None
+ assert job.error == "Skipped because upstream views source_0, source_1, source_2 and 14 more are failing."
+
+ async def test_does_not_write_a_second_row_for_the_same_fire(self, ateam, adag_local):
+ blocked, blocked_query = await _make_node(ateam, adag_local, "rollup_daily")
+ parent, _ = await _make_node(ateam, adag_local, "orders_daily")
+ skipped = [
+ SkippedDataModelingNode(
+ node_id=str(blocked.id),
+ failed_upstream_node_ids=[str(parent.id)],
+ failed_upstream_total=1,
+ )
+ ]
+
+ await _run(ateam, adag_local, skipped)
+ await _run(ateam, adag_local, skipped)
+
+ count = await database_sync_to_async(
+ lambda: DataModelingJob.objects.filter(saved_query_id=blocked_query.id).count()
+ )()
+ assert count == 1
diff --git a/products/data_modeling/backend/logic/tier_run_report.py b/products/data_modeling/backend/logic/tier_run_report.py
index 02c07aca612d..39e0ac0e3e92 100644
--- a/products/data_modeling/backend/logic/tier_run_report.py
+++ b/products/data_modeling/backend/logic/tier_run_report.py
@@ -61,6 +61,7 @@ _JOB_STATUS_TO_NODE_STATUS = {
DataModelingJobStatus.FAILED.value: FAILED,
DataModelingJobStatus.RUNNING.value: RUNNING,
DataModelingJobStatus.CANCELLED.value: CANCELLED,
+ DataModelingJobStatus.SKIPPED.value: BLOCKED,
}
diff --git a/products/data_modeling/backend/migrations/0029_add_skipped_data_modeling_job_status.py b/products/data_modeling/backend/migrations/0029_add_skipped_data_modeling_job_status.py
new file mode 100644
index 000000000000..0917a0bac7a2
--- /dev/null
+++ b/products/data_modeling/backend/migrations/0029_add_skipped_data_modeling_job_status.py
@@ -0,0 +1,27 @@
+# Generated by Django 5.2.17 on 2026-08-07 12:51
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("data_modeling", "0028_alter_datawarehousemanagedviewset_kind"),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name="datamodelingjob",
+ name="status",
+ field=models.CharField(
+ choices=[
+ ("Cancelled", "Cancelled"),
+ ("Completed", "Completed"),
+ ("Failed", "Failed"),
+ ("Running", "Running"),
+ ("Skipped", "Skipped"),
+ ],
+ default="Running",
+ max_length=400,
+ ),
+ ),
+ ]
diff --git a/products/data_modeling/backend/migrations/max_migration.txt b/products/data_modeling/backend/migrations/max_migration.txt
index 62c0d908a679..040ca7b70b26 100644
--- a/products/data_modeling/backend/migrations/max_migration.txt
+++ b/products/data_modeling/backend/migrations/max_migration.txt
@@ -1 +1 @@
-0028_alter_datawarehousemanagedviewset_kind
+0029_add_skipped_data_modeling_job_status
diff --git a/products/data_modeling/backend/models/data_modeling_job.py b/products/data_modeling/backend/models/data_modeling_job.py
index b3239aa790ee..9dd3a2a75a8d 100644
--- a/products/data_modeling/backend/models/data_modeling_job.py
+++ b/products/data_modeling/backend/models/data_modeling_job.py
@@ -9,6 +9,7 @@ class DataModelingJobStatus(models.TextChoices):
COMPLETED = "Completed", "Completed"
FAILED = "Failed", "Failed"
RUNNING = "Running", "Running"
+ SKIPPED = "Skipped", "Skipped"
class DataModelingJobEngine(models.TextChoices):
diff --git a/products/data_modeling/frontend/lineage/LineageNode.tsx b/products/data_modeling/frontend/lineage/LineageNode.tsx
index 880239844799..bd1af2b5ec44 100644
--- a/products/data_modeling/frontend/lineage/LineageNode.tsx
+++ b/products/data_modeling/frontend/lineage/LineageNode.tsx
@@ -83,6 +83,7 @@ function StatusDot({ status }: { status?: DataModelingJobStatus }): JSX.Element
status === 'Running' && 'bg-warning',
status === 'Failed' && 'bg-danger',
status === 'Cancelled' && 'bg-warning',
+ status === 'Skipped' && 'bg-muted',
!status && 'bg-surface-primary'
)}
/>
diff --git a/products/data_modeling/frontend/lineage/nodeStyles.ts b/products/data_modeling/frontend/lineage/nodeStyles.ts
index 073ffd16f828..dc806506d24b 100644
--- a/products/data_modeling/frontend/lineage/nodeStyles.ts
+++ b/products/data_modeling/frontend/lineage/nodeStyles.ts
@@ -17,5 +17,6 @@ export const STATUS_TAG_SETTINGS: Record<string, LemonTagType> = {
Completed: 'success',
Failed: 'danger',
Cancelled: 'muted',
+ Skipped: 'muted',
Modified: 'warning',
}
diff --git a/products/data_warehouse/backend/presentation/views/data_modeling_job.py b/products/data_warehouse/backend/presentation/views/data_modeling_job.py
index 9f851f704b15..dc6bc52c9029 100644
--- a/products/data_warehouse/backend/presentation/views/data_modeling_job.py
+++ b/products/data_warehouse/backend/presentation/views/data_modeling_job.py
@@ -1,3 +1,5 @@
+from django.db.models import Q
+
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework import pagination, serializers, viewsets
from rest_framework.decorators import action
@@ -96,7 +98,11 @@ class DataModelingJobViewSet(TeamAndOrgViewSetMixin, viewsets.ReadOnlyModelViewS
queryset = (
self.get_queryset()
.exclude(status=DataModelingJob.Status.RUNNING)
- .filter(saved_query_id__isnull=False, workflow_id__startswith="materialize")
+ .filter(saved_query_id__isnull=False)
+ # a skip row is written by the DAG run itself, so it carries the execute-dag id rather
+ # than a materialize one. Matching only materialize hides the skip and leaves the last
+ # successful run standing as "last run" for as long as the upstream stays broken.
+ .filter(Q(workflow_id__startswith="materialize") | Q(workflow_id__startswith="execute-dag"))
.order_by("saved_query_id", "-created_at")
.distinct("saved_query_id")
)
diff --git a/products/data_warehouse/backend/tests/api/test_datamodelingjob.py b/products/data_warehouse/backend/tests/api/test_datamodelingjob.py
index 7921b3a849fe..3206e63d7c8a 100644
--- a/products/data_warehouse/backend/tests/api/test_datamodelingjob.py
+++ b/products/data_warehouse/backend/tests/api/test_datamodelingjob.py
@@ -135,6 +135,30 @@ class TestDataModelingJob(APIBaseTest):
second_ids = {job["id"] for job in second_page["results"]}
self.assertEqual(first_ids & second_ids, set())
+ def test_recent_reports_a_skip_over_the_older_success(self):
+ query = DataWarehouseSavedQuery.objects.create(team=self.team, name="Blocked saved query")
+ DataModelingJob.objects.create(
+ team=self.team,
+ saved_query=query,
+ status=DataModelingJob.Status.COMPLETED,
+ workflow_id="materialize-view-abc",
+ last_run_at=timezone.now(),
+ )
+ skipped = DataModelingJob.objects.create(
+ team=self.team,
+ saved_query=query,
+ status=DataModelingJob.Status.SKIPPED,
+ error="Skipped because upstream view orders_daily is failing.",
+ workflow_id="execute-dag-abc:900-2026-08-07T10:17:00Z",
+ last_run_at=timezone.now(),
+ )
+
+ response = self.client.get(f"/api/environments/{self.team.pk}/data_modeling_jobs/recent/")
+ self.assertEqual(response.status_code, 200)
+
+ for_query = [job for job in response.json() if job["saved_query_id"] == str(query.id)]
+ self.assertEqual([job["id"] for job in for_query], [str(skipped.id)])
+
def test_cannot_access_other_teams_jobs(self):
response = self.client.get(f"/api/environments/{self.team.pk}/data_modeling_jobs/{self.other_team_job.id}/")
self.assertEqual(response.status_code, 404)
diff --git a/products/data_warehouse/frontend/generated/api.schemas.ts b/products/data_warehouse/frontend/generated/api.schemas.ts
index 59da81b7d6b0..038ebbf93398 100644
--- a/products/data_warehouse/frontend/generated/api.schemas.ts
+++ b/products/data_warehouse/frontend/generated/api.schemas.ts
@@ -12,6 +12,7 @@
* * `Completed` - Completed
* * `Failed` - Failed
* * `Running` - Running
+ * * `Skipped` - Skipped
*/
export type DataModelingJobStatusEnumApi =
(typeof DataModelingJobStatusEnumApi)[keyof typeof DataModelingJobStatusEnumApi]
@@ -21,6 +22,7 @@ export const DataModelingJobStatusEnumApi = {
Completed: 'Completed',
Failed: 'Failed',
Running: 'Running',
+ Skipped: 'Skipped',
} as const
export interface DataModelingJobApi {
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index d7c29237b51c..46eeaa917a8c 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -18029,6 +18029,7 @@ export namespace Schemas {
* * `Completed` - Completed
* * `Failed` - Failed
* * `Running` - Running
+ * * `Skipped` - Skipped
*/
export type DataModelingJobStatusEnum = typeof DataModelingJobStatusEnum[keyof typeof DataModelingJobStatusEnum];
@@ -18038,6 +18039,7 @@ export namespace Schemas {
Completed: 'Completed',
Failed: 'Failed',
Running: 'Running',
+ Skipped: 'Skipped',
} as const;
export interface DataModelingJob {