Skip to content

fix: auto-clear stale publish-request blocks (#428) - #801

Merged
neuromechanist merged 2 commits into
devfrom
fix/issue-428-stale-block-reason
Jun 18, 2026
Merged

neuromechanist merged 2 commits into
devfrom
fix/issue-428-stale-block-reason

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Problem

nemar dataset publish request blocks a request when BIDS validation CI is pending/running (block_reason='bids_validation_pending' | 'bids_validation_in_progress'). That block was one-shot: nothing re-evaluated the request when CI later went green, so requests sat in blocked forever. 13 of bruaristimunha's requests were stuck for weeks and had to be cleared by hand.

Fix (cron sweep + CLI hint)

  • backend/src/services/publication-sweep.ts (new):
    • evaluateBlockedBidsValidation() — pure decision: no runs → keep; latest success → unblock; latest failure → re-block as bids_validation_failed; null/cancelled/skipped → keep.
    • sweepBlockedBidsValidationRequests() — finds every blocked request with a bids_validation_* reason, re-reads the latest bids-validation.yml run via getWorkflowRuns (same call the publish-request path uses), and transitions it. Never throws; per-row failures are counted and skipped. Updates are guarded on status='blocked' so a concurrent re-request can't be clobbered.
  • backend/src/index.ts — wired into scheduledCleanup (daily 3 AM cron) as step 5, with a tally in the audit log + summary line.
  • CLI dataset publish status — now surfaces the block_reason message, the CI link, and a next-step hint instead of a bare Status: blocked (the issue's "side note"). Added ci_url to PublishStatusResponse.

Design notes

  • No email from the sweep — a daily batch could otherwise fire a burst of notifications for a backlog. Unblocked requests re-enter the admin queue (nemar admin publish list); the move is logged.
  • Webhook real-time path is a deliberate follow-up. The issue also proposes a workflow_run.completed webhook for near-real-time clearing. That needs the nemar-publish-bot GitHub App to also subscribe to workflow_run events (infra/config outside this repo), so it's not in this PR. The cron sweep already resolves the stuck-row problem on its own (it's the "defense in depth" item the issue lists); the webhook would only reduce latency from ~1 day to minutes.

Tests

test/publication-sweep.unit.test.ts pins the decision matrix (all conclusion states) and that the swept block-reason set matches what the readiness check can produce. 6 pass; tsc --noEmit 0; biome check src/ clean.

Closes #428

A publish request blocked while BIDS validation CI was pending/running
never re-checked itself when CI later passed, so requests sat in
'blocked' indefinitely (13 stuck for weeks, cleared by hand).

- publication-sweep.ts: pure evaluateBlockedBidsValidation() + a daily
  cron sweep that re-reads the latest bids-validation.yml run for each
  blocked request and transitions it (green -> requested, failing ->
  bids_validation_failed). Reuses getWorkflowRuns so the cron and the
  interactive readiness check can't disagree.
- index.ts: wire the sweep into scheduledCleanup (step 5) + audit log.
- CLI publish status: surface the block_reason message, CI link, and
  next-step hint instead of a bare 'Status: blocked'.

Real-time webhook re-eval is a follow-up (needs the GitHub App to also
deliver workflow_run events); the cron sweep resolves the stuck rows
without that infra change.

Closes #428
@github-actions

github-actions Bot commented Jun 18, 2026 •

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR801

Version: 0.8.62-PR801.f496733
Commit: f496733


🤖 Updated on each push.

@neuromechanist

Copy link
Copy Markdown
Contributor Author

PR review (pr-review-toolkit, Sonnet) — code-reviewer + silent-failure-hunter

All findings addressed in f496733:

  1. Unblock now clears stale prescreen columns (code-reviewer, conf 87) — the interactive re-request path nulls prescreen_status/nonce/issue_url/reasons on unblock; the sweep only cleared block_reason, so a previously-screened request would surface a phantom advisory after the sweep moved it to requested. Now mirrors the interactive UPDATE exactly.
  2. Initial SELECT wrapped in try/catch (silent-failure CRITICAL) — a D1 outage/schema drift on the opening query previously threw past the "never throws" contract and (via the outer cron catch) produced an all-zero tally indistinguishable from "nothing to do". Now logs + errors++ + returns.
  3. getDatasetsToken failure increments errors (silent-failure HIGH) — a broken token now shows errors>0 in the audit log instead of reading as a clean run.
  4. Both UPDATEs wrapped in per-row try/catch (silent-failure MEDIUM) — a transient D1 error on one row no longer aborts the whole sweep; it's counted and skipped, matching the getWorkflowRuns per-row pattern.

Not changed (self-downgraded by the reviewer): the bids-validation.yml filename — it correctly matches the interactive publish-request path.

Clean items confirmed: SQL IN (...) bind order (3 constants + LIMIT), the WHERE id=? AND status='blocked' concurrency guard, the decision matrix, the 0-row-changed handling, and the CLI display.

Re-verified: 6 tests pass, tsc --noEmit 0, biome check src/ clean.

@neuromechanist
neuromechanist merged commit a7b3fd4 into dev Jun 18, 2026
10 checks passed
@neuromechanist
neuromechanist deleted the fix/issue-428-stale-block-reason branch June 18, 2026 21:56

This branch was previously deployed

1 inactive deployment
npm — f4967333 Deployed Jun 18, 2026 by neuromechanist via publish #1491
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