Skip to content

Feature: GET /<id>/<version>/records.json and manifest.bytes_urlΒ #615

Closed
5 of 5 issues completed
Closed

Description

@bruAristimunha

Hi @neuromechanist πŸ‘‹

First, congratulations on the new data.nemar.org stack β€” nemar-cli,
neuroschema, nemar-citations, the central manifest epic (#559).
The metadata.json contract is already in beautiful shape, and reading
through dataset-metadata-columns.ts, llm-enrich.ts, and
emit_manifest.py made it obvious how much of what we need is
already computed on your side.

This issue is a small feature request to surface two pieces of data
the system already produces internally, so EEGDash (and any other
consumer β€” the nemar.org frontend would benefit too) can stop
re-deriving them. Happy to send PRs and/or co-design any part of it.

Companion technical write-up with the EEGDash-side cleanup that
this unblocks (~1,300 lines of NEMAR-specific code we'd retire):
08-NEMAR-API-SIMPLIFICATION.md.


What we'd love to see

Two additions, both small relative to the central manifest pattern
you already shipped:

  1. GET /<id>/<version>/records.json β€” array of per-data-file
    neuroschema record documents (one per .edf / .bdf / .vhdr /
    .set / .fif / .snirf). Conforms to
    nemarOrg/neuroschema:schema/core/record.schema.json v0.3.0.
  2. bytes_url field on every manifest.json file entry β€” a
    stable HTTPS URL that returns the actual data bytes (the S3
    public URL resolved from the annex key, or the raw GitHub URL
    for git-tracked files). Today consumers resolve s3://nemar/<key>
    by convention; the field would make that contract.

records.json example

[
  {
    "schema_version": "0.3.0",
    "doc_type": "record",
    "dataset": "nm000110",
    "bids_relpath": "sub-chb01/eeg/sub-chb01_task-rest_run-01_eeg.edf",
    "modality": "EEG",
    "datatype": "eeg",
    "suffix": "eeg",
    "file_extension": ".edf",
    "entities": { "subject": "chb01", "task": "rest", "run": "01" },
    "signal_summary": {
      "nchans": 23,
      "ntimes": 921600,
      "recording_duration": 3600.0,
      "channel_type_counts": { "EEG": 21, "EOG": 2 }
    },
    "provenance": {
      "extracted_at": "2026-05-24T06:14:00Z",
      "extractor_version": "0.1.0"
    }
  }
]

signal_properties is intentionally absent when nothing diverges
from dataset.signal_defaults β€” BIDS inheritance applies
(see neuroschema/docs/inheritance.md).

Per-channel arrays (full ch_names, sidecar JSON, TSV content)
belong in the rawDetail extension and a separate endpoint β€” out
of scope here.

manifest.json addition

One backward-compatible field per file entry:

{
  "path": "sub-chb01/eeg/sub-chb01_task-rest_run-01_eeg.edf",
  "size": 124573612,
  "checksum_algorithm": "git",
  "checksum": "abc123...",
  "url": "https://raw.githubusercontent.com/nemarDatasets/nm000110/v1.0.1/...",
  "bytes_url": "https://nemar.s3.us-east-2.amazonaws.com/SHA256E-s124573612--abc123.edf"
}

For git-tracked files (checksum_algorithm: "git"), bytes_url
equals the existing url. For annex-keyed files it resolves to the
S3 public URL.

Architecture (mirrors #559)

No new infra needed. Same repository_dispatch β†’ central workflow on
nemarDatasets/.github β†’ S3 β†’ webhook callback pattern that #559
established for manifest.json:

[Tag pushed on nemarDatasets/<id>]
      ↓ (existing GH App webhook, #559)
[POST /webhooks/dataset-release]
      ↓
[triggerManifestGeneration()]    ← already exists; adds bytes_url
[triggerRecordsGeneration()]     ← new dispatch, parallel
      ↓
[generate-manifest.yml + generate-records.yml on nemarDatasets/.github]
      ↓
[s3://nemar/<id>/version/v<X.Y.Z>.json           ← manifest + bytes_url]
[s3://nemar/<id>/version/v<X.Y.Z>-records.json   ← new]
      ↓
[POST /webhooks/manifest-ready]
[POST /webhooks/records-ready]   ← new
      ↓
[GET /<id>/<version>/records.json]   ← new route on data.ts

Stability β€” open to your guidance here

Drafted following the patterns from epic #559 / #557. None of this
is novel; flagging the bits where a stricter or looser default would
help you.

  • Feature flag RECORDS_VIA_CENTRAL_WORKFLOW (default false),
    mirrors MANIFEST_VIA_CENTRAL_WORKFLOW. Per-env flip; dev first,
    prod after a week of clean runs.
  • Idempotency: records_jobs (dataset_id, version) UNIQUE.
    Re-dispatching reuses the row when artifact exists + status is
    uploaded, replaces it when failed or older than a 7-day TTL.
  • Callback HMAC: same one-shot HMAC as
    /webhooks/manifest-ready. Store sha256(callback_token) in
    records_jobs.callback_token_hash; never the secret.
  • S3 liveness probe: HEAD before serving. 502 with
    reason: "artifact_unreachable" on HEAD failure. 404 with
    reason: "records_pending" + Retry-After: 60 for versions
    whose dispatch is still in-flight.
  • Schema validation in CI: one workflow step running
    python -m neuroschema.validate --doc-type record --array …
    against the emitter's test-fixture output. Pinned neuroschema
    version; un-pinned upgrades land as a separate PR.
  • Graceful degradation: records emission is fire-and-forget.
    The publish flow does not block on it β€” DOI + manifest succeed
    independently. A nemar admin records replay --since 24h
    command re-dispatches failed rows.
  • Rate limits: repository_dispatch is 5,000/hour per token, so
    the dispatch rate is safe. CF cache on data.nemar.org carries
    the read load (Cache-Control: public, max-age=300 + ETag would
    be ideal β€” happy to bundle ETag in this issue or split).
  • Observability: three structured log events per dispatch
    (records.dispatch, records.ready, records.served); one
    dashboard panel β€” count(records.ready) / count(records.dispatch)
    over 24h.
  • Rollback: flip the flag off β†’ route 404, dispatch no-op, no
    data lost. bytes_url is a purely additive field β€” removable
    with a one-line revert.

Suggested rollout

Week Records endpoint Manifest bytes_url
1 flag on in dev added in dev manifests
2 dev only, monitoring dev only
3 flag on in prod for new versions added in prod for new versions
4–6 backfill old prod versions via re-dispatch backfill via same script
7+ EEGDash + frontend cut over EEGDash + frontend cut over

Old consumers see new fields appear; nothing requires immediate action.
No coordinated cutover.

Out of scope (separate issues, happy to file if useful)

  • LLM enrichment of records (already covered by your llm-enrich.ts).
  • dataQuality extension (frame retention, ICA stats) β€” owned by
    nemar-pipeline; separate issue.
  • Per-subject demographics (age, sex, handedness, pathology dict).
  • rawDetail extension β€” per-channel arrays, full sidecar JSON;
    needs its own endpoint and access policy.
  • MEF3 and CTF (.ds directory) header parsers β€” propose v0.2 of
    the emitter; v1 covers EDF / BDF / BrainVision / EEGLAB / FIF /
    SNIRF.

Two tiny companion PRs on nemarOrg/neuroschema

Both one-line fixes against v0.3.0 that block EEGDash adoption.
Happy to send these against neuroschema directly if you'd like:

  1. schema/core/record.schema.json line 20:
    "pattern": "^ds[0-9]+$" rejects every nm* and on* record.
    Change to "^[a-z]{2}[0-9]+$" (matches dataset_id in
    dataset.schema.json).
  2. schema/extensions/eegdash.schema.json line 14:
    storage.backend enum is missing "nemar". EEGDash uses it
    for the git-annex key resolution backend.

Open questions for you

  1. Header readers in the central workflow vs. SDSC. The QA
    pipeline already reads every file with EEGLAB and writes MAT
    files. Re-reading with MNE in the new workflow duplicates that.
    Would you prefer (a) parsing the MAT files (no MNE dependency in
    the workflow, but cross-system coupling), or (b) re-reading with
    MNE (simpler, more isolated)? My draft assumes (b); easy to
    pivot.
  2. on* (OpenNeuro mirror) coverage. Should records emission
    fire for on* datasets too, or stay nm*-only initially? EEGDash
    would benefit from parity but understands if on* BIDS
    validation differs.
  3. ETag / If-None-Match on the JSON endpoints. Cheap to add;
    lets downstream consumers conditional-fetch. Bundle in this
    epic, or split into a follow-up?
  4. Webhook for third parties. EEGDash would happily subscribe
    to a records-ready push event instead of polling β€” the
    backend/src/routes/webhooks.ts infra already exists. In scope
    here, or a separate ask?

What this unblocks

After this lands, EEGDash retires three helper scripts (patch_nemar_source.py,
patch_nemar_records_storage.py, inject_nemar_citations.py),
drops the MNE branch from its ingestion pipeline, and converges its
NEMAR path with the Zenodo/OSF path: trust the upstream JSON, fetch
incrementally, upsert. Net ~1,300 lines removed. The nemar.org
frontend gains the same JSON contract and can stop calling the
legacy PHP dataexplorer API.

Truly grateful for the work you've put into the neuroschema spec
and the central manifest pattern β€” this issue is small precisely
because the heavy design lifting is already done. Let me know what
shape works best for you and I'll send PRs as soon as the architecture
is locked.

Thanks again πŸ™

Sub-issues

Sub-issues

5 of 5 Issues completed
Loading 5 sub-issues

Activity

  1. neuromechanist commented on Jun 5, 2026

    @neuromechanist
    Contributor

    Hi Bruno β€” thank you for the unusually well-scoped issue; the fact that it maps almost 1:1 onto the central-manifest pattern is exactly why it's easy to say yes. We've locked the design on our side. Summary of decisions so you can send PRs against a stable contract, plus answers to your four questions and a separate note on nemar-py.

    records.json β€” yes, with one internal refinement

    Your consumption contract is accepted as-is: GET /<id>/<version>/records.json returning an array of neuroschema record docs, one per primary signal file.

    The only change is internal and invisible to consumers: records.json is the committed .nemar/records.json in the dataset repo (git-versioned, captured by the version tag, offline in full clones β€” same pattern as .nemar/metadata.json), and the version/v<X>-records.json S3 snapshot is the served copy behind the endpoint. So you fetch the exact URL you proposed; we just also keep a git-provenanced source of truth. Cache: s-maxage=86400 (immutable per version).

    signal_summary source β€” sidecar-first, not an MNE re-read

    We're not re-reading every file with MNE (your Q1 option b). Instead, a tiered cascade that resolves ~99% from the git tree alone:

    1. Git walk (default): BIDS *_eeg.json/*_meg.json sidecars (RecordingDuration, SamplingFrequency, *ChannelCount) + channels.tsv (authoritative for nchans and channel_type_counts) via git cat-file β€” no header read, no annex fetch. This mirrors your own 3_digest.py precedence, so we should land on identical numbers.
    2. biosigIO mid-product (fallback): for the gaps (notably MEG, where BIDS has no RecordingDuration field), we read the metadata our Zarr converter already produces with biosigIO (duration_s = n_samples/rate) β€” we read the computed mid-product, not a re-conversion.
    3. biosigIO importers (last resort): for BIDS-approved formats biosigIO can't read yet (CTF .ds, KIT/4D, .snirf), we'll add importers upstream to biosigIO so it stays the single reader, rather than bolting MNE into the emitter. Until an importer lands, those rare recordings ship recording_duration: null (graceful degradation).

    channel_type_counts always comes from channels.tsv β€” note the Zarr per-channel channel_type is EEGLAB-derived and not faithful, so please don't source it from the store. We'll set a per-record provenance.duration_source (sidecar | biosigio | null) so you can distinguish "pending" from "absent".

    bytes_url β€” yes, additive, but same-origin (not raw S3)

    We'll add bytes_url to every manifest entry, but pointing at the data.nemar.org origin (https://data.nemar.org/<id>/<version>/<bids_relpath>, which 302s to the bytes), not the raw S3 host. Two reasons:

    1. Your example https://nemar.s3.us-east-2.amazonaws.com/SHA256E-...edf is actually wrong β€” blobs are content-addressed at <id>/objects/<annexKey>, not at a BIDS path, so that URL 404s. The correct stable raw form would be https://nemar.s3.us-east-2.amazonaws.com/<id>/objects/<annexKey>.
    2. A same-origin bytes_url keeps the official Python client's assert_within honest.

    For EEGDash's anonymous-s3fs fast path you don't need a raw-S3 bytes_url: the manifest already exposes the annex key, and <id>/objects/<key> is the stable public object URI (bucket is public-read post deny-list inversion). For git: files bytes_url == url == raw.githubusercontent.com/....

    neuroschema

    • record.dataset FK pattern β€” fixed: fix: align record.dataset FK pattern to dataset_idΒ neuroschema#10 sets it to ^[a-z]{2}[0-9]+$, bit-identical to dataset_id. You were spot on that ^ds[0-9]+$ rejects every nm*/on*. We framed it as completing the half-applied v0.3.0 relaxation (the FK twin was missed in ff27f7b). No schema_version bump.
    • eegdash.storage.backend enum + "nemar" β€” this one we'd push back on: backend is a transport discriminator (s3/https/local), and "nemar" is a provider/host (data.nemar.org is plain HTTPS over S3 blobs, both already expressible). Suggest a separate optional provider field rather than overloading the transport enum. It's your extension, so your call β€” happy either way, just flagging the semantics.

    Your four questions

    1. Header readers β€” MNE vs reuse? Reuse the biosigIO pass (see above); MNE only as upstream biosigIO importers for the unsupported long-tail.
    2. on* coverage? In scope. biosigIO already reads on* recordings (several are in our converted set), and records.json rides the same data plane that serves on* today.
    3. ETag / 304 on the JSON endpoints? Defer to a follow-up. records.json is s-maxage=86400-immutable per version and the client verifies against body checksums, not HTTP ETag, so 304 buys little now.
    4. records-ready webhook for third parties? Defer; the polling + cache story is fine for v1. Easy to add later on the existing webhook infra if EEGDash wants a push.

    One thing to decide together: the storage block

    Your example record carries only signal_summary and omits storage. EEGDash's loader hard-requires storage{backend, base, raw_key, dep_keys} (esp. dep_keys to prefetch channels.tsv/events/.fdt before the raw file). So records.json with only signal_summary won't let EEGDash drop its dep-walk β€” the "~1,300 lines retired" is overstated without it. Proposal: v1 = signal_summary (ships now), v2 = optional storage/dep_keys block once the core lands and validates. Want to co-design the v2 storage shape? (Separately: I couldn't find patch_nemar_source.py / patch_nemar_records_storage.py in any EEGDash branch I fetched β€” the retireable code I see is 3_digest.py:extract_record. Point me at the right branch if I'm looking in the wrong place.)

    The 429s (your earlier report)

    Fixed in #699 β€” the data plane now gets a dedicated, much larger rate-limit bucket so a parallel --jobs 16 download doesn't trip the anonymous cap. (For context, the "many 302s" you saw are expected: the per-file route 302-redirects to the bytes; nothing's wrong there. And the earlier 403s were the pre-deny-list private/missing-object behavior, now resolved.)

    nemar-py β€” validated, recommend it with a short punch-list

    I ran a full pass of nemar-py against the hardened contract. Net: safe to recommend for the standard download() flow today. Solid parts: the checksum_algorithm/checksum split parse, content-hash verification (incl. the git: blob-SHA1 framing), version-tag normalization, path-traversal hardening, and the JSON control-plane same-origin check. Client items worth a small PR:

    • H3 (the real one): _entry_to_file can't parse the raw version/v<X>.json shape ({key, size, checksum:"sha256:<hex>"}, no url) that s3.version_url points at β€” it falls back to size-only verification. Split a bare <algo>:<hex> checksum on the first : and recover algo+hash from the annex key; or route all manifest reads through manifest.json (the split shape the parser already handles).
    • H1 (doc honesty): _endpoint.py's "scoped to data.nemar.org" claim is a no-op for file bytes (per-file assert_within is intentionally not called, and every manifest url is off-origin by design). Either re-enable the check against a trusted-netloc allow-list (data.nemar.org, nemar.s3.us-east-2.amazonaws.com, raw.githubusercontent.com) or soften the docstring to match reality.
    • bytes_url forward-compat: add bytes_url to _first_value's url-key list so a future bytes_url-only entry doesn't synthesize a path-relative URL.
    • Minor: honor Retry-After on 503/429; make DatasetIndex.latest Optional[str] (we return 200 + latest:null for exists-but-unpublished).

    (One I initially over-weighted and am now standing down: expired-presign mid-download. The default auto path is direct anonymous S3 with no presigned URL, and the data plane is public-only, so it doesn't bite the normal flow β€” not a blocker.)

    Confirming the structure you assumed (objects/, version/<v>.json, version/<v>-summary.json, archives/<v>.zip) and the s3 β†’ datalad β†’ https order both match our roadmap, so you're building against the right contract.

    Thanks again β€” send the neuroschema follow-ups and nemar-py PRs whenever; we'll take the emitter + route + bytes_url on our side and ping you for the v2 storage co-design.

  2. neuromechanist commented on Jun 8, 2026

    @neuromechanist
    Contributor

    @bruAristimunha both parts of this are now implemented and live on production. πŸŽ‰

    1. records.json

    Endpoint: GET https://data.nemar.org/<id>/<version>/records.json

    Shape: a JSON array of neuroschema v0.3.0 record documents β€” one per primary signal file (.edf/.bdf/.set/.vhdr/.fif/...). Each record carries:

    {
      "schema_version": "0.3.0",
      "doc_type": "record",
      "dataset": "nm000132",
      "modality": "EEG",
      "datatype": "eeg",
      "suffix": "eeg",
      "file_extension": ".set",
      "bids_relpath": "sub-01/eeg/sub-01_task-..._eeg.set",
      "entities": { ... },
      "signal_summary": {
        "nchans": 33,
        "ntimes": 622592,
        "recording_duration": 608,
        "sampling_frequency": 1024,
        "channel_type_counts": { ... }
      }
    }

    Durations are resolved from the BIDS sidecar first, then via a biosigIO header read for files whose sidecar omits RecordingDuration (so MEG/EEG without that field still get a value; the rare formats biosigIO can't read yet degrade to recording_duration: null).

    Coverage: the full backfill is done β€” every published version (latest + older) has a records.json snapshot, so nothing 404s. Going forward, it's emitted automatically on each version publish.

    2. manifest.bytes_url

    Every entry in GET /<id>/<version>/manifest.json now has an additive, same-origin bytes_url:

    • git keys β†’ raw.githubusercontent.com/...@<tag>
    • annex keys β†’ https://data.nemar.org/<id>/<version>/<path> (302s to a fresh presigned S3 URL each request β€” no expiry to manage). Same-origin so nemar-py's assert_within accepts it.

    Bonus

    The data.nemar.org/<id>/ index pages now link records.json next to manifest.json (version table + per-version footer), so it's discoverable by browsing.

    Known scope / possible v2

    records.json currently carries signal_summary but not a storage block (backend/base/raw_key/dep_keys). If EEGDash wants to drop its dep-walk entirely, let's decide together whether records.json should add that block. Also tracking a couple of follow-ups (biosigIO importers for CTF .ds/KIT MEG; a sampling_frequency edge case) β€” happy to coordinate.

    Released in nemar-cli v0.8.48 (route + bytes_url) and v0.8.49 (index links). Leaving this open for the v2 storage-block discussion β€” let me know how you'd like to proceed.

  3. added
    P2
    backend
    feature
    on Jun 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2backendfeature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions