Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Road domain, v0.1:
their readings. Congestion is computed from a self-derived free-flow baseline (85th
percentile), with native reference speeds where a feed ships one and OSM `maxspeed` as a day-one proxy.
See [docs/speed-coverage.md](docs/speed-coverage.md).
- **Emitters:** a paged record API, GeoJSON, JSON-LD, TraFF, DATEX II, Valhalla exclusions, and an SSE stream —
- **Emitters:** a paged record API, GeoJSON, JSON-LD, TraFF, CIFS (XML & JSON), DATEX II, Valhalla exclusions, and an SSE stream —
all public, rate-limited, and bbox-filterable.
- **Graph binding:** road situations, and effects with a location of their own, are bound to the directed
OSM segment spine (`way_id:f|b` spans with confidence); see [docs/graph-binding.md](docs/graph-binding.md).
Expand Down Expand Up @@ -89,14 +89,14 @@ packages/ reusable libraries (Apache-2.0 unless noted)
facilities, maritime, vehicles, weather
core/ canonical model, severity, freshness, read helpers, DB schema/migrations (./server)
ingest-framework/ feed descriptors, credentials, guarded fetch, catalogue resolvers, licences, domain plugins
roads/ road parsers (DATEX II / Open511 / WZDx and more), the roads domain, TMC location tables
roads/ road parsers (DATEX II / Open511 / WZDx / CIFS and more), the roads domain, TMC location tables
bind/ event → segment resolver + evaluation corpus
parking/ fuel/ charging/ cameras/ hazards/ weather/ vehicles/ border/
each domain's parsers and its ingest domain
datex2/ DATEX II decoding shared by the domains (XML, publications, value decoders)
ocpi/ OCPI wire types, decoders and dialects
openlr/ OpenLR binary decode + resolver client
publishers/ outbound emitters (GeoJSON, JSON-LD, TraFF, DATEX II, SSE, Valhalla)
publishers/ outbound emitters (GeoJSON, JSON-LD, TraFF, CIFS, DATEX II, SSE, Valhalla)
storage/ the source catalogue and the record writer (AGPL-3.0)
contrib-core/ the signed, portable crowd report and sub-claim format
federation/ instance identity: Ed25519 keys, the actor document, the pinned peers registry
Expand Down
38 changes: 38 additions & 0 deletions docs/cifs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# CIFS v2 ingest and export

OpenConditions implements the **Closure and Incident Feed Specification (CIFS v2)** published by Google/Waze in both directions: inbound parsing (`format: "cifs"` in `@openconditions/roads`, XML and JSON) and outbound publishing (`situationsToCifsXml` and `situationsToCifsJson` in `@openconditions/publishers`, exposed at `GET /cifs.xml` and `GET /cifs.json`).

## Schema and crosswalk

The official XML Schema (`https://www.gstatic.com/road-incidents/cifsv2.xsd`) is pinned by SHA-256 in `packages/conformance/src/standards/cifs-v2.ts` and validated at test time with `xmllint-wasm`. Every CIFS `type` and `subtype` is declared in `packages/model-roads/src/vocabularies/cifs.ts` and mapped in `packages/model-roads/src/crosswalk/cifs.ts`.

Inbound parsing validates `(type, subtype)` pairs before classification so mismatched pairs (such as `HAZARD` with `ROAD_CLOSED_EVENT`) fail closed. `CHIT_CHAT` is accounted as `terminal` rather than published as a road condition. Two documented subtypes absent from `cifsv2.xsd` (`HAZARD_ON_ROAD_EMERGENCY_VEHICLE` and `POLICE_WITH_MOBILE_CAMERA`) are accepted inbound and never written outbound. Outbound export never writes deprecated top-level `CONSTRUCTION` (it emits `HAZARD` / `HAZARD_ON_ROAD_CONSTRUCTION` instead) or `CHIT_CHAT`.

## Inbound parsing and snapshot authority

`parseCifsSnapshot` reads both CIFS XML (`<incidents>`) and CIFS JSON (`{ "incidents": [...] }`, supporting both flat incident objects and wrapped `{ "incident": { ... } }` entries) as well as legacy nested `location` objects. Contradictory values between flat location fields and a nested `location` object fail closed.

Because Waze partner feeds do not uniformly guarantee complete-world snapshot semantics, `format: "cifs"` always parses through the accounted snapshot path (`reconcileRoadSnapshots`) with `situationsComplete: false` by default and a bounded retrieval TTL (`freshness.expiresAt`). The format declares `reparseUnchanged: true` so conditional `304 Not Modified` responses replay the held payload and advance `freshness.expiresAt` on healthy feeds, while failed or malformed polls leave existing records untouched. Malformed records, wrong roots, explicit failure envelopes (`error`, `errors`, `success: false`, `ok: false`, HTTP error status), and conflicting duplicate IDs fail the poll rather than withdrawing valid predecessors. A catalogue source may declare `snapshot: { completeness: "complete" }` only after qualifying its withdrawal contract.

Inbound semantic rules:

- `ROAD_CLOSED` and `ROAD_CLOSED_*` retain their cause classification (`roadworks.works.construction`, `public_event.event`, `road_hazard.hazard`, or `closure.closure.full`) and explicitly set `roadState: "closed"`, producing a `closure` effect. Closures without an explicit usable `starttime` set `validity.status: "unknown"`, and single-point, circular, zero-length, or >20 km `ROAD_CLOSED` geometries attach a non-temporal `invalid_value` issue so they remain `normalization: "partial"` and never enter routing.
- Bare `CONSTRUCTION` and `HAZARD_ON_ROAD_CONSTRUCTION` remain works alerts unless backed by valid lane evidence.
- On a `LineString`, `ONE_DIRECTION` and omitted `direction` map to `{ value: "positive", basis: "geometry" }`. On a `Point`, `ONE_DIRECTION` maps to `{ value: "positive", basis: "unknown", text: "ONE_DIRECTION" }` so graph binding treats it as `unplaced` instead of widening to both directions. Duplicate or non-scalar direction/location/timing fields fail closed rather than collapsing to absent.
- Partial lane data (`<lanes>` and `<lane_impact>`) is validated as single-direction linear evidence only. Zero-based `order` (`0..99`) is normalized to 1-based lane indices, non-traffic lane types (anything other than `LANE`) are excluded from traffic lane counts, count and roadside conflicts between `<lanes>` and `<lane_impact>` are flagged as partial evidence, and partial lane data never synthesizes `all_lanes_closed`.
- `<source>` / JSON `reference` maps to `provenance.informationSource` while `provenance.attribution` stays catalogue-owned. `<parent_event id="..."/>` is preserved in `externalIds` under `cifs:parent_event` alongside `cifs:incident`.
- Inverted `starttime > endtime`, unparseable or malformed bounds, malformed or equal-endpoint schedule windows, schedules without a resolvable timezone, and recurring windows that cross a DST transition set `validity.status: "unknown"` with a matching temporal issue so the record never defaults to 24/7 active or drifts by an hour across DST.

## Outbound export (`GET /cifs.xml` and `GET /cifs.json`)

`GET /cifs.xml` and `GET /cifs.json` return one **complete public point-in-time CIFS v2 feed** from a single repeatable-read read-only database snapshot, sharing the exact same projection. Neither endpoint accepts `cursor`, `limit`, `simplify`, `from`, or `to` (400); use `at` (and optional `horizonDays`) for point-in-time reads. Both endpoints always use the public scope even when an operator bearer token is sent, and enforce a maximum of **20,000 candidate situations** and **32 MiB of UTF-8 serialized output** (answering 413 JSON with `Cache-Control: no-store` if either bound is exceeded). `X-Data-License` names the licences of the public selection.

Outbound safety and geometry policy:

- **Never fabricate geometry.** Coordinates are rounded to 6 decimal places first; distinctness, non-circularity (rejecting closed rings where first and last vertices coincide for 3+ vertices), and Haversine length are validated on the serialized coordinates.
- **`ROAD_CLOSED` requires strong evidence:** a complete, active or confirmed-scheduled (`actionStatus` not `rejected` or `requested`), mandatory, road-wide (no `laneScope`) `closure` effect with scope in `road`, `carriageway`, `ramp`, `bridge`, or `tunnel`, an explicit `validity.start` timestamp (never defaulted from mutable poll or update timestamps), and a non-circular `LineString` of length > 0 m and ≤ 20,000 m. `lane_restriction` effects (including `all_lanes_closed`) and bare `closure` classifications never synthesize `ROAD_CLOSED`.
- **Single-point incidents:** single-point closures are always withheld. Non-closure single-point alerts (`ACCIDENT`, `HAZARD`, `JAM`, `POLICE`) are exported with `<direction>BOTH_DIRECTIONS</direction>` only when the canonical situation carries explicit bilateral evidence (`direction.value === "both"`). Single-point alerts with absent or non-bilateral direction are withheld rather than widened.
- **Line direction:** absent direction or `direction.value === "both"` writes `BOTH_DIRECTIONS`. `basis: "geometry"` writes `ONE_DIRECTION` (reversing coordinates when `value === "negative"`). Compass, bearing, Alert-C, and unknown directions are withheld with `unrepresentable_direction`.
- **Timing and schedules:** `unknown`, `ended`, `cancelled`, and `suspended` root lifecycles are withheld. Recurring `periods` are exported as `<schedule>` (strictly in `cifsv2.xsd` sequence order: `everyday` or `monday`..`sunday`) only when `scheduleTimezone` matches the geometry timezone, no `exceptions` / `exceptDate` / `byMonth` / `byMonthDay` / `repeatCount` or narrower date sub-bounds are present, windows are same-day minute-aligned with authoritative `duration` matching any `endTime`, and the window does not cross a DST transition. Note that Waze defaults omitted `endtime` on closures to 14 days from `starttime`.
- **Lanes and splitting:** `<lanes>` is attached only on `ONE_DIRECTION` non-closure incidents with a complete contiguous `1..N` traffic lane list whose statuses are `open` or `closed` and whose counts reconcile with declared `lanesTotal`, `lanesClosed`, `lanesRestricted`, `lanesOperational`, and `vehicleImpact`. Partial counts never fabricate `<roadside>` for `<lane_impact>`. Effects with their own geometry, effective validity (including `periods`), or direction split into separate incidents; overlapping effective windows (intersecting recurring schedules) at the same location and direction with conflicting lane restrictions (including `all_lanes_open`) are withheld with `conflicting_effects`.
- **Timestamps, sanitization, and identity:** `xs:dateTime` values are formatted as second-resolution UTC clamped to `0001-01-01T00:00:00Z` through `9999-12-31T23:59:59Z`. Text fields pass through XML 1.0 character sanitization before enforcing `cifsv2.xsd` minimum Unicode code-point lengths (`@id` ≥ 3, `<street>` ≥ 2, `<description>` ≥ 1). Preserved `cifs:parent_event` external IDs (≥ 3 code points) are emitted as `<parent_event id="..."/>` / `parent_event`. Feed-wide incident ID uniqueness is enforced across root and split records after sanitization.
Loading
Loading