From 195bedfd51306383b7c110f26ce5eb1ec266166b Mon Sep 17 00:00:00 2001 From: felix Date: Sun, 22 Nov 2026 07:14:05 +0000 Subject: [PATCH 1/2] feat(fleet-queue): select the enqueue row priority from Drew's #7030 label bands MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit task_from_packet copied the packet's stated priority verbatim, and no label→band mapping existed anywhere in the enqueue path — the 90/70 values of the inverted 2026-10-29 design (expedite ⇒ 90) were produced by machinery outside it, and the broker's priority-ASC claim order reads them as last. Now, when the payload's labels array (the array the claim filter's label field already reads) carries Drew's labels, the band is the selected row priority: expedite ⇒ 15 (the ratified 10–20 band value), next-up ⇒ 25 (the ratified 20–30 band value) — the exact stored values Drew ratified on 2026-11-07, deliberately off PRIORITY_SCALE, which constrains stated values only. Expedite outranks next-up when both are present. Unlabeled packets keep their stated priority (or null) byte-for-byte. --- pkgs/fleet/crates/fleet-queue/src/validate.rs | 51 ++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/pkgs/fleet/crates/fleet-queue/src/validate.rs b/pkgs/fleet/crates/fleet-queue/src/validate.rs index d5a2e11bb7..9bc4f7a183 100644 --- a/pkgs/fleet/crates/fleet-queue/src/validate.rs +++ b/pkgs/fleet/crates/fleet-queue/src/validate.rs @@ -47,11 +47,28 @@ //! the two statements is tracked on #9029. The inventory that //! dispositioned every forwarded field, client flag, and broker //! verb parameter against this contract is recorded on #6449. +//! +//! One row-level selection sits downstream of this contract: +//! task_from_packet derives the stored priority from the payload's +//! labels when Drew's #7030 labels are present (expedite ⇒ 15, +//! next-up ⇒ 25 — the ratified stored bands, deliberately off the +//! stated-value scale above). The packet's stated priority is +//! validated here exactly as before, and stands whenever neither +//! label is present. use serde_json::{Value, json}; use std::time::{SystemTime, UNIX_EPOCH}; pub const PRIORITY_SCALE: [i64; 7] = [10, 20, 30, 40, 50, 70, 90]; +/// #7030: Drew's ratified label bands (ratified 2026-11-07): an issue +/// carrying the `expedite` label queues at priority 15 (the 10–20 +/// band) and one carrying `next-up` at 25 (the 20–30 band). These are +/// the ratified *stored* values — deliberately not on PRIORITY_SCALE, +/// which constrains what a packet may state; the broker claims by +/// the stored row (priority ASC), and stored expedite rows already +/// read back at 15/25. task_from_packet performs the selection. +pub const EXPEDITE_PRIORITY: i64 = 15; +pub const NEXT_UP_PRIORITY: i64 = 25; pub const KINDS: [&str; 5] = [ "pr_shepherd", "triage", @@ -1085,6 +1102,24 @@ pub fn validate_packet(packet: &Value) -> (Vec, Vec) { (errors, warnings) } +/// The #7030 band a payload's labels select, if any. An issue task +/// carries its GitHub labels in the payload's `labels` array — the +/// same array the claim filter's label field reads. `expedite` +/// outranks `next-up` when a packet somehow carries both. Parsing is +/// tolerant, mirroring the claim filter: a non-array `labels` value +/// or non-string entries select nothing. +fn label_band_priority(payload: &Value) -> Option { + let labels = payload.get("labels")?.as_array()?; + let has = |name: &str| labels.iter().any(|l| l.as_str() == Some(name)); + if has("expedite") { + Some(EXPEDITE_PRIORITY) + } else if has("next-up") { + Some(NEXT_UP_PRIORITY) + } else { + None + } +} + /// task_from_packet: the agent.tasks row shape the enqueue RPC takes. pub fn task_from_packet(packet: &Value, queue: &str) -> Value { let mut payload = packet.get("payload").cloned().unwrap_or(json!({})); @@ -1148,13 +1183,27 @@ pub fn task_from_packet(packet: &Value, queue: &str) -> Value { ); } } + // #7030: Drew's labels state his claim order directly, so when + // the payload carries `expedite` / `next-up` the label band is + // the selected row priority — this row is the single source of + // truth, exactly as for max_attempts above — and the packet's + // stated priority stands only when neither label is present. + // (Stated values for labelled issues were historically produced + // by machinery applying the inverted 2026-10-29 mapping, + // expedite ⇒ 90, which the broker's priority-ASC claim order + // reads as last; the label is Drew's signal, the stated number + // is that machinery's output.) + let priority = match label_band_priority(&payload) { + Some(band) => json!(band), + None => packet.get("priority").cloned().unwrap_or(Value::Null), + }; json!({ "queue": queue, "title": packet.get("title").cloned().unwrap_or(Value::Null), "body": packet.get("body").cloned().unwrap_or(Value::Null), "payload": payload, "dedupe_key": packet.get("dedupe_key").cloned().unwrap_or(Value::Null), - "priority": packet.get("priority").cloned().unwrap_or(Value::Null), + "priority": priority, "not_before": packet.get("not_before").cloned().unwrap_or(Value::Null), "max_attempts": max_attempts, "required_budget_minutes": required_budget, From bc3f662a1761eef7d6cb59dae5fe5dbeeca6c072 Mon Sep 17 00:00:00 2001 From: felix Date: Sun, 22 Nov 2026 07:14:05 +0000 Subject: [PATCH 2/2] =?UTF-8?q?test(fleet-queue):=20#7030=20oracle=20?= =?UTF-8?q?=E2=80=94=20label=20bands=20select=20the=20row=20priority?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Acceptance oracle, quoted in the test: an expedited issue's task reads in the 10–20 band in the Turso store. Covers expedite (15, superseding a stated 90), next-up (25), both-labels precedence, unrelated/absent labels leaving the stated priority untouched, and the labeled/unstated and unlabeled/unstated cases. Verified fail-before: on the base commit with only the selection reverted, the expedite case reads back 90 instead of 15. --- pkgs/fleet/crates/fleet-queue/src/validate.rs | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/pkgs/fleet/crates/fleet-queue/src/validate.rs b/pkgs/fleet/crates/fleet-queue/src/validate.rs index 9bc4f7a183..63f9b7c301 100644 --- a/pkgs/fleet/crates/fleet-queue/src/validate.rs +++ b/pkgs/fleet/crates/fleet-queue/src/validate.rs @@ -1296,6 +1296,62 @@ mod tests { assert_eq!(task_from_packet(&packet, "q")["max_attempts"], 7); } + #[test] + fn label_bands_select_row_priority_7030() { + // #7030 oracle (the issue's acceptance line): "Label mapping + // flipped and verified by readback: an expedited issue's task + // reads in the 10–20 band in the Turso store". The row + // task_from_packet builds is what the store reads back, so + // the oracle is decided here. Drew ratified the exact stored + // values on 2026-11-07: expedite = 15 (10–20 band), + // next-up = 25 (20–30 band). + let payload = payload_with(json!({"issue": {"number": 7030}})); + // The stated 90 is the inverted mapping's expedite value: + // valid on the design scale, and exactly what the label must + // supersede. + let base = json!({"title": "test", "priority": 90, "payload": payload}); + + // Expedite: the band is selected over the stated priority + // and reads back inside 10..=20. + let mut packet = base.clone(); + packet["payload"]["labels"] = json!(["expedite"]); + let row = task_from_packet(&packet, "q"); + assert_eq!(row["priority"], EXPEDITE_PRIORITY); + assert!((10..=20).contains(&row["priority"].as_i64().unwrap())); + + // Next-up: the 20..=30 band, ratified stored value 25. + packet["payload"]["labels"] = json!(["next-up"]); + let row = task_from_packet(&packet, "q"); + assert_eq!(row["priority"], NEXT_UP_PRIORITY); + assert!((20..=30).contains(&row["priority"].as_i64().unwrap())); + + // Both labels present: expedite outranks next-up. + packet["payload"]["labels"] = json!(["next-up", "expedite"]); + assert_eq!( + task_from_packet(&packet, "q")["priority"], + EXPEDITE_PRIORITY + ); + + // Unrelated labels, then no labels at all: the stated + // priority is untouched. + packet["payload"]["labels"] = json!(["queue/queued"]); + assert_eq!(task_from_packet(&packet, "q")["priority"], 90); + packet["payload"].as_object_mut().unwrap().remove("labels"); + assert_eq!(task_from_packet(&packet, "q")["priority"], 90); + + // Unlabeled and unstated: priority stays null, as before. + let mut packet = base.clone(); + packet.as_object_mut().unwrap().remove("priority"); + assert!(task_from_packet(&packet, "q")["priority"].is_null()); + + // Labeled and unstated: the band still selects the row value. + packet["payload"]["labels"] = json!(["expedite"]); + assert_eq!( + task_from_packet(&packet, "q")["priority"], + EXPEDITE_PRIORITY + ); + } + #[test] fn implementation_repo_validates_explicit_target() { // Oracle: an optional owner/name target, not an issue-repo allowlist.