From bdd842ca6c9a6d4884fbdfff5e011f5f9c1dd218 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 28 Oct 2026 09:14:42 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20a=20builtin=20job=20witho?= =?UTF-8?q?ut=20`memory`=20gets=20the=20runner's=20memory=20budget=20as=20?= =?UTF-8?q?its=20cgroup=20limit,=20as=20docs/ci.md=20says,=20instead=20of?= =?UTF-8?q?=20limits.memory=20(4g),=20which=20OOM-killed=20rustc=20in=20ca?= =?UTF-8?q?rgo=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- crates/forge-runner/src/config.rs | 21 +++++++++++++++++++ crates/forge-runner/src/executor.rs | 10 +++++++-- crates/forge-runner/src/runner.rs | 1 + .../forge-runner/tests/integration/builtin.rs | 1 + 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/crates/forge-runner/src/config.rs b/crates/forge-runner/src/config.rs index 9635ced..c0d6da1 100644 --- a/crates/forge-runner/src/config.rs +++ b/crates/forge-runner/src/config.rs @@ -98,6 +98,21 @@ impl Limits { limits } + /// [`Limits::for_job`] for the builtin executor, where every job sits in the runner's box: a + /// job without `memory` may use the whole budget (docs/ci.md, Memory), never less than the + /// default reservation. The box and the pressure controller keep jobs together inside it. + pub fn for_builtin_job(&self, declared: Option, budget: Option) -> Limits { + match (declared, budget) { + (None, Some(budget)) => { + let reserve = forge_ci::size::parse_size(&self.reserve_memory).unwrap_or(0); + let mut limits = self.clone(); + limits.memory = budget.max(reserve).max(1).to_string(); + limits + } + _ => self.for_job(declared), + } + } + /// The cgroup `memory.max` of a job in bytes, see [`Limits::for_job`]. `None` when /// `limits.memory` does not parse, which the sandbox reports itself. pub fn job_memory_limit(&self, declared: Option) -> Option { @@ -670,6 +685,12 @@ mod tests { }; assert_eq!(bad.job_memory_limit(None), None); assert_eq!(bad.for_job(None).memory, "lots"); + // Builtin: no `memory` means the whole budget; a declared one keeps its slack. + assert_eq!(limits.for_builtin_job(None, Some(6 * gib)).memory, (6 * gib).to_string()); + assert_eq!( + limits.for_builtin_job(Some(gib), Some(6 * gib)).memory, + limits.for_job(Some(gib)).memory + ); } #[test] diff --git a/crates/forge-runner/src/executor.rs b/crates/forge-runner/src/executor.rs index 356af31..897750c 100644 --- a/crates/forge-runner/src/executor.rs +++ b/crates/forge-runner/src/executor.rs @@ -57,6 +57,9 @@ pub struct ExecRequest<'a> { /// Where the executor leaves OOM kills it saw in the job's cgroup. Executors that cannot see /// them leave it alone. pub oom: OomSink, + /// The runner's memory budget now. The builtin executor gives a job without `memory` this as + /// its cgroup limit; `None` keeps the configured `limits.memory`. + pub memory_budget: Option, } /// The executor's answer. The runner adds timeouts and artifact results on top of it. @@ -641,14 +644,16 @@ impl BuiltinExecutor { logs, cancel, oom: oom_sink, + memory_budget, } = req; + let limits = self.limits.for_builtin_job(job.memory_bytes, memory_budget); if let Err(e) = validate_job_id(&job.job_id) { return error_result(e.to_string()); } if let Err(e) = check_image(&job.image) { return error_result(e.to_string()); } - let env = match job_env_with_defaults(job, &self.limits.for_job(job.memory_bytes)) { + let env = match job_env_with_defaults(job, &limits) { Ok(env) => env, Err(e) => return error_result(e.to_string()), }; @@ -680,7 +685,7 @@ impl BuiltinExecutor { env, run: job.run.clone(), network: job.network, - limits: self.limits.for_job(job.memory_bytes), + limits, idmap: self.idmap.clone(), }; // The request holds the secrets. It goes to the helper's stdin and nowhere else. @@ -996,6 +1001,7 @@ mod tests { logs: tx, cancel: CancellationToken::new(), oom: OomSink::default(), + memory_budget: None, }) .await; assert_eq!(result.outcome, Outcome::Success, "{result:?}"); diff --git a/crates/forge-runner/src/runner.rs b/crates/forge-runner/src/runner.rs index d185ab2..b86d8fb 100644 --- a/crates/forge-runner/src/runner.rs +++ b/crates/forge-runner/src/runner.rs @@ -407,6 +407,7 @@ impl Runner { logs: tx.clone(), cancel: job_cancel.clone(), oom: oom.clone(), + memory_budget: Some(self.memory.budget()), }) .await; workspace_dir = Some(dir); diff --git a/crates/forge-runner/tests/integration/builtin.rs b/crates/forge-runner/tests/integration/builtin.rs index c73964e..03baab8 100644 --- a/crates/forge-runner/tests/integration/builtin.rs +++ b/crates/forge-runner/tests/integration/builtin.rs @@ -105,6 +105,7 @@ async fn run_job( logs: tx, cancel, oom: forge_runner::oom::OomSink::default(), + memory_budget: None, }) .await; let logs = collector.await.expect("log collector");