diff --git a/pkgs/fleet/crates/fleet-agent/src/next.rs b/pkgs/fleet/crates/fleet-agent/src/next.rs index dee6175bd..eba466c39 100644 --- a/pkgs/fleet/crates/fleet-agent/src/next.rs +++ b/pkgs/fleet/crates/fleet-agent/src/next.rs @@ -393,6 +393,33 @@ pub(super) fn default_lane(agent: &str) -> String { ) } +/// The broker binds registered lanes to workers. Agent names identify +/// the mailbox, but a known lane may belong to a shared queue worker +/// (for example `code-i` belongs to `repo-worker-code`). +fn registered_lane_worker(lane: &str) -> Option<&'static str> { + if matches!(lane, "not-code-a" | "not-code-g") { + return Some("repo-worker-nix"); + } + if matches!(lane, "not-code-b" | "not-code-e") { + return Some("repo-worker-opencode"); + } + if lane == "not-code-d" { + return Some("repo-worker-openchamber"); + } + + let (family, suffix) = lane.rsplit_once('-')?; + if suffix.len() != 1 || !suffix.bytes().all(|b| b.is_ascii_lowercase()) { + return None; + } + match family { + "code" | "any" | "not-code" => Some("repo-worker-code"), + "opencode" => Some("repo-worker-opencode"), + "openchamber" => Some("repo-worker-openchamber"), + "nix" => Some("repo-worker-nix"), + _ => None, + } +} + /// How many listed entries in a row may turn out stale in one run /// before the shortlist rung gives way to the priority rung. const MAX_STALE_ENTRIES: usize = 5; @@ -507,11 +534,12 @@ pub fn next(world: &dyn World, args: &[String]) -> R<(Value, i32)> { tried(&mut log, "queue", "skipped", "--no-queue"); } else { let lease = AGENT_CLAIM_LEASE_SECONDS.to_string(); + let worker = registered_lane_worker(&lane).unwrap_or(&agent); let mut claim = argv(&[ "queue", "claim", "--worker", - &agent, + worker, "--lane", &lane, "--lease-seconds", @@ -552,8 +580,8 @@ pub fn next(world: &dyn World, args: &[String]) -> R<(Value, i32)> { ), }); let then = vec![ - format!("fleet queue checkpoint {id} --worker {agent} --lane {lane} ..."), - format!("fleet queue complete {id} --worker {agent} --lane {lane} ..."), + format!("fleet queue checkpoint {id} --worker {worker} --lane {lane} ..."), + format!("fleet queue complete {id} --worker {worker} --lane {lane} ..."), ]; return Ok(answer("queue", task, then, log)); } diff --git a/pkgs/fleet/crates/fleet-agent/src/tests.rs b/pkgs/fleet/crates/fleet-agent/src/tests.rs index 4c5aecd05..c87e38eb8 100644 --- a/pkgs/fleet/crates/fleet-agent/src/tests.rs +++ b/pkgs/fleet/crates/fleet-agent/src/tests.rs @@ -270,12 +270,67 @@ fn an_empty_mailbox_falls_to_a_queue_claim() { rung_results(&out), vec![("push".to_string(), "empty".to_string())] ); - // The claim carries the agent as worker, the lane, and the claimer's own flags. + // For an unrecognized custom lane, the agent remains the fallback + // worker; the lane and the claimer's own flags are also preserved. assert!(fake.called( "fleet queue claim --worker oc-go-1 --lane go --lease-seconds 14400 --platform opencode --remaining-budget-minutes 90" )); } +#[test] +fn next_uses_the_registered_worker_for_a_known_lane() { + // Oracle (#6853): the broker's canonical lane registry binds + // these lane/worker pairs, and claim/complete must preserve them. + for (lane, worker) in [ + ("code-i", "repo-worker-code"), + ("code-a", "repo-worker-code"), + ("code-b", "repo-worker-code"), + ("opencode-a", "repo-worker-opencode"), + ("opencode-b", "repo-worker-opencode"), + ("openchamber-a", "repo-worker-openchamber"), + ("openchamber-b", "repo-worker-openchamber"), + ("nix-a", "repo-worker-nix"), + ("nix-b", "repo-worker-nix"), + ("not-code-a", "repo-worker-nix"), + ("not-code-b", "repo-worker-opencode"), + ("not-code-c", "repo-worker-code"), + ("not-code-d", "repo-worker-openchamber"), + ("not-code-e", "repo-worker-opencode"), + ("not-code-f", "repo-worker-code"), + ("not-code-g", "repo-worker-nix"), + ] { + let fake = Fake::new(); + fake.on(INBOX, vec![empty_inbox()]).on( + CLAIM, + vec![ok( + json!({"id": 10814, "queue": "fleet", "status": "claimed"}), + )], + ); + let (out, code) = run(&fake, &["next", "--agent", "code-i", "--lane", lane]); + assert_eq!(code, EXIT_OK, "lane {lane}"); + assert_eq!(out["rung"], "queue", "lane {lane}"); + assert!( + fake.called(&format!( + "fleet queue claim --worker {worker} --lane {lane} --lease-seconds 14400" + )), + "lane {lane} must be claimed by {worker}: {:?}", + fake.calls() + ); + assert!( + out["then"][0] + .as_str() + .unwrap() + .contains(&format!("--worker {worker}")) + ); + assert!( + out["then"][1] + .as_str() + .unwrap() + .contains(&format!("--worker {worker}")) + ); + } +} + #[test] fn a_queue_claim_carries_the_agent_lease_and_the_handout_names_it() { // Oracle (#12618): a claim taken by `next` asks the queue for the