From a7c271781e6810da234fe173bc55cd4f03c7d91c 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 08:24:54 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20a=20memory-pressure=20sig?= =?UTF-8?q?nal=20no=20longer=20shuts=20the=20runner's=20claim=20gate=20for?= =?UTF-8?q?=20good,=20and=20a=20requeued=20job=20no=20longer=20takes=20its?= =?UTF-8?q?=20killed=20run's=20cgroup;=20=F0=9F=92=84=20style:=20runner=20?= =?UTF-8?q?detail=20shows=20the=20online/offline=20dot=20like=20the=20list?= =?UTF-8?q?,=20restart=20asks=20with=20two=20explained=20choices?= 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/pressure.rs | 37 ++++++++++++---- crates/forge-web/src/i18n/admin.rs | 4 -- crates/forge-web/src/pages/admin_runners.rs | 23 +++++----- style/main.scss | 48 +++++++++++++++++++++ 4 files changed, 88 insertions(+), 24 deletions(-) diff --git a/crates/forge-runner/src/pressure.rs b/crates/forge-runner/src/pressure.rs index 4428293..4338611 100644 --- a/crates/forge-runner/src/pressure.rs +++ b/crates/forge-runner/src/pressure.rs @@ -50,6 +50,9 @@ const RECLAIM_ATTEMPTS: u32 = 4; /// How long a leftover job cgroup from an earlier runner gets to die at startup. const LEFTOVER_POLLS: u32 = 50; const LEFTOVER_POLL: Duration = Duration::from_millis(100); +/// How long a pressure signal holds the gate shut. Pressure is a moment, not a state: without a +/// later look the gate would stay shut when the last signal came after the last job ended. +const PRESSURE_COOLDOWN: Duration = Duration::from_secs(10); /// What woke the controller. #[derive(Clone, Copy, Debug, PartialEq, Eq)] @@ -116,8 +119,9 @@ pub fn pick_thaw(parked: &[Parked], unfrozen_running: usize, headroom: u64) -> O /// Whether the box is marked as under pressure after a pass. Pressure signals set it. Any other /// wake clears it, unless the box still sits at `memory.high`. -pub fn hot_after(cause: Cause, over_high: bool) -> bool { - cause == Cause::Pressure || over_high +pub fn hot_after(cause: Cause, over_high: bool, jobs: usize) -> bool { + // An empty box has nothing to hold back, so nothing keeps the runner from claiming. + jobs > 0 && (cause == Cause::Pressure || over_high) } /// The admission gate: the runner claims a new job only while it is open. @@ -387,9 +391,13 @@ impl Pressure { } async fn watch(self: Arc, mut watcher: Watcher, shutdown: CancellationToken) { + // Set while the gate is hot: when no new signal came by then, the box is looked at again. + let mut recheck: Option = None; loop { let cause = tokio::select! { () = shutdown.cancelled() => return, + () = tokio::time::sleep_until(recheck.unwrap_or_else(tokio::time::Instant::now)), + if recheck.is_some() => Cause::Jobs, cause = watcher.rx.recv() => { let Some(cause) = cause else { tracing::warn!("memory control stopped, the watcher thread ended"); @@ -403,6 +411,11 @@ impl Pressure { if let Err(e) = tokio::task::spawn_blocking(move || this.settle(cause)).await { tracing::error!("memory control pass panicked: {e}"); } + recheck = self + .lock() + .gate + .hot + .then(|| tokio::time::Instant::now() + PRESSURE_COOLDOWN); } } @@ -410,10 +423,14 @@ impl Pressure { /// `memory.high` for what runs now. Blocks, so it runs off the async runtime. fn settle(&self, cause: Cause) { let mut state = self.lock(); + // A job given back and claimed again keeps its id, and the killed run's cgroup can still + // be there, so a directory another entry holds is not this entry's. + let mut taken: Vec = state.entries.iter().filter_map(|e| e.dir.clone()).collect(); for entry in &mut state.entries { if entry.dir.is_none() - && let Some(dir) = find_job_dir(&self.dir, &entry.handle.id) + && let Some(dir) = find_job_dir(&self.dir, &entry.handle.id, &taken) { + taken.push(dir.clone()); // A real OOM then takes the whole job, not one of its processes. let _ = fs::write(dir.join("memory.oom.group"), "1"); entry.dir = Some(dir); @@ -458,7 +475,7 @@ impl Pressure { let over_high = high.is_some_and(|h| box_usage(&self.dir).is_some_and(|u| u >= h)); state.gate = Gate { frozen: state.entries.iter().filter(|e| e.frozen.is_some()).count(), - hot: hot_after(cause, over_high), + hot: hot_after(cause, over_high, state.entries.len()), }; drop(state); self.changed.notify_waiters(); @@ -587,13 +604,14 @@ fn give_back(entry: &mut Entry, why: &str) { // ----- cgroup files ----- /// The job's cgroup under the box: `forge-job--`. -fn find_job_dir(box_dir: &Path, job_id: &str) -> Option { +fn find_job_dir(box_dir: &Path, job_id: &str, taken: &[PathBuf]) -> Option { let prefix = format!("forge-job-{job_id}-"); fs::read_dir(box_dir) .ok()? .flatten() - .find(|e| e.file_name().to_string_lossy().starts_with(&prefix)) + .filter(|e| e.file_name().to_string_lossy().starts_with(&prefix)) .map(|e| e.path()) + .find(|path| !taken.contains(path)) } /// A single-number cgroup file. `None` when missing or `max`. @@ -925,9 +943,10 @@ mod tests { .open() ); // A pressure signal heats the box, a job event cools it unless it is still at high. - assert!(hot_after(Cause::Pressure, false)); - assert!(!hot_after(Cause::Jobs, false)); - assert!(hot_after(Cause::Jobs, true)); + assert!(hot_after(Cause::Pressure, false, 1)); + assert!(!hot_after(Cause::Jobs, false, 1)); + assert!(hot_after(Cause::Jobs, true, 1)); + assert!(!hot_after(Cause::Pressure, false, 0)); } /// A fake box: a temp dir with the files the controller reads. diff --git a/crates/forge-web/src/i18n/admin.rs b/crates/forge-web/src/i18n/admin.rs index 92e3e93..dbe2372 100644 --- a/crates/forge-web/src/i18n/admin.rs +++ b/crates/forge-web/src/i18n/admin.rs @@ -38,7 +38,6 @@ pub enum K { Disable, Disabled, Enable, - Enabled, ErrAccountCannotBeDeleted, ErrBackupsNotConfigured, ErrChooseSecurity, @@ -264,8 +263,6 @@ pub fn t(lang: Lang, key: K) -> &'static str { (Disabled, Tr) => "devre dışı", (Enable, En) => "Enable", (Enable, Tr) => "Etkinleştir", - (Enabled, En) => "enabled", - (Enabled, Tr) => "etkin", (ErrAccountCannotBeDeleted, En) => "this account cannot be deleted", (ErrAccountCannotBeDeleted, Tr) => "bu hesap silinemez", (ErrBackupsNotConfigured, En) => { @@ -841,7 +838,6 @@ mod tests { K::Disable, K::Disabled, K::Enable, - K::Enabled, K::ErrAccountCannotBeDeleted, K::ErrBackupsNotConfigured, K::ErrChooseSecurity, diff --git a/crates/forge-web/src/pages/admin_runners.rs b/crates/forge-web/src/pages/admin_runners.rs index 5f483b5..201c7f0 100644 --- a/crates/forge-web/src/pages/admin_runners.rs +++ b/crates/forge-web/src/pages/admin_runners.rs @@ -473,15 +473,20 @@ async fn restart_control(
(s(lang, "Restart", "Yeniden başlat"))
-

(s(lang, "Restart this runner? It stops taking jobs first.", "Bu çalıştırıcı yeniden başlatılsın mı? Önce iş almayı bırakır."))

-
+

(s(lang, "Restart this runner? It stops taking new jobs first.", "Bu çalıştırıcı yeniden başlatılsın mı? Önce yeni iş almayı bırakır."))

+ - - - + + +
-

(s(lang, "Restart now cancels the running jobs. They end as cancelled and can be run again.", "Şimdi yeniden başlat çalışan işleri iptal eder. İşler iptal edilmiş olarak biter ve yeniden çalıştırılabilir."))

} else { @@ -1159,11 +1164,7 @@ async fn runner_detail_view(

(runner.name.as_str())

- if row.disabled { - (g::t(lang, K::Disabled)) - } else { - (g::t(lang, K::Enabled)) - } + (row.state_text) if row.restart_pending.is_some() { (s(lang, "restart pending", "yeniden başlatma bekliyor")) } diff --git a/style/main.scss b/style/main.scss index a1e74a7..83150ae 100644 --- a/style/main.scss +++ b/style/main.scss @@ -7613,6 +7613,54 @@ button.ci-job-last { } } +// The detail head says what the list's dot says: online, offline or disabled, in the dot's words. +.runner-state { + display: inline-flex; + align-items: center; + gap: 6px; + color: var(--muted); + font-size: 0.9rem; +} + +// Restart asks with two choices, each a full-width row that says what it does to the running +// jobs, so the buttons never wrap into a ragged line and the note never trails under them. +.restart-choices { + display: flex; + flex-direction: column; + gap: 6px; +} + +.restart-choice { + display: flex; + flex-direction: column; + align-items: flex-start; + align-self: stretch; + gap: 2px; + height: auto; + padding: 8px 12px; + white-space: normal; + text-align: left; + + strong { + font-weight: 600; + } + + span { + color: var(--muted); + font-size: 0.8rem; + font-weight: 400; + } + + &.is-danger strong { + color: var(--danger); + } +} + +.restart-cancel { + align-self: flex-end; + margin-top: 4px; +} + .runner-head-actions { display: flex; flex-wrap: wrap;