Skip to content

feat: add sandbox training requirement for uploads - #24

Merged
neuromechanist merged 33 commits into
devfrom
feature/sandbox-training
Jan 17, 2026
Merged

neuromechanist merged 33 commits into
devfrom
feature/sandbox-training

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Summary

Implements mandatory sandbox training before users can upload real datasets to NEMAR. This ensures users have verified their setup and are familiar with the upload workflow.

Changes

CLI Changes

  • New nemar sandbox command: Run sandbox training
  • New nemar sandbox status command: Check training completion
  • New nemar sandbox reset command: Reset status for re-training
  • Upload gating: Block nemar dataset upload until sandbox is completed
  • Login welcome message: Show sandbox status after login

Backend Changes

  • Add sandbox_completed, sandbox_completed_at, sandbox_dataset_id to users table
  • Add is_sandbox flag to datasets table
  • Add xx prefix to id_sequence for sandbox datasets (xx000XXX pattern)
  • New /sandbox/status, /sandbox/complete, /sandbox/reset endpoints
  • Update /auth/login and /users/me to include sandbox status
  • Gate /datasets creation on sandbox completion for non-sandbox uploads

Sandbox Training Flow

  1. User runs nemar sandbox
  2. CLI generates a placeholder BIDS dataset (~500KB with random EDF)
  3. Dataset uploaded to sandbox S3 path (s3://nemar/sandbox/xx000XXX/)
  4. On success, backend marks sandbox_completed=true
  5. User can now upload real datasets

Test plan

  • Run nemar sandbox to complete training
  • Verify nemar sandbox status shows completion
  • Verify nemar dataset upload is blocked without sandbox
  • Verify nemar dataset upload works after sandbox
  • Run nemar sandbox reset and verify status is cleared

Migration Required

Run backend/src/db/migrations/0004_sandbox.sql on the database before deploying.

Closes #16

- Add sandbox command (nemar sandbox, nemar sandbox status, nemar sandbox reset)
- Generate placeholder BIDS dataset with random EDF for training
- Gate real uploads on sandbox completion
- Show sandbox status on login welcome message
- Backend: Add sandbox fields to users table, sandbox routes, dataset sandbox flag
- Backend: Update auth/users/datasets endpoints for sandbox support

Addresses #16
@neuromechanist

Copy link
Copy Markdown
Contributor Author

PR Review Summary

Issues Found

Input Validation (High Priority)

  • POST /sandbox/complete endpoint lacks Zod validation for request body
  • Should validate dataset_id is a non-empty string before processing

Error Handling (Medium Priority)

  • Database query errors in sandbox routes could propagate unhandled
  • JSON parse errors in POST /sandbox/complete not explicitly caught
  • File generation in generateSandboxDataset could leave partial state on error

Local vs Server State (Low Priority)

  • CLI sandbox check uses local config only (isSandboxCompleted())
  • Consider verifying with server for authoritative state (already done in upload flow via API)

Strengths

  • Clean command structure with status and reset subcommands
  • Proper authentication middleware on all sandbox routes
  • Good validation of dataset ownership before marking complete
  • Comprehensive placeholder BIDS dataset generation

Recommended Fixes

  1. Add Zod validation to POST /sandbox/complete
  2. Add try-catch around database operations
  3. Add cleanup on partial failure in sandbox generation

Will address these before merging to main.

@neuromechanist

Copy link
Copy Markdown
Contributor Author

PR Review Summary (Automated)

Agents Used

  • Code Reviewer - General code quality and security
  • Silent Failure Hunter - Error handling audit
  • Test Analyzer - Test coverage gaps

Critical Issues (2 found)

Agent Issue Location
Code Reviewer Missing dataset_id format validation in /sandbox/complete backend/src/routes/sandbox.ts:19-21
Code Reviewer Sandbox datasets exposed in public listings backend/src/routes/datasets.ts:276-289

High Severity Issues (7 found)

Agent Issue Location
Silent Failure Empty catch blocks in cleanup src/lib/sandbox.ts:233-240
Silent Failure Empty catch swallows stat errors src/lib/sandbox.ts:259-262
Silent Failure Silent workflow deployment failure backend/src/routes/datasets.ts:486-495
Silent Failure Silent branch protection failure backend/src/routes/datasets.ts:497-503
Silent Failure Silent auto-merge enable failure backend/src/routes/datasets.ts:505-511
Silent Failure Upload continues after failures src/commands/sandbox.ts:214-224
Silent Failure URL registration continues after failures src/commands/sandbox.ts:241-248

Test Coverage Gaps (Priority order)

Priority Test Gap Criticality
1 POST /sandbox/complete validation (404, 403, 400 cases) 9/10
2 POST /datasets sandbox gating (server-side) 9/10
3 generateDatasetId sandbox prefix 8/10
4 nemar sandbox status command 7/10
5 nemar sandbox reset command 6/10

Positive Observations

  • Excellent Zod validation throughout backend routes
  • Consistent error handling with try-catch blocks
  • Good separation of concerns (sandbox logic isolated)
  • Proper authentication middleware usage
  • Idempotent operations (can be retried safely)

Recommendation: The feature is functional and all CI checks pass. The issues identified are improvements for future iterations, not blockers for merge. Consider addressing critical issues in a follow-up PR.

- Add regex validation for sandbox dataset_id format (xx000000)
- Filter sandbox datasets from public listings
- Replace empty catch blocks with proper error logging
- Return warnings instead of silent failures in finalize endpoint
- Abort sandbox training on upload/URL registration failures
- Update test configs to include sandboxCompleted flag
@neuromechanist

Copy link
Copy Markdown
Contributor Author

Review Issues Addressed ✓

The following issues from the automated review have been fixed in commit 917ad36:

Critical Issues (2/2 fixed)

  • Added regex validation for sandbox dataset_id format (/^xx\d{6}$/)
  • Filter sandbox datasets from public listings (is_sandbox = 0 filter)

High Severity Issues (7/7 fixed)

  • Empty catch blocks in cleanup function - now logs warnings
  • Empty catch in getSandboxDatasetSize - only ignores ENOENT, warns on other errors
  • Silent workflow deployment failure - returns warnings in response
  • Silent branch protection failure - returns warnings in response
  • Silent auto-merge enable failure - returns warnings in response
  • Upload continues after failures - now aborts sandbox training
  • URL registration continues after failures - now aborts sandbox training

Additional Fixes

  • Audit log wrapped in try-catch so it doesn't fail the main operation
  • Test configs updated to include sandboxCompleted: true where needed

All tests pass. Ready for merge.

- Use SHA instead of run number for feature branch versions
- Only publish feature branches that have an associated PR
- Tag format: feature-{pr-number}, version: {base}-feature.{pr}.{sha}
- Skip npm publish for feature branches without PRs
@github-actions

github-actions Bot commented Jan 17, 2026 •

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR24

Version: 0.2.8-PR24.8cea225
Commit: 8cea225


🤖 Updated on each push.

@nemarOrg nemarOrg deleted a comment from github-actions Bot Jan 17, 2026

This branch was previously deployed

1 inactive deployment
npm — 8cea2252 Deployed Jan 17, 2026 by neuromechanist
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.

feat: sandbox environment for testing dataset uploads

1 participant