diff --git a/pkgs/fleet/crates/fleet-queue/src/queue_broker.rs b/pkgs/fleet/crates/fleet-queue/src/queue_broker.rs index 73049a4e25..6fca93daf8 100644 --- a/pkgs/fleet/crates/fleet-queue/src/queue_broker.rs +++ b/pkgs/fleet/crates/fleet-queue/src/queue_broker.rs @@ -1183,9 +1183,16 @@ fn dispatch(st: &State, path: &str, req: &Value) -> Value { }; let offset = crate::client::list_offset_or_default(req.get("offset").and_then(|o| o.as_i64())); + // #9420 parity with the Turso verb_list: omit the queue + // predicate when no queue is named (queue=eq. with an + // empty value matches nothing and breaks exact readback). + let queue_pred = if queue.is_empty() { + String::new() + } else { + format!("&queue=eq.{}", quote(queue, "")) + }; let mut path = format!( - "tasks?select={select}&queue=eq.{}&order=priority.asc,created_at.asc,id.asc&limit={limit}&offset={offset}", - quote(queue, "") + "tasks?select={select}{queue_pred}&order=priority.asc,created_at.asc,id.asc&limit={limit}&offset={offset}" ); // #7871: --task narrows to one task id, so a worker can // verify a single recent completion from list output @@ -1196,6 +1203,10 @@ fn dispatch(st: &State, path: &str, req: &Value) -> Value { if let Some(s) = req.get("status").and_then(|s| s.as_str()) { path += &format!("&status=eq.{}", quote(s, "")); } + // #9420: dedupe_key narrows to the task carrying that key. + if let Some(d) = req.get("dedupe_key").and_then(|d| d.as_str()) { + path += &format!("&dedupe_key=eq.{}", quote(d, "")); + } if let Some(nb) = req.get("not_before").and_then(|s| s.as_str()) { path += &format!("&or=(not_before.is.null,not_before.lte.{})", quote(nb, ":")); } diff --git a/pkgs/fleet/crates/fleet-queue/src/turso_queue.rs b/pkgs/fleet/crates/fleet-queue/src/turso_queue.rs index 4594c0ada1..922c13a2bd 100644 --- a/pkgs/fleet/crates/fleet-queue/src/turso_queue.rs +++ b/pkgs/fleet/crates/fleet-queue/src/turso_queue.rs @@ -6424,8 +6424,16 @@ fn verb_list(t: &TursoBackend, req: &Value) -> Value { } else { "id, queue, title, priority, status, dedupe_key, created_at, not_before, platform" }; - let mut sql = format!("SELECT {select} FROM tasks WHERE queue = ?"); - let mut args: Vec = vec![Arg::Text(queue)]; + // #9420: the queue predicate applies only when a queue is named; + // an unnamed queue must not become `queue = ''`, which by + // construction returns zero rows and breaks exact-task readback + // ({"task": id} / {"dedupe_key": key} with no queue). + let mut sql = format!("SELECT {select} FROM tasks WHERE 1 = 1"); + let mut args: Vec = vec![]; + if !queue.is_empty() { + sql += " AND queue = ?"; + args.push(Arg::Text(queue)); + } if let Some(s) = req_str(req, "status") { sql += " AND status = ?"; args.push(Arg::Text(s.to_string())); @@ -6451,6 +6459,12 @@ fn verb_list(t: &TursoBackend, req: &Value) -> Value { sql += " AND id = ?"; args.push(Arg::Int(id)); } + // #9420: dedupe_key narrows to the task carrying that key (the + // delivery publisher's enqueue readback verifies by dedupe key). + if let Some(d) = req_str(req, "dedupe_key") { + sql += " AND dedupe_key = ?"; + args.push(Arg::Text(d.to_string())); + } let offset = crate::client::list_offset_or_default(req_i64(req, "offset")); sql += &format!( " ORDER BY (priority IS NULL), priority ASC, created_at ASC, id ASC LIMIT {limit} OFFSET {offset}" @@ -7762,6 +7776,36 @@ mod tests { ); } + #[test] + fn list_exact_readback_filters_9420() { + // #9420 oracle: exact-task readback works on the Turso + // verb_list — the task filter, a dedupe_key filter, and a + // queue predicate that applies only when a queue is named (an + // unnamed queue must not degenerate into queue = ''). The + // PostgREST /list handler carries the same contract. + let src = include_str!("turso_queue.rs"); + let seg = seg8217(src, "fn verb_list(", "\nfn verb_health"); + assert!(seg.contains("req_i64(req, \"task\")"), "task filter present"); + assert!(seg.contains("AND id = ?"), "task filter narrows by id"); + assert!( + seg.contains("req_str(req, \"dedupe_key\")") && seg.contains("AND dedupe_key = ?"), + "dedupe_key filter present" + ); + assert!( + seg.contains("if !queue.is_empty()"), + "queue predicate is conditional on a named queue" + ); + let broker = include_str!("queue_broker.rs"); + assert!( + broker.contains("dedupe_key=eq."), + "PostgREST /list applies the dedupe_key filter" + ); + assert!( + broker.contains("queue_pred"), + "PostgREST /list omits the queue predicate when unnamed" + ); + } + #[test] fn stack_storage_wiring_8582() { // Source oracle for increment 2 of #8582: the schema applies