From cb40525f5a02e9e57bdecd975bda7ad5f4c81e1f Mon Sep 17 00:00:00 2001 From: Michel Blaauw Date: Wed, 25 Nov 2026 14:45:53 +0100 Subject: [PATCH] fix(launcher): a container that never ran keeps its retry (#399) Image pull and container config errors with no earlier termination (ImagePullBackOff, ErrImagePull, InvalidImageName, CreateContainerConfigError, CreateContainerError, RunContainerError) were mapped to worker_exited, so the API failed the launch's executions without retry and ended the team run, although nothing ran. - orbit-contracts: new WorkerTerminationReason::WorkerDidNotStart ("worker_did_not_start", audit worker.did_not_start) and ends_without_retry(), false only for it. - launcher mapping: such waiting errors without lastState now map to worker_did_not_start; CrashLoopBackOff and errors after a run keep their earlier cause. In a Deployment, a terminal pod (an evicted pod stays listed as Failed) no longer decides the status while a replacement is live. - API: for worker_did_not_start only executions still dispatched fail, marked retryable, and report_ended_execution keeps the team poller's queue retry. The legacy OOM text fallback matches "OOM"/"OOMKilled" as whole words, not "room" or "zoom". - Docs (launcher table, runtime contract, events, guides) and the execution page message describe the new reason. Co-Authored-By: Claude Opus 5.5 --- apps/web/app/executions/[id]/page.tsx | 2 +- changelog.d/399.fixed.md | 8 + crates/orbit-api/src/background.rs | 8 +- .../orbit-api/src/handlers/worker_launches.rs | 46 +++++- crates/orbit-contracts/src/worker.rs | 28 ++++ docs/architecture/events.md | 4 +- docs/architecture/runtime-contract.md | 7 +- docs/development/kubernetes-launcher.md | 11 +- docs/guide/executions.md | 4 +- docs/guide/worker-profiles.md | 4 +- services/launcher/src/mapping.rs | 138 +++++++++++++++++- 11 files changed, 237 insertions(+), 23 deletions(-) create mode 100644 changelog.d/399.fixed.md diff --git a/apps/web/app/executions/[id]/page.tsx b/apps/web/app/executions/[id]/page.tsx index 4ff8a345..d3a91f71 100644 --- a/apps/web/app/executions/[id]/page.tsx +++ b/apps/web/app/executions/[id]/page.tsx @@ -56,7 +56,7 @@ const WORKER_TERMINATION_CODES = ["worker_oom", "worker_evicted", "worker_exited const PLATFORM_ERROR_TEXT = new Map([ [ "worker_did_not_start", - "A worker took this run but never started it, so ORBIT ended it. This usually means the worker could not read the run, for example because it is older than the platform. Its logs in Workers say more.", + "A worker took this run but never started it, so ORBIT ended it. This usually means the worker could not read the run, for example because it is older than the platform, or that its container never started, for example because its image could not be pulled. Nothing ran, so the run can be retried. Its logs and launches in Workers say more.", ], [ "worker_oom", diff --git a/changelog.d/399.fixed.md b/changelog.d/399.fixed.md new file mode 100644 index 00000000..43e2e179 --- /dev/null +++ b/changelog.d/399.fixed.md @@ -0,0 +1,8 @@ +- A launched worker whose container never ran (image pull or container config errors such as + `ImagePullBackOff`, `ErrImagePull` or `CreateContainerConfigError` with no earlier + termination) now ends as `worker_did_not_start`: only runs still `dispatched` to it fail, + marked retryable, and team queue items keep their retry. Previously these ended as + `worker_exited` with no retry although nothing ran. A Deployment whose evicted pod is still + listed next to a live replacement now follows the replacement instead of failing the + launch, and the OOM fallback for older launchers no longer matches words such as "room" + (#399). diff --git a/crates/orbit-api/src/background.rs b/crates/orbit-api/src/background.rs index f54c8462..a8a9f2a5 100644 --- a/crates/orbit-api/src/background.rs +++ b/crates/orbit-api/src/background.rs @@ -876,10 +876,12 @@ pub(crate) async fn report_ended_execution( // A worker that vanished (or stopped reporting a still-live harness) may have caused // side effects, so its team run must not be auto-retried. The same holds for a worker // terminated by the runtime (OOM, eviction, exit or node loss). Other endings keep the - // normal team poller behaviour, including queue retries for runs that never started. + // normal team poller behaviour, including queue retries for runs that never started + // (`worker_did_not_start`, from the reaper or from a container that never started). let code = data.get("code").and_then(serde_json::Value::as_str); - let worker_terminated = - code.is_some_and(|code| orbit_contracts::WorkerTerminationReason::parse(code).is_some()); + let worker_terminated = code + .and_then(orbit_contracts::WorkerTerminationReason::parse) + .is_some_and(orbit_contracts::WorkerTerminationReason::ends_without_retry); if worker_terminated || matches!(code, Some("harness_unresponsive")) { if let Err(error) = crate::handlers::teams::fail_team_run_for_execution(state, execution).await diff --git a/crates/orbit-api/src/handlers/worker_launches.rs b/crates/orbit-api/src/handlers/worker_launches.rs index 247e8b9c..f4adb6eb 100644 --- a/crates/orbit-api/src/handlers/worker_launches.rs +++ b/crates/orbit-api/src/handlers/worker_launches.rs @@ -175,10 +175,7 @@ fn launch_termination( if let Some(termination) = status.termination.clone() { return Some(termination); } - let oom = status - .error - .as_deref() - .is_some_and(|error| error.to_lowercase().contains("oom")); + let oom = status.error.as_deref().is_some_and(mentions_oom); if !oom { return None; } @@ -194,9 +191,19 @@ fn launch_termination( )) } +/// True when a launcher error names an OOM kill as a word ("OOM", "OOMKilled"), not as part +/// of another word such as "room" or "zoom". +fn mentions_oom(error: &str) -> bool { + error + .split(|c: char| !c.is_ascii_alphanumeric()) + .any(|word| word.eq_ignore_ascii_case("oom") || word.eq_ignore_ascii_case("oomkilled")) +} + /// A worker terminated by the runtime (OOM, eviction, exit or node loss) cannot report its /// own execution failure. Fail every in-flight execution on that worker with the structured -/// reason, terminate the team step/run/queue without auto-retry, and audit the cause. +/// reason, terminate the team step/run/queue without auto-retry, and audit the cause. A +/// container that never started (`worker_did_not_start`) only fails runs still `dispatched` +/// to it, marked retryable, so the team poller keeps its normal queue retry. async fn fail_worker_executions( state: &AppState, launch: &WorkerLaunch, @@ -216,6 +223,16 @@ async fn fail_worker_executions( return; } }; + // A container that never started ran nothing: only runs still waiting for it end, and + // they keep their retry. A run already running on this worker id is left to the + // liveness reaper, since some other container must have started it. + let never_started = !termination.reason.ends_without_retry(); + let executions: Vec<_> = executions + .into_iter() + .filter(|execution| { + !never_started || execution.status == orbit_domain::ExecutionStatus::Dispatched.as_str() + }) + .collect(); let message = launch .error .clone() @@ -230,8 +247,9 @@ async fn fail_worker_executions( object.insert("workerId".into(), serde_json::json!(worker_id)); object.insert("profileId".into(), serde_json::json!(launch.profile_id)); object.insert("launchId".into(), serde_json::json!(launch.id)); - // Side effects may already have happened; an operator must decide to rerun. - object.insert("retryable".into(), serde_json::json!(false)); + // Side effects may already have happened; an operator must decide to rerun. A + // container that never started ran nothing, so its runs may be retried. + object.insert("retryable".into(), serde_json::json!(never_started)); } for execution in executions { let finished = state @@ -750,3 +768,17 @@ mod worker_id_tests { assert!(launch_worker_id(a).len() <= 63); } } + +#[cfg(test)] +mod tests { + use super::mentions_oom; + + #[test] + fn oom_fallback_matches_whole_words_only() { + assert!(mentions_oom("worker container was OOMKilled")); + assert!(mentions_oom("killed: oom (memory limit 512Mi)")); + assert!(!mentions_oom("no room left on device")); + assert!(!mentions_oom("zoom service unavailable")); + assert!(!mentions_oom("ImagePullBackOff")); + } +} diff --git a/crates/orbit-contracts/src/worker.rs b/crates/orbit-contracts/src/worker.rs index 503ac7c9..9332d52c 100644 --- a/crates/orbit-contracts/src/worker.rs +++ b/crates/orbit-contracts/src/worker.rs @@ -17,6 +17,9 @@ pub enum WorkerTerminationReason { WorkerExited, /// The node/pod disappeared or the cause could not be determined. WorkerLost, + /// The container never started (image pull or container config error with no earlier + /// termination). Nothing ran, so the work may be retried. + WorkerDidNotStart, } impl WorkerTerminationReason { @@ -25,6 +28,7 @@ impl WorkerTerminationReason { "worker_evicted", "worker_exited", "worker_lost", + "worker_did_not_start", ]; pub fn as_str(self) -> &'static str { @@ -33,6 +37,7 @@ impl WorkerTerminationReason { Self::WorkerEvicted => "worker_evicted", Self::WorkerExited => "worker_exited", Self::WorkerLost => "worker_lost", + Self::WorkerDidNotStart => "worker_did_not_start", } } @@ -42,6 +47,7 @@ impl WorkerTerminationReason { "worker_evicted" => Some(Self::WorkerEvicted), "worker_exited" => Some(Self::WorkerExited), "worker_lost" => Some(Self::WorkerLost), + "worker_did_not_start" => Some(Self::WorkerDidNotStart), _ => None, } } @@ -53,8 +59,15 @@ impl WorkerTerminationReason { Self::WorkerEvicted => "worker.evicted", Self::WorkerExited => "worker.exited", Self::WorkerLost => "execution.worker_lost", + Self::WorkerDidNotStart => "worker.did_not_start", } } + + /// Whether work on a worker that ended this way may have had side effects, so the team + /// run must end without an automatic retry. A container that never started ran nothing. + pub fn ends_without_retry(self) -> bool { + !matches!(self, Self::WorkerDidNotStart) + } } /// Structured, non-secret termination information reported by the launcher. @@ -105,6 +118,9 @@ impl WorkerTermination { WorkerTerminationReason::WorkerLost => { format!("{identity} was lost; the run outcome is unknown") } + WorkerTerminationReason::WorkerDidNotStart => { + format!("{identity} never started its container, so nothing ran") + } }; if let Some(detail) = self.detail.as_deref().filter(|value| !value.is_empty()) { message.push_str(&format!(" ({detail})")); @@ -126,6 +142,18 @@ mod tests { assert!(WorkerTerminationReason::parse("oom").is_none()); } + #[test] + fn only_a_worker_that_never_started_allows_a_retry() { + for code in WorkerTerminationReason::ALL { + let reason = WorkerTerminationReason::parse(code).unwrap(); + assert_eq!( + reason.ends_without_retry(), + reason != WorkerTerminationReason::WorkerDidNotStart, + "{code}" + ); + } + } + #[test] fn termination_json_is_camel_case_and_has_no_env() { let termination = WorkerTermination { diff --git a/docs/architecture/events.md b/docs/architecture/events.md index 0988d3b4..7fc92388 100644 --- a/docs/architecture/events.md +++ b/docs/architecture/events.md @@ -117,7 +117,9 @@ a launch comes back `failed` with a structured `termination` (see on that worker becomes `failed` with `worker_oom`, `worker_evicted`, `worker_exited` or `worker_lost`, carrying the pod/container name, restart count, exit code and termination time. Each gets an `error` event, an `orbit.execution.updated` message and an audit entry; -the team step, run and queue item become terminal with no automatic rerun. +the team step, run and queue item become terminal with no automatic rerun. A container that +never started (`worker_did_not_start`) only fails the executions still `dispatched` to it, +marked retryable, and the team poller keeps its normal queue retry. ## Scheduling and dispatch diff --git a/docs/architecture/runtime-contract.md b/docs/architecture/runtime-contract.md index 35ed83a7..40b52d2e 100644 --- a/docs/architecture/runtime-contract.md +++ b/docs/architecture/runtime-contract.md @@ -124,7 +124,7 @@ cause instead. `GET /launches/{id}` returns a `termination` object | Field | Meaning | |---|---| -| `reason` | `worker_oom`, `worker_evicted`, `worker_exited` or `worker_lost` | +| `reason` | `worker_oom`, `worker_evicted`, `worker_exited`, `worker_lost` or `worker_did_not_start` | | `workerName` | pod name (Kubernetes) or container name (Docker) | | `restartCount` | container restart count, when the runtime reports it | | `terminatedAt` | RFC 3339 finish time reported by the runtime | @@ -140,7 +140,10 @@ flight on that worker (`dispatched`, `running`, `awaiting_approval`) with the re `error.code`, appends an `error` execution event, writes an audit entry (`worker.oom_killed`, `worker.evicted`, `worker.exited`, `execution.worker_lost`) and ends the team step, run and queue item without an automatic rerun: side effects may already have -happened, so a person decides whether to run it again. +happened, so a person decides whether to run it again. `worker_did_not_start` (an image pull +or container config error before the container ever ran) is the exception: it fails only the +executions still `dispatched` to that worker, marked `retryable: true`, audits +`worker.did_not_start`, and leaves the team poller's normal queue retry in place. ## Inputs diff --git a/docs/development/kubernetes-launcher.md b/docs/development/kubernetes-launcher.md index 14fd298c..11b8808a 100644 --- a/docs/development/kubernetes-launcher.md +++ b/docs/development/kubernetes-launcher.md @@ -172,7 +172,9 @@ Status is mapped by pure functions in `services/launcher/src/mapping.rs` from | Exit code 137 without `OOMKilled` | `failed` | SIGKILL, explicitly not OOM | `worker_exited` | | Any other non-zero exit | `failed` | exit code + reason | `worker_exited` | | Deployment pod running after an earlier OOM restart | `running` | hint: OOMKilled earlier, restart count | none (still live) | -| CrashLoopBackOff, ImagePullBackOff, ErrImagePull, InvalidImageName, CreateContainerConfigError, CreateContainerError, RunContainerError | `failed` | reason, restart count, last termination | from `lastState.terminated`, else `worker_exited` | +| CrashLoopBackOff, or any waiting error below after the container already ran | `failed` | reason, restart count, last termination | from `lastState.terminated`, else `worker_exited` | +| ImagePullBackOff, ErrImagePull, InvalidImageName, CreateContainerConfigError, CreateContainerError, RunContainerError with no `lastState` (the container never ran) | `failed` | reason, restart count, waiting message | `worker_did_not_start` | +| Deployment with a terminal pod (for example evicted, phase `Failed`) and a live replacement pod | from the replacement (`running` / `starting`) | none | none | | ContainerCreating / pending / not ready | `starting` | none | none | | Job `Complete` | `stopped` | none | none | | Job `Failed` condition (e.g. DeadlineExceeded, BackoffLimitExceeded) | `failed` | condition reason + message, container cause | container cause, else `Evicted` → `worker_evicted`, `DeadlineExceeded`/`BackoffLimitExceeded` → `worker_exited`, otherwise `worker_lost` | @@ -186,8 +188,11 @@ A `failed` mapping also carries a structured `termination` object container name), `restartCount`, `terminatedAt`, `exitCode` and a short `detail` such as `OOMKilled`. It never contains env, command lines or logs. The API turns it into the execution error (`data.code` = the reason), an `error` execution event, an audit entry, and -a terminal team step/run/queue item with no automatic rerun. Older launchers that only send -a human-readable `error` containing "OOM" are still understood as `worker_oom`. +a terminal team step/run/queue item with no automatic rerun. The exception is +`worker_did_not_start`: nothing ran, so only runs still `dispatched` to that worker end, marked +retryable, and the team poller keeps its normal queue retry. Older launchers that only send +a human-readable `error` naming "OOM" or "OOMKilled" as a word are still understood as +`worker_oom` (text such as "room" does not match). The API only refreshes launches that are `pending`, `starting` or `running`, so a terminal status it has already stored (for example `failed`) is never overwritten by a later diff --git a/docs/guide/executions.md b/docs/guide/executions.md index ff29e0b2..cf722e0b 100644 --- a/docs/guide/executions.md +++ b/docs/guide/executions.md @@ -89,7 +89,9 @@ ended is expired and cannot be decided (409). - `worker_did_not_start` (a `failed` run): a worker took the run but never started it. ORBIT ends it after 10 minutes without activity, or one minute after you cancel it. The worker's logs on the Workers page usually say why, for example a worker older than the - platform. + platform. A launched worker whose container never started (its image could not be pulled, + or its container config is invalid) ends the runs waiting for it the same way straight + away. Nothing ran, so a team queue item is retried as usual. When the runtime reports them, a run ended by `worker_oom`, `worker_evicted`, `worker_exited` or `worker_lost` also shows the worker/pod name, exit code, restart count and termination diff --git a/docs/guide/worker-profiles.md b/docs/guide/worker-profiles.md index b9ba803e..2c1ddba7 100644 --- a/docs/guide/worker-profiles.md +++ b/docs/guide/worker-profiles.md @@ -114,7 +114,9 @@ stopping profiles needs `settings:write`. - Stop deletes the workload; logs are read by the `orbit.launch-id` label - A worker stopped by the runtime is surfaced as a failed launch with a structured reason: `worker_oom` (OOMKilled, with the memory limit), `worker_evicted` (node pressure or drain), - `worker_exited` (non-zero exit) or `worker_lost` (node/pod gone). Exit code 137 alone is + `worker_exited` (non-zero exit), `worker_lost` (node/pod gone) or `worker_did_not_start` + (image pull or container config error before the container ever ran; its waiting runs + keep their retry). Exit code 137 alone is SIGKILL, not OOM. Every in-flight execution on that worker fails with the same reason, pod name, restart count, exit code and termination time; team runs are not retried automatically. The API polls live launches every 15 seconds, so this happens even when diff --git a/services/launcher/src/mapping.rs b/services/launcher/src/mapping.rs index 4f77735b..48209202 100644 --- a/services/launcher/src/mapping.rs +++ b/services/launcher/src/mapping.rs @@ -7,7 +7,11 @@ //! - A container is "OOM" only when the kubelet says `reason == "OOMKilled"`. Exit code 137 //! alone is SIGKILL (cancel, eviction, `kubectl delete`) and is reported as such. //! - Waiting reasons that Kubernetes retries forever (CrashLoopBackOff, ImagePullBackOff, ...) -//! are reported as `failed` with a message instead of staying `starting`. +//! are reported as `failed` with a message instead of staying `starting`. When the +//! container never ran (no `lastState`), the cause is `worker_did_not_start`, which keeps +//! the run's retry; only a container that ran and then stopped ends work without retry. +//! - In a Deployment, a terminal pod (evicted or otherwise `Failed`) does not decide the +//! status while a replacement pod is still live. use orbit_contracts::{WorkerTermination, WorkerTerminationReason}; use serde_json::Value; @@ -125,6 +129,11 @@ fn is_evicted(pod: &Value, terminated: Option<&Value>) -> bool { || terminated.is_some_and(|value| str_at(value, "/reason") == Some("Evicted")) } +/// A pod that will never run again: phase `Failed` or `Succeeded`. +fn is_terminal_pod(pod: &Value) -> bool { + matches!(str_at(pod, "/status/phase"), Some("Failed" | "Succeeded")) +} + fn is_node_loss(pod: &Value) -> bool { str_at(pod, "/status/phase") == Some("Unknown") || matches!( @@ -233,10 +242,17 @@ fn map_pod(pod: &Value, restart_always: bool) -> Mapped { } else if let Some(detail) = str_at(waiting, "/message") { message = format!("{message}: {detail}"); } + // With no earlier termination the container never ran (image pull or + // config error); CrashLoopBackOff always means it ran and stopped. + let never_ran_reason = if reason == "CrashLoopBackOff" { + WorkerTerminationReason::WorkerExited + } else { + WorkerTerminationReason::WorkerDidNotStart + }; let termination = match last { Some(last) => container_termination(pod, status, last), None => termination( - WorkerTerminationReason::WorkerExited, + never_ran_reason, pod_name(pod), Some(restarts(status)), None, @@ -388,10 +404,18 @@ pub fn map_kubernetes(items: &[Value]) -> Mapped { } if has_deployment { // Ignore pods that are being replaced. - let mut best = Mapped::new("starting", None); - for pod in pods + let current: Vec<&Value> = pods .iter() + .copied() .filter(|p| p.pointer("/metadata/deletionTimestamp").is_none()) + .collect(); + // A terminal pod (an evicted pod stays listed as `Failed`) does not decide the + // status while the ReplicaSet's replacement is live. + let replacement_live = current.iter().any(|pod| !is_terminal_pod(pod)); + let mut best = Mapped::new("starting", None); + for pod in current + .into_iter() + .filter(|pod| !replacement_live || !is_terminal_pod(pod)) { let mapped = map_pod(pod, true); match mapped.status { @@ -645,6 +669,112 @@ mod tests { assert!(mapped.error.unwrap().contains("ImagePullBackOff")); } + #[test] + fn waiting_errors_without_last_state_did_not_start() { + for reason in [ + "ImagePullBackOff", + "ErrImagePull", + "InvalidImageName", + "CreateContainerConfigError", + "CreateContainerError", + "RunContainerError", + ] { + let items = [ + deployment(), + pod(json!({ "restartCount": 0, "state": { "waiting": { "reason": reason } } })), + ]; + let mapped = map_kubernetes(&items); + assert_eq!(mapped.status, "failed", "{reason}"); + let termination = mapped.termination.unwrap(); + assert_eq!( + termination.reason, + WorkerTerminationReason::WorkerDidNotStart, + "{reason}" + ); + assert!(!termination.reason.ends_without_retry(), "{reason}"); + assert_eq!(termination.detail.as_deref(), Some(reason)); + } + } + + #[test] + fn crash_loop_and_waiting_after_a_run_end_without_retry() { + let crash = [ + deployment(), + pod( + json!({ "restartCount": 3, "state": { "waiting": { "reason": "CrashLoopBackOff" } } }), + ), + ]; + let termination = map_kubernetes(&crash).termination.unwrap(); + assert_eq!(termination.reason, WorkerTerminationReason::WorkerExited); + assert!(termination.reason.ends_without_retry()); + + // An image pull error after the container already ran keeps the earlier cause. + let after_run = [ + deployment(), + pod(json!({ + "restartCount": 1, + "state": { "waiting": { "reason": "ImagePullBackOff" } }, + "lastState": { "terminated": { "reason": "Error", "exitCode": 1 } } + })), + ]; + let termination = map_kubernetes(&after_run).termination.unwrap(); + assert_eq!(termination.reason, WorkerTerminationReason::WorkerExited); + } + + fn evicted_deployment_pod() -> Value { + let mut pod = pod(json!({ + "state": { "terminated": { "reason": "Evicted", "exitCode": 137 } } + })); + pod["metadata"]["name"] = json!("orbit-worker-1234-old"); + pod["status"]["phase"] = json!("Failed"); + pod["status"]["reason"] = json!("Evicted"); + pod + } + + #[test] + fn evicted_deployment_pod_with_a_running_replacement_is_running() { + let replacement = pod(json!({ "state": { "running": {} } })); + for items in [ + [deployment(), evicted_deployment_pod(), replacement.clone()], + [deployment(), replacement.clone(), evicted_deployment_pod()], + ] { + let mapped = map_kubernetes(&items); + assert_eq!(mapped.status, "running"); + assert!(mapped.termination.is_none()); + } + // A replacement that is still being created keeps the launch starting. + let creating = pod(json!({ "state": { "waiting": { "reason": "ContainerCreating" } } })); + let mut pending = creating; + pending["status"]["phase"] = json!("Pending"); + assert_eq!( + map_kubernetes(&[deployment(), evicted_deployment_pod(), pending]).status, + "starting" + ); + } + + #[test] + fn evicted_deployment_pod_alone_is_failed_evicted() { + let mapped = map_kubernetes(&[deployment(), evicted_deployment_pod()]); + assert_eq!(mapped.status, "failed"); + assert_eq!( + mapped.termination.unwrap().reason, + WorkerTerminationReason::WorkerEvicted + ); + } + + #[test] + fn a_live_replacement_that_fails_still_fails_the_launch() { + let crash = pod( + json!({ "restartCount": 2, "state": { "waiting": { "reason": "CrashLoopBackOff" } } }), + ); + let mapped = map_kubernetes(&[deployment(), evicted_deployment_pod(), crash]); + assert_eq!(mapped.status, "failed"); + assert_eq!( + mapped.termination.unwrap().reason, + WorkerTerminationReason::WorkerExited + ); + } + #[test] fn container_creating_is_starting() { let items = [