Skip to content

detectProvenance picks wrong source id when on* has multiple IsDerivedFrom #19

Closed

Description

@neuromechanist

Symptom

On `/dataset/on002718`, the provenance chip reads "NEMAR copy of ds000117" and the OpenNeuro link points at ds000117. The header correctly says "Imported from OpenNeuro ds002718" and the canonical `source_id` in the catalog is also `ds002718`.

Cause

`metadata.json` for re-released OpenNeuro datasets carries multiple `IsDerivedFrom` entries — the older OpenNeuro id (this dataset was originally released as ds000117 then re-released as ds002718) AND the canonical:

```json
"related_identifiers": [
{ "identifier": "10.18112/openneuro.ds000117", "relation_type": "IsDerivedFrom" },
{ "identifier": "10.18112/openneuro.ds002718.v1.1.0", "relation_type": "IsDerivedFrom" }
]
```

`detectProvenance` iterates with `??=` and locks the first hit (`ds000117`).

Fix

Prefer the candidate whose extracted ds id matches `id.replace(/^on/, "ds")` (the canonical on->ds swap). Fall back to the first candidate when no match. Falls back further to the swap-only path when there are no `IsDerivedFrom` entries at all (existing behavior).

Acceptance

  • `on002718` -> provenance chip says `ds002718`, link goes to openneuro.org/datasets/ds002718
  • `on005262` (single IsDerivedFrom, matches) -> unchanged
  • `on*` with no related_identifiers -> unchanged (id-swap fallback)
  • `on*` with only a non-matching IsDerivedFrom -> falls back to that entry (best we can do)

Activity

  1. neuromechanist commented on Jul 29, 2026

    @neuromechanist
    ContributorAuthor

    Already fixed on main — no code change needed here.

    The fix landed in PR #20 (fix(provenance): prefer canonical ds id when multiple IsDerivedFrom entries, commit a485d00), which merged into the epic branch feature/issue-1-epic-nemar-redesign on 2026-05-18. That branch's history (including this commit) is now part of main following the Phase 5 cutover. This issue stayed open only because PR #20's base at merge time wasn't the repo's default branch, so GitHub's "Closes #19" auto-close never fired.

    src/lib/provenance.ts on current main already implements exactly the fix this issue asks for: it collects all DERIVED_RELATIONS candidates from related_identifiers, then picks the one whose extracted ds id matches id.replace(/^on/, "ds"), falling back to the first candidate, then to the id-swap-only path when there are no matches at all.

    src/lib/provenance.test.ts on main already covers all four acceptance cases from this issue:

    • multiple IsDerivedFrom (on002718 -> ds002718, canonical wins over ds000117)
    • single matching IsDerivedFrom (on005262 -> ds005262, unchanged)
    • no related_identifiers (id-swap fallback, unchanged)
    • only a non-matching IsDerivedFrom (falls back to that entry)

    Re-verified today in a clean worktree off origin/main:

    • bun run test — 906/906 passing, no changes needed
    • bun run typecheck — 0 errors
    • bun run lint — clean
    • Live check: https://data.nemar.org/on002718/metadata.json currently returns exactly the two IsDerivedFrom entries quoted in this issue (ds000117 and ds002718.v1.1.0), confirming the fixture shape is accurate and the picked id is ds002718.

    Closing as already resolved. Reopen if /dataset/on002718 is still showing the wrong OpenNeuro link in production.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions