Skip to content

feat: automated publication pre-screen (#666) - #667

Merged
neuromechanist merged 4 commits into
devfrom
feature/issue-666-publication-prescreen
Jun 1, 2026
Merged

neuromechanist merged 4 commits into
devfrom
feature/issue-666-publication-prescreen

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Closes #666.

What

Adds an automated, feature-flagged publication pre-screen. When a user requests publication and the dataset passes BIDS-validation readiness, the Worker dispatches repository_dispatch[run-prescreen] to nemarDatasets/.github, which runs claude -p --model haiku against the dataset and POSTs a verdict back. NEMAR stays a publisher, not a peer reviewer — the screen only checks the publisher minimum.

Block criteria (Recommended gate)

  • No real data (declared annex size ~0, or S3 objects/ prefix empty)
  • README missing/empty or citations-only (must say what the data is + how to use it)
  • dataset_description.json missing Name or Authors

Missing data paper = non-blocking note.

Backend changes

  • migration 0028_prescreen.sql: prescreen_status, prescreen_nonce, prescreen_issue_url, prescreen_at on publication_requests.
  • github.ts: triggerPrescreenRun dispatch + sign/verifyPrescreenCallbackToken (same one-shot HMAC handshake as the manifest callback).
  • webhooks.ts: POST /webhooks/prescreen-result + pure decidePrescreenOutcome / validatePrescreenCallbackBody. The handler runs an independent server-side S3 presence check (getDatasetS3Stats, Worker has creds) and combines it with the claude verdict.
  • datasets.ts: prescreen_failed block message + dispatch on publish request (non-blocking, logged on failure).
  • email.ts: sendPublicationBlockedEmail.
  • bindings.ts: PRESCREEN_ENABLED flag + PRESCREEN_CALLBACK_SECRET.

Companion workflow run-prescreen.yml is a separate PR on nemarDatasets/.github.

Safety / rollout

  • Dark by default: dispatch only fires when PRESCREEN_ENABLED="true" AND PRESCREEN_CALLBACK_SECRET is set, so this deploy changes nothing until explicitly enabled. No prod deploy in this PR.
  • Callback is HMAC-verified and one-shot (gated on prescreen_status='pending').
  • S3 read error -> s3=null -> never a false block.

Secrets to add before enabling

  • Worker: PRESCREEN_CALLBACK_SECRET (prod + dev)
  • nemarDatasets/.github: CLAUDE_CODE_OAUTH_TOKEN, NEMAR_ADMIN_TOKEN

Tests

163 related tests pass; 28 new (token round-trip + tamper, dispatch payload, decision/validator). Typecheck clean.

Context

Backfill of a 99-dataset EEGDash bulk import (2026-06-01) surfaced 8 with missing README/metadata/data; this automates that screen going forward.

@github-actions

github-actions Bot commented Jun 1, 2026 •

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR667

Version: 0.8.40-PR667.6a5c98e
Commit: 6a5c98e


🤖 Updated on each push.

@neuromechanist

Copy link
Copy Markdown
Contributor Author

PR review (pr-review-toolkit, Sonnet) — findings + resolutions

Ran code-reviewer, silent-failure-hunter, and pr-test-analyzer in parallel. All real findings addressed in f2235ea (backend) + the companion workflow commit.

Critical (fixed)

  • Workflow broke on every real dataset — EXTS="edf:5 json:10 …" and RFILE=<none> written to /tmp/ctx.env then sourced under set -e → source mis-parsed the multi-word value / treated <none> as a redirect and aborted before any verdict, stranding the row in prescreen_status='pending'. Fix: merged context-build into the screen step; values stay as in-shell variables, no source round-trip.
  • Re-unblock left stale pre-screen state — transitioning a prescreen_failed request back to requested didn't clear prescreen_status/nonce, so a future enable would never re-screen it (status 'failed' ≠ 'pending'). Fix: unblock UPDATE now clears prescreen_status, prescreen_nonce, prescreen_issue_url.

High (fixed)

  • Workflow crash before verdict stranded the row forever (no callback fired). Fix: added a Report failure callback step that POSTs verdict:"error"; the handler resets prescreen_status=NULL so the request falls back to manual admin review.
  • try/catch around waitUntil was dead code — async email rejection isn't caught by it. Fix: .catch() attached to the email promise with the dataset id in the message.

Medium (fixed)

  • Duplicate block email possible on a racing replay. Fix: email only sent when res.meta.changes > 0 (this call did the transition).
  • prescreen_issue_url not surfaced in publish/status. Fix: returned when block_reason='prescreen_failed'.
  • No size cap on dataset_description.json fed to the model. Fix: head -c 4096.
  • Silent null from RETURNING id. Fix: console.warn when the insert returns no id.

Tests (added)

  • sign-side "changes when secret changes"; verdict=block + null-S3 preserves reasons; verdict='error' accepted; request_id 0/-1 accepted, NaN/Infinity rejected; s3-arm dedup. 169 related tests green; real config untouched.

Assessed, not changed

  • issue_title shell-injection (code-reviewer, conf 91): false positive. --title "$TITLE" is safe — bash does not re-evaluate $() that lives in a variable's value; command substitution only fires from source text. Hardened cosmetically anyway (tr -d '\000-\037' | head -c 180).
  • Prompt-injection of the model verdict (adversarial README steering a "pass"): accepted residual risk, mitigated by --disallowedTools + the independent server-side S3 presence check that can override a bogus pass.
  • Persistent S3 credential failure silently disables the data check: logged per-call; a metric/alert is out of scope for this PR (the claude verdict still sees "0 MB / 0 files").

Separate incident fixed here

test/publish-progress.test.ts called setConfig("apiKey","test-token-284") against the real ~/.config/nemar/config.json (no isolation) — it clobbered a live admin key during this very session. Now isolated via a throwaway NEMAR_CONFIG_DIR with restore + cleanup.

@neuromechanist

Copy link
Copy Markdown
Contributor Author

CI status (for whoever merges)

Green: lint, unit-test, api-test, e2e-sandbox, zenodo-sandbox-test, publish, changes.

Red: unit-test-all — pre-existing, unrelated. The 4 failures are environment-dependent integration tests that hit real services and are already red on dev HEAD (0.8.40-dev1):

  • data.nemar.org catalog index (#584)
  • IAM Removal: collaborator can get upload credentials for nm099999
  • IAM Removal: collaborator can get presigned upload URLs
  • IAM Removal: collaborator gets download credentials

This PR touches no IAM/collaborator/credential code; no prescreen or publish-progress test fails. Held for manual merge per owner decision. Merge target: #667 → dev, companion #17 → main. Dark by default (PRESCREEN_ENABLED unset).

@neuromechanist
neuromechanist merged commit 3c6cdfd into dev Jun 1, 2026
10 checks passed
@neuromechanist
neuromechanist deleted the feature/issue-666-publication-prescreen branch June 1, 2026 23:13

This branch was previously deployed

1 inactive deployment
npm — 6a5c98ef Deployed Jun 1, 2026 by neuromechanist via publish #1230
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