Skip to content

fix(sandbox): migrate to S3 special remote, add --verbose - #378

Merged
neuromechanist merged 2 commits into
devfrom
feature/issue-377-sandbox-errors-and-s3-remote
Apr 28, 2026
Merged

neuromechanist merged 2 commits into
devfrom
feature/issue-377-sandbox-errors-and-s3-remote

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Closes #377

Why

WSL user reported nemar sandbox aborting at Step 5/6 with:

URL registration failed for 1 file(s)
    Failed: sub-01/eeg/sub-01_task-rest_eeg.edf

…and no actionable detail. The error path swallows stderr from git annex add and git annex registerurl, so the user can't diagnose. This is the same fragile presigned-URL + registerurl flow that #182 migrated everywhere else; sandbox was the last consumer.

What

  1. Sandbox upload now uses the S3 special remote (same as dataset upload / dataset update):
    • requestUploadCredentials (STS, scoped to xx*/objects/)
    • configureS3Remote with protocol=https, publicurl, autoenable=true
    • gitAnnexAdd (respects annex.largefiles)
    • copyToAnnexRemote (git annex copy --to nemar-s3 -J4)
    • clearAnnexCredentials (so subsequent git annex get falls back to publicurl)
  2. --verbose / -v flag on nemar sandbox — prints every git/git-annex subprocess (cmd, cwd, stdout, stderr, exit code). Module-level setVerbose() in src/lib/verbose.ts so runCommand in git-annex.ts can pick it up.
  3. Deletes dead code that was only used by the old sandbox flow:
    • uploadFileWithPresignedUrl
    • uploadFilesWithPresignedUrls
    • registerUrlWithGitAnnex
    • registerUrlsWithGitAnnex
    • configureWebRemote
    • PresignedUploadProgress

Net diff: 3 files changed, 118 insertions(+), 364 deletions(-).

Verified

  • bun run build — clean
  • bunx tsc --noEmit — clean
  • bun test — all sandbox/git-annex tests pass; pre-existing unrelated failure in datalad-commands.test.ts:191 (live API check for nm999999) reproduces on dev without these changes
  • bunx biome check src/commands/sandbox.ts src/lib/git-annex.ts src/lib/verbose.ts — clean (one pre-existing noNonNullAssertion warning at line 120, untouched)
  • STS policy already prefix-agnostic — generateUploadPolicy in backend/src/services/sts.ts:96 emits unconditional s3:ListBucket for both xx* and nm*, so HeadBucket during initremote works
  • pushToGitHub already pushes the git-annex branch (src/lib/git-annex.ts:1329-1332), so clones see the S3 remote config

Test plan

  • nemar sandbox reset && nemar sandbox — completes Step 5/6 successfully
  • nemar sandbox reset && nemar sandbox --verbose — prints git/git-annex subprocess output during Step 5/6
  • After sandbox completes, git clone <xx-repo> + cd <repo> && git annex init && git annex get . from a clean dir downloads via publicurl without credentials
  • Trigger an artificial failure (e.g. revoke STS perms mid-run) and confirm --verbose surfaces the underlying git-annex stderr instead of just "Failed to copy to remote"
  • Test on WSL (the reporting user's environment) to confirm the original symptom is resolved

The sandbox command used a fragile presigned-URL upload + git-annex
registerurl flow. Errors from git annex add and registerurl were silently
swallowed, leaving WSL/HPC users stuck with no actionable diagnostic.

The same flow was migrated everywhere else in #182; sandbox was the last
holdout. Replace with the validated path: requestUploadCredentials +
configureS3Remote + gitAnnexAdd + copyToAnnexRemote + clearAnnexCredentials.

Also add a --verbose / -v flag that prints every git/git-annex subprocess
invocation, stdout, stderr, and exit code so the next stuck user has
something to report.

Removes now-unused helpers: uploadFileWithPresignedUrl,
uploadFilesWithPresignedUrls, registerUrlWithGitAnnex,
registerUrlsWithGitAnnex, configureWebRemote, PresignedUploadProgress.

Closes #377
@github-actions

github-actions Bot commented Apr 28, 2026 •

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR378

Version: 0.8.3-PR378.13b8d35
Commit: 13b8d35


🤖 Updated on each push.

- Drop the dataFileCount gate that decided whether to run the S3 setup
  based on the backend's upload_urls response. The new flow does not need
  upload_urls, so gating on it is a future-fragile coupling. Always run
  the S3 setup; copyToAnnexRemote is a no-op when there are no annexed
  files. Removes the now-unused uploadUrls local.
- Trim sandbox.ts comments that restated WHAT instead of explaining WHY.
  Keep the clearAnnexCredentials WHY comment, drop the rest.
- Trim verbose.ts docstrings.
- Add test/verbose.test.ts: state round-trip + vlog gating.

Findings #2 and #3 (orphan repo+S3 cleanup, copy-line regex) tracked
separately as #379.
@neuromechanist

Copy link
Copy Markdown
Contributor Author

/review-pr summary

Ran code-reviewer, silent-failure-hunter, comment-analyzer, and pr-test-analyzer in parallel.

Addressed in 13b8d35

  1. dataFileCount === 0 gate dropped (code-reviewer, important). The S3 setup was gated on Object.keys(uploadUrls).length, which couples the new flow to a backend response field the new flow no longer uses. If a future backend trim drops upload_urls from the sandbox response, the sandbox would silently skip S3 entirely. Now always run the S3 setup; copyToAnnexRemote is a no-op when nothing is annexed.
  2. Comments trimmed (comment-analyzer). Dropped redundant restating-WHAT comments; kept the clearAnnexCredentials WHY (security/behavior). Trimmed verbose.ts docstrings. Removed the "still" temporal framing that would rot.
  3. Unit test added for verbose.ts (pr-test-analyzer). Round-trip state + vlog gating, no mocks.

Tracked separately

  • Orphaned GitHub repo + S3 prefix on failed sandbox runs (silent-failure-hunter, HIGH). Filed as sandbox: orphaned GitHub repo + S3 prefix on failed run #379. Pre-existing condition; out of scope here. Every post-createDataset error path leaves a server-side orphan until the 14-day sweep. Proposed fix: a single failSandbox(datasetId, datasetPath) helper that calls DELETE /admin/datasets/:id (or sandbox-scoped equivalent).
  • filesCopied regex parsing brittleness (silent-failure-hunter, minor). Cosmetic, not a real silent failure.

Confirmations from the reviewers

  • Original swallowing-bug class (git annex add stderr discarded) cannot recur. runCommand verbose logging is purely a side-channel; returned stderr unchanged.
  • clearAnnexCredentials runs on every upload-failure path before the success check.
  • pushToGitHub already pushes the git-annex branch (clones see the S3 remote config).
  • STS upload policy is prefix-agnostic (xx* and nm* both get unconditional s3:ListBucket).
  • setVerbose as process-scoped global is fine for a single-shot CLI.

@neuromechanist
neuromechanist merged commit e701cb6 into dev Apr 28, 2026
13 of 15 checks passed
@neuromechanist
neuromechanist deleted the feature/issue-377-sandbox-errors-and-s3-remote branch May 11, 2026 05:15

This branch was previously deployed

1 inactive deployment
npm — 13b8d354 Deployed Apr 28, 2026 by neuromechanist via publish #664
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