Skip to content

Commit c3bcdea

Browse files
committed
fix(mesh): keep readiness diagnosis honest on a single-worker mesh
Translating the probe to the wire name left the catalog-visibility check below it comparing against `AUTO_MODEL_ID`. Post-translation that value can only be `mesh` or a named model, so the delegated-choice branch was unreachable. MeshLLM only advertises the virtual `mesh` model once two non-virtual models are reachable (`should_advertise_virtual_mesh`), so on a single-worker mesh the name is never listed and `model_ever_visible` stayed false for the whole wait. A readiness timeout — a lone host still loading weights, say — was then reported as `CatalogNeverSynced`, "a network path problem between this machine and the host", when `RoutingNeverCompleted`, "try again shortly", is the truth. Confirmed against a live node here: with one worker, `/v1/models` lists only the served model. Only the wrong-diagnosis-on-timeout is affected; the happy path always worked, because the chat probe sends `mesh` and the server degrades it. The comparison now keys on the translated name, preserving the original "delegated choice — any advertised model counts" semantics. The predicate is extracted as `mesh_catalog_shows_model` so that rule is testable rather than buried in the poll loop, and the failure copy now names the model the caller asked for, so someone who picked "Auto" is not shown "mesh". Four tests cover it. Verified they fail with the old comparison restored, so they pin the behaviour rather than merely passing alongside it. Reported by @wpfleger96 in review; the diagnosis and the suggested fix are theirs. Signed-off-by: Michael Neale <[email protected]>
1 parent 8e3b150 commit c3bcdea

2 files changed

Lines changed: 76 additions & 13 deletions

File tree

‎desktop/src-tauri/src/commands/mesh_llm.rs‎

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,28 @@ enum MeshReadinessFailure {
558558
/// Pure classifier: given whether the served model was ever observed in the
559559
/// local `/v1/models` catalog during the wait, decide which stage failed.
560560
/// Split out so the diagnosis is unit-testable without a live mesh.
561+
/// Whether the catalog has synced enough to count, for the model actually being
562+
/// requested (a wire name — see `relay_mesh_wire_model`).
563+
///
564+
/// The virtual `mesh` model delegates the choice to the router, so any
565+
/// advertised model proves the catalog synced. It has to work that way: MeshLLM
566+
/// only advertises `mesh` itself once two non-virtual models are reachable
567+
/// (`should_advertise_virtual_mesh`), so requiring it by name would leave a
568+
/// single-worker mesh looking permanently unsynced and misreport a slow model
569+
/// load as a network path problem.
570+
fn mesh_catalog_shows_model(advertised: &[String], wire_model: &str) -> bool {
571+
if advertised.is_empty() {
572+
return false;
573+
}
574+
if wire_model == crate::managed_agents::RELAY_MESH_VIRTUAL_MODEL_ID {
575+
return true;
576+
}
577+
let wanted = wire_model.trim().replace("@main", "");
578+
advertised
579+
.iter()
580+
.any(|id| id.replace("@main", "") == wanted)
581+
}
582+
561583
fn classify_mesh_readiness_failure(model_ever_visible: bool) -> MeshReadinessFailure {
562584
if model_ever_visible {
563585
MeshReadinessFailure::RoutingNeverCompleted
@@ -600,6 +622,7 @@ async fn wait_for_mesh_inference(model_id: &str) -> CmdResult<()> {
600622
// advertises: probing it would validate a route no agent uses, and could
601623
// fail readiness while the real route works. Named models pass through
602624
// unchanged, so this is safe for the serve-side callers too.
625+
let requested_model = model_id;
603626
let model_id = crate::managed_agents::relay_mesh_wire_model(model_id);
604627
let client = reqwest::Client::builder()
605628
.timeout(std::time::Duration::from_secs(30))
@@ -617,8 +640,12 @@ async fn wait_for_mesh_inference(model_id: &str) -> CmdResult<()> {
617640
let mut model_ever_visible = false;
618641

619642
while tokio::time::Instant::now() < deadline {
620-
// Refresh catalog visibility. "auto" delegates model choice to the
621-
// router, so any advertised model counts as the catalog having synced.
643+
// Refresh catalog visibility. The virtual `mesh` model delegates the
644+
// choice to the router, so any advertised model counts as the catalog
645+
// having synced — and it must, because MeshLLM only advertises `mesh`
646+
// itself once two non-virtual models are reachable
647+
// (`should_advertise_virtual_mesh`). Requiring it by name would leave a
648+
// single-worker mesh looking permanently unsynced.
622649
if let Ok(response) = client
623650
.get(&models_url)
624651
.bearer_auth(crate::managed_agents::RELAY_MESH_API_KEY_PLACEHOLDER)
@@ -627,16 +654,12 @@ async fn wait_for_mesh_inference(model_id: &str) -> CmdResult<()> {
627654
{
628655
if let Ok(body) = response.json::<serde_json::Value>().await {
629656
if let Some(data) = body.get("data").and_then(|d| d.as_array()) {
630-
let wanted = model_id.trim().replace("@main", "");
631-
let visible = !data.is_empty()
632-
&& (model_id == crate::mesh_llm::AUTO_MODEL_ID
633-
|| data.iter().any(|m| {
634-
m.get("id")
635-
.and_then(|id| id.as_str())
636-
.map(|id| id.replace("@main", "") == wanted)
637-
.unwrap_or(false)
638-
}));
639-
model_ever_visible |= visible;
657+
let advertised: Vec<String> = data
658+
.iter()
659+
.filter_map(|m| m.get("id").and_then(|id| id.as_str()))
660+
.map(str::to_owned)
661+
.collect();
662+
model_ever_visible |= mesh_catalog_shows_model(&advertised, model_id);
640663
}
641664
}
642665
}
@@ -667,7 +690,7 @@ async fn wait_for_mesh_inference(model_id: &str) -> CmdResult<()> {
667690
let failure = classify_mesh_readiness_failure(model_ever_visible);
668691
Err(mesh_readiness_failure_message(
669692
failure,
670-
model_id,
693+
requested_model,
671694
&last_error,
672695
))
673696
}

‎desktop/src-tauri/src/commands/mesh_llm_tests.rs‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,46 @@ fn role_switch_checkpoint_starts_exactly_once_after_restart() {
178178
assert_eq!(consumed.relay_url, config.relay_url);
179179
}
180180

181+
/// The regression this guards: MeshLLM only advertises the virtual `mesh` model
182+
/// once two non-virtual models are reachable, so a single-worker mesh never
183+
/// lists it by name. Keying visibility on the literal name would report a lone
184+
/// host that is still loading weights as a network path problem.
185+
#[test]
186+
fn virtual_mesh_counts_any_advertised_model_as_a_synced_catalog() {
187+
let one_worker = vec!["unsloth/gemma-4-E4B-it-GGUF:Q4_K_M".to_string()];
188+
assert!(mesh_catalog_shows_model(
189+
&one_worker,
190+
crate::managed_agents::RELAY_MESH_VIRTUAL_MODEL_ID
191+
));
192+
}
193+
194+
#[test]
195+
fn an_empty_catalog_is_never_synced_even_for_the_virtual_model() {
196+
assert!(!mesh_catalog_shows_model(
197+
&[],
198+
crate::managed_agents::RELAY_MESH_VIRTUAL_MODEL_ID
199+
));
200+
}
201+
202+
#[test]
203+
fn a_named_model_must_actually_be_advertised() {
204+
let advertised = vec!["unsloth/gemma-4-E4B-it-GGUF:Q4_K_M".to_string()];
205+
assert!(mesh_catalog_shows_model(
206+
&advertised,
207+
"unsloth/gemma-4-E4B-it-GGUF:Q4_K_M"
208+
));
209+
assert!(!mesh_catalog_shows_model(&advertised, "some/other-model"));
210+
}
211+
212+
#[test]
213+
fn a_named_model_ignores_the_main_revision_suffix() {
214+
let advertised = vec!["unsloth/gemma-4-E4B-it-GGUF:Q4_K_M@main".to_string()];
215+
assert!(mesh_catalog_shows_model(
216+
&advertised,
217+
"unsloth/gemma-4-E4B-it-GGUF:Q4_K_M"
218+
));
219+
}
220+
181221
#[test]
182222
fn readiness_failure_is_catalog_sync_when_model_never_visible() {
183223
assert_eq!(

0 commit comments

Comments
 (0)