Skip to content

Approve blocks on a 16-step orchestrator; make it non-blocking #200

Open

Description

@neuromechanist

Surfaced by review of #198.

Problem

POST /admin/publish/:id/approve fully awaits runPublicationApproval — a sixteen-step state machine (nemar-cli backend/src/services/publication-orchestrator.ts) that walks GitHub (tree read, blob read, workflow existence check, workflow deploy, run poll, visibility flip, repo spec, tag protection), verifies S3 state, and mints a Zenodo DOI. Several steps are wrapped in withRetry at three attempts with backoff. Only waitForPublicPropagation is deferred via c.executionCtx.waitUntil; everything else blocks the HTTP response.

So a single admin click on Approve holds one request open for the entire run. On a healthy backend, one retried GitHub step is enough to push that past any reasonable client deadline.

Why a longer timeout is not the fix

#198 raised the client deadline for approve to 120s, which stops the frontend aborting a healthy run. But that only moves the wall. The real problems remain:

  • The Worker-side run is not tied to the client's AbortController. If the client does give up, the orchestrator keeps going — the admin sees a failure for something that may well be succeeding.
  • src/pages/admin/publication-requests.astro re-enables the button on error, inviting a second click while the first run may still be executing or may have partly completed. The retry sends body: "{}", not {resume: true}, so resume-skip-already-done is not guaranteed to engage. Individual steps look idempotent (DOI "already exists" handling, S3 lock 403 treated as idempotent) so corruption looks unlikely, but redoing finished GitHub calls compounds the latency that caused the timeout.
  • The admin gets no progress feedback during a run that can legitimately take a minute or more.

Ask

Make approve non-blocking: the endpoint accepts the request, starts the run, and returns immediately with a job handle. The admin page polls (or streams) progress. The orchestrator already writes per-step progress (startStep / updateProgress), so the state needed for a progress view largely exists.

Needs a nemar-cli change first; file the backend issue and link it here. Once it lands, ADMIN_TIMEOUTS_MS.approve in src/lib/admin-api.ts drops back to a normal deadline and its long comment goes away.

Activity

  1. added
    enhancement
    on Jul 29, 2026
  2. neuromechanist commented on Oct 1, 2026

    @neuromechanist
    ContributorAuthor

    Finding: the web Approve cannot finish a real dataset

    Approval is not a single request. After the irreversible publish_doi step, S3 Object Lock (step 14) runs in batches of 100 objects and returns hasMore with a continuation token that the caller must send back. The CLI loops (with retries and resume); the web page sends one {} and reloads. Any dataset over 100 files would stop in approving with its repository public and DOI published, but no S3 lock, no catalog sync and no owner email, and an approving row has no buttons to continue from. Until this lands, the web Approve button is withheld (PR #407, WEB_PUBLISH_APPROVE_ENABLED) and the page shows the CLI command.

    The loop lives in the caller on purpose: running it inside the Worker would cost too much.

    Decision

    The backend route is the contract, and executors are pluggable. For now the web button is executed by a GitHub Action in nemarDatasets/.github. The CLI path is unchanged. Not nemaring, and not the Worker.

    • Backend (nemar-cli): POST /admin/publish/:id/approve-dispatch claims the request atomically, records the clicking admin, and sends one repository_dispatch (approve-publication). The list route gains approval_in_flight so clients need no timing constant. Migration adds approval_requested_by and approval_dispatched_at.
    • Workflow (nemarDatasets/.github): approve-publication.yml runs nemar admin publish approve <id> [--resume] with one concurrency group per dataset. The environment (production or dev) selects both the API URL and the secret from a fixed map; nothing from the payload is trusted.
    • Website: the button calls the dispatch route; rows show Queued or Running with the current step, and a Resume button when a run stalls. Closing the page no longer matters.
    • Attribution forks: a CLI approval records the CLI user; a web click records the admin who clicked, not the Action's key. The audit row also records the executing key.

    Deploy order

    1. Backend to dev, verify on api-test.
    2. Workflow merged to .github main before the backend dispatches in production (a dispatch with no workflow does nothing, so the page would say "queued" forever).
    3. Backend promoted to main, then the website promoted.

    Also fixed on the way: when approve fails, the page shows the backend's real sentence instead of "Approve failed: Bad Gateway" (the backend sends it as error, which readError files under code).

  3. neuromechanist commented on Oct 1, 2026

    @neuromechanist
    ContributorAuthor

    Shipped to staging and dev

    Approval no longer runs inside the page's request. Merged 2026-10-01:

    ADMIN_TIMEOUTS_MS.approve is gone; dispatch has a 15 s deadline.

    Not yet promoted to production, and not yet run end to end: it needs the NEMAR_ADMIN_API_KEY_DEV secret on nemarDatasets/.github and a dev request to approve (an exemplar, since dev blocks non-sandbox DOI creation).

    Follow-ups, filed in nemar-cli

    • #1579 /approve takes a request_id precondition
    • #1580 persist the S3 lock continuation token so a resume does not restart at page 1
    • #1581 nemar admin publish approve exits 0 when an approval fails
    • #1582 release the lease when the executor fails before the backend can see it
    • #1583 approve-dispatch validates the dataset id before claiming
    • #1584 admin router: Origin check on cookie-authenticated unsafe routes

    Leaving this open until the change is on production.

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

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions