Skip to content

feat: stage task results back to S3 work dir so tasks complete (#14) - #16

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/14-s3-output-staging
Jun 3, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/14-s3-output-staging

Conversation

@scttfrdmn

Copy link
Copy Markdown
Collaborator

Problem

Tasks dispatched to spawn instances ran but never returned results to Nextflow. nf-spawn had no copy-back logic — and declared outputs never appeared in task.workDir, so outputs never bound and downstream tasks hung in PENDING forever (the symptom in #12).

Fix

buildStagingScript() now emits instance user-data that:

  1. aws s3 syncs the S3 work dir (task.workDirStr) down to a local dir,
  2. runs the task script, capturing .command.out/.command.err and the real exit code into .exitcode,
  3. syncs outputs back up, then uploads .exitcode last so Nextflow never observes a completed exitcode before the outputs land.

Nextflow reads .exitcode + declared outputs from the work dir to finalize the task, so this is what lets a pipeline progress past its first process.

Design notes

Test

buildStagingScript/shellQuote are package-scope and pure. Spock specs assert stage-down → run → stage-up ordering, real-exitcode capture, .exitcode-uploaded-last, and shell quoting/escaping. ./gradlew test green (5 tests).

Sequencing

Builds on #13 (merged) — that made the script actually run; this makes the task complete. Depends on the instance role having S3 read/write on the work-dir bucket (already true for the demo).

Fixes #14

Tasks dispatched to spawn instances ran but never returned results to
Nextflow, so outputs never bound and downstream tasks hung in PENDING
forever. nf-spawn had no copy-back logic at all.

buildStagingScript() now emits user-data that:
  1. aws s3 sync's the S3 work dir (task.workDirStr) down to a local dir,
  2. runs the task script, capturing .command.out/.command.err and the
     REAL exit code into .exitcode,
  3. syncs outputs back up, then uploads .exitcode LAST so Nextflow never
     sees a completed exitcode before the outputs land.

Nextflow reads .exitcode + declared outputs from the work dir to finalize
the task, so this is what lets a pipeline progress past the first process.

Chose S3 sync over scp-before-terminate: the latter is lossy under
--on-complete terminate, while S3 sync is idempotent and object-atomic.

Did NOT adopt BashWrapperBuilder (as floated on the issue): with an S3
work dir its default SimpleFileCopyStrategy (nf-amazon's S3 strategy is
not on a generic executor's classpath) bakes unusable s3:// paths into
.command.run's stage/unstage and exit-file writes. The self-contained
sync wrapper sidesteps that and is directly testable.

buildStagingScript/shellQuote are package-scope and pure; Spock specs
assert stage-down→run→stage-up ordering, real-exitcode capture, and
.exitcode-uploaded-last.

Fixes #14
@scttfrdmn
scttfrdmn merged commit 91d941f into main Jun 3, 2026
1 check passed
@scttfrdmn
scttfrdmn deleted the feat/14-s3-output-staging branch June 3, 2026 04:57
@scttfrdmn scttfrdmn mentioned this pull request Jun 3, 2026
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.

No output staging back to task.workDir → tasks never bind outputs, downstream stays PENDING

1 participant