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
| Field | Recorded |
|---|---|
| Problem | Legacy Dispatch counts response events where its definition requires one row per work order. |
| Change | Replace the report's join to every response event with the one-row-per-work-order first-response fact. |
| Boundary | One model, in a separate after-workspace. Raw input, Dispatch and Contract Management may not change. |
| Before | Legacy 7 of 11, including two passing rows for W01. |
| After | Legacy 6 of 10, the same work orders and results as Dispatch. Contract Management still 4 of 7. |
| Approval | Simulated 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 order | Dispatch | Contract Management | Legacy, before | Legacy, after |
|---|---|---|---|---|
| W01 | pass | pass | pass + pass | pass |
| W02 | pass | fail | pass | pass |
| W03 | fail | pass | fail | fail |
| W04 | fail | fail | fail | fail |
| W06 | pass | not counted | pass | pass |
| W07 | fail | not counted | fail | fail |
| W08 | pass | pass | pass | pass |
| W09 | pass | not counted | pass | pass |
| W10 | pass | pass | pass | pass |
| W11 | fail | fail | fail | fail |
| Result | 6 of 10 | 4 of 7 | 7 of 11 | 6 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.