diff --git a/backend/src/monitor.rs b/backend/src/monitor.rs index 9ee707113a..323398c5d7 100644 --- a/backend/src/monitor.rs +++ b/backend/src/monitor.rs @@ -6442,7 +6442,7 @@ async fn handle_zombie_jobs(db: &Pool, base_internal_url: &str, node_n &completed, memory_peak, None, - error::Error::ExecutionErr(error_message.clone()), + error::Error::WorkerLost(error_message.clone()), // a same worker zombie means the worker itself is gone if matches!(error_kind, ErrorMessage::SameWorker) { StepFailureKind::Unrecoverable @@ -6501,7 +6501,7 @@ async fn force_complete_zombie_job( let error_value = serde_json::json!({ "error": { "message": error_message, - "name": "ExecutionErr", + "name": "WorkerLost", } }); diff --git a/backend/windmill-api-jobs/src/concurrency_groups.rs b/backend/windmill-api-jobs/src/concurrency_groups.rs index 4040d41bd2..ee30bceee5 100644 --- a/backend/windmill-api-jobs/src/concurrency_groups.rs +++ b/backend/windmill-api-jobs/src/concurrency_groups.rs @@ -201,6 +201,7 @@ async fn get_concurrent_intervals( parent_job: None, is_skipped: None | Some(false), resolved: None, + system_error: None, suspended: None, schedule_path: None, args: None, diff --git a/backend/windmill-api-jobs/src/query.rs b/backend/windmill-api-jobs/src/query.rs index ebfc0c3725..8291878f41 100644 --- a/backend/windmill-api-jobs/src/query.rs +++ b/backend/windmill-api-jobs/src/query.rs @@ -527,6 +527,13 @@ pub fn filter_list_completed_query( sqlb.and_where(format!("NOT {exists}")); } } + if let Some(se) = &lq.system_error { + if *se { + sqlb.and_where(crate::types::SYSTEM_ERROR_SQL); + } else { + sqlb.and_where(format!("NOT {}", crate::types::SYSTEM_ERROR_SQL)); + } + } if let Some(fs) = &lq.is_flow_step { if *fs { sqlb.and_where_is_not_null("flow_step_id"); @@ -714,6 +721,7 @@ mod tests { job_kinds: None, is_skipped: None, resolved: None, + system_error: None, is_flow_step: None, suspended: None, schedule_path: None, @@ -1024,6 +1032,28 @@ mod tests { } } + #[test] + fn system_error_sql_lists_exactly_the_system_error_names() { + let sql = crate::types::SYSTEM_ERROR_SQL; + for name in windmill_common::error::SYSTEM_ERROR_NAMES { + assert!( + sql.contains(&format!("'{name}'")), + "{name} missing from {sql}" + ); + } + let listed = sql + .split(" IN (") + .nth(1) + .unwrap() + .split(')') + .next() + .unwrap(); + assert_eq!( + listed.split(", ").count(), + windmill_common::error::SYSTEM_ERROR_NAMES.len() + ); + } + #[test] fn test_completed_filter_status_canceled() { let lq = ListCompletedQuery { diff --git a/backend/windmill-api-jobs/src/types.rs b/backend/windmill-api-jobs/src/types.rs index f50cb61451..92926ff0d9 100644 --- a/backend/windmill-api-jobs/src/types.rs +++ b/backend/windmill-api-jobs/src/types.rs @@ -167,6 +167,8 @@ pub struct ListCompletedQuery { // has no resolution, which is why `resolved = false` must not reach the queue side // of the runs-list union. pub resolved: Option, + // Completed-jobs only, like `resolved`. + pub system_error: Option, pub is_flow_step: Option, pub suspended: Option, pub schedule_path: Option, @@ -323,8 +325,19 @@ pub struct UnifiedJob { pub runnable_settings_handle: Option, pub is_retry: Option, pub resolved: Option, + pub system_error: Option, } +/// Whether a completed job failed because of the platform: its stored `error.name` is one of +/// `windmill_common::error::SYSTEM_ERROR_NAMES`, listed again here as SQL needs them literal. +macro_rules! system_error_sql { + () => { + "COALESCE(v2_job_completed.status = 'failure' AND v2_job_completed.result->'error'->>'name' \ + IN ('InternalErr', 'SqlErr', 'ConnectingToDatabase', 'WorkerLost', 'OutOfMemory'), false)" + }; +} +pub const SYSTEM_ERROR_SQL: &str = system_error_sql!(); + const CJ_FIELDS: &[&str] = &[ "'CompletedJob' as typ", "v2_job_completed.id", @@ -366,6 +379,7 @@ const CJ_FIELDS: &[&str] = &[ "null as runnable_settings_handle", "EXISTS(SELECT 1 FROM native_retry_attempt WHERE job_id = v2_job.id) as is_retry", "EXISTS(SELECT 1 FROM job_resolution WHERE job_id = v2_job_completed.id) as resolved", + concat!(system_error_sql!(), " as system_error"), ]; const QJ_FIELDS: &[&str] = &[ @@ -410,6 +424,7 @@ const QJ_FIELDS: &[&str] = &[ "EXISTS(SELECT 1 FROM native_retry_attempt WHERE job_id = v2_job.id) as is_retry", // A job still in the queue has not failed, so it can never be resolved. "false as resolved", + "false as system_error", ]; impl UnifiedJob { @@ -470,6 +485,7 @@ impl From for Job { resolution_note: None, resolved_automatically: None, trigger_kind: None, + system_error: uj.system_error, }, )), "QueuedJob" => Job::QueuedJob(JobExtended::new( @@ -726,6 +742,7 @@ mod tests { ])), is_skipped: None, resolved: None, + system_error: None, is_flow_step: None, suspended: None, schedule_path: None, @@ -797,6 +814,7 @@ mod tests { job_kinds: None, is_skipped: None, resolved: None, + system_error: None, is_flow_step: None, suspended: None, schedule_path: None, diff --git a/backend/windmill-api/openapi.yaml b/backend/windmill-api/openapi.yaml index bfe317c1b7..9d9022e57b 100644 --- a/backend/windmill-api/openapi.yaml +++ b/backend/windmill-api/openapi.yaml @@ -17584,6 +17584,14 @@ paths: in: query schema: type: boolean + - name: system_error + description: >- + filter on whether a failed run failed because of the platform (internal or + database error, lost worker, out of memory) rather than its code. true keeps only + those runs, false hides them + in: query + schema: + type: boolean - name: is_flow_step description: is the job a flow step in: query @@ -17896,6 +17904,14 @@ paths: in: query schema: type: boolean + - name: system_error + description: >- + filter on whether a failed run failed because of the platform (internal or + database error, lost worker, out of memory) rather than its code. true keeps only + those runs, false hides them + in: query + schema: + type: boolean - name: is_flow_step description: is the job a flow step in: query @@ -18178,6 +18194,14 @@ paths: in: query schema: type: boolean + - name: system_error + description: >- + filter on whether a failed run failed because of the platform (internal or + database error, lost worker, out of memory) rather than its code. true keeps only + those runs, false hides them + in: query + schema: + type: boolean - name: is_flow_step description: is the job a flow step in: query @@ -27091,6 +27115,14 @@ paths: in: query schema: type: boolean + - name: system_error + description: >- + filter on whether a failed run failed because of the platform (internal or + database error, lost worker, out of memory) rather than its code. true keeps only + those runs, false hides them + in: query + schema: + type: boolean - name: is_flow_step description: is the job a flow step in: query @@ -32201,6 +32233,12 @@ components: true when a succeeding retry resolved this rather than a person. Explicit rather than inferred from an absent resolved_by, which is also absent for a manual resolution outside enterprise + system_error: + type: boolean + description: >- + true when this failed run failed because of the platform rather than its code, + derived from its error name: InternalErr, SqlErr, ConnectingToDatabase, + WorkerLost or OutOfMemory trigger_kind: $ref: "#/components/schemas/JobTriggerKind" worker: diff --git a/backend/windmill-api/src/jobs.rs b/backend/windmill-api/src/jobs.rs index 76f5440cdd..e95cbb4f64 100644 --- a/backend/windmill-api/src/jobs.rs +++ b/backend/windmill-api/src/jobs.rs @@ -2796,6 +2796,15 @@ impl<'a> GetQuery<'a> { if let Some(mut cjob) = cjob { cjob.inner = format_completed_job_result(cjob.inner); + let failed = !cjob.inner.success && !cjob.inner.canceled; + cjob.inner.system_error = Some( + failed + && cjob.inner.json_result().is_some_and(|r| { + r["error"]["name"].as_str().is_some_and(|name| { + windmill_common::error::SYSTEM_ERROR_NAMES.contains(&name) + }) + }), + ); return Ok(Some(cjob)); } Ok(cjob) @@ -4988,6 +4997,7 @@ async fn list_jobs( // into a resolved-only view. "resolved = false" (hide resolved) must keep them, // since a running job has no resolution to hide. && lq.resolved != Some(true) + && lq.system_error != Some(true) && lq.created_before.is_none() && lq.started_before.is_none() && lq.created_or_started_before.is_none() diff --git a/backend/windmill-common/src/error.rs b/backend/windmill-common/src/error.rs index dd8ec49f92..8a7223177a 100644 --- a/backend/windmill-common/src/error.rs +++ b/backend/windmill-common/src/error.rs @@ -94,8 +94,23 @@ pub enum Error { MigrationNeeded { version: String, feature: String, guide_url: url::Url }, #[error("{0} is unavailable. It is possible for this worker to be behind.")] FeatureUnavailable(String), + /// The job's worker stopped reporting on it: a crash, an OOM kill of the worker, a lost host. + #[error("{0}")] + WorkerLost(String), } +/// The `error.name`s of a job that the platform failed rather than its own code: an internal or +/// database error while handling it, its worker lost mid-run (no ping, worker gone, restarts +/// exhausted), or its process killed for memory. The runs list derives `system_error` from these, +/// in SQL that must list the same names (`windmill-api-jobs`, `system_error_sql!`). +pub const SYSTEM_ERROR_NAMES: &[&str] = &[ + "InternalErr", + "SqlErr", + "ConnectingToDatabase", + "WorkerLost", + "OutOfMemory", +]; + impl Error { pub fn name(&self) -> &str { match self { @@ -130,6 +145,7 @@ impl Error { Self::NotAuthorized(_) => "NotAuthorized", Self::MetricNotFound(_) => "MetricNotFound", Self::PermissionDenied(_) => "PermissionDenied", + Self::WorkerLost(_) => "WorkerLost", _ => "InternalErr", } } diff --git a/backend/windmill-types/src/jobs.rs b/backend/windmill-types/src/jobs.rs index 17e5235c5f..db3252e678 100644 --- a/backend/windmill-types/src/jobs.rs +++ b/backend/windmill-types/src/jobs.rs @@ -480,6 +480,11 @@ pub struct CompletedJob { #[serde(default, skip_serializing_if = "Option::is_none")] #[sqlx(default)] pub trigger_kind: Option, + // True when the run failed because of the platform rather than its code, derived from the + // stored `error.name` (`SYSTEM_ERROR_NAMES`); `status` stays 'failure'. + #[serde(default, skip_serializing_if = "Option::is_none")] + #[sqlx(default)] + pub system_error: Option, } impl CompletedJob { diff --git a/backend/windmill-worker/src/handle_child.rs b/backend/windmill-worker/src/handle_child.rs index 31eb8034f9..8bf4652722 100644 --- a/backend/windmill-worker/src/handle_child.rs +++ b/backend/windmill-worker/src/handle_child.rs @@ -378,7 +378,11 @@ pub async fn handle_child( // when the kill could not be confirmed. SIGINT and SIGTERM are only sent where the // sends below are compiled in: elsewhere an exit during their wait is unsignaled. let unix_signal = |s: &'static str| { - if cfg!(any(target_os = "linux", target_os = "macos")) { s } else { "none" } + if cfg!(any(target_os = "linux", target_os = "macos")) { + s + } else { + "none" + } }; let kill = async { #[allow(unused_variables)] @@ -1253,6 +1257,11 @@ pub fn process_status( } else if let Some(code) = status.code() { Err(error::Error::ExitStatus(program.to_string(), code)) } else { + // Without tini the OOM killer's SIGKILL arrives as a signal, not as exit code 137. + #[cfg(any(target_os = "linux", target_os = "macos"))] + if status.signal() == Some(9) { + return Err(error::Error::ExitStatus(program.to_string(), 137)); + } #[cfg(any(target_os = "linux", target_os = "macos"))] return Err(error::Error::ExecutionErr(format!( "process terminated by signal: {:#?}, stopped_signal: {:#?}, core_dumped: {}", diff --git a/backend/windmill-worker/src/result_processor.rs b/backend/windmill-worker/src/result_processor.rs index e82f1a1d93..2f00b80c5f 100644 --- a/backend/windmill-worker/src/result_processor.rs +++ b/backend/windmill-worker/src/result_processor.rs @@ -671,7 +671,13 @@ pub async fn process_result( Error::ExecutionRawError(e) => to_raw_value(&e), err @ _ => to_raw_value(&SerializedError { message: format!("execution error:\n{err:#}",), - name: "ExecutionErr".to_string(), + // A platform failure keeps its own name, which is what marks the run as a + // system error. + name: if windmill_common::error::SYSTEM_ERROR_NAMES.contains(&err.name()) { + err.name().to_string() + } else { + "ExecutionErr".to_string() + }, step_id: job.flow_step_id.clone(), exit_code: None, }), @@ -2187,7 +2193,14 @@ pub fn extract_error_value( "exit code for \"{program}\": {i}, last log lines:\n{}", ANSI_ESCAPE_RE.replace_all(log_lines.trim(), "").to_string() ), - name: "ExecutionErr".to_string(), + // 137 is SIGKILL, which the worker never sends itself without reporting a timeout or a + // cancel instead: here it is the OOM killer. + name: if i == 137 { + "OutOfMemory" + } else { + "ExecutionErr" + } + .to_string(), step_id, exit_code: Some(i), }); diff --git a/frontend/src/lib/components/JobStatus.svelte b/frontend/src/lib/components/JobStatus.svelte index 30fd5f0a27..9d0712a944 100644 --- a/frontend/src/lib/components/JobStatus.svelte +++ b/frontend/src/lib/components/JobStatus.svelte @@ -49,8 +49,14 @@ {/if} {:else if job && 'success' in job} - - {job.canceled ? 'Canceled' : 'Failed'} after {msToReadableTime(job.duration_ms)} + + {job.canceled ? 'Canceled' : job.system_error ? 'System error' : 'Failed'} after {msToReadableTime( + job.duration_ms + )} {#if job.self_wait_time_ms || job.aggregate_wait_time_ms} + {:else if 'success' in job && job.system_error} + + + {:else if 'success' in job} diff --git a/frontend/src/lib/components/runs/runsFilter.ts b/frontend/src/lib/components/runs/runsFilter.ts index cef8cca6e9..5644954d3b 100644 --- a/frontend/src/lib/components/runs/runsFilter.ts +++ b/frontend/src/lib/components/runs/runsFilter.ts @@ -164,6 +164,7 @@ export function buildRunsFilterSearchbarSchema({ { label: 'Running', value: 'running' as const }, { label: 'Success', value: 'success' as const }, { label: 'Failure', value: 'failure' as const }, + { label: 'System error', value: 'system_error' as const }, { label: 'Canceled', value: 'canceled' as const }, { label: 'Waiting', value: 'waiting' as const }, { label: 'Suspended', value: 'suspended' as const } diff --git a/frontend/src/lib/components/runs/useJobsLoader.svelte.ts b/frontend/src/lib/components/runs/useJobsLoader.svelte.ts index 8055278c77..08ecfb9799 100644 --- a/frontend/src/lib/components/runs/useJobsLoader.svelte.ts +++ b/frontend/src/lib/components/runs/useJobsLoader.svelte.ts @@ -94,7 +94,9 @@ export function useJobsLoader(args: () => UseJobLoaderArgs) { let label = $derived(filters?.label ?? null) let worker = $derived(filters?.worker ?? null) - let success = $derived(filters?.status ?? null) + // A system error is a failure with a platform error name, so it loads as one, narrowed. + let systemError = $derived(filters?.status === 'system_error') + let success = $derived(systemError ? 'failure' : (filters?.status ?? null)) let isQueueOnly = $derived(success == 'running' || success == 'suspended' || success == 'waiting') let showSkipped = $derived(filters?.show_skipped ?? false) let resolutionFilter = $derived(filters?.resolved ?? 'all') @@ -485,6 +487,7 @@ export function useJobsLoader(args: () => UseJobLoaderArgs) { : resolutionFilter === 'unresolved' ? false : undefined, + systemError: systemError || undefined, // isFlowStep: jobKindsCat != 'all' ? false : undefined, hasNullParent: jobKindsCat != 'all' ? true : undefined, label: label == null || label === '' ? undefined : label, @@ -548,6 +551,7 @@ export function useJobsLoader(args: () => UseJobLoaderArgs) { : resolutionFilter === 'unresolved' ? false : undefined, + systemError: systemError || undefined, isFlowStep: jobKindsCat != 'all' ? false : undefined, label: label == null || label === '' ? undefined : label, tag: tag == null || tag === '' ? undefined : tag,