Skip to content

Admin doctor framework for diagnosing/fixing stuck datasets #554

Closed

Description

@neuromechanist

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_versions row exists but S3 manifest.json missing → data.nemar.org/<id>/<version>/manifest.json 404s (active right now: ~10 datasets including on005261, nm000103, nm000106, nm000166, on004362)
  • latest_version_doi set but no dataset_versions row (the original symptom in Stuck publish: ~33% of on* datasets have GitHub tag but no version row #529)
  • subject_count IS NULL because 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_catalog row missing for a dataset (migrations 0023/0024 backfilled this once)
  • nemar_sync_status failed 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

  1. added
    P1
    feature
    on May 18, 2026
  2. added a commit that references this issue on May 18, 2026
    2dc7654
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions