Skip to content

Epic #559: Centralize manifest generation (PR-1 of #557 + #556 + #558) - #563

Merged
neuromechanist merged 14 commits into
devfrom
feature/issue-559-epic-central-manifest
May 19, 2026
Merged

neuromechanist merged 14 commits into
devfrom
feature/issue-559-epic-central-manifest

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Summary

Epic #559 — PR-1 of the 4-PR phasing in #557. Bundles the algorithmic fix from #556 and the new summary.json artifact from #558 into a single integration into dev. Three sub-PRs landed onto the epic branch in parallel:

Design contract pinned in .context/epic_central_manifest_state.md. Each sub-PR was reviewed (code-reviewer, pr-test-analyzer, silent-failure-hunter) and all findings addressed.

What this fixes (today's failure mode)

backend/src/services/manifest.ts:generateManifest() makes one GitHub REST API call per annex-pointer-candidate blob. For a typical BIDS-EEG dataset (on005261, 14,536 candidate files) that single publish exhausts 116% of the nemarDatasets GH App installation hourly quota. Worker logs from the doctor-framework (#555) recovery run on 2026-05-18:

{"tag":"github-rl","path":"/repos/nemarDatasets/on005261/commits/v1.0.0",
 "status":403,"resource":"core","remaining":0,"resetEpoch":1779153203,"limit":12500}

Replaces the API-per-pointer algorithm with a git ls-tree -r v<X> + git cat-file blob <sha> walk on a managed GitHub-Actions runner (Python, ~ 2 min for the largest dataset). Zero GitHub API calls during manifest generation.

What this adds (companion: nemarOrg/website#29)

A compact summary.json sibling artifact alongside manifest.json. The website's detail page only needs paths + readme + totals; today it pulls a 10+MB manifest.json with presigned URLs per file on every request. The new summary is path-only, typically 50-200 KB regardless of dataset size, statically cacheable for 24 hours.

Ops sequence (BLOCKS MANIFEST_VIA_CENTRAL_WORKFLOW=true rollout)

Required secrets on nemarOrg/nemar-cli:

Required Workers secret (prod + dev SCCN):

  • MANIFEST_CALLBACK_SECRET (same value as above)

Required D1 migration application after merge:

  • npx cfman wrangler --account neuromechanist d1 migrations apply nemar-db -c backend/wrangler.toml (prod + dev)
  • npx cfman wrangler --account sccn d1 migrations apply nemar-db -c backend/wrangler-sccn.toml (prod + dev)

Rollout: flip MANIFEST_VIA_CENTRAL_WORKFLOW=true on SCCN dev first, run a real publish on nm099999, observe a week of clean runs, then flip prod.

Test plan

  • 25 real-git tests in scripts/test_emit_manifest.py pass (Stream A)
  • 3 tests in test/data-summary-route.test.ts + conditional real-S3 test/s3-summary.test.ts pass (Stream C)
  • 108 manifest+sync tests pass across 7 files (Stream B)
  • Backend typecheck clean
  • Backfill --dry-run prints Dry-run would fire (5): (verified live)
  • nemar admin e2e-test --verbose on SCCN dev with MANIFEST_VIA_CENTRAL_WORKFLOW=true once secrets are in (BLOCKING)
  • Manual gh workflow run generate-manifest.yml -f dataset_id=nm099999 -f version=1.0.0 ... on this repo once secrets are in
  • https://data.nemar.org/nm099999/1.0.0/summary.json returns 200 with documented shape
  • https://data.nemar.org/nm099999/1.0.0/manifest.json still returns existing per-file presigned-URL shape (back-compat unchanged)
  • 5 recovered datasets backfilled via scripts/backfill-summaries.sh (post-merge)
  • /review-pr clean

Out of scope (later sub-issues of #557, opened after this lands)

  • PR-2: dual-write phase — both paths fire, write to manifest_jobs table, compare for a week
  • PR-3: cutover — delete per-repo publish-version-doi.yml/generate-archive.yml; remove generateManifest() worker fallback
  • PR-4: migrate generate-archive to the same central pattern

Closes #559. Partially closes #556, #557, #558 (the remaining work for #557 is tracked in PR-2/PR-3/PR-4 follow-ups).

…+ part of #558)

PR-1 Stream A of epic #559. Adds scripts/emit_manifest.py (git-tree walk, no GitHub API), .github/workflows/generate-manifest.yml (repository_dispatch + workflow_dispatch), and helper scripts. Replaces in-worker manifest generation. Emits both manifest.json (existing shape) and summary.json (new compact artifact per #558). 25 real-git tests pass. Closes part of #556 + #558.
PR-1 Stream C of epic #559. Adds loadSummary helper, GET /:datasetId/:version/summary.json route (static passthrough, s-maxage=86400), and scripts/backfill-summaries.sh for the 5 recovered datasets. Includes 403-throws fix (silent-credentials-drift) and 500-on-S3-error fix from review round. 3 unit tests + real-S3 conditional test pass. Companion: nemarOrg/website#29. Closes part of #558.
PR-1 Stream B of epic #559. Adds triggerManifestGeneration dispatch (targeting nemarOrg/nemar-cli central repo), POST /webhooks/manifest-ready callback (HMAC-validated, S3 HEAD-checked, dataset_versions insert + nemar-sync deferred until callback), POST /webhooks/manifest-failed callback, migration 0025 (manifest_jobs), and feature flag MANIFEST_VIA_CENTRAL_WORKFLOW (default false). Includes review-round fixes: 403→throw, crypto-error→500, nemar-sync moved to manifest-ready, 500-on-insert-fail, skipCanary wired, validateManifestCallbackBody + isCentralManifestWorkflowEnabled unit tests, supersession warn, dead fallback removed. canary_skipped field handoff from Stream A accepted. 108 manifest+sync tests pass. Closes part of #557.
@neuromechanist

Copy link
Copy Markdown
Contributor Author

Cross-phase review (epic leader)

Three reviewers ran (code-reviewer, pr-test-analyzer, silent-failure-hunter) AGAINST THE INTEGRATED DIFF. Per-phase reviews of #560/#561/#562 already addressed; this surfaces issues only visible across phase boundaries.

Critical — wire drift (block merge to dev)

  1. failed_step field dropped on every failure — scripts/build_failure_body.py emits {..., "failed_step": ...}. /webhooks/manifest-failed reads body.error_message ?? "unknown error". Every failure gets manifest_jobs.error_message = "unknown error" regardless of which step died. Fix: rename Python key to error_message, OR add failed_step to ManifestCallbackBody + read it in the handler.

Critical — before flipping MANIFEST_VIA_CENTRAL_WORKFLOW=true

  1. backend/wrangler-sccn.toml has MANIFEST_VIA_CENTRAL_WORKFLOW only at top-level [vars], NOT under [env.dev.vars]. SCCN dev (the designated soak target) won't see the flag. Add it.
  2. Missing # Redeploy to change. annotation on the flag in both wranglers (matches existing pattern above MAINTENANCE_MODE). Operator trap: wrangler vars set does nothing without redeploy.
  3. State doc skip_canary semantics — .context/epic_central_manifest_state.md line 100 says "Worker sets true for private/sandbox repos". Code always sends true because the canary races GitHub Pages propagation. Correct the doc.
  4. No stuck-dispatched detection — workflow timeout/cancel without failure-callback leaves rows stuck forever. Add a SELECT COUNT(*) FROM manifest_jobs WHERE status='dispatched' AND created_at < datetime('now','-1 hour') check in the existing daily scheduledCleanup and log at console.error if >0.
  5. Misleading 502 body when headVersionArtifact throws on 403/5xx — body says "S3 artifacts not found" but the actual cause is IAM credential drift. Distinguish: surface the caught error message in the 502 response.
  6. Admin manifest regeneration endpoint (POST /admin/datasets/:id/manifest/:version) calls legacy generateManifest() + uploadManifest() but does NOT insert dataset_versions row. Under centralFlow this breaks admin recovery. Add a backfill INSERT after uploadManifest().
  7. CI doesn't run Python tests — .github/workflows/test.yml paths-filter covers src/**, backend/**, test/** but NOT scripts/**. scripts/test_emit_manifest.py (25 real-git tests) never runs in PR CI. Add scripts/** filter + python-test job.
  8. build_callback_body.py + build_failure_body.py untested — these scripts produce JSON that validateManifestCallbackBody parses. No round-trip test pins this cross-phase contract. Add a test in scripts/test_emit_manifest.py that invokes both scripts and asserts the produced field set matches validateManifestCallbackBody's required fields.

Important

  • data-summary-route.test.ts static-passthrough check is brittle (text-search between two async function declarations); will silently pass under refactor. Defer fix or replace with E2E assertion.
  • e2e-test.ts doesn't exercise MANIFEST_VIA_CENTRAL_WORKFLOW=true path — separate follow-up issue. The acceptance checkbox stays unchecked until that lands.
  • Manual workflow_dispatch recovery doesn't complete the publish pipeline (no callback token). Separate follow-up: nemar admin manifest-accept command.

Strengths

  • Wire-shape consistency clean elsewhere (snake_case throughout, triggerManifestGeneration aligns with workflow reads)
  • Feature flag semantics correct on mid-publish flip (/webhooks/manifest-ready doesn't consult the flag)
  • Backwards-compat clean (CREATE TABLE IF NOT EXISTS, if (!centralFlow) guard wraps inline path)
  • Concurrency safe (different nonces, OR IGNORE on dataset_versions, ORDER BY DESC LIMIT 1 on job lookup)
  • HMAC + constant-time compare exemplary; --max-time 30 on curl; pre-insert-before-dispatch ordering

Recommendation

All three reviewers said: PR is mergeable behind default flag=false. But CLAUDE.md says address all findings. Items 1-9 land on this branch before merge to dev. Items 10-12 become follow-up issues opened after merge.

Fix agent spawning shortly.

@neuromechanist

Copy link
Copy Markdown
Contributor Author

Cross-phase findings: resolutions

All 9 in-scope items addressed on this branch. Items 10-12 deferred to follow-up issues as planned.

# Finding Resolution SHA
1 failed_step field dropped on every failure Renamed Python key to error_message; value packs the step name as failed at step: <step>. Worker handler now records the real failure point. c4ed391
2 wrangler-sccn.toml flag missing from [env.dev.vars] Added MANIFEST_VIA_CENTRAL_WORKFLOW = "false" block to SCCN dev vars. 0a2ec35
3 Missing # Redeploy to change. annotation Added above every MANIFEST_VIA_CENTRAL_WORKFLOW declaration in both wranglers. 0a2ec35
4 State doc skip_canary semantics inaccuracy Corrected to: "Worker always sets true at publish time because the canary races GH Pages propagation." 7f4ae57
5 Stuck-dispatched detection Added query in scheduledCleanup (backend/src/index.ts); logs to console.error when rows are stuck > 1 hour. No D1 mutation. 2aec447
6 Misleading 502 body in /webhooks/manifest-ready Captures HEAD exception messages separately; 502 body now distinguishes "credentials/permissions error" from "artifacts not found" and surfaces the raw error in manifest_head_error / summary_head_error keys. 68b6fda
7 Admin manifest regen missing dataset_versions insert POST /admin/datasets/:id/manifest/:version now backfills the row after uploadManifest() (uses provided/manifest DOI; falls back to dataset's doi_provider). Documented contract in JSDoc; response includes dataset_versions_backfilled flag. 8db6d0b
8 CI doesn't run Python tests Added scripts: filter + python-unit-test job in .github/workflows/test.yml. Runs python scripts/test_emit_manifest.py when scripts/** changes. d0dc678
9 build_callback_body.py / build_failure_body.py round-trip test Added CallbackBodyRoundTripTests + FailureBodyRoundTripTests to scripts/test_emit_manifest.py. Asserts produced field sets EXACTLY match what validateManifestCallbackBody requires (plus the optional canary_skipped). 1706831

Verification

  • Python: uv run python scripts/test_emit_manifest.py → 33 tests pass (4 new)
  • Backend typecheck: clean
  • Backend tests: 86 pass / 0 fail (6 files, 548 expect() calls)
  • Manifest-focused tests: 47 pass / 0 fail across manifest-callback-body-validation.test.ts, manifest-jobs-migration.test.ts, manifest-callback-token.test.ts

Out of scope (deferred to follow-up issues, per plan)

  • 10: data-summary-route.test.ts static-passthrough brittleness
  • 11: E2E MANIFEST_VIA_CENTRAL_WORKFLOW=true coverage
  • 12: Manual workflow_dispatch recovery (nemar admin manifest-accept command)

Feature flag stays default "false" everywhere; migration 0025 stays unapplied until the ops sequence runs. Ready for re-review.

This branch had an error being deployed

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