The Engagement · Change record

The change, with before and after

One report changed. It now counts each work order once, at its first valid response. Everything else was held still.

A fictional field-service company with invented data. The fault was planted so the right answer is known. Built and run on DuckDB and dbt on 17 November 2026; running the same exercise on a Snowflake account is the next step. Change approval inside the scenario is simulated.

Change record

FieldRecorded
ProblemLegacy Dispatch counts response events where its definition requires one row per work order.
ChangeReplace the report's join to every response event with the one-row-per-work-order first-response fact.
BoundaryOne model, in a separate after-workspace. Raw input, Dispatch and Contract Management may not change.
BeforeLegacy 7 of 11, including two passing rows for W01.
AfterLegacy 6 of 10, the same work orders and results as Dispatch. Contract Management still 4 of 7.
ApprovalSimulated inside the scenario. A real engagement uses the client's own approval.

The SQL change

Red lines are the old report; green lines are the new one.

--- before/models/marts/legacy_dispatch.sql
+++ after/models/marts/legacy_dispatch.sql
@@ -1,22 +1,11 @@
--- Faulty legacy Dispatch implementation (before remediation):
--- Joins eligible work orders directly to all valid response events without
--- deduplicating to the earliest valid response, causing multi-event fan-out.
-WITH eligible_orders AS (
-    SELECT
-        work_order_id,
-        created_at
-    FROM {{ ref('stg_work_orders') }}
-    WHERE COALESCE(status, '') <> 'cancelled'
-      AND created_at <= {{ fse_snapshot_ts() }}
-)
+-- Remediated Legacy Dispatch implementation (after remediation):
+-- Reads work-order-grain earliest valid response from fct_work_order_responses,
+-- matching the Dispatch metric definition at one row per eligible work order.
 SELECT
-    w.work_order_id,
-    COALESCE(e.event_at <= {{ fse_add_minutes('w.created_at', 60) }}, FALSE) AS passed,
-    e.event_id,
-    w.created_at,
-    e.event_at AS response_at,
-    {{ fse_add_minutes('w.created_at', 60) }} AS deadline_at
-FROM eligible_orders w
-LEFT JOIN {{ ref('fct_valid_response_events') }} e
-  ON e.work_order_id = w.work_order_id
-ORDER BY w.work_order_id, passed
+    work_order_id,
+    COALESCE(first_response_at <= {{ fse_add_minutes('created_at', 60) }}, FALSE) AS passed,
+    created_at,
+    first_response_at AS response_at,
+    {{ fse_add_minutes('created_at', 60) }} AS deadline_at
+FROM {{ ref('fct_work_order_responses') }}
+ORDER BY work_order_id

Every row, before and after

All ten eligible work orders, under each report. The highlighted row is the one the legacy report counted twice.

Work orderDispatchContract ManagementLegacy, beforeLegacy, after
W01passpasspass + passpass
W02passfailpasspass
W03failpassfailfail
W04failfailfailfail
W06passnot countedpasspass
W07failnot countedfailfail
W08passpasspasspass
W09passnot countedpasspass
W10passpasspasspass
W11failfailfailfail
Result6 of 104 of 77 of 116 of 10

Dispatch and Contract Management are identical in the before and after builds. Two eligible-looking orders never appear: W05 was cancelled, and W12 was created after the snapshot.

Why W01 was counted twice

W01 was created at 10:00. It has a note at 10:10, which is not a response, and two valid responses, at 10:30 and 10:50, both before its 11:00 deadline. The old query produced one row per response. The definition asks for one row per work order.

Download the rows (JSON) · Download the diff

All the evidenceAssessmentThe changeVerification and rollbackLineage← The engagement