forge
Explore
Log in

Don't you dare go Hollow

A memory-pressure signal no longer shuts the runner's claim gate for good, and a requeued job no longer takes its killed run's cgroup

Browse files at this commit

a7c271781e6810da234fe173bc55cd4f03c7d91cAhmet Kaan Gümüş and Claude Opus 5.5Parent: e21faf8
Some checks failed
Show checks
  • fix
    • a memory-pressure signal no longer shuts the runner's claim gate for good, and a requeued job no longer takes its killed run's cgroup
  • style
    • runner detail shows the online/offline dot like the list, restart asks with two explained choices
Show full message
🐛 fix: a memory-pressure signal no longer shuts the runner's claim gate for good, and a requeued job no longer takes its killed run's cgroup; 💄 style: runner detail shows the online/offline dot like the list, restart asks with two explained choices
crates/forge-runner/src/pressure.rsmodified+28 -9
@@ -50,6 +50,9 @@ const RECLAIM_ATTEMPTS: u32 = 4;
50 /// How long a leftover job cgroup from an earlier runner gets to die at startup.50 /// How long a leftover job cgroup from an earlier runner gets to die at startup.
51 const LEFTOVER_POLLS: u32 = 50;51 const LEFTOVER_POLLS: u32 = 50;
52 const LEFTOVER_POLL: Duration = Duration::from_millis(100);52 const LEFTOVER_POLL: Duration = Duration::from_millis(100);
53+/// How long a pressure signal holds the gate shut. Pressure is a moment, not a state: without a
54+/// later look the gate would stay shut when the last signal came after the last job ended.
55+const PRESSURE_COOLDOWN: Duration = Duration::from_secs(10);
53 56
54 /// What woke the controller.57 /// What woke the controller.
55 #[derive(Clone, Copy, Debug, PartialEq, Eq)]58 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
@@ -116,8 +119,9 @@ pub fn pick_thaw(parked: &[Parked], unfrozen_running: usize, headroom: u64) -> O
116 119
117 /// Whether the box is marked as under pressure after a pass. Pressure signals set it. Any other120 /// Whether the box is marked as under pressure after a pass. Pressure signals set it. Any other
118 /// wake clears it, unless the box still sits at `memory.high`.121 /// wake clears it, unless the box still sits at `memory.high`.
119-pub fn hot_after(cause: Cause, over_high: bool) -> bool {122+pub fn hot_after(cause: Cause, over_high: bool, jobs: usize) -> bool {
120- cause == Cause::Pressure || over_high123+ // An empty box has nothing to hold back, so nothing keeps the runner from claiming.
124+ jobs > 0 && (cause == Cause::Pressure || over_high)
121 }125 }
122 126
123 /// The admission gate: the runner claims a new job only while it is open.127 /// The admission gate: the runner claims a new job only while it is open.
@@ -387,9 +391,13 @@ impl Pressure {
387 }391 }
388 392
389 async fn watch(self: Arc<Self>, mut watcher: Watcher, shutdown: CancellationToken) {393 async fn watch(self: Arc<Self>, mut watcher: Watcher, shutdown: CancellationToken) {
394+ // Set while the gate is hot: when no new signal came by then, the box is looked at again.
395+ let mut recheck: Option<tokio::time::Instant> = None;
390 loop {396 loop {
391 let cause = tokio::select! {397 let cause = tokio::select! {
392 () = shutdown.cancelled() => return,398 () = shutdown.cancelled() => return,
399+ () = tokio::time::sleep_until(recheck.unwrap_or_else(tokio::time::Instant::now)),
400+ if recheck.is_some() => Cause::Jobs,
393 cause = watcher.rx.recv() => {401 cause = watcher.rx.recv() => {
394 let Some(cause) = cause else {402 let Some(cause) = cause else {
395 tracing::warn!("memory control stopped, the watcher thread ended");403 tracing::warn!("memory control stopped, the watcher thread ended");
@@ -403,6 +411,11 @@ impl Pressure {
403 if let Err(e) = tokio::task::spawn_blocking(move || this.settle(cause)).await {411 if let Err(e) = tokio::task::spawn_blocking(move || this.settle(cause)).await {
404 tracing::error!("memory control pass panicked: {e}");412 tracing::error!("memory control pass panicked: {e}");
405 }413 }
414+ recheck = self
415+ .lock()
416+ .gate
417+ .hot
418+ .then(|| tokio::time::Instant::now() + PRESSURE_COOLDOWN);
406 }419 }
407 }420 }
408 421
@@ -410,10 +423,14 @@ impl Pressure {
410 /// `memory.high` for what runs now. Blocks, so it runs off the async runtime.423 /// `memory.high` for what runs now. Blocks, so it runs off the async runtime.
411 fn settle(&self, cause: Cause) {424 fn settle(&self, cause: Cause) {
412 let mut state = self.lock();425 let mut state = self.lock();
426+ // A job given back and claimed again keeps its id, and the killed run's cgroup can still
427+ // be there, so a directory another entry holds is not this entry's.
428+ let mut taken: Vec<PathBuf> = state.entries.iter().filter_map(|e| e.dir.clone()).collect();
413 for entry in &mut state.entries {429 for entry in &mut state.entries {
414 if entry.dir.is_none()430 if entry.dir.is_none()
415- && let Some(dir) = find_job_dir(&self.dir, &entry.handle.id)431+ && let Some(dir) = find_job_dir(&self.dir, &entry.handle.id, &taken)
416 {432 {
433+ taken.push(dir.clone());
417 // A real OOM then takes the whole job, not one of its processes.434 // A real OOM then takes the whole job, not one of its processes.
418 let _ = fs::write(dir.join("memory.oom.group"), "1");435 let _ = fs::write(dir.join("memory.oom.group"), "1");
419 entry.dir = Some(dir);436 entry.dir = Some(dir);
@@ -458,7 +475,7 @@ impl Pressure {
458 let over_high = high.is_some_and(|h| box_usage(&self.dir).is_some_and(|u| u >= h));475 let over_high = high.is_some_and(|h| box_usage(&self.dir).is_some_and(|u| u >= h));
459 state.gate = Gate {476 state.gate = Gate {
460 frozen: state.entries.iter().filter(|e| e.frozen.is_some()).count(),477 frozen: state.entries.iter().filter(|e| e.frozen.is_some()).count(),
461- hot: hot_after(cause, over_high),478+ hot: hot_after(cause, over_high, state.entries.len()),
462 };479 };
463 drop(state);480 drop(state);
464 self.changed.notify_waiters();481 self.changed.notify_waiters();
@@ -587,13 +604,14 @@ fn give_back(entry: &mut Entry, why: &str) {
587 // ----- cgroup files -----604 // ----- cgroup files -----
588 605
589 /// The job's cgroup under the box: `forge-job-<id>-<pid>`.606 /// The job's cgroup under the box: `forge-job-<id>-<pid>`.
590-fn find_job_dir(box_dir: &Path, job_id: &str) -> Option<PathBuf> {607+fn find_job_dir(box_dir: &Path, job_id: &str, taken: &[PathBuf]) -> Option<PathBuf> {
591 let prefix = format!("forge-job-{job_id}-");608 let prefix = format!("forge-job-{job_id}-");
592 fs::read_dir(box_dir)609 fs::read_dir(box_dir)
593 .ok()?610 .ok()?
594 .flatten()611 .flatten()
595- .find(|e| e.file_name().to_string_lossy().starts_with(&prefix))612+ .filter(|e| e.file_name().to_string_lossy().starts_with(&prefix))
596 .map(|e| e.path())613 .map(|e| e.path())
614+ .find(|path| !taken.contains(path))
597 }615 }
598 616
599 /// A single-number cgroup file. `None` when missing or `max`.617 /// A single-number cgroup file. `None` when missing or `max`.
@@ -925,9 +943,10 @@ mod tests {
925 .open()943 .open()
926 );944 );
927 // A pressure signal heats the box, a job event cools it unless it is still at high.945 // A pressure signal heats the box, a job event cools it unless it is still at high.
928- assert!(hot_after(Cause::Pressure, false));946+ assert!(hot_after(Cause::Pressure, false, 1));
929- assert!(!hot_after(Cause::Jobs, false));947+ assert!(!hot_after(Cause::Jobs, false, 1));
930- assert!(hot_after(Cause::Jobs, true));948+ assert!(hot_after(Cause::Jobs, true, 1));
949+ assert!(!hot_after(Cause::Pressure, false, 0));
931 }950 }
932 951
933 /// A fake box: a temp dir with the files the controller reads.952 /// A fake box: a temp dir with the files the controller reads.
crates/forge-web/src/i18n/admin.rsmodified+0 -4
@@ -38,7 +38,6 @@ pub enum K {
38 Disable,38 Disable,
39 Disabled,39 Disabled,
40 Enable,40 Enable,
41- Enabled,
42 ErrAccountCannotBeDeleted,41 ErrAccountCannotBeDeleted,
43 ErrBackupsNotConfigured,42 ErrBackupsNotConfigured,
44 ErrChooseSecurity,43 ErrChooseSecurity,
@@ -264,8 +263,6 @@ pub fn t(lang: Lang, key: K) -> &'static str {
264 (Disabled, Tr) => "devre dışı",263 (Disabled, Tr) => "devre dışı",
265 (Enable, En) => "Enable",264 (Enable, En) => "Enable",
266 (Enable, Tr) => "Etkinleştir",265 (Enable, Tr) => "Etkinleştir",
267- (Enabled, En) => "enabled",
268- (Enabled, Tr) => "etkin",
269 (ErrAccountCannotBeDeleted, En) => "this account cannot be deleted",266 (ErrAccountCannotBeDeleted, En) => "this account cannot be deleted",
270 (ErrAccountCannotBeDeleted, Tr) => "bu hesap silinemez",267 (ErrAccountCannotBeDeleted, Tr) => "bu hesap silinemez",
271 (ErrBackupsNotConfigured, En) => {268 (ErrBackupsNotConfigured, En) => {
@@ -841,7 +838,6 @@ mod tests {
841 K::Disable,838 K::Disable,
842 K::Disabled,839 K::Disabled,
843 K::Enable,840 K::Enable,
844- K::Enabled,
845 K::ErrAccountCannotBeDeleted,841 K::ErrAccountCannotBeDeleted,
846 K::ErrBackupsNotConfigured,842 K::ErrBackupsNotConfigured,
847 K::ErrChooseSecurity,843 K::ErrChooseSecurity,
crates/forge-web/src/pages/admin_runners.rsmodified+12 -11
@@ -473,15 +473,20 @@ async fn restart_control(
473 <details class="confirm-inline">473 <details class="confirm-inline">
474 <summary class="button">(s(lang, "Restart", "Yeniden başlat"))</summary>474 <summary class="button">(s(lang, "Restart", "Yeniden başlat"))</summary>
475 <div class="confirm-pop">475 <div class="confirm-pop">
476- <p>(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."))</p>476+ <p>(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."))</p>
477- <form method="post" action=(action)>477+ <form method="post" action=(action) class="restart-choices">
478 <input type="hidden" name="csrf" value=(csrf)>478 <input type="hidden" name="csrf" value=(csrf)>
479 <input type="hidden" name="back" value=(back)>479 <input type="hidden" name="back" value=(back)>
480- <button type="submit" name="mode" value="drain" class="primary">(s(lang, "Restart after current jobs", "Mevcut işlerden sonra yeniden başlat"))</button>480+ <button type="submit" name="mode" value="drain" class="restart-choice">
481- <button type="submit" name="mode" value="now" class="danger">(s(lang, "Restart now", "Şimdi yeniden başlat"))</button>481+ <strong>(s(lang, "Restart after current jobs", "Mevcut işlerden sonra yeniden başlat"))</strong>
482- <button type="button" data-close-details="">(s(lang, "Cancel", "Vazgeç"))</button>482+ <span>(s(lang, "The running jobs finish, then it restarts.", "Çalışan işler biter, sonra yeniden başlar."))</span>
483+ </button>
484+ <button type="submit" name="mode" value="now" class="restart-choice is-danger">
485+ <strong>(s(lang, "Restart now", "Şimdi yeniden başlat"))</strong>
486+ <span>(s(lang, "The running jobs end as cancelled and can be run again.", "Çalışan işler iptal edilmiş olarak biter ve yeniden çalıştırılabilir."))</span>
487+ </button>
488+ <button type="button" class="restart-cancel" data-close-details="">(s(lang, "Cancel", "Vazgeç"))</button>
483 </form>489 </form>
484- <p class="muted small">(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."))</p>
485 </div>490 </div>
486 </details>491 </details>
487 } else {492 } else {
@@ -1159,11 +1164,7 @@ async fn runner_detail_view(
1159 <section class="page-head">1164 <section class="page-head">
1160 <div class="runner-head">1165 <div class="runner-head">
1161 <h1>(runner.name.as_str())</h1>1166 <h1>(runner.name.as_str())</h1>
1162- if row.disabled {1167+ <span class="runner-state"><span class=(row.dot_class)></span>(row.state_text)</span>
1163- <span class="ci-state runner-disabled">(g::t(lang, K::Disabled))</span>
1164- } else {
1165- <span class="ci-state ci-success">(g::t(lang, K::Enabled))</span>
1166- }
1167 if row.restart_pending.is_some() {1168 if row.restart_pending.is_some() {
1168 <span class="ci-state runner-disabled">(s(lang, "restart pending", "yeniden başlatma bekliyor"))</span>1169 <span class="ci-state runner-disabled">(s(lang, "restart pending", "yeniden başlatma bekliyor"))</span>
1169 }1170 }
style/main.scssmodified+48 -0
@@ -7613,6 +7613,54 @@ button.ci-job-last {
7613 }7613 }
7614 }7614 }
7615 7615
7616+// The detail head says what the list's dot says: online, offline or disabled, in the dot's words.
7617+.runner-state {
7618+ display: inline-flex;
7619+ align-items: center;
7620+ gap: 6px;
7621+ color: var(--muted);
7622+ font-size: 0.9rem;
7623+}
7624+
7625+// Restart asks with two choices, each a full-width row that says what it does to the running
7626+// jobs, so the buttons never wrap into a ragged line and the note never trails under them.
7627+.restart-choices {
7628+ display: flex;
7629+ flex-direction: column;
7630+ gap: 6px;
7631+}
7632+
7633+.restart-choice {
7634+ display: flex;
7635+ flex-direction: column;
7636+ align-items: flex-start;
7637+ align-self: stretch;
7638+ gap: 2px;
7639+ height: auto;
7640+ padding: 8px 12px;
7641+ white-space: normal;
7642+ text-align: left;
7643+
7644+ strong {
7645+ font-weight: 600;
7646+ }
7647+
7648+ span {
7649+ color: var(--muted);
7650+ font-size: 0.8rem;
7651+ font-weight: 400;
7652+ }
7653+
7654+ &.is-danger strong {
7655+ color: var(--danger);
7656+ }
7657+}
7658+
7659+.restart-cancel {
7660+ align-self: flex-end;
7661+ margin-top: 4px;
7662+}
7663+
7616 .runner-head-actions {7664 .runner-head-actions {
7617 display: flex;7665 display: flex;
7618 flex-wrap: wrap;7666 flex-wrap: wrap;