diff --git a/backend/windmill-api-inputs/src/history.rs b/backend/windmill-api-inputs/src/history.rs index 1a0c54390d..fc961094fe 100644 --- a/backend/windmill-api-inputs/src/history.rs +++ b/backend/windmill-api-inputs/src/history.rs @@ -261,10 +261,12 @@ fn inline_args(alias: &str) -> String { ) } -/// When the run `{id}` started, or NULL before it does. Every run inside it is created after -/// that, but a scheduled run is created a whole period before it starts, so its creation time -/// is no bound. A queued workflow-as-code run's `started_at` is its current segment's; its first -/// start is in `extras`. The queue and completed rows carry no row-level security: this also +/// When the run `{id}` started, or NULL before it does: a group's count is exact when its +/// top-level run started after the oldest run the list's window read. Its creation time would +/// leave a scheduled run's group inexact, since that run is created a whole period before it +/// starts. A queued workflow-as-code run's `started_at` is its current segment's; its first +/// start is in `extras`. After a zombie recovery it is the latest pull's, which can mark a +/// group exact too early. The queue and completed rows carry no row-level security: this also /// works for a run the viewer cannot read. fn run_start(id: &str) -> String { format!( @@ -790,7 +792,11 @@ pub(crate) async fn list_inside( top_run: Uuid, ) -> Result> { let categories: Vec<&str> = q.started_by.iter().map(|c| c.as_str()).collect(); - // The latest CAP runs since `top_run` started hold every run the list's window can count. + // The latest CAP runs since `top_run` was created hold every run the list's window can + // count. Its creation time is the bound that holds whatever happened since: its start is + // stamped again after a zombie recovery and on each workflow-as-code segment. The queue row + // has no row-level security, for a queued run the viewer cannot read; a completed one leaves + // the read unbounded, which the LIMIT still caps. // Only a script run has native retries, and a flow can have a loop's worth of children. let retry_gate = match q.runnable_type { RunnableType::FlowPath => "AND false", @@ -801,9 +807,10 @@ pub(crate) async fn list_inside( (SELECT id FROM v2_job \ WHERE workspace_id = $2 AND runnable_path = $1 AND parent_job IS NOT NULL \ AND kind = {inside_kind} \ - AND created_at >= COALESCE({start}, \ + AND created_at >= COALESCE(\ (SELECT created_at FROM v2_job WHERE id = $4 AND workspace_id = $2), \ - (SELECT created_at FROM v2_job_queue WHERE id = $4 AND workspace_id = $2)) \ + (SELECT created_at FROM v2_job_queue WHERE id = $4 AND workspace_id = $2), \ + '-infinity') \ ORDER BY created_at DESC LIMIT $7) \ UNION \ SELECT x.id FROM v2_job x JOIN native_retry_attempt n ON n.job_id = x.id \ @@ -848,7 +855,6 @@ pub(crate) async fn list_inside( classify = classify_inside(q.runnable_type), state = run_state("s"), args = inline_args("s"), - start = run_start("$4"), ); let rows = sqlx::query_as::<_, InsideRow>(&sql) .bind(q.path) diff --git a/backend/windmill-api-integration-tests/tests/inputs.rs b/backend/windmill-api-integration-tests/tests/inputs.rs index 3f7a33c43d..256cd6ef38 100644 --- a/backend/windmill-api-integration-tests/tests/inputs.rs +++ b/backend/windmill-api-integration-tests/tests/inputs.rs @@ -427,23 +427,22 @@ async fn test_input_history_started_by(db: Pool) -> anyhow::Result<()> sqlx::query("ANALYZE v2_job, v2_job_completed") .execute(&db) .await?; - // A workflow-as-code run in a later segment: its queue row's start is the segment's, and its - // first start is in extras. Opening its group must still find an earlier segment's task. - let workflow = insert_run( + // A run whose start was stamped again, as the pull after a zombie recovery does: opening its + // group must still find the call it made before. + let restarted = insert_run( &db, - Run { path: "f/test/workflow", running: true, at: 24, ..Run::default() }, + Run { path: "f/test/restarted", running: true, at: 24, ..Run::default() }, ) .await?; - let task = insert_run( + let early_call = insert_run( &db, - Run { path: "f/test/task", parent_job: Some(workflow), at: 25, ..Run::default() }, + Run { path: "f/test/task", parent_job: Some(restarted), at: 25, ..Run::default() }, ) .await?; sqlx::query( - "UPDATE v2_job_queue SET started_at = started_at + interval '5 seconds', \ - extras = jsonb_build_object('wac_first_started_at', started_at) WHERE id = $1", + "UPDATE v2_job_queue SET started_at = started_at + interval '5 seconds' WHERE id = $1", ) - .bind(workflow) + .bind(restarted) .execute(&db) .await?; let mut late_calls = vec![]; @@ -560,9 +559,9 @@ async fn test_input_history_started_by(db: Pool) -> anyhow::Result<()> assert_eq!(retried[0]["group"]["retries"], 1); let opened = fetch("SECRET_TOKEN", format!("{manual}&top_run={failed_call}")).await?; assert_eq!(ids(&opened), [retried_call.to_string()]); - let calls = format!("&runnable_id=f/test/task&started_by=script_call&top_run={workflow}"); + let calls = format!("&runnable_id=f/test/task&started_by=script_call&top_run={restarted}"); let opened = fetch("SECRET_TOKEN", calls).await?; - assert_eq!(ids(&opened), [task.to_string()]); + assert_eq!(ids(&opened), [early_call.to_string()]); let opened = fetch("SECRET_TOKEN", format!("{busy}&top_run={long_flow}")).await?; assert_eq!( ids(&opened),