Repository navigation
Merged
Conversation
This was referenced Oct 15, 2026
Merged
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
…tput work (#910, #911) A pipeline stage's data_input and data_output were validated and then ignored: the stage user data had TODOs where the S3 download and upload belonged, so stages started with no inputs and lost their outputs, and the pipeline could still report COMPLETED. The code that implements the handoff, `spored run-pipeline-stage` (pkg/pipeline's stage runner, data handoff and peer discovery), had no caller. The stage user data now runs `spored run-pipeline-stage` under the stage timeout, inside #912's EXIT trap, so termination, TTL tags and FAILED handling are unchanged. What the runner needed and lacked: - Tags: the orchestrator now writes spawn:s3-bucket, spawn:s3-prefix and spawn:s3-config-key; without the last the runner refused to start. - The definition: launchStage writes it to <prefix>/config/<id>.json in the pipeline's own bucket (pipeline.StageConfigKey), on every stage launch, so in-flight pipelines get it too. - S3 access: the shared spored profile grants nothing on pipeline data, so stages could not read inputs or write outputs or even their markers. `spawn pipeline launch` now creates (or reuses, by policy hash) a profile scoped to s3_bucket/s3_prefix (StageDataPolicy) and records it in the state; the orchestrator launches with it, falling back to the default for old records. The template lets the Lambda pass spawn-instance-* roles to EC2. - One marker scheme: StageKeyPrefix/StageMarkerKey/StageOutputPrefix in pkg/pipeline are used by the runner, the orchestrator's reader and the user data's fallback FAILED marker (rendered in Go). The runner now writes FAILED itself on any error, and COMPLETE only after outputs. - Region: the runner hands its IMDS-region config to the data handler, definition download and peer discovery, and its S3 clients use the bucket's own region (GetBucketRegion), so a stage in another region reaches the pipeline bucket. The user data also exports AWS_REGION. - The command runs in the user data's work dir, not a fixed /root. Tests: the rendered user data runs under bash with faked curl/aws/ shutdown and the REAL spored built from cmd/spored, against the in-process Substrate emulator and a fake IMDS. The stage instance is launched in the emulator from the orchestrator's own RunInstances input, so its tags are the orchestrator's. It shows the upstream output downloaded, the command's output uploaded under the stage's output prefix, COMPLETE seen by the orchestrator's markerExists, and, for a failing command, FAILED written by spored and nothing uploaded. Unit tests cover launchStage's tags, config write ordering and profile, the policy's coverage and scope, bucket-region resolution and the CLI's role config. Each was watched failing against a compiling revert.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #910
Fixes #911
Stacked on #931 (fix/912). Review and merge that first; this PR's base is
fix/912.Cost safety. Found and tested by reading the code and running it locally against the in-process Substrate emulator. No AWS resources were created, no instances launched, and nothing was deployed.
What was wrong
data_inputanddata_outputwere validated and then ignored. The stage user data had# TODOwhere the S3 download and upload belonged. Stages started with an empty input directory, their outputs were lost when the instance terminated, and the pipeline could still reportCOMPLETED(pipeline: data_input / data_output are validated but silently ignored; stages get no inputs and their outputs are lost #911).spored run-pipeline-stageimplements the handoff and peer discovery, but nothing ran it (spored run-pipeline-stage (and pkg/pipeline's stage runner) is unreachable: remove it or wire it into the orchestrator #910). It also could not have worked if invoked:loadStageInfoFromTagsrequiresspawn:s3-config-keyand readss3-bucket/s3-prefix. The orchestrator wrote none of them.spored-instance-profile, whose policy (sporedDCVRolePolicy) grants S3 only onspawn-binaries-*,spawn-schedules-*,spawn-certs-*anddcv-license.*. So a stage could read neither its inputs nor the definition. Reading the code, I don't think it could write itsCOMPLETEmarker either, even under Terminate failed pipeline stages and make them reapable (#912) #931's inline script. Unless something outside this repo attached a grant to that role, no stage could ever have completed. I have not checked the live role.LoadDefaultConfig. That has no region on an instance (pkg/pipeline: AWS clients built without a region fail on instances (same class as #899) #906/Give the pipeline stage runner's AWS clients the instance's region (#906) #915)./root.What changed
User data. It now installs spored (unchanged) and runs
timeout -k 60 <stage timeout> spored run-pipeline-stagein/opt/spawn/pipeline/<id>/<stage>. All of #931's guarantees stay as they were: the EXIT trap installed first, FAILED unless complete, API terminate with the IMDSv2 id plus halt, and TTL tags. The command andenvno longer appear in the user data at all. The runner reads them from the definition and runs the command with exec.One marker scheme.
pkg/pipelinenow hasStageKeyPrefix,StageMarkerKey,StageOutputPrefixandStageConfigKey. Three things use them:COMPLETEonly after the outputs are uploaded, and now also writesFAILEDitself on any error;markerExists;FAILEDmarker, which is rendered in Go rather than rebuilt in bash.The keys are unchanged (
<prefix>/stages/<id>/COMPLETE|FAILED).Orchestrator.
spawn:s3-bucket,spawn:s3-prefixandspawn:s3-config-key.launchStagewrites the definition tos3://<s3_bucket>/<s3_prefix>/config/<pipeline>.jsonbefore launching. It does this on every stage launch, so pipelines already in flight also get it.IAM.
spawn pipeline launchcreates the stages' profile, or reuses it (it is named by policy hash), using the caller's credentials asspawn task rundoes. The profile hasCreateOrGetInstanceProfile's spored baseline and SSM, pluspipeline.StageDataPolicy:s3:GetObject/PutObjecton<bucket>/<prefix>/*ands3:ListBucketon the bucket, conditioned ons3:prefix=<prefix>/*. Nothing outside the prefix is granted.PipelineState.InstanceProfile. Records without it fall back to the default.template.yamllets the Lambdaiam:PassRolespawn-instance-*toec2.amazonaws.com. The Lambda still creates no IAM.Region.
manager.GetBucketRegion, an unsigned HeadBucket). A stage in another region therefore still reaches the pipeline bucket.AWS_REGION.Dependency on #915
#915 (fix/906) gives pkg/pipeline's AWS clients the IMDS region. This PR does not need it to work: every client on the runner's path now gets the region-bearing config, and the user data exports
AWS_REGION. I did not cherry-pick it. The two PRs touch the sameLoadDefaultConfiglines instage_runner.go, so whichever merges second has a small, mechanical conflict. This PR adds no newLoadDefaultConfigcall in pkg/pipeline, so #915's AST gate stays satisfied. Merge #915 too:IsPipelineInstanceand the unusedNewStageDataHandler/DownloadResultsToLocalstill use a bare config.Tests
lambda/pipeline-orchestrator/stage_runner_e2e_test.go). The test builds the realsporedfromcmd/spored. The emulator instance is launched with the orchestrator's ownbuildStageRunInstancesInput, so it carries exactly the orchestrator's tags. The test then runs the rendered user data under bash, with faked curl/aws/shutdown and fake IMDS, against Substrate:dest_path; the command's output (input upper-cased, then the stageenvvalue) is in S3 under the stage's output prefix; the orchestrator'smarkerExistsseesCOMPLETEand noFAILED; the instance self-terminates.FAILED, with the exit status in the body, and the orchestrator sees it. NoCOMPLETEis written, nothing is uploaded, and the instance self-terminates.TestLaunchStageGivesTheRunnerItsTagsConfigAndProfile). The config is written before any launch, at exactly the key every instance'ss3-config-keynames. It is the definition, it lives inside the granted prefix, the bucket and prefix tags are set, and the profile is the pipeline's. Also: the fallback profile, and the user data's fallback marker key and runner invocation.StageDataPolicycovers config, upstream outputs, own outputs and both markers (including an empty prefix) and does not reach another prefix.bucketRegionConfigfollowsx-amz-bucket-regionand falls back. The CLI's role config carries the policy.Every gate was watched failing against a compiling revert (15 reverts, each
go vet-clean). Reverted: spored not run;s3-config-keytag dropped;s3-buckettag dropped; config not written; config tag pointing at the CLI's copy; default profile; runner not writing FAILED; COMPLETE at another key; outputs not uploaded; ListBucket dropped; PutObject dropped; grant widened to the bucket; bucket region ignored; CLI policy empty; fallback marker at another key.Commands run.
make checkpasses except the known Docker-onlyTestGenerateWrapper_ChownFixesCrossUIDStickyUnlink_Docker.make check-nestedpasses (all 9 modules).go test ./lambda/pipeline-orchestrator/passes, and the e2e tests are stable at-count=3. golangci-lint shows nothing new in the touched packages; the only findings are the pre-existingmanager.Uploaderdeprecations.GOOS=linux GOARCH=arm64builds the Lambda.Deployment (not done here)
cd lambda/pipeline-orchestrator AWS_PROFILE=spore-host-infra make deploy AWS_PROFILE=spore-host-infra make -C ../.. lambda-versions-deployedspawn task rundoes.spawn-binaries-*. Until a spored containing this PR's pkg/pipeline changes is published, they run the old runner. With the old runner, the command runs in/root, the runner does not write FAILED (the user data's fallback still does), and the data handler has no region. In practice: release spored together with the Lambda deploy.Caveats and follow-ups
GetBucketRegionworks from instances without internet egress. On failure it falls back to the instance's region.data_outputpath keeps its full path underoutput/, so/data/processed/xarrives downstream as<dest_path>/data/processed/x. Withinstance_count > 1, instances overwrite each other's same-named outputs. pipeline: with instance_count > 1 the first instance to finish marks the whole stage complete, and the budget uses a flat $0.10/hour #930 (next PR) covers the per-instance markers.