diff --git a/backend/ee-repo-ref.txt b/backend/ee-repo-ref.txt index 40a56983ff508..7ace64b50eb3f 100644 --- a/backend/ee-repo-ref.txt +++ b/backend/ee-repo-ref.txt @@ -1 +1 @@ -cac1d382a7c22e8a4e9c56832ad12d11de5bba7f +57c9ae5b1b5c594fcdd9b398052a24006a367117 diff --git a/backend/windmill-queue/src/jobs.rs b/backend/windmill-queue/src/jobs.rs index 6623eff4185fd..12034de7bb20e 100644 --- a/backend/windmill-queue/src/jobs.rs +++ b/backend/windmill-queue/src/jobs.rs @@ -4992,10 +4992,10 @@ pub async fn pull( }; if let Some(job) = job.as_ref() { - if (job.is_flow() || job.is_dependency()) - && !(job.kind.is_preview() - && PREVIEW_TAGS_OVERRIDE.load(std::sync::atomic::Ordering::Relaxed)) - { + // An agent worker cannot drive a flow, so a flow preview on an agent's tag is + // requeued too, preview tags override or not: the job keeps its tag in v2_job + // for its steps. + if job.is_flow() || job.is_dependency() { let tag = match configured_dependency_job_tag( &job.kind, job.script_lang.as_ref(), diff --git a/backend/windmill-queue/tests/custom_query_flow_requeue_test.rs b/backend/windmill-queue/tests/custom_query_flow_requeue_test.rs new file mode 100644 index 0000000000000..a12c2c7332e2c --- /dev/null +++ b/backend/windmill-queue/tests/custom_query_flow_requeue_test.rs @@ -0,0 +1,81 @@ +//! A flow job pulled through a caller's own query (an agent worker's) is handed to the generic +//! flow tag, flow previews under the preview tag override included: an agent cannot drive a flow. +//! +//! Run with: +//! cargo test -p windmill-queue --test custom_query_flow_requeue_test + +use std::collections::HashMap; +use std::sync::atomic::Ordering; + +use sqlx::{Pool, Postgres}; +use windmill_common::jobs::JobPayload; +use windmill_common::worker::{make_pull_query, PREVIEW_TAGS_OVERRIDE}; +use windmill_queue::{pull, push, PushArgs, PushIsolationLevel}; + +#[sqlx::test(migrations = "../migrations", fixtures("base"))] +async fn flow_preview_on_an_agent_tag_goes_to_the_flow_tag(db: Pool) { + PREVIEW_TAGS_OVERRIDE.store(true, Ordering::Relaxed); + + let payload = JobPayload::RawFlow { + value: serde_json::from_value(serde_json::json!({ "modules": [] })).unwrap(), + path: None, + restarted_from: None, + }; + let args = HashMap::new(); + let (id, tx) = push( + &db, + PushIsolationLevel::IsolatedRoot(db.clone()), + "test-workspace", + payload, + PushArgs { extra: None, args: &args }, + "test-user", + "test@windmill.dev", + "u/test-user".to_string(), + None, + None, + None, + None, + None, + None, + None, + None, + false, + false, + None, + true, + Some("agentx".to_string()), + None, + None, + None, + None, + false, + None, + None, + None, + None, + ) + .await + .expect("push"); + tx.commit().await.expect("commit push"); + + let query = (String::new(), make_pull_query(&["agentx".to_string()])); + let pulled = pull(&db, false, "ag-test", Some(&query)) + .await + .expect("pull"); + assert!(pulled.job.is_none(), "an agent must not receive a flow job"); + + let (queue_tag, running): (String, bool) = + sqlx::query_as("SELECT tag, running FROM v2_job_queue WHERE id = $1") + .bind(id) + .fetch_one(&db) + .await + .unwrap(); + assert_eq!((queue_tag.as_str(), running), ("flow", false)); + // Its steps inherit this one. + let job_tag: String = sqlx::query_scalar("SELECT tag FROM v2_job WHERE id = $1") + .bind(id) + .fetch_one(&db) + .await + .unwrap(); + assert_eq!(job_tag, "agentx"); +} diff --git a/backend/windmill-worker/src/worker.rs b/backend/windmill-worker/src/worker.rs index c482caac603c3..6007928242272 100644 --- a/backend/windmill-worker/src/worker.rs +++ b/backend/windmill-worker/src/worker.rs @@ -5312,7 +5312,7 @@ pub async fn handle_queued_job( Ok(JobOutcome::Completed) } else { return Err(Error::internal_err( - "Could not handle flow job with agent worker".to_string(), + "Agent workers do not run flow jobs: the server hands a flow on an agent's tag to a regular worker serving the flow tag".to_string(), )); } } else {