Skip to content

Epic #66: Cold-paint perf + cache hygiene for dataset detail - #70

Merged
neuromechanist merged 11 commits into
mainfrom
feature/issue-66-epic-cold-paint
May 26, 2026
Merged

neuromechanist merged 11 commits into
mainfrom
feature/issue-66-epic-cold-paint

Conversation

@neuromechanist

@neuromechanist neuromechanist commented May 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes three independent cold-paint regressions on /dataset/<id> that compounded into a multi-second blocking experience for users on low-bandwidth connections.

Three phases shipped via separate sub-PRs and review passes; this PR bundles them onto main.

Closes #66
Closes #65
Closes #63
Closes #64

CLI counterpart

The nemar-cli side (epic nemar-cli#618) ships the schema 1.1 generator (#616) + backfill, plus a separate page-bundle endpoint (#617) that's intentionally out of scope here. The page-bundle consumer will be filed as a follow-up website issue once nemar-cli#617 lands — it collapses the website's cold-load waterfall to one RTT and is the logical next epic.

Phases completed

  1. Phase 1 — Edge-cache namespace v1 → v2 — PR Phase 1 (#65): bump edge-cache namespace to v2 #67 (merged 2026-05-26T18:43:41Z)
  2. Phase 2 — Consume summary.readme.content (schema 1.1) — PR Phase 2 (#63): consume summary.readme.content from schema 1.1 #68 (merged 2026-05-26T19:13:48Z)
  3. Phase 3 — Progressive BIDS tree (skeleton + per-subject lazy) — PR Phase 3 (#64): progressive BIDS tree (skeleton + lazy per-subject) #69 (merged 2026-05-26T19:46:53Z)

Test plan

  • bun run typecheck — 0 errors across all three phases
  • bun run lint — biome clean
  • bun run test — full suite green; cumulative diff adds 23 new tests (+8 in data-api.test.ts, +11 in the new render-tree.test.ts, +4 in the new tree-endpoint.test.ts)
  • Local bun run build — astro build clean, no Workers-runtime warnings introduced
  • Each constituent phase PR (Phase 1 (#65): bump edge-cache namespace to v2 #67, Phase 2 (#63): consume summary.readme.content from schema 1.1 #68, Phase 3 (#64): progressive BIDS tree (skeleton + lazy per-subject) #69) reviewed by the parallel sonnet pr-review-toolkit pass and findings addressed in follow-up review(#NN) commits before merge
  • Cross-phase review pass on the cumulative diff; one Cache-Control asymmetry found and fixed
  • Post-deploy: https://ww2.nemar.org/dataset/on005505 no longer renders the poisoned fallback HTML; cold-isolate response on /api/dataset/on005505/readme and /tree returns full content; /tree skeleton stays under 50 KB
  • Post-deploy after nemar-cli#616 backfill: README endpoint cold response < 200 ms (no GitHub RTT)

Out of scope (follow-up issues to file post-merge)

  • Page-bundle consumer (nemar-cli#617 dependency) — collapses cold-load waterfall to one RTT. New website issue.
  • Small-subject UX regression — 2-3 subject datasets now require an extra click to expand. Genuinely a minor degradation outside Progressive BIDS tree: render skeleton sync, lazy-load subject contents #64's stated target (100+ subjects). New website issue, low priority.
  • Pre-existing 404 Cache-Control inconsistency — landingOut.kind === "not_found" 404s on both readme and tree endpoints have never set explicit cache headers. Cross-phase review confirmed this predates this epic; not regressed here. New website issue if we want to harden it.

Orphans pre-PR-#54 SWR-poisoned fallback partials still served from
PoP caches under the old namespace. Existing on005505 symptom of
"No description available" / "Manifest unavailable" goes away on
next deploy without touching the cache layer at runtime.

Closes #65
Part of epic #66
Comment-analyzer found the rationale block named the wrong cached
keys: poisoned entries are responses from /api/dataset/<id>/readme
and /api/dataset/<id>/tree (the partial endpoints), not the SSR
/dataset/<id> page. Also add "(fixes #53)" next to "PR #54" so a
future GitHub search lands on the original bug report.
Phase 1 (#65): bump edge-cache namespace to v2
Extends SummaryReadme with the schema 1.1 fields nemar-cli#616 will
emit (content, content_bytes, sha256, truncated; all optional) and
inserts a Step 0.5 in /api/dataset/<id>/readme that returns the
inlined markdown directly. Eliminates the synchronous GitHub raw
fetch on the cold-paint path once the upstream backfill completes.
Back-compat: schema 1.0 docs miss the new branch and fall through
to the unchanged Step 1-4 resolver.

Closes #63
Part of epic #66
Four findings from the parallel sonnet review pass:

- pr-test-analyzer: whitespace-only inline content would slip past
  the length-check, render to empty HTML, and get cached with
  PUBLISHED_CACHE for the full SWR window. Switch the guard to
  trim().length === 0; add tests for the whitespace case and for
  preserving leading whitespace inside otherwise-valid markdown.

- type-design-analyzer: declared `content?: string` but the docstring
  said the generator emits `content: null` on truncation. Align the
  type to `string | null`. Add a test for the explicit-null case.

- comment-analyzer: clarify "leaves content null" in the interface
  comment now that the type matches; note that nemar-cli#616 is
  still open so the 256 KB cap is proposed, not enforced.

- comment-analyzer: soften the Step 0.5 "abstraction surface tight"
  rationale and add a forward pointer for the case where a future
  ReadmeSourceKind needs to distinguish inline vs presigned at
  render time.

378/378 tests pass (was 375 before this commit).
…rom-summary

Phase 2 (#63): consume summary.readme.content from schema 1.1
Splits /api/dataset/<id>/tree?v=<v> into two response modes via
the new optional subject= parameter. Without subject= the endpoint
emits a skeleton: top-level non-subject entries inline, each sub-XYZ
as a collapsed <details data-subject="..."> with a lazy slot. With
subject= it returns just that subject's inner subtree. The dataset
detail page picks up subtree expansions on the first <details>
toggle and drops the fragment into the matching slot.

Targets on005505 specifically: 5,409 paths / 136 subjects used to
ship 3.3 MB of HTML in one blob and block the file panel for
seconds. Skeleton stays under 50 KB; subtree fetches are scoped to
one subject at a time and edge-cached per (id, version, subject)
for free via the existing URL-keyed cache.

Adds isSubjectDir(name) predicate (used both for skeleton row
identification and as the param-validation gate on the endpoint),
renderBidsSubtree(node, basePath) for the subtree response, and 8
tests covering subject-vs-non-subject rendering plus the
traversal-guard cases on the predicate.

Closes #64
Part of epic #66
Five sonnet reviewers ran in parallel. Critical and important fixes:

- silent-failure-hunter + code-reviewer: 503 response on the subtree
  branch had no Cache-Control. Add FALLBACK_CACHE (no-store) so a
  transient upstream failure doesn't pin at the edge, matching the
  skeleton's no-manifest treatment.
- silent-failure-hunter + comment-analyzer: the 404 (subject not
  found) inline comment promised a "short cache" the code never
  set. Add a NOT_FOUND_SUBJECT_CACHE constant (60s s-maxage) so
  the wire behavior matches the documented intent.
- code-reviewer: 400 responses (missing v=, invalid subject=)
  carried no Cache-Control. Add no-store on both paths so an
  intermediate proxy can't pin the error.
- code-reviewer: subject regex was alphanumeric-only; widen to
  /^sub-[A-Za-z0-9-]+$/ so BIDS 2.0 + real OpenNeuro datasets
  like sub-NDAR-AC904DMU don't silently regress to inline render.
  Update isSubjectDir tests; embedded slash still rejected.
- code-reviewer: .tree__error class had no CSS rule. Add a scoped
  rule in BidsTree.astro so the subtree-fetch-failure paragraph
  reads as a retry prompt, not body text.
- type-design-analyzer: replace inline import("...").TreeNode
  with a top-of-file import type so the dependency is legible.
- comment-analyzer: tighten the renderBidsSubtree docstring with
  the concrete renderDirChildren(node, basePath, 1) call site,
  and add a "keep in sync" warning to the subject-param
  validation comment.
- pr-test-analyzer: add four endpoint-validation tests (no v=,
  malformed subject, empty subject, underscore label) and two
  rendering edge cases (subjects-only tree, nested sub-* doesn't
  re-collapse).

393/393 tests (was 386).

Deferred to a follow-up issue: small-subject UX regression (2-3
subjects now require an extra click). Out of #64's stated scope
(100+ subject case).
CF Pages picks up *.test.ts under src/pages/** as a route entry
and breaks the build (same class as PR #62 / commit 3cbc89f for
the proxy test). Relocate to src/lib/tree-endpoint.test.ts; the
file still imports GET from the route source, so the wire-contract
coverage is unchanged. 393/393 tests pass; local astro build
completes clean.
…s-tree

Phase 3 (#64): progressive BIDS tree (skeleton + lazy per-subject)
Cross-phase review surfaced an asymmetry introduced by Phase 3:
tree.ts's "Missing id or v=" 400 was hardened with Cache-Control:
no-store, but the parallel branch in readme.ts was missed. Add
the matching header so both partial endpoints behave consistently
at the cache boundary. Pre-existing 404 inconsistencies on the
landing not_found path are out of scope (predate this epic).
@cloudflare-workers-and-pages

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

Copy link
Copy Markdown

@neuromechanist
neuromechanist merged commit 7e4f297 into main May 26, 2026
1 check passed
@neuromechanist
neuromechanist deleted the feature/issue-66-epic-cold-paint branch June 21, 2026 22:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant