Skip to content

feat(dataset): consume compact summary.json with manifest fallback - #31

Merged
neuromechanist merged 3 commits into
mainfrom
29-use-compact-summaryjson-instead-of-full-manifestjson-for-dataset-detail-page
May 19, 2026
Merged

neuromechanist merged 3 commits into
mainfrom
29-use-compact-summaryjson-instead-of-full-manifestjson-for-dataset-detail-page

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Summary

The dataset detail page's `/api/dataset//readme` and `/tree` endpoints now fetch `data.nemar.org///summary.json` first (compact, no presigned URLs, ~50-200 KB) and fall back to the full manifest if absent.

Fully backward compatible. Activates automatically per-dataset once summary.json starts being published (companion: nemarOrg/nemar-cli#558).

Why this matters

Today the public `manifest.json` is 5-10+ MB for typical BIDS-EEG datasets because the worker mints a presigned S3 URL into every file entry on every request. The website only uses paths + readme; we're shipping 10 MB to use 50 KB. First-load times out, second browser is the CF edge cache making the bloat warm — that's the "switching browsers fixed it" symptom users report.

Dataset manifest.json (target) summary.json
on005261 10.5 MB ~150 KB
nm000103 7.9 MB ~120 KB

What changed

  • `src/lib/data-api.ts` — `Summary` interface, `getSummary()` fetch helper, `findReadmePathInSummary()` pure helper
  • `src/lib/bids-tree.ts` — new `buildTreeFromPaths(paths: string[])` that builds the same tree shape as `buildTree(manifest)` but from a flat path list
  • `src/pages/api/dataset/[id]/readme.ts` — fast path: summary + GitHub raw README (no presigned URL). Slow path: original manifest-based code unchanged.
  • `src/pages/api/dataset/[id]/tree.ts` — fast path: `buildTreeFromPaths` on `summary.paths`. Slow path: original `buildTree` on manifest unchanged.
  • `src/lib/data-api.test.ts` — 8 unit tests for `findReadmePathInSummary`
  • `src/lib/bids-tree.test.ts` — 4 unit tests for `buildTreeFromPaths`

Test plan

  • `vitest run` — 119/119 pass (12 new tests)
  • `astro check` — 0 errors, 0 warnings, 0 hints
  • `biome check` on changed files — clean
  • `astro build` — succeeds
  • Post-deploy + after nemar-cli#558 lands: `/dataset/on005261` loads sub-1s on cold cache (was 8-15s)
  • Pre-summary datasets continue rendering correctly via fallback

Notes

Fast path when data.nemar.org/<id>/<version>/summary.json is available:
the readme + tree endpoints build the tree from summary.paths (a flat
path list, ~50-200 KB regardless of dataset size) and locate the README
via summary.readme.path + GitHub raw fetch. No presigned-URL transcript
download (which is 5-10+ MB on real BIDS-EEG datasets).

Slow path is the current code path entirely unchanged: fetch the full
manifest, find README, build tree. Activates automatically when summary
is absent.

This PR is fallback-safe: until the data layer starts emitting
summary.json (nemarOrg/nemar-cli#558), the slow path runs and behavior
is identical. Once the artifact lands for a dataset, the fast path
activates for it with no website redeploy.

Refs nemarOrg/nemar-cli#558. Closes #29.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 19, 2026 •

Copy link
Copy Markdown

Critical:
- readme.ts: fast path no longer silently drops the README when a
  dataset has no GitHub URL or the GH fetch fails. Now always falls
  through to the manifest path before settling for description.
  (code-reviewer finding 1, silent-failure finding 2)

Important:
- tree.ts: validate summary.paths is a non-empty array before using;
  fall through to manifest with a console.warn if summary is malformed
  or partial. (silent-failure finding 3)
- console.warn on getSummary returning null in both endpoints so
  degraded data-layer is visible in logs. (silent-failure finding 4)
- readme.ts module JSDoc rewritten to reflect actual 4-step resolution
  order; old JSDoc was misleading. (comment-analyzer finding 1)
- findReadmePathInSummary JSDoc now documents the priority order +
  why subdirectory READMEs are intentionally skipped (BIDS spec).
  (comment-analyzer finding 4)
- buildTreeFromPaths JSDoc explains the synthetic-filler choice +
  notes the renderer doesn't read entry.url. (comment-analyzer finding 3)

Tests:
- Pin "subdirectory README is ignored" (locks in BIDS-spec contract)
- Pin "malformed segments don't throw" for buildTreeFromPaths

Out of scope (PR comment):
- jsonFetch broad-swallow (pre-existing on main; same as #30's deferred)
- archiveZipUrl comment drift (pre-existing on main)
- bids-tree.ts pre-existing inline comments (not touched by this PR)
- Pure-helper extraction for endpoint branching (refactor; not blocking)
- render-tree url="" finding was a false positive — render-tree.ts
  builds anchors from basePath+path and never reads entry.url
@neuromechanist

Copy link
Copy Markdown
Contributor Author

Review findings addressed (commit 34ae52e)

Critical:

  • readme.ts fast path no longer drops the README when summary says "README exists" but GitHub isn't reachable (no external_links.github_url, GH down, or the README isn't actually served at the GH raw URL). Now falls through to the manifest-based path before settling for the description fallback. This was a real regression for datasets without a linked GitHub repo. (code-reviewer 1, silent-failure 2)

Important:

  • tree.ts validates summary.paths is a non-empty array before using it. If summary is malformed or partial, falls through to the manifest with a console.warn. (silent-failure 3)
  • console.warn on getSummary returning null in both endpoints, so a degraded data layer is visible in production logs instead of silently activating the slow path on every request. (silent-failure 4)
  • readme.ts module JSDoc rewritten to reflect the actual 4-step resolution order. Previous JSDoc implied summary-present alone activates the fast path; in reality it requires both summary AND a resolved readme path. (comment-analyzer 1)
  • findReadmePathInSummary JSDoc now documents the priority order (explicit summary.readme.path wins over scan) and why subdirectory READMEs are skipped (BIDS treats only the root README as canonical). (comment-analyzer 4)
  • buildTreeFromPaths JSDoc explains the synthetic zero-size + empty-string filler choice + notes the renderer doesn't read entry.url. (comment-analyzer 3)

Tests:

  • Pin "subdirectory README is ignored" in findReadmePathInSummary — locks in the BIDS-spec contract.
  • Pin "malformed segments don't throw" in buildTreeFromPaths — covers the empty / slash-only / trailing-slash edge cases the analyzer flagged.

Deferred / declined:

  • silent-failure 1 (jsonFetch broad swallow): pre-existing on main; same as PR feat(dataset): short-circuit unpublished datasets in readme + tree endpoints #30's deferred jsonFetch refactor. Larger surgery best done as a standalone PR that updates every jsonFetch caller at once.
  • comment-analyzer 2 (archiveZipUrl comment drift): pre-existing comment, not introduced by this PR.
  • comment-analyzer 5 (bids-tree.ts inline comments): pre-existing on main, not in this PR's diff.
  • pr-test-analyzer 3 (extract selectTreeSource/selectReadmeSource): refactor that improves testability but doesn't fix a bug. Worth filing as a follow-up; not blocking this PR.
  • code-reviewer 2 (download links broken when url=""): false positive. src/lib/render-tree.ts builds download anchors from basePath + entry.path (lines 54, 86) and never reads entry.url. Verified: data.nemar.org/<id>/<version>/<bidsPath> returns HTTP 200 — the path-based form is the canonical download route, signed on demand by the worker. The empty url filler in buildTreeFromPaths is harmless.

Net result: 121 tests pass (2 new), typecheck clean, biome clean on changed files, no new lint errors introduced.

…yjson-instead-of-full-manifestjson-for-dataset-detail-page

# Conflicts:
#	src/lib/data-api.test.ts
#	src/pages/api/dataset/[id]/readme.ts
#	src/pages/api/dataset/[id]/tree.ts
@neuromechanist
neuromechanist merged commit 5db8ded into main May 19, 2026
1 check passed
@neuromechanist
neuromechanist deleted the 29-use-compact-summaryjson-instead-of-full-manifestjson-for-dataset-detail-page branch May 19, 2026 03:27
neuromechanist added a commit that referenced this pull request May 19, 2026
Replaces the unconditional T|null contract of jsonFetch with a
FetchOutcome<T> discriminated union covering: ok, not_found,
rate_limited, upstream_error, timeout, network_error, parse_error.
Every previously-throwing path (AbortError, JSON parse, network/DNS
failures) is now caught + tagged so callers can distinguish "the
resource genuinely doesn't exist" from "the data layer is degraded."

Legacy T|null API preserved via jsonFetchOrNull (used by the four
existing getX helpers); new *Outcome variants are introduced for
callers that need the discriminant.

Behavioral changes (user-visible):
- /dataset/<id> SSR: real 404 only when BOTH landing and metadata are
  not_found. Degraded responses (timeout, 5xx, parse error) now return
  503 instead of silently 404ing, so monitoring distinguishes typo'd
  URLs from data-layer outages.
- /api/dataset/<id>/{readme,tree}: explicit 404 when landing is
  not_found, short-circuiting the manifest fall-through that would
  otherwise render a misleading "no manifest" state for missing
  datasets.

Also sweeps the archiveZipUrl comment drift flagged on PR #31 — the
old comment referenced a `download/<id>/<v>.zip` path that doesn't
exist in the code.

Closes #32.
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.

Use compact summary.json instead of full manifest.json for dataset detail page

1 participant