feat(geofence): hear quakes, WFIGS incidents, and news pins #61

Merged
sirius merged 1 commit from wt/t_02dd06a8 into master 2026-11-17 19:56:56 +00:00
Owner

Summary

An active polygon now gets a geofence_alerts row when an earthquake, a WFIGS fire incident, or a news map pin falls inside it. A point outside writes nothing. source_kind=camera is never passed to record_and_notify.

Existing adsb/ais/firms callers are unchanged and may omit evidence. The new kinds always include this object. Frozen — the frontend inbox card reads these keys and no others:

"evidence": {
  "cameras": [{"id": "<cameras.id>", "name": "<location_name or ''>", "snapshot_url": "/api/cameras/<id>/snapshot"}],
  "news": [{"headline": "<str>", "url": "<articles/news url or ''>", "importance": "<str or ''>"}],
  "snapshot": "/api/geofences/<gid>/at?ts=<iso8601>"
}

Caps: at most 5 cameras (nearest the hit, inside the fence), at most 3 news items (most recent inside the fence). Empty arrays if none. snapshot_url is the proxy path only — the camera SQL does not select cameras.snapshot_url, so an agency URL or rtsp:// cannot leak. snapshot is a path+query (ts=), not a fetched body. GET /api/geofences/{gid}/at accepts ts as an alias of timestamp.

Hooks (premise corrections)

  • Earthquake: notify on ingest_event after a new insert (source_type=earthquake, lat/lon required). Entity id is raw.usgs_id, else url, else the event id. A catch-up scan of events (last 7 days, cap 200) runs on the ingester loop so a fence drawn after the quake was stored still hears it.
  • WFIGS: not persisted. Fence-scoped poll on run_ingester.geofence_feed_loop (sibling of producer_loop / fire_loop, same process, INGEST_INTERVAL, default 300s). Uses load_fire_incidents — no fire_last_known mutation, no aircraft correlate, no FIRMS/AIS key. Entity id is IrwinID, else UniqueFireIdentifier, else name|state|discovered. Marker id stays the incident name.
  • News: reader of news_items on that same loop. Does not import the summarizer. Pins match GET /api/news/map (kind=map, critical/high, lat/lon, last 24h). Entity id is news_items.id.
  • Cooldown: still 5 minutes per (fence_id, entity_id). Polled kinds also pass skip_existing, so a later poll of the same incident id does not insert again (in-process set, plus a geofence_alerts lookup after restart). Fail closed on that lookup so a broken read cannot page every fence.
  • Cameras: upsert_cameras, publish_new_cameras, and ingest_event(source_type=camera) do not call record_and_notify. record_and_notify refuses source_kind=camera.

GET /api/geofence-alerts?source_kind= now accepts earthquake|fire_incident|news and still 422s camera.

No Telegram, webhook, or other delivery channel. No live fence created. No deploy.

Test plan

  • PYTHONPATH=app pytest tests/test_geofence.py -q → 27 passed
  • Inside point → 1 row with payload.evidence matching the keys above; outside point → 0 rows, for earthquake, fire_incident, and news
  • Camera publish/insert does not call record_and_notify
  • Two incidents with the same entity_id inside 5 minutes → 1 row
  • Known-red CI docker login 127.0.0.1:3000 is not this change
## Summary An active polygon now gets a `geofence_alerts` row when an earthquake, a WFIGS fire incident, or a news map pin falls inside it. A point outside writes nothing. `source_kind=camera` is never passed to `record_and_notify`. Existing adsb/ais/firms callers are unchanged and may omit `evidence`. The new kinds always include this object. Frozen — the frontend inbox card reads these keys and no others: ```json "evidence": { "cameras": [{"id": "<cameras.id>", "name": "<location_name or ''>", "snapshot_url": "/api/cameras/<id>/snapshot"}], "news": [{"headline": "<str>", "url": "<articles/news url or ''>", "importance": "<str or ''>"}], "snapshot": "/api/geofences/<gid>/at?ts=<iso8601>" } ``` Caps: at most 5 cameras (nearest the hit, inside the fence), at most 3 news items (most recent inside the fence). Empty arrays if none. `snapshot_url` is the proxy path only — the camera SQL does not select `cameras.snapshot_url`, so an agency URL or `rtsp://` cannot leak. `snapshot` is a path+query (`ts=`), not a fetched body. `GET /api/geofences/{gid}/at` accepts `ts` as an alias of `timestamp`. ## Hooks (premise corrections) - **Earthquake:** notify on `ingest_event` after a new insert (`source_type=earthquake`, lat/lon required). Entity id is `raw.usgs_id`, else url, else the event id. A catch-up scan of `events` (last 7 days, cap 200) runs on the ingester loop so a fence drawn after the quake was stored still hears it. - **WFIGS:** not persisted. Fence-scoped poll on `run_ingester.geofence_feed_loop` (sibling of `producer_loop` / `fire_loop`, same process, `INGEST_INTERVAL`, default 300s). Uses `load_fire_incidents` — no `fire_last_known` mutation, no aircraft correlate, no FIRMS/AIS key. Entity id is IrwinID, else UniqueFireIdentifier, else `name|state|discovered`. Marker `id` stays the incident name. - **News:** reader of `news_items` on that same loop. Does not import the summarizer. Pins match `GET /api/news/map` (`kind=map`, critical/high, lat/lon, last 24h). Entity id is `news_items.id`. - **Cooldown:** still 5 minutes per `(fence_id, entity_id)`. Polled kinds also pass `skip_existing`, so a later poll of the same incident id does not insert again (in-process set, plus a `geofence_alerts` lookup after restart). Fail closed on that lookup so a broken read cannot page every fence. - **Cameras:** `upsert_cameras`, `publish_new_cameras`, and `ingest_event(source_type=camera)` do not call `record_and_notify`. `record_and_notify` refuses `source_kind=camera`. `GET /api/geofence-alerts?source_kind=` now accepts `earthquake|fire_incident|news` and still 422s `camera`. No Telegram, webhook, or other delivery channel. No live fence created. No deploy. ## Test plan - [x] `PYTHONPATH=app pytest tests/test_geofence.py -q` → 27 passed - [x] Inside point → 1 row with `payload.evidence` matching the keys above; outside point → 0 rows, for earthquake, fire_incident, and news - [x] Camera publish/insert does not call `record_and_notify` - [x] Two incidents with the same entity_id inside 5 minutes → 1 row - Known-red CI `docker login 127.0.0.1:3000` is not this change
New hits carry a frozen evidence pack. adsb/ais/firms payloads stay
unchanged, and cameras are never passed to record_and_notify.
sirius merged commit 23286e14da into master 2026-11-17 19:56:56 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
sirius/osint-dashboard!61
No description provided.