Skip to content

feat(dataset): short-circuit unpublished datasets in readme + tree endpoints - #30

Merged
neuromechanist merged 3 commits into
mainfrom
28-clean-unpublished-state-render-when-apidatasetidreadmetree-has-no-published-version
May 19, 2026
Merged

neuromechanist merged 3 commits into
mainfrom
28-clean-unpublished-state-render-when-apidatasetidreadmetree-has-no-published-version

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Summary

Detects `versions: []` / `latest: null` from `data.nemar.org//` (via the existing `getLanding` + new `isUnpublished` pure helper) before any manifest fetch and returns a clean 200 placeholder. Caps worst-case response time at ~1.5s.

Removes the 500-driven retry cascade that was triggering per-IP 429s on the CF edge when users hit datasets that had been onboarded but never published.

What changed

  • `src/lib/data-api.ts` — new `isUnpublished()` pure helper (already had `getLanding`)
  • `src/lib/render-readme.ts` — new `renderUnpublishedReadme()` placeholder
  • `src/lib/render-tree.ts` — new `renderUnpublishedTree()` placeholder
  • `src/pages/api/dataset/[id]/readme.ts` — early-return unpublished path
  • `src/pages/api/dataset/[id]/tree.ts` — early-return unpublished path
  • `src/pages/dataset/[id].astro` — SSR renders unpublished block instead of deferred Readme/QualityPanel/BidsTree
  • `src/lib/data-api.test.ts` — 5 unit tests pinning `isUnpublished` behavior

Test plan

Notes

…dpoints

Detect versions:[] / latest:null via getLanding before attempting manifest
fetch, return a clean 200 with an "unpublished" placeholder. Caps the
worst-case response at ~1.5s instead of 5s+timeout+500, which removes the
500-driven retry cascade that was triggering per-IP 429s at the CF edge.

Affects datasets that were onboarded but never had a published version
(on005506, on005507, and the rest of the original #529 cohort). Fully
published datasets are unchanged.

Closes #28.
@cloudflare-workers-and-pages

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

Copy link
Copy Markdown

- Parallel-fire getLanding + getManifest + getMetadata so unpublished
  detection doesn't add 1.5s serial RTT to the published-dataset budget
  (code-reviewer finding 2)
- Split cache constants: short SWR (60s/300s) for the unpublished branch
  so users don't see 24h of stale "not yet published" after a real
  release; keep 600s/86400s for the published response (silent-failure-
  hunter finding 2, code-reviewer finding 1)
- console.warn when getLanding returns null so a degraded data layer is
  visible in logs rather than silently degrading to the slow path
  (silent-failure-hunter finding 1)
- isUnpublished now uses !landing.latest instead of === null, catching
  the case where the upstream emits "" instead of null
  (pr-test-analyzer gap 3)
- JSDoc on isUnpublished now documents the null contract and the
  why-not-AND choice; redundant JSDocs on render fns removed
  (comment-analyzer findings)
- New tests: renderUnpublishedReadme + renderUnpublishedTree shape
  assertions (pr-test-analyzer gaps 1+2), plus the empty-string latest
  case for isUnpublished

Out of scope (deferred): jsonFetch broad swallow + disambiguating 404
vs 5xx in getLanding null. Pre-existing on main, larger refactor.
@neuromechanist

Copy link
Copy Markdown
Contributor Author

Review findings addressed (commit f925b0f + c8041cc)

From code-reviewer:

  • (1) Renamed UNPUBLISHED_CACHE → PUBLISHED_CACHE + introduced a separate, shorter-SWR UNPUBLISHED_CACHE constant. Tree endpoint now matches the same split.
  • (2) Parallel-fired getLanding + getManifest + getMetadata so unpublished detection no longer adds 1.5s serial RTT to the published-dataset latency budget.
  • (3) Kept OR (not AND) on isUnpublished. Documented the choice in the JSDoc. Rationale: false-positive "unpublished" during a race is recoverable (user refreshes); false-negative lets the 5s-timeout-500 symptom resurface, which is the whole reason for this PR.

From silent-failure-hunter:

  • (1) console.warn on getLanding returning null so a degraded data layer is visible in logs.
  • (2) Split caches: the unpublished branch uses s-maxage=60, stale-while-revalidate=300, so users won't see 24h of stale "not yet published" after a real release.
  • (3) Conflated null cases: kept current behavior because disambiguating 404 vs 5xx from getLanding null requires a bigger surgery in jsonFetch (see deferred below).

From pr-test-analyzer:

  • (1+2) New src/lib/render-unpublished.test.ts: 8 tests pinning the rendered HTML, classes, and role attributes for both renderUnpublishedReadme and renderUnpublishedTree. The role="note" vs role="alert" check is explicit since renderNoManifest already uses role="alert" and the two could easily get swapped.
  • (3) Switched isUnpublished from === null to !landing.latest, catching the empty-string case too. New test added.

From comment-analyzer:

  • Dropped the redundant Unpublished-state placeholder for the README panel. and Unpublished-state placeholder for the file tree panel. JSDocs.
  • Rewrote isUnpublished's JSDoc to document the null contract + the why-not-AND choice.

Deferred to follow-up

silent-failure-hunter finding 4 (jsonFetch broad swallow): pre-existing on main and affects every jsonFetch caller, not just this PR's new ones. Disambiguating timeout vs network-failure vs JSON parse vs 404 needs a refactor of jsonFetch itself + cascading caller updates. Will file as a separate website issue.

silent-failure-hunter finding 3 (404 vs 5xx disambiguation in landing null path): same — depends on the above.

Net result: 120 tests pass (8 new), typecheck clean, biome clean on changed files, no new lint errors introduced (pre-existing debt in render-readme.ts/render-tree.ts unchanged).

neuromechanist added a commit that referenced this pull request May 19, 2026
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
neuromechanist merged commit 31ea24d into main May 19, 2026
1 check passed
@neuromechanist
neuromechanist deleted the 28-clean-unpublished-state-render-when-apidatasetidreadmetree-has-no-published-version branch May 19, 2026 03:23
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.

Clean unpublished-state render when /api/dataset/<id>/{readme,tree} has no published version

1 participant