Skip to content

chore(nws): fetch the zone dataset, verify it, then install it - #449

Merged
seevee merged 1 commit into
seevee:mainfrom
systems-monitor:feat/nws-zone-data-fetch
Nov 27, 2026
Merged

seevee merged 1 commit into
seevee:mainfrom
systems-monitor:feat/nws-zone-data-fetch

Conversation

@systems-monitor

Copy link
Copy Markdown
Contributor

Round 3 of #316. One module, providers/nws_zone_fetch.py, and its tests. Nothing calls it yet, so this changes nothing for any entry.

It does not depend on the offset and placing pull request, and that one does not depend on this. Either can merge first. Both add lines to the same part of AGENTS.md, so whichever merges second may need a one-line rebase, which I will do.

Why

The reader from #434 loads the zone dataset from one fixed path in .storage, and nothing puts a file there. This is the one path by which a download reaches it, and the way to take the file away again.

What it does

Download (async_download_zone_data). The caller gives the address, the SHA-256 it wants, and the hosts it allows. The module takes nothing the answering server says on trust:

  1. The address must be https, with no credentials and no unusual port. Redirects are followed by hand, five at most, and each hop must again be https on an allowed host.
  2. The request asks for no transfer compression, and a response that applies one is refused unread.
  3. Only a 200 is accepted. The body is read in chunks and abandoned past 16 MB or 120 seconds, and a size the server announced must be the size that arrives.
  4. The bytes are verified with the reader's own check before anything is written, and only the dataset asked for is accepted. An older published dataset is refused, so a download cannot roll an install back.
  5. The bytes go to a .part file beside the target and are renamed into place. The .part file is made new each time, private and exclusive, so a link, a named pipe or a stale file left at its path is never opened.
  6. Entries already running are handed the new set.
    Every failure raises ZoneDataFetchError with a reason a screen can show, and leaves the fixed path exactly as it was. A failure never repeats the address.

A file placed by hand (async_adopt_zone_data) goes through the same check before it is used.

Removal (async_remove_zone_data) deletes the file and any .part file under the lock an install holds, so it cannot take half of one. It never raises. This is the removal you asked for in #434. The rule that calls it, when the last entry using the dataset is deleted, comes with the piece that knows which entries those are.

One thing I need from you

Where the dataset will be published. I would suggest a release asset on this repository: the file cap_alerts.nws_zones.jsonl.gz with SHA-256 c985ed4f…ee58, which your build reproduces. The module takes the address from its caller, so nothing in this pull request depends on your answer. The later piece that offers the download does, and it needs the address and the tag and file name you choose.

GitHub serves a release asset through a redirect to another host. The caller has to allow that host, and I have not yet made a real download from GitHub.

How it was checked

  • Gates at the head of the branch: pytest 2564 passed, 18 skipped; cov 98%; flow cov 100%; ruff check ok; ruff format ok; mypy ok.
  • 83 tests, covering every line of the module. Each failure reason is tested with a working file already in place, which must be left byte-identical with no .part file remaining.
  • Each check was removed in turn to confirm a test fails without it: 21 for the download and the write, 6 for the removal.
  • 180,000 generated addresses and redirect chains: every outcome was a body read or a refusal with a reason, and no request went to anything but https on an allowed host.
  • The real dataset (3,660,899 bytes) installed through the download path from a stand-in server and came out byte-identical. With one byte changed it was refused and the file in place was left alone.

Where this sits

It is the fifth of six pieces, sent early because it stands alone and because the address question is better asked now:

  1. Offset position and 2. Placing: the other open pull request.
  2. Local mode in the provider, with no switch.
  3. What the entry shows: counts and a distance on each alert.
  4. Zone data delivery: this module; the offer to download and the repair for a missing file follow.
  5. The switch: the option in the forms, and the README.
    Refs NWS: area-scoped GPS/tracker mode that never sends coordinates (local point matching, multiple areas) #316

Round 3 of seevee#316. The
reader loads the zone dataset from a fixed path, and nothing puts a
file there. providers/nws_zone_fetch.py is the one path by which a
download reaches it, and the way to take the file away again.
Nothing calls it yet, and it does not know where datasets are
published: the caller gives the address and the SHA-256 it wants.

It assumes whatever answers the request is hostile. The address
must be https with no credentials and no unusual port. Redirects are
followed by hand, five at most, each hop https on a host the caller
allowed. The request asks for no transfer compression and a response
that applies one is refused unread. Only a 200 is accepted, the body
is read in chunks and abandoned past 16 MB or 120 seconds, and a
size the server announced must be the size that arrives.

The bytes are verified before anything is written, and only the
dataset asked for is accepted: an older published one is refused, so
a download cannot roll an install back. They are written to a .part
file and renamed into place. The .part file is made new each time,
private and exclusive, so a link, a named pipe or a stale file left
at its path is never opened. Entries already running are handed the
new set. Every failure raises with a reason and leaves the fixed
path as it was. async_adopt_zone_data() accepts a file placed there
by hand through the same check.

async_remove_zone_data() deletes the file and any .part file under
the lock an install holds, so it cannot take half of one. It never
raises: what cannot be removed is logged by name and left.

Refs: seevee#316
@seevee

seevee commented Nov 27, 2026

Copy link
Copy Markdown
Owner

Thanks, this reads clean and I didn't find anything to change in the fetch itself.

On where it's published: a release asset on this repo, as you suggest, under the name you have, cap_alerts.nws_zones.jsonl.gz. It goes on the code release that first pins its hash and stays on that tag, so the address never moves. I'll give you the exact tag when the download piece is up.

I ran async_download_zone_data against the v0.9.0-alpha.3 zip, so that's your real GitHub download done. GitHub answers with one 302 to release-assets.githubusercontent.com. Without that host allowed it stops at blocked. With it the whole body comes in, 375,490 bytes matching the announced size, and it's refused as unrecognised with nothing written. So that's the one extra host.

One nit from the run: the message reads "NWS zone data unrecognised: NWS zone data unrecognised: SHA-256 ...", the reader's prefix gets wrapped again.

Merging this now, the prefix can ride with the next piece.

@seevee
seevee merged commit 8d1c739 into seevee:main Nov 27, 2026
6 checks passed
@seevee

seevee commented Nov 28, 2026

Copy link
Copy Markdown
Owner

@systems-monitor the tag I owed you: the dataset is up on v0.9.0-alpha.3, the first release that lists its hash.

https://github.com/seevee/cap_alerts/releases/download/v0.9.0-alpha.3/cap_alerts.nws_zones.jsonl.gz

I rebuilt it from the April shapefiles today and got c985ed4f again, and your check script passed all ten. The download from GitHub hashes the same. So the download piece can pin that tag and file name, later releases won't carry their own copy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants