Skip to content

fix(datasets): hide ds* catalog shadows when on* mirror exists - #534

Merged
neuromechanist merged 1 commit into
devfrom
fix/list-endpoint-shadow-dedup
May 18, 2026
Merged

neuromechanist merged 1 commit into
devfrom
fix/list-endpoint-shadow-dedup

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Problem

GET /datasets UNIONs managed and catalog rows. The catalog half's dedup compares c.id NOT IN (SELECT dataset_id FROM datasets), but mirrored OpenNeuro datasets have:

  • managed row: dataset_id = "on002718", source = "openneuro", source_id = "ds002718"
  • catalog row: id = "ds002718"

c.id = "ds002718" never matches dataset_id = "on002718", so the catalog shadow ships alongside its canonical in every list.

Symptom on production today: GET /datasets?q=ds000117&limit=10 returns on000117, ds000117, ds002718, ds003645 — all but the first are shadows whose on counterparts exist (on000117, on002718, on003645).

Fix

Add a second NOT IN to the catalog query that joins on datasets.source_id where source = 'openneuro'. One-line behavioral change to backend/src/routes/datasets.ts:585.

WHERE c.id NOT IN (SELECT dataset_id FROM datasets WHERE status = 'active')
  AND c.id NOT IN (
    SELECT source_id FROM datasets
    WHERE status = 'active' AND source = 'openneuro' AND source_id IS NOT NULL
  )

Test

New regression test in test/api.test.ts under Datasets API > GET /datasets: lists ?limit=200, then asserts no on* row has its ds<same digits> counterpart alongside it.

Acceptance

  • GET /datasets?q=ds000117 returns 1 result (on000117), not 4
  • GET /datasets?limit=200 returns 0 shadow pairs (was 6 today)
  • Existing behavior preserved: catalog-only ds* (no on* mirror exists yet) still appear

The list endpoint's catalog UNION used a single NOT IN clause comparing
nemar_catalog.id against datasets.dataset_id. That worked for the case
where a catalog row was "promoted" into the managed table under the
same id, but missed the ds -> on mirror case entirely: mirrored rows
have dataset_id = 'on002718' while the catalog shadow keeps
id = 'ds002718', so the NOT IN never matched.

Add a second NOT IN that joins on datasets.source_id where
source='openneuro'. Catalog rows whose id appears as a managed mirror's
source_id are now hidden.

Symptom (live before this change): GET /datasets?q=ds000117 returned
on000117 plus three ds* shadows (ds000117, ds002718, ds003645) all of
which had on counterparts in the catalog. After this change the list
returns only the canonical on* rows.

Adds a regression test asserting no on* row in /datasets has its
ds* counterpart alongside it.

Refs nemarOrg/website#1 (redesign epic discover-page dedup).
@github-actions

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR534

Version: 0.8.20-PR534.bec0af3
Commit: bec0af3


🤖 Updated on each push.

@neuromechanist
neuromechanist merged commit cb69b16 into dev May 18, 2026
9 checks passed
neuromechanist added a commit that referenced this pull request May 18, 2026
…537)

* chore: bump version to 0.8.21-dev0

* Fix #535: stop seeding OpenNeuro placeholder description; route provenance to README

The OpenNeuro importer used to set the D1 datasets.description column to
'Imported from OpenNeuro <ds>' at import time. buildDatasetMetadata then
prioritized that catalog row over the LLM-enriched v2 description, so
the placeholder survived every successful enrichment cycle and the
public metadata.json endpoint kept returning it forever — defeating the
whole point of the enrichment pipeline that v0.8.20 unblocked.

Three coordinated changes:

src/lib/import-openneuro.ts: drop the description: 'Imported from
OpenNeuro <ds>' arg from importDataset(). Provenance is already
encoded by source: 'openneuro', source_id, and the on* dataset_id
prefix; the website renders the attribution badge from those fields.
Add a new appendOpenNeuroProvenance helper that writes a deterministic
'## Provenance' section to README.md at import time (idempotent;
re-running the importer is a no-op once the marker is present). The
README is the right place for human-readable provenance — it ships
with the GitHub repo, is visible without hitting any API, and stays
out of the LLM enrichment write path.

backend/src/services/data-router.ts: flip buildDatasetMetadata's
description-priority order so the LLM-enriched v2 (or v1) description
wins over row.description, with row.description as the fallback for
datasets that have not been enriched yet. The existing v2 fallback
test stays; new tests pin the placeholder→enrichment substitution and
the no-enrichment fallback.

test/import-openneuro.test.ts: new describe block for
appendOpenNeuroProvenance covering creation, append-to-existing,
idempotency, and the no-trailing-newline edge case.

The fix is forward-looking (new on* imports never get the placeholder)
and backward-compatible (existing on* datasets in D1 still have the
stale placeholder, but the metadata.json endpoint now correctly serves
the enrichment when present).

* fix(datasets): hide ds* catalog shadows when on* mirror exists (#534)

The list endpoint's catalog UNION used a single NOT IN clause comparing
nemar_catalog.id against datasets.dataset_id. That worked for the case
where a catalog row was "promoted" into the managed table under the
same id, but missed the ds -> on mirror case entirely: mirrored rows
have dataset_id = 'on002718' while the catalog shadow keeps
id = 'ds002718', so the NOT IN never matched.

Add a second NOT IN that joins on datasets.source_id where
source='openneuro'. Catalog rows whose id appears as a managed mirror's
source_id are now hidden.

Symptom (live before this change): GET /datasets?q=ds000117 returned
on000117 plus three ds* shadows (ds000117, ds002718, ds003645) all of
which had on counterparts in the catalog. After this change the list
returns only the canonical on* rows.

Adds a regression test asserting no on* row in /datasets has its
ds* counterpart alongside it.

Refs nemarOrg/website#1 (redesign epic discover-page dedup).

* chore: bump version to 0.8.21-dev1

* Address review finding: drop require('node:fs') in test helper

The pr-review-toolkit code-reviewer flagged that the readReadme() helper
in test/import-openneuro.test.ts used a dynamic require() call instead
of the ES module import already present at the top of the file. Add
readFileSync to the existing destructure and use it directly. No
behavior change; consistent with .rules/javascript.md (ES modules only).

* chore: bump version to 0.8.21-dev2

* Drop two remaining require('node:fs') calls in import-openneuro tests (#538)

Same anti-pattern that commit f9c22b4 fixed in appendOpenNeuroProvenance's
readReadme(). seedMetadata's readMeta() helper and the config.json read in
the 'metadata.json appears, config.json survives' test both still used a
dynamic require() instead of the readFileSync that's already destructured
at the top of the file. Flagged by the pr-review-toolkit code-reviewer
during the v0.8.21 release review; pre-existing on dev so non-blocking,
but bundling here keeps the file consistent and satisfies the
.rules/javascript.md 'ES modules only' rule.

* chore: bump version to 0.8.21-dev3

---------

Co-authored-by: nemar-bot <[email protected]>
@neuromechanist
neuromechanist deleted the fix/list-endpoint-shadow-dedup branch May 18, 2026 11:10

This branch was previously deployed

1 inactive deployment
npm — bec0af36 Deployed May 18, 2026 by neuromechanist via publish #965
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