Skip to content

Stream A: emit_manifest.py + central generate-manifest workflow (#556 + part of #558) - #560

Merged
neuromechanist merged 15 commits into
feature/issue-559-epic-central-manifestfrom
feature/issue-556-stream-a-generator
May 19, 2026
Merged

neuromechanist merged 15 commits into
feature/issue-559-epic-central-manifestfrom
feature/issue-556-stream-a-generator

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Summary

PR-1 Stream A of epic #559 — replaces the in-worker GitHub-API-per-pointer manifest generation (#556) with a git-tree walk run on a managed runner, plus emits the new compact summary.json artifact (#558).

  • scripts/emit_manifest.py — port of /tmp/manifest_recover.py, productionized; writes manifest.json (matches VersionManifest shape exactly), summary.json (matches the schema_version=1.0 contract in .context/epic_central_manifest_state.md), and totals.json (workflow-internal). Supports --verify-canary / --no-verify-canary; the canary mirrors verifyGitBackedFiles in backend/src/services/manifest.ts.
  • scripts/test_emit_manifest.py — 16 real-git assertions, no mocks. Creates a tmp BIDS-shaped repo with a real annex-style symlink, tags it v0.0.0, runs the script, and asserts manifest + summary + totals shapes.
  • .github/workflows/generate-manifest.yml — repository_dispatch[generate-manifest] (production) + workflow_dispatch (manual). Mints an App installation token scoped to the target dataset repo, shallow-clones at tag, runs emit_manifest.py, uploads both artifacts to S3, POSTs the documented callback (or best-effort /webhooks/manifest-failed on failure).
  • scripts/build_callback_body.py + scripts/build_failure_body.py — tiny helpers that build the callback JSON from totals.json, pulled out of the workflow YAML to avoid heredoc indentation pitfalls.

Contract surface (locked against .context/epic_central_manifest_state.md)

  • manifest.json shape — unchanged from VersionManifest (dataset_id, version without leading v, doi, concept_doi, created ISO Z, files)
  • summary.json shape — schema_version: "1.0", totals: {files, bytes, subjects}, modalities (BIDS datatypes), subjects (sorted sub-XXX), readme: {path}|null, sorted paths
  • S3 keys — s3://nemar/<id>/version/v<X.Y.Z>.json and …-summary.json
  • Dispatch payload — accepts dataset_id, version, doi, concept_doi, callback_url, callback_token, skip_canary (the last lets Stream B opt out of the raw.githubusercontent.com HEAD check for private repos)
  • Callback POST body — {dataset_id, version, manifest_url, summary_url, totals: {files, bytes, annex, git}, workflow_run_id} with X-Webhook-Token: <callback_token>

Interfaces with Streams B and C

  • Stream B (feature/issue-557-stream-b-worker) dispatches with the documented client_payload shape and validates X-Webhook-Token on the callback. Stream A trusts the worker to set skip_canary=true for private/sandbox datasets.
  • Stream C (feature/issue-558-stream-c-serving) reads v<X.Y.Z>-summary.json from S3 and serves it via data.nemar.org.

Out-of-scope (intentionally not touched)

  • backend/src/services/manifest.ts — Stream B adds the feature-flag dispatch path
  • backend/src/routes/data.ts — Stream C
  • backend/src/services/github.ts getWorkflowTemplates() — the central workflow does NOT fan out to dataset repos

Test plan

  • python3 scripts/test_emit_manifest.py passes locally (16 tests, real git repo, no mocks)
  • USER STEP: set repo secrets on nemarOrg/nemar-cli (NEMAR_APP_ID, NEMAR_APP_PRIVATE_KEY, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, MANIFEST_CALLBACK_SECRET)
  • Manual workflow_dispatch run against nm099999 with skip_canary=true to verify clone + S3 upload + callback round-trip (blocked on the secrets step above)
  • Full E2E via nemar admin e2e-test lands with Stream B's dispatch path and Stream C's serving route

Closes part of #556, 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. curl callback POST has no --max-time — runner can hang for hours on unresponsive Worker. .github/workflows/generate-manifest.yml:184 and the failure-callback at ~210. Add --max-time 30 --connect-timeout 10 to both. Also add timeout-minutes: 30 on the job.
  2. Failure-callback step missing set -euo pipefail — every other substantive run: block has it. Inconsistency is a maintenance trap.
  3. Success-callback failure fires failure-callback with misleading context — when the Worker returns 401/5xx to the success callback, curl -fsS exits nonzero, if: failure() fires the failure-callback, S3 already has a valid manifest but the Worker records it as "failed". Split the success-callback step + emit a distinct ::error:: annotation so the failure mode is recognizable. Optionally add canary_skipped to callback body for similar disambiguation.

Test gaps (critical)

  • Malformed annex symlink fall-through to git: key — no test covers a non-annex symlink (e.g., ../../some/other/path). Silent data corruption risk.
  • readme: null branch — production datasets without README are untested.
  • summary.json dataset_id/version pass-through — both fields are contract-required but not asserted in the test.

Important

  • Unlocked-mode annex pointer files misidentified — mode 100644 with content /annex/objects/KEY falls through to git:<sha> with pointer-blob size (~80 bytes), not the real annex file size. Compare against manifest.ts:parseAnnexPointer which handles both forms. Currently safe at tag time (DataLad tags locked commits) but a silent correctness landmine.
  • extract_size_from_key()/extract_checksum_from_key()/extract_algo_from_key() silently return 0/"" when the regex doesn't match. Add print(...file=sys.stderr) warnings.
  • failed_step always "unknown" — build_failure_body.py defines --failed-step but the workflow never passes it. Thread the failing step via $GITHUB_ENV from per-step if: failure() traps.
  • import time inside hot loop — move to module top (PEP 8 / ruff E402).
  • Test gaps (important): README priority order, version-with-v-prefix input, empty tree, sub- length guard.

Strengths

  • Contract fidelity is exact (VersionManifest shape, summary shape, git:<sha>/checksum format)
  • Annex regex correctness (ports manifest.ts helpers cleanly)
  • set -euo pipefail on every other run block
  • Shell injection safety (variables via env, not ${{ }} interpolation)
  • No mocks in test (real git repo, real symlink)
  • Failure callback decoupled with || true

Fix agent spawning shortly.

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

Copy link
Copy Markdown
Contributor Author

Review findings — resolution map

All findings from the epic-leader review addressed in the following commits. Per CLAUDE.md "no technical debt carried forward" policy — every finding either fixed or explicitly justified.

Critical (block merge)

# Finding Status
1 curl callback POST has no --max-time; add --max-time 30 --connect-timeout 10 to both success and failure callbacks, plus timeout-minutes: 30 on the job Fixed in 64f16e3
2 Failure-callback step missing set -euo pipefail Fixed in 26e5d59
3 Success-callback failure misroute; split step, emit distinct ::error:: annotation when Worker rejects callback (S3 artifact valid). Also add canary_skipped to body. Fixed in 74f9b48 (distinct error log) + f44bad6 (canary_skipped field)

Test gaps (critical)

# Finding Status
4 Malformed annex symlink fall-through test (symlink to ../README.md, assert key starts with git:) Fixed in 2695051
5 readme: null branch test Fixed in 965871b
6 summary.json dataset_id/version pass-through test Fixed in 965871b

Important

# Finding Status
7 Unlocked-mode annex pointer files (/annex/objects/KEY content in mode 100644) misidentified as git:<sha>; mirror manifest.ts:parseAnnexPointer Fixed in 382cefa — added parse_annex_pointer_content() + ANNEX_POINTER_CONTENT_RE; gated on blob size ≤512 bytes to avoid pulling participants.tsv content into memory
8 extract_size_from_key/extract_checksum_from_key/extract_algo_from_key silent on regex miss; add stderr warnings Fixed in 382cefa
9 failed_step always "unknown"; thread via $GITHUB_ENV from per-step outcomes Fixed in 02d787d — added id: to each substantive step, "Identify failed step" computes FAILED_STEP from steps.<id>.outcome, passed to build_failure_body.py --failed-step
10 import time inside hot loop Fixed in a0c113a
11a Test: README priority order (commit both README and README.md, assert README wins) Fixed in 22c9475
11b Test: version-with-v-prefix input Fixed in 22c9475
11c Test: sub- length guard Fixed in 15ca31c
11d Test: empty tree Skipped — true empty git tree cannot be tagged (git tag requires at least one commit, and git commit --allow-empty still yields a non-empty parent). The review notes the same; alternative coverage (one-file repo) is already implicit in ReadmeNoneTests (single dataset_description.json file, no subjects, no modalities). Justified per review's own caveat.

Test count

25 tests total (16 baseline + 9 new). uv run python scripts/test_emit_manifest.py → Ran 25 tests in 0.692s — OK.

Notes on implementation choices

  • Unlocked-mode pointer parsing is gated on blob size ≤512 bytes to keep cat-file blob calls cheap. Real annex pointer blobs are ~70-120 bytes; the 512-byte ceiling is generous but bounds the per-large-file cost.
  • Success-callback split preserves the previous "fail this step → trigger failure-callback" wiring, but the distinct ::error title=Callback rejected by Worker:: annotation makes it impossible to confuse "manifest generation failed" with "manifest succeeded but Worker rejected the callback". The failure-callback body now also carries failed_step: "post-success" for the latter case.
  • canary_skipped is a boolean (true/false), defaulted to false. Stream B can set skip_canary: true on dispatch for private repos.

Ready for re-review.

@neuromechanist
neuromechanist merged commit 4318140 into feature/issue-559-epic-central-manifest May 19, 2026
1 check failed
@neuromechanist
neuromechanist deleted the feature/issue-556-stream-a-generator branch May 19, 2026 04:05

This branch had an error being deployed

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