Skip to content

Phase 3: page-bundle endpoint for one-RTT dataset detail SSR - #624

Merged
neuromechanist merged 2 commits into
feature/issue-618-epic-summary-11from
feature/issue-621-phase3-page-bundle
May 26, 2026
Merged

neuromechanist merged 2 commits into
feature/issue-618-epic-summary-11from
feature/issue-621-phase3-page-bundle

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Summary

New GET /<id>/page-bundle.json?v=<v> on data.nemar.org returns landing + enriched metadata + summary + catalog row in one response so the website can render the dataset detail page from a single SSR fetch instead of its current 4-parallel-SSR + 2-deferred-client waterfall.

Each upstream is wrapped in Promise.allSettled and surfaces as a tagged-union component ({ok: true, data} | {ok: false, error}). Partial-failure responses use Cache-Control: no-store so a transient blip isn't pinned at the CF edge for 24h via SWR; the success path gets public, max-age=60, s-maxage=300, stale-while-revalidate=86400.

Closes #621
Phase 3 of epic #618.

Design notes

  • Manifest skipped — the website renders the BIDS tree progressively from summary.paths (per Progressive BIDS tree: render skeleton sync, lazy-load subject contents website#64), so metadata.bids_index would be unused work. The full /<id>/metadata.json endpoint still serves the complete index for the rare consumer that needs it.
  • pickVersion is forgiving — unknown or empty ?v= falls back to landing.latest rather than 404-ing the whole bundle. The consumer can render a "version not found, showing latest" UI from the bundle's own data.
  • Route registration order — /:datasetId/page-bundle.json is registered immediately after /:datasetId/metadata.json and before /:datasetId/:version so Hono doesn't capture page-bundle.json as a version.

Why it's safe to ship before the website consumes it

Additive endpoint with no behavior change to existing routes. The website agent has nemarOrg/website#63/#64/#65 in flight and will hit this once it's live; until then nothing breaks.

Test plan

  • bun test test/page-bundle.unit.test.ts — 10/10 pass (pickVersion + settled wrapper)
  • cd backend && bun run typecheck — clean
  • Post-deploy smoke: curl -s https://data.nemar.org/on005505/page-bundle.json?v=v1.0.0 | jq '{complete, version, landing: .landing.ok, metadata: .metadata.ok, summary: .summary.ok}' returns all true
  • Post-deploy smoke: a known-unpublished dataset returns complete: true, summary: {ok: true, data: null} (no published version is not a failure)
  • Post-deploy smoke: requesting a bad version returns version: <latest>, complete: true

Companion

Phase 3 of epic #618 / Closes #621.

New `GET /<id>/page-bundle.json?v=<v>` returns landing + enriched
metadata + summary + catalog row in one JSON response so the website
can render the dataset detail page in a single SSR fetch instead of
its current 4-parallel-SSR + 2-deferred-client waterfall.

Internals:
- backend/src/services/page-bundle.ts owns the fan-in. Each upstream is
  wrapped in Promise.allSettled and surfaces as a tagged union
  ({ok: true, data} | {ok: false, error}) so a single failure doesn't
  blank the whole bundle.
- bundle.complete drives the cache header: success path gets long
  s-maxage + SWR, partial-failure path gets no-store so a transient
  blip isn't pinned at the edge for 24h.
- Skips the latestManifest read (multi-MB) — the website renders the
  tree progressively from summary.paths per nemarOrg/website#64, so
  metadata.bids_index would be unused work here.
- pickVersion falls back to landing.latest when the requested version
  is missing or unknown rather than 404-ing the whole bundle; the
  consumer can render a 'version not found, showing latest' UI from
  the bundle's own data.

Route is registered before /:datasetId/:version so Hono doesn't treat
'page-bundle.json' as a version param. Mirrors the metadata.json
registration order.

Tests: 10 new unit tests for the pure helpers (pickVersion + settled).
Per project policy, no D1/S3 mocks for the full buildPageBundle —
end-to-end coverage is via the post-deploy smoke against a real
dataset.
@github-actions

github-actions Bot commented May 26, 2026 •

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR624

Version: 0.8.35-PR624.1637433
Commit: 1637433


🤖 Updated on each push.

@neuromechanist

Copy link
Copy Markdown
Contributor Author

Addressed PR review (4 agents):

CRITICAL (silent-failure-hunter): loadVersionRowsForBundle was swallowing D1 failures as [], which then flipped the bundle to a complete=true "no versions exist" response and pinned that lie at the CF edge for 24h via SWR. Hard-fail now — the outer pageBundleHandler already returns 500 + no-store for thrown exceptions, which is the correct policy. Documented in the new docstring why this differs from data.ts's loadVersionRows.

Severity 8 (pr-test-analyzer): Extracted isBundleComplete as a pure exported predicate. Added 7 truth-table tests pinning the cache-header decision: all-ok-with-version → true, all-ok-with-no-version → true (healthy unpublished), all-ok-but-summary-null-with-version → false (the regression class the previous reviewer flagged), each component-failed → false. The whole point is to prevent the partial-bundle-cached-as-success class — pinning it directly.

Silent-failure (borderline): Corrupt enrichment_json now surfaces as a top-level enrichment_degraded: boolean on the bundle so the website can render a "metadata may be incomplete" indicator if it wants to. Still doesn't fail the whole bundle (matches the existing /metadata.json policy that just logs and continues), but the degraded state is no longer invisible to consumers.

Comment fixes:

  • Reworded buildPageBundle failure-model docstring to be accurate about which components are in allSettled (the three S3/D1 fanouts, not landing).
  • Dropped the misleading "mirror of" language from loadVersionRowsForBundle and documented the intentional divergence in error policy vs data.ts.
  • Fixed the pageBundleHandler route-ordering docstring to reference the actual catch-all pattern (/:datasetId/:version/*).

Improvement: summary JSON parse error message now includes the S3 key so forensic triage doesn't need a second lookup.

Out of scope (acknowledged): shared loadVersionRows extraction across page-bundle + data.ts (code-reviewer conf 55) — defer to a follow-up cleanup; the two paths intentionally differ on error policy now.

Tests: 17/17 pass (was 10 → +7 truth-table). Backend typecheck clean. CI pending on this push.

@neuromechanist
neuromechanist merged commit 24b0df9 into feature/issue-618-epic-summary-11 May 26, 2026
1 check passed
@neuromechanist
neuromechanist deleted the feature/issue-621-phase3-page-bundle branch May 26, 2026 20:24

This branch was previously deployed

1 inactive deployment
npm — 1637433c Deployed May 26, 2026 by neuromechanist via publish #1158
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.

1 participant