From 71e7d9e440bd17d81f776f03d835a45a76072ea0 Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Wed, 18 Nov 2026 22:53:19 +0100 Subject: [PATCH] feat: show a flow's continue-on-error failures on its run and status (#12525) * feat: show a flow's continue-on-error failures on its run and status Co-Authored-By: Claude Opus 5.5 * fix: record continued failures after the flow's row and render jobless ones as text Co-Authored-By: Claude Opus 5.5 * fix: keep the share link's view token on failed-step links Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5.5 --- ...361b028471ba1bfe2fc45a7dc2914f059c9c3.json | 16 ++++++ backend/tests/worker.rs | 55 +++++++++++++++++++ backend/windmill-queue/src/jobs.rs | 2 + backend/windmill-types/src/flow_status.rs | 13 +++++ backend/windmill-worker/src/worker_flow.rs | 47 +++++++++++++++- .../components/FlowStatusViewerInner.svelte | 32 +++++++++++ frontend/src/lib/components/JobStatus.svelte | 47 ++++++++++++---- openflow.openapi.yaml | 14 +++++ 8 files changed, 213 insertions(+), 13 deletions(-) create mode 100644 backend/.sqlx/query-4c260718afc95b83abd83daca83361b028471ba1bfe2fc45a7dc2914f059c9c3.json diff --git a/backend/.sqlx/query-4c260718afc95b83abd83daca83361b028471ba1bfe2fc45a7dc2914f059c9c3.json b/backend/.sqlx/query-4c260718afc95b83abd83daca83361b028471ba1bfe2fc45a7dc2914f059c9c3.json new file mode 100644 index 0000000000..ddae680264 --- /dev/null +++ b/backend/.sqlx/query-4c260718afc95b83abd83daca83361b028471ba1bfe2fc45a7dc2914f059c9c3.json @@ -0,0 +1,16 @@ +{ + "db_name": "PostgreSQL", + "query": "UPDATE v2_job_status\n SET flow_status = JSONB_SET(\n flow_status,\n ARRAY['continued_on_error'],\n COALESCE(flow_status->'continued_on_error', '[]'::jsonb) || JSONB_BUILD_ARRAY($2::jsonb)\n )\n WHERE id = $1\n AND flow_status IS NOT NULL\n AND JSONB_ARRAY_LENGTH(COALESCE(flow_status->'continued_on_error', '[]'::jsonb)) < $3", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Uuid", + "Jsonb", + "Int4" + ] + }, + "nullable": [] + }, + "hash": "4c260718afc95b83abd83daca83361b028471ba1bfe2fc45a7dc2914f059c9c3" +} diff --git a/backend/tests/worker.rs b/backend/tests/worker.rs index 4a2c3e5a18..ee622009b3 100644 --- a/backend/tests/worker.rs +++ b/backend/tests/worker.rs @@ -4852,6 +4852,61 @@ async fn test_unrecoverable_failure_on_continue_on_error_runs_failure_module( Ok(()) } +/// A failure the flow goes past because of `continue_on_error` is recorded on the root flow's +/// status, including one inside a loop iteration's subflow. +#[cfg(feature = "deno_core")] +#[sqlx::test(fixtures("base"))] +async fn test_continue_on_error_recorded_on_root(db: Pool) -> anyhow::Result<()> { + initialize_tracing().await; + let server = ApiServer::start(db.clone()).await?; + let port = server.addr.port(); + + let failing = |id: &str| { + json!({"id": id, "continue_on_error": true, "value": { + "type": "rawscript", "language": "bun", "input_transforms": {}, + "content": "export function main() { throw new Error('boom'); }", + }}) + }; + let flow: FlowValue = serde_json::from_value(json!({ + "modules": [ + failing("a"), + {"id": "loop", "value": { + "type": "forloopflow", "parallel": true, "skip_failures": false, + "iterator": {"type": "static", "value": [1, 2]}, + "modules": [failing("b"), {"id": "c", "value": {"type": "identity"}}], + }}, + ], + })) + .unwrap(); + + let job = RunJob::from(JobPayload::RawFlow { value: flow, path: None, restarted_from: None }) + .run_until_complete(&db, false, port) + .await; + server.close().await.unwrap(); + + assert!(job.success, "{:?}", job.json_result()); + let mut recorded: Vec<(String, Uuid, Option)> = sqlx::query_as( + "SELECT e->>'id', (e->>'job')::uuid, j.parent_job + FROM v2_job_completed c, JSONB_ARRAY_ELEMENTS(c.flow_status->'continued_on_error') e + JOIN v2_job j ON j.id = (e->>'job')::uuid + WHERE c.id = $1", + ) + .bind(job.id) + .fetch_all(&db) + .await?; + recorded.sort(); + let ids: Vec<&str> = recorded.iter().map(|(id, ..)| id.as_str()).collect(); + assert_eq!(ids, vec!["a", "b", "b"]); + assert_eq!(recorded[0].2, Some(job.id)); + assert_ne!(recorded[1].1, recorded[2].1); + assert_ne!( + recorded[1].2, + Some(job.id), + "b runs in an iteration's subflow" + ); + Ok(()) +} + #[cfg(feature = "deno_core")] #[sqlx::test(fixtures("base"))] async fn test_run_wait_result_early_return_with_failure_module( diff --git a/backend/windmill-queue/src/jobs.rs b/backend/windmill-queue/src/jobs.rs index f6f01e9ac7..7f4a231cf4 100644 --- a/backend/windmill-queue/src/jobs.rs +++ b/backend/windmill-queue/src/jobs.rs @@ -7397,6 +7397,7 @@ async fn push_inner<'c, 'd>( chat_input_enabled: None, memory_id: None, no_inherited_flow_env: false, + continued_on_error: vec![], } } _ => { @@ -7797,6 +7798,7 @@ async fn push_inner<'c, 'd>( chat_input_enabled: None, memory_id: None, no_inherited_flow_env: false, + continued_on_error: vec![], }; // The completed job's own scopes are gone with its `job_perms` row, so the restart // takes the flow's current setting (and the restarting caller's ceiling). diff --git a/backend/windmill-types/src/flow_status.rs b/backend/windmill-types/src/flow_status.rs index a64de227b9..eaac32a0fc 100644 --- a/backend/windmill-types/src/flow_status.rs +++ b/backend/windmill-types/src/flow_status.rs @@ -46,6 +46,18 @@ pub struct FlowStatus { /// the worker then walks the ancestors as usual. #[serde(default, skip_serializing_if = "std::ops::Not::not")] pub no_inherited_flow_env: bool, + /// On a root flow: the steps, at any depth, that failed and that the flow went past + /// because of `continue_on_error`. Capped at `MAX_CONTINUED_ON_ERROR` entries. + #[serde(default, skip_serializing_if = "Vec::is_empty")] + pub continued_on_error: Vec, +} + +pub const MAX_CONTINUED_ON_ERROR: i32 = 100; + +#[derive(Serialize, Deserialize, Debug, Clone)] +pub struct ContinuedOnError { + pub id: String, + pub job: Uuid, } #[derive(Serialize, Deserialize, Debug, Clone, Default)] @@ -633,6 +645,7 @@ impl FlowStatus { chat_input_enabled: f.chat_input_enabled, memory_id: None, no_inherited_flow_env: false, + continued_on_error: vec![], } } diff --git a/backend/windmill-worker/src/worker_flow.rs b/backend/windmill-worker/src/worker_flow.rs index 5b76a7c111..fd7e010c00 100644 --- a/backend/windmill-worker/src/worker_flow.rs +++ b/backend/windmill-worker/src/worker_flow.rs @@ -39,7 +39,7 @@ use windmill_common::client::AuthedClient; use windmill_common::db::Authed; use windmill_common::flow_conversations::{add_message_to_conversation_tx, MessageType}; use windmill_common::flow_status::{ - ApprovalConditions, FlowJobDuration, FlowJobsDuration, FlowStatusModuleWParent, + ApprovalConditions, ContinuedOnError, MAX_CONTINUED_ON_ERROR, FlowJobDuration, FlowJobsDuration, FlowStatusModuleWParent, Iterator as FlowIterator, JobResult, }; use windmill_common::flows::{add_virtual_items_if_necessary, Branch, FlowNodeId, StopAfterIf}; @@ -844,6 +844,7 @@ pub async fn update_flow_status_after_job_completion_internal( add_time!(bench, "process module status START"); let mut nresult = None; + let mut continued_on_error = None; let (inc_step_counter, new_status) = match module_status { FlowStatusModule::InProgress { iterator, @@ -1415,6 +1416,12 @@ pub async fn update_flow_status_after_job_completion_internal( } else { false }; + if inc { + continued_on_error = Some(ContinuedOnError { + id: module_status.id(), + job: *job_id_for_status, + }); + } if (stop_early && stop_early_err_msg.is_some()) || loop_exhausted_err.is_some() { // if stop_early with error message, we need to set explictely success to false as this function was called with success = true as the job succeeded @@ -1614,6 +1621,12 @@ pub async fn update_flow_status_after_job_completion_internal( .map_err(|e| Error::internal_err(format!("error while setting leaf jobs: {e:#}")))?; } + // Written after the flow's own row, keeping the child-to-ancestor lock order of + // every flow completion. + if let (Some(entry), Some(flow_job)) = (continued_on_error, flow_job.as_ref()) { + record_continued_on_error(&mut tx, get_root_job_id(flow_job), entry).await?; + } + flow_job }; @@ -2498,6 +2511,38 @@ async fn set_success_and_duration_in_flow_job_success<'c>( Ok(()) } +/// Records on the root flow a step that failed and that its flow went past because of +/// `continue_on_error`, so that the failure shows on the root run without expanding the +/// subflow it happened in. +async fn record_continued_on_error( + tx: &mut Transaction<'_, Postgres>, + root: Uuid, + entry: ContinuedOnError, +) -> error::Result<()> { + sqlx::query!( + "UPDATE v2_job_status + SET flow_status = JSONB_SET( + flow_status, + ARRAY['continued_on_error'], + COALESCE(flow_status->'continued_on_error', '[]'::jsonb) || JSONB_BUILD_ARRAY($2::jsonb) + ) + WHERE id = $1 + AND flow_status IS NOT NULL + AND JSONB_ARRAY_LENGTH(COALESCE(flow_status->'continued_on_error', '[]'::jsonb)) < $3", + root, + json!(entry), + MAX_CONTINUED_ON_ERROR, + ) + .execute(&mut **tx) + .await + .map_err(|e| { + Error::internal_err(format!( + "error while recording continued_on_error on root flow {root}: {e:#}" + )) + })?; + Ok(()) +} + /// Applies a step's edits to the flow's `v2_job_status` row and reads the flow back, in one /// statement: every UPDATE of that row writes a new row version carrying the whole /// `flow_status`, so the edits must not be split. `leaf_job` is only written here when the flow diff --git a/frontend/src/lib/components/FlowStatusViewerInner.svelte b/frontend/src/lib/components/FlowStatusViewerInner.svelte index 78cd10c856..2a875126ad 100644 --- a/frontend/src/lib/components/FlowStatusViewerInner.svelte +++ b/frontend/src/lib/components/FlowStatusViewerInner.svelte @@ -1470,6 +1470,8 @@ let totalEventsWaiting = $derived( Object.values(suspendStatus?.val ?? {}).reduce((a, b) => a + (b?.nb ?? 0), 0) ) + + let continuedOnError = $derived(job?.flow_status?.continued_on_error ?? []) @@ -1484,6 +1486,36 @@ {:else}
{/if} --> + {#if !isListJob && continuedOnError.length > 0} + +
+ + {#each continuedOnError as failure, i (i)} + {#if isReplay || failure.job == '00000000-0000-0000-0000-000000000000'} + {failure.id} + {:else} + + {failure.id} + + + {/if} + {/each} +
+
+ {/if} {#if isListJob} {#if render}
diff --git a/frontend/src/lib/components/JobStatus.svelte b/frontend/src/lib/components/JobStatus.svelte index 30fd5f0a27..a905f32874 100644 --- a/frontend/src/lib/components/JobStatus.svelte +++ b/frontend/src/lib/components/JobStatus.svelte @@ -17,20 +17,42 @@ } let { job, large = false }: Props = $props() + + let continuedOnError = $derived(job?.flow_status?.continued_on_error ?? []) +{#snippet continuedOnErrorBadge()} + {#if continuedOnError.length > 0} + + {continuedOnError.length}{continuedOnError.length >= 100 ? '+' : ''} failed step{continuedOnError.length > + 1 + ? 's' + : ''} continued + + {/if} +{/snippet} + {#if job && 'success' in job && job.success} - - Successfully ran in {msToReadableTime(job.duration_ms)} - {job.is_skipped ? '(Skipped)' : ''} - {#if job.self_wait_time_ms || job.aggregate_wait_time_ms} - - {/if} - +
+ + Successfully ran in {msToReadableTime(job.duration_ms)} + {job.is_skipped ? '(Skipped)' : ''} + {#if job.self_wait_time_ms || job.aggregate_wait_time_ms} + + {/if} + + {@render continuedOnErrorBadge()} +
{:else if job && 'success' in job && job.resolved}