Skip to content

Warn when pulling a dataset still being ported - #470

Merged
neuromechanist merged 3 commits into
devfrom
feature/issue-460-port-pull-warning
May 14, 2026
Merged

neuromechanist merged 3 commits into
devfrom
feature/issue-460-port-pull-warning

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Closes #460.

What changed

nemar dataset download <id> and nemar dataset get against an OpenNeuro-imported dataset whose porting workflow is still mid-flight used to fail with a cryptic git annex get error (typically "remote unavailable" / "no known location"). The user reported the bug as "pulling data after porting fails" — they had no way to tell whether the dataset was broken or simply not done copying yet.

Fix is scoped to the client-side warning path the brief recommended:

  • New helper detectImportMarker(datasetPath) in src/lib/git-annex.ts. Inspects the local clone's git history for any commit that touched .nemar/metadata.json (the importer always emits one as its final step before pushing — see src/lib/import-openneuro.ts step 6). Returns present / absent / unknown.
  • nemar dataset download checks the marker after clone, only when the resolved dataset record has source === "openneuro". If absent, prints a clear "Porting still in progress" warning with a retry hint and exits non-zero before requesting download credentials or running git annex get.
  • nemar dataset get does the same check after fetching dataset info from the backend.

Why marker absence is a reliable signal: the importer pushes main and git-annex branches atomically (step 7), so by the time the metadata commit is visible in the clone, the S3 copy (step 5) has already completed. A clone without the marker is either an empty auto_init: false shell (repo created but importer hasn't pushed) or a partially-pushed history (the importer aborts on partial push, so this should not exist in practice; if it ever does we still bail with a useful message rather than letting git-annex throw).

Scope decisions

  • No backend changes. The brief flagged that backend porting state would be a wider scope; I kept this PR client-side only. A future improvement could add a status='importing' flag on the datasets row and gate the warning on that for a more precise signal.
  • No git-annex error rewriting. The marker check fires before git annex get, so we never need to parse its error output for this case. If a different "objects not in S3" failure mode shows up (e.g., S3 ACL drift on a published dataset), that's a separate issue.
  • Non-OpenNeuro datasets are untouched — the new check is gated on source === "openneuro".

Test plan

  • 4 new unit tests in test/git-helpers.test.ts for detectImportMarker:
    • empty repo (no marker commit) -> absent
    • repo with committed .nemar/metadata.json -> present
    • file present in working tree but uncommitted -> absent (guards a false-positive)
    • non-git directory -> unknown
  • bun test test/git-helpers.test.ts -> 14/14 pass
  • bun run build succeeds
  • bun run typecheck clean
  • cli.test.ts integration test count unchanged from baseline (13 pre-existing failures, none new)

@neuromechanist

Copy link
Copy Markdown
Contributor Author

PR Review: #470 — Warn when pulling a dataset still being ported

Critical

1. False negative in get command when API is unreachable

In the get command (~line 4007 of dataset.ts), getDataset() is wrapped in a bare catch {} that silently swallows errors. If the backend is unreachable, dsInfo stays null, dsInfo?.source === "openneuro" evaluates false, and the marker check is never reached. The user gets the original cryptic git annex get error instead of the new warning. The protection vanishes exactly when the user is working in a degraded-network environment. The fix: cache the resolved source before the credential-fetch try/catch, or split the source lookup from the credential lookup.

2. Marker JSDoc comment misleads: -1 flag vs. "any commit ever touched"

The JSDoc says "if any commit ever touched .nemar/metadata.json", but the implementation uses git log -1 --format=%H -- .nemar/metadata.json, which returns the most recent commit that touched the file. Semantically correct for presence detection, but the comment implies --all or no -1. Suggest changing to: "Returns the most recent commit hash that touched the file; non-empty means the file exists in history (import completed)."


Important

3. No escape hatch for automation or power users

process.exit(1) with no override means CI scripts and admins cannot bypass this check. If the marker is absent for a legitimate edge case (restored dataset, admin-created source="openneuro" record created outside the importer), the user is permanently blocked with no recourse. A --skip-port-check flag or NEMAR_SKIP_PORT_CHECK=1 env var would give an escape hatch without changing the safe default.

4. Permanent false-positive if source="openneuro" was set without running import-openneuro.ts

The marker is coupled to a single importer's commit convention. Any future mechanism that creates a dataset with source="openneuro" in D1 without committing .nemar/metadata.json (restored dataset, batch importer, admin manual creation) will produce a permanent "Porting still in progress" block for all users. This is a forward-compatibility hazard worth documenting at minimum, and worth fixing with item 3 above.

5. Confusing retry hint in download: re-running download will fail

When the marker is absent in download, the command exits but leaves a metadata-only clone on disk. The first hint says "Retry the download in ~5 minutes" — if the user re-runs nemar dataset download <id>, it will fail because the directory already exists. The second hint ("run cd ${absoluteOutput} && nemar dataset get") is the correct recovery path. Drop the first hint or replace with: "Re-run is not needed — the metadata clone is already at the path above. Once porting completes, run nemar dataset get from that directory to pull data files."

6. "~5 minutes" retry hint is inaccurate for large datasets

The importer can take 25+ minutes (5-minute polling intervals × 5 publication attempts). Users who retry at 5 minutes and find it still incomplete may conclude the dataset is broken. Change to "Retry in a few minutes" or link to nemar dataset status.


Suggestions

7. unknown return value silently passes through at both call sites without comment

When detectImportMarker returns "unknown" (git unavailable, non-git directory), execution proceeds without any marker check. This is intentional but undocumented at the call sites. Suggest: // unknown: git unavailable or non-git dir; skip port check and let git-annex handle it.

8. Missing test: marker committed then removed via git rm

The four tests cover absent/present/working-tree-only/non-git-dir. Missing: marker committed, then deleted with git rm + follow-up commit. git log -1 -- .nemar/metadata.json correctly returns the last touching commit even through deletion. A test would document this and guard against implementation changes.


Nice-to-haves

9. Verbose logging when marker result is unknown

If isVerbose(), emit vlog("detectImportMarker: git unavailable, skipping port check") to help operators debug CI issues without polluting normal output.


False Positives / Intentional Decisions

  • Non-zero exit with no --force: Intentional per PR scope; defensible for user-facing CLI. Item 3 above addresses automation pain if it arises.
  • Client-side vs. backend status='importing' field: Acknowledged in PR description; acceptable MVP scope.
  • Race condition: Low risk. Step 7 of the importer pushes main + git-annex atomically; if S3 copy succeeded (step 5 exits on failure), a post-push clone has both the marker and registered S3 keys. The window is effectively zero in practice.
  • source resolved from backend API, not local metadata.json: Correct — more reliable than local state which could be stale or absent.

Summary: 2 critical, 4 important, 2 suggestions, 1 nice-to-have. The most actionable immediate fixes are items 1 (API-fail false-negative in get) and 5 (misleading retry hint in download). Items 3 and 4 prevent a future maintenance trap.

- fix: API-fail false-negative in get: fall back to reading local
  .nemar/metadata.json when backend is unreachable so port check
  fires even offline
- fix: update detectImportMarker JSDoc to clarify -1 semantics
  (most recent commit, not any-commit) and add forward-compat note
- feat: add --skip-port-check to both download and get commands so
  admins and automation can bypass the check
- fix: replace misleading retry hint in download; clone already
  exists, instruct user to wait then run get from that dir
- fix: replace "~5 minutes" with "5-30 minutes depending on size"
  in both commands
- docs: add unknown-case comment at both call sites
- test: add git-rm deletion case for detectImportMarker
@neuromechanist

Copy link
Copy Markdown
Contributor Author

Review findings addressed (commit b15eef0)

Critical

#1 API-fail false-negative in `get`: When `getDataset()` throws (unreachable backend), `apiReachable` is now tracked separately. If the API failed and `dsInfo?.source` did not resolve, the code reads `.nemar/metadata.json` from local disk and checks `source` from there. The port check fires even offline; only a fully malformed local metadata file silently skips it. The bare `catch {}` comment is updated accordingly.

#2 JSDoc misleads on `-1` vs "any commit ever touched": The inner comment now reads "returns the most recent commit that touched `.nemar/metadata.json`". The Returns block clarifies "non-empty `git log -1` output". A forward-compatibility note is added warning about future `source="openneuro"` setters that bypass the importer's commit convention (with a TODO referencing #460).

Important

#1 No escape hatch: `--skip-port-check` added to both `download` and `get`. Shown in the error output so users know it exists.

#3 Misleading retry hint in `download`: "Retry the download in ~5 minutes" replaced with: "The metadata-only clone is already at the path above. Wait 5–30 minutes…, then run: `cd && nemar dataset get`."

#4 "~5 minutes" too optimistic: Changed to "5–30 minutes (depending on dataset size)" in both `download` and `get`.

Suggestions addressed

#7 `unknown` falls through silently: Added inline comment "unknown = git unavailable or non-git dir; skip port check and let git-annex handle it" at both call sites.

#8 Missing test for git-rm deletion case: Added test "marker committed then deleted via git rm still returns 'present'" — verifies `git log -1` returns the deletion commit hash rather than empty output.

Not addressed

All 15 tests pass. Build clean.

@github-actions

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR470

Version: 0.8.14-PR470.b15eef0
Commit: b15eef0


🤖 Updated on each push.

@neuromechanist
neuromechanist merged commit 85bd191 into dev May 14, 2026
2 checks passed
@neuromechanist
neuromechanist deleted the feature/issue-460-port-pull-warning branch May 14, 2026 05:16

This branch was previously deployed

1 inactive deployment
npm — aa564f64 Deployed May 14, 2026 by neuromechanist via publish #837
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