diff --git a/backend/tests/recent_runs_tag_scope.rs b/backend/tests/recent_runs_tag_scope.rs index e0a241325f..7c679479d6 100644 --- a/backend/tests/recent_runs_tag_scope.rs +++ b/backend/tests/recent_runs_tag_scope.rs @@ -1,5 +1,6 @@ -//! `jobs/recent_runs` aggregates over the workspace through `user_db`, which applies RLS but not a -//! token's `if_jobs:filter_tags` scope: the handler has to filter on it itself. +//! `jobs/recent_runs`: it aggregates over the workspace through `user_db`, which applies RLS but +//! not a token's `if_jobs:filter_tags` scope, so the handler filters on it itself; and it reports a +//! resolved failure apart from an unresolved one. use sqlx::{Pool, Postgres}; use windmill_test_utils::*; @@ -9,9 +10,13 @@ const DENO_JOB: &str = "14141414-1414-1414-1414-141414141414"; const FLOW_JOB: &str = "15151515-1515-1515-1515-151515151515"; async fn recent_runs(port: u16, token: &str) -> String { + recent_runs_query(port, token, "").await +} + +async fn recent_runs_query(port: u16, token: &str, query: &str) -> String { let resp = reqwest::Client::new() .get(format!( - "http://localhost:{port}/api/w/test-workspace/jobs/recent_runs" + "http://localhost:{port}/api/w/test-workspace/jobs/recent_runs{query}" )) .header("Authorization", format!("Bearer {token}")) .send() @@ -37,3 +42,108 @@ async fn test_recent_runs_honors_tag_scope(db: Pool) -> anyhow::Result assert!(!scoped.contains(FLOW_JOB), "{scoped}"); Ok(()) } + +async fn insert_root_run( + db: &Pool, + id: &str, + status: &str, + resolved: bool, +) -> anyhow::Result<()> { + sqlx::query( + "INSERT INTO v2_job (id, workspace_id, created_by, permissioned_as, permissioned_as_email, + kind, script_lang, runnable_path, tag, visible_to_owner) + VALUES ($1::uuid, 'test-workspace', 'test-user-2', 'u/test-user-2', 'test2@windmill.dev', + 'script', 'deno', 'u/test-user-2/flaky', 'deno', true)", + ) + .bind(id) + .execute(db) + .await?; + sqlx::query( + "INSERT INTO v2_job_completed (id, workspace_id, duration_ms, status) + VALUES ($1::uuid, 'test-workspace', 10, $2::job_status)", + ) + .bind(id) + .bind(status) + .execute(db) + .await?; + if resolved { + sqlx::query( + "INSERT INTO job_resolution (job_id, workspace_id) VALUES ($1::uuid, 'test-workspace')", + ) + .bind(id) + .execute(db) + .await?; + } + Ok(()) +} + +/// A resolved failure is `resolved`, not `failure`: Home's failed counts leave it out, and the +/// failed ids asked for one item are the failures that item counts. +#[sqlx::test(fixtures("base", "jobs_read_auth"))] +async fn test_recent_runs_resolved_failures(db: Pool) -> anyhow::Result<()> { + initialize_tracing().await; + insert_root_run(&db, "a0000000-0000-0000-0000-000000000001", "failure", true).await?; + insert_root_run(&db, "a0000000-0000-0000-0000-000000000002", "failure", false).await?; + insert_root_run(&db, "a0000000-0000-0000-0000-000000000003", "canceled", true).await?; + // A failed single-step flow wrapping a flow at the same path: the flow's failure, not the + // script's, though a job listing by path and kind cannot tell them apart. + sqlx::query( + "INSERT INTO v2_job (id, workspace_id, created_by, permissioned_as, permissioned_as_email, + kind, script_lang, runnable_path, tag, visible_to_owner, raw_flow) + VALUES ('a0000000-0000-0000-0000-000000000004', 'test-workspace', 'test-user-2', + 'u/test-user-2', 'test2@windmill.dev', 'singlestepflow', 'deno', 'u/test-user-2/flaky', + 'deno', true, + '{\"modules\": [{\"id\": \"a\", \"value\": {\"type\": \"flow\", \"path\": \"u/test-user-2/flaky\"}}]}')", + ) + .execute(&db) + .await?; + sqlx::query( + "INSERT INTO v2_job_completed (id, workspace_id, duration_ms, status) + VALUES ('a0000000-0000-0000-0000-000000000004', 'test-workspace', 10, 'failure')", + ) + .execute(&db) + .await?; + let server = ApiServer::start(db.clone()).await?; + + let body: serde_json::Value = serde_json::from_str( + &recent_runs_query( + server.addr.port(), + "SECRET_TOKEN_2", + "?failed_ids_kind=script&failed_ids_path=u/test-user-2/flaky", + ) + .await, + )?; + let item = body["items"] + .as_array() + .unwrap() + .iter() + .find(|i| i["path"] == "u/test-user-2/flaky" && i["kind"] == "script") + .expect("item"); + let status_of = |id: &str| { + item["runs"] + .as_array() + .unwrap() + .iter() + .find(|r| r["id"] == id) + .map(|r| r["status"].clone()) + }; + assert_eq!(status_of("a0000000-0000-0000-0000-000000000001"), Some("resolved".into())); + assert_eq!(status_of("a0000000-0000-0000-0000-000000000002"), Some("failure".into())); + assert_eq!(status_of("a0000000-0000-0000-0000-000000000003"), Some("canceled".into())); + assert_eq!(item["failed_runs"], 1, "{body}"); + // Only the item named in the query carries its ids, and they are its own unresolved failures. + assert_eq!( + item["failed_run_ids"], + serde_json::json!(["a0000000-0000-0000-0000-000000000002"]), + "{body}" + ); + let flow = body["items"] + .as_array() + .unwrap() + .iter() + .find(|i| i["path"] == "u/test-user-2/flaky" && i["kind"] == "flow") + .expect("flow item"); + assert!(flow.get("failed_run_ids").is_none(), "{body}"); + assert_eq!(body["failed_runs"], 2, "{body}"); + Ok(()) +} diff --git a/backend/windmill-api/openapi.yaml b/backend/windmill-api/openapi.yaml index bdf1159249..56b0e85d7e 100644 --- a/backend/windmill-api/openapi.yaml +++ b/backend/windmill-api/openapi.yaml @@ -18049,6 +18049,17 @@ paths: in: query schema: type: string + - name: failed_ids_kind + description: with failed_ids_path, the item whose unresolved failed run ids to list in failed_run_ids + in: query + schema: + type: string + enum: [script, flow, agent] + - name: failed_ids_path + description: with failed_ids_kind, the path of that item + in: query + schema: + type: string responses: "200": description: runs that completed in the window or are running, grouped by item, newest run first @@ -18085,8 +18096,14 @@ paths: status: $ref: "#/components/schemas/RecentRunStatus" failed_runs: - description: failed runs of the item over the whole window, not only those in runs + description: unresolved failed runs of the item over the whole window, not only those in runs type: integer + failed_run_ids: + description: the ids of those failed runs, only for the item named by failed_ids_kind and failed_ids_path + type: array + items: + type: string + format: uuid runs: type: array items: @@ -33456,8 +33473,9 @@ components: - has_preprocessor RecentRunStatus: + description: a failure someone or something marked as handled is `resolved`, not `failure` type: string - enum: [success, failure, canceled, running] + enum: [success, failure, resolved, canceled, running] ScriptLang: type: string diff --git a/backend/windmill-api/src/jobs_recent_runs.rs b/backend/windmill-api/src/jobs_recent_runs.rs index 2819e62cee..6136f2ea7d 100644 --- a/backend/windmill-api/src/jobs_recent_runs.rs +++ b/backend/windmill-api/src/jobs_recent_runs.rs @@ -41,6 +41,10 @@ const LISTED_ROOT_RUN: &str = "j.workspace_id = $1 #[derive(Deserialize)] pub(crate) struct RecentRunsQuery { folder: Option, + /// With `failed_ids_path`: list that item's unresolved failures in `failed_run_ids`. Only on + /// request, since a constantly failing item would put thousands of ids in every poll. + failed_ids_kind: Option, + failed_ids_path: Option, } #[derive(Serialize)] @@ -61,8 +65,11 @@ pub(crate) struct RecentRunItem { summary: Option, /// The status of the item's newest run. status: String, - /// Over the whole window, not only the runs listed. + /// Unresolved failures over the whole window, not only the runs listed. failed_runs: i64, + /// Their ids, for the item named by the query's `failed_ids_*` only. + #[serde(skip_serializing_if = "Option::is_none")] + failed_run_ids: Option>, /// Newest first. runs: Vec, } @@ -92,6 +99,7 @@ pub(crate) async fn list_recent_runs( .folder .filter(|f| !f.is_empty()) .map(|f| format!("f/{f}/")); + let failed_ids_of = q.failed_ids_kind.zip(q.failed_ids_path); let mut tx = user_db.begin(&authed).await?; // A run counts when it completed in the window or is running now, whenever it was queued: @@ -140,6 +148,7 @@ pub(crate) async fn list_recent_runs( CASE WHEN r.status IS NULL THEN 'running' WHEN r.status IN ('success', 'skipped') THEN 'success' WHEN r.status = 'canceled' THEN 'canceled' + WHEN EXISTS (SELECT 1 FROM job_resolution jr WHERE jr.job_id = r.id) THEN 'resolved' ELSE 'failure' END AS status, COALESCE(r.started_at, j.created_at) AS ran_at, r.duration_ms, @@ -166,10 +175,16 @@ pub(crate) async fn list_recent_runs( let mut items: Vec = vec![]; let mut index: HashMap<(String, String), usize> = HashMap::new(); for run in runs { - let failed = (run.status == "failure") as i64; + let failed = run.status == "failure"; + let wanted = failed_ids_of + .as_ref() + .is_some_and(|(k, p)| *k == run.kind && *p == run.path); match index.get(&(run.kind.clone(), run.path.clone())) { Some(&i) => { - items[i].failed_runs += failed; + items[i].failed_runs += failed as i64; + if failed && wanted { + items[i].failed_run_ids.get_or_insert_with(Vec::new).push(run.id); + } if items[i].runs.len() < RUNS_PER_ITEM { items[i].runs.push(run); } @@ -181,7 +196,8 @@ pub(crate) async fn list_recent_runs( kind: run.kind.clone(), summary: None, status: run.status.clone(), - failed_runs: failed, + failed_runs: failed as i64, + failed_run_ids: wanted.then(|| if failed { vec![run.id] } else { vec![] }), runs: vec![run], }); } diff --git a/frontend/src/lib/components/ForkWorkspaceBanner.svelte b/frontend/src/lib/components/ForkWorkspaceBanner.svelte index 49edab0827..c27e2e9693 100644 --- a/frontend/src/lib/components/ForkWorkspaceBanner.svelte +++ b/frontend/src/lib/components/ForkWorkspaceBanner.svelte @@ -244,81 +244,96 @@ {#snippet forkAction()} {@const total = comparison?.summary.total_diffs ?? 0} {@const conflicts = comparison?.summary.conflicts ?? 0} + {@const status = loading + ? 'loading' + : error + ? 'error' + : showDraftsOnly + ? 'drafts' + : total > 0 + ? 'drift' + : undefined} - {#if loading} - Checking for changes… - {:else if error} - Comparison failed - {:else if showDraftsOnly} - - {draftCount} draft{draftCount !== 1 ? 's' : ''} - - {:else if total > 0} - - - {#if changesAhead > 0} - openCompareDir('deploy_to')} - title="{changesAhead} ahead of {parentWorkspaceId} — review what this {currentNoun} has to give" - > - - {changesAhead}{compactCounts ? '' : ' ahead'} - - {/if} - {#if changesBehind > 0} - openCompareDir('update')} - title="{changesBehind} behind {parentWorkspaceId} — review what this {currentNoun} has yet to take" - > - - {changesBehind}{compactCounts ? '' : ' behind'} - - {/if} - {#if conflicts > 0} - - openCompareDir('deploy_to')} - title="{conflicts} conflicting item{conflicts !== 1 ? 's' : ''} — review them" - > - - {conflicts}{compactCounts ? '' : ` conflict${conflicts !== 1 ? 's' : ''}`} - - {/if} - - {#if draftCount > 0} - - - {draftCount}{compactCounts ? '' : ` draft${draftCount !== 1 ? 's' : ''}`} - - {/if} - {/if} + + {#key status} + + {#if loading} + Checking for changes… + {:else if error} + Comparison failed + {:else if showDraftsOnly} + + {draftCount} draft{draftCount !== 1 ? 's' : ''} + + {:else if total > 0} + + + {#if changesAhead > 0} + openCompareDir('deploy_to')} + title="{changesAhead} ahead of {parentWorkspaceId} — review what this {currentNoun} has to give" + > + + {changesAhead}{compactCounts ? '' : ' ahead'} + + {/if} + {#if changesBehind > 0} + openCompareDir('update')} + title="{changesBehind} behind {parentWorkspaceId} — review what this {currentNoun} has yet to take" + > + + {changesBehind}{compactCounts ? '' : ' behind'} + + {/if} + {#if conflicts > 0} + + openCompareDir('deploy_to')} + title="{conflicts} conflicting item{conflicts !== 1 ? 's' : ''} — review them" + > + + {conflicts}{compactCounts ? '' : ` conflict${conflicts !== 1 ? 's' : ''}`} + + {/if} + + {#if draftCount > 0} + + + {draftCount}{compactCounts ? '' : ` draft${draftCount !== 1 ? 's' : ''}`} + + {/if} + {/if} + + {/key} {#if showDraftsOnly} {:else} - - {draftCount} draft{draftCount !== 1 ? 's' : ''} - - + + + + {draftCount} draft{draftCount !== 1 ? 's' : ''} + + + {/if} {/snippet} diff --git a/frontend/src/lib/components/copilot/chat/AIChatDisplay.svelte b/frontend/src/lib/components/copilot/chat/AIChatDisplay.svelte index fa7e5956b3..87980ee691 100644 --- a/frontend/src/lib/components/copilot/chat/AIChatDisplay.svelte +++ b/frontend/src/lib/components/copilot/chat/AIChatDisplay.svelte @@ -1138,13 +1138,15 @@ the panel, or the Escape-to-stop focus check would wrongly reject them. --> {/if} {/snippet} {#snippet toolbar()} +
{#if showFooterLeftControls} -
+
{#if showContextPicker && !disabled} {#snippet trigger()} @@ -1385,11 +1387,11 @@ the panel, or the Escape-to-stop focus check would wrongly reject them. -->
{/if} {#if footerMessageShown} -
+
{:else} -
+
{#if chatHost.mode === AIMode.GLOBAL} {/if} diff --git a/frontend/src/lib/components/home/RecentRunRow.svelte b/frontend/src/lib/components/home/RecentRunRow.svelte index 6ffe8e4d98..066c61e244 100644 --- a/frontend/src/lib/components/home/RecentRunRow.svelte +++ b/frontend/src/lib/components/home/RecentRunRow.svelte @@ -1,8 +1,9 @@