Repository navigation
fix(sweep): honour --detach without --max-concurrent; decide the sweep path once (#1535) - #1536
Conversation
…p path once (#1535) An explicit --detach with no --max-concurrent ran the sweep in the foreground while printing 'Orchestration: Lambda (detached)'. The path is now decided once by sweepDispatch and read by the summary, --wait, the path-specific refusals and the dispatch. A detached sweep checks SpawnSweepCrossAccountRole exists before creating anything. Refs #1535
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Live test at
|
| Run | Output | Result |
|---|---|---|
--detach (no --max-concurrent) |
Setting --max-concurrent=2, Orchestration: Lambda (detached), ✓ Lambda invoked |
COMPLETED 2/2 via the orchestrator. Before this PR it ran in the foreground. |
| no detach flag | Auto-enabling --detach, Setting --max-concurrent=2, Lambda (detached) |
COMPLETED 2/2, unchanged from v0.160.0 |
--detach --wait --wait-timeout 20m |
Progress: 2/2 launched, Status: COMPLETED |
It waited, returned at COMPLETED, exit 0 |
--no-detach |
Orchestration: foreground (--no-detach: this CLI launches every member; keep it running), ✓ Launched … 1/2, 2/2 |
0 occurrences of "Lambda" in the output |
Missing-role refusal, aws account (942542972736, which has no SpawnSweepCrossAccountRole)
With AWS_PROFILE=aws SPAWN_COMPUTE_PROFILE=aws, the default detached sweep exited 1: a detached sweep needs SpawnSweepCrossAccountRole in account 942542972736 … Nothing was created. Run the sweep with --no-detach …
I verified that nothing was created: no record in spawn-sweep-orchestration, 0 params objects in spawn-sweeps-us-east-1, no new IAM role, and no new instances. The check is one read-only iam:GetRole.
A pre-existing bug the first attempt exposed (filed as #1538, not caused by this PR): without SPAWN_COMPUTE_PROFILE, the compute profile defaults to the hardcoded spore-host-dev. So AWS_PROFILE=aws alone checked, and launched in, 435415984226. The orchestrator started 2 members there, which I terminated.
Not run live: spawn resume --detach. The hermetic tests cover it.
Leak check: every test sweep's instances (d1–d4, mr) are terminated, and none are still running.
Fixes #1535
What was wrong
cmd/launch_sweep.gotook the orchestrator only fordetach && maxConcurrent > 0, and only the auto-detach branch (no detach flag) set a max-concurrent (min(rows, 10)). An explicit--detachskipped that branch, so max-concurrent stayed 0 and the sweep ran in the foreground while the summary printedOrchestration: Lambda (detached). A sweep with no flag was already genuinely detached (TestDetachedSweepWithNestedRowGetsTheDetachedRefusalpins this), so the issue's "plain sweep is affected too" does not hold. Owner decision (A, on #1535): keep the default, honour--detach.Dispatch (
sweepDispatch, decided once)--max-concurrentif given, else--max-concurrent-auto's, else min(rows, 10) (unchanged)--detach--detach --max-concurrent N--no-detach--detach --no-detach/--max-concurrent+-auto/ negativeA detached sweep is never recorded with max-concurrent 0. The orchestrator launches only while
active < max_concurrent, so 0 would launch nothing.The summary,
--wait, the path-specific refusals (#1331/#1372 detached, #1375 foreground),--max-concurrent-autoand the dispatch all read the decision.TestSweepDispatchIsTheOnlyReaderOfTheDetachFlagstype-checks package cmd and fails if anything other than asweepDispatch(...)argument reads thedetach/noDetach/maxConcurrent/maxConcurrentAutoglobals.Behaviour changes
--detachwithout--max-concurrentnow goes to the orchestrator. The summary says so, and the same "Setting --max-concurrent=N" message prints.Orchestration: foreground (--no-detach: …). It used to print no line at all, and it never mentions Lambda.--waitis accepted on a default (no flag) sweep, which is detached. It used to be refused with "--wait requires --detach". It is still refused with--no-detach.--detach --waitused to run in the foreground and return without waiting. It now waits. Theexamples/workflows/*pass exactly that.--max-concurrent< 0 is refused. It used to mean a foreground sweep, all at once.Fail-closed
SpawnSweepCrossAccountRolecheckBefore this change, nothing checked the role.
sweep.ValidateParameterSetstries the assume, always fails (the role trusts onlySpawnSweepOrchestratorRole) and only warns "validation skipped". A sweep in an account without the role created the CLI IAM role, the spored instance profile, the egress proxies, the S3 params and the DynamoDB record, then invoked the orchestrator and printed "queued successfully", and the orchestrator launched nothing.Now
spawn launch(detached path) andspawn resume --detachcalliam:GetRoleon the role before anything is created (pkg/sweep.CheckCrossAccountRole).spawn launchandspawn resumealready calliam:GetRole, so the IAM inventory is unchanged. ANoSuchEntityrefuses, names the account and points at--no-detach. Any other error (no permission to look, a throttle) warns and goes on, as before. Resume skips the check when the credentials' account isn't the account in the record.Tests (hermetic)
TestSweepDispatchTable: the (detach, noDetach, maxConcurrent, auto, rows) table.TestSweepPrintedModeIsTheDispatchedPath: through the realrunLaunchwith the recording AWS fake (withLogDir). The printed mode matches the path taken, and the foreground output contains no "Lambda".TestDetachedSweepWithoutTheCrossAccountRoleCreatesNothing: default,--detach, and--detach --iam-policy. No AWS call beyond the identity lookups.TestSweepRefusalsFollowTheDispatchedPath,TestSweepWaitFollowsTheDispatchedPath,TestCrossAccountRoleCheckRefusesOnlyAbsence, plus the source gate.Revert evidence:
cmd/launch_sweep.gofrom main, every new gate fails.--detachhitsDescribeKeyPairs(the foreground path). The default sweep goes on toCreateRolewithout the role.--waitwithout--detachis refused. The gate lists 9+ direct reads.--detachto the foreground;detach && maxConcurrent > 0;--waitkeyed on the flag.Checks
make check, the hermeticgo test ./...(AWS env stripped),make test-e2e-tier0,semgrep scan --config=auto --error .(0 findings),make gen-docs(committed),make api-snapshot(no change) andmake cli-iam-actions(no change) all pass.lambda/scheduler-handler/go.modis tidied, becausepkg/sweepnow importsservice/iam.Live-test checklist (not run; no AWS access from this change)
Detached runs go in spore-host-dev only.
spawn launch t --param-file 2rows.yaml --detach --ttl 30m→Setting --max-concurrent=2,Orchestration: Lambda (detached), orchestrator invoked once,spawn sweep status <id>found, 2 members launched by the orchestrator, then reaped/cancelled.--detach --wait --wait-timeout 20mwaits and returns on COMPLETED.--no-detach --ttl 30m→Orchestration: foreground …, no "Lambda" in output, members launched by the CLI.spawn-sweep-orchestrationitem, no S3 params object, no new IAM role or profile.spawn resume --sweep-id <detached id> --detachpasses the role check and re-invokes.