Repository navigation
fix(sweep): dashboard cancel marks CANCELLED and starts the orchestrator, which terminates the members (#1349) - #1357
Merged
Conversation
…tor, which terminates the members (#1349)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements the owner decision of 2026-10-26 on #1349.
What changes
Dashboard sweep cancel (
lambda/dashboard-api/sweeps.go). It no longer assumesSpawnSweepCrossAccountRole. That role's trust names onlySpawnSweepOrchestratorRole, so the assume was always denied and the members ran on until their TTL.terminateSweepInstancesCrossAccountandawsAccountIDReare deleted. The cancel keeps the existing ownership and terminal-state checks, marks the record CANCELLED withcancel_requestedas before, and then invokesspawn-sweep-orchestratorasynchronously (InvocationType: Event, payload{"sweep_id": ...}), the wayspawn launch --detachand the scheduler start it. The response says the orchestrator is terminating the instances:instances_terminatedis now always 0 andinstances_to_terminateis new. If the invoke fails, the cancel still succeeds and the message namesspawn cancel <id>.Sweep orchestrator (
lambda/sweep-orchestrator/cancel.go,main.go). A cancelled sweep's live members (pending, running, stopping, stopped) are terminated in every region the sweep has, using theSpawnSweepCrossAccountRolethe orchestrator already assumes:cancel_requested. Before this change, that path exited without doing anything.Members are found by the
spawn:sweep-idandspawn:managed=truetags. Those tags are filtered on and also re-checked on every instance EC2 returns. A member launched after the last record save is therefore still found, and another sweep's instances or untagged ones are never touched. A Spot member's request is cancelled first withpkg/spotrequest.Cancel(#922), best effort. A re-run finds nothing live and writes nothing. The outcome is an UpdateItem (status CANCELLED,cancel_requested,completed_atif it is unset,ADD cancel_terminated), not a put of the orchestrator's copy.saveSweepStateis now conditional on the record not being cancelled. Before this, a loop that had read the record before the cancel could put it back to RUNNING withcancel_requested=false. A refused save returnserrSweepCancelled, and the next poll picks the cancel up.How the orchestrator is triggered. It is started asynchronously by
spawn launch --detach,spawn resumeand scheduler-handler. While running, it polls the record every 10 s and re-invokes itself asynchronously before its 13-minute deadline. A live orchestrator therefore sees a cancel within one poll. Two cases had no invocation that would act on it:For the second case the dashboard now invokes the orchestrator itself. Only detached sweeps are in
spawn-sweep-orchestration(records are written only bylaunchSweepDetachedand scheduler-handler), so those are the only sweeps the dashboard can see or cancel. A foreground sweep's members are launched by the CLI, it has no record, the dashboard returns 404 for it, and nothing here changes for it. Single-region and multi-region detached sweeps both go throughcancelSweep.IAM.
setup-dashboard-lambda-role.sh: newStartSweepOrchestratorstatement,lambda:InvokeFunctiononfunction:spawn-sweep-orchestratoronly (SPAWN_ORCHESTRATOR_FUNCTION_NAMEoverrides it, the same variable the Lambda reads).setup-sweep-cross-account-role.sh:ec2:CancelSpotInstanceRequests, next to the unconditionedTerminateInstancesthat is already there. Members' Spot requests are untagged, so thespawn:managedcondition would refuse them. Cancelling never terminates anything.SpawnDashboardLambdaRolenever grantedsts:AssumeRole, which is why the ledger carried that entry.internal/iamcoverage: thedashboard-api | SpawnDashboardLambdaRole | sts:AssumeRoleentry is removed. It also coveredcross_account.go's caller-credential assume (Dashboard cross-account EC2 reads have never worked: the role it assumes is not granted #815), which the gate attributed to the Lambda role. That assume is now its own function,callerAssumeRoleProvider, and it is cut from the dashboard-api inventory because it runs as the caller, not asSpawnDashboardLambdaRole. A source test keeps that function to the STS client and the provider, so the cut cannot hide anything else.SpawnDashboardCrossAccountReadRoleterminate entries are rewritten as permanent, explained decisions (Dashboard: terminate and sweep cancel in a member account have no role that may do them (owner decision) #1349 option 3). Instance terminate behaves as fix(iam): batch-queue results role; dashboard role scripts match the code (#1344) #1352 left it.make cli-iam-actions: the CLI inventory is unchanged (TestCLIActionInventoryIsCurrentpasses).Gates (each watched failing against a revert that compiles)
The existing orchestrator and dashboard tests use in-process fakes, not Substrate, so these do too. The orchestrator gates run the real
handlerfrom a JSON payload through seams (loadState,memberClientsFor,recordCancelOutcome). The fake EC2 ignores filters and returns every instance, so the in-code ownership check is what the gate proves. The dashboard gates callhandleCancelSweepwith anaws.Configwhose HTTP transport serves and records every AWS request.TestCancelledSweepTerminatesItsMembersOnly: members in 2 regions terminated, Spot cancelled first, other sweep / untagged / unmanaged / terminated untouched, outcome 4 recordedisSweepMemberreturns trueTestCancelReRunIsANoOpTestLoopSaveDoesNotClobberACancelTestDashboardSweepCancelAssumesNoRolests.AssumeRoleof SpawnSweepCrossAccountRole in the cancelTestDashboardSweepCancelInvokesTheOrchestratorTestEveryPrincipalCallIsGrantedlambda:InvokeFunctiongrantcallerAssumeRoleProvidercutCancelSpotInstanceRequestsgrantLive deploys this needs (none done here)
setup-dashboard-lambda-role.sh: re-run in the infra account (966362334030) for thelambda:InvokeFunctiongrant. Until then, the cancel's invoke is denied. The cancel still marks the sweep and a live orchestrator still acts within one poll, but an orchestrator that is no longer running is not restarted. The message then namesspawn cancel <id>.spawn-dashboard-apiLambda: redeploy (lambda/dashboard-api/deploy.sh).spawn-sweep-orchestratorLambda: redeploy (scripts/deploy-sweep-orchestrator.sh). Until then, nothing terminates a cancelled sweep's members.scripts/setup-sweep-cross-account-role.sh: re-run in each member account that runs detached sweeps (435415984226), forec2:CancelSpotInstanceRequests. Until then, the Spot cancel is denied and logged, and the terminate still happens. Orchestrator members are one-time Spot requests, which close with their instance.Order: 3 before 2, so that a dashboard cancel never invokes an orchestrator that exits on CANCELLED. 1 and 4 are independent.
Follow-up
The dashboard web UI (
spore-host/web/js/main.js:1573) alerts "Terminated ${data.instances_terminated} instance(s)", which will now say 0. Filed as spore-host/spore-host#613.Fixes #1349
Checks:
make check(all passed, including the build-tags step),make lint(0 issues in every module),semgrep scan --config=auto --error .(clean),go test ./internal/iamcoverage(ok).