Skip to content

Enrichment: Sonnet 5.5 and stricter data-paper relation typing - #1550

Merged
neuromechanist merged 14 commits into
devfrom
feature/enrich-sonnet-5-5
Sep 29, 2026
Merged

neuromechanist merged 14 commits into
devfrom
feature/enrich-sonnet-5-5

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1549.

Why

The citation pipeline (nemarOrg/nemar-citations) credits a dataset with the citations of the DOIs that .nemar/metadata.json marks as describing the data. The enrichment LLM saw only README prose and bare DOI strings, so it got the label wrong in both directions: nm000275's own Scientific Data descriptor ended up as References, while MNE-BIDS, EEG-BIDS, and MEG-BIDS ended up as IsDescribedBy on dozens of datasets.

What changed

  • Model: enrichment, validation, and correction run on claude-sonnet-5-5 ($2 / $10 per MTok; estimateUsageCostUsd updated). The request shape is unchanged: effort: "low", no thinking field, and no forced tool_choice.
  • One registry fetch path (doi-registry.ts):
    • ORCID discovery (stages 1b and 2c) and DOI metadata resolution (stage 1d) share a per-run cache, so each (registry, DOI) pair is fetched once per enrichment run.
    • Every lookup is classified: found; absent (HTTP 400, 404, or 410); or failed (429, 5xx, timeout, network error).
  • Resolved DOI metadata (stage 1d):
    • Candidates are the DOIs in the BIDS fields, the existing related identifiers, and the README. At most 15 are looked up, 5 at a time, and the dataset's own NEMAR DOI is skipped.
    • Extraction keeps balanced parentheses, e.g. 10.1016/S0006-3223(99)00000-0.
    • Each DOI's title, first author, year, venue, and type go into the enrichment, validation, and correction prompts.
    • Registry text is sanitized before it reaches a prompt: markup and control characters stripped, whitespace collapsed, double quotes swapped for single, and titles capped at 300 characters.
  • Deterministic guard (enforceNeverDataPaper):
    • It runs at the seed, after resolution, after each merge, and on the final document.
    • It demotes listed standards, software, platform, and umbrella DOIs (now including NIRS-BIDS) from any data-describing relation to References. It also demotes DOIs whose title matches the BIDS-spec rule.
    • It drops the dataset's own 10.82901/nemar.<id> DOI, concept or version, under any relation (on008862 and on007655 carried their own DOI as IsSupplementTo).
    • IsSupplementTo on an unlisted DOI is left for nemar-citations' judge. URL IsDescribedBy entries are untouched.
  • DOI key and title rule are ported from nemar-citations' normalize_doi and is_spec_title. The title rule's phrase form is anchored at the start of the title, so data papers that mention an extension no longer match.
  • IsDerivedFrom ratchet:
    • The LLM may promote References to IsDerivedFrom, or add a new IsDerivedFrom, only for a DOI whose DataCite resourceTypeGeneral is Dataset. Otherwise the entry stays, or lands as, References.
    • The validator no longer raises blocking issues about IsDerivedFrom, since the corrector and merge cannot act on them.
  • Reporting:
    • The enrichment body gains doi_resolution: {resolved, unresolved, failed, skipped}, plus demoted_dois and self_dois_dropped when non-empty.
    • The single and bulk reindex responses carry doi_resolution.
    • nemar admin reindex prints it, and gains --json.
  • ADR 0075 records the rules and the cross-repo obligation to keep the list in step with nemar-citations.

The MIPDB resource paper (10.1038/sdata.2017.40, Langer et al. 2017) is deliberately not blocked: it is nm000153's own data descriptor.

Tests

  • bun run typecheck: clean
  • Biome on every changed file: clean (bun run lint, which covers src/, is clean)
  • Offline unit-pure tier, same file classification as test.yml: 7299 pass, 26 skip, 0 fail across 416 files (local, at 80ba196c)
  • Live DataCite and Crossref integration tests (doi-metadata, doi-orcid-discovery): 18 pass, 0 fail
  • Each intermediate commit typechecks and passes the enrichment test files on its own. Exception: at 295b86a0 the source-level guard in backend/test/enrich-doi-sync-skip.test.ts fails, because Biome wrapped the pinned return { ok: false, error: subErrors.join(...) } line. 80ba196c restores that exact line; the test is unchanged, and a skip-only body still returns ok: true.
  • Mutation-checked: 15 single-line mutations of the new behavior, each caught by a failing test (status table, failed vs. unresolved, sanitizer, parenthesis extraction, version DOI, self-DOI drop, ratchet, new-entry gate, phrase anchor, normalization loop, seed and final guard wiring, Dataset set, NIRS-BIDS entry)

Parse tests run on recorded real DataCite and Crossref responses (test/fixtures/doi-registry/), including a live Crossref record with author: null and date-parts: [[null]], and a title carrying <i> markup and line breaks. Malformed shapes are real responses with a single field broken.

enrichDataset itself is not driven end to end, for the same blocker backend/test/enrich-doi-sync-skip.test.ts documents: a process-wide mock.module of the github service returns an empty tree. backend/test/enrich-relation-guard-wiring.test.ts instead pins, at the source level, that every guard call gets the context, that titles are in place before the first LLM merge, that the final guard runs before the commit, that both merges get the Dataset evidence, and that all three lookup stages share the cache.

Post-deploy: re-enrichment sweep

Run this against production after the release that ships this PR. It needs the CLI from that release, for --json and doi_resolution.

Scope.

  • reindex --all selects every dataset with a github_repo, except the xx sandboxes; the live catalog reports 777.
  • Each run is forced. For every dataset it:
    • commits .nemar/metadata.json (and possibly an auto-generated participants.tsv);
    • refreshes D1;
    • syncs DOI metadata to EZID when the dataset has a concept DOI;
    • may open a "Metadata validation failed" issue on the dataset repo.
  • The live datasets nm000103 to nm000107 are excluded below.

Drive it one dataset at a time. The bulk request runs sequentially inside one Worker request, so a full catalog would exceed the per-invocation subrequest limit, and it cannot resume.

export FORCE_COLOR=0

# 1. Everything --all would touch, minus the LIVE datasets nm000103-nm000107.
nemar admin reindex --all --dry-run --json \
  | jq -r '.datasets[]' \
  | grep -vxE 'nm00010[3-7]' > sweep.txt
wc -l < sweep.txt

# 2. Pilot, then inspect each dataset's .nemar/metadata.json:
#    nm000275: its Scientific Data paper becomes IsDescribedBy
#    nm000273: MNE-BIDS and EEG-BIDS become References
#    on002721: the typo'd 10.1038/sdata.2018.203 becomes References
for id in nm000275 nm000273 on002721; do nemar admin reindex "$id"; done

# 3. Sweep. Resumable: rerun this block until retry.txt and failed.txt stay empty.
touch done.txt
: > retry.txt
: > failed.txt
while IFS= read -r id; do
  grep -qxF "$id" done.txt && continue
  if out=$(nemar admin reindex "$id" --json < /dev/null); then
    # A registry did not answer (429, 5xx, timeout): labels were chosen
    # without that DOI's metadata, so run the dataset again later.
    if printf '%s' "$out" | jq -e '(.enrichment.doi_resolution.failed // 0) > 0' > /dev/null; then
      echo "$id" >> retry.txt
    else
      echo "$id" >> done.txt
    fi
  else
    echo "$id" >> failed.txt
  fi
done < sweep.txt
wc -l done.txt retry.txt failed.txt

The sweep runs for hours, so start it in tmux. A dataset in failed.txt had an enrichment or sync error; its reason is on stderr, and nemar admin reindex <id> shows it again.

Cost at $2 / $10 per MTok:

  • A typical run makes 2 calls (enrich and validate): about 11 to 13k input and 2.5 to 3.5k output tokens, roughly $0.05 to $0.06 per dataset. Across the catalog that is about $40 to $50.
  • The worst case is 3 correction rounds, 8 calls, about $0.22 per dataset. The bound is about $170 if every dataset needed all of them.

llm_usage.est_cost_usd in each --json result gives the real figure, so measure the pilot and extrapolate.

Deliberate differences from nemar-citations

  • normalizeDoiKey repeats the unmatched-) and trailing-punctuation trims until nothing changes. Python's normalize_doi trims each once, so (10.1016/S0006-3223(99)00000-0). keeps a stray ) there.
  • Resolver prefixes are stripped case-insensitively. Python matches https://doi.org/ and the others case-sensitively.
  • JavaScript's \w in the name rule is ASCII-only.

@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR1550

Version: 0.10.10-PR1550.80ba196
Commit: 80ba196


🤖 Updated on each push.

@neuromechanist

Copy link
Copy Markdown
Contributor Author

Review round 1: findings and resolution

A Sonnet review raised 14 findings. All 14 are addressed on this branch, in commits 092f0fb9 through 80ba196c.

# Finding Resolution
1 Runbook filter never matched the - id dry-run lines, and $(...) split them unquoted The runbook now reads the IDs with --dry-run --json | jq -r '.datasets[]', excludes nm000103 to nm000107 with grep -vxE, and uses a quoted while read loop (PR body)
2 NIRS-BIDS not listed Added 10.1038/s41597-024-04136-9; the title-rule test now uses ASL-BIDS (10.1038/s41597-022-01615-9), which is not listed (85728eef, 295b86a0)
3 Title rule matched "extension" anywhere Ported the name rule and the start-anchored phrase rule; all five negatives are tested (85728eef)
4 DOI normalization diverged from normalize_doi normalizeDoiKey now strips doi: and the http/https doi.org and dx.doi.org prefixes, trims unmatched ), strips .,;:, and lowercases; it is used for the title lookup too (85728eef, 9cb5e33d)
5 Own DOI enforceNeverDataPaper(target, { datasetId, resolvedTitles }) drops 10.82901/nemar.<id> concept and version DOIs; tested against on008862's live entries (295b86a0)
6 IsSupplementTo No deterministic rewrite; only a listed DOI is demoted; tested (295b86a0)
7 References to IsDerivedFrom ratchet Allowed only for a DataCite resourceTypeGeneral of Dataset, for new entries too; IsDerivedFrom removed from the validator's blocking list (295b86a0)
8 Registry outages indistinguishable from 404 Lookups are classified as found, absent, or failed; doi_resolution is on the enrichment body and the single and bulk reindex responses; the runbook routes failed > 0 to retry.txt (9cb5e33d, 295b86a0, 4cd08cbf)
9 Tests Parse tests on recorded real DataCite and Crossref responses, including malformed shapes; enrichDataset cannot be driven in-suite (see enrich-doi-sync-skip.test.ts), so enrich-relation-guard-wiring.test.ts pins the wiring at the source level
10 DOI_IN_TEXT dropped parentheses Now uses nemar-citations' _DOI_BARE character class; tested on 10.1016/S0006-3223(99)00000-0 (9cb5e33d)
11 Prompt safety sanitizeRegistryText strips markup and control characters, collapses whitespace, swaps " for ', and caps titles at 300 characters (9cb5e33d)
12 Duplicate lookups doi-registry.ts gives stages 1b, 1d, and 2c one per-run cache; a live test shows stage 1d makes no new requests after ORCID discovery (092f0fb9, 9cb5e33d)
13 MIPDB mislabel Code comment, ADR 0075, and the PR body now call it the MIPDB resource paper (85728eef, 8ca84cfd)
14 Em-dashes Removed from every added line (295b86a0, 8ca84cfd)

A regression found in CI and fixed: 295b86a0 wrapped the sub-error return in runEnrichmentForDataset, and that broke the source-level guard in enrich-doi-sync-skip.test.ts (#1255 item 26). 80ba196c restores the exact pinned line by spreading a reported object on both branches. The test is unchanged, and a skip-only body still returns ok: true.

Verification: typecheck is clean; Biome is clean on the changed files; the offline tier, integration tests, and mutation results are listed in the PR body.

@neuromechanist
neuromechanist merged commit 691122f into dev Sep 29, 2026
12 checks passed
@neuromechanist
neuromechanist deleted the feature/enrich-sonnet-5-5 branch September 29, 2026 17:16
neuromechanist added a commit that referenced this pull request Sep 29, 2026
dev took ADR 0075 (#1550), so the news images ADR is renumbered 0076, with the migration comment and the index updated. Typecheck, news suites (90), and migrations:d1-check pass after the merge.
neuromechanist added a commit that referenced this pull request Sep 29, 2026
* docs: CHANGELOG entry for 0.10.10

Covers #1550 (Sonnet 5.5 enrichment, DOI lookups, relation guard) and
#1552 (biosigio 1.2.10 case-only sidecar matches). Claims checked against
the merged code.

* docs: add #1556 to the 0.10.10 entry

Failed-lookup warnings, the lookup-stage deadline, the over-cap marker,
and the summary now printing warnings. Changelog format test passes.

This branch was previously deployed

1 inactive deployment
npm — 80ba196c Deployed Sep 29, 2026 by neuromechanist via publish #2969
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