Skip to content

A detached sweep (the DEFAULT) launches instances with no spored and no spawn:managed tag — so neither spored nor the reaper can ever stop them #725

Closed

Description

@scttfrdmn

Found while hardware-testing #697's fix. This is worse than #697 and it is on the default path, so I am filing it separately rather than folding it in.

Detached is the default, not an opt-in

cmd/launch_sweep.go:132 auto-enables it for every sweep:

if !detach && !noDetach {
    detach = true
    fmt.Fprintf(os.Stderr, "\n⚠️  Auto-enabling --detach for parameter sweep\n")
    fmt.Fprintf(os.Stderr, "   This prevents zombie instances if CLI disconnects.\n")
}

The stated reason is zombie prevention, which makes the finding below painful: the path chosen to prevent zombies is the one that cannot stop them.

So the CLI uploads params to S3, invokes spawn-sweep-orchestrator, and returns. The instances are launched by that Lambda, not by the code #697 fixes.

The Lambda builds RunInstances from four keys

lambda/sweep-orchestrator/main.go:676:

input := &ec2.RunInstancesInput{
    MinCount:     aws.Int32(1),
    MaxCount:     aws.Int32(1),
    InstanceType: ec2types.InstanceType(instanceType),
    IamInstanceProfile: &ec2types.IamInstanceProfileSpecification{Name: aws.String(iamRole)},
    TagSpecifications: []ec2types.TagSpecification{{
        ResourceType: ec2types.ResourceTypeInstance,
        Tags: []ec2types.Tag{
            {Key: aws.String("spawn:sweep-id"), ...},
            {Key: aws.String("spawn:sweep-index"), ...},
            {Key: aws.String("Name"), ...},
        },
    }},
}
if ami != "" { input.ImageId = aws.String(ami) }
if keyName != "" { input.KeyName = aws.String(keyName) }
if spot { input.InstanceMarketOptions = ... }

It reads exactly four param keys — ami, iam_role, instance_type, key_name — and that is the whole launch.

There is no UserData. The Lambda declares its own 9-field LaunchConfig at line 172 with a UserData field that is never populated and never read, under the comment // Additional fields as needed. Verified: zero SecurityGroupIds, zero SubnetId, zero BlockDeviceMappings anywhere in the file.

Why that is a cost leak rather than a feature gap

Two independent consequences, and together they remove every lifetime guarantee the project claims:

No UserData means no spored. So no TTL enforcement, no idle enforcement, no cost-limit enforcement, no completion signal, no --on-complete. The instance runs until something external stops it.

No spawn:managed tag means the reaper cannot touch it either. The reaper's ec2:TerminateInstances grant is conditioned on ec2:ResourceTag/spawn:managed=true — deliberately, as the rail that "kept the reaper away from three unrelated 1200 GiB research filesystems and a c7g.4xlarge belonging to someone else". A detached sweep's rows do not carry that tag, so the terminate is an implicitDeny.

That is the lifecycle invariant inverted. The project's position is that "lifetime is enforced in-instance by spored, so it needs an out-of-band reaper backstop" (#70/#72). On this path neither layer applies: nothing inside the instance enforces anything, and nothing outside it is permitted to.

A detached sweep of N rows therefore runs until a human notices. --ttl, --cost-limit and --on-complete are all accepted on the command line and none of them can function.

Why it has not been noticed

The CLI prints a confident success and a status command:

✅ Parameter sweep queued successfully!
Orchestration:     Lambda (infra account)
The sweep is now running in Lambda. You can disconnect safely.

Nothing says the rows will be unmanaged. And spawn orphans cannot show them either, for the same missing tag — discovery filters on spawn:managed=true.

Relationship to #697

#697 measured "83 of 127 flags dropped" by analysing cmd/launch_sweep.go and buildLaunchConfigFromParams. That is the foreground path, reachable only with --no-detach. My fix there is real and verified, but it covers the path almost nobody takes by default.

On the default path the count is closer to 123 of 127, and the four that survive are not the ones that matter.

Suggested direction, not a patch

I do not think this should be fixed by growing the Lambda's four keys into a second implementation of buildLaunchConfig — that is how the two paths diverged. Two shapes seem plausible:

  1. Have the CLI build the full configs and hand them to the Lambda, so there is one config builder and the Lambda only orchestrates concurrency and retries. The sweep record already goes through S3, so there is a natural place to put them.
  2. Make the Lambda call the same pkg/ code the CLI does, rather than its own RunInstances.

(1) looks smaller and removes the duplicate rather than widening it.

Minimum viable mitigation, if a full fix is not immediate: have the Lambda stamp spawn:managed=true and spawn:ttl-deadline. That alone restores the reaper backstop, which is the difference between "a sweep row has no in-instance enforcement" and "a sweep row cannot be stopped by anything".

Reproduce

spawn launch s --instance-type t4g.small --param-file two-rows.json \
  --efs-id fs-… --ttl 20m --cost-limit 0.50
# CLI returns 0 immediately: "Parameter sweep queued successfully"
aws ec2 describe-instances --filters Name=tag:spawn:sweep-id,Values=<id> \
  --query 'Reservations[].Instances[].Tags'
# → spawn:sweep-id, spawn:sweep-index, Name. No spawn:managed. No TTL.
# And no UserData, so no spored.

Found on spawn v0.124.0 + the #697 branch, us-east-1, via the sweep leg added to make smoke.

Activity

  1. added
    bug
    on Oct 8, 2026
  2. scttfrdmn commented on Oct 8, 2026

    @scttfrdmn
    ContributorAuthor

    Reopening context rather than the issue: the tag fix (#726) is merged and deployed, but it is unobservable on the default path. Running the real-hardware test for this issue found that a detached sweep launches zero instances — MissingParameter: The request must contain the parameter ImageId on every row, because the CLI never seeds ami into the params the Lambda reads — and then logs All instances launched and completed while the CLI reports success. Filed as #749.

    So the tagging is correct code behind a door that does not open. #749 has to land before this can be verified end to end.

  3. scttfrdmn commented on Oct 9, 2026

    @scttfrdmn
    ContributorAuthor

    Verified end to end on real hardware. 8/8. Closing.

    This is the first run in which the assertions were observable at all — every
    previous attempt died on #749 before an instance existed.

    === Launching a 2-row DETACHED sweep (t4g.small, ttl=20m)
      ✅ sweep dispatched: sweep-20261008-696000
    
    === Waiting for the orchestrator to launch the rows (up to 5 min)
      ✅ both rows launched by the orchestrator
    
    === #725: the lifecycle tags that make a row reapable
      --- i-050c70b18f359d277
           Name              sweep-1
           spawn:managed     true
           spawn:sweep-id    sweep-20261008-696000
           spawn:sweep-index 1
           spawn:ttl-deadline 2026-10-09T00:59:01Z
      ✅ spawn:managed=true — the rail the reaper's terminate is conditioned on
      ✅ spawn:ttl-deadline=2026-10-09T00:59:01Z
      ✅ the reaper is permitted to terminate it
      --- i-0986b2a46c114a8d3   (same three, sweep-0)
    
    === Result: 8 passed, 0 failed
    

    The third assertion per row is the one that matters most: spawn:managed=true
    is only worth having if it actually unlocks the terminate, so the test runs
    iam simulate-principal-policy for ec2:TerminateInstances against each
    instance's real ARN with ec2:ResourceTag/spawn:managed supplied as context.
    Both returned allowed. The tag and the grant are confirmed together, not
    separately.

    Why it works now

    Two things had to be true at once, and only one of them lives in the repo:

    requirement where state
    CLI seeds ami into the params the Lambda reads #751, seedDetachedLaunchKeys shipped in v0.126.0
    deployed orchestrator carries the tag fix #726 deployed LastModified 15:20:55Z, newer than every commit touching lambda/sweep-orchestrator/

    I checked the second one by hand before running, because a Lambda does not
    upgrade with the CLI — that is #654, and it is the reason a green run here is
    not self-evidently a green codebase. The script's header now says so, with the
    command to re-check.

    Cost safety

    Baseline before: 0 instances, 0 placement groups, 0 pre-existing sweep rows in
    435415984226/us-east-1. After the script's own teardown, verified
    independently: 0 live instances, and both row IDs queried directly report
    terminated — not merely absent from a filtered list, which is the #736 trap.
    Cost ≈ $0.01.

    scripts/hardware-test-detached-sweep.sh's header, which still claimed the test
    fails, is corrected in the same change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions