feat: show runs failed by the platform as system errors

This commit is contained in:
hugocasa
2026-11-04 18:50:52 +01:00
parent d8773f4316
commit 0aefd660fd
15 changed files with 173 additions and 9 deletions
+2 -2
View File
@@ -6442,7 +6442,7 @@ async fn handle_zombie_jobs(db: &Pool<Postgres>, 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",
}
});
@@ -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,
+30
View File
@@ -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 {
+18
View File
@@ -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<bool>,
// Completed-jobs only, like `resolved`.
pub system_error: Option<bool>,
pub is_flow_step: Option<bool>,
pub suspended: Option<bool>,
pub schedule_path: Option<String>,
@@ -323,8 +325,19 @@ pub struct UnifiedJob {
pub runnable_settings_handle: Option<i64>,
pub is_retry: Option<bool>,
pub resolved: Option<bool>,
pub system_error: Option<bool>,
}
/// 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<UnifiedJob> 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,
+38
View File
@@ -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:
+10
View File
@@ -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()
+16
View File
@@ -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",
}
}
+5
View File
@@ -480,6 +480,11 @@ pub struct CompletedJob {
#[serde(default, skip_serializing_if = "Option::is_none")]
#[sqlx(default)]
pub trigger_kind: Option<TriggerKindLabel>,
// 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<bool>,
}
impl CompletedJob {
+10 -1
View File
@@ -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: {}",
@@ -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),
});
+8 -2
View File
@@ -49,8 +49,14 @@
{/if}
</Badge>
{:else if job && 'success' in job}
<Badge {large} color="red">
{job.canceled ? 'Canceled' : 'Failed'} after {msToReadableTime(job.duration_ms)}
<Badge
{large}
color="red"
title={job.system_error ? 'The platform failed this run, not its code' : undefined}
>
{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}
<WaitTimeWarning
self_wait_time_ms={job.self_wait_time_ms}
+4 -1
View File
@@ -287,7 +287,10 @@
status:
filters.val.status == 'failure' || filters.val.status == 'canceled'
? filters.val.status
: undefined,
: filters.val.status == 'system_error'
? ('failure' as const)
: undefined,
systemError: filters.val.status == 'system_error' ? true : undefined,
running:
filters.val.status == 'running' || filters.val.status == 'suspended'
? true
@@ -8,6 +8,7 @@
FastForward,
Hourglass,
Play,
ServerCrash,
ShieldQuestion,
Wrench,
X
@@ -57,6 +58,15 @@
>
<Wrench size={14} />
</Badge>
{:else if 'success' in job && job.system_error}
<Badge
color="red"
{roundedFull}
baseClass={roundedFull ? '' : '!px-1.5'}
title="System error: the platform failed this run, not its code"
>
<ServerCrash size={14} />
</Badge>
{:else if 'success' in job}
<Badge color="red" {roundedFull} baseClass={roundedFull ? '' : '!px-1.5'}>
<X size={14} />
@@ -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 }
@@ -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,