Resolve runner_machine_id when queuing a suspend/resume build
Related MRs
- !244035 (merged) — schema + read-side groundwork
- !247560 (merged) — persist
Ci::JobRuntimeEnvironmenton suspend - !247561 (merged) — record the runner machine assignment when a build starts running
- This MR — resolve
runner_machine_idwhen queuing a suspend/resume build - !247563 — consume the routed runner machine when assigning jobs
- !247564 — retire the old
environment_keystring-matching routing mechanism
What does this MR do and why?
When a suspended CI job resumes, the follow-up job has to land on the exact runner machine that ran the original job — that machine is the one holding the suspended environment's state. !247561 already records which runner machine ran a suspending build, onto that build's own environment row.
This MR carries that recorded id forward to the resuming job, at the moment it's queued. Ci::JobRuntimeEnvironment.runner_machine_id_for looks up whether any build tied to the same Ci::RuntimeEnvironment already has a runner machine recorded (there can be more than one prior build in the chain; it picks the earliest recorded one), and Ci::PendingBuild.args_from_build stores that id on the new build's queue entry (ci_pending_builds.runner_machine_id). Resolving it once here, instead of on every runner poll, is what lets the poll-time check become a plain indexed column filter instead of a per-poll lookup.
Gated behind ci_suspendable_environment_runner_routing, checked against the build's project; no-ops for builds that aren't part of a suspend/resume chain. This MR only makes the resolved id available on the queue entry — it doesn't change which runner actually gets offered the job. That happens once !247563 wires the runner-polling path to read this column.
Part of routing resumed builds to the runner machine that holds their suspended environment: Resumable Jobs for CI and Agent Sessions (gitlab-org#21159)
References
Depends on !247561 (merged) and !244035 (merged).
Issue: Resumable Jobs for CI and Agent Sessions (gitlab-org#21159)
Blueprint: Add blueprint for suspendable environments (gitlab-com/content-sites/handbook!18954 - merged)
How to set up and validate locally
Run the spec files covering this change:
bundle exec rspec spec/models/ci/job_runtime_environment_spec.rb spec/models/ci/pending_build_spec.rbMR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.