Immutable snippets that read microscopy data formats, plus a human-owned harness that samples 256×256
PNG crops through them. SPEC.md is the contract; this README explains it. The mia-data worker (in
temporal-prototype) drives everything: it matches datasets to snippets, asks autodev to write a snippet when
none fits, tests the result on real data, and crops in production once a human approves.
One directory, snippets/<name>/, added once and never changed:
snippets/<name>/
├── snippet.py SPEC_VERSION = 1 and open_array(src: Source, io: IO) -> Array
├── snippet.yaml name, formats, containers, params schema, requires, tested_on, supersedes
├── README.md what it reads, how params are chosen, known limits
└── examples/<record-id>.yaml ≥ 1 binding it was tested on
snippet.py does one thing: given a Source (file URLs and params from a binding) it returns an Array, an
object with axes (letters from czyx), shape, dtype, voxel_size_nm, access (chunk, plane or
file: the cheapest unit this file can be read in) and read(region). It must not read voxel data until
read is called. Everything else, sampling, filtering, stretching to PNG, overlays, provenance, is the
harness's job, so every crop in the system goes through the same code.
Rules a snippet lives by (SPEC §2, §3):
- Type hints are required.
from mia_harness.api import IO, Array, Sourceand annotateopen_arrayexactly as above. CI rejects an unannotatedopen_array. (tiff-zip-memberandmrc-httppredate this rule and stay as tested; immutability wins over tidiness.)mia_harness.apiis the only harness module a snippet may import; it also exports the exceptionsNeedsFetch,HostNotAllowedandBudgetExceeded. - All bytes come through
io.io.open(url)is a seekable range-backed file,io.fetch(url)stages the whole file,io.list(url)lists zip members.ioenforces the job's byte cap and host allowlist and records validators for provenance. A snippet never usesrequests,urllib,fsspec, sockets, subprocesses,pickle, or writes outsideio's staging. - Pure, independent reader. No cropping, resampling or normalising. No imports of other snippets; shared
code becomes a new snippet. Dependencies must be on
harness/allowlist.txt; an agent that needs a new one reports it, and a human extends the harness environment. - Immutable. A fix is a new directory (
tiff-zip-member-2) whosesnippet.yamlsetssupersedes. A wrong snippet is listed inWITHDRAWN.yamlby a maintainer, never edited or deleted (SPEC §6).
A binding (SPEC §4) is the data that connects a dataset to snippets: which snippet reads which URLs with which params, how labels pair with raws, and a reason for every non-default choice. Agents write bindings; humans approve them.
Four layers, cheapest first. A snippet reaches production only by passing all of them.
- Static CI on every PR (
ci/check_pr.py, run by.github/workflows/check.yml). A PR may only add files under one newsnippets/<name>/; changing anything existing fails unless the author is inci/maintainers.txt.snippet.yamlmust validate: name matches the directory and is unused, everyrequiresis on the allowlist, everytested_onhas an example.snippet.pyis parsed, not run: banned modules and calls,allow_pickle, imports of other snippets or of harness internals, a literalSPEC_VERSION = 1, and a fully annotatedopen_array. CI runs the checker, maintainers and allowlist as they are onmain(--base origin/main), so a PR cannot loosen its own check. - The loader, before any snippet code runs (
harness/src/mia_harness/loader.py). It refuses a withdrawn or superseded snippet, aspec_versionother than 1, a name mismatch, or binding params outside the declared schema. After import it checksSPEC_VERSIONand a callableopen_array, andapi.check_arrayvalidates every opened array's axes, shape and access. - Real-data test crops, published as a required commit status. The mia-data worker runs two sandboxed
cluster jobs against the exact PR head:
harness crop --n 4, thenharness verifyandharness previewin a separate job that loads no snippet code, so a snippet cannot forge its own report. Verify checks every PNG decodes at the right size and bit depth, the box lies within the recorded shape, the content and overlap filters pass, labels are present,crop.jsonis complete and checksums are unique. The worker posts the crops on the PR and setsmia-data/cropson that SHA. After merge, a tree-hash comparison confirms the merged snippet is the one that was tested. Hand-written snippets go through the same path viamia-data test-pr. - Harness unit tests (
cd harness && pixi run test) cover the harness and the snippets in this repo, loaded through the real loader over a local range server (tests/test_snippet_*.py). CI-checker tests:cd harness && pixi run ci-test.
Comments and labels never authorise a merge; only the two required statuses and a review do.
harness/ is a pip-installable package with a CLI (SPEC §7): smoke opens every array in a binding and
reads one patch, crop samples and writes crops, verify checks a crop directory without loading snippets,
preview draws label overlays. Humans own it; agents use it and never modify it. Jobs pin the harness
checkout's commit and pixi.lock digest when a round is admitted, and refuse to run if either moved.
Set on main once the repo exists (not applied yet):
- require the status checks
checkandmia-data/crops(the latter restricted to the mia-data app, once it exists); - require one approving review; dismiss stale approvals.
PRs that touch nothing under snippets/ get mia-data/crops = success from the poller. Until the poller
runs, merge maintainer PRs by review alone, before protection is switched on. Changes to .github/ itself
remain guarded only by the required review and autodev's refusal of agent commits that touch .github/.