{
  "round": "alerts and on-call",
  "design": "DESIGN-reliability.md",
  "question": "When the scorecard's checks run every morning on a month of daily loads, which way of routing their alerts tells the right owner before a viewer reads a wrong number, and at what cost in pages? When a check fails, should the refresh run anyway, stop, or quarantine the failing rows and mark the affected numbers not final?",
  "self_test": "One author wrote the severities, routes, timings, row rules and runbook, knowing which checks the earlier rounds saw fail; every routing result is a self-test of one declared policy.",
  "replay": {
    "data": "the scorecard's pinned 10,000-row January 2024 sample (vendor/portfolio-eval-contract-0.1.0.zip)",
    "landing": "each trip date's file lands at 01:00 the next day; a fault fixture's own landing times win; a row is in the landing table from its landing time on (until a declared upstream deletion); a removed row never lands",
    "mornings": "06:00 every day from 2024-01-02 to 2024-02-01 (31): load every row landed so far, rebuild the models in-process on DuckDB, run every check",
    "models": "the scorecard's dbt SQL from the archive with its one edit (staging takes loaded_at from the landing table), as quality/lineage.py renders and runs it",
    "views": "09:00 every day from 2024-01-02 to 2024-02-01, on each dashboard's schedule; dashboards, tiles and metrics read from lineage_slo/protocol.json unchanged",
    "clock": "2024-02-01T23:59; an owner told later counts as never told",
    "month_end_test": "the February 1 morning must reproduce the scorecard's recorded failed-check sets (v2 for the ten scenarios and the clean month; v3 for both blind sets and the clean month)",
    "independence": "one fault per replay; nothing is fixed during a replay"
  },
  "daily_adaptations": {
    "freshness": "the newest landed row's age at each morning's 06:00; warn after 6 hours, error after 12; warn counts as fail",
    "historical_freshness": "the literal timestamp '2024-02-02 00:00:00' becomes midnight after the check's own morning",
    "unknown": "a check whose status is unknown (the anomaly check without 14 days of history) does not alert"
  },
  "owners": {
    "ingestion": "Ingestion engineer",
    "analytics": "Analytics engineer",
    "feed": "Trip feed owner"
  },
  "severity_rule": {
    "critical": "a failure means rows a dashboard counts are missing, doubled, misdated or in the wrong unit",
    "warning": "a share of values looks off and may be real",
    "info": "bookkeeping identities and the zone reference"
  },
  "checks": {
    "freshness": {
      "attached_to": "raw_trips",
      "owner": "ingestion",
      "severity": "critical",
      "checks": "newest landed row no older than 6 hours at the check (scorecard source freshness, warn counts as fail)"
    },
    "file_arrival_trips": {
      "attached_to": "raw_trips",
      "owner": "ingestion",
      "severity": "critical",
      "checks": "yesterday's trip file landed by the check with at least half the median rows of up to 7 earlier trip dates (given at least 3)"
    },
    "reference_present_zones": {
      "attached_to": "raw_zones",
      "owner": "ingestion",
      "severity": "info",
      "checks": "the zone reference table holds rows"
    },
    "fare_completeness": {
      "attached_to": "raw_trips",
      "owner": "feed",
      "severity": "warning",
      "checks": "no trip date has more than 5% missing fares"
    },
    "day_volume": {
      "attached_to": "raw_trips",
      "owner": "ingestion",
      "severity": "critical",
      "checks": "no trip date below 0.6 times the median of the 14 days before it"
    },
    "source_unique": {
      "attached_to": "raw_trips",
      "owner": "ingestion",
      "severity": "critical",
      "checks": "no trip ID landed twice"
    },
    "content_duplicates": {
      "attached_to": "raw_trips",
      "owner": "ingestion",
      "severity": "critical",
      "checks": "no two rows equal in every field but the trip ID"
    },
    "unit_invariant": {
      "attached_to": "raw_trips",
      "owner": "feed",
      "severity": "critical",
      "checks": "miles agree with the audit metres field"
    },
    "fare_null_anomaly_v2": {
      "attached_to": "raw_trips",
      "owner": "feed",
      "severity": "warning",
      "checks": "no day's missing-fare share above its 14-day bound (floor 0.02)"
    },
    "totals_reconcile": {
      "attached_to": "raw_trips",
      "owner": "feed",
      "severity": "warning",
      "checks": "no day with more than 1% of totals off fare plus tip plus charges"
    },
    "duration_plausible": {
      "attached_to": "raw_trips",
      "owner": "feed",
      "severity": "warning",
      "checks": "no day with more than 1% empty, zero or impossible durations"
    },
    "flag_share_shift": {
      "attached_to": "raw_trips",
      "owner": "feed",
      "severity": "warning",
      "checks": "shared-trip flag shares within 0.15 of their 14-day median"
    },
    "day_copy": {
      "attached_to": "raw_trips",
      "owner": "ingestion",
      "severity": "critical",
      "checks": "no day more than 10% copied from the day before"
    },
    "arrival_window": {
      "attached_to": "raw_trips",
      "owner": "ingestion",
      "severity": "warning",
      "checks": "no row landed before its day ended or more than 36 hours after"
    },
    "historical_freshness": {
      "attached_to": "trips",
      "owner": "analytics",
      "severity": "critical",
      "checks": "the newest load in trips is less than 48 hours older than midnight after the check's morning"
    },
    "month_boundary": {
      "attached_to": "trips",
      "owner": "analytics",
      "severity": "critical",
      "checks": "every trip date is in January 2024"
    },
    "nonnegative_units": {
      "attached_to": "trips",
      "owner": "analytics",
      "severity": "warning",
      "checks": "no negative or empty seconds or miles, no negative fare or tip"
    },
    "not_null_trips_trip_id": {
      "attached_to": "trips",
      "owner": "analytics",
      "severity": "warning",
      "checks": "trip ID never empty"
    },
    "not_null_trips_trip_date": {
      "attached_to": "trips",
      "owner": "analytics",
      "severity": "critical",
      "checks": "trip date never empty"
    },
    "not_null_trips_pickup_zone_id": {
      "attached_to": "trips",
      "owner": "analytics",
      "severity": "warning",
      "checks": "pickup zone never empty"
    },
    "not_null_trips_dropoff_zone_id": {
      "attached_to": "trips",
      "owner": "analytics",
      "severity": "warning",
      "checks": "drop-off zone never empty"
    },
    "relationships_trips_pickup_zone_id__zone_id__ref_zones_": {
      "attached_to": "trips",
      "owner": "analytics",
      "severity": "warning",
      "checks": "every pickup zone exists in zones"
    },
    "relationships_trips_dropoff_zone_id__zone_id__ref_zones_": {
      "attached_to": "trips",
      "owner": "analytics",
      "severity": "warning",
      "checks": "every drop-off zone exists in zones"
    },
    "unique_trips_trip_id": {
      "attached_to": "trips",
      "owner": "analytics",
      "severity": "critical",
      "checks": "trip ID unique in trips"
    },
    "row_identity": {
      "attached_to": "trips",
      "owner": "analytics",
      "severity": "info",
      "checks": "trips holds as many rows as the landing table (bookkeeping identity)"
    },
    "daily_reconciliation": {
      "attached_to": "daily_trips",
      "owner": "analytics",
      "severity": "info",
      "checks": "daily_trips sums to the trips row count (bookkeeping identity)"
    },
    "not_null_zones_zone_id": {
      "attached_to": "zones",
      "owner": "analytics",
      "severity": "info",
      "checks": "zone ID never empty"
    },
    "not_null_zones_zone_name": {
      "attached_to": "zones",
      "owner": "analytics",
      "severity": "info",
      "checks": "zone name never empty"
    },
    "unique_zones_zone_id": {
      "attached_to": "zones",
      "owner": "analytics",
      "severity": "info",
      "checks": "zone ID unique"
    }
  },
  "critical_models": [
    "trips",
    "daily_trips",
    "zones"
  ],
  "rules": {
    "R1": {
      "label": "Page on every failed check",
      "route": "page for every check"
    },
    "R2": {
      "label": "Page only on critical models",
      "route": "page when the check is attached to a model in critical_models, ticket otherwise"
    },
    "R3": {
      "label": "Route by severity",
      "route": "critical: page; warning: ticket; info: digest"
    },
    "R4": {
      "label": "Digest only",
      "route": "digest for every check"
    }
  },
  "told": {
    "page": "06:30 on the check's morning, any day",
    "ticket": "10:00 on the check's day when a weekday, otherwise 10:00 on the next Monday",
    "digest": "sent 17:00 on the check's day, read 09:30 on the next weekday"
  },
  "page_count": "one page per failing check routed to page, per morning it fails",
  "modes": {
    "load": "the refresh always runs on everything landed; checks only alert (the routing measures use this mode)",
    "stop": "source checks (attached to raw_trips or raw_zones) run first; when any critical source check fails the models are not rebuilt that morning and keep the last morning's tables; checks attached to models then run on those tables",
    "quarantine": "rows breaking a row rule move to a quarantine table with the first rule they break (in the listed order); the models build on the rest; every check runs on the rows that passed the quarantine (the build's input); a trip date is not final when the quarantine holds rows of it or a failing check names it; a failing check that names no date makes every date not final that morning; a view whose window includes a not-final date is marked not final"
  },
  "date_naming_checks": {
    "fare_completeness": "the dates it returns",
    "day_volume": "the dates it returns",
    "content_duplicates": "the dates it returns",
    "fare_null_anomaly_v2": "its failed days",
    "file_arrival_trips": "yesterday",
    "freshness": "yesterday"
  },
  "row_rules": [
    {
      "id": "schema",
      "from": "staging casts",
      "rule": "a field fails its staging cast (trip date, numbers, flags, zone codes)"
    },
    {
      "id": "duplicate_id",
      "from": "source_unique",
      "rule": "its trip ID already landed; the first landed copy (landing time, then file order) stays"
    },
    {
      "id": "content_copy",
      "from": "content_duplicates",
      "rule": "every field but the trip ID (and landing time) equals an earlier landed row's on the same trip date"
    },
    {
      "id": "units",
      "from": "unit_invariant",
      "rule": "abs(trip_miles * 1609.344 - audit_distance_meters) > 0.000001, or either is empty"
    },
    {
      "id": "negative_units",
      "from": "nonnegative_units",
      "rule": "trip_seconds or trip_miles empty or negative, or fare or tip negative"
    },
    {
      "id": "totals",
      "from": "totals_reconcile",
      "rule": "fare present and abs(trip_total - (fare + tip + additional_charges)) > 0.01, empty tip and charges as 0"
    },
    {
      "id": "duration",
      "from": "duration_plausible",
      "rule": "trip_seconds <= 0, or trip_miles > 1 and miles per hour > 100"
    },
    {
      "id": "month",
      "from": "month_boundary",
      "rule": "trip date outside January 2024"
    },
    {
      "id": "arrival",
      "from": "arrival_window",
      "rule": "landed before its trip date ended or more than 36 hours after"
    }
  ],
  "faults": [
    {
      "id": "late_partition",
      "family": "scorecard",
      "source": "quality/pipeline.py inject()"
    },
    {
      "id": "null_spike",
      "family": "scorecard",
      "source": "quality/pipeline.py inject()"
    },
    {
      "id": "duplicate_load",
      "family": "scorecard",
      "source": "quality/pipeline.py inject()"
    },
    {
      "id": "unit_change",
      "family": "scorecard",
      "source": "quality/pipeline.py inject()"
    },
    {
      "id": "null_dose_2",
      "family": "scorecard",
      "source": "quality/pipeline.py inject()"
    },
    {
      "id": "null_dose_5",
      "family": "scorecard",
      "source": "quality/pipeline.py inject()"
    },
    {
      "id": "null_dose_10",
      "family": "scorecard",
      "source": "quality/pipeline.py inject()"
    },
    {
      "id": "null_spike_other_day",
      "family": "scorecard",
      "source": "quality/pipeline.py inject()"
    },
    {
      "id": "fresh_id_duplicates",
      "family": "scorecard",
      "source": "quality/pipeline.py inject()"
    },
    {
      "id": "partial_late_partition",
      "family": "scorecard",
      "source": "quality/pipeline.py inject()"
    },
    {
      "id": "late_reload_jan29",
      "family": "blind 1",
      "source": "quality/heldout.py TRANSFORMS"
    },
    {
      "id": "fare_to_tip",
      "family": "blind 1",
      "source": "quality/heldout.py TRANSFORMS"
    },
    {
      "id": "timezone_shift",
      "family": "blind 1",
      "source": "quality/heldout.py TRANSFORMS"
    },
    {
      "id": "duration_minutes",
      "family": "blind 1",
      "source": "quality/heldout.py TRANSFORMS"
    },
    {
      "id": "total_drops_charges",
      "family": "blind 1",
      "source": "quality/heldout.py TRANSFORMS"
    },
    {
      "id": "stale_copy",
      "family": "blind 1",
      "source": "quality/heldout.py TRANSFORMS"
    },
    {
      "id": "zero_distances",
      "family": "blind 1",
      "source": "quality/heldout.py TRANSFORMS"
    },
    {
      "id": "boolean_flip",
      "family": "blind 1",
      "source": "quality/heldout.py TRANSFORMS"
    },
    {
      "id": "partial_reload_duplicate",
      "family": "blind 2",
      "source": "quality/blind2.py TRANSFORMS"
    },
    {
      "id": "timezone_shift_jan11",
      "family": "blind 2",
      "source": "quality/blind2.py TRANSFORMS"
    },
    {
      "id": "total_rounded_dollars",
      "family": "blind 2",
      "source": "quality/blind2.py TRANSFORMS"
    },
    {
      "id": "pickup_area_off_by_one",
      "family": "blind 2",
      "source": "quality/blind2.py TRANSFORMS"
    },
    {
      "id": "duration_cap",
      "family": "blind 2",
      "source": "quality/blind2.py TRANSFORMS"
    },
    {
      "id": "empty_fare_zero",
      "family": "blind 2",
      "source": "quality/blind2.py TRANSFORMS"
    },
    {
      "id": "audit_double_conversion",
      "family": "blind 2",
      "source": "quality/blind2.py TRANSFORMS"
    },
    {
      "id": "early_partial_load",
      "family": "blind 2",
      "source": "quality/blind2.py TRANSFORMS"
    },
    {
      "id": "S03",
      "family": "lineage source",
      "source": "lineage_slo/protocol.json changes"
    },
    {
      "id": "S04",
      "family": "lineage source",
      "source": "lineage_slo/protocol.json changes"
    },
    {
      "id": "S05",
      "family": "lineage source",
      "source": "lineage_slo/protocol.json changes"
    },
    {
      "id": "S06",
      "family": "lineage source",
      "source": "lineage_slo/protocol.json changes"
    }
  ],
  "fault_readings": {
    "S03": "rows of 2024-01-18 land at 2024-01-20 13:00",
    "S04": "rows of 2024-01-05 leave the landing table at 2024-01-20 01:00",
    "S05": "copies of the 2024-01-08 to 2024-01-14 rows, same trip IDs, land at 2024-01-22 01:00",
    "S06": "rows of 2024-01-24 after the first third in file order land at 2024-01-26 01:00",
    "landing": "a fault's landing time is the earliest landing, in the fault or the clean month, of any row it adds, removes or changes (rows compared as whole records including landing time; for S04 the deletion time)",
    "left_out": "the combined scenario (four faults at once); the lineage part's code changes and its schema and value source changes (S01, S02, H05)"
  },
  "truth": {
    "view": "a view is wrong when a tile's displayed value (scale and decimals of the lineage protocol) differs from the clean replay's same view, or the tile fails or is blank where the clean one is not",
    "metric_day": "a metric-day (one of the ten metrics on one morning) is wrong when its value for any trip date differs from the clean replay's that morning by more than 1e-9 relative, or cannot be computed",
    "month_value": "a metric's value over 2024-01-01 to 2024-01-31 on the last morning"
  },
  "measures": {
    "faults_paged": "faults with at least one page, of 30",
    "reached_viewer_first": "faults whose first wrong view (09:00) came before the first owner was told, including faults never told, of the faults with at least one wrong view",
    "false_pages_per_week": "pages on the clean month per 7 mornings; and on fault replays, pages from a check that also fails on the clean replay that morning",
    "time_to_detect": "hours from the fault's landing to the first owner told; median over faults told by the clock, and the count never told",
    "pages_per_fault": "pages on the first morning any check fails for the fault, and over all 31 mornings with no fix",
    "quarantine": "rows quarantined and how many of them the fault added or changed; the largest relative error of the ten metrics' month values on the last morning; wrong views with no mark; views marked not final; hid a real change (quarantine removed rows and left at least one metric's month value further from clean than the load mode)",
    "false_quarantine": "rows quarantined on the clean month, by rule",
    "freshness_per_source": "per fault, the first morning each of freshness, file_arrival_trips and historical_freshness fails"
  },
  "incident_review": {
    "fault": "the fault with the most wrong metric-days in the load mode; ties go to the earlier landing, then the protocol order",
    "fields": [
      "timeline",
      "impact in wrong metric-days and wrong views",
      "root cause",
      "the check that fired first and the check that would have caught it sooner",
      "owner of the follow-up"
    ],
    "scored": "nothing scores the review; it is a template filled from the replay"
  },
  "runbook": {
    "title": "On-call runbook: daily trip feed",
    "scope": "One daily trip feed, its landing tables, four dbt models, three dashboards. Synthetic owners.",
    "steps": [
      {
        "when": "A page arrives (critical check)",
        "do": [
          "Acknowledge within 30 minutes and open an incident note with the check, the trip dates it names and the time.",
          "Before 09:00, put a data warning on every tile that reads the named dates (the lineage page's tile list).",
          "Decide the refresh: let it run, stop it, or quarantine the failing rows, using the table below.",
          "Tell the dashboard owners in one message: what is wrong, which tiles, when it will be right again."
        ]
      },
      {
        "when": "A ticket opens (warning check)",
        "do": [
          "Triage at 10:00 on the next weekday: real change in the world, or a fault in the feed?",
          "If a fault, raise it to an incident and follow the page steps; if real, record why and adjust the check's bound."
        ]
      },
      {
        "when": "The daily digest lists a check (info)",
        "do": [
          "Read it once a day. A bookkeeping identity that fails means the check itself broke: fix the check first."
        ]
      },
      {
        "when": "Choosing what the refresh does",
        "do": [
          "Rows doubled or copied: quarantine the extra rows; the published numbers are right without them.",
          "Rows missing or late: do not stop the refresh; mark the affected days not final until the rows land.",
          "Values that changed meaning (units, totals, durations): quarantine only when the rule cannot catch a real change; otherwise load, mark not final and ask the source."
        ]
      },
      {
        "when": "Closing",
        "do": [
          "Remove the warnings only after the check passes on the morning after the fix.",
          "Write the incident review within two working days: timeline, impact in wrong metric-days, root cause, the check that would have caught it sooner, and who owns the follow-up."
        ]
      }
    ]
  },
  "headline_rule": "the h1 leads with faults that reached a viewer before an owner was told, paging on every check against routing by severity, with the pages per week each costs, and says the severities have one author",
  "predictions": [
    "No rule pages on the clean month (0 false pages per week).",
    "Paging on every failed check pages every fault any check catches, about 20 of 30.",
    "Paging only on critical models pages at most 6 of 30.",
    "Routing by severity lets no more faults reach a viewer first than paging only on critical models.",
    "Under paging on every failed check, the median fault sends at least 2 pages on the morning it is first seen.",
    "The totals row rule quarantines some rows of the clean month.",
    "Quarantine leaves less metric error than loading on the duplicate faults, and hides the late file (S03)."
  ]
}
