mirror of
https://github.com/zvx-echo6/meshai.git
synced 2026-06-11 01:14:45 +02:00
feat(v0.5.9): unified incident pipeline + state_511_atis Idaho cutover + two-sided freshness gate
Coordinated change across the consumer dispatch layer + central_normalizer + new incident_handler + new itd_511 work_zone parser. The integrated story: Central PM filed a heads-up that ITD 511 publishes four EventTypes (work_zone, closure, incident, special_event) under us.id Convention A, and meshais v0.5.8 work focused on work_zone shape only -- meaning incidents (the higher-priority operational signal) were silently rendering as the v0.5.7-regression-style fallback. This v0.5.9 closes that gap by treating incidents + closures + special_events from all three traffic adapters (state_511_atis, itd_511, tomtom_incidents) as a single unified pipeline, while also migrating Idaho coverage from state_511_atis to itd_511 (the direct ITD feed) at the consumer level. Components: (1) new meshai/central/incident_handler.py routes incident/closure/special_event events through per-adapter parsers (tomtom, itd_511, state_511_atis-non-ID) to a canonical incident shape, then a single rendering pipeline with sub_type-aware emoji selection (jam/crash/road_closed/disabled_vehicle/parade/special_event/vehicle_fire/road_works). (2) Universal two-sided freshness gate in the consumer dispatch layer: only events with 0 <= age <= 1800s (default-allow on missing start_time) make it past the gate. Rejects both stale events (more than 30 min old) AND future-scheduled events (negative age -- a real itd_511 case for scheduled work projects). The gate sits ABOVE both incident_handler and the v0.5.8 work_zone formatter so all adapters get gated uniformly. (3) state_511_atis Idaho cutover -- both incident_handler and the v0.5.8 work_zone parser skip state_511_atis events where the state token is ID, deferring to itd_511 as the authoritative source. state_511_atis remains fully active for non-Idaho neighbor coverage (WA/OR/MT/UT/WY/NV) -- verified by Phase 2 WA broadcasts in the synthetic probe. (4) new itd_511 work_zone parser (extension to central_normalizer.py) consumes the itd_511 work_zone EventType and produces the same MEDIUM-style wire format as the existing state_511_atis work_zone parser (road + mile range + town + direction + sub_type + ends-at). (5) No Update: broadcasts in the incident pipeline -- per Matts call, real-time traffic Updates (jam getting worse, delay growing) are not actionable for mesh users. State tracking continues via traffic_events UPSERT but only the first sighting of an external_id ever fires a New: broadcast. WFIGS handler unchanged -- fires keep their 8h-rate-limited Update: behavior since acres growth IS operationally meaningful (evacuation decisions). Forecast: 3-10 mesh broadcasts/day in Idaho, all New:. Cross-check: original raw broadcast count was 623 against a fixed-clock 49-min synthetic window; after v0.5.9 REVISED (no Updates) it dropped to 18; after v0.5.9 GAMMA (two-sided gate + Idaho cutover) it dropped to 9. Test count: was 589 baseline, +45 net new -- 634 passing. Synthetic probe verified all four phases: Phase 1 (replay 3032 captured envelopes) = 0 broadcasts (correctly suppressed); Phase 2 (synthesized fresh non-ID + ID) = 7 broadcasts; Phase 3 (synthesized fresh itd_511 work_zone) = 2 broadcasts; Phase 4 (synthesized fresh ID for explicit ID-skip exercise) = caught by ID-skip 1/1. Master stays off in prod; no toggle flips. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
053d67db6e
commit
0099d0fd94
8 changed files with 2088 additions and 12 deletions
|
|
@ -673,3 +673,132 @@ def test_wzdx_sub_type_unknown_vocab_is_lowercased_with_spaces(monkeypatch):
|
|||
"_enriched": {"geocoder": {"city": "Boise"}}}}}
|
||||
n = normalize(env)
|
||||
assert n["sub_type"] == "some custom work" # lowercased + hyphens→spaces
|
||||
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# v0.5.9 GAMMA -- state_511_atis Idaho cutover
|
||||
# ============================================================================
|
||||
|
||||
|
||||
def _state_511_envelope(state_code="ID", primary_region="US-ID"):
|
||||
return {
|
||||
"subject": "central.traffic.work_zone.id",
|
||||
"id": "ID:Construction:33333",
|
||||
"data": {
|
||||
"id": "ID:Construction:33333", "adapter": "state_511_atis",
|
||||
"category": "work_zone.state_511_atis", "severity": 1,
|
||||
"geo": {"centroid": [-116.79, 47.70],
|
||||
"primary_region": primary_region},
|
||||
"data": {
|
||||
"roadway_name": "US-95", "direction": "Both",
|
||||
"event_sub_type": "brushControl",
|
||||
"description": "Minor Brush control on US-95.",
|
||||
"is_full_closure": False, "layer": "Construction",
|
||||
"county": "Kootenai", "state": "Idaho",
|
||||
"state_code": state_code,
|
||||
"start_date": "6/1/26, 5:00 AM",
|
||||
"last_updated": "5/28/26, 12:54 PM",
|
||||
"latitude": 47.7, "longitude": -116.79,
|
||||
"_enriched": {"geocoder": {
|
||||
"city": "Coeur d'Alene", "county": "Kootenai",
|
||||
}},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def test_gamma_should_skip_state_511_atis_id_via_state_code():
|
||||
"""Helper returns True when state_code='ID'."""
|
||||
from meshai.central_normalizer import should_skip_state_511_atis_id
|
||||
env = _state_511_envelope(state_code="ID")
|
||||
assert should_skip_state_511_atis_id(env) is True
|
||||
|
||||
|
||||
def test_gamma_should_skip_state_511_atis_id_via_primary_region():
|
||||
"""Helper returns True when only primary_region='US-ID' is set."""
|
||||
from meshai.central_normalizer import should_skip_state_511_atis_id
|
||||
env = _state_511_envelope(state_code="", primary_region="US-ID")
|
||||
assert should_skip_state_511_atis_id(env) is True
|
||||
|
||||
|
||||
def test_gamma_should_skip_state_511_atis_id_false_for_non_id():
|
||||
"""Helper returns False for neighbor states."""
|
||||
from meshai.central_normalizer import should_skip_state_511_atis_id
|
||||
env = _state_511_envelope(state_code="WA", primary_region="US-WA")
|
||||
assert should_skip_state_511_atis_id(env) is False
|
||||
|
||||
|
||||
def test_gamma_state_511_non_id_still_parses():
|
||||
"""state_511_atis with state_code='WA' continues to be parsed --
|
||||
neighbor-state coverage remains active after the Idaho cutover.
|
||||
With the v0.5.9 GAMMA fixup, the parser is unconditionally pure;
|
||||
this test guards against a future regression that would put the
|
||||
skip back into normalize()."""
|
||||
env = _state_511_envelope(state_code="WA", primary_region="US-WA")
|
||||
n = normalize(env)
|
||||
assert n is not None
|
||||
assert n.get("source") == "state_511_atis"
|
||||
assert n.get("road") == "US-95"
|
||||
|
||||
|
||||
def test_gamma_itd_511_work_zone_dispatch():
|
||||
"""itd_511 + category=work_zone.* routes to _parse_itd_511_work_zone."""
|
||||
env = {
|
||||
"subject": "central.traffic.work_zone.us.id",
|
||||
"id": "ITD:469:99",
|
||||
"data": {
|
||||
"id": "ITD:469:99", "adapter": "itd_511",
|
||||
"category": "work_zone.itd_511", "severity": 1,
|
||||
"geo": {"centroid": [-116.79, 47.70],
|
||||
"primary_region": "US-ID"},
|
||||
"data": {
|
||||
"event_type_short": "work_zone",
|
||||
"event_sub_type": "roadConstruction",
|
||||
"roadway_name": "I-90", "direction": "Both",
|
||||
"description": "Road construction on I-90.",
|
||||
"is_full_closure": False,
|
||||
"comment": "", "cause": "roadwork",
|
||||
"organization": "ERS",
|
||||
"start_epoch": 1780600000,
|
||||
"planned_end_epoch": 1781000000,
|
||||
"latitude": 47.7, "longitude": -116.79,
|
||||
"_enriched": {"geocoder": {
|
||||
"city": "Coeur d'Alene", "county": "Kootenai",
|
||||
}},
|
||||
},
|
||||
},
|
||||
}
|
||||
n = normalize(env)
|
||||
assert n is not None
|
||||
assert n.get("source") == "itd_511"
|
||||
assert n.get("road") == "I-90"
|
||||
|
||||
|
||||
def test_gamma_itd_511_non_work_zone_returns_none_or_marker():
|
||||
"""itd_511 + category=incident.* should NOT go through work_zone parser."""
|
||||
env = {
|
||||
"subject": "central.traffic.incident.us.id",
|
||||
"id": "ITD:469:100",
|
||||
"data": {
|
||||
"id": "ITD:469:100", "adapter": "itd_511",
|
||||
"category": "incident.itd_511", "severity": 1,
|
||||
"geo": {"primary_region": "US-ID"},
|
||||
"data": {
|
||||
"event_type_short": "incident",
|
||||
"event_sub_type": "crash",
|
||||
"roadway_name": "I-84", "direction": "East",
|
||||
"description": "Crash on I-84.",
|
||||
"is_full_closure": False, "comment": "",
|
||||
"cause": "crash", "organization": "ERS",
|
||||
"start_epoch": 1780600000,
|
||||
"planned_end_epoch": None,
|
||||
"latitude": 43.5, "longitude": -116.5,
|
||||
"_enriched": {"geocoder": {"city": "Boise"}},
|
||||
},
|
||||
},
|
||||
}
|
||||
n = normalize(env)
|
||||
# Either None or not a work_zone shape -- never a parsed work_zone.
|
||||
if n is not None:
|
||||
assert n.get("source") != "itd_511" or "road" not in n
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue