diff --git a/backend/tests/workspace_job_pause.rs b/backend/tests/workspace_job_pause.rs index a232421e54..d3e5eb2ede 100644 --- a/backend/tests/workspace_job_pause.rs +++ b/backend/tests/workspace_job_pause.rs @@ -135,7 +135,8 @@ async fn pause_holds_and_resume_releases(db: Pool) -> anyhow::Result<( })) .send() .await?; - assert_eq!(resp.status(), 201, "{}", resp.text().await?); + assert_eq!(resp.status(), 201); + let obo_hash = resp.text().await?; let admin_obo = job_id( post(format!("{ws}/jobs/run/p/u/test-user/obo_member"), ADMIN) .json(&json!({})) @@ -144,6 +145,14 @@ async fn pause_holds_and_resume_releases(db: Pool) -> anyhow::Result<( ) .await; assert_eq!(kind_and_due(&db, admin_obo).await.0, "script"); + let admin_obo_hash = job_id( + post(format!("{ws}/jobs/run/h/{obo_hash}"), ADMIN) + .json(&json!({})) + .send() + .await?, + ) + .await; + assert_eq!(kind_and_due(&db, admin_obo_hash).await.0, "script"); // A caller waiting for the result is refused rather than left waiting. let resp = post( diff --git a/backend/windmill-api-workspaces/src/job_pause.rs b/backend/windmill-api-workspaces/src/job_pause.rs index 39c72bf942..73bc1aaff3 100644 --- a/backend/windmill-api-workspaces/src/job_pause.rs +++ b/backend/windmill-api-workspaces/src/job_pause.rs @@ -42,7 +42,10 @@ struct JobsPaused { pause_id: Uuid, } -async fn read_pause(db: &DB, w_id: &str) -> windmill_common::error::Result> { +async fn read_pause<'c, E: sqlx::PgExecutor<'c>>( + db: E, + w_id: &str, +) -> windmill_common::error::Result> { Ok(sqlx::query_as!( JobsPaused, r#"SELECT paused_until, paused_by, paused_at, reason, pause_id, @@ -140,6 +143,8 @@ async fn pause_jobs( ), ) .await?; + // Read before the commit releases the lock: a later pause would hand this one its `pause_id`. + let pause = read_pause(&mut *tx, &w_id).await?; tx.commit().await?; job_pause::evict(&w_id); @@ -149,7 +154,7 @@ async fn pause_jobs( }; log_feature_usage("workspace_job_pause", "paused", source); - Ok(Json(read_pause(&db, &w_id).await?)) + Ok(Json(pause)) } #[derive(Deserialize, Default)] diff --git a/backend/windmill-api/src/jobs.rs b/backend/windmill-api/src/jobs.rs index db5ea19b06..8b64be12ff 100644 --- a/backend/windmill-api/src/jobs.rs +++ b/backend/windmill-api/src/jobs.rs @@ -10856,37 +10856,42 @@ pub async fn run_job_by_hash_inner( let end_user_email = run_end_user_email(&db, &w_id, &authed, trigger.as_ref()).await?; let scope_ceiling = windmill_api_auth::caller_scope_ceiling(&db, &authed).await?; - let (uuid, tx) = push( - &db, - tx, - &w_id, - job_payload, - push_args, - authed.display_username(), - email, - permissioned_as, - authed.token_prefix.as_deref(), - authed.username_override.as_deref(), - scheduled_for, - None, - run_query.parent_job, - None, - run_query.root_job, - run_query.job_id, - false, - false, - None, - !run_query.invisible_to_owner.unwrap_or(false), - tag, - timeout, - None, - None, - push_authed.as_ref(), - false, - end_user_email, - authed.trigger_or_fallback(trigger), - run_query.suspended_mode, - scope_ceiling.as_deref(), + // `push` gets no `authed` for an on-behalf-of run, so it cannot see an admin started it. + let admin_direct_obo = push_authed.is_none() && authed.is_admin && trigger.is_none(); + let (uuid, tx) = windmill_common::job_pause::exempt_if( + admin_direct_obo, + push( + &db, + tx, + &w_id, + job_payload, + push_args, + authed.display_username(), + email, + permissioned_as, + authed.token_prefix.as_deref(), + authed.username_override.as_deref(), + scheduled_for, + None, + run_query.parent_job, + None, + run_query.root_job, + run_query.job_id, + false, + false, + None, + !run_query.invisible_to_owner.unwrap_or(false), + tag, + timeout, + None, + None, + push_authed.as_ref(), + false, + end_user_email, + authed.trigger_or_fallback(trigger), + run_query.suspended_mode, + scope_ceiling.as_deref(), + ), ) .await?; tx.commit().await?;