Skip to content

fix: localize declared path inputs on the instance (#37) - #38

Merged
scttfrdmn merged 3 commits into
mainfrom
fix/37-stage-declared-inputs
Jun 13, 2026
Merged

scttfrdmn merged 3 commits into
mainfrom
fix/37-stage-declared-inputs

Conversation

@scttfrdmn

Copy link
Copy Markdown
Collaborator

The spawn executor's staging script only did aws s3 sync <the task's own work dir> then ran .command.sh. But a task's declared path inputs normally live outside its own work dir — produced by an upstream process, or from a samplesheet / Channel.fromPath (often s3://). They were never placed on the instance, so stock nf-core modules ran with missing inputs (the FASTQC-can't-find-its-reads symptom in the issue).

Change

buildStagingScript now takes the task's resolved input map (task.getInputFilesMap()) and, before the task runs, copies each declared input from its real source URI to ${LOCAL_DIR}/<stageName> — the name .command.sh symlinks against:

  • s3:// sources → aws s3 cp (--recursive for directory inputs)
  • stage names with subdirs → mkdir -p first
  • non-s3:// sources → left to the existing work-dir sync (unchanged)

Preserves the existing Docker (#30), .exitcode, and spored complete (#24) machinery. New Spock tests assert the emitted stage-in commands; 30 tests green.

Approach note

This is the targeted form of the issue's option 1/2: it localizes every declared input by source URI (covering cross-task + samplesheet s3://), spliced into nf-spawn's existing remote staging script. I went this way rather than generating a full Nextflow .command.run because nf-amazon's S3 copy strategy isn't a build dep here and .command.run would also swallow nf-spawn's own Docker/exitcode/complete handling — this keeps those intact while fixing the staging gap.

Validation ask

Unit-tested, but I can't run a full multi-process pipeline locally. @filer — could you run this build against the taxprofiler demo (aws-microbiome-demo) that surfaced this? Specifically whether FASTQC now finds its staged reads. Happy to iterate on what the generated stage-in looks like for your inputs.

Closes #37 (pending that validation).

The staging script only synced the task's OWN S3 work dir, then ran .command.sh.
But a task's declared `path` inputs usually live elsewhere — produced by an
upstream process, or from a samplesheet / channel (s3://) — so they were never
placed on the instance, and stock nf-core modules ran with missing inputs.

buildStagingScript now takes the task's resolved input map
(task.getInputFilesMap()) and, before running the task, copies each declared
input from its real source URI to ${LOCAL_DIR}/<stageName> so the symlinks
.command.sh creates resolve:
- s3:// sources -> aws s3 cp (--recursive for directory inputs)
- stage names with subdirs are mkdir -p'd first
- non-s3 sources are left to the work-dir sync (unchanged)

Preserves the existing Docker (#30), .exitcode, and `spored complete` (#24)
behavior. Adds Spock coverage for the emitted stage-in commands. 30 tests green.
Bring nf-spawn under the spore.host-wide SemVer + Keep-a-Changelog policy. The
release ritual notes nf-spawn's specifics (bump build.gradle version to match
the tag — the workflow verifies it). CHANGELOG seeds Unreleased with the #37
input-localization fix from this PR.
@scttfrdmn

Copy link
Copy Markdown
Collaborator Author

Filer of #37 here (the aws-microbiome-demo taxprofiler pipeline that surfaced this). Code-review pass — I can't run a full end-to-end validation yet (see the blocker at the bottom), but the approach looks right and directly targets the failure I reported.

The fix maps onto the exact failure

My #37 case: the demo's samplesheet sets fastq_1 = s3://…/fetch/<hash>/SRR059374_stool_1.fastq.gz, taxprofiler does file(row.fastq_1), and FASTQC (input: path reads) then symlinks the staged basename:

ln -s SRR059374_stool_1.fastq.gz SRR059374_stool_..._raw_1.gz   # dangling → "didn't exist"

buildInputStaging() copying each declared input to ${LOCAL_DIR}/<stageName> before .command.sh runs should make that symlink target exist — the input map entry SRR059374_stool_1.fastq.gz → s3://…/SRR059374_stool_1.fastq.gz lands at exactly the basename the symlink references. So this addresses the root cause as I diagnosed it. Routing through task.getInputFilesMap() rather than a full .command.run (keeping the Docker/.exitcode/spored complete machinery intact) seems like the right tradeoff.

Two things only a live run will confirm (the unit tests stub toUri(), so they prove the emitter, not these)

  1. Stage-name ↔ .command.sh reference match for aliased modules. taxprofiler imports modules under aliases (FASTP_SINGLE/FASTP_PAIRED, FASTQC/FASTQC_PROCESSED, *COMBINEKREPORTS*). The fix keys copies on getInputFilesMap()'s stage names; the symlink targets in .command.sh come from Nextflow's input resolution. They should be the same names, but that identity is the whole ballgame and isn't exercised by the stubbed tests.

  2. The .extension == "gz" rename. nf-core FASTQC renames inputs to ${prefix}.${reads.extension}, and for *.fastq.gz Nextflow's .extension is just gz → the symlink becomes ..._raw_1.gz (no .fastq). Once the input is actually staged, does FastQC accept the bare .gz name? Probably (it sniffs gzip), but my earlier run never got far enough to find out — worth watching in validation.

One small thing in the diff

The directory-vs-file branch keys --recursive on the source URI ending in /:

final recursive = uri.endsWith('/') ? ' --recursive' : ''

For inputs that arrive as an s3:// prefix without a trailing slash (a staged directory whose toUri() doesn't append /), this would emit a single-object cp of a prefix and miss the contents. Might be worth keying on Files.isDirectory(source) instead of the trailing-slash heuristic, if that's cheap on the resolved Path. Non-blocking for my file-input case.

Validation status (the blocker)

I'm set up to run the real end-to-end check — the demo's arm64 leg is also my rehearsal, so it's one run that validates both — but the head node installs nf-spawn from a published release ZIP (releases/download/v<ver>/nf-spawn-<ver>.zip), and there's no artifact for this branch yet (latest release is still v0.2.8). If you cut a pre-release tag from fix/37-stage-declared-inputs (or publish a CI build artifact), I'll point the demo at it, run the pipeline, and report back specifically whether FASTQC finds its staged reads + how the two caveats above shake out.

@scttfrdmn

Copy link
Copy Markdown
Collaborator Author

@scttfrdmn — this is ready for a real-pipeline check against the taxprofiler demo (aws-microbiome-demo) that surfaced #37. Unit tests cover the generated stage-in, but I can't reproduce a full multi-process pipeline locally, so a run on your env is the real validation.

Try it from this branch

git fetch origin fix/37-stage-declared-inputs && git checkout fix/37-stage-declared-inputs
./gradlew installPlugin    # builds + installs nf-spawn-0.2.8 into ~/.nextflow/plugins/
# pin the local build in your pipeline's nextflow.config:
#   plugins { id '[email protected]' }
#   process.executor = 'spawn'
nextflow run <taxprofiler> -profile <...> -work-dir s3://<your-bucket>/work

What to look for

  • FASTQC finds its reads — the failing case in the issue. With the fix, the task's .command.run… actually, note this fix does NOT switch to .command.run; it adds per-input aws s3 cp into nf-spawn's existing staging script. So on the FASTQC instance you should now see its declared path inputs land in /var/lib/nf-work/<stageName> before .command.sh runs, and the ln -s no longer points at a missing file.
  • The generated staging script for a multi-input task — grab it from the launch (it's the --user-data-file temp script, or add -process.debug) and confirm there's an aws s3 cp 's3://…' '${LOCAL_DIR}/<stageName>' line per declared input, including the upstream-produced and samplesheet s3:// ones.
  • Directory inputs (e.g. a reference DB passed as path) come down via --recursive.

Two things I'd especially want your eyes on

  1. Stage-name vs. source basename. The fix copies each input to the stage name Nextflow assigned (the map key from task.getInputFilesMap()), which is what .command.sh references — so the rename/symlink case in the issue (SRR…_raw_1.gz) should resolve. Confirm that holds for taxprofiler's renamed inputs.
  2. Anything still missing. If a process declares inputs that aren't in getInputFilesMap() (e.g. staged via a different mechanism), they won't be copied — flag any process that still runs with a missing input and I'll dig in.

If it works end-to-end I'll merge; if a class of input still doesn't stage, paste the failing task's staging script + the getInputFilesMap it had and I'll iterate. Thanks!

@scttfrdmn

Copy link
Copy Markdown
Collaborator Author

Thanks — ./gradlew installPlugin is the right move for a local laptop run, but the demo's head node doesn't load the plugin from ~/.nextflow/plugins, so a couple of mechanics matter before I can validate cleanly:

How the demo installs nf-spawn (worker_script.py):

TARGET_NF_SPAWN_VERSION="0.2.8"
NF_SPAWN_PLUGIN_DIR="/opt/nextflow_cache/plugins/nf-spawn-${TARGET_NF_SPAWN_VERSION}"
if [ ! -d "${NF_SPAWN_PLUGIN_DIR}/classes" ]; then
    curl -fsSL ".../releases/download/v${VER}/nf-spawn-${VER}.zip" ...
fi

It pulls a release ZIP into /opt/nextflow_cache/plugins/ (the head runs NXF_HOME=/opt/nextflow_cache), and the AMI already has 0.2.8 baked there.

The trap: the PR leaves build.gradle at 0.2.8 (CHANGELOG entry is under [Unreleased]), so installPlugin produces nf-spawn-0.2.8 — the same version string as the baked one. Two problems for the demo path:

  1. The if [ ! -d .../nf-spawn-0.2.8/classes ] guard sees the baked dir and skips install entirely — the fix never lands.
  2. Even if force-installed, id '[email protected]' is now ambiguous: no way to tell from the version whether the box is running the fix or the old code.

Cleanest path to a real validation: bump build.gradle to 0.2.9 (or 0.2.9-rc1) on this branch and publish the ZIP (tag or CI artifact). Then it's a one-line change on my side — TARGET_NF_SPAWN_VERSION=0.2.9 in worker_script.py + build_ami.py — the head pulls it unambiguously, and @0.2.9 in the config proves which code ran. Per your CHANGELOG policy that's the [Unreleased] → [0.2.9] bump anyway, and pre-1.0 a backward-compatible fix bumping MINOR is correct here.

Once that ZIP exists I'll point the demo at it and run the arm64 leg (which doubles as my rehearsal + the benchmark's arm64 leg), then report back specifically: does FASTQC find its staged reads, do the aliased-module stage names line up, and does the .gz rename trip FastQC. If you'd rather not bump yet, I can instead hack the demo to force-install a branch build at a throwaway version — but the version bump is cleaner and you need it for release regardless.

…0.2.9

Address PR #38 review: keying --recursive on a trailing slash misses an s3://
directory input whose URI has no trailing slash. Detect via Files.isDirectory
(trailing slash kept as an unambiguous fast-path + stat-failure fallback).

Bump to 0.2.9 + promote CHANGELOG so the demo head node can pull a distinct
release ZIP (the baked 0.2.8 install guard would otherwise skip the fix, and
@0.2.8 couldn't prove which code ran). Per SemVer (pre-1.0, backward-compatible)
this is the right MINOR-equivalent bump; the release workflow verifies the tag
matches build.gradle's version.
@scttfrdmn
scttfrdmn merged commit 2c9e621 into main Jun 13, 2026
1 check passed
@scttfrdmn
scttfrdmn deleted the fix/37-stage-declared-inputs branch June 13, 2026 19:51
@scttfrdmn

Copy link
Copy Markdown
Collaborator Author

Done — both your points are in, and v0.2.9 is published with the ZIP the demo needs.

Release: https://github.com/spore-host/nf-spawn/releases/tag/v0.2.9 → nf-spawn-0.2.9.zip (the releases/download/v0.2.9/nf-spawn-0.2.9.zip URL your worker_script.py pulls). #38 merged to main; build.gradle is 0.2.9 so the release workflow's tag==version check passed.

Your one-line change should now be unambiguous:

TARGET_NF_SPAWN_VERSION = "0.2.9"   # worker_script.py + build_ami.py

The if [ ! -d .../nf-spawn-0.2.9/classes ] guard won't find a baked 0.2.9, so it installs fresh, and id '[email protected]' in the config proves the fix is what ran.

Your review point (directory detection): fixed. --recursive no longer keys on a trailing slash alone — it's uri.endsWith('/') || Files.isDirectory(source) (slash kept as an unambiguous fast-path + a fallback when the path can't be stat'd). So an s3:// directory input without a trailing slash now copies recursively. 30 tests green.

On the two things only a live run confirms — those are exactly what I'm hoping your run answers, and I deliberately didn't try to fake them in unit tests (the stubs prove the emitter, not the identity):

  1. stage-name ↔ .command.sh symlink-target identity for aliased modules (FASTP_SINGLE/FASTQC_PROCESSED/etc.) — this is the whole ballgame, as you said.
  2. the .gz rename — whether FastQC accepts the bare ..._raw_1.gz once the file is actually present.

If FASTQC finds its reads and the aliased stage names line up, I'll close #37. If a class of input still doesn't stage (e.g. something not in getInputFilesMap()), paste that task's generated staging script (the --user-data-file temp script) + its input map and I'll iterate into a 0.2.10. Thanks for the thorough review — the isDirectory catch was a real one.

@scttfrdmn

Copy link
Copy Markdown
Collaborator Author

Validated against the taxprofiler demo with nf-spawn 0.2.9 (3 small accessions, native arm64/Graviton). Two clear wins and one new blocker:

✅ #38's input staging works. FASTQC's failure moved from the original "Skipping '…raw_1.gz' which didn't exist" (missing input) to a write-permission error on the symlink it creates next to the now-present input. The aws s3 cp per-input localization put the file on the instance — exactly what this PR set out to do. So I'm comfortable considering #37 resolved by this change.

✅ Native arm64 container ran. Status: Downloaded newer image for quay.io/aarchbio/fastqc:0.12.1--hdfd78af_0 — pulled and executed, no exec format error.

❌ Next blocker (filed separately as #39). The task now fails with:

ln: failed to create symbolic link 'SRR059377_…_raw_1.gz': Permission denied
.command.sh: line 12: versions.yml: Permission denied

Root cause (confirmed against the v0.2.9 SpawnTaskHandler): buildRunLine hardcodes the docker run argv and drops Nextflow's docker.runOptions, so the demo's --user root is ignored and the container runs as the image's default non-root user — but buildStagingScript sudo chowns /var/lib/nf-work to root, so the non-root container can't write the work dir. Details + suggested fix in #39.

On the two caveats I flagged earlier:

Happy to re-run the moment #39 lands — same one-line version bump on my end.

scttfrdmn added a commit that referenced this pull request Jun 13, 2026
…#42)

The declared-input staging from #37/#38 emitted two broken commands so the
inputs were never actually copied (silently, since the script runs
`set -uo pipefail`, not `-e`):

  1. nf-amazon's S3 Path renders `toUri().toString()` with an empty authority
     (`s3:///bucket/key`, three slashes), so the bucket landed in the path and
     `aws s3 cp` parsed an empty bucket. normalizeS3Uri() now collapses the
     leading `s3:///` to `s3://`.
  2. The destination single-quoted the literal `${LOCAL_DIR}`, so the shell
     passed it to `aws` unexpanded — the file would have landed in a dir named
     `${LOCAL_DIR}`. `${LOCAL_DIR}/` is now kept outside the single quotes (only
     the stage name is quoted), matching how WORKDIR_S3/AWS_REGION are handled.

Also guards each input copy with `|| exit 1` so a failed stage-in fails loud
instead of letting the task run with a missing input and fail later with a
confusing MissingFileException.
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.

Task instances don't stage Nextflow file inputs (only sync the task's own work dir) — breaks any process with a staged path input

1 participant