Skip to content

fix(sweep): resume re-creates a deleted spawn-instance-* profile from the recorded IAM config (#1385) - #1395

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/1385-resume-recreates-role
Oct 28, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/1385-resume-recreates-role

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #1385

What checkpoints stored

Nothing about IAM. SweepState held the param-file path and instance records only. applyCLIIAMToSweep writes the CLI profile into the in-memory Defaults["iam_role"], and resume re-parses the file from disk, so:

Change

  • SweepState gains iam_recorded and iam_role (SweepIAMRole: profile, verbatim flag, the full IAMRoleConfig with stable JSON names, the policy file's sha256, and the original flags for messages). Written on both checkpoint writes in runSweepLaunch. A detached sweep writes the same record to ~/.spawn/sweeps/detached-iam/<id>.json before the params upload (the orchestrator PutItems its whole DynamoDB record, so a new attribute there would be dropped).
  • Foreground resume (spawn resume, spawn sweep resume): applyRecordedIAM restores the CLI profile into defaults; relaunchPending calls ensureResumeProfiles before the first launch. Each spawn-created profile (spawn-instance-* or recorded-with-config) gets one InstanceProfileReady (iam:GetInstanceProfile). If it exists, it is reused unchanged with no IAM writes. If it is gone, it is re-created via CreateOrGetInstanceProfile(original config) (or SetupNestedSpawnProfile for a nested role), and the returned name must match. All checks run before any write.
  • Refusals (nothing launched): a gone profile with no record (old checkpoint, or a name taken from the param file), which names the flags it can't recover; a recorded --iam-policy-file that is missing or changed; an old checkpoint whose own still-visible instances carry a profile different from what the resume would use.
  • Detached resume: ensureDetachedResumeProfile re-creates from the local record before InvokeSweepOrchestrator. With no record (older sweep, other machine), it prints a note that it can't check.
  • Also: resume gave spored's shared profile only when the first pending config had none; now any config without one gets it.
  • API: aws.Client.InstanceProfileReady (added; api/public-surface.txt regenerated). cli-iam-actions is unchanged because iam:GetInstanceProfile is already listed for sweep resume. No new permission for any principal.

Gates (each watched failing against a compiling revert)

  • TestResume_RecreatesDeletedSpawnRoleWithOriginalPolicyBeforeLaunch: the call log is ready, create, launch, launch, and the create uses the original config. Fails with the ensure call removed from relaunchPending and with applyRecordedIAM made a no-op.
  • TestSweepCheckpointRecordsCLIIAMConfig: fails when runSweepLaunch records IAMRole: nil.
  • TestResume_OldCheckpointWithRoleGoneIsRefusedWithZeroLaunches: zero launches, no create, only the readiness read. Fails without the ensure call, and when the unrecorded gone-role branch returns nil.
  • TestResume_OldCheckpointRefusesADifferentRole: fails with the drift check disabled.
  • TestResume_ExistingRoleReusedUnchanged: log is ready, launch, launch. Fails when the readiness short-circuit is removed (always re-create).
  • TestDetachedResume_RecreatesRecordedRole: fails when the record isn't loaded.
  • TestResumePathsReachTheIAMRecord: AST ordering in runResume, relaunchPending, resumeSweepDetached and launchSweepDetached.
  • Plus TestResume_ChangedPolicyFileIsRefused and TestResume_RecreatesNestedSpawnRole.

make check, make lint (0 issues), semgrep scan --config=auto --error . all pass. No help text changed. Not exercised against AWS.

Follow-up filed: #1394 (resume also drops CLI --ttl/--idle-timeout/--cost-limit and skips the 1h idle default).

@codecov

codecov Bot commented Oct 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 64.67890% with 77 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/sweep_iam_record.go 79.28% 35 Missing ⚠️
cmd/resume.go 16.66% 15 Missing ⚠️
pkg/aws/iam.go 0.00% 14 Missing ⚠️
cmd/launch_sweep.go 23.52% 13 Missing ⚠️

📢 Thoughts on this report? Let us know!

… the recorded IAM config (#1385)

A sweep checkpoint stored neither the profile the CLI IAM flags resolved
to nor how it was made. Resume reloads the param file, which never held
it, so a resumed member silently got spored-instance-profile; and a
spawn-instance-* profile named in the file was reused without being
re-created, failing at RunInstances once the idle-role sweep deleted it.

New checkpoints (and a local record for detached sweeps) carry the
profile and its IAMRoleConfig. Before the first launch, resume checks
each spawn-created profile (iam:GetInstanceProfile): an existing one is
reused unchanged, a gone one is re-created through the same
CreateOrGetInstanceProfile call and must return the same name. A gone
profile with no record, a changed --iam-policy-file, or an old checkpoint
whose own instances show a different profile refuses the resume with
nothing launched.

Fixes #1385
@scttfrdmn
scttfrdmn force-pushed the fix/1385-resume-recreates-role branch from cdfd461 to eb1f3dd Compare October 28, 2026 20:19
@scttfrdmn
scttfrdmn merged commit 60bdd8f into main Oct 28, 2026
9 checks passed
@scttfrdmn
scttfrdmn deleted the fix/1385-resume-recreates-role branch October 28, 2026 20:43
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.

sweep resume reuses a spawn-instance-* profile name without re-creating it; fails if the role sweep deleted it

1 participant