Repository navigation
feat(enrich): auto-generate participants.tsv when missing at root - #553
Merged
Merged
Conversation
BIDS treats participants.tsv as RECOMMENDED rather than REQUIRED, so the validator passes when it is absent. The catalog flow doesn't tolerate that: subject_count is read from participants.tsv, and without it the column stays NULL forever -- which then re-traps the row in --missing-metadata sweeps (fixed via the recency guard in #552). Two paths fall in the trap today: - nm* uploaded via 'nemar upload' where the user didn't include the file (e.g. nm000133; fixed per-dataset via PR nm000133#3) - on* imported via --trust-upstream when the OpenNeuro source itself lacks one (e.g. ds005262; OpenNeuro upstream confirmed missing) Fix structurally in enrichment, which is the single point that runs after BOTH paths: 1. New backend/src/services/participants-tsv.ts -- pure helpers: - enumerateBidsSubjects(tree): finds every sub-* dir at root - buildPlaceholderParticipantsTsv(subjects): emits a minimal BIDS-compliant TSV with n/a for age and sex (the safe placeholder BIDS recognizes for 'not collected / not disclosed') - ensureParticipantsTsv(tree): pure decision -- returns the content to commit, or null when the file already exists or when the tree has no subjects (refusing to fabricate) 2. backend/src/services/enrich-dataset.ts Stage 1c: when the tree has no participants.tsv, call ensureParticipantsTsv. Queue the result for the enrichment commit so the file lands alongside .nemar/metadata.json in a single batched commit. Also use the generated content for the in-memory subject_count parse so the catalog gets the right number on this very enrichment run. 3. backend/src/services/github.ts commitEnrichmentWithBidsignore: accept an optional additionalFiles[] param. When non-empty, force the batched-tree commit even if .bidsignore didn't change. Lets the enrichment commit batch metadata + bidsignore + participants.tsv in a single tree write rather than two commits. Doesn't bypass --trust-upstream: enrichment runs after the OpenNeuro import path too, so the auto-generation lands on on* mirrors as well. The dataset repo retains the file across future enrichments; if real demographics later become available, a follow-up commit can replace the placeholder. The clientCommits path (Action does the commit) doesn't yet thread additionalFiles through buildEnrichmentCommitPayload -- TODO follow-up, the in-process path covers the common case. 14 new unit tests cover subject enumeration (derivatives ignored, alphanumeric ids, dedup, sort order), the TSV formatter, and the decision rule (already-present / generate / no-subjects-skip).
- commitEnrichmentWithBidsignore: defensive duplicate-path guard. The
treeFiles array is now checked for repeats before commitFilesAsTree
is called; throws EnrichmentCommitError('duplicate path ...') instead
of letting GitHub's tree API silently last-wins. Prevents a future
caller from accidentally clobbering metadataPath or .bidsignore via
additionalFiles.
- enrich-dataset.ts: log message now says 'pending commit' to make the
one-cycle inconsistency window (subject_count derived from in-memory
TSV before the commit succeeds) explicit in tail logs.
- New unit test pins rejection of hyphenated subject labels
(sub-PD-01). BIDS strictly defines labels as ^[0-9a-zA-Z]+$; we
intentionally skip non-conformant datasets rather than fabricate
partial participants.tsv files. The test documents that decision so
a future regex tweak can't silently flip it.
- Three new tests for commitEnrichmentWithBidsignore additionalFiles
path (zero coverage before): bidsignore-unchanged forces batched,
bidsignore-needs-update batches all three, duplicate-path collision
is rejected.
42 unit tests pass.
Contributor
Author
pr-review-toolkit review (sonnet)Two reviewers, all actionable findings addressed in 63b6c3c. code-reviewer (APPROVE w/ suggestion)
pr-test-analyzer (NEEDS MORE COVERAGE)
42 unit tests pass, typecheck clean. |
This was referenced May 18, 2026
Contributor
Author
Fresh review pass (pr-review-toolkit:code-reviewer)The PR has been stable for 4 days while dev moved 30+ commits forward; this re-review confirms no new conflicts surfaced. Critical: none. Important (1 actionable):
Already addressed by prior review pass (commit "review: address pr-review-toolkit findings on #553"): all the original-review findings. Strengths confirmed against current dev:
Companion to PR #579 (the `--missing-metadata` recency guard). These two solve the same root symptom (`nm000133` reindex loop) from different angles. Land together. |
📦 Package PreviewYour package is ready to test! bun install -g nemar-cli@PR553Version: 🤖 Updated on each push. |
neuromechanist
added a commit
that referenced
this pull request
May 22, 2026
…#579) Adds a recency guard to the reindex --missing-metadata filter so datasets whose upstream genuinely lacks required columns (e.g. nm000133 has no participants.tsv → subject_count stays NULL) don't get reindexed every hour with no progress. Default 24h; force-retry via --all. Replaces auto-closed #552. Companion to #553.
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem (architectural)
BIDS treats `participants.tsv` as RECOMMENDED rather than REQUIRED, so the bids-validator passes when it's absent. The NEMAR catalog flow doesn't tolerate that: `subject_count` is read exclusively from participants.tsv. Without it the column stays NULL forever, which then re-traps the row in `--missing-metadata` sweeps (the recency guard in #552 stops the loop but doesn't populate the data).
Two paths fall in the trap:
Per-dataset PRs aren't a scalable fix.
Architectural fix
The enrichment pipeline runs after BOTH paths (including `--trust-upstream`). Hooking the auto-generation there means a single point of repair.
New `backend/src/services/participants-tsv.ts` (pure, ~115 lines):
`enrich-dataset.ts` Stage 1c: when the tree has no participants.tsv at root, call `ensureParticipantsTsv`. Queue the result for the enrichment commit so it lands alongside `.nemar/metadata.json` in a single batched tree write. Use the generated content for the in-memory subject_count parse too so the catalog gets the right count on this very run.
`commitEnrichmentWithBidsignore` accepts an optional `additionalFiles[]` param; when non-empty, forces the batched-tree commit mode even if .bidsignore didn't change, so metadata + bidsignore + participants.tsv land in one commit.
Doesn't bypass --trust-upstream
The whole point: enrichment IS the path that --trust-upstream uses post-import. The auto-generation lands on on* mirrors that arrive without participants.tsv just as well as nm* datasets where the uploader omitted it.
Tests
14 unit tests cover the three pure helpers across the shapes we actually see:
Out of scope
Refs nm000133#3 (per-dataset fix); supersedes the per-dataset approach.