fix: run squashed loop iterations as regular jobs (#12772)

* fix: run squashed loop iterations as regular jobs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test: cover squashed loops running iterations as regular jobs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ruben Fiszel
2026-12-01 05:14:55 +01:00
committed by GitHub
co-authored by Claude Opus 5.5
parent e44dfe5eb6
commit b4ca673a29
2 changed files with 17 additions and 10 deletions
+14 -6
View File
@@ -313,10 +313,10 @@ mod dedicated_worker_tests {
Ok(())
}
/// Test flow runners: a squashed for-loop spawns dedicated subprocesses.
/// A squashed for-loop runs each iteration as a regular job, not in a shared subprocess.
#[sqlx::test(fixtures("base", "dedicated_flows"))]
#[serial]
async fn test_dedicated_flow_runners(db: Pool<Postgres>) -> anyhow::Result<()> {
async fn test_squashed_loop_runs_iterations_as_jobs(db: Pool<Postgres>) -> anyhow::Result<()> {
initialize_tracing().await;
// Reset dedicated_workers in WORKER_CONFIG to avoid pollution from previous tests.
{
@@ -355,8 +355,17 @@ mod dedicated_worker_tests {
// for-loop over [1, 2, 3], each * 10 = [10, 20, 30]
assert_eq!(job.json_result().unwrap(), json!([10, 20, 30]));
// Verify the loop iterations ran on dedicated worker subprocesses
assert_ran_on_dedicated_worker(&db, job.id, "bun").await;
let in_subprocess: i64 = sqlx::query_scalar(
"WITH RECURSIVE t(id) AS (
SELECT $1::uuid UNION SELECT j.id FROM v2_job j JOIN t ON j.parent_job = t.id
)
SELECT count(*) FROM job_logs l JOIN t ON l.job_id = t.id
WHERE l.logs LIKE '%dedicated worker%'",
)
.bind(job.id)
.fetch_one(&db)
.await?;
assert_eq!(in_subprocess, 0);
Ok(())
}
@@ -732,8 +741,7 @@ mod dedicated_worker_tests {
Ok(())
}
/// Test a squashed for-loop with a bash step (unsupported for flow runners).
/// The bash step can't spawn a flow runner, so each iteration falls back to normal execution.
/// Test a squashed for-loop with a bash step.
#[sqlx::test(fixtures("base", "dedicated_flows"))]
#[serial]
async fn test_dedicated_flow_runners_unsupported_lang(
+3 -4
View File
@@ -6500,7 +6500,6 @@ async fn compute_next_flow_transform(
FlowModuleValue::WhileloopFlow {
modules,
modules_node,
squash,
skip_failures,
failure_threshold,
..
@@ -6536,7 +6535,7 @@ async fn compute_next_flow_transform(
};
let next_loop_idx = flow_jobs.len();
let start_runners = next_loop_idx == 0 && squash.unwrap_or(false);
let start_runners = false;
next_loop_iteration(
flow,
status,
@@ -6573,7 +6572,6 @@ async fn compute_next_flow_transform(
modules_node,
iterator,
parallel,
squash,
iteration_label,
skip_failures,
failure_threshold,
@@ -6659,7 +6657,8 @@ async fn compute_next_flow_transform(
ForLoopStatus::NextIteration(mut ns) => {
ns.iteration_label = iteration_label;
ns.failure_threshold = failure_threshold;
let start_runners = ns.index == 0 && squash.unwrap_or(false);
// A squashed loop runs each iteration as a regular job, like any other loop.
let start_runners = false;
next_loop_iteration(
flow,
status,