Skip to content

fix(pool): survive the instance-profile race, name each missing worker, retry a run id (#1448) - #1453

Merged
scttfrdmn merged 2 commits into
mainfrom
fix/1448-pool-iam-race
Oct 31, 2026
Merged

scttfrdmn merged 2 commits into
mainfrom
fix/1448-pool-iam-race

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #1448

All four problems in the issue and its comment are fixed. Root cause first.

1. Workers lost to the instance-profile race: cause (d), the cohort's launch budget

The pool path does call runInstancesWithRetry (cmd/pool.go → taskcohort.Actuator.Launch → aws.Client.Launch → runInstancesWithRetry), and the classifier matches the pool's error, so it was neither (a) nor (b). The cause is (d):

This matches the CloudTrail: all four rejected at 19:47:41, worker-3 retried at :43, three succeeded at :48 (the third attempt, about 7 s in), and no further call for worker-1. Pool 1 has the same shape.

Fix. The pool's budget is now poolCohortBudget(): LaunchAcked = aws.InstanceProfilePropagationRetryWindow() + 1m for Launch's own calls. The backoff is extended to 2/4/8/16/30 s (60 s in total) for IAM's longer tail. The sleep now honours ctx.

2. Empty failure reason: dropped in two places

  • The code was empty because the error was the SDK's context error, not an smithy.APIError. runInstancesWithRetry now returns RunInstances retry stopped (<ctx err>) after N attempt(s) rejected with: <AWS err>, which wraps both. newLaunchError extracts InvalidParameterValue again. taskcohort.Classifier now also takes the code from a bare AWS error, and uses AWS's own message, noting a deadline.
  • The message was never printed. The Classifier did keep it (Fault.Message), but cohort.Record.Summary() renders only Class/Code. poolMemberReason renders the code and message, for the culprit and for each cohort-cancelled survivor: terminal/InvalidParameterValue: Value (…) for parameter iamInstanceProfile.name is invalid. Invalid IAM Instance Profile name at phase=launch-acked ….

3. "ready" hid a 1-of-4 pool

The output is now ✅ Pool "X" ready: 1 of 4 workers (min viable 1), queue created., followed by ⚠️ 3 worker(s) did not come up; the pool runs with 1: and one line per missing worker with its reason. The failure error also says how many came up. pool create has no JSON output: it writes only to stderr and ignores the global -o, so there was no JSON to change.

4. IdempotentParameterMismatch on a retry with the same run id

What differs. The token was cohort.Token("pool", "<run>-worker-<i>", "g1"), fixed per run id and worker. The request is not fixed: buildTags stamps spawn:launch-time and spawn:ttl-deadline (RFC 3339, to the second, from tagClock) on both the instance and volume TagSpecifications. Pool workers always have a TTL (--ttl 4h). User data, profile name, AMI and instance type are deterministic, and TestAnchorLaunchTagsMovesEveryInstant already shows these two tags are the ones that move.

Choice: scope the token, not freeze the parameter. The timestamps are right to differ, because a retried pool's TTL must run from its own launch. So the token's generation is now the run queue's incarnation, its SQS CreatedTimestamp (taskpool.Queue.Incarnation).

Why this can't create duplicate workers:

  • Within an attempt, every re-issue of a worker's RunInstances (the SDK's retries, the Task launch dies on a transient "Invalid IAM Instance Profile name" — the fixed 10s propagation sleep loses the IAM→EC2 race; RunInstances isn't retried #572 retry) resends the identical input with the same token, so EC2 returns the one instance. The new test checks that the retry sends the same input.
  • Across attempts, a new token needs a new queue. A failed create deletes its queue (existing behaviour), so its retry creates a new queue and gets new tokens. A create while the pool is live finds the same queue, because CreateQueue returns an existing queue. It therefore sends the live workers' tokens, and EC2 either dedupes them or refuses them with a mismatch.
  • pool create also refuses up front, in plain words, when the run has live workers (poolLiveWorkers, matched on the spawn:pool-run-id tag), and points at spawn pool drain.
  • Without sqs:GetQueueAttributes, pool create warns and scopes tokens to the attempt (a random nonce). Retry still works, and only the token backstop for a live pool is lost.
  • A retry within 60 s of the failed attempt hits SQS's QueueDeletedRecently. taskpool.CreateQueue now says to retry in a minute.

Gates (each watched failing against a compiling revert)

Gate Revert Failure
cmd TestPoolLaunchBudgetHoldsTheProfileRetryWindow (real Reconciler + taskcohort seam, min-viable 1 and 4) poolCohortBudget = DefaultBudget() both subtests: 0 came up
pkg/aws TestRunInstancesWithRetry_PoolWorkersOutlastTheProfileRace (4 concurrent workers, all rejected until the profile propagates; counted through the sleep seam, simulated clock, no wall-clock) backoff back to 2/4/8 45s subtest fails (the 7 s CloudTrail case passes under both: the schedule was not the cause, the budget was)
pkg/aws TestRunInstancesWithRetry_StoppedRetryKeepsTheAWSError retryStopped returns ctx err only both subtests: LaunchError code empty
pkg/taskcohort TestClassifierFaultCarriesTheAWSReason old Classifier (LaunchError-only code, err.Error()) both subtests
cmd TestPoolFailureNamesTheAWSError, …WhenTheDeadlineEndsTheRetry render with rec.Summary() both fail (plus the ready test)
cmd TestPoolReadySaysHowManyWorkersExist old "requested %d workers" line, missing list disabled fails: no "1 of 4", no reasons
cmd TestPoolCreateRetriesUnderTheSameRunID, TestPoolCreateCannotDuplicateALivePool (fake EC2 that remembers tokens incl. rejected ones and moves launch-time per call) generation hard-coded "g1" retry: all 4 terminal/IdempotentParameterMismatch (the comment's symptom reproduced); tokens shared across incarnations

Checks

make check (from /private/tmp) passes, make lint reports 0 issues, semgrep scan --config=auto --error . is clean, and make check-docs passes. make api-snapshot adds aws.InstanceProfilePropagationRetryWindow and (*taskpool.Queue).Incarnation. make cli-iam-actions adds sqs:GetQueueAttributes to spawn pool create. pool status already needs that action, and pool create degrades with a warning without it.

Deploy checklist (make deploy-checklist FROM=v0.151.0 TO=HEAD)

lambda/pipeline-orchestrator and lambda/sweep-orchestrator show as code-only because they compile pkg/aws/client.go. Both call ec2Client.RunInstances directly and never reach runInstancesWithRetry, so the change does not alter their behaviour. The other manual entry, setup-lambda-deploy-ci-role.sh, comes from #1445 on main, not from this PR.

@codecov

codecov Bot commented Oct 31, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 74.26471% with 35 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/pool.go 68.60% 27 Missing ⚠️
pkg/aws/client.go 66.66% 6 Missing ⚠️
pkg/taskcohort/adapter.go 94.73% 1 Missing ⚠️
pkg/taskpool/queue.go 92.30% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn force-pushed the fix/1448-pool-iam-race branch from 494dbb4 to 0977e12 Compare October 31, 2026 00:25
@scttfrdmn
scttfrdmn merged commit 9b49859 into main Oct 31, 2026
9 checks passed
@scttfrdmn
scttfrdmn deleted the fix/1448-pool-iam-race branch October 31, 2026 00:44
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.

pool create: workers lost to the IAM instance-profile race (#572) on pool launch; failure reason empty, 1-of-4 pool reported ready

1 participant