# OIP-0005: Alert notices and the CAP binding

| Field | Value |
|---|---|
| Status | DRAFT |
| Function | `exchange` (§5.10); no new function (the register keeps exactly twelve) |
| Affects | §4.2 (core objects), §5.10, §6 (Exchange row); new schema `alert-notice` with fixtures both ways; `registers/functions.yaml` (`exchange` objects); `registers/relations.yaml` (new row `EXT-CAP`); new binding `bindings/cap/`; new cases CT-GRID-008, CT-GRID-009, CT-CONSUMER-006 |
| Protocol version | obsp/0.1 |
| Relates to | OIP-0001 (read APIs). Both edit §5.10: whichever is accepted second is rebased on the first |
| Last call | 30 days (revision of an existing function) unless the editors rule otherwise; see Open questions |

## Problem

Early-warning work needs to know when qualified observations cross a declared threshold, and to hand that fact to
the systems that warn people. Today the protocol has no object for it. An operator can publish observations and
products, but a threshold crossing travels, if at all, as an unstructured message with no link to the evidence that
caused it, no correction path, and no statement of who issued it and with what authority.

The established exchange format for alerts is the Common Alerting Protocol (OASIS CAP 1.2, also ITU-T X.1303 bis).
The protocol must map to it, not replace it, and must not turn an observation operator into a public alerting
authority: in most jurisdictions only designated authorities issue public warnings.

## Change

### Normative text (added to §5.10 as a sub-list "Alert notices")

An alert notice states that a declared trigger condition was met by qualified observations. It is evidence for an
alerting authority's decision; it is not a public warning.

1. **ALRT-1.** An AlertNotice MUST reference the trigger definition it evaluated (URI and digest) and every
   observation record that met the condition (UNI, version and digest).
2. **ALRT-2.** Every referenced observation MUST have passed qualification (every quality flag on it is `GOOD`), and
   its time quality MUST be trusted (§5.4, §5.6). A notice built on unqualified data or untrusted time MUST NOT be
   issued.
3. **ALRT-3.** An AlertNotice MUST state its issuer by role (the operator's participant UNI) and its scope
   (`scope`: `OPERATOR` for an operator's notice, or `AUTHORITY` only when the issuer is registered as an alerting
   authority for the area). A notice with scope `OPERATOR` MUST NOT be presented as a public warning.
4. **ALRT-4.** An AlertNotice MUST carry its status (`ACTUAL`, `EXERCISE`, `SYSTEM`, `TEST`, `DRAFT`) and its
   message type (`ALERT`, `UPDATE`, `CANCEL`). An `UPDATE` or `CANCEL` MUST reference the notice it changes; a notice
   is never deleted (§5.9).
5. **ALRT-5.** An AlertNotice MUST describe its area as a polygon, a circle or registered geocodes, and SHOULD state
   the location precision of the observations it rests on.
6. **ALRT-6.** An AlertNotice MAY be published as a CAP 1.2 message through the binding `bindings/cap/`. The binding
   maps each AlertNotice field to the CAP element by clause; a CAP message derived from a notice with scope
   `OPERATOR` MUST NOT use a CAP `scope` of `Public` unless an alerting authority reissues it.
7. **ALRT-7.** A consumer that relays an AlertNotice MUST keep its references to the evidence and its status, and
   MUST NOT relay a notice with status `TEST`, `EXERCISE` or `DRAFT` as `ACTUAL`.

§6, Exchange row: add "CAP 1.2 for alert notices (`bindings/cap/`)".
§4.2: add the row "AlertNotice | `alert-notice` | Exchange".

### Contract: `alert-notice` (schemaVersion `3.1.0`)

| Property | Required | Shape |
|---|---|---|
| `schemaVersion` | yes | `3.1.0` |
| `noticeUni` | yes | UNI |
| `issuedAt` | yes | date-time |
| `issuer` | yes | object: `participantUni` (UNI), `role` (participant role id) |
| `scope` | yes | `OPERATOR` or `AUTHORITY` |
| `status` | yes | `ACTUAL`, `EXERCISE`, `SYSTEM`, `TEST`, `DRAFT` |
| `msgType` | yes | `ALERT`, `UPDATE`, `CANCEL` |
| `references` | when `msgType` is `UPDATE` or `CANCEL` | array (min 1) of `{noticeUni, issuedAt}` |
| `trigger` | yes | object: `uri`, `digest` (Digest), optional `title` |
| `evidence` | yes | array (min 1) of `{recordUni, recordVersion, digest}` observation references |
| `hazard` | yes | object: `category` (the CAP category vocabulary, cited), `event` (free text, max 160) |
| `urgency`, `severity`, `certainty` | yes | the CAP value vocabularies, cited by clause; `Unknown` allowed |
| `area` | yes | object: `description`, and at least one of `polygon` (array of `[lon, lat]`, closed ring, min 4 points), `circle` (`center` `[lon, lat]`, `radiusKm` > 0), `geocodes` (array of `{scheme, value}`) |
| `locationPrecisionM` | no | number ≥ 0 |
| `expires` | no | date-time after `issuedAt` |
| `extensions` | no | namespaced bag, as other schemas |

Invariants (suite):

- `alert-evidence-qualified`: every evidence record is present in the set with the digest the notice cites, every
  quality flag on it is `GOOD`, and its time quality is trusted.
- `alert-update-references`: an `UPDATE` or `CANCEL` references a notice present in the set, issued earlier.
- `alert-polygon-closed`: an area polygon's first and last positions are equal (JSON Schema cannot compare them).
- `alert-expires-after-issue`: `expires`, when present, is after `issuedAt`.
- `alert-operator-not-public`: a CAP example derived from an `OPERATOR` notice does not carry CAP scope `Public`
  (binding check).

### Binding `bindings/cap/` (status proposed)

`PROFILE.md`, `binding.yaml` (requirements `BND-CAP-01..`), and the artefact: a mapping file from `alert-notice` to
CAP 1.2 elements (`alert`, `info`, `area`), each row with the CAP clause; examples both ways (a CAP message built from
the positive fixture; a CAP message with scope `Public` from an operator notice; one missing `references` on a
`Cancel`). CAP fields with no protocol source (for example `sender` contact details) are listed as "not mapped" with
the reason; contact details are never invented. Relation row `EXT-CAP`: "OASIS CAP 1.2 (Common Alerting Protocol);
ITU-T X.1303 bis", kind `aligns-with`, function `exchange`, schema `alert-notice`, artefacts `[bindings/cap/]`.

## Compatibility

Additive: a new object, a new binding and a new relation. No existing document changes. `exchange` gains one object.

## Tests

| Requirement | Case | Kind |
|---|---|---|
| ALRT-1, ALRT-3, ALRT-4, ALRT-5 | CT-GRID-008 | schema + invariant (`alert-update-references`) on `alert-notice` |
| ALRT-2 | CT-GRID-009 | invariant `alert-evidence-qualified` on `alert-notice`, `observation-record`, `quality-flag`, `time-quality` |
| ALRT-6 | binding cases `BND-CAP-*` | binding examples (validator group `bindings`) |
| ALRT-7 | CT-CONSUMER-006 | manual (consumer attestation) |

Negative fixtures: `alert-notice.missing-evidence`, `.cancel-without-references`, `.unknown-status`,
`.polygon-too-few-points`, `.circle-zero-radius`. Polygon closure and the operator scope rule are not expressible in
JSON Schema: the invariant `alert-polygon-closed` and the binding's negative examples cover them.

## Open questions

1. Trigger definitions: should the protocol define a `trigger-definition` object (threshold, window, observed
   property), or only reference one by URI and digest as here?
2. `AUTHORITY` scope: which register records that an issuer is an alerting authority for an area (participants
   register, or an external authority list cited by identifier)?
3. Hazard vocabulary: CAP's category list, or the standards programme's hazard standard (relation `REL-NHS-1`), or
   both with a crosswalk?
4. Last call: revision (30 days) or new capability (90 days)?

Acceptance needs appointed editors and a last-call window. Until then this proposal stays at DRAFT and no alert
object exists in the protocol.
