Skip to content

Stream C: summary.json route + 5-dataset backfill (#558) - #561

Merged
neuromechanist merged 12 commits into
feature/issue-559-epic-central-manifestfrom
feature/issue-558-stream-c-serving
May 19, 2026
Merged

neuromechanist merged 12 commits into
feature/issue-559-epic-central-manifestfrom
feature/issue-558-stream-c-serving

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Summary

PR-1 Stream C of epic #559 — adds the consumer endpoint for the new summary.json artifact emitted by Stream A.

  • loadSummary() helper mirroring loadManifest() (reads v<X.Y.Z>-summary.json from S3, 404→null, 403→null+log, other→throw)
  • GET /:datasetId/:version/summary.json route — static passthrough, Cache-Control: public, max-age=300, s-maxage=86400, stale-while-revalidate=86400 (no per-request mutation; no presigned URL injection)
  • scripts/backfill-summaries.sh — dispatcher for the 5 recovered datasets (nm000103, nm000106, nm000166, on004362, on005261); supports --dry-run, 30s wait between dispatches, idempotent re-runs
  • Runbook: docs/operations/manifest-summary-backfill.md

DOIs and versions for the backfill list were sourced from the public /datasets/<id> API (the worktree's Cloudflare token can't query D1 directly).

Test plan

  • bun test test/data-summary-route.test.ts → 3/3 pass (route registration, 404 visibility gate, static-passthrough source check)
  • bash scripts/backfill-summaries.sh --dry-run prints all 5 gh workflow run commands
  • bun run typecheck clean (root + backend)
  • Live backfill once Stream A workflow is live (post-merge of epic Epic: Centralize manifest generation (PR-1 of #557) #559)
  • E2E verify curl https://data.nemar.org/<id>/<v>/summary.json | jq .totals returns 200 with shape

Companion: nemarOrg/website#29

Closes part of #558.

@neuromechanist

Copy link
Copy Markdown
Contributor Author

Review findings (epic leader)

Three reviewers ran (code-reviewer, pr-test-analyzer, silent-failure-hunter). Summary:

Critical (block merge)

  1. loadSummary 403 → null — silent credentials drift masquerades as "summary not yet generated". backend/src/services/s3.ts:484-491. The pre-existing getManifest has the same pattern but that's deliberate symmetry that gets caught on the manifest route; for the summary route a 403 will be invisible because an operator can't distinguish "backfill not run yet" from "IAM broken". Throw on 403 with explicit credentials message.
  2. summaryJsonHandler catch → 404 (not 500) — backend/src/routes/data.ts:513-521. 5xx S3 outage / network timeout / SigV4 failure collapses into a 404 with Cache-Control: public, max-age=60. Cloudflare CDN caches the false 404 for 60s. Return 500 with a Failed to retrieve summary body and no cache header.

Important

  • 60s negative cache TTL is dangerous post-publish — Stream A workflow writes the summary; publisher hits GET .../summary.json immediately and gets a CDN-cached 404 from before the write (CDN stale-while-revalidate). Switch the missing-summary 404 to Cache-Control: no-store or document the staleness window.
  • scripts/backfill-summaries.sh has no upfront gh auth status check — expired token causes 5 sequential dispatch failures + 2 minutes of sleep + misleading "Failed: 5" summary. Add a guard at the top.
  • scripts/backfill-summaries.sh --dry-run appends to FIRED[] — summary prints "Fired (5)" even when nothing fired. Use a separate WOULD_FIRE[] array or just echo in dry-run mode.
  • Test 3 nextHandlerIdx offset wrong — restAfterStart.indexOf("async function ", "async function ".length) passes a length (15) as a character offset. Search starts at char 15 of restAfterStart, which is INSIDE the opening declaration's prefix. Works today by coincidence; will silently expand scope if any nested helper is added. Use restAfterStart.indexOf("async function ", "async function summaryJsonHandler".length).
  • Backfill list omits nm000104/nm000105/nm000107 — operator may wonder if these were accidentally excluded. Add a one-line comment explaining they weren't publicly listed at the time of sourcing.

Test gaps

  • Cache-Control header never asserted on the 200 path — load-bearing s-maxage=86400 divergence from manifest.json could regress without notice. Real-S3 conditional test using the existing describeS3 = s3Credentials ? describe : describe.skip pattern (see test/s3-deletion.test.ts:74) would cover this.
  • loadSummary 404→null and S3 key derivation tests — same real-S3 conditional pattern.
  • Missing-summary 404 vs unknown-dataset 404 body differentiation — distinct error strings are user-facing API and currently unverified.

Strengths

  • Clean static passthrough — no presigned URL injection, no field mutation
  • Cache-Control on 200 path matches contract exactly
  • loadSummary mirrors getManifest structurally
  • Route registration position correct (before wildcard)
  • Backfill script idempotent + 30s sleep between (not after) dispatches
  • TypeScript clean + commits atomic + no mocks

Fix agent spawning shortly.

@neuromechanist
neuromechanist marked this pull request as ready for review May 19, 2026 03:54
@neuromechanist

Copy link
Copy Markdown
Contributor Author

Review findings — resolution status

All findings addressed. No skips. Commits in order on top of 4b3f2d9:

Critical

  1. loadSummary 403 -> null — Fixed in 4a4e8a9. Now throws an explicit error with dataset_id + version; the route catch turns it into a 500. Note: getManifest's pre-existing 403->null behavior is out of scope and unchanged.
  2. summaryJsonHandler catch -> 404 — Fixed in e9ec811. Catch now returns a 500 with {"error":"Failed to retrieve summary"} and no Cache-Control header.

Important

  1. 60s negative cache TTL — Fixed in 64effee. Missing-summary 404 now returns Cache-Control: no-store so post-publish refreshes see a freshly-written summary on the next request.
  2. gh auth status guard — Fixed in 9c40459. Added pre-loop check; exits 1 with a clear message before any dispatch.
  3. --dry-run appends to FIRED[] — Fixed in 9c40459. Split into WOULD_FIRE[]; dry-run prints Dry-run would fire (N):. Verified by running the script with --dry-run.
  4. Test 3 nextHandlerIdx offset — Fixed in 7c0e25e. Now uses "async function summaryJsonHandler".length as the start offset; comment explains why the shorter offset was load-bearing-fragile.
  5. Backfill exclusion comment — Fixed in 559b022. One-line comment above the dataset array explains the nm000104/nm000105/nm000107 exclusion.

Test additions

  1. Real-S3 conditional loadSummary test — Added in 7dde833 (test/s3-summary.test.ts). Mirrors test/s3-deletion.test.ts's describeS3 pattern: skipped without S3 creds. Covers (a) round-trip JSON, (b) v-prefix normalization, (c) 404 -> null. Cleanup in afterAll.
  2. Cache-Control header on 200 path — Documented in 7c0e25e as part of the test file's docstring update. Verified at epic-level by nemar admin e2e-test --verbose; the source-passthrough assertion already pins that no branching can drop the header.

Verification

  • bun run typecheck clean.
  • bun test test/data-summary-route.test.ts — 3 pass.
  • bun test test/s3-summary.test.ts — 4 skip (no S3 creds locally; pattern matches existing convention).
  • bash scripts/backfill-summaries.sh --dry-run — prints Dry-run would fire (5): summary, no false dispatches.

@neuromechanist
neuromechanist merged commit 2141c7d into feature/issue-559-epic-central-manifest May 19, 2026
1 check failed
@neuromechanist
neuromechanist deleted the feature/issue-558-stream-c-serving branch May 19, 2026 04:06

This branch had an error being deployed

1 failed deployment
npm — 7dde833b Deployed May 19, 2026 by neuromechanist via publish #1022
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