Skip to content

Key pipeline outputs by pattern directory and instance index; reject collisions (#944) - #980

Merged
scttfrdmn merged 2 commits into
mainfrom
fix/944
Oct 17, 2026
Merged

scttfrdmn merged 2 commits into
mainfrom
fix/944

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #944

Stacked on #972 (fix/943). This PR's base is fix/943. Merge in order: #931, #942, #957, #972, then this.

Cost safety. Found by reading pkg/pipeline/data_handoff.go, then tested locally against the in-process Substrate emulator, and with the real spored built from this tree. No AWS resources were created, nothing was launched and nothing was deployed.

What was wrong

  • UploadStageOutputs kept an absolute data_output path whole. So preprocess's /data/processed/a.csv in examples/pipelines/ml-training.json arrived in train as /data/input/data/processed/a.csv. A relative pattern was keyed by basename only, which collapsed any subdirectories.
  • With instance_count > 1, every instance uploaded to the same output/ prefix. train's four best.h5 overwrote each other, and the last upload won.
  • Found next to these, and fixed in this PR because they are the same kind of silent overwrite or loss:
    • Two source_stages that both output x.csv overwrote each other in dest_path.
    • fanout-fanin.json's data_input.pattern values were absolute (/data/chunks/chunk-1-*). They are matched against key-relative paths, so they could never match, and those stages received nothing.
    • An invalid pattern was logged and then ignored, which downloaded every file.
    • TestS3KeyGeneration re-implemented the old rule in its own body without calling the code, and asserted the bug.

What changed

  • Key relative to the pattern's directory. OutputRelPath keys a file by its path relative to the pattern's directory part: everything before the first segment containing *, ? or [, or the file's directory for a literal path. So /data/processed/* → a.csv, /data/*/part.csv → 2026/part.csv, /logs/training.log → training.log. Absolute and relative patterns behave alike.
  • Per-instance namespace. A stage with instance_count > 1 uploads under output/<instance-index>/ (StageInstanceOutputPrefix). Its files arrive downstream as <dest_path>/<index>/<file>. Both sides decide this from the definition's instance_count, which the runner now hands to the data handler.
  • Collisions are rejected, not overwritten. This covers two files of one upload with one key, and two sources delivering one local path. A key that would land outside dest_path (../) is refused.
  • data_input.pattern. It is matched against the same relative path. For a multi-instance source it is matched within each instance's directory, so *.h5 picks every instance's model. Validate rejects an absolute pattern, and rejects bad pattern syntax at validate time.
  • Docs. examples/pipelines/README.md documents the mapping and the S3 layout. There was no pipeline documentation at all. The examples follow it: fanout-fanin.json gets relative patterns and distinct fan-in names, and ml-training.json's evaluate reads /models/0/best.h5.

Tests (each watched failing against a revert that compiles)

revert fails
an absolute pattern keeps the whole path TestS3KeyGeneration, TestMLTrainingExampleDataLandsWhereTheExampleReadsIt, TestFanoutExamplePatternsSelectTheirChunks
no per-instance namespace TestS3KeyGeneration, TestMLTrainingExampleDataLandsWhereTheExampleReadsIt
no upload collision check TestUploadRefusesTwoFilesWithOneKey
no download collision check TestDownloadRefusesTwoSourcesWritingOnePath
no filepath.IsLocal check TestDownloadRefusesAKeyOutsideDestPath
absolute patterns validate TestValidateRejectsAnAbsoluteInputPattern
pattern not matched within the instance directory TestMLTrainingExampleDataLandsWhereTheExampleReadsIt
runner does not pass the definition to the handler TestStageRunnerEndToEnd_OutputsAreKeyedByInstanceAndPatternDir (the real spored, instance 1 of 2)

The two example tests load the real example files. They re-root the examples' absolute paths into a temp dir and run the real upload and download against the emulator, so they assert what the README says, not what the code happens to do.

  • make check: all pass except the known Docker-only TestGenerateWrapper_ChownFixesCrossUIDStickyUnlink_Docker.
  • make check-nested: clean.
  • go test -count=1 ./lambda/pipeline-orchestrator/ ./pkg/pipeline/: pass. Use -count=1 because the e2e tests build spored, and the test cache does not see spored's sources.

Deploy

Stage instances download spored at boot, so this takes effect when spored is released, through the normal release that publishes to spawn-binaries-*. The orchestrator Lambda is unaffected by this PR.

Caveats

  • This is a layout change for existing definitions. A downstream command that read <dest_path>/data/processed/a.csv, the old accidental path, now finds <dest_path>/a.csv. A consumer of a multi-instance stage now gets <index>/ directories. Both are what the examples always implied, and the CHANGELOG says so.
  • A pipeline whose stages boot on either side of the spored release could mix layouts. Stages download the latest spored at boot, so this needs a release in the middle of a pipeline.

…collisions (#944)

UploadStageOutputs kept an absolute data_output path whole, so
"/data/processed/a.csv" arrived downstream as
"<dest_path>/data/processed/a.csv", while a relative pattern was keyed
by basename only. With instance_count > 1 every instance uploaded to
the same output/ prefix and same-named outputs overwrote each other.

OutputRelPath keys every file by its path relative to the pattern's
directory part (globRoot), absolute and relative alike. Instances of a
multi-instance stage upload under StageInstanceOutputPrefix
(output/<instance-index>/), decided from the definition's
instance_count, which the runner now hands the data handler. Two files
of one upload mapping to one key, or two source stages delivering one
local path, fail instead of overwriting; a key that would leave
dest_path is refused. data_input.pattern is matched against the same
relative path (within the instance directory for a multi-instance
source); Validate rejects an absolute pattern, which could never match.

examples/pipelines/README.md documents the layout; fanout-fanin.json
(absolute patterns, colliding fan-in names) and ml-training.json
(evaluate reads /models/0/best.h5) follow it. TestS3KeyGeneration
re-implemented the old rule in its body and asserted the bug; it now
calls the code with the README's table. The examples are run through
the real upload/download on the emulator, and the real spored is shown
to upload instance 1 of 2 under output/1/. Each guard was watched
failing against a compiling revert. (#944)
@codecov

codecov Bot commented Oct 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.56716% with 9 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/pipeline/data_handoff.go 89.28% 4 Missing and 2 partials ⚠️
pkg/pipeline/pipeline.go 66.66% 1 Missing and 1 partial ⚠️
pkg/pipeline/stage_runner.go 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 86b155b into main Oct 17, 2026
8 checks passed
@scttfrdmn
scttfrdmn deleted the fix/944 branch October 17, 2026 05:08
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.

pipeline data handoff: absolute data_output paths arrive nested under dest_path, and multi-instance stages overwrite each other's outputs

1 participant