Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions pkgs/fleet/crates/fleet-agent/src/next.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,12 @@ pub(super) fn default_lane(agent: &str) -> String {
/// 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> {
// The `oc-*` scheduled lanes carry a registered family under an
// `oc-` prefix (`oc-code-02`); the broker binds them to the same
// shared worker as the bare family (#13073).
if let Some(inner) = lane.strip_prefix("oc-") {
return oc_lane_worker(inner);
}
if matches!(lane, "not-code-a" | "not-code-g") {
return Some("repo-worker-nix");
}
Expand All @@ -462,6 +468,12 @@ fn registered_lane_worker(lane: &str) -> Option<&'static str> {
if suffix.len() != 1 || !suffix.bytes().all(|b| b.is_ascii_lowercase()) {
return None;
}
family_worker(family)
}

/// The shared worker a registered lane family binds to, by family
/// name alone.
fn family_worker(family: &str) -> Option<&'static str> {
match family {
"code" | "any" | "not-code" => Some("repo-worker-code"),
"opencode" => Some("repo-worker-opencode"),
Expand All @@ -471,6 +483,22 @@ fn registered_lane_worker(lane: &str) -> Option<&'static str> {
}
}

/// An `oc-*` lane with the prefix stripped. A letter suffix resolves
/// exactly like the bare lane (`oc-not-code-a` is `not-code-a` under
/// the prefix); the scheduled lanes' numeric suffix (`oc-code-02`)
/// resolves by family. An unknown family stays unregistered, so the
/// caller still falls back to the agent name.
fn oc_lane_worker(inner: &str) -> Option<&'static str> {
if let Some(worker) = registered_lane_worker(inner) {
return Some(worker);
}
let (family, suffix) = inner.rsplit_once('-')?;
if suffix.is_empty() || !suffix.bytes().all(|b| b.is_ascii_digit()) {
return None;
}
family_worker(family)
}

/// 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;
Expand Down
33 changes: 33 additions & 0 deletions pkgs/fleet/crates/fleet-agent/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,16 @@ fn next_uses_the_registered_worker_for_a_known_lane() {
("not-code-e", "repo-worker-opencode"),
("not-code-f", "repo-worker-code"),
("not-code-g", "repo-worker-nix"),
// The `oc-*` scheduled lanes bind to the same worker as the
// bare family (#13073): a numeric suffix resolves by family,
// a letter suffix exactly like the bare lane.
("oc-code-01", "repo-worker-code"),
("oc-code-02", "repo-worker-code"),
("oc-opencode-01", "repo-worker-opencode"),
("oc-openchamber-01", "repo-worker-openchamber"),
("oc-nix-01", "repo-worker-nix"),
("oc-not-code-01", "repo-worker-code"),
("oc-not-code-a", "repo-worker-nix"),
] {
let fake = Fake::new();
fake.on(INBOX, vec![empty_inbox()]).on(
Expand Down Expand Up @@ -331,6 +341,29 @@ fn next_uses_the_registered_worker_for_a_known_lane() {
}
}

#[test]
fn next_keeps_the_agent_as_worker_for_an_unknown_oc_lane() {
// An `oc-` prefix alone does not register a lane: an unknown
// family under it still falls back to the agent name as worker,
// so the broker's ownership check keeps its say (#13073).
let fake = Fake::new();
fake.on(INBOX, vec![empty_inbox()]).on(
CLAIM,
vec![ok(
json!({"id": 10815, "queue": "fleet", "status": "claimed"}),
)],
);
let (out, code) = run(
&fake,
&["next", "--agent", "oc-bogus-02", "--lane", "oc-bogus-02"],
);
assert_eq!(code, EXIT_OK);
assert_eq!(out["rung"], "queue");
assert!(fake.called(
"fleet queue claim --worker oc-bogus-02 --lane oc-bogus-02 --lease-seconds 14400"
));
}

#[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
Expand Down