Repository navigation
Closed
Description
Motivation
We've accumulated several "stuck dataset" patterns where a dataset is partially published or partially synced and there's no human-facing recovery path:
dataset_versionsrow exists but S3 manifest.json missing →data.nemar.org/<id>/<version>/manifest.json404s (active right now: ~10 datasets including on005261, nm000103, nm000106, nm000166, on004362)latest_version_doiset but nodataset_versionsrow (the original symptom in Stuck publish: ~33% of on* datasets have GitHub tag but no version row #529)subject_count IS NULLbecause upstream lacks participants.tsv (fixed forward by PR feat(enrich): auto-generate participants.tsv when missing at root #553's auto-generation, but doesn't backfill historic datasets)nemar_catalogrow missing for a dataset (migrations 0023/0024 backfilled this once)nemar_sync_statusfailed or stuck NULL- Other patterns we'll discover next month
Today we patch each pattern with a one-off endpoint (/admin/catalog/sync-local, /admin/datasets/:id/manifest/:version, etc.) and each PR rebuilds the wheel: query, fix, deploy, run, archive.
Proposal
A single admin "doctor" framework where each pattern is a check with a scan (diagnostic, read-only) and a fix (idempotent write):
POST /admin/doctor/scan -> run all checks, return findings
POST /admin/doctor/scan?check=<name> -> run one check
POST /admin/doctor/fix?check=<name>&dataset_id=<id> -> apply fix to one dataset
POST /admin/doctor/fix?check=<name>&dry_run=true -> show what would happen
POST /admin/doctor/fix?check=<name> -> apply fix to all matches (with confirm)
Each check is a small module with a defined shape. Adding a new check means writing a scan SQL/probe + a fix function that reuses existing helpers. No new routes per check.
Initial check catalog
| Check name | Detect | Fix |
|---|---|---|
| missing-manifest | dataset_versions row exists but S3 manifest.json missing | generateManifest + uploadManifest |
| missing-version-row | latest_version_doi set but no dataset_versions row | INSERT row from DOI suffix |
| null-subject-count | subject_count IS NULL on active dataset | Re-run enrichment (auto-gens participants.tsv per #553) |
| missing-catalog-row | datasets row exists, no nemar_catalog row | syncNemarCatalogFromEnrichment |
| stale-catalog | nemar_catalog.updated_at < datasets.enrichment_updated_at | Re-sync catalog row |
| failed-nemar-sync | nemar_sync_status IN ('failed', NULL) AND tag exists | Re-trigger syncDatasetToNemar |
| stuck-publish-request | publish_requests.status='pending' but GH tag exists | Mark complete or re-fire webhook |
| orphaned-github-tag | GH tag with no dataset_versions row | Insert row + generate manifest |
Phase 1 (this PR)
- Framework:
services/doctor/registry.ts, types, dispatch routes - First check:
missing-manifest(reuses existing generateManifest + uploadManifest) - Run it across all stuck datasets to recover production manifests
Phase 2+
- One sub-issue per additional check; each is a separate PR
Closes #529 mechanically once missing-version-row lands.
Activity
feat(admin): doctor framework + missing-manifest check