diff --git a/Justfile b/Justfile index 7e2364a75a..056f4313e9 100644 --- a/Justfile +++ b/Justfile @@ -382,8 +382,15 @@ test-all: echo "=== 2/8 Rust format check ===" just with-lld cargo fmt --all -- --check echo "" + echo "=== GPU bench Rust feature check ===" + MESH_LLM_GPU_BENCH_RUST_ONLY=1 just with-lld cargo check -p mesh-llm-gpu-bench --features cuda,hip,intel + echo "" echo "=== 3/8 Clippy ===" - just with-lld cargo clippy -p mesh-llm -- -D warnings + mapfile -t clippy_crates < <(bash scripts/plan-clippy-batches.sh --all --bins 1 | jq -r '.[].crates[]') + for crate in "${clippy_crates[@]}"; do + echo "--- $crate ---" + just with-lld cargo clippy -p "$crate" --all-targets -- -D warnings + done echo "" echo "=== 4/8 Rust tests ===" echo "--- mesh-llm-host-runtime lib ---" diff --git a/crates/llama-spec-bench/src/main.rs b/crates/llama-spec-bench/src/main.rs index 66345f37be..a5c77a4fd8 100644 --- a/crates/llama-spec-bench/src/main.rs +++ b/crates/llama-spec-bench/src/main.rs @@ -875,10 +875,10 @@ fn prompt_cases(args: &Args) -> Result> { .is_file() .then(|| PathBuf::from(DEFAULT_CORPUS)) }); - if prompts.is_empty() { - if let Some(path) = corpus.as_ref() { - prompts.extend(read_prompt_corpus(path)?); - } + if prompts.is_empty() + && let Some(path) = corpus.as_ref() + { + prompts.extend(read_prompt_corpus(path)?); } if prompts.is_empty() { prompts.push(PromptCase { diff --git a/crates/mesh-client/src/network/http_parse.rs b/crates/mesh-client/src/network/http_parse.rs index 139ed11189..443cd2fd67 100644 --- a/crates/mesh-client/src/network/http_parse.rs +++ b/crates/mesh-client/src/network/http_parse.rs @@ -530,10 +530,10 @@ fn translate_responses_content_item(item: &serde_json::Value) -> Result) -> serde_json::Value { - if blocks.len() == 1 { - if let Some(text) = blocks[0].get("text").and_then(|value| value.as_str()) { - return serde_json::Value::String(text.to_string()); - } + if blocks.len() == 1 + && let Some(text) = blocks[0].get("text").and_then(|value| value.as_str()) + { + return serde_json::Value::String(text.to_string()); } serde_json::Value::Array(blocks) } @@ -632,13 +632,13 @@ fn translate_openai_responses_input( let mut messages = Vec::new(); if let Some(instructions_value) = object.remove("instructions") { - if let Some(instructions) = instructions_value.as_str().map(str::trim) { - if !instructions.is_empty() { - messages.push(serde_json::json!({ - "role": "system", - "content": instructions, - })); - } + if let Some(instructions) = instructions_value.as_str().map(str::trim) + && !instructions.is_empty() + { + messages.push(serde_json::json!({ + "role": "system", + "content": instructions, + })); } changed = true; } diff --git a/crates/mesh-client/src/network/nostr.rs b/crates/mesh-client/src/network/nostr.rs index a1885ca4c1..15fa501ad2 100644 --- a/crates/mesh-client/src/network/nostr.rs +++ b/crates/mesh-client/src/network/nostr.rs @@ -271,10 +271,10 @@ pub async fn discover( .and_then(|t| t.as_slice().get(1)) .and_then(|s| s.parse::().ok()); - if let Some(exp) = expires_at { - if exp < now { - continue; - } + if let Some(exp) = expires_at + && exp < now + { + continue; } let listing: MeshListing = match serde_json::from_str(&event.content) { @@ -316,10 +316,10 @@ pub fn score_mesh(mesh: &DiscoveredMesh, _now_secs: u64, last_mesh_id: Option<&s } } - if let (Some(last_id), Some(mesh_id)) = (last_mesh_id, &mesh.listing.mesh_id) { - if last_id == mesh_id { - score += 500; - } + if let (Some(last_id), Some(mesh_id)) = (last_mesh_id, &mesh.listing.mesh_id) + && last_id == mesh_id + { + score += 500; } if mesh.listing.max_clients > 0 { diff --git a/crates/mesh-client/src/network/rewrite.rs b/crates/mesh-client/src/network/rewrite.rs index e156169c0e..f37a2c63dd 100644 --- a/crates/mesh-client/src/network/rewrite.rs +++ b/crates/mesh-client/src/network/rewrite.rs @@ -80,28 +80,28 @@ pub async fn relay_with_rewrite( .to_string(); // Parse port from endpoint string like "127.0.0.1:49502" - if let Some(port_str) = endpoint_str.rsplit(':').next() { - if let Ok(remote_port) = port_str.parse::() { - let map = port_map.read().await; - if let Some(&local_port) = map.get(&remote_port) { - // Rewrite endpoint field - let new_endpoint = format!("127.0.0.1:{local_port}"); - let mut new_endpoint_bytes = [0u8; 128]; - let copy_len = new_endpoint.len().min(127); - new_endpoint_bytes[..copy_len] - .copy_from_slice(&new_endpoint.as_bytes()[..copy_len]); - payload[4..132].copy_from_slice(&new_endpoint_bytes); + if let Some(port_str) = endpoint_str.rsplit(':').next() + && let Ok(remote_port) = port_str.parse::() + { + let map = port_map.read().await; + if let Some(&local_port) = map.get(&remote_port) { + // Rewrite endpoint field + let new_endpoint = format!("127.0.0.1:{local_port}"); + let mut new_endpoint_bytes = [0u8; 128]; + let copy_len = new_endpoint.len().min(127); + new_endpoint_bytes[..copy_len] + .copy_from_slice(&new_endpoint.as_bytes()[..copy_len]); + payload[4..132].copy_from_slice(&new_endpoint_bytes); - tracing::info!( - "Rewrote REGISTER_PEER: peer_id={peer_id} \ + tracing::info!( + "Rewrote REGISTER_PEER: peer_id={peer_id} \ {endpoint_str} → 127.0.0.1:{local_port}" - ); - } else { - tracing::warn!( - "REGISTER_PEER: no rewrite mapping for port {remote_port} \ + ); + } else { + tracing::warn!( + "REGISTER_PEER: no rewrite mapping for port {remote_port} \ (peer_id={peer_id}, endpoint={endpoint_str}), passing through" - ); - } + ); } } diff --git a/crates/mesh-client/src/network/router.rs b/crates/mesh-client/src/network/router.rs index cbf3deca82..19b13413d6 100644 --- a/crates/mesh-client/src/network/router.rs +++ b/crates/mesh-client/src/network/router.rs @@ -514,15 +514,13 @@ pub fn classify(body: &Value) -> Classification { let mut system_code = false; if let Some(messages) = body.get("messages").and_then(|m| m.as_array()) { for msg in messages { - if msg.get("role").and_then(|r| r.as_str()) == Some("system") { - if let Some(content) = msg.get("content").and_then(|c| c.as_str()) { - let sys = content.to_lowercase(); - if sys.contains("developer") - || sys.contains("coding") - || sys.contains("programmer") - { - system_code = true; - } + if msg.get("role").and_then(|r| r.as_str()) == Some("system") + && let Some(content) = msg.get("content").and_then(|c| c.as_str()) + { + let sys = content.to_lowercase(); + if sys.contains("developer") || sys.contains("coding") || sys.contains("programmer") + { + system_code = true; } } } diff --git a/crates/mesh-llm-gpu-bench/build.rs b/crates/mesh-llm-gpu-bench/build.rs index 36c01fa86a..62e55efe32 100644 --- a/crates/mesh-llm-gpu-bench/build.rs +++ b/crates/mesh-llm-gpu-bench/build.rs @@ -1,4 +1,9 @@ fn main() { + println!("cargo:rerun-if-env-changed=MESH_LLM_GPU_BENCH_RUST_ONLY"); + if std::env::var_os("MESH_LLM_GPU_BENCH_RUST_ONLY").is_some() { + return; + } + if target_os_is("macos") { build_metal(); } diff --git a/crates/mesh-llm-gpu-bench/src/cuda.rs b/crates/mesh-llm-gpu-bench/src/cuda.rs index a8b3cff1b1..bb5722761a 100644 --- a/crates/mesh-llm-gpu-bench/src/cuda.rs +++ b/crates/mesh-llm-gpu-bench/src/cuda.rs @@ -2,7 +2,7 @@ use crate::{BenchmarkOutput, capture::capture_stdout, parse_benchmark_output}; use anyhow::{Context, Result}; use std::ffi::c_int; -extern "C" { +unsafe extern "C" { fn mesh_llm_gpu_bench_cuda_main() -> c_int; } diff --git a/crates/mesh-llm-gpu-bench/src/hip.rs b/crates/mesh-llm-gpu-bench/src/hip.rs index e5a2502fe9..9586b999aa 100644 --- a/crates/mesh-llm-gpu-bench/src/hip.rs +++ b/crates/mesh-llm-gpu-bench/src/hip.rs @@ -2,7 +2,7 @@ use crate::{BenchmarkOutput, capture::capture_stdout, parse_benchmark_output}; use anyhow::{Context, Result}; use std::ffi::c_int; -extern "C" { +unsafe extern "C" { fn mesh_llm_gpu_bench_hip_main() -> c_int; } diff --git a/crates/mesh-llm-gpu-bench/src/intel.rs b/crates/mesh-llm-gpu-bench/src/intel.rs index f87d21f34a..6f33a3daa9 100644 --- a/crates/mesh-llm-gpu-bench/src/intel.rs +++ b/crates/mesh-llm-gpu-bench/src/intel.rs @@ -2,7 +2,7 @@ use crate::{BenchmarkOutput, capture::capture_stdout, parse_benchmark_output}; use anyhow::{Context, Result}; use std::ffi::c_int; -extern "C" { +unsafe extern "C" { fn mesh_llm_gpu_bench_intel_main() -> c_int; } diff --git a/crates/mesh-llm-gpu-bench/src/runner.rs b/crates/mesh-llm-gpu-bench/src/runner.rs index 96f92ccca4..ddd42fc844 100644 --- a/crates/mesh-llm-gpu-bench/src/runner.rs +++ b/crates/mesh-llm-gpu-bench/src/runner.rs @@ -1,5 +1,12 @@ use crate::BenchmarkOutput; -use anyhow::{Result, anyhow}; +use anyhow::Result; +#[cfg(any( + not(target_os = "macos"), + not(feature = "cuda"), + not(feature = "hip"), + not(feature = "intel") +))] +use anyhow::anyhow; use std::time::Duration; #[derive(Debug, Clone, Copy, PartialEq, Eq)] @@ -74,11 +81,11 @@ pub fn parse_benchmark_output(stdout: &[u8]) -> Option> { None } Err(err) => { - if let Ok(val) = serde_json::from_slice::(stdout) { - if let Some(msg) = val.get("error").and_then(|v| v.as_str()) { - tracing::warn!("benchmark reported error: {msg}"); - return None; - } + if let Ok(val) = serde_json::from_slice::(stdout) + && let Some(msg) = val.get("error").and_then(|v| v.as_str()) + { + tracing::warn!("benchmark reported error: {msg}"); + return None; } tracing::warn!("failed to parse benchmark output: {err}"); None diff --git a/crates/mesh-llm-guardrails/src/compact.rs b/crates/mesh-llm-guardrails/src/compact.rs index d80c28f727..22eecfe863 100644 --- a/crates/mesh-llm-guardrails/src/compact.rs +++ b/crates/mesh-llm-guardrails/src/compact.rs @@ -193,13 +193,12 @@ fn is_tool_result_message(message: &Value) -> bool { fn strip_reasoning_fields(messages: &mut [Value]) -> usize { let mut dropped = 0; for message in messages { - if let Some(object) = message.as_object_mut() { - if object.remove("reasoning_content").is_some() + if let Some(object) = message.as_object_mut() + && (object.remove("reasoning_content").is_some() || object.remove("reasoning").is_some() - || object.remove("thinking").is_some() - { - dropped += 1; - } + || object.remove("thinking").is_some()) + { + dropped += 1; } } dropped diff --git a/crates/mesh-llm-guardrails/src/structured.rs b/crates/mesh-llm-guardrails/src/structured.rs index d7881dd965..a51482a490 100644 --- a/crates/mesh-llm-guardrails/src/structured.rs +++ b/crates/mesh-llm-guardrails/src/structured.rs @@ -109,10 +109,10 @@ fn validate_object_schema(object: &Map) -> Result<(), Unsupported } } } - if let Some(additional_properties) = object.get("additionalProperties") { - if !additional_properties.is_boolean() { - return Err(UnsupportedStructuredSchema); - } + if let Some(additional_properties) = object.get("additionalProperties") + && !additional_properties.is_boolean() + { + return Err(UnsupportedStructuredSchema); } if let Some(properties) = properties { for schema in properties.values() { diff --git a/crates/mesh-llm-guardrails/src/tools.rs b/crates/mesh-llm-guardrails/src/tools.rs index ea0535ac17..439b40746b 100644 --- a/crates/mesh-llm-guardrails/src/tools.rs +++ b/crates/mesh-llm-guardrails/src/tools.rs @@ -53,10 +53,10 @@ pub fn model_param_size_b(name: &str) -> Option { if unit != b'b' && unit != b'B' { continue; } - if let Some(&after) = bytes.get(end + 1) { - if after.is_ascii_digit() { - continue; - } + if let Some(&after) = bytes.get(end + 1) + && after.is_ascii_digit() + { + continue; } let number = std::str::from_utf8(&bytes[i..end]) diff --git a/crates/mesh-llm-host-runtime/src/cli/commands/blackboard.rs b/crates/mesh-llm-host-runtime/src/cli/commands/blackboard.rs index dd71ec528d..47d18e4568 100644 --- a/crates/mesh-llm-host-runtime/src/cli/commands/blackboard.rs +++ b/crates/mesh-llm-host-runtime/src/cli/commands/blackboard.rs @@ -32,12 +32,12 @@ pub(crate) async fn run_blackboard( .get(format!("{base}/api/blackboard/feed?limit=1")) .send() .await; - if let Ok(resp) = feed_check { - if resp.status().as_u16() == 404 { - eprintln!("Mesh is running but blackboard is disabled on that node."); - eprintln!("Re-enable it in the mesh config if you want to use the blackboard plugin."); - std::process::exit(1); - } + if let Ok(resp) = feed_check + && resp.status().as_u16() == 404 + { + eprintln!("Mesh is running but blackboard is disabled on that node."); + eprintln!("Re-enable it in the mesh config if you want to use the blackboard plugin."); + std::process::exit(1); } let default_hours = 24.0; diff --git a/crates/mesh-llm-host-runtime/src/cli/commands/integrations.rs b/crates/mesh-llm-host-runtime/src/cli/commands/integrations.rs index 25b44f2fb5..ca990314d6 100644 --- a/crates/mesh-llm-host-runtime/src/cli/commands/integrations.rs +++ b/crates/mesh-llm-host-runtime/src/cli/commands/integrations.rs @@ -725,14 +725,14 @@ async fn fetch_model_context_lengths( ) -> std::collections::HashMap> { let mut context_map = std::collections::HashMap::new(); - if let Ok(resp) = client.get(management_models_url).send().await { - if let Ok(body) = resp.json::().await { - for model in body["mesh_models"].as_array().unwrap_or(&vec![]) { - let name = model["name"].as_str().map(String::from); - let ctx_len = model["context_length"].as_u64().map(|v| v as u32); - if let Some(n) = name { - context_map.insert(n, ctx_len); - } + if let Ok(resp) = client.get(management_models_url).send().await + && let Ok(body) = resp.json::().await + { + for model in body["mesh_models"].as_array().unwrap_or(&vec![]) { + let name = model["name"].as_str().map(String::from); + let ctx_len = model["context_length"].as_u64().map(|v| v as u32); + if let Some(n) = name { + context_map.insert(n, ctx_len); } } } @@ -774,18 +774,18 @@ async fn write_opencode_config_to_path( // Merge schema if needed (for display in ordered format) let mut merged_config = existing_config.clone(); - if merged_config.get("$schema").is_none() { - if let Some(schema) = config_value.get("$schema") { - merged_config - .as_object_mut() - .ok_or_else(|| { - anyhow::anyhow!( - "Expected {} to contain a JSON object", - config_path.display() - ) - })? - .insert("$schema".to_string(), schema.clone()); - } + if merged_config.get("$schema").is_none() + && let Some(schema) = config_value.get("$schema") + { + merged_config + .as_object_mut() + .ok_or_else(|| { + anyhow::anyhow!( + "Expected {} to contain a JSON object", + config_path.display() + ) + })? + .insert("$schema".to_string(), schema.clone()); } merge_mesh_provider(&mut merged_config, mesh_provider.clone(), config_path)?; diff --git a/crates/mesh-llm-host-runtime/src/cli/commands/models/formatters_console.rs b/crates/mesh-llm-host-runtime/src/cli/commands/models/formatters_console.rs index 6b89566e06..85b6de5447 100644 --- a/crates/mesh-llm-host-runtime/src/cli/commands/models/formatters_console.rs +++ b/crates/mesh-llm-host-runtime/src/cli/commands/models/formatters_console.rs @@ -62,10 +62,10 @@ impl SearchFormatter for ConsoleFormatter { if let Some(description) = model.description.as_deref() { writeln!(&mut output, " {}", description)?; } - if let Some(size) = model.size.as_deref() { - if let Some(fit) = fit_hint_for_size_label(size) { - writeln!(&mut output, " {}", fit)?; - } + if let Some(size) = model.size.as_deref() + && let Some(fit) = fit_hint_for_size_label(size) + { + writeln!(&mut output, " {}", fit)?; } writeln!(&mut output)?; } @@ -158,10 +158,10 @@ impl SearchFormatter for ConsoleFormatter { " download: mesh-llm models download {}", result.exact_ref )?; - if let Some(size) = &result.size_label { - if let Some(fit) = fit_hint_for_size_label(size) { - writeln!(&mut output, " {}", fit)?; - } + if let Some(size) = &result.size_label + && let Some(fit) = fit_hint_for_size_label(size) + { + writeln!(&mut output, " {}", fit)?; } if let Some(model) = result.catalog.as_ref() { match model.size.as_deref() { @@ -246,10 +246,10 @@ impl ModelsFormatter for ConsoleFormatter { "external" } )?; - if let Some(last_used_at) = row.last_used_at.as_deref() { - if let Some(label) = format_relative_timestamp(last_used_at) { - writeln!(&mut output, " last used: {}", label)?; - } + if let Some(last_used_at) = row.last_used_at.as_deref() + && let Some(label) = format_relative_timestamp(last_used_at) + { + writeln!(&mut output, " last used: {}", label)?; } let mut caps = vec!["💬 text".to_string()]; if row.capabilities.multimodal_label().is_some() { @@ -343,44 +343,44 @@ impl ModelsFormatter for ConsoleFormatter { println!(" {}", details.download_url); } - if let Some(variants) = variants { - if !variants.is_empty() { - println!(); - println!("Variants:"); - let mut rows = Vec::new(); - for variant in variants { - let size = variant.size_label.as_deref().unwrap_or("-"); - let fit = variant - .size_label - .as_deref() - .and_then(fit_hint_for_size_label) - .unwrap_or_else(|| "-".to_string()); - let selected = variant.exact_ref == details.exact_ref; - rows.push(( - variant_selector_label(&variant.exact_ref), - size.to_string(), - fit, - variant.exact_ref.clone(), - selected, - )); - } - let mut table = TabWriter::new(Vec::new()).padding(2); - writeln!(&mut table, "sel\tquant\tsize\tfit\tref")?; - writeln!(&mut table, "---\t-----\t----\t---\t---")?; - for (quant, size, fit, r#ref, selected) in rows { - writeln!( - &mut table, - "{}\t{}\t{}\t{}\t{}", - if selected { "*" } else { " " }, - quant, - size, - fit, - r#ref - )?; - } - table.flush()?; - print!("{}", String::from_utf8_lossy(&table.into_inner()?)); + if let Some(variants) = variants + && !variants.is_empty() + { + println!(); + println!("Variants:"); + let mut rows = Vec::new(); + for variant in variants { + let size = variant.size_label.as_deref().unwrap_or("-"); + let fit = variant + .size_label + .as_deref() + .and_then(fit_hint_for_size_label) + .unwrap_or_else(|| "-".to_string()); + let selected = variant.exact_ref == details.exact_ref; + rows.push(( + variant_selector_label(&variant.exact_ref), + size.to_string(), + fit, + variant.exact_ref.clone(), + selected, + )); + } + let mut table = TabWriter::new(Vec::new()).padding(2); + writeln!(&mut table, "sel\tquant\tsize\tfit\tref")?; + writeln!(&mut table, "---\t-----\t----\t---\t---")?; + for (quant, size, fit, r#ref, selected) in rows { + writeln!( + &mut table, + "{}\t{}\t{}\t{}\t{}", + if selected { "*" } else { " " }, + quant, + size, + fit, + r#ref + )?; } + table.flush()?; + print!("{}", String::from_utf8_lossy(&table.into_inner()?)); } Ok(()) } diff --git a/crates/mesh-llm-host-runtime/src/cli/commands/models/mod.rs b/crates/mesh-llm-host-runtime/src/cli/commands/models/mod.rs index 794e2b4ef4..7572330fe4 100644 --- a/crates/mesh-llm-host-runtime/src/cli/commands/models/mod.rs +++ b/crates/mesh-llm-host-runtime/src/cli/commands/models/mod.rs @@ -223,10 +223,10 @@ pub async fn run_model_certify( .await?; let report_json = serde_json::to_string_pretty(&report)?; if let Some(path) = report_out { - if let Some(parent) = path.parent() { - if !parent.as_os_str().is_empty() { - std::fs::create_dir_all(parent)?; - } + if let Some(parent) = path.parent() + && !parent.as_os_str().is_empty() + { + std::fs::create_dir_all(parent)?; } std::fs::write(path, format!("{report_json}\n"))?; } diff --git a/crates/mesh-llm-host-runtime/src/cli/mod.rs b/crates/mesh-llm-host-runtime/src/cli/mod.rs index d4da2f016b..1b7c62fac6 100644 --- a/crates/mesh-llm-host-runtime/src/cli/mod.rs +++ b/crates/mesh-llm-host-runtime/src/cli/mod.rs @@ -483,10 +483,10 @@ pub(crate) fn validate_discovery_mode_args(cli: &Cli) -> anyhow::Result<()> { if !cli.nostr_relay.is_empty() { anyhow::bail!("--nostr-relay is only valid with --mesh-discovery-mode nostr"); } - if let Some(Command::Discover { relay, .. }) = cli.command.as_ref() { - if !relay.is_empty() { - anyhow::bail!("discover --relay is only valid with --mesh-discovery-mode nostr"); - } + if let Some(Command::Discover { relay, .. }) = cli.command.as_ref() + && !relay.is_empty() + { + anyhow::bail!("discover --relay is only valid with --mesh-discovery-mode nostr"); } Ok(()) @@ -848,11 +848,11 @@ where // Check for --flag value form if value_taking_flags.contains(&arg_str) { // Advance by 2 if next token exists and doesn't start with '-' - if let Some(next) = original.get(pos + 1).and_then(|arg| arg.to_str()) { - if !next.starts_with('-') { - pos += 2; - continue; - } + if let Some(next) = original.get(pos + 1).and_then(|arg| arg.to_str()) + && !next.starts_with('-') + { + pos += 2; + continue; } // If next doesn't exist or starts with '-', advance by 1 (let Clap handle the error) pos += 1; diff --git a/crates/mesh-llm-host-runtime/src/cli/output/mod.rs b/crates/mesh-llm-host-runtime/src/cli/output/mod.rs index aefeb84f10..56582443b7 100644 --- a/crates/mesh-llm-host-runtime/src/cli/output/mod.rs +++ b/crates/mesh-llm-host-runtime/src/cli/output/mod.rs @@ -873,10 +873,10 @@ impl OutputEvent { if let Some(capacity_gb) = capacity_gb { line.push_str(&format!(" ({capacity_gb:.1}GB capacity)")); } - if let Some(models_on_disk) = models_on_disk { - if !models_on_disk.is_empty() { - line.push_str(&format!(" models={}", models_on_disk.join(", "))); - } + if let Some(models_on_disk) = models_on_disk + && !models_on_disk.is_empty() + { + line.push_str(&format!(" models={}", models_on_disk.join(", "))); } line } @@ -2138,29 +2138,29 @@ impl DashboardState { let llama_component = self.startup_component_for_truthful_status(TruthfulStartupStatusKey::LlamaServer); - if let Some(webserver) = &mut self.webserver { - if let Some(key) = Self::truthful_startup_key_for_endpoint(&webserver.label) { - webserver.status = Self::truthful_runtime_status_for_component( - match key { - TruthfulStartupStatusKey::Console => &console_component, - TruthfulStartupStatusKey::Api => &api_component, - TruthfulStartupStatusKey::LlamaServer => &llama_component, - }, - &webserver.status, - ); - } + if let Some(webserver) = &mut self.webserver + && let Some(key) = Self::truthful_startup_key_for_endpoint(&webserver.label) + { + webserver.status = Self::truthful_runtime_status_for_component( + match key { + TruthfulStartupStatusKey::Console => &console_component, + TruthfulStartupStatusKey::Api => &api_component, + TruthfulStartupStatusKey::LlamaServer => &llama_component, + }, + &webserver.status, + ); } - if let Some(api) = &mut self.api { - if let Some(key) = Self::truthful_startup_key_for_endpoint(&api.label) { - api.status = Self::truthful_runtime_status_for_component( - match key { - TruthfulStartupStatusKey::Console => &console_component, - TruthfulStartupStatusKey::Api => &api_component, - TruthfulStartupStatusKey::LlamaServer => &llama_component, - }, - &api.status, - ); - } + if let Some(api) = &mut self.api + && let Some(key) = Self::truthful_startup_key_for_endpoint(&api.label) + { + api.status = Self::truthful_runtime_status_for_component( + match key { + TruthfulStartupStatusKey::Console => &console_component, + TruthfulStartupStatusKey::Api => &api_component, + TruthfulStartupStatusKey::LlamaServer => &llama_component, + }, + &api.status, + ); } let ready_llama_process_rows = self.ready_llama_process_rows.clone(); for row in &mut self.llama_process_rows { @@ -2464,13 +2464,13 @@ impl DashboardState { return None; } - if let Some(progress) = self.model_progress.as_ref() { - if let Some(ratio) = model_download_progress_ratio(progress) { - return Some(LoadingProgressState { - ratio, - detail: loading_progress_detail(model_progress_detail(progress), ratio, None), - }); - } + if let Some(progress) = self.model_progress.as_ref() + && let Some(ratio) = model_download_progress_ratio(progress) + { + return Some(LoadingProgressState { + ratio, + detail: loading_progress_detail(model_progress_detail(progress), ratio, None), + }); } if let Some(progress) = self.startup_progress.as_ref() { @@ -8555,19 +8555,16 @@ impl OutputManager { } else if matches!(mode, LogFormat::Pretty) && worker_prompt_active.load(Ordering::Acquire) && formatter.writes_ready_prompt() - { - if let Err(err) = write_prompt() { + && let Err(err) = write_prompt() { tracing::warn!("interactive prompt write failed: {err}"); } - } } OutputCommand::ActivateReadyPrompt => { worker_prompt_active.store(true, Ordering::Release); - if matches!(mode, LogFormat::Pretty) && formatter.writes_ready_prompt() { - if let Err(err) = write_prompt() { + if matches!(mode, LogFormat::Pretty) && formatter.writes_ready_prompt() + && let Err(err) = write_prompt() { tracing::warn!("interactive prompt write failed: {err}"); } - } } OutputCommand::Flush(response) => { let flush_result = if formatter.is_interactive_dashboard() { diff --git a/crates/mesh-llm-host-runtime/src/inference/skippy/family_policy.rs b/crates/mesh-llm-host-runtime/src/inference/skippy/family_policy.rs index 65be35928f..aa5a71b7fe 100644 --- a/crates/mesh-llm-host-runtime/src/inference/skippy/family_policy.rs +++ b/crates/mesh-llm-host-runtime/src/inference/skippy/family_policy.rs @@ -185,12 +185,11 @@ fn capability_from_gguf_meta( return Some(capability); } - if !meta.architecture.trim().is_empty() { - if let Some(capability) = + if !meta.architecture.trim().is_empty() + && let Some(capability) = infer_family_capability(&meta.architecture, meta.layer_count, meta.embedding_size) - { - return Some(capability); - } + { + return Some(capability); } None diff --git a/crates/mesh-llm-host-runtime/src/inference/skippy/materialization.rs b/crates/mesh-llm-host-runtime/src/inference/skippy/materialization.rs index f61801f2e9..ff5ab3262e 100644 --- a/crates/mesh-llm-host-runtime/src/inference/skippy/materialization.rs +++ b/crates/mesh-llm-host-runtime/src/inference/skippy/materialization.rs @@ -474,10 +474,10 @@ impl ProgressHandler for LayerPackageDownloadProgress { let force = matches!(event, DownloadEvent::Complete) && should_show_progress; if should_show_progress { self.draw(&mut state, force); - } else if matches!(event, DownloadEvent::Complete) { - if let Ok(mut spinner) = self.preflight_spinner.lock() { - spinner.take(); - } + } else if matches!(event, DownloadEvent::Complete) + && let Ok(mut spinner) = self.preflight_spinner.lock() + { + spinner.take(); } } } @@ -592,31 +592,29 @@ fn resolve_local_package_files( "missing shared metadata: {}", metadata_path.display() ); - if include_embeddings { - if let Some(path) = manifest + if include_embeddings + && let Some(path) = manifest .pointer("/shared/embeddings/path") .and_then(|v| v.as_str()) - { - let path = safe_manifest_file_path(path)?; - anyhow::ensure!( - package_dir.join(&path).is_file(), - "missing shared embeddings: {}", - path.display() - ); - } + { + let path = safe_manifest_file_path(path)?; + anyhow::ensure!( + package_dir.join(&path).is_file(), + "missing shared embeddings: {}", + path.display() + ); } - if include_output { - if let Some(path) = manifest + if include_output + && let Some(path) = manifest .pointer("/shared/output/path") .and_then(|v| v.as_str()) - { - let path = safe_manifest_file_path(path)?; - anyhow::ensure!( - package_dir.join(&path).is_file(), - "missing shared output: {}", - path.display() - ); - } + { + let path = safe_manifest_file_path(path)?; + anyhow::ensure!( + package_dir.join(&path).is_file(), + "missing shared output: {}", + path.display() + ); } // Verify needed layer files exist if let Some(layers) = manifest.get("layers").and_then(|l| l.as_array()) { @@ -625,15 +623,16 @@ fn resolve_local_package_files( .get("layer_index") .and_then(|v| v.as_u64()) .unwrap_or(i as u64) as u32; - if idx >= layer_start && idx < layer_end { - if let Some(path) = layer.get("path").and_then(|a| a.as_str()) { - let path = safe_manifest_file_path(path)?; - anyhow::ensure!( - package_dir.join(&path).is_file(), - "missing layer file: {}", - path.display() - ); - } + if idx >= layer_start + && idx < layer_end + && let Some(path) = layer.get("path").and_then(|a| a.as_str()) + { + let path = safe_manifest_file_path(path)?; + anyhow::ensure!( + package_dir.join(&path).is_file(), + "missing layer file: {}", + path.display() + ); } } } @@ -826,16 +825,16 @@ pub(crate) fn resolve_hf_package_to_local( .join(&repo_folder) .join("snapshots") .join(&revision_cache_path); - if direct_snapshot_dir.join("model-package.json").is_file() { - if let Some(local_ref) = cache_resolution::resolve_cached_hf_package_snapshot( + if direct_snapshot_dir.join("model-package.json").is_file() + && let Some(local_ref) = cache_resolution::resolve_cached_hf_package_snapshot( &direct_snapshot_dir, layer_start, layer_end, include_embeddings, include_output, - )? { - return Ok(local_ref); - } + )? + { + return Ok(local_ref); } if let Ok(commit_hash) = fs::read_to_string(&ref_path) { let commit_hash = commit_hash.trim(); @@ -846,16 +845,16 @@ pub(crate) fn resolve_hf_package_to_local( .join(&repo_folder) .join("snapshots") .join(commit_hash_path); - if snapshot_dir.join("model-package.json").is_file() { - if let Some(local_ref) = cache_resolution::resolve_cached_hf_package_snapshot( + if snapshot_dir.join("model-package.json").is_file() + && let Some(local_ref) = cache_resolution::resolve_cached_hf_package_snapshot( &snapshot_dir, layer_start, layer_end, include_embeddings, include_output, - )? { - return Ok(local_ref); - } + )? + { + return Ok(local_ref); } } let downloaded = crate::models::run_hf_sync(move || { @@ -970,25 +969,23 @@ fn download_hf_package_to_local_sync( safe_manifest_file_path(metadata_path)?, manifest_artifact_bytes(metadata_artifact), )); - if include_embeddings { - if let Some(artifact) = manifest.pointer("/shared/embeddings") { - if let Some(path) = artifact.get("path").and_then(|v| v.as_str()) { - needed_files.push(( - safe_manifest_file_path(path)?, - manifest_artifact_bytes(artifact), - )); - } - } - } - if include_output { - if let Some(artifact) = manifest.pointer("/shared/output") { - if let Some(path) = artifact.get("path").and_then(|v| v.as_str()) { - needed_files.push(( - safe_manifest_file_path(path)?, - manifest_artifact_bytes(artifact), - )); - } - } + if include_embeddings + && let Some(artifact) = manifest.pointer("/shared/embeddings") + && let Some(path) = artifact.get("path").and_then(|v| v.as_str()) + { + needed_files.push(( + safe_manifest_file_path(path)?, + manifest_artifact_bytes(artifact), + )); + } + if include_output + && let Some(artifact) = manifest.pointer("/shared/output") + && let Some(path) = artifact.get("path").and_then(|v| v.as_str()) + { + needed_files.push(( + safe_manifest_file_path(path)?, + manifest_artifact_bytes(artifact), + )); } // Layer files for assigned range — use explicit layer_index if present, @@ -999,25 +996,26 @@ fn download_hf_package_to_local_sync( .get("layer_index") .and_then(|v| v.as_u64()) .unwrap_or(i as u64) as u32; - if idx >= layer_start && idx < layer_end { - if let Some(path) = layer.get("path").and_then(|a| a.as_str()) { - needed_files.push(( - safe_manifest_file_path(path)?, - manifest_artifact_bytes(layer), - )); - } + if idx >= layer_start + && idx < layer_end + && let Some(path) = layer.get("path").and_then(|a| a.as_str()) + { + needed_files.push(( + safe_manifest_file_path(path)?, + manifest_artifact_bytes(layer), + )); } } } - if layer_start == 0 { - if let Some(projectors) = manifest.get("projectors").and_then(|p| p.as_array()) { - for projector in projectors { - if let Some(path) = projector.get("path").and_then(|value| value.as_str()) { - needed_files.push(( - safe_manifest_file_path(path)?, - manifest_artifact_bytes(projector), - )); - } + if layer_start == 0 + && let Some(projectors) = manifest.get("projectors").and_then(|p| p.as_array()) + { + for projector in projectors { + if let Some(path) = projector.get("path").and_then(|value| value.as_str()) { + needed_files.push(( + safe_manifest_file_path(path)?, + manifest_artifact_bytes(projector), + )); } } } diff --git a/crates/mesh-llm-host-runtime/src/inference/skippy/materialization/cache_resolution.rs b/crates/mesh-llm-host-runtime/src/inference/skippy/materialization/cache_resolution.rs index 885021cac5..f36c2398dc 100644 --- a/crates/mesh-llm-host-runtime/src/inference/skippy/materialization/cache_resolution.rs +++ b/crates/mesh-llm-host-runtime/src/inference/skippy/materialization/cache_resolution.rs @@ -149,10 +149,10 @@ fn cached_snapshot_has_requested_layers( if !metadata.is_file() { return Ok(false); } - if let Some(expected_bytes) = manifest_artifact_bytes(layer) { - if metadata.len() != expected_bytes { - return Ok(false); - } + if let Some(expected_bytes) = manifest_artifact_bytes(layer) + && metadata.len() != expected_bytes + { + return Ok(false); } } Ok(true) diff --git a/crates/mesh-llm-host-runtime/src/inference/skippy/stage/inventory.rs b/crates/mesh-llm-host-runtime/src/inference/skippy/stage/inventory.rs index 52c493d365..ee324ca5e2 100644 --- a/crates/mesh-llm-host-runtime/src/inference/skippy/stage/inventory.rs +++ b/crates/mesh-llm-host-runtime/src/inference/skippy/stage/inventory.rs @@ -61,10 +61,10 @@ pub(super) fn resolve_inventory_source(request: &StageInventoryRequest) -> Optio pub(super) fn inventory_source_candidates(request: &StageInventoryRequest) -> Vec { let mut candidates = Vec::new(); - if let Some(path) = request.package_ref.strip_prefix("gguf://") { - if !path.is_empty() { - candidates.push(PathBuf::from(path)); - } + if let Some(path) = request.package_ref.strip_prefix("gguf://") + && !path.is_empty() + { + candidates.push(PathBuf::from(path)); } if !request.model_id.is_empty() { candidates.push(crate::models::find_model_path(&request.model_id)); diff --git a/crates/mesh-llm-host-runtime/src/inference/skippy/stage/mod.rs b/crates/mesh-llm-host-runtime/src/inference/skippy/stage/mod.rs index ad4de49609..b7f7e45dda 100644 --- a/crates/mesh-llm-host-runtime/src/inference/skippy/stage/mod.rs +++ b/crates/mesh-llm-host-runtime/src/inference/skippy/stage/mod.rs @@ -225,18 +225,17 @@ impl StageControlState { preparation_status_from_load(&request.load, StagePreparationState::Assigned, None); { let mut preparations = self.preparations.lock().await; - if let Some(existing) = preparations.get(&key) { - if existing.state == StagePreparationState::Cancelled - && existing.shutdown_generation >= request.load.shutdown_generation - { - let mut status = existing.clone(); - status.error = Some("stale shutdown generation".to_string()); - return Ok(StagePrepareAcceptedResponse { - accepted: false, - status, - error: Some("stale shutdown generation".to_string()), - }); - } + if let Some(existing) = preparations.get(&key) + && existing.state == StagePreparationState::Cancelled + && existing.shutdown_generation >= request.load.shutdown_generation + { + let mut status = existing.clone(); + status.error = Some("stale shutdown generation".to_string()); + return Ok(StagePrepareAcceptedResponse { + accepted: false, + status, + error: Some("stale shutdown generation".to_string()), + }); } preparations.insert(key.clone(), status.clone()); } @@ -274,12 +273,12 @@ impl StageControlState { ) -> StagePreparationStatus { let key = stage_key(&cancel.topology_id, &cancel.run_id, &cancel.stage_id); let mut preparations = self.preparations.lock().await; - if let Some(existing) = preparations.get(&key) { - if cancel.shutdown_generation < existing.shutdown_generation { - let mut status = existing.clone(); - status.error = Some("stale shutdown generation".to_string()); - return status; - } + if let Some(existing) = preparations.get(&key) + && cancel.shutdown_generation < existing.shutdown_generation + { + let mut status = existing.clone(); + status.error = Some("stale shutdown generation".to_string()); + return status; } if let Some(task) = self.preparation_tasks.remove(&key) { diff --git a/crates/mesh-llm-host-runtime/src/inference/virtual_llm.rs b/crates/mesh-llm-host-runtime/src/inference/virtual_llm.rs index 42f2147ebf..d7dce6371b 100644 --- a/crates/mesh-llm-host-runtime/src/inference/virtual_llm.rs +++ b/crates/mesh-llm-host-runtime/src/inference/virtual_llm.rs @@ -329,10 +329,10 @@ pub fn extract_image(payload: &Value) -> (String, String) { Some("text") => { // Check for mesh_image_url preserved by the OpenAI surface // when mesh hooks strip unsupported images. - if image_url.is_empty() { - if let Some(url) = part["mesh_image_url"]["url"].as_str() { - image_url = url.to_string(); - } + if image_url.is_empty() + && let Some(url) = part["mesh_image_url"]["url"].as_str() + { + image_url = url.to_string(); } text = part["text"].as_str().unwrap_or("").to_string(); } diff --git a/crates/mesh-llm-host-runtime/src/mesh/mod.rs b/crates/mesh-llm-host-runtime/src/mesh/mod.rs index 44081d4dc3..d8e3f50c03 100644 --- a/crates/mesh-llm-host-runtime/src/mesh/mod.rs +++ b/crates/mesh-llm-host-runtime/src/mesh/mod.rs @@ -1787,11 +1787,11 @@ impl LocalRequestMetricsSampler { .lock() .expect("pretty request metrics mutex poisoned"); guard.prune(now_sec); - if let Some((second, count)) = guard.accepted_by_second.back_mut() { - if *second == now_sec { - *count += 1; - return; - } + if let Some((second, count)) = guard.accepted_by_second.back_mut() + && *second == now_sec + { + *count += 1; + return; } guard.accepted_by_second.push_back((now_sec, 1)); } @@ -2102,14 +2102,13 @@ impl StageTopologyState { if !runtime_status.bind_addr.is_empty() && !runtime_status.bind_addr.ends_with(":0") { let topology_key = stage_topology_key(&runtime_status.topology_id, &runtime_status.run_id); - if let Some(topology) = self.topologies.get_mut(&topology_key) { - if let Some(stage) = topology + if let Some(topology) = self.topologies.get_mut(&topology_key) + && let Some(stage) = topology .stages .iter_mut() .find(|stage| stage.stage_id == runtime_status.stage_id) - { - stage.endpoint.bind_addr = runtime_status.bind_addr.clone(); - } + { + stage.endpoint.bind_addr = runtime_status.bind_addr.clone(); } } self.statuses.insert( @@ -3362,10 +3361,10 @@ impl Node { pub fn invite_token(&self) -> String { let mut addr = self.endpoint_addr_for_advertisement(); // Inject STUN-discovered public address if relay STUN didn't provide one. - if let Some(pub_addr) = self.public_addr { - if !endpoint_addr_has_public_ipv4(&addr) { - addr.addrs.insert(TransportAddr::Ip(pub_addr)); - } + if let Some(pub_addr) = self.public_addr + && !endpoint_addr_has_public_ipv4(&addr) + { + addr.addrs.insert(TransportAddr::Ip(pub_addr)); } addr = filter_endpoint_addr_for_bind_ip(addr, self.quic_bind.ip); let json = serde_json::to_vec(&addr).expect("serializable"); @@ -3718,21 +3717,20 @@ impl Node { detail_json: String, ) { let plugin_manager = self.plugin_manager.lock().await.clone(); - if let Some(plugin_manager) = plugin_manager { - if let Err(err) = plugin_manager + if let Some(plugin_manager) = plugin_manager + && let Err(err) = plugin_manager .broadcast_mesh_event( self.build_mesh_event(kind, peer.map(peer_info_to_mesh_peer), detail_json) .await, ) .await - { - tracing::debug!( - "Failed to deliver plugin mesh event {:?} for {}: {err}", - kind, - peer.map(|p| p.id.fmt_short().to_string()) - .unwrap_or_else(|| self.endpoint.id().fmt_short().to_string()) - ); - } + { + tracing::debug!( + "Failed to deliver plugin mesh event {:?} for {}: {err}", + kind, + peer.map(|p| p.id.fmt_short().to_string()) + .unwrap_or_else(|| self.endpoint.id().fmt_short().to_string()) + ); } } @@ -4045,18 +4043,17 @@ impl Node { noun: &str, ) -> bool { let plugin_manager = self.plugin_manager.lock().await.clone(); - if let Some(plugin_manager) = plugin_manager { - if !plugin_manager + if let Some(plugin_manager) = plugin_manager + && !plugin_manager .plugin_declares_mesh_channel(plugin_id, channel) .await - { - tracing::debug!( - plugin = %plugin_id, - channel = %channel, - "Dropping outbound {noun} for undeclared mesh channel" - ); - return false; - } + { + tracing::debug!( + plugin = %plugin_id, + channel = %channel, + "Dropping outbound {noun} for undeclared mesh channel" + ); + return false; } true } @@ -5988,11 +5985,10 @@ impl Node { { if let Ok(path) = crate::models::resolve_model_spec(std::path::Path::new(candidate)).await + && path.exists() { - if path.exists() { - load.model_path = Some(path.to_string_lossy().to_string()); - break; - } + load.model_path = Some(path.to_string_lossy().to_string()); + break; } } } diff --git a/crates/mesh-llm-host-runtime/src/models/artifact_transfer.rs b/crates/mesh-llm-host-runtime/src/models/artifact_transfer.rs index 55f02dfaaf..617370724a 100644 --- a/crates/mesh-llm-host-runtime/src/models/artifact_transfer.rs +++ b/crates/mesh-llm-host-runtime/src/models/artifact_transfer.rs @@ -178,21 +178,21 @@ pub(crate) fn required_stage_package_artifacts( .pointer("/shared/metadata") .context("manifest missing shared metadata")?, )?; - if selection.include_embeddings { - if let Some(embeddings) = manifest.pointer("/shared/embeddings") { - push_manifest_artifact( - &mut out, - &mut seen, - package_ref, - manifest_sha256, - embeddings, - )?; - } + if selection.include_embeddings + && let Some(embeddings) = manifest.pointer("/shared/embeddings") + { + push_manifest_artifact( + &mut out, + &mut seen, + package_ref, + manifest_sha256, + embeddings, + )?; } - if selection.include_output { - if let Some(output) = manifest.pointer("/shared/output") { - push_manifest_artifact(&mut out, &mut seen, package_ref, manifest_sha256, output)?; - } + if selection.include_output + && let Some(output) = manifest.pointer("/shared/output") + { + push_manifest_artifact(&mut out, &mut seen, package_ref, manifest_sha256, output)?; } if let Some(layers) = manifest.get("layers").and_then(Value::as_array) { for (index, layer) in layers.iter().enumerate() { @@ -205,17 +205,11 @@ pub(crate) fn required_stage_package_artifacts( } } } - if selection.include_projectors { - if let Some(projectors) = manifest.get("projectors").and_then(Value::as_array) { - for projector in projectors { - push_manifest_artifact( - &mut out, - &mut seen, - package_ref, - manifest_sha256, - projector, - )?; - } + if selection.include_projectors + && let Some(projectors) = manifest.get("projectors").and_then(Value::as_array) + { + for projector in projectors { + push_manifest_artifact(&mut out, &mut seen, package_ref, manifest_sha256, projector)?; } } Ok(out) @@ -250,15 +244,13 @@ pub(crate) fn local_artifact_satisfies( if !metadata.is_file() { return Ok(false); } - if let Some(expected_size) = request.expected_size { - if metadata.len() != expected_size { - return Ok(false); - } + if let Some(expected_size) = request.expected_size + && metadata.len() != expected_size + { + return Ok(false); } - if verify_sha { - if let Some(expected_sha) = request.expected_sha256.as_deref() { - return Ok(file_sha256_hex(&path)?.eq_ignore_ascii_case(expected_sha)); - } + if verify_sha && let Some(expected_sha) = request.expected_sha256.as_deref() { + return Ok(file_sha256_hex(&path)?.eq_ignore_ascii_case(expected_sha)); } Ok(true) } diff --git a/crates/mesh-llm-host-runtime/src/models/catalog.rs b/crates/mesh-llm-host-runtime/src/models/catalog.rs index ab0f60d48b..fbc0acfa90 100644 --- a/crates/mesh-llm-host-runtime/src/models/catalog.rs +++ b/crates/mesh-llm-host-runtime/src/models/catalog.rs @@ -374,10 +374,10 @@ impl MeshDownloadProgress { } } DownloadEvent::Progress { files } => { - if let Some(first) = files.first() { - if !first.filename.is_empty() { - state.filename = first.filename.clone(); - } + if let Some(first) = files.first() + && !first.filename.is_empty() + { + state.filename = first.filename.clone(); } if !files.is_empty() { let reported_downloaded: u64 = @@ -433,10 +433,10 @@ impl ProgressHandler for MeshDownloadProgress { spinner.take(); } Self::draw(&mut state, force); - } else if matches!(event, DownloadEvent::Complete) { - if let Ok(mut spinner) = self.preflight_spinner.lock() { - spinner.take(); - } + } else if matches!(event, DownloadEvent::Complete) + && let Ok(mut spinner) = self.preflight_spinner.lock() + { + spinner.take(); } } } diff --git a/crates/mesh-llm-host-runtime/src/models/delete.rs b/crates/mesh-llm-host-runtime/src/models/delete.rs index fd1c79c593..dc2139d3ad 100644 --- a/crates/mesh-llm-host-runtime/src/models/delete.rs +++ b/crates/mesh-llm-host-runtime/src/models/delete.rs @@ -191,11 +191,12 @@ pub fn collect_delete_paths(resolved_paths: &[PathBuf]) -> Result> } let primary_path = &resolved_paths[0]; - if let Some(record) = usage::load_model_usage_record_for_path(primary_path) { - if record.mesh_managed && !record.managed_paths.is_empty() { - for p in &record.managed_paths { - to_delete.insert(normalize_path(p)); - } + if let Some(record) = usage::load_model_usage_record_for_path(primary_path) + && record.mesh_managed + && !record.managed_paths.is_empty() + { + for p in &record.managed_paths { + to_delete.insert(normalize_path(p)); } } @@ -232,13 +233,13 @@ pub async fn delete_model_by_identifier(identifier: &str) -> Result(&bytes) { - return cached.into_proto(); - } + if let Ok(bytes) = std::fs::read(&cache_path) + && let Ok(cached) = serde_json::from_slice::(&bytes) + { + return cached.into_proto(); } let meta = computed(); if let Some(parent) = cache_path.parent() { diff --git a/crates/mesh-llm-host-runtime/src/models/local.rs b/crates/mesh-llm-host-runtime/src/models/local.rs index c4d1544c20..749e5ef360 100644 --- a/crates/mesh-llm-host-runtime/src/models/local.rs +++ b/crates/mesh-llm-host-runtime/src/models/local.rs @@ -324,31 +324,30 @@ pub fn huggingface_identity_for_path(path: &Path) -> Option Opt continue; } for revision in &repo.revisions { - if let Some(wanted_revision) = model.revision.as_deref() { - if revision.commit_hash != wanted_revision { - continue; - } + if let Some(wanted_revision) = model.revision.as_deref() + && revision.commit_hash != wanted_revision + { + continue; } for file in &revision.files { if !file.file_name.ends_with(".gguf") { @@ -825,10 +824,10 @@ pub fn find_model_path(model_ref: &str) -> PathBuf { return path; } let canonical_dir = huggingface_hub_cache_dir(); - if let Ok(parsed) = model_ref::ModelRef::parse(model_ref) { - if let Some(found) = find_hf_cache_model_ref_path(&canonical_dir, &parsed) { - return found; - } + if let Ok(parsed) = model_ref::ModelRef::parse(model_ref) + && let Some(found) = find_hf_cache_model_ref_path(&canonical_dir, &parsed) + { + return found; } if let Some(found) = find_hf_cache_model_path(&canonical_dir, model_ref) { @@ -896,10 +895,9 @@ fn is_named_mmproj_match(lower: &str, model_base: &str, model_stem: &str) -> boo if let Some((prefix, _)) = lower .split_once("-mmproj") .or_else(|| lower.split_once("_mmproj")) + && (model_base.starts_with(prefix) || model_stem.starts_with(prefix)) { - if model_base.starts_with(prefix) || model_stem.starts_with(prefix) { - return true; - } + return true; } // Try pattern: mmproj-... (model name after mmproj) if let Some(after) = lower @@ -1015,24 +1013,22 @@ pub fn find_mmproj_path(model_name: &str, model_path: &Path) -> Option if !named_matches.is_empty() { // Multiple named matches: try quant-aware selection before precision fallback - if named_matches.len() > 1 { - if let Some(ref quant) = model_quant { - if let Some(candidate) = pick_quant_match(&named_matches, quant) { - return Some(candidate); - } - } + if named_matches.len() > 1 + && let Some(ref quant) = model_quant + && let Some(candidate) = pick_quant_match(&named_matches, quant) + { + return Some(candidate); } // Single named match, or quant-match failed: precision-variant pick or None return choose_mmproj_candidate(&named_matches); } // No named matches: try quant-aware selection among all siblings, then precision fallback - if mmproj_siblings.len() > 1 { - if let Some(ref quant) = model_quant { - if let Some(candidate) = pick_quant_match(&mmproj_siblings, quant) { - return Some(candidate); - } - } + if mmproj_siblings.len() > 1 + && let Some(ref quant) = model_quant + && let Some(candidate) = pick_quant_match(&mmproj_siblings, quant) + { + return Some(candidate); } choose_mmproj_candidate(&mmproj_siblings) } diff --git a/crates/mesh-llm-host-runtime/src/models/resolve/mod.rs b/crates/mesh-llm-host-runtime/src/models/resolve/mod.rs index db9251fd26..a0f769fa21 100644 --- a/crates/mesh-llm-host-runtime/src/models/resolve/mod.rs +++ b/crates/mesh-llm-host-runtime/src/models/resolve/mod.rs @@ -241,12 +241,12 @@ pub async fn resolve_model_spec_with_progress(input: &Path, progress: bool) -> R record_resolved_model_usage(&installed_path, Some(&model_ref)); return Ok(installed_path); } - if let Ok(canonical) = canonicalize_model_ref_input(&raw).await { - if canonical != raw { - return download_exact_ref_with_progress(&canonical, progress) - .await - .with_context(|| format!("Resolve model spec {raw}")); - } + if let Ok(canonical) = canonicalize_model_ref_input(&raw).await + && canonical != raw + { + return download_exact_ref_with_progress(&canonical, progress) + .await + .with_context(|| format!("Resolve model spec {raw}")); } bail!( "Model not found: {raw}\nNot a local file, not in the Hugging Face cache, not in catalog.\n\ @@ -979,10 +979,10 @@ async fn fetch_repo_sibling_entries( #[cfg(test)] { let func = REPO_SIBLING_ENTRIES_OVERRIDE.lock().unwrap().clone(); - if let Some(func) = func { - if let Some(entries) = func(repo, revision) { - return Ok(entries); - } + if let Some(func) = func + && let Some(entries) = func(repo, revision) + { + return Ok(entries); } } diff --git a/crates/mesh-llm-host-runtime/src/models/usage.rs b/crates/mesh-llm-host-runtime/src/models/usage.rs index ff322f024b..219e89a3fa 100644 --- a/crates/mesh-llm-host-runtime/src/models/usage.rs +++ b/crates/mesh-llm-host-runtime/src/models/usage.rs @@ -322,11 +322,11 @@ fn plan_cleanup_entries( } let last_used = parse_timestamp(&record.last_used_at).unwrap_or(DateTime::::UNIX_EPOCH); - if let Some(cutoff) = cutoff { - if last_used > cutoff { - *skipped_recent += 1; - continue; - } + if let Some(cutoff) = cutoff + && last_used > cutoff + { + *skipped_recent += 1; + continue; } let removable_paths: Vec = unique_paths(record.managed_paths.clone()) @@ -371,13 +371,12 @@ fn execute_model_cleanup_entries(entries: Vec) -> Result Option { // prompt and no tools — plenty of real chats look like this, and without // a fallback the prefix cache is never populated, so turn-2+ has no way // to stick to the same peer and reuse its serving-runtime KV cache. - if !found { - if let Some(user_hash) = first_user_hash_from_body(body) { - hash = hash_combine(hash, user_hash); - found = true; - } + if !found && let Some(user_hash) = first_user_hash_from_body(body) { + hash = hash_combine(hash, user_hash); + found = true; } found.then_some(hash) @@ -710,11 +708,11 @@ pub fn prepare_remote_targets_for_request( let eligible = affinity.route_eligible_candidates(model, &ordered); if eligible.len() != ordered.len() { - if let (Some(prefix_hash), Some(target)) = (learn_prefix_hash, cached_target.as_ref()) { - if !eligible.contains(target) { - affinity.forget_target(model, prefix_hash, target); - cached_target = None; - } + if let (Some(prefix_hash), Some(target)) = (learn_prefix_hash, cached_target.as_ref()) + && !eligible.contains(target) + { + affinity.forget_target(model, prefix_hash, target); + cached_target = None; } ordered = eligible; } diff --git a/crates/mesh-llm-host-runtime/src/network/nostr.rs b/crates/mesh-llm-host-runtime/src/network/nostr.rs index 6bdce76382..071c5b4eaf 100644 --- a/crates/mesh-llm-host-runtime/src/network/nostr.rs +++ b/crates/mesh-llm-host-runtime/src/network/nostr.rs @@ -1097,10 +1097,10 @@ pub fn score_mesh(mesh: &DiscoveredMesh, _now_secs: u64, last_mesh_id: Option<&s } // Sticky preference: strong bonus for the mesh we were last on - if let (Some(last_id), Some(mesh_id)) = (last_mesh_id, &mesh.listing.mesh_id) { - if last_id == mesh_id { - score += 500; // strong preference, not infinite — dead/degraded mesh loses on other factors - } + if let (Some(last_id), Some(mesh_id)) = (last_mesh_id, &mesh.listing.mesh_id) + && last_id == mesh_id + { + score += 500; // strong preference, not infinite — dead/degraded mesh loses on other factors } // Capacity: prefer meshes that aren't full @@ -1318,7 +1318,7 @@ pub fn auto_model_pack(vram_gb: f64) -> Vec { let primary = on_disk_fit .or(any_fit) - .map(|(name, _)| name.to_string()) + .map(|(name, _)| catalog_ref(name)) .unwrap_or_else(|| catalog_ref("Qwen3-4B-Q4_K_M")); vec![primary] diff --git a/crates/mesh-llm-host-runtime/src/network/openai/ingress.rs b/crates/mesh-llm-host-runtime/src/network/openai/ingress.rs index 64d6b062e4..9433713529 100644 --- a/crates/mesh-llm-host-runtime/src/network/openai/ingress.rs +++ b/crates/mesh-llm-host-runtime/src/network/openai/ingress.rs @@ -147,10 +147,10 @@ async fn handle_models_list_request( ) { let mut models = callable_models(targets); models.extend(node.models_being_served().await); - if let Some(plugin_manager) = plugin_manager { - if let Ok(mut external_models) = plugin_manager.inference_models().await { - models.append(&mut external_models); - } + if let Some(plugin_manager) = plugin_manager + && let Ok(mut external_models) = plugin_manager.inference_models().await + { + models.append(&mut external_models); } models.sort(); models.dedup(); @@ -169,12 +169,12 @@ async fn collect_available_models_for_auto_route( available_models.push(name); } } - if let Some(plugin_manager) = plugin_manager { - if let Ok(external_models) = plugin_manager.inference_models().await { - for name in external_models { - if !available_models.iter().any(|existing| existing == &name) { - available_models.push(name); - } + if let Some(plugin_manager) = plugin_manager + && let Ok(external_models) = plugin_manager.inference_models().await + { + for name in external_models { + if !available_models.iter().any(|existing| existing == &name) { + available_models.push(name); } } } diff --git a/crates/mesh-llm-host-runtime/src/network/openai/moa_gateway.rs b/crates/mesh-llm-host-runtime/src/network/openai/moa_gateway.rs index fc8bf8bef2..d2e5a9cdc6 100644 --- a/crates/mesh-llm-host-runtime/src/network/openai/moa_gateway.rs +++ b/crates/mesh-llm-host-runtime/src/network/openai/moa_gateway.rs @@ -672,7 +672,7 @@ impl moa::ModelBackend for RemoteModelBackend { let mut raw = http_request.into_bytes(); raw.extend_from_slice(&body_bytes); - let result = tokio::time::timeout(timeout, async { + tokio::time::timeout(timeout, async { let (mut send, mut recv) = self .node .open_http_tunnel(self.peer_id) @@ -689,8 +689,7 @@ impl moa::ModelBackend for RemoteModelBackend { parse_quic_http_response(&response) }) .await - .map_err(|_| format!("remote timeout after {}s", timeout.as_secs()))?; - result + .map_err(|_| format!("remote timeout after {}s", timeout.as_secs()))? } } diff --git a/crates/mesh-llm-host-runtime/src/network/openai/transport.rs b/crates/mesh-llm-host-runtime/src/network/openai/transport.rs index 84df684d46..9be2f400c4 100644 --- a/crates/mesh-llm-host-runtime/src/network/openai/transport.rs +++ b/crates/mesh-llm-host-runtime/src/network/openai/transport.rs @@ -2696,12 +2696,12 @@ fn rewrite_http_request_target( let mut rebuilt = format!("{method} {new_path} {version}\r\n"); let mut saw_host = false; for line in lines { - if let Some((name, _value)) = line.split_once(':') { - if name.eq_ignore_ascii_case("host") { - rebuilt.push_str(&format!("Host: {host}:{port}\r\n")); - saw_host = true; - continue; - } + if let Some((name, _value)) = line.split_once(':') + && name.eq_ignore_ascii_case("host") + { + rebuilt.push_str(&format!("Host: {host}:{port}\r\n")); + saw_host = true; + continue; } rebuilt.push_str(line); rebuilt.push_str("\r\n"); @@ -2871,10 +2871,8 @@ async fn build_mesh_request_plan( if is_auto_request { inject_mesh_hooks_flag(&mut request.raw, true); } - if track_demand { - if let Some(name) = effective_model.as_deref() { - node.record_request(name); - } + if track_demand && let Some(name) = effective_model.as_deref() { + node.record_request(name); } let resolved_hosts = match resolve_mesh_target_hosts(node, effective_model.as_deref()).await { @@ -2910,10 +2908,10 @@ async fn build_mesh_request_plan( } fn rewrite_effective_model(request: &mut BufferedHttpRequest, effective_model: Option<&str>) { - if let Some(name) = effective_model { - if request.model_name.as_deref() != Some(name) { - rewrite_model_field(request, name); - } + if let Some(name) = effective_model + && request.model_name.as_deref() != Some(name) + { + rewrite_model_field(request, name); } } @@ -3242,10 +3240,9 @@ fn forget_mesh_cached_target( effective_model, prepared.learn_prefix_hash, prepared.cached_target.as_ref(), - ) { - if cached_target == failed_target { - affinity.forget_target(name, prefix_hash, failed_target); - } + ) && cached_target == failed_target + { + affinity.forget_target(name, prefix_hash, failed_target); } } @@ -3719,10 +3716,10 @@ fn handle_delivered_route_model_attempt( state: &RouteModelState, affinity: &AffinityRouter, ) -> RouteModelDisposition { - if should_learn_affinity(status_code) { - if let Some(prefix_hash) = selection.learn_prefix_hash { - affinity.learn_target(model, prefix_hash, target); - } + if should_learn_affinity(status_code) + && let Some(prefix_hash) = selection.learn_prefix_hash + { + affinity.learn_target(model, prefix_hash, target); } node.record_routed_request( Some(model), @@ -3789,10 +3786,9 @@ fn forget_selected_route_model_target( if let (Some(prefix_hash), Some(cached_target)) = ( selection.learn_prefix_hash, selection.cached_target.as_ref(), - ) { - if cached_target == target { - affinity.forget_target(model, prefix_hash, target); - } + ) && cached_target == target + { + affinity.forget_target(model, prefix_hash, target); } } @@ -4075,12 +4071,11 @@ fn public_model_id(model_name: &str, descriptor: Option<&mesh::ServedModelDescri // local models), and finally the internal model_name (which // always carries the quant suffix our resolver knows how to // route). - if let Some(descriptor) = descriptor { - if descriptor_can_produce_lossless_id(&descriptor.identity) { - if let Some(id) = public_model_id_from_identity(&descriptor.identity) { - return id; - } - } + if let Some(descriptor) = descriptor + && descriptor_can_produce_lossless_id(&descriptor.identity) + && let Some(id) = public_model_id_from_identity(&descriptor.identity) + { + return id; } if let Some(id) = public_model_id_from_local_path(model_name) { diff --git a/crates/mesh-llm-host-runtime/src/network/router.rs b/crates/mesh-llm-host-runtime/src/network/router.rs index 5f2fd1fa14..a36bb087f9 100644 --- a/crates/mesh-llm-host-runtime/src/network/router.rs +++ b/crates/mesh-llm-host-runtime/src/network/router.rs @@ -732,10 +732,10 @@ fn is_single_digit_b_name(name: &str) -> bool { continue; } // And the byte after that must not be another digit (avoid BF16-like continuations) - if let Some(&after) = bytes.get(i + 2) { - if after.is_ascii_digit() { - continue; - } + if let Some(&after) = bytes.get(i + 2) + && after.is_ascii_digit() + { + continue; } return true; } diff --git a/crates/mesh-llm-host-runtime/src/plugin/config.rs b/crates/mesh-llm-host-runtime/src/plugin/config.rs index 403dfde091..4b3502a876 100644 --- a/crates/mesh-llm-host-runtime/src/plugin/config.rs +++ b/crates/mesh-llm-host-runtime/src/plugin/config.rs @@ -939,17 +939,16 @@ pub fn load_config(override_path: Option<&Path>) -> Result { } pub(crate) fn validate_config(config: &MeshConfig) -> Result<()> { - if let Some(version) = config.version { - if version != 1 { - bail!("unsupported config version {version}; expected version = 1"); - } + if let Some(version) = config.version + && version != 1 + { + bail!("unsupported config version {version}; expected version = 1"); } - if let Some(bind) = config.owner_control.bind { - if bind.port() == 0 && !bind.ip().is_loopback() { - bail!( - "owner_control.bind must use a concrete port when binding a non-loopback address" - ); - } + if let Some(bind) = config.owner_control.bind + && bind.port() == 0 + && !bind.ip().is_loopback() + { + bail!("owner_control.bind must use a concrete port when binding a non-loopback address"); } if let Some(advertise_addr) = config.owner_control.advertise_addr { if advertise_addr.port() == 0 { @@ -959,10 +958,10 @@ pub(crate) fn validate_config(config: &MeshConfig) -> Result<()> { bail!("owner_control.advertise_addr must not use an unspecified IP address"); } } - if let Some(parallel) = config.gpu.parallel { - if parallel < 1 { - bail!("gpu.parallel must be at least 1, got {parallel}"); - } + if let Some(parallel) = config.gpu.parallel + && parallel < 1 + { + bail!("gpu.parallel must be at least 1, got {parallel}"); } validate_telemetry_config(&config.telemetry)?; let defaults_hardware = config @@ -1126,10 +1125,10 @@ fn validate_model_fit(config: &ModelFitConfig, base_path: &str) -> Result<()> { validate_optional_positive_u32(config.ctx_size, &format!("{base_path}.ctx_size"))?; validate_optional_positive_u32(config.batch, &format!("{base_path}.batch"))?; validate_optional_positive_u32(config.ubatch, &format!("{base_path}.ubatch"))?; - if let (Some(batch), Some(ubatch)) = (config.batch, config.ubatch) { - if ubatch > batch { - bail!("{base_path}.ubatch must be less than or equal to {base_path}.batch"); - } + if let (Some(batch), Some(ubatch)) = (config.batch, config.ubatch) + && ubatch > batch + { + bail!("{base_path}.ubatch must be less than or equal to {base_path}.batch"); } validate_optional_non_empty( config.cache_type_k.as_deref(), @@ -1160,18 +1159,19 @@ fn validate_model_fit(config: &ModelFitConfig, base_path: &str) -> Result<()> { config.context_shift.as_ref(), &format!("{base_path}.context_shift"), )?; - if let Some(cache_idle_slots) = config.cache_idle_slots { - if cache_idle_slots > 0 && matches!(config.prompt_cache, Some(BoolOrAuto::Bool(false))) { - bail!("{base_path}.cache_idle_slots requires {base_path}.prompt_cache = true"); - } + if let Some(cache_idle_slots) = config.cache_idle_slots + && cache_idle_slots > 0 + && matches!(config.prompt_cache, Some(BoolOrAuto::Bool(false))) + { + bail!("{base_path}.cache_idle_slots requires {base_path}.prompt_cache = true"); } if let Some(prefix_cache) = &config.prefix_cache { validate_prefix_cache(prefix_cache, &format!("{base_path}.prefix_cache"))?; } - if let (Some(keep_tokens), Some(ctx_size)) = (config.keep_tokens, config.ctx_size) { - if keep_tokens > ctx_size { - bail!("{base_path}.keep_tokens must be less than or equal to {base_path}.ctx_size"); - } + if let (Some(keep_tokens), Some(ctx_size)) = (config.keep_tokens, config.ctx_size) + && keep_tokens > ctx_size + { + bail!("{base_path}.keep_tokens must be less than or equal to {base_path}.ctx_size"); } validate_optional_positive_u32( config.checkpoint_interval, @@ -1319,10 +1319,10 @@ fn validate_hardware( } fn validate_throughput(config: &ThroughputConfig, base_path: &str) -> Result<()> { - if let Some(parallel) = config.parallel { - if parallel < 1 { - bail!("{base_path}.parallel must be at least 1, got {parallel}"); - } + if let Some(parallel) = config.parallel + && parallel < 1 + { + bail!("{base_path}.parallel must be at least 1, got {parallel}"); } validate_bool_or_auto( config.continuous_batching.as_ref(), @@ -1350,10 +1350,10 @@ fn validate_throughput(config: &ThroughputConfig, base_path: &str) -> Result<()> } } validate_optional_non_empty(config.numa.as_deref(), &format!("{base_path}.numa"))?; - if let Some(slot_prompt_similarity) = config.slot_prompt_similarity { - if slot_prompt_similarity < 0.0 { - bail!("{base_path}.slot_prompt_similarity must be non-negative"); - } + if let Some(slot_prompt_similarity) = config.slot_prompt_similarity + && slot_prompt_similarity < 0.0 + { + bail!("{base_path}.slot_prompt_similarity must be non-negative"); } if config.sleep_idle_seconds.is_some() { bail!("{base_path}.sleep_idle_seconds is documented-rejected and must not be set"); @@ -1460,12 +1460,12 @@ fn validate_speculative(config: &SpeculativeConfig, base_path: &str) -> Result<( config.draft_max_tokens, &format!("{base_path}.draft_max_tokens"), )?; - if let (Some(min), Some(max)) = (config.draft_min_tokens, config.draft_max_tokens) { - if min > max { - bail!( - "{base_path}.draft_min_tokens must be less than or equal to {base_path}.draft_max_tokens" - ); - } + if let (Some(min), Some(max)) = (config.draft_min_tokens, config.draft_max_tokens) + && min > max + { + bail!( + "{base_path}.draft_min_tokens must be less than or equal to {base_path}.draft_max_tokens" + ); } validate_probability( config.draft_acceptance_threshold, @@ -1475,10 +1475,10 @@ fn validate_speculative(config: &SpeculativeConfig, base_path: &str) -> Result<( config.draft_split_probability, &format!("{base_path}.draft_split_probability"), )?; - if let Some(gpu_layers) = config.draft_gpu_layers { - if gpu_layers < -1 { - bail!("{base_path}.draft_gpu_layers must be at least -1"); - } + if let Some(gpu_layers) = config.draft_gpu_layers + && gpu_layers < -1 + { + bail!("{base_path}.draft_gpu_layers must be at least -1"); } validate_optional_non_empty( config.draft_device.as_deref(), @@ -1495,10 +1495,10 @@ fn validate_speculative(config: &SpeculativeConfig, base_path: &str) -> Result<( )?; validate_optional_positive_u32(config.ngram_min, &format!("{base_path}.ngram_min"))?; validate_optional_positive_u32(config.ngram_max, &format!("{base_path}.ngram_max"))?; - if let (Some(min), Some(max)) = (config.ngram_min, config.ngram_max) { - if max < min { - bail!("{base_path}.ngram_max must be greater than or equal to {base_path}.ngram_min"); - } + if let (Some(min), Some(max)) = (config.ngram_min, config.ngram_max) + && max < min + { + bail!("{base_path}.ngram_max must be greater than or equal to {base_path}.ngram_min"); } validate_bool_or_auto( config.spec_default.as_ref(), @@ -1530,10 +1530,10 @@ fn validate_request_defaults(config: &RequestDefaultsConfig, base_path: &str) -> } validate_non_negative_f64(config.temperature, &format!("{base_path}.temperature"))?; validate_probability(config.top_p, &format!("{base_path}.top_p"))?; - if let Some(top_k) = config.top_k { - if top_k < 0 { - bail!("{base_path}.top_k must be greater than or equal to 0"); - } + if let Some(top_k) = config.top_k + && top_k < 0 + { + bail!("{base_path}.top_k must be greater than or equal to 0"); } validate_probability(config.min_p, &format!("{base_path}.min_p"))?; validate_probability(config.typical_p, &format!("{base_path}.typical_p"))?; @@ -1550,10 +1550,10 @@ fn validate_request_defaults(config: &RequestDefaultsConfig, base_path: &str) -> config.repeat_penalty, &format!("{base_path}.repeat_penalty"), )?; - if let Some(repeat_last_n) = config.repeat_last_n { - if repeat_last_n < -1 { - bail!("{base_path}.repeat_last_n must be greater than or equal to -1"); - } + if let Some(repeat_last_n) = config.repeat_last_n + && repeat_last_n < -1 + { + bail!("{base_path}.repeat_last_n must be greater than or equal to -1"); } validate_non_negative_f64( config.presence_penalty, @@ -1650,22 +1650,18 @@ fn validate_multimodal_pair( if let (Some(hardware), Some(multimodal)) = (hardware, multimodal) { if let (Some(hardware_mmproj), Some(multimodal_mmproj)) = (hardware.mmproj.as_deref(), multimodal.mmproj.as_deref()) + && hardware_mmproj != multimodal_mmproj { - if hardware_mmproj != multimodal_mmproj { - bail!( - "{multimodal_path}.mmproj must match {hardware_path}.mmproj when both are set" - ); - } + bail!("{multimodal_path}.mmproj must match {hardware_path}.mmproj when both are set"); } if let (Some(hardware_offload), Some(multimodal_offload)) = ( hardware.mmproj_offload.as_ref(), multimodal.mmproj_offload.as_ref(), - ) { - if hardware_offload != multimodal_offload { - bail!( - "{multimodal_path}.mmproj_offload must match {hardware_path}.mmproj_offload when both are set" - ); - } + ) && hardware_offload != multimodal_offload + { + bail!( + "{multimodal_path}.mmproj_offload must match {hardware_path}.mmproj_offload when both are set" + ); } } Ok(()) @@ -1681,12 +1677,12 @@ fn validate_multimodal(config: &MultimodalConfig, base_path: &str) -> Result<()> config.mmproj_offload.as_ref(), &format!("{base_path}.mmproj_offload"), )?; - if let (Some(min), Some(max)) = (config.image_min_tokens, config.image_max_tokens) { - if min > max { - bail!( - "{base_path}.image_min_tokens must be less than or equal to {base_path}.image_max_tokens" - ); - } + if let (Some(min), Some(max)) = (config.image_min_tokens, config.image_max_tokens) + && min > max + { + bail!( + "{base_path}.image_min_tokens must be less than or equal to {base_path}.image_max_tokens" + ); } if config.embeddings.is_some() { bail!("{base_path}.embeddings is documented-rejected and must not be set"); @@ -1798,28 +1794,28 @@ fn validate_bool_or_auto(value: Option<&BoolOrAuto>, path: &str) -> Result<()> { } fn validate_probability(value: Option, path: &str) -> Result<()> { - if let Some(value) = value { - if !(0.0..=1.0).contains(&value) { - bail!("{path} must be between 0.0 and 1.0"); - } + if let Some(value) = value + && !(0.0..=1.0).contains(&value) + { + bail!("{path} must be between 0.0 and 1.0"); } Ok(()) } fn validate_non_negative_f64(value: Option, path: &str) -> Result<()> { - if let Some(value) = value { - if value < 0.0 { - bail!("{path} must be greater than or equal to 0.0"); - } + if let Some(value) = value + && value < 0.0 + { + bail!("{path} must be greater than or equal to 0.0"); } Ok(()) } fn validate_positive_f64(value: Option, path: &str) -> Result<()> { - if let Some(value) = value { - if value <= 0.0 { - bail!("{path} must be greater than 0.0"); - } + if let Some(value) = value + && value <= 0.0 + { + bail!("{path} must be greater than 0.0"); } Ok(()) } @@ -1847,35 +1843,35 @@ fn validate_string_list(values: &[String], path: &str) -> Result<()> { } fn validate_telemetry_config(config: &TelemetryConfig) -> Result<()> { - if let Some(service_name) = &config.service_name { - if service_name.trim().is_empty() { - bail!("telemetry.service_name must not be empty when set"); - } + if let Some(service_name) = &config.service_name + && service_name.trim().is_empty() + { + bail!("telemetry.service_name must not be empty when set"); } - if let Some(endpoint) = &config.endpoint { - if endpoint.trim().is_empty() { - bail!("telemetry.endpoint must not be empty when set"); - } + if let Some(endpoint) = &config.endpoint + && endpoint.trim().is_empty() + { + bail!("telemetry.endpoint must not be empty when set"); } - if let Some(endpoint) = &config.metrics.endpoint { - if endpoint.trim().is_empty() { - bail!("telemetry.metrics.endpoint must not be empty when set"); - } + if let Some(endpoint) = &config.metrics.endpoint + && endpoint.trim().is_empty() + { + bail!("telemetry.metrics.endpoint must not be empty when set"); } for key in config.headers.keys() { if key.trim().is_empty() { bail!("telemetry.headers keys must not be empty"); } } - if let Some(export_interval_secs) = config.export_interval_secs { - if export_interval_secs < 1 { - bail!("telemetry.export_interval_secs must be at least 1"); - } + if let Some(export_interval_secs) = config.export_interval_secs + && export_interval_secs < 1 + { + bail!("telemetry.export_interval_secs must be at least 1"); } - if let Some(queue_size) = config.queue_size { - if queue_size < 1 { - bail!("telemetry.queue_size must be at least 1"); - } + if let Some(queue_size) = config.queue_size + && queue_size < 1 + { + bail!("telemetry.queue_size must be at least 1"); } if config.prompt_shape_metrics { bail!("telemetry.prompt_shape_metrics is not supported yet and must remain false"); diff --git a/crates/mesh-llm-host-runtime/src/plugin/stapler.rs b/crates/mesh-llm-host-runtime/src/plugin/stapler.rs index 149c4478b4..68c4c6d927 100644 --- a/crates/mesh-llm-host-runtime/src/plugin/stapler.rs +++ b/crates/mesh-llm-host-runtime/src/plugin/stapler.rs @@ -20,12 +20,11 @@ pub(crate) fn operation(exposed_name: String, manifest: &proto::OperationManifes if let Some(title) = &manifest.title { operation = operation.with_title(title.clone()); } - if let Some(output_schema_json) = &manifest.output_schema_json { - if let Ok(schema) = serde_json::from_str::(output_schema_json) { - if let Some(schema) = schema.as_object() { - operation.output_schema = Some(Arc::new(schema.clone())); - } - } + if let Some(output_schema_json) = &manifest.output_schema_json + && let Ok(schema) = serde_json::from_str::(output_schema_json) + && let Some(schema) = schema.as_object() + { + operation.output_schema = Some(Arc::new(schema.clone())); } operation } diff --git a/crates/mesh-llm-host-runtime/src/plugins/blackboard/mod.rs b/crates/mesh-llm-host-runtime/src/plugins/blackboard/mod.rs index 465a432b4a..43e5de6c2d 100644 --- a/crates/mesh-llm-host-runtime/src/plugins/blackboard/mod.rs +++ b/crates/mesh-llm-host-runtime/src/plugins/blackboard/mod.rs @@ -485,8 +485,8 @@ fn build_blackboard_plugin(name: String) -> mesh_llm_plugin::SimplePlugin { }, on_mesh_event: move |event, context| { Box::pin(async move { - if event.kind() == mesh_llm_plugin::proto::mesh_event::Kind::PeerUp { - if let Some(peer) = event.peer { + if event.kind() == mesh_llm_plugin::proto::mesh_event::Kind::PeerUp + && let Some(peer) = event.peer { context .send_json_channel( BLACKBOARD_CHANNEL, @@ -496,7 +496,6 @@ fn build_blackboard_plugin(name: String) -> mesh_llm_plugin::SimplePlugin { ) .await?; } - } Ok(()) }) }, diff --git a/crates/mesh-llm-host-runtime/src/runtime/discovery.rs b/crates/mesh-llm-host-runtime/src/runtime/discovery.rs index 48c965c1b9..331994e4e0 100644 --- a/crates/mesh-llm-host-runtime/src/runtime/discovery.rs +++ b/crates/mesh-llm-host-runtime/src/runtime/discovery.rs @@ -318,17 +318,17 @@ pub(crate) async fn check_mesh( let mut models: Vec = Vec::new(); for i in 0..40 { - if let Ok(resp) = client.get(&url).send().await { - if let Ok(body) = resp.json::().await { - models = body["data"] - .as_array() - .unwrap_or(&vec![]) - .iter() - .filter_map(|m| m["id"].as_str().map(String::from)) - .collect(); - if !models.is_empty() { - break; - } + if let Ok(resp) = client.get(&url).send().await + && let Ok(body) = resp.json::().await + { + models = body["data"] + .as_array() + .unwrap_or(&vec![]) + .iter() + .filter_map(|m| m["id"].as_str().map(String::from)) + .collect(); + if !models.is_empty() { + break; } } tokio::time::sleep(std::time::Duration::from_secs(3)).await; diff --git a/crates/mesh-llm-host-runtime/src/runtime/local.rs b/crates/mesh-llm-host-runtime/src/runtime/local.rs index eb607f679b..bf410a5edb 100644 --- a/crates/mesh-llm-host-runtime/src/runtime/local.rs +++ b/crates/mesh-llm-host-runtime/src/runtime/local.rs @@ -1123,18 +1123,18 @@ async fn load_split_runtime_generation( &mut cleanup_on_error, )) .await; - if let Err(error) = &result { - if cleanup_on_error { - tracing::warn!( - model_ref = spec.model_ref, - topology_id = %spec.generation.topology_id, - run_id = %spec.generation.run_id, - generation = spec.generation.generation, - error = %error, - "cleaning up split runtime generation after failed load" - ); - stop_split_generation(spec.node, spec.generation, spec.generation.generation).await; - } + if let Err(error) = &result + && cleanup_on_error + { + tracing::warn!( + model_ref = spec.model_ref, + topology_id = %spec.generation.topology_id, + run_id = %spec.generation.run_id, + generation = spec.generation.generation, + error = %error, + "cleaning up split runtime generation after failed load" + ); + stop_split_generation(spec.node, spec.generation, spec.generation.generation).await; } result } diff --git a/crates/mesh-llm-host-runtime/src/runtime/mod.rs b/crates/mesh-llm-host-runtime/src/runtime/mod.rs index 984e5fbd5d..4029a593da 100644 --- a/crates/mesh-llm-host-runtime/src/runtime/mod.rs +++ b/crates/mesh-llm-host-runtime/src/runtime/mod.rs @@ -413,10 +413,10 @@ impl RuntimeDashboardSnapshotProvider { async fn inventory_snapshot(&self) -> crate::models::LocalModelInventorySnapshot { { let cache = self.inventory_snapshot_cache.lock().await; - if let Some(captured_at) = cache.captured_at { - if captured_at.elapsed() < self.inventory_snapshot_ttl { - return cache.snapshot.clone(); - } + if let Some(captured_at) = cache.captured_at + && captured_at.elapsed() < self.inventory_snapshot_ttl + { + return cache.snapshot.clone(); } } @@ -2945,10 +2945,10 @@ async fn maybe_discover_join_candidates( return Ok(()); } - if let Some(name) = cli.discover.as_ref().filter(|name| !name.is_empty()) { - if cli.mesh_name.is_none() { - cli.mesh_name = Some(name.clone()); - } + if let Some(name) = cli.discover.as_ref().filter(|name| !name.is_empty()) + && cli.mesh_name.is_none() + { + cli.mesh_name = Some(name.clone()); } let my_vram_gb = mesh::detect_vram_bytes_capped(cli.max_vram) as f64 / 1e9; @@ -3504,10 +3504,10 @@ fn build_startup_model_specs( flash_attention: FlashAttentionType::Auto, }); } - if let Some(mmproj) = &cli.mmproj { - if let Some(primary) = specs.first_mut() { - primary.mmproj_ref = Some(mmproj.clone()); - } + if let Some(mmproj) = &cli.mmproj + && let Some(primary) = specs.first_mut() + { + primary.mmproj_ref = Some(mmproj.clone()); } return Ok(specs); } @@ -3877,16 +3877,14 @@ fn startup_launch_plan( port: api_port, pid: None, }]; - if !headless { - if let Some(console_port) = console_port { - webserver_rows.push(DashboardEndpointRow { - label: "Console".to_string(), - status: RuntimeStatus::NotReady, - url: format!("http://localhost:{console_port}"), - port: console_port, - pid: None, - }); - } + if !headless && let Some(console_port) = console_port { + webserver_rows.push(DashboardEndpointRow { + label: "Console".to_string(), + status: RuntimeStatus::NotReady, + url: format!("http://localhost:{console_port}"), + port: console_port, + pid: None, + }); } sort_dashboard_endpoint_rows(&mut webserver_rows); @@ -3927,10 +3925,8 @@ fn serve_path_builtin_endpoint_ready_events( ) -> Vec { let mut events = vec![OutputEvent::ApiReady { url: api_url }]; - if !headless { - if let Some(console_url) = console_url { - events.push(OutputEvent::WebserverReady { url: console_url }); - } + if !headless && let Some(console_url) = console_url { + events.push(OutputEvent::WebserverReady { url: console_url }); } events @@ -4609,10 +4605,10 @@ async fn handle_auto_decision( // Clients skip health probe — joining itself is the test. // Queue all candidates so we can fall back if the top one is unreachable. let (_, mesh) = &candidates[0]; - if cli.mesh_name.is_none() { - if let Some(ref name) = mesh.listing.name { - cli.mesh_name = Some(name.clone()); - } + if cli.mesh_name.is_none() + && let Some(ref name) = mesh.listing.name + { + cli.mesh_name = Some(name.clone()); } let _ = emit_event(OutputEvent::DiscoveryJoined { mesh: mesh @@ -5512,10 +5508,10 @@ fn update_cli_with_successful_run_auto_join( cli.join.clear(); if let Some((token, mesh_name)) = successful_join { cli.join.push(token); - if cli.mesh_name.is_none() { - if let Some(name) = mesh_name { - cli.mesh_name = Some(name); - } + if cli.mesh_name.is_none() + && let Some(name) = mesh_name + { + cli.mesh_name = Some(name); } } } @@ -8242,10 +8238,10 @@ fn update_pi_models_json(model_id: &str, port: u16) { if let Some(parent) = models_path.parent() { let _ = std::fs::create_dir_all(parent); } - if let Ok(json) = serde_json::to_string_pretty(&root) { - if let Err(e) = std::fs::write(&models_path, json) { - tracing::warn!("Failed to update {}: {e}", models_path.display()); - } + if let Ok(json) = serde_json::to_string_pretty(&root) + && let Err(e) = std::fs::write(&models_path, json) + { + tracing::warn!("Failed to update {}: {e}", models_path.display()); } } diff --git a/crates/mesh-llm-host-runtime/src/runtime_data/collector.rs b/crates/mesh-llm-host-runtime/src/runtime_data/collector.rs index a9fed38974..8beee80093 100644 --- a/crates/mesh-llm-host-runtime/src/runtime_data/collector.rs +++ b/crates/mesh-llm-host-runtime/src/runtime_data/collector.rs @@ -184,14 +184,13 @@ impl RuntimeDataCollector { build_llama_runtime_snapshot(&runtime_status.llama_runtime.metrics, snapshot); let mut changed = false; - if let Some(instance_id) = next_runtime.slots.instance_id.clone() { - if runtime_status.llama_runtime_by_instance.get(&instance_id) != Some(&next_runtime) - { - runtime_status - .llama_runtime_by_instance - .insert(instance_id, next_runtime.clone()); - changed = true; - } + if let Some(instance_id) = next_runtime.slots.instance_id.clone() + && runtime_status.llama_runtime_by_instance.get(&instance_id) != Some(&next_runtime) + { + runtime_status + .llama_runtime_by_instance + .insert(instance_id, next_runtime.clone()); + changed = true; } if let Some(model) = next_runtime.slots.model.clone() { diff --git a/crates/mesh-llm-routing/src/lib.rs b/crates/mesh-llm-routing/src/lib.rs index bdeb2d5c70..38bc8933f1 100644 --- a/crates/mesh-llm-routing/src/lib.rs +++ b/crates/mesh-llm-routing/src/lib.rs @@ -9,17 +9,17 @@ pub fn total_model_bytes(model: &Path) -> u64 { let name = model.to_string_lossy(); if let Some(pos) = name.find("-00001-of-") { let of_pos = pos + 10; - if let Some(ext_pos) = name[of_pos..].find(".gguf") { - if let Ok(n_split) = name[of_pos..of_pos + ext_pos].parse::() { - let prefix = &name[..pos + 1]; - let suffix = &name[of_pos + ext_pos..]; - let mut total: u64 = 0; - for i in 1..=n_split { - let split_name = format!("{}{:05}-of-{:05}{}", prefix, i, n_split, suffix); - total += std::fs::metadata(&split_name).map(|m| m.len()).unwrap_or(0); - } - return total; + if let Some(ext_pos) = name[of_pos..].find(".gguf") + && let Ok(n_split) = name[of_pos..of_pos + ext_pos].parse::() + { + let prefix = &name[..pos + 1]; + let suffix = &name[of_pos + ext_pos..]; + let mut total: u64 = 0; + for i in 1..=n_split { + let split_name = format!("{}{:05}-of-{:05}{}", prefix, i, n_split, suffix); + total += std::fs::metadata(&split_name).map(|m| m.len()).unwrap_or(0); } + return total; } } std::fs::metadata(model).map(|m| m.len()).unwrap_or(0) diff --git a/crates/mesh-llm-system/src/benchmark.rs b/crates/mesh-llm-system/src/benchmark.rs index 9860e3187d..0211c8d7f4 100644 --- a/crates/mesh-llm-system/src/benchmark.rs +++ b/crates/mesh-llm-system/src/benchmark.rs @@ -180,14 +180,14 @@ fn per_gpu_names(hw: &HardwareSurvey) -> Vec { } // Handle summarized "N× name" form (e.g., "8× NVIDIA A100"). - if let Some((count_str, name)) = part_trimmed.split_once('×') { - if let Ok(count) = count_str.trim().parse::() { - let name_trimmed = name.trim(); - for _ in 0..count { - names.push(name_trimmed.to_string()); - } - continue; + if let Some((count_str, name)) = part_trimmed.split_once('×') + && let Ok(count) = count_str.trim().parse::() + { + let name_trimmed = name.trim(); + for _ in 0..count { + names.push(name_trimmed.to_string()); } + continue; } // Fallback: treat as a single GPU name. @@ -336,30 +336,30 @@ pub fn run_or_load( let path = fingerprint_path(); // Cache-hit path - if let Some(ref cached) = load_fingerprint(&path) { - if !hardware_changed(cached, hw) { - let mem_bandwidth: Vec = cached.gpus.iter().map(|g| g.p90_gbps).collect(); - let compute_tflops_fp32 = cached - .gpus - .iter() - .map(|g| g.compute_tflops_fp32) - .collect::>>(); - let compute_tflops_fp16 = cached - .gpus - .iter() - .map(|g| g.compute_tflops_fp16) - .collect::>>(); - let result = BenchmarkResult { - mem_bandwidth_gbps: mem_bandwidth, - compute_tflops_fp32, - compute_tflops_fp16, - }; - tracing::info!( - "Using cached bandwidth fingerprint: {} GPUs", - result.mem_bandwidth_gbps.len() - ); - return Some(result); - } + if let Some(ref cached) = load_fingerprint(&path) + && !hardware_changed(cached, hw) + { + let mem_bandwidth: Vec = cached.gpus.iter().map(|g| g.p90_gbps).collect(); + let compute_tflops_fp32 = cached + .gpus + .iter() + .map(|g| g.compute_tflops_fp32) + .collect::>>(); + let compute_tflops_fp16 = cached + .gpus + .iter() + .map(|g| g.compute_tflops_fp16) + .collect::>>(); + let result = BenchmarkResult { + mem_bandwidth_gbps: mem_bandwidth, + compute_tflops_fp32, + compute_tflops_fp16, + }; + tracing::info!( + "Using cached bandwidth fingerprint: {} GPUs", + result.mem_bandwidth_gbps.len() + ); + return Some(result); } tracing::info!("Hardware changed or no cache — running memory bandwidth benchmark"); diff --git a/crates/mesh-llm-system/src/hardware/enrichers.rs b/crates/mesh-llm-system/src/hardware/enrichers.rs index 7699446039..8b574c501b 100644 --- a/crates/mesh-llm-system/src/hardware/enrichers.rs +++ b/crates/mesh-llm-system/src/hardware/enrichers.rs @@ -28,11 +28,11 @@ mod linux { } unsafe fn symbol(&self, name: &'static [u8]) -> Option { - let symbol = libc::dlsym(self.0, name.as_ptr().cast()); + let symbol = unsafe { libc::dlsym(self.0, name.as_ptr().cast()) }; if symbol.is_null() { None } else { - Some(std::mem::transmute_copy(&symbol)) + Some(unsafe { std::mem::transmute_copy(&symbol) }) } } } @@ -147,13 +147,12 @@ mod linux { return None; } - if let Some(pci_bdf) = gpu.pci_bdf.as_deref().and_then(normalize_pci_bdf) { - if let Some(info) = infos + if let Some(pci_bdf) = gpu.pci_bdf.as_deref().and_then(normalize_pci_bdf) + && let Some(info) = infos .iter() .find(|info| info.pci_bdf.as_deref() == Some(pci_bdf.as_str())) - { - return Some(info); - } + { + return Some(info); } infos.get(gpu.index).or_else(|| { @@ -317,7 +316,10 @@ mod linux { if ptr.is_null() { return None; } - let value = CStr::from_ptr(ptr).to_string_lossy().trim().to_string(); + let value = unsafe { CStr::from_ptr(ptr) } + .to_string_lossy() + .trim() + .to_string(); if value.is_empty() { None } else { Some(value) } } diff --git a/crates/mesh-llm-system/src/hardware/mod.rs b/crates/mesh-llm-system/src/hardware/mod.rs index b4d70c9ff1..bf0469dda4 100644 --- a/crates/mesh-llm-system/src/hardware/mod.rs +++ b/crates/mesh-llm-system/src/hardware/mod.rs @@ -328,24 +328,23 @@ impl Collector for DefaultCollector { if metrics.contains(&Metric::IsSoc) { survey.is_soc = true; } - if metrics.contains(&Metric::VramBytes) { - if let Some((vram_bytes, reserved_bytes)) = + if metrics.contains(&Metric::VramBytes) + && let Some((vram_bytes, reserved_bytes)) = macos_metal_gpu_budget(query_metal_recommended_working_set_bytes()) - { - survey.vram_bytes = vram_bytes; - survey.gpu_vram = vec![vram_bytes]; - survey.gpu_reserved = vec![reserved_bytes]; - } + { + survey.vram_bytes = vram_bytes; + survey.gpu_vram = vec![vram_bytes]; + survey.gpu_reserved = vec![reserved_bytes]; } if metrics.contains(&Metric::GpuName) { let out = std::process::Command::new("sysctl") .args(["-n", "machdep.cpu.brand_string"]) .output() .ok(); - if let Some(out) = out { - if let Ok(s) = String::from_utf8(out.stdout) { - survey.gpu_name = parse_macos_cpu_brand(&s); - } + if let Some(out) = out + && let Ok(s) = String::from_utf8(out.stdout) + { + survey.gpu_name = parse_macos_cpu_brand(&s); } } if metrics.contains(&Metric::GpuCount) { @@ -367,19 +366,19 @@ impl Collector for DefaultCollector { ]) .output() .ok(); - if let Some(out) = out { - if out.status.success() { - let s = String::from_utf8(out.stdout).ok()?; - let parsed = parse_nvidia_gpu_memory_and_reserved(&s); - if !parsed.is_empty() { - survey.gpu_reserved = - parsed.iter().map(|(_, reserved)| *reserved).collect(); - let per_gpu: Vec = - parsed.iter().map(|(total, _)| *total).collect(); - let total: u64 = per_gpu.iter().sum(); - if total > 0 { - return Some((total, per_gpu)); - } + if let Some(out) = out + && out.status.success() + { + let s = String::from_utf8(out.stdout).ok()?; + let parsed = parse_nvidia_gpu_memory_and_reserved(&s); + if !parsed.is_empty() { + survey.gpu_reserved = + parsed.iter().map(|(_, reserved)| *reserved).collect(); + let per_gpu: Vec = + parsed.iter().map(|(total, _)| *total).collect(); + let total: u64 = per_gpu.iter().sum(); + if total > 0 { + return Some((total, per_gpu)); } } } @@ -535,15 +534,15 @@ impl Collector for DefaultCollector { .output() .ok(); if let Some(out) = out { - if out.status.success() { - if let Ok(s) = String::from_utf8(out.stdout) { - let names = parse_rocm_gpu_names(&s); - if metrics.contains(&Metric::GpuName) { - survey.gpu_name = summarize_gpu_name(&names); - } - if metrics.contains(&Metric::GpuCount) { - survey.gpu_count = u8::try_from(names.len()).unwrap_or(u8::MAX); - } + if out.status.success() + && let Ok(s) = String::from_utf8(out.stdout) + { + let names = parse_rocm_gpu_names(&s); + if metrics.contains(&Metric::GpuName) { + survey.gpu_name = summarize_gpu_name(&names); + } + if metrics.contains(&Metric::GpuCount) { + survey.gpu_count = u8::try_from(names.len()).unwrap_or(u8::MAX); } } } else { @@ -552,23 +551,22 @@ impl Collector for DefaultCollector { .args(args) .output() .ok(); - if let Some(out) = out { - if out.status.success() { - if let Ok(stdout) = String::from_utf8(out.stdout) { - let gpus = parse_xpu_smi_discovery_json(&stdout); - if !gpus.is_empty() { - let names: Vec = - gpus.iter().map(|gpu| gpu.name.clone()).collect(); - if metrics.contains(&Metric::GpuName) { - survey.gpu_name = summarize_gpu_name(&names); - } - if metrics.contains(&Metric::GpuCount) { - survey.gpu_count = - u8::try_from(names.len()).unwrap_or(u8::MAX); - } - break; - } + if let Some(out) = out + && out.status.success() + && let Ok(stdout) = String::from_utf8(out.stdout) + { + let gpus = parse_xpu_smi_discovery_json(&stdout); + if !gpus.is_empty() { + let names: Vec = + gpus.iter().map(|gpu| gpu.name.clone()).collect(); + if metrics.contains(&Metric::GpuName) { + survey.gpu_name = summarize_gpu_name(&names); + } + if metrics.contains(&Metric::GpuCount) { + survey.gpu_count = + u8::try_from(names.len()).unwrap_or(u8::MAX); } + break; } } } @@ -687,10 +685,10 @@ impl Collector for TegraCollector { survey.is_soc = true; } - if metrics.contains(&Metric::GpuName) { - if let Ok(model) = std::fs::read_to_string("/sys/firmware/devicetree/base/model") { - survey.gpu_name = parse_tegra_model_name(&model); - } + if metrics.contains(&Metric::GpuName) + && let Ok(model) = std::fs::read_to_string("/sys/firmware/devicetree/base/model") + { + survey.gpu_name = parse_tegra_model_name(&model); } if metrics.contains(&Metric::VramBytes) { @@ -731,12 +729,11 @@ fn detect_collector_impl() -> Box { #[cfg(all(target_os = "linux", not(feature = "skippy-devices")))] fn detect_collector_impl() -> Box { - if cfg!(target_arch = "aarch64") { - if let Ok(compat) = std::fs::read_to_string("/proc/device-tree/compatible") { - if is_tegra(&compat) { - return Box::new(TegraCollector); - } - } + if cfg!(target_arch = "aarch64") + && let Ok(compat) = std::fs::read_to_string("/proc/device-tree/compatible") + && is_tegra(&compat) + { + return Box::new(TegraCollector); } Box::new(DefaultCollector) } @@ -928,15 +925,13 @@ fn resolve_pinned_gpu_with_compatibility<'a>( .iter() .filter(|gpu| !gpu_pinnable_ids(gpu).is_empty()) .collect::>(); - if accept_single_pinnable_gpu_fallback { - if let [gpu] = pinnable_gpus.as_slice() { - tracing::warn!( - "configured gpu_id '{}' did not match the single available pinnable GPU; accepting '{}' for compatibility", - configured_id, - gpu_pinnable_ids(gpu).join(", ") - ); - return Ok(*gpu); - } + if accept_single_pinnable_gpu_fallback && let [gpu] = pinnable_gpus.as_slice() { + tracing::warn!( + "configured gpu_id '{}' did not match the single available pinnable GPU; accepting '{}' for compatibility", + configured_id, + gpu_pinnable_ids(gpu).join(", ") + ); + return Ok(*gpu); } Err(PinnedGpuResolverError::NoMatch { diff --git a/crates/mesh-llm-system/src/hardware/parsers.rs b/crates/mesh-llm-system/src/hardware/parsers.rs index ede446fbcc..3416f0f7ab 100644 --- a/crates/mesh-llm-system/src/hardware/parsers.rs +++ b/crates/mesh-llm-system/src/hardware/parsers.rs @@ -251,15 +251,15 @@ pub fn expand_gpu_names(summary: Option<&str>, expected_count: usize) -> Vec() { - let name = name.trim(); - if !name.is_empty() { - for _ in 0..count { - names.push(name.to_string()); - } - continue; + if let Some((count_str, name)) = part.split_once('×') + && let Ok(count) = count_str.trim().parse::() + { + let name = name.trim(); + if !name.is_empty() { + for _ in 0..count { + names.push(name.to_string()); } + continue; } } names.push(part.to_string()); diff --git a/crates/mesh-llm/tests/virtual_llm_injection.rs b/crates/mesh-llm/tests/virtual_llm_injection.rs index db6f708e98..da8cd3c600 100644 --- a/crates/mesh-llm/tests/virtual_llm_injection.rs +++ b/crates/mesh-llm/tests/virtual_llm_injection.rs @@ -72,12 +72,11 @@ async fn wait_for_ready(port: u16, timeout_secs: u64) -> bool { if tokio::time::Instant::now() > deadline { return false; } - if let Ok(resp) = reqwest::get(format!("http://127.0.0.1:{port}/health")).await { - if let Ok(body) = resp.json::().await { - if body["status"] == "ok" { - return true; - } - } + if let Ok(resp) = reqwest::get(format!("http://127.0.0.1:{port}/health")).await + && let Ok(body) = resp.json::().await + && body["status"] == "ok" + { + return true; } tokio::time::sleep(Duration::from_millis(500)).await; } diff --git a/crates/mesh-mixture-of-agents/src/arbiter.rs b/crates/mesh-mixture-of-agents/src/arbiter.rs index 5d7c156fcb..cd328c35a5 100644 --- a/crates/mesh-mixture-of-agents/src/arbiter.rs +++ b/crates/mesh-mixture-of-agents/src/arbiter.rs @@ -243,19 +243,20 @@ pub fn try_early_decision( // Two workers saying "Paris" and "Berlin" must not be treated as // consensus. Find the largest cluster of content-similar answers // and only early-exit if it's ≥2 workers AND a majority of answers. - if answers.len() >= 2 && tool_proposals.is_empty() { - if let Some((cluster_size, best)) = largest_agreeing_cluster(&answers) { - let majority = cluster_size * 2 >= answers.len(); - if majority && best.confidence >= 0.5 { - tracing::info!( - "moa: early exit — {}/{} workers agree on answer (conf={:.2}), {} still pending", - cluster_size, - answers.len(), - best.confidence, - remaining, - ); - return Some(Decision::Answer(best.payload.clone())); - } + if answers.len() >= 2 + && tool_proposals.is_empty() + && let Some((cluster_size, best)) = largest_agreeing_cluster(&answers) + { + let majority = cluster_size * 2 >= answers.len(); + if majority && best.confidence >= 0.5 { + tracing::info!( + "moa: early exit — {}/{} workers agree on answer (conf={:.2}), {} still pending", + cluster_size, + answers.len(), + best.confidence, + remaining, + ); + return Some(Decision::Answer(best.payload.clone())); } } diff --git a/crates/mesh-mixture-of-agents/src/backend.rs b/crates/mesh-mixture-of-agents/src/backend.rs index 50a1f59404..3f1a8cc9f0 100644 --- a/crates/mesh-mixture-of-agents/src/backend.rs +++ b/crates/mesh-mixture-of-agents/src/backend.rs @@ -268,20 +268,20 @@ fn extract_text_from_response(resp: &Value) -> Result { .ok_or_else(|| "malformed response: missing choices[0].message".to_string())?; // Native tool_calls → KV format for normalizer - if let Some(tool_calls) = message.get("tool_calls").and_then(|tc| tc.as_array()) { - if let Some(tc) = tool_calls.first() { - let name = tc - .pointer("/function/name") - .and_then(|n| n.as_str()) - .unwrap_or("unknown"); - let args = tc - .pointer("/function/arguments") - .and_then(|a| a.as_str()) - .unwrap_or("{}"); - return Ok(format!( - "kind: tool_proposal\ntool: {name}\narguments: {args}\nconfidence: 0.9\npayload: calling {name}", - )); - } + if let Some(tool_calls) = message.get("tool_calls").and_then(|tc| tc.as_array()) + && let Some(tc) = tool_calls.first() + { + let name = tc + .pointer("/function/name") + .and_then(|n| n.as_str()) + .unwrap_or("unknown"); + let args = tc + .pointer("/function/arguments") + .and_then(|a| a.as_str()) + .unwrap_or("{}"); + return Ok(format!( + "kind: tool_proposal\ntool: {name}\narguments: {args}\nconfidence: 0.9\npayload: calling {name}", + )); } let content = message diff --git a/crates/mesh-mixture-of-agents/src/normalize.rs b/crates/mesh-mixture-of-agents/src/normalize.rs index 247119e497..2303ff98fb 100644 --- a/crates/mesh-mixture-of-agents/src/normalize.rs +++ b/crates/mesh-mixture-of-agents/src/normalize.rs @@ -173,25 +173,25 @@ fn try_json_parse( // — if the worker writes inline tool JSON and we miss it, MoA leaks // the JSON back as `content` and the agent does nothing. This is // the failure mode PR #566 review called out. - if obj.get("kind").is_none() { - if let Some((tool_name, arguments)) = extract_tool_name_and_arguments(&obj) { - let args = normalize_tool_arguments(arguments).map(Value::Object); - return Some(WorkerOutput { - kind: OutputKind::ToolProposal, - // OpenAI-shape tool calls have no native confidence - // marker, but a structurally well-formed proposal is a - // stronger signal than a heuristic catch — score it - // higher than the heuristic's 0.6 so the arbiter - // prefers it on tie. - confidence: 0.75, - tool_name: Some(tool_name.to_string()), - tool_arguments: args, - payload: raw.to_string(), - model: model.to_string(), - role, - elapsed_ms, - }); - } + if obj.get("kind").is_none() + && let Some((tool_name, arguments)) = extract_tool_name_and_arguments(&obj) + { + let args = normalize_tool_arguments(arguments).map(Value::Object); + return Some(WorkerOutput { + kind: OutputKind::ToolProposal, + // OpenAI-shape tool calls have no native confidence + // marker, but a structurally well-formed proposal is a + // stronger signal than a heuristic catch — score it + // higher than the heuristic's 0.6 so the arbiter + // prefers it on tie. + confidence: 0.75, + tool_name: Some(tool_name.to_string()), + tool_arguments: args, + payload: raw.to_string(), + model: model.to_string(), + role, + elapsed_ms, + }); } let kind = match obj.get("kind").and_then(|k| k.as_str()) { @@ -515,19 +515,19 @@ fn extract_tool_proposal(raw: &str) -> (Option, Option) { } // Strategy 1: Look for structured JSON in the text - if let Some(json_str) = extract_json_object(raw) { - if let Ok(obj) = serde_json::from_str::(&json_str) { - if let Some((name, arguments)) = extract_tool_name_and_arguments(&obj) { - let args = normalize_tool_arguments(arguments).map(Value::Object); - return (Some(name.to_string()), args); - } - // Could be the arguments themselves (e.g. {"path": "src/auth.py"}) - // Look for a tool name in the surrounding text - let lower = raw.to_lowercase(); - for tool in KNOWN_TOOLS { - if lower.contains(tool) { - return (Some(tool.to_string()), Some(obj)); - } + if let Some(json_str) = extract_json_object(raw) + && let Ok(obj) = serde_json::from_str::(&json_str) + { + if let Some((name, arguments)) = extract_tool_name_and_arguments(&obj) { + let args = normalize_tool_arguments(arguments).map(Value::Object); + return (Some(name.to_string()), args); + } + // Could be the arguments themselves (e.g. {"path": "src/auth.py"}) + // Look for a tool name in the surrounding text + let lower = raw.to_lowercase(); + for tool in KNOWN_TOOLS { + if lower.contains(tool) { + return (Some(tool.to_string()), Some(obj)); } } } diff --git a/crates/mesh-mixture-of-agents/src/worker.rs b/crates/mesh-mixture-of-agents/src/worker.rs index 86e92f72fa..6b2e34c474 100644 --- a/crates/mesh-mixture-of-agents/src/worker.rs +++ b/crates/mesh-mixture-of-agents/src/worker.rs @@ -135,10 +135,10 @@ pub(crate) fn is_single_digit_b_name(name: &str) -> bool { continue; } // Byte after must not be another digit (avoid BF16-like continuations) - if let Some(&after) = bytes.get(i + 2) { - if after.is_ascii_digit() { - continue; - } + if let Some(&after) = bytes.get(i + 2) + && after.is_ascii_digit() + { + continue; } return true; } diff --git a/crates/model-artifact/src/gguf.rs b/crates/model-artifact/src/gguf.rs index 9ba64b7189..c9ba8b69ab 100644 --- a/crates/model-artifact/src/gguf.rs +++ b/crates/model-artifact/src/gguf.rs @@ -491,17 +491,17 @@ pub fn scan_gguf_compact_meta(path: &Path) -> Option { } } - if meta.key_length == 0 && meta.head_count > 0 { - if let Some(key_length) = meta.embedding_size.checked_div(meta.head_count) { - meta.key_length = key_length; - } + if meta.key_length == 0 + && meta.head_count > 0 + && let Some(key_length) = meta.embedding_size.checked_div(meta.head_count) + { + meta.key_length = key_length; } - if meta.value_length == 0 { - if let Some(effective_kv) = meta.effective_kv_head_count() { - if let Some(value_length) = meta.embedding_size.checked_div(effective_kv) { - meta.value_length = value_length; - } - } + if meta.value_length == 0 + && let Some(effective_kv) = meta.effective_kv_head_count() + && let Some(value_length) = meta.embedding_size.checked_div(effective_kv) + { + meta.value_length = value_length; } Some(meta) diff --git a/crates/model-hf/src/lib.rs b/crates/model-hf/src/lib.rs index e85972e474..bffdc684c5 100644 --- a/crates/model-hf/src/lib.rs +++ b/crates/model-hf/src/lib.rs @@ -244,31 +244,30 @@ pub fn huggingface_identity_for_path_in_cache( let resolved_cache_root = cache_root .canonicalize() .unwrap_or_else(|_| cache_root.to_path_buf()); - if resolved_cache_root != cache_root { - if let Some(identity) = identity_from_cache_snapshot_path(path, &resolved_cache_root) { - return Some(identity); - } + if resolved_cache_root != cache_root + && let Some(identity) = identity_from_cache_snapshot_path(path, &resolved_cache_root) + { + return Some(identity); } let resolved = path.canonicalize().unwrap_or_else(|_| path.to_path_buf()); if resolved != path { if let Some(identity) = identity_from_cache_snapshot_path(&resolved, cache_root) { return Some(identity); } - if resolved_cache_root != cache_root { - if let Some(identity) = + if resolved_cache_root != cache_root + && let Some(identity) = identity_from_cache_snapshot_path(&resolved, &resolved_cache_root) - { - return Some(identity); - } + { + return Some(identity); } } if let Some(identity) = identity_from_snapshot_layout_ancestors(path) { return Some(identity); } - if resolved != path { - if let Some(identity) = identity_from_snapshot_layout_ancestors(&resolved) { - return Some(identity); - } + if resolved != path + && let Some(identity) = identity_from_snapshot_layout_ancestors(&resolved) + { + return Some(identity); } scan_hf_cache_identity_for_path(path, cache_root) } diff --git a/crates/model-package/src/prepare.rs b/crates/model-package/src/prepare.rs index e53944169b..9829364854 100644 --- a/crates/model-package/src/prepare.rs +++ b/crates/model-package/src/prepare.rs @@ -67,10 +67,10 @@ pub async fn list_quants(client: &HFClient, repo: &str) -> Result = Vec::new(); while let Some(entry) = stream.next().await { let entry = entry.context("read repo tree entry")?; - if let RepoTreeEntry::File { path, size, .. } = entry { - if path.ends_with(".gguf") { - gguf_files.push((path, size)); - } + if let RepoTreeEntry::File { path, size, .. } = entry + && path.ends_with(".gguf") + { + gguf_files.push((path, size)); } } @@ -153,10 +153,9 @@ pub async fn resolve( // Verify it's shard 00001. if shard.part != "00001" { // Reconstruct the -00001- path. - let first = matched + matched .first_file - .replace(&format!("-{}-of-", shard.part), "-00001-of-"); - first + .replace(&format!("-{}-of-", shard.part), "-00001-of-") } else { matched.first_file.clone() } diff --git a/crates/model-ref/src/lib.rs b/crates/model-ref/src/lib.rs index 87be810288..a3214476eb 100644 --- a/crates/model-ref/src/lib.rs +++ b/crates/model-ref/src/lib.rs @@ -101,10 +101,10 @@ pub fn quant_selector_from_gguf_file(file: &str) -> Option { return None; } - if let Some((prefix, _)) = file.split_once('/') { - if is_quant_like_selector(prefix) { - return Some(prefix.to_string()); - } + if let Some((prefix, _)) = file.split_once('/') + && is_quant_like_selector(prefix) + { + return Some(prefix.to_string()); } let basename = Path::new(file).file_name()?.to_str()?; diff --git a/crates/openai-frontend/src/errors.rs b/crates/openai-frontend/src/errors.rs index dac93f332a..8b17855e85 100644 --- a/crates/openai-frontend/src/errors.rs +++ b/crates/openai-frontend/src/errors.rs @@ -256,10 +256,10 @@ pub fn map_upstream_error_body(status_code: u16, body: &[u8]) -> Option> } let parsed = serde_json::from_slice::(body).ok(); - if let Some(value) = parsed.as_ref() { - if already_openai_error(value) { - return None; - } + if let Some(value) = parsed.as_ref() + && already_openai_error(value) + { + return None; } let message = parsed diff --git a/crates/openai-frontend/src/guardrails/rescue.rs b/crates/openai-frontend/src/guardrails/rescue.rs index 463d169c45..fe3c38481f 100644 --- a/crates/openai-frontend/src/guardrails/rescue.rs +++ b/crates/openai-frontend/src/guardrails/rescue.rs @@ -535,21 +535,20 @@ fn classify_tool_call_value( }; } - if let Some(forced_name) = prepared.state.request_contract.forced_tool_name() { - if parsed_calls + if let Some(forced_name) = prepared.state.request_contract.forced_tool_name() + && parsed_calls .iter() .any(|tool_call| tool_call.name != forced_name) - { - return ClassifiedGuardrailResponse { - category: GuardrailResponseCategory::UnknownTool, - parser_stage, - visible_content: None, - tool_calls: Some(normalized_tool_calls(&parsed_calls)), - synthetic_text: None, - structured_payload: None, - finish_reason, - }; - } + { + return ClassifiedGuardrailResponse { + category: GuardrailResponseCategory::UnknownTool, + parser_stage, + visible_content: None, + tool_calls: Some(normalized_tool_calls(&parsed_calls)), + synthetic_text: None, + structured_payload: None, + finish_reason, + }; } if matches!( diff --git a/crates/openai-frontend/src/responses.rs b/crates/openai-frontend/src/responses.rs index 6a4698d94e..48838af931 100644 --- a/crates/openai-frontend/src/responses.rs +++ b/crates/openai-frontend/src/responses.rs @@ -371,10 +371,10 @@ fn translate_responses_content_item(item: &Value) -> Result } fn collapse_blocks_if_text_only(blocks: Vec) -> Value { - if blocks.len() == 1 { - if let Some(text) = blocks[0].get("text").and_then(Value::as_str) { - return Value::String(text.to_string()); - } + if blocks.len() == 1 + && let Some(text) = blocks[0].get("text").and_then(Value::as_str) + { + return Value::String(text.to_string()); } Value::Array(blocks) } @@ -469,13 +469,13 @@ fn translate_openai_responses_input(object: &mut Map) -> Result) -> Result) -> Value { "text": text, "annotations": [], }); - if let Some(logprobs) = logprobs { - if let Some(object) = content.as_object_mut() { - object.insert("logprobs".to_string(), logprobs); - } + if let Some(logprobs) = logprobs + && let Some(object) = content.as_object_mut() + { + object.insert("logprobs".to_string(), logprobs); } content } @@ -902,10 +902,10 @@ pub fn responses_stream_delta_event_with_logprobs_and_sequence( "content_index": 0, "delta": delta, }); - if let Some(logprobs) = logprobs { - if let Some(object) = event.as_object_mut() { - object.insert("logprobs".to_string(), logprobs); - } + if let Some(logprobs) = logprobs + && let Some(object) = event.as_object_mut() + { + object.insert("logprobs".to_string(), logprobs); } event } diff --git a/crates/skippy-bench/src/distributed.rs b/crates/skippy-bench/src/distributed.rs index 258ee1aa92..6b662eb0b7 100644 --- a/crates/skippy-bench/src/distributed.rs +++ b/crates/skippy-bench/src/distributed.rs @@ -1270,13 +1270,13 @@ fn prepare_local_stage(args: &RunArgs, stage: &StageAssignment) -> Result<()> { stage.remote_config_path ) })?; - if args.rsync_model_artifacts { - if let (Some(stage_model), Some(local_model)) = ( + if args.rsync_model_artifacts + && let (Some(stage_model), Some(local_model)) = ( args.stage_model.as_ref(), stage.local_materialized_model_path.as_ref(), - ) { - materialize_stage_model_on_coordinator(stage_model, stage, local_model)?; - } + ) + { + materialize_stage_model_on_coordinator(stage_model, stage, local_model)?; } Ok(()) } diff --git a/crates/skippy-cache/src/exact_state.rs b/crates/skippy-cache/src/exact_state.rs index 16101f17f1..fe8d421ca0 100644 --- a/crates/skippy-cache/src/exact_state.rs +++ b/crates/skippy-cache/src/exact_state.rs @@ -108,12 +108,13 @@ impl ExactStateCache { ); let (mut evicted_entries, mut evicted_logical_bytes) = self.evict_until_within_limits(); - if self.max_bytes > 0 && self.blobs.physical_bytes() > self.max_bytes { - if let Some(entry) = self.entries.remove(&page_id) { - evicted_entries = evicted_entries.saturating_add(1); - evicted_logical_bytes = evicted_logical_bytes.saturating_add(entry.logical_bytes); - self.remove_entry(entry); - } + if self.max_bytes > 0 + && self.blobs.physical_bytes() > self.max_bytes + && let Some(entry) = self.entries.remove(&page_id) + { + evicted_entries = evicted_entries.saturating_add(1); + evicted_logical_bytes = evicted_logical_bytes.saturating_add(entry.logical_bytes); + self.remove_entry(entry); } let stored = self.entries.contains_key(&page_id); let stats = self.stats(); diff --git a/crates/skippy-coordinator/src/topology.rs b/crates/skippy-coordinator/src/topology.rs index 21623e1191..9566d36618 100644 --- a/crates/skippy-coordinator/src/topology.rs +++ b/crates/skippy-coordinator/src/topology.rs @@ -86,13 +86,11 @@ pub fn plan_topology(input: &TopologyPlanningInput) -> Result(report: &T, report_out: Option<&Path>) -> Result<() let json = serde_json::to_string_pretty(report)?; println!("{json}"); if let Some(path) = report_out { - if let Some(parent) = path.parent() { - if !parent.as_os_str().is_empty() { - fs::create_dir_all(parent) - .with_context(|| format!("create report directory {}", parent.display()))?; - } + if let Some(parent) = path.parent() + && !parent.as_os_str().is_empty() + { + fs::create_dir_all(parent) + .with_context(|| format!("create report directory {}", parent.display()))?; } fs::write(path, format!("{json}\n")) .with_context(|| format!("write correctness report {}", path.display()))?; diff --git a/crates/skippy-ffi/build.rs b/crates/skippy-ffi/build.rs index 1746db9663..94ef8c6936 100644 --- a/crates/skippy-ffi/build.rs +++ b/crates/skippy-ffi/build.rs @@ -233,15 +233,16 @@ fn link_linux_cuda_libs(cmake_cache: &std::path::Path) { // Check CMakeCache for NCCL_FOUND or NCCL_LIBRARY to detect this and extract the search path. if let Ok(contents) = std::fs::read_to_string(cmake_cache) { let mut nccl_found = cmake_cache_bool(&contents, "NCCL_FOUND"); - if let Some(nccl_path) = cmake_cache_value(&contents, "NCCL_LIBRARY") { - if !nccl_path.contains("NOTFOUND") && !nccl_path.contains("-NOTFOUND") { - nccl_found = true; - let path = std::path::PathBuf::from(&nccl_path); - if let Some(parent) = path.parent() { - if parent.is_dir() { - println!("cargo:rustc-link-search=native={}", parent.display()); - } - } + if let Some(nccl_path) = cmake_cache_value(&contents, "NCCL_LIBRARY") + && !nccl_path.contains("NOTFOUND") + && !nccl_path.contains("-NOTFOUND") + { + nccl_found = true; + let path = std::path::PathBuf::from(&nccl_path); + if let Some(parent) = path.parent() + && parent.is_dir() + { + println!("cargo:rustc-link-search=native={}", parent.display()); } } if nccl_found { @@ -387,14 +388,14 @@ fn windows_openmp_search_paths( } fn link_linux_lib_from_cache(cmake_cache: &std::path::Path, cache_key: &str, lib: &str) { - if let Ok(cache) = std::fs::read_to_string(cmake_cache) { - if let Some(path) = cmake_cache_value(&cache, cache_key) { - let path = std::path::PathBuf::from(path); - if path.exists() { - if let Some(parent) = path.parent() { - println!("cargo:rustc-link-search=native={}", parent.display()); - } - } + if let Ok(cache) = std::fs::read_to_string(cmake_cache) + && let Some(path) = cmake_cache_value(&cache, cache_key) + { + let path = std::path::PathBuf::from(path); + if path.exists() + && let Some(parent) = path.parent() + { + println!("cargo:rustc-link-search=native={}", parent.display()); } } println!("cargo:rustc-link-lib=dylib={lib}"); diff --git a/crates/skippy-model-package/src/main.rs b/crates/skippy-model-package/src/main.rs index db81f8401c..10689795d5 100644 --- a/crates/skippy-model-package/src/main.rs +++ b/crates/skippy-model-package/src/main.rs @@ -1216,11 +1216,11 @@ fn write_json_file(path: &Path, value: &T) -> Result<()> { } fn create_parent_dir(path: &Path) -> Result<()> { - if let Some(parent) = path.parent() { - if !parent.as_os_str().is_empty() { - fs::create_dir_all(parent) - .with_context(|| format!("create output directory {}", parent.display()))?; - } + if let Some(parent) = path.parent() + && !parent.as_os_str().is_empty() + { + fs::create_dir_all(parent) + .with_context(|| format!("create output directory {}", parent.display()))?; } Ok(()) } diff --git a/crates/skippy-prompt/src/prompt_cli/generation.rs b/crates/skippy-prompt/src/prompt_cli/generation.rs index 6ec62a90d3..4c032e519f 100644 --- a/crates/skippy-prompt/src/prompt_cli/generation.rs +++ b/crates/skippy-prompt/src/prompt_cli/generation.rs @@ -493,11 +493,10 @@ fn run_prompt(run: PromptRun<'_>) -> Result<()> { } } speculative_stats.adaptive_window_final = adaptive_window; - if decision.rejected() || reached_eog { - if let Some(draft) = draft.as_deref_mut() { + if (decision.rejected() || reached_eog) + && let Some(draft) = draft.as_deref_mut() { draft.reset_to_context(&context_tokens)?; } - } if reached_eog { break; } @@ -511,8 +510,8 @@ fn run_prompt(run: PromptRun<'_>) -> Result<()> { ); } let mut live_rematerialize_failed = false; - if live_enabled { - if let Err(error) = rematerialize_live_transcript( + if live_enabled + && let Err(error) = rematerialize_live_transcript( stream, tokenizer, chat_template_model, @@ -533,7 +532,6 @@ fn run_prompt(run: PromptRun<'_>) -> Result<()> { the next prompt will reset the live session: {error:#}" ); } - } if !live_enabled { stop_prompt_stream(stream, wire_dtype, request_id, wire_session_id, args)?; @@ -557,12 +555,11 @@ fn run_prompt(run: PromptRun<'_>) -> Result<()> { live.stream = None; } live.messages = live_messages; - if let Some(last) = live.messages.last_mut() { - if last.role == "user" { + if let Some(last) = live.messages.last_mut() + && last.role == "user" { live.messages .push(ChatTemplateMessage::new("assistant", &assistant_raw_text)); } - } live.resident_tokens = live_transcript_tokens(tokenizer, chat_template_model, args, &live.messages)?; live.dirty = !generation_reached_eog || live_rematerialize_failed; diff --git a/crates/skippy-prompt/src/prompt_cli/stage_config.rs b/crates/skippy-prompt/src/prompt_cli/stage_config.rs index 2365a68965..d8eebf8a1a 100644 --- a/crates/skippy-prompt/src/prompt_cli/stage_config.rs +++ b/crates/skippy-prompt/src/prompt_cli/stage_config.rs @@ -144,8 +144,8 @@ fn prompt_stage_cache_max_bytes( stage: &LocalStage, hf_package_ref: bool, ) -> Result { - if let Some(meta) = prompt_cache_meta(args, stage, hf_package_ref)? { - if let Some(bytes) = estimate_prompt_stage_cache_max_bytes( + if let Some(meta) = prompt_cache_meta(args, stage, hf_package_ref)? + && let Some(bytes) = estimate_prompt_stage_cache_max_bytes( stage.layer_start, stage.layer_end, args.ctx_size, @@ -156,7 +156,6 @@ fn prompt_stage_cache_max_bytes( ) { return Ok(bytes); } - } estimate_prompt_stage_cache_max_bytes_from_width( stage.layer_start, diff --git a/crates/skippy-runtime/src/lib.rs b/crates/skippy-runtime/src/lib.rs index 783006c5eb..74af67bec7 100644 --- a/crates/skippy-runtime/src/lib.rs +++ b/crates/skippy-runtime/src/lib.rs @@ -353,15 +353,14 @@ impl NativeLogAggregator { } if let Some(layer_index) = parse_layer_assign_index(s) { - if self.layer_assign_progress.total.is_none() { - if let Some(total) = self + if self.layer_assign_progress.total.is_none() + && let Some(total) = self .metadata_highlights .block_count .as_deref() .and_then(|s| s.parse::().ok()) - { - self.layer_assign_progress.set_total(total); - } + { + self.layer_assign_progress.set_total(total); } let new_completed = layer_index + 1; if new_completed > self.layer_assign_progress.completed { @@ -675,10 +674,10 @@ unsafe extern "C" fn write_native_log(_level: c_int, text: *const c_char, _user_ } let bytes = unsafe { CStr::from_ptr(text) }.to_bytes(); - if let Ok(mut guard) = native_log_file().lock() { - if let Some(writer) = guard.as_mut() { - let _ = writer.write_all(bytes); - } + if let Ok(mut guard) = native_log_file().lock() + && let Some(writer) = guard.as_mut() + { + let _ = writer.write_all(bytes); } // Also send aggregated messages through the channel when runtime forwarding is enabled. @@ -691,13 +690,12 @@ unsafe extern "C" fn write_native_log(_level: c_int, text: *const c_char, _user_ Ok(mut aggregator) => aggregator.process_line(text_str.trim()), _ => Vec::new(), }; - if let Some(tx) = NATIVE_LOG_FILTERED_TX.get() { - if let Ok(guard) = tx.lock() { - if let Some(ref sender) = *guard { - for event in events { - let _ = sender.send(event); - } - } + if let Some(tx) = NATIVE_LOG_FILTERED_TX.get() + && let Ok(guard) = tx.lock() + && let Some(ref sender) = *guard + { + for event in events { + let _ = sender.send(event); } } } diff --git a/crates/skippy-runtime/src/package.rs b/crates/skippy-runtime/src/package.rs index a4eba0ad83..dfa5907083 100644 --- a/crates/skippy-runtime/src/package.rs +++ b/crates/skippy-runtime/src/package.rs @@ -568,10 +568,10 @@ fn parse_hf_package_ref(value: &str) -> Result { if repo_id.split('/').count() != 2 || repo_id.contains(':') || repo_id.contains('@') { bail!("HF package repo id must look like namespace/repo"); } - if let Some(revision) = revision { - if revision.is_empty() { - bail!("HF package revision is empty"); - } + if let Some(revision) = revision + && revision.is_empty() + { + bail!("HF package revision is empty"); } Ok(HfPackageRef { @@ -865,17 +865,17 @@ fn verify_package_artifacts( format!("read package artifact metadata {}", relative_path.display()) })?; let fingerprint = file_fingerprint(&metadata); - if let Some(cache_dir) = &options.cache_dir { - if integrity_cache_hit( + if let Some(cache_dir) = &options.cache_dir + && integrity_cache_hit( cache_dir, manifest_sha256, &artifact, metadata.len(), fingerprint, - )? { - report.cached_artifacts += 1; - continue; - } + )? + { + report.cached_artifacts += 1; + continue; } let actual = file_sha256(&absolute)?; diff --git a/crates/skippy-server/src/binary_transport.rs b/crates/skippy-server/src/binary_transport.rs index 813c02f236..ae21cddcfb 100644 --- a/crates/skippy-server/src/binary_transport.rs +++ b/crates/skippy-server/src/binary_transport.rs @@ -685,29 +685,28 @@ fn handle_binary_connection( &token_ids, ); control_stats.merge(local.stats); - if local.hit { - if let Some(downstream) = downstream.as_mut() { - write_stage_message_conditioned( - &mut *downstream, - &message, - wire_dtype, - downstream_wire_condition, - ) - .context("forward prefix cache control")?; - let reply = - recv_reply(&mut *downstream).context("prefix cache downstream ACK")?; - if reply.kind != WireReplyKind::Ack { - bail!("prefix cache control expected downstream ACK"); - } - let downstream_missed = message.kind == WireMessageKind::TryRestorePrefill - && (reply.stats.kv_lookup_misses > 0 - || reply.stats.kv_lookup_errors > 0 - || reply.stats.kv_lookup_hits == 0); - control_stats.merge(reply.stats); - if downstream_missed { - let mut runtime = runtime.lock().expect("runtime lock poisoned"); - let _ = runtime.drop_session_timed(&session_key); - } + if local.hit + && let Some(downstream) = downstream.as_mut() + { + write_stage_message_conditioned( + &mut *downstream, + &message, + wire_dtype, + downstream_wire_condition, + ) + .context("forward prefix cache control")?; + let reply = recv_reply(&mut *downstream).context("prefix cache downstream ACK")?; + if reply.kind != WireReplyKind::Ack { + bail!("prefix cache control expected downstream ACK"); + } + let downstream_missed = message.kind == WireMessageKind::TryRestorePrefill + && (reply.stats.kv_lookup_misses > 0 + || reply.stats.kv_lookup_errors > 0 + || reply.stats.kv_lookup_hits == 0); + control_stats.merge(reply.stats); + if downstream_missed { + let mut runtime = runtime.lock().expect("runtime lock poisoned"); + let _ = runtime.drop_session_timed(&session_key); } } let mut attrs = binary_message_attrs(config, session_id, &message); @@ -929,29 +928,28 @@ fn handle_binary_connection( &tokens, ); drop(runtime); - if let Some(kv) = kv { - if config.downstream.is_some() { - let base = binary_message_base(config, &session_key, &message); - if let Some(activation) = kv.record_resident_activation( - config, - &base, - 0, - &tokens, - activation_width, - &output, - ) { - record.recorded_activations = - record.recorded_activations.saturating_add(1); - record.recorded_activation_bytes = record - .recorded_activation_bytes - .saturating_add(activation.payload_bytes as u64); - record.evicted_activation_entries = record - .evicted_activation_entries - .saturating_add(activation.evicted_entries); - record.evicted_activation_bytes = record - .evicted_activation_bytes - .saturating_add(activation.evicted_bytes); - } + if let Some(kv) = kv + && config.downstream.is_some() + { + let base = binary_message_base(config, &session_key, &message); + if let Some(activation) = kv.record_resident_activation( + config, + &base, + 0, + &tokens, + activation_width, + &output, + ) { + record.recorded_activations = record.recorded_activations.saturating_add(1); + record.recorded_activation_bytes = record + .recorded_activation_bytes + .saturating_add(activation.payload_bytes as u64); + record.evicted_activation_entries = record + .evicted_activation_entries + .saturating_add(activation.evicted_entries); + record.evicted_activation_bytes = record + .evicted_activation_bytes + .saturating_add(activation.evicted_bytes); } } record @@ -2518,40 +2516,39 @@ fn maybe_record_binary_prefill( } } } - if config.downstream.is_some() { - if let Some(output) = output { - if let Some(record) = kv.record_resident_activation( - config, - &base, - token_start, - token_ids, - activation_width, - output, - ) { - result.recorded_activations = result.recorded_activations.saturating_add(1); - result.recorded_activation_bytes = result - .recorded_activation_bytes - .saturating_add(record.payload_bytes as u64); - result.evicted_activation_entries = result - .evicted_activation_entries - .saturating_add(record.evicted_entries); - result.evicted_activation_bytes = result - .evicted_activation_bytes - .saturating_add(record.evicted_bytes); - attrs.insert( - "skippy.activation_cache.recorded_page_id".to_string(), - json!(record.page_id), - ); - attrs.insert( - "skippy.activation_cache.entries".to_string(), - json!(record.entries), - ); - attrs.insert( - "skippy.activation_cache.resident_bytes".to_string(), - json!(record.resident_bytes), - ); - } - } + if config.downstream.is_some() + && let Some(output) = output + && let Some(record) = kv.record_resident_activation( + config, + &base, + token_start, + token_ids, + activation_width, + output, + ) + { + result.recorded_activations = result.recorded_activations.saturating_add(1); + result.recorded_activation_bytes = result + .recorded_activation_bytes + .saturating_add(record.payload_bytes as u64); + result.evicted_activation_entries = result + .evicted_activation_entries + .saturating_add(record.evicted_entries); + result.evicted_activation_bytes = result + .evicted_activation_bytes + .saturating_add(record.evicted_bytes); + attrs.insert( + "skippy.activation_cache.recorded_page_id".to_string(), + json!(record.page_id), + ); + attrs.insert( + "skippy.activation_cache.entries".to_string(), + json!(record.entries), + ); + attrs.insert( + "skippy.activation_cache.resident_bytes".to_string(), + json!(record.resident_bytes), + ); } attrs.insert( "skippy.kv.record_ms".to_string(), @@ -3254,14 +3251,13 @@ fn upstream_layer_range( topology: Option<&StageTopology>, message: &StageWireMessage, ) -> (i32, i32) { - if let Some(topology) = topology { - if let Some(stage) = topology + if let Some(topology) = topology + && let Some(stage) = topology .stages .iter() .find(|stage| stage.stage_index as i32 == message.state.source_stage_index) - { - return (stage.layer_start as i32, stage.layer_end as i32); - } + { + return (stage.layer_start as i32, stage.layer_end as i32); } (0, config.layer_start as i32) } diff --git a/crates/skippy-server/src/frontend.rs b/crates/skippy-server/src/frontend.rs index 39213a0a50..b165403705 100644 --- a/crates/skippy-server/src/frontend.rs +++ b/crates/skippy-server/src/frontend.rs @@ -1774,11 +1774,12 @@ impl ChatOutputStreamParser { if let Some(delta) = suffix_delta(parsed.content.as_deref(), &mut self.emitted_content) { events.push(GenerationStreamEvent::Delta(delta)); } - if !is_partial && !self.emitted_tool_calls { - if let Some(tool_calls) = parsed.tool_calls { - self.emitted_tool_calls = true; - events.push(GenerationStreamEvent::ToolCalls(tool_calls)); - } + if !is_partial + && !self.emitted_tool_calls + && let Some(tool_calls) = parsed.tool_calls + { + self.emitted_tool_calls = true; + events.push(GenerationStreamEvent::ToolCalls(tool_calls)); } Ok(events) } diff --git a/crates/skippy-server/src/frontend/embedded_generation.rs b/crates/skippy-server/src/frontend/embedded_generation.rs index b8dc1fc3b0..1e5fc9273a 100644 --- a/crates/skippy-server/src/frontend/embedded_generation.rs +++ b/crates/skippy-server/src/frontend/embedded_generation.rs @@ -90,28 +90,28 @@ impl StageOpenAiBackend { fused_first_decode = Some(fused); } } - if !prefill_chain_cache_restored { - if let Some(restore) = self.try_restore_embedded_split_prefill( + if !prefill_chain_cache_restored + && let Some(restore) = self.try_restore_embedded_split_prefill( &request, &session_key, downstream, prefill_tokens, - )? { - prefill_chain_restored_tokens = restore.restored_tokens; - prefill_chain_cache_restored = - prefill_chain_restored_tokens >= prefill_tokens.len(); - prefill_chain_cache_stats = restore.stats; - cache_stats.cached_prompt_tokens = - saturating_u32(prefill_chain_restored_tokens); - cache_stats.matched_prefix_tokens = - saturating_u32(prefill_chain_restored_tokens); - cache_stats.suffix_prefill_tokens = saturating_u32( - prefill_tokens - .len() - .saturating_sub(prefill_chain_restored_tokens), - ); - cache_stats.hit_kind = Some("chain_prefix"); - } + )? + { + prefill_chain_restored_tokens = restore.restored_tokens; + prefill_chain_cache_restored = + prefill_chain_restored_tokens >= prefill_tokens.len(); + prefill_chain_cache_stats = restore.stats; + cache_stats.cached_prompt_tokens = + saturating_u32(prefill_chain_restored_tokens); + cache_stats.matched_prefix_tokens = + saturating_u32(prefill_chain_restored_tokens); + cache_stats.suffix_prefill_tokens = saturating_u32( + prefill_tokens + .len() + .saturating_sub(prefill_chain_restored_tokens), + ); + cache_stats.hit_kind = Some("chain_prefix"); } let mut pos_start = prefill_chain_restored_tokens.min(prefill_tokens.len()); let mut chunk_index = 0usize; @@ -663,15 +663,15 @@ impl StageOpenAiBackend { let proposal_limit = remaining.min(adaptive_window); let propose_timer = PhaseTimer::start(); let mut draft_tokens = Vec::new(); - if draft_tokens.is_empty() { - if let Some(draft) = draft_guard.as_deref_mut() { - let proposal_limit = proposal_limit.min(draft.window); - draft_tokens = draft - .propose(current, proposal_limit) - .map_err(openai_backend_error)?; - if !draft_tokens.is_empty() { - proposal_source = "draft-model"; - } + if draft_tokens.is_empty() + && let Some(draft) = draft_guard.as_deref_mut() + { + let proposal_limit = proposal_limit.min(draft.window); + draft_tokens = draft + .propose(current, proposal_limit) + .map_err(openai_backend_error)?; + if !draft_tokens.is_empty() { + proposal_source = "draft-model"; } } let draft_propose_ms = propose_timer.elapsed_ms(); diff --git a/crates/skippy-server/src/frontend/generation_flow.rs b/crates/skippy-server/src/frontend/generation_flow.rs index c5c7f6b337..de125b9249 100644 --- a/crates/skippy-server/src/frontend/generation_flow.rs +++ b/crates/skippy-server/src/frontend/generation_flow.rs @@ -187,28 +187,27 @@ impl StageOpenAiBackend { lane_pool, .. } = self.mode.clone() + && config.downstream.is_some() { - if config.downstream.is_some() { - let lane_pool = lane_pool.ok_or_else(|| { - OpenAiError::backend("embedded stage 0 has no downstream lane pool") - })?; - return self.generate_split_multimodal_text( - SplitMultimodalGeneration { - prompt, - max_tokens, - stop, - sampling, - cancellation, - ids, - config, - wire_dtype, - activation_width, - downstream_wire_condition, - lane_pool, - }, - on_text_chunk, - ); - } + let lane_pool = lane_pool.ok_or_else(|| { + OpenAiError::backend("embedded stage 0 has no downstream lane pool") + })?; + return self.generate_split_multimodal_text( + SplitMultimodalGeneration { + prompt, + max_tokens, + stop, + sampling, + cancellation, + ids, + config, + wire_dtype, + activation_width, + downstream_wire_condition, + lane_pool, + }, + on_text_chunk, + ); } match &self.mode { diff --git a/crates/skippy-server/src/frontend/local_generation.rs b/crates/skippy-server/src/frontend/local_generation.rs index 2e9b272215..2f6d43085e 100644 --- a/crates/skippy-server/src/frontend/local_generation.rs +++ b/crates/skippy-server/src/frontend/local_generation.rs @@ -184,105 +184,104 @@ impl StageOpenAiBackend { cache_stats.matched_prefix_tokens = saturating_u32(restored_prefill_tokens); cache_stats.suffix_prefill_tokens = saturating_u32(prefill_tokens.len().saturating_sub(restored_prefill_tokens)); - if !restored_prefill || decoded_prefill_suffix { - if let Some(kv) = self.kv.as_ref() { - let base = self.local_kv_message_base(&session_id, request.ids); - let exact_identity = - kv.prefill_identity(&self.config, &base, 0, prefill_tokens); - if let Ok(Some(record)) = - kv.record_exact_state(&mut runtime, &session_id, &exact_identity) - { + if (!restored_prefill || decoded_prefill_suffix) + && let Some(kv) = self.kv.as_ref() + { + let base = self.local_kv_message_base(&session_id, request.ids); + let exact_identity = + kv.prefill_identity(&self.config, &base, 0, prefill_tokens); + if let Ok(Some(record)) = + kv.record_exact_state(&mut runtime, &session_id, &exact_identity) + { + resident_recorded_pages = resident_recorded_pages.saturating_add(1); + let mut attrs = self.openai_attrs(request.ids); + attrs.insert( + "skippy.exact_cache.recorded_page_id".to_string(), + json!(record.page_id), + ); + attrs.insert( + "skippy.exact_cache.payload_kind".to_string(), + json!(record.payload_kind.to_string()), + ); + attrs.insert( + "skippy.exact_cache.recorded_tokens".to_string(), + json!(record.token_count), + ); + attrs.insert( + "skippy.exact_cache.stored".to_string(), + json!(record.stored), + ); + attrs.insert( + "skippy.exact_cache.logical_bytes".to_string(), + json!(record.logical_bytes), + ); + attrs.insert( + "skippy.exact_cache.physical_bytes".to_string(), + json!(record.physical_bytes), + ); + attrs.insert( + "skippy.exact_cache.entries".to_string(), + json!(record.entries), + ); + attrs.insert( + "skippy.exact_cache.evicted_entries".to_string(), + json!(record.evicted_entries), + ); + attrs.insert( + "skippy.exact_cache.evicted_logical_bytes".to_string(), + json!(record.evicted_logical_bytes), + ); + attrs.insert( + "skippy.exact_cache.dedupe_hash_ms".to_string(), + json!(record.dedupe.hash_ms), + ); + attrs.insert( + "skippy.exact_cache.dedupe_block_count".to_string(), + json!(record.dedupe.block_count), + ); + attrs.insert( + "skippy.exact_cache.dedupe_new_block_count".to_string(), + json!(record.dedupe.new_block_count), + ); + attrs.insert( + "skippy.exact_cache.dedupe_reused_block_count".to_string(), + json!(record.dedupe.reused_block_count), + ); + self.telemetry + .emit("stage.openai_kv_record_decision", attrs); + } + for identity in kv.record_identities(&self.config, &base, 0, prefill_tokens) { + if let Ok(Some(record)) = kv.record_resident_prefix( + &mut runtime, + &session_id, + &identity, + prefill_tokens, + ) { resident_recorded_pages = resident_recorded_pages.saturating_add(1); let mut attrs = self.openai_attrs(request.ids); attrs.insert( - "skippy.exact_cache.recorded_page_id".to_string(), + "skippy.kv.recorded_page_id".to_string(), json!(record.page_id), ); attrs.insert( - "skippy.exact_cache.payload_kind".to_string(), - json!(record.payload_kind.to_string()), - ); - attrs.insert( - "skippy.exact_cache.recorded_tokens".to_string(), + "skippy.kv.recorded_tokens".to_string(), json!(record.token_count), ); attrs.insert( - "skippy.exact_cache.stored".to_string(), - json!(record.stored), - ); - attrs.insert( - "skippy.exact_cache.logical_bytes".to_string(), - json!(record.logical_bytes), - ); - attrs.insert( - "skippy.exact_cache.physical_bytes".to_string(), - json!(record.physical_bytes), + "skippy.kv.resident_seq_id".to_string(), + json!(record.seq_id), ); attrs.insert( - "skippy.exact_cache.entries".to_string(), + "skippy.kv.resident_entries".to_string(), json!(record.entries), ); attrs.insert( - "skippy.exact_cache.evicted_entries".to_string(), + "skippy.kv.evicted_entries".to_string(), json!(record.evicted_entries), ); - attrs.insert( - "skippy.exact_cache.evicted_logical_bytes".to_string(), - json!(record.evicted_logical_bytes), - ); - attrs.insert( - "skippy.exact_cache.dedupe_hash_ms".to_string(), - json!(record.dedupe.hash_ms), - ); - attrs.insert( - "skippy.exact_cache.dedupe_block_count".to_string(), - json!(record.dedupe.block_count), - ); - attrs.insert( - "skippy.exact_cache.dedupe_new_block_count".to_string(), - json!(record.dedupe.new_block_count), - ); - attrs.insert( - "skippy.exact_cache.dedupe_reused_block_count".to_string(), - json!(record.dedupe.reused_block_count), - ); self.telemetry .emit("stage.openai_kv_record_decision", attrs); } - for identity in kv.record_identities(&self.config, &base, 0, prefill_tokens) - { - if let Ok(Some(record)) = kv.record_resident_prefix( - &mut runtime, - &session_id, - &identity, - prefill_tokens, - ) { - resident_recorded_pages = resident_recorded_pages.saturating_add(1); - let mut attrs = self.openai_attrs(request.ids); - attrs.insert( - "skippy.kv.recorded_page_id".to_string(), - json!(record.page_id), - ); - attrs.insert( - "skippy.kv.recorded_tokens".to_string(), - json!(record.token_count), - ); - attrs.insert( - "skippy.kv.resident_seq_id".to_string(), - json!(record.seq_id), - ); - attrs.insert( - "skippy.kv.resident_entries".to_string(), - json!(record.entries), - ); - attrs.insert( - "skippy.kv.evicted_entries".to_string(), - json!(record.evicted_entries), - ); - self.telemetry - .emit("stage.openai_kv_record_decision", attrs); - } - } } } // Proactive eviction: after prefill recording, evict enough @@ -463,8 +462,8 @@ impl StageOpenAiBackend { runtime_lock_hold_max_ms.max(token_runtime_lock_hold_ms); predicted }; - if generation_hooks_active { - if let Some(injected_current) = self.maybe_run_generation_hooks( + if generation_hooks_active + && let Some(injected_current) = self.maybe_run_generation_hooks( &session_id, &mut hook_request, hook_runtime.as_ref(), @@ -473,10 +472,10 @@ impl StageOpenAiBackend { &mut last_mid_generation_hook_at, token_signal, signal_window, - )? { - current = injected_current; - continue; - } + )? + { + current = injected_current; + continue; } decoded_tokens += 1; if emit_token_debug { diff --git a/crates/skippy-server/src/frontend/request.rs b/crates/skippy-server/src/frontend/request.rs index f24ced254b..e7c56edaae 100644 --- a/crates/skippy-server/src/frontend/request.rs +++ b/crates/skippy-server/src/frontend/request.rs @@ -126,20 +126,21 @@ pub(super) fn media_url(part: &MessageContentPart) -> Option { pub(super) fn media_data(part: &MessageContentPart) -> Option { for key in ["input_audio", "audio", "image", "input_image", "image_url"] { - if let Some(value) = part.extra.get(key) { - if let Some(data) = value.get("data").and_then(Value::as_str) { - return Some(data.to_string()); - } + if let Some(value) = part.extra.get(key) + && let Some(data) = value.get("data").and_then(Value::as_str) + { + return Some(data.to_string()); } } None } pub(super) fn decode_media_url(url: &str) -> OpenAiResult> { - if let Some((prefix, payload)) = url.split_once(',') { - if prefix.starts_with("data:") && prefix.contains(";base64") { - return decode_base64_payload(payload); - } + if let Some((prefix, payload)) = url.split_once(',') + && prefix.starts_with("data:") + && prefix.contains(";base64") + { + return decode_base64_payload(payload); } if url.starts_with("http://") || url.starts_with("https://") { return Err(OpenAiError::unsupported( @@ -196,27 +197,26 @@ fn apply_shared_request_defaults( .as_ref() .map(|values| stop_sequence_from_defaults(values.clone())); } - if extra_value_is_omitted(extra, "top_k") { - if let Some(value) = defaults.top_k { - extra.insert("top_k".to_string(), serde_json::json!(value)); - } + if extra_value_is_omitted(extra, "top_k") + && let Some(value) = defaults.top_k + { + extra.insert("top_k".to_string(), serde_json::json!(value)); } - if extra_value_is_omitted(extra, "min_p") { - if let Some(value) = defaults.min_p { - extra.insert("min_p".to_string(), serde_json::json!(value)); - } + if extra_value_is_omitted(extra, "min_p") + && let Some(value) = defaults.min_p + { + extra.insert("min_p".to_string(), serde_json::json!(value)); } if extra_value_is_omitted(extra, "repeat_penalty") && extra_value_is_omitted(extra, "repetition_penalty") + && let Some(value) = defaults.repeat_penalty { - if let Some(value) = defaults.repeat_penalty { - extra.insert("repeat_penalty".to_string(), serde_json::json!(value)); - } + extra.insert("repeat_penalty".to_string(), serde_json::json!(value)); } - if extra_value_is_omitted(extra, "repeat_last_n") { - if let Some(value) = defaults.repeat_last_n { - extra.insert("repeat_last_n".to_string(), serde_json::json!(value)); - } + if extra_value_is_omitted(extra, "repeat_last_n") + && let Some(value) = defaults.repeat_last_n + { + extra.insert("repeat_last_n".to_string(), serde_json::json!(value)); } apply_reasoning_defaults(reasoning, reasoning_effort, extra, defaults); } diff --git a/crates/skippy-server/src/http.rs b/crates/skippy-server/src/http.rs index 8ac1e5dfa6..83ae9b2011 100644 --- a/crates/skippy-server/src/http.rs +++ b/crates/skippy-server/src/http.rs @@ -319,28 +319,28 @@ async fn message( &prefill.token_ids, ) .await; - if let Some(runtime) = state.runtime.as_ref() { - if restored_tokens < prefill.token_ids.len() { - let records = { - let mut runtime = runtime.lock().expect("runtime lock poisoned"); - runtime.prefill( - &prefill.base.session_id, - &prefill.token_ids[restored_tokens..], - )?; - let records = maybe_plan_record_prefill( - &state, - &prefill.base, - prefill.prompt_token_start, - &prefill.token_ids, - restored_tokens as u64, - ); - state - .telemetry - .emit("stage.llama_decode", lifecycle_attrs(&state.config)); - records - }; - spawn_record_prefill(state.clone(), records); - } + if let Some(runtime) = state.runtime.as_ref() + && restored_tokens < prefill.token_ids.len() + { + let records = { + let mut runtime = runtime.lock().expect("runtime lock poisoned"); + runtime.prefill( + &prefill.base.session_id, + &prefill.token_ids[restored_tokens..], + )?; + let records = maybe_plan_record_prefill( + &state, + &prefill.base, + prefill.prompt_token_start, + &prefill.token_ids, + restored_tokens as u64, + ); + state + .telemetry + .emit("stage.llama_decode", lifecycle_attrs(&state.config)); + records + }; + spawn_record_prefill(state.clone(), records); } StageMessage::PrefillChunk(prefill).ack_for(&state.config) } @@ -353,28 +353,28 @@ async fn message( &prefill.token_ids, ) .await; - if let Some(runtime) = state.runtime.as_ref() { - if restored_tokens < prefill.token_ids.len() { - let records = { - let mut runtime = runtime.lock().expect("runtime lock poisoned"); - runtime.prefill( - &prefill.base.session_id, - &prefill.token_ids[restored_tokens..], - )?; - let records = maybe_plan_record_prefill( - &state, - &prefill.base, - prefill.prompt_token_start, - &prefill.token_ids, - restored_tokens as u64, - ); - state - .telemetry - .emit("stage.llama_decode", lifecycle_attrs(&state.config)); - records - }; - spawn_record_prefill(state.clone(), records); - } + if let Some(runtime) = state.runtime.as_ref() + && restored_tokens < prefill.token_ids.len() + { + let records = { + let mut runtime = runtime.lock().expect("runtime lock poisoned"); + runtime.prefill( + &prefill.base.session_id, + &prefill.token_ids[restored_tokens..], + )?; + let records = maybe_plan_record_prefill( + &state, + &prefill.base, + prefill.prompt_token_start, + &prefill.token_ids, + restored_tokens as u64, + ); + state + .telemetry + .emit("stage.llama_decode", lifecycle_attrs(&state.config)); + records + }; + spawn_record_prefill(state.clone(), records); } StageMessage::FinalPrefillChunk(prefill).ack_for(&state.config) }