Skip to content

fix: --command as instance user, idempotent IAM, Tier 2 fixes (#61, #64) - #69

Merged
scttfrdmn merged 2 commits into
mainfrom
fix/61-command-prestop
Jun 6, 2026
Merged

scttfrdmn merged 2 commits into
mainfrom
fix/61-command-prestop

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Summary

Resolves the remaining #61 Tier 2 failures and the #64 IAM race uncovered while getting Tier 2 green. (The two spored lifecycle bugs found in the same investigation — #65/#66 — ship separately in #67.)

#61 — --command ran as a nonexistent user / was gated to sweeps (already committed: 732e0f6)

--command was nested inside the sweep-only branch and ran su - local (the local user never exists). Hoisted it out so any instance with the spawn:command tag runs it, as su - "$LOCAL_USERNAME".

#64 — concurrent launches raced on the shared IAM role

CreateOrGetInstanceProfile / createIAMRole did check-then-act on a shared spored-instance-role + profile, so parallel launches failed with EntityAlreadyExists / LimitExceeded. Made IAM setup idempotent:

  • retryIAM() treats already-exists as success and retries throttling with backoff; applied to CreateRole, CreateInstanceProfile, AddRoleToInstanceProfile.
  • iamErrorCode/isAlreadyExists/isThrottle classify via smithy.APIError with a message fallback. Note: modeled SDK codes drop the Exception suffix (EntityAlreadyExists, LimitExceeded) while substrate keeps it → match on code prefix.
  • TestCreateOrGetInstanceProfile_Concurrent (8 goroutines, same role) + classifier unit tests.

e2e — unblock parallel launches

With IAM setup now concurrency-safe, launchSem 1→4: the launch burst is bounded but no longer serialized; running/assertion phases stay fully parallel.

TestTier2_PreStop — assert the real path

Rewritten to verify completion → grace → pre-stop → stop, then start back up and check the marker. The marker is written to /var/tmp, not /tmp: the stop/start cycle reboots the instance and /tmp is wiped on boot (systemd-tmpfiles, AL2023), so a /tmp marker would false-negative even when pre-stop works. (Caught during #66 validation.)

status --check-complete — correct exit codes

resolveInstance / findSSHKey failures now exit 3 (error/unknown), not cobra's exit 1 ("task failed"). A just-launched instance is unresolvable for ~1s (InvalidInstanceID.NotFound); pollers must keep polling. (nf-spawn#31.)

Validation

IAM concurrency + classifier tests pass; go vet -tags=e2e_tier2 ./test/e2e/ clean. Full Tier 2 re-run is gated on the #65/#66 fix being released to the S3 binary bucket (instances pull spored from S3 at boot), since PreStop/on-complete depend on the now-fixed monitor.

Related

Closes #64
Contributes to #61

scttfrdmn added 2 commits June 5, 2026 19:37
…al' (#61)

--command (and the parameter-sweep workflow command) ran via
'su - local', but no 'local' user exists — the bootstrap creates
$LOCAL_USERNAME. So the command silently failed with 'user local does not
exist'. Also: the command-exec block was nested inside the sweep-only
SWEEP_ID gate, so a plain single 'spawn launch --command' never ran it at
all. Hoisted it out to run for any instance with a spawn:command tag, and
run it as $LOCAL_USERNAME. TestTier2_CommandExecution now PASSES.

Test harness: launchSem capped at 1 (serialize launches) to avoid the
concurrent IAM-role race (#64) until that's fixed; PreStop poll widened to
3m (spored monitor ticks ~1m).

Remaining Tier 2 failures (pre-stop, iam-policy, name-resolution) tracked
in #61/#63/#64.
…#61)

#64 — concurrent launches raced on the shared spored-instance-role.
CreateOrGetInstanceProfile / createIAMRole did check-then-act on a shared
role+profile, so parallel launches failed with EntityAlreadyExists /
LimitExceeded. Made the IAM setup idempotent:
  - retryIAM() treats already-exists as success and retries throttling with
    backoff; applied to CreateRole, CreateInstanceProfile, and
    AddRoleToInstanceProfile.
  - iamErrorCode/isAlreadyExists/isThrottle classify via smithy.APIError with a
    message fallback. NOTE: the modeled SDK codes drop the "Exception" suffix
    (EntityAlreadyExists, LimitExceeded) while substrate keeps it, so we match
    on the code prefix.
  - TestCreateOrGetInstanceProfile_Concurrent (8 goroutines, same role) + unit
    tests for the classifiers.

e2e — with IAM setup now concurrency-safe, raise launchSem 1→4 so the launch
burst is bounded but no longer serialized; running/assertion phases stay fully
parallel.

TestTier2_PreStop — rewritten to assert the real path: completion → grace →
pre-stop → stop, then start back up and verify the marker. The marker is
written to /var/tmp (NOT /tmp): the stop/start cycle reboots the instance and
/tmp is wiped on boot (systemd-tmpfiles, AL2023), so a /tmp marker would
false-negative even when pre-stop works.

status — in --check-complete mode, resolveInstance / findSSHKey failures now
exit 3 (error/unknown), not cobra's exit 1 (which means "task failed"). A
just-launched instance is unresolvable for ~1s (InvalidInstanceID.NotFound);
pollers must keep polling, not conclude failure (nf-spawn#31).
@codecov

codecov Bot commented Jun 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 53 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/launch.go 0.00% 29 Missing ⚠️
cmd/status.go 0.00% 13 Missing ⚠️
pkg/aws/iam.go 82.81% 8 Missing and 3 partials ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 7f55e7d into main Jun 6, 2026
3 checks passed
@scttfrdmn
scttfrdmn deleted the fix/61-command-prestop branch June 6, 2026 19:31
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.

Concurrent launches race on shared spored-instance-role IAM setup → launch fails

1 participant