Repository navigation
Description
Problem
When an actor resumes from a MEMORY snapshot, runtime fallback is driven by assignWorkerAttempt in cmd/ateapi/internal/controlapi/workflow_resume.go, outside Scheduler.Schedule. Three costs follow from that.
-
Two fleet scans on fallback.
assignWorkerAttemptcallsSchedulewithRequiredRuntimeset. OnErrNoCapacityit clearsRequiredRuntimeand callsScheduleagain. Each call takes theworkercacheread lock, copies the full[]*ateapi.Workerslice, and runs the static filters and label selectors over every worker. -
Two runtime scans per candidate. Inside
Schedule,AppliescallsRequiredRuntime.WorkerMatches, which walks the worker'sDefaultRuntimeandRestorableRuntimes.Bookingthen callsSnapshotRuntime.WorkerRuntimeFor, which walks the same list again to readActorOverhead. -
Fallback state spread into
controlapi. Because the retry mutatesConstraintsbetween passes,Constraintscarries twohardware.Requirementfields (RequiredRuntimeandSnapshotRuntime), andvalidateAssignedWorkerneeds its ownappliesWithFallbackto agree with what placement would do.
This gets worse with a third fidelity. #3230 asks resume to drop to VOLUMES rather than ROOTFS when the architecture differs. With caller-driven retries that is a third pass over workercache.
Proposal
Move fidelity preference into the scheduler so placement picks the best worker in a single pass:
- Pass the lowest acceptable fidelity once: Instead of calling
ScheduleforMEMORY, catchingErrNoCapacity, mutatingConstraints, and callingScheduleagain, the resume workflow tellsScheduleupfront both the snapshot's runtime and the lowest fidelity it is willing to accept (MEMORYwhen pinned to a node, orROOTFS— and laterVOLUMES— when fallback is allowed). - Keep only the highest-fidelity tier during a single scan: As
Schedulewalks the worker cache once, it evaluates each eligible worker's runtime once to get both the restore fidelity it can achieve and its memory overhead:- While only
ROOTFSworkers with room have been seen,SchedulecollectsROOTFScandidates. - As soon as the first
MEMORYworker with room is found,Schedulediscards theROOTFScandidates in place, raises its floor toMEMORY, and skips any remaining lower-fidelity workers for the rest of the loop.
- While only
- Sample from the winning tier: At the end of the pass,
candidatesholds every available worker at the highest fidelity reachable in the fleet (MEMORYif any had room, otherwiseROOTFS, and laterVOLUMES), and Power-of-Two-Choices picks between them as before.
The set of workers an actor can land on and the choice among them do not change: today's second pass only runs when no MEMORY worker has room, which is the exact ROOTFS set the single pass keeps when no MEMORY worker qualifies.
Activity
juli4n commentedon Nov 17, 2026
This is a good idea. The scheduler should be aware of constraints that can be relaxed (e.g. fidelity) so we don't need to do do multiple scans. I think there is also value in having the logic to decide how fidelity interplays with scheduling in one place.
cc Zoe Zhao (@zoez7) as we discussed this last week.
shrutiyam-glitch commentedon Nov 20, 2026
Added more about the flow and the test cases considered here - https://docs.google.com/document/d/1hqgUq3z-8gXKCZUNsqSYITEyuT-6mt4kQpel0IzxJ8U/edit?tab=t.0