From 815aa22f9b09f99c7869864c573468282129b470 Mon Sep 17 00:00:00 2001 From: repo-worker-code-k Date: Mon, 9 Nov 2026 20:38:50 -0600 Subject: [PATCH 1/2] =?UTF-8?q?feat(queue):=20#8097=20Rules=201+2=20?= =?UTF-8?q?=E2=80=94=20no-id=20handoff=20pick,=20optional=20platform=20sel?= =?UTF-8?q?ector?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rule 1: lanes never need to block/claim by task id in the default flow. The broker gains a pick mode (pick=parked_handoff, CLI claim --handoff): the BROKER picks the next parked recorded opencode handoff; the caller names no id. The opencode claimant collects parked handoffs exclusively through it. claim --task stays as the explicit special-case verb (one-off revivals). Rule 2: tasks gain an optional platform column (additive ALTER in ensure_schema; existing rows NULL = unset). Enqueue accepts it optionally (CLI --platform, or the packet field); every claim path enforces it: a set item is claimable only by a claim declaring the same family (openchamber|muse); undeclared claims keep exactly their old reach (unset items only). By-id claims honor the selector too. The selector names a family, never a lane, and is never required. --- pkgs/fleet/crates/fleet-queue/src/client.rs | 65 +- .../crates/fleet-queue/src/turso_queue.rs | 670 ++++++++++++------ pm-stack/opencode-claimant/claimant.py | 126 ++-- pm-stack/opencode-claimant/prompt.md | 23 +- pm-stack/opencode-claimant/test_claimant.py | 53 ++ 5 files changed, 636 insertions(+), 301 deletions(-) diff --git a/pkgs/fleet/crates/fleet-queue/src/client.rs b/pkgs/fleet/crates/fleet-queue/src/client.rs index 2e284c3417..acdf4e97e8 100644 --- a/pkgs/fleet/crates/fleet-queue/src/client.rs +++ b/pkgs/fleet/crates/fleet-queue/src/client.rs @@ -1020,6 +1020,18 @@ fn validate_via_broker(packet: &Value, quiet: bool) -> Vec { // Subcommands // --------------------------------------------------------------------------- +/// #8097 Rule 2: a --platform value is a coarse FAMILY selector, +/// never a lane name: exactly "openchamber" or "muse". Shared by +/// the enqueue and claim verbs so both spell the rule once. +fn platform_flag(v: &str) -> Result { + match v { + "openchamber" | "muse" => Ok(v.to_string()), + other => Err(format!( + "invalid --platform {other:?} (expected \"openchamber\" or \"muse\")" + )), + } +} + fn cmd_validate(rest: &[String]) -> i32 { let args = parse_args(rest, &[], &[]); reject_extra_pos("validate", &args, 1); @@ -1070,7 +1082,7 @@ fn resolve_enqueue_queue( } fn cmd_enqueue(rest: &[String]) -> i32 { - let args = parse_args(rest, &["queue"], &["dry-run", "shadow-intent"]); + let args = parse_args(rest, &["queue", "platform"], &["dry-run", "shadow-intent"]); reject_extra_pos("enqueue", &args, 1); let path = args .pos @@ -1089,6 +1101,15 @@ fn cmd_enqueue(rest: &[String]) -> i32 { Ok(q) => q, Err(e) => die(2, &e), }; + // #8097 Rule 2: the platform selector is optional; when given + // it restricts the item to that family. Absent = unset. + let platform = match args.get("platform") { + None => None, + Some(p) => match platform_flag(&p) { + Ok(v) => Some(v), + Err(e) => die(2, &e), + }, + }; let shadow_intent = args.has("shadow-intent"); if queue.ends_with("-shadow") && !shadow_intent { die( @@ -1104,7 +1125,7 @@ fn cmd_enqueue(rest: &[String]) -> i32 { "/enqueue", &json!({ "packet": packet, "queue": queue, "dry_run": dry_run, - "shadow_intent": shadow_intent, + "shadow_intent": shadow_intent, "platform": platform, }), ); let resp = unwrap_ok(resp); @@ -1247,7 +1268,18 @@ fn cmd_list(rest: &[String]) -> i32 { } fn cmd_claim(rest: &[String]) -> i32 { - let args = parse_args(rest, &["queue", "worker", "lease-seconds", "lane", "task"], &[]); + let args = parse_args( + rest, + &[ + "queue", + "worker", + "lease-seconds", + "lane", + "task", + "platform", + ], + &["handoff"], + ); reject_extra_pos("claim", &args, 0); let worker = opt_worker(&args); let mut body = json!({ @@ -1258,6 +1290,23 @@ fn cmd_claim(rest: &[String]) -> i32 { if let Some(lane) = args.get("lane") { body["lane"] = json!(lane); } + // --platform : declare this claim's family (#8097 + // Rule 2). The broker only hands this claim items whose + // platform selector is unset or equal to it. A claim that + // declares no family keeps its pre-#8097 reach (unset items). + if let Some(p) = args.get("platform") { + match platform_flag(&p) { + Ok(v) => body["platform"] = json!(v), + Err(e) => die(2, &e), + } + } + // --handoff: the no-id collection of the next parked recorded + // opencode handoff (#8097 Rule 1) — the claimant's default + // parked-handoff path. The BROKER picks the row; the caller + // names no task id. (--task remains the special-case claim.) + if args.has("handoff") { + body["pick"] = json!("parked_handoff"); + } // --task : by-id claim — take exactly that row when the // broker's by-id predicate allows it (a queued row under the // ordinary predicate, or a parked recorded opencode handoff). @@ -1912,6 +1961,16 @@ mod tests { use super::*; use proptest::prelude::*; + #[test] + fn platform_flag_accepts_only_the_two_families() { + // #8097 Rule 2: the selector is a coarse family, never a + // lane name — a lane id as --platform is a usage error. + assert_eq!(platform_flag("openchamber"), Ok("openchamber".to_string())); + assert_eq!(platform_flag("muse"), Ok("muse".to_string())); + assert!(platform_flag("code-a").is_err()); + assert!(platform_flag("").is_err()); + } + #[test] fn fallback_switch_json_shape() { let v = fallback_switch_json("/claim", 4, "store down"); diff --git a/pkgs/fleet/crates/fleet-queue/src/turso_queue.rs b/pkgs/fleet/crates/fleet-queue/src/turso_queue.rs index 783eb69bd7..cddb831e3a 100644 --- a/pkgs/fleet/crates/fleet-queue/src/turso_queue.rs +++ b/pkgs/fleet/crates/fleet-queue/src/turso_queue.rs @@ -59,7 +59,7 @@ pub const DEFAULT_TURSO_URL: &str = "https://fleet-queue-dezren39.aws-us-east-1. pub const TURSO_TOKEN_SECRET_NAME: &str = "turso.fleet-queue-rw-token"; const TASK_COLS: &str = "id, queue, title, body, payload, dedupe_key, priority, status, \ - not_before, worker_id, claimed_at, lease_until, lane_id, attempts, max_attempts, \ + not_before, worker_id, claimed_at, lease_until, lane_id, platform, attempts, max_attempts, \ progress, result, last_error, park_kind, wait_kind, ready_condition, \ last_checked_at, check_outcome, created_at, updated_at, completed_at"; const LEDGER_COLS: &str = "id, queue, task_id, assigned_lane, executed_lane, \ @@ -317,17 +317,16 @@ impl TursoBackend { } fn exec(&self, sql: &str, args: &[Arg]) -> Result { - Ok(self.pipeline(&[(sql, args.to_vec())])?.into_iter().next().unwrap()) + Ok(self + .pipeline(&[(sql, args.to_vec())])? + .into_iter() + .next() + .unwrap()) } /// Rows of one SELECT as JSON objects, with the given TEXT /// columns parsed back into JSON values. - fn query_objs( - &self, - sql: &str, - args: &[Arg], - json_cols: &[&str], - ) -> Result, TErr> { + fn query_objs(&self, sql: &str, args: &[Arg], json_cols: &[&str]) -> Result, TErr> { let r = self.exec(sql, args)?; Ok(r.rows .iter() @@ -350,6 +349,17 @@ impl TursoBackend { pub fn ensure_schema(&self) -> Result<(), TErr> { let stmts: Vec<(&str, Vec)> = SCHEMA.iter().map(|s| (*s, Vec::new())).collect(); self.pipeline(&stmts)?; + // #8097 Rule 2: tasks.platform (the optional coarse platform + // selector) — databases created before the column landed + // gain it here. Existing rows read NULL (unset: either + // family may claim them); no backfill, nothing destructive. + let cols = self.query_objs("SELECT name FROM pragma_table_info('tasks')", &[], &[])?; + let has_platform = cols + .iter() + .any(|c| c.get("name").and_then(|v| v.as_str()) == Some("platform")); + if !has_platform { + self.exec("ALTER TABLE tasks ADD COLUMN platform TEXT", &[])?; + } Ok(()) } } @@ -373,7 +383,7 @@ const SCHEMA: [&str; 12] = [ payload TEXT NOT NULL DEFAULT '{}', dedupe_key TEXT, \ priority INTEGER, status TEXT NOT NULL DEFAULT 'queued', \ not_before TEXT, worker_id TEXT, claimed_at TEXT, lease_until TEXT, \ - lane_id TEXT, attempts INTEGER NOT NULL DEFAULT 0, \ + lane_id TEXT, platform TEXT, attempts INTEGER NOT NULL DEFAULT 0, \ max_attempts INTEGER NOT NULL DEFAULT 4, \ progress TEXT NOT NULL DEFAULT '{}', result TEXT NOT NULL DEFAULT '{}', \ last_error TEXT, park_kind TEXT, wait_kind TEXT, ready_condition TEXT, \ @@ -467,9 +477,7 @@ fn get_task(t: &TursoBackend, id: i64) -> Result, TErr> { fn get_ledger(t: &TursoBackend, task_id: i64) -> Result, TErr> { let rows = t.query_objs( - &format!( - "SELECT {LEDGER_COLS} FROM repo_task_lane_ledger WHERE task_id = ?" - ), + &format!("SELECT {LEDGER_COLS} FROM repo_task_lane_ledger WHERE task_id = ?"), &[Arg::Int(task_id)], &[], )?; @@ -500,9 +508,7 @@ fn event( /// Parse an /events-append request: kind is required and must be a /// non-empty string; worker_id/task_id optional (the PG stream's /// non-queue writers always wrote task_id NULL); detail defaults {}. -fn parse_event_append( - req: &Value, -) -> Result<(Option, Option, String, Value), String> { +fn parse_event_append(req: &Value) -> Result<(Option, Option, String, Value), String> { let kind = req_str(req, "kind") .map(str::trim) .filter(|k| !k.is_empty()) @@ -732,9 +738,7 @@ fn revalidate_parked( target_status = trow .into_iter() .next() - .and_then(|r| { - r.get("status").and_then(|v| v.as_str()).map(str::to_string) - }); + .and_then(|r| r.get("status").and_then(|v| v.as_str()).map(str::to_string)); } } Some("event_seen") => { @@ -1223,11 +1227,7 @@ fn record_execution(t: &TursoBackend, req: &Value, row: &Value) -> Result