Repository navigation
Description
Summary
spawn launch calls RunInstances, gets back a successful response with an instance ID, then immediately calls DescribeInstances on that ID — which returns InvalidInstanceID.NotFound (HTTP 400). The launch exits 1 even though the instance was created and is running.
Reproduction
This surfaces reliably when spawn launch is called from within an EC2 instance (nested spawn, e.g. via nf-spawn dispatching Nextflow tasks), but can also happen from any caller when the DescribeInstances call races EC2 API propagation.
From the spawn launch log captured on a head node:
{"timestamp":"...","level":"info","operation":"launch_instance","instance_id":"i-0e61513d099a3f99c","result":"success",...}
❌ Error: failed to describe instance: operation error EC2: DescribeInstances,
https response error StatusCode: 400, RequestID: 9844b2e2-763b-44ba-8987-f71d5d5d6ab7,
api error InvalidInstanceID.NotFound: The instance ID 'i-0e61513d099a3f99c' does not exist
The instance i-0e61513d099a3f99c was successfully created — it appeared in aws ec2 describe-instances seconds later and ran to completion. The launch JSON log confirms "result":"success".
Root cause
EC2's RunInstances and DescribeInstances are eventually consistent. After a successful RunInstances, a subsequent DescribeInstances for the new instance ID can return InvalidInstanceID.NotFound for a few seconds while EC2 propagates the new instance across its internal systems. This is documented AWS behavior.
The fix is to retry DescribeInstances with exponential backoff when InvalidInstanceID.NotFound is returned in the post-launch window, rather than treating it as a hard failure. The AWS SDK v2 ec2.NewInstanceRunningWaiter handles pending → running transitions but does not automatically retry on a NotFound 400 — that must be handled explicitly.
Impact
- Causes
spawn launchto exit 1 and fail the caller (nf-spawn marks the task as failed and aborts the Nextflow run) - The leaked instance continues running with its TTL, but the user's workload is lost
- Reproducible from nested launch paths (instance → spawn launch → EC2) where propagation seems slower than direct CLI usage
Suggested fix
In the post-launch DescribeInstances / --wait-for-running path: catch InvalidInstanceID.NotFound and retry with backoff (e.g., 1s, 2s, 4s up to ~30s) before treating it as a fatal error. This is a standard pattern for post-RunInstances polling.
Context
- spawn v0.36.11, region us-east-1
- nf-spawn Nextflow executor v0.2.6 — see also checkIfRunning() treats EC2 propagation-window NotFound as task failure — race condition on first poll nf-spawn#34
- Related to the
time.Sleepcleanup issue — the blind 30s sleep inlaunchWithProgresswas actually masking this in direct CLI use, but nested launch (no TUI) doesn't have the same delay - https://github.com/scttfrdmn/aws-microbiome-demo
Activity
scttfrdmn commentedon Jun 8, 2026
Fixed in #81, released as v0.37.2.
DescribeInstanceWithRetrynow retriesInvalidInstanceID.NotFound(and the empty-result race) with capped backoff (~30s) before failing, applied to GetInstancePublicIP/GetInstanceState, WaitForRunning (which pre-absorbs the window since the SDK running-waiter doesn't retry a NotFound 400), and the queue connect path. nf-spawn nested launches should no longer abort on the post-RunInstances propagation race — worth confirming with a microbiome-demo rerun on a spawn ≥ v0.37.2.fix(cmd): adopt WaitForRunning and honour ctx in the instance polls (#…