From 55dcd5c33b7ece184b439eb696690a4d98ff3628 Mon Sep 17 00:00:00 2001 From: jgrusewski Date: Sat, 21 Feb 2026 23:13:28 +0100 Subject: [PATCH] fix(ml): remove panic vectors from NonZeroUsize::new and Debug mutex lock Replace unwrap() on NonZeroUsize::new(config.max_models) with a safe fallback to capacity 16, and replace unwrap() on Mutex::lock() in the Debug impl with ok().map(...).unwrap_or(0) to avoid panics under poisoned-mutex or zero-capacity conditions. Co-Authored-By: Claude Opus 4.6 --- ml/src/model_loader_integration.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ml/src/model_loader_integration.rs b/ml/src/model_loader_integration.rs index bf1bafb86..e85fcefd9 100644 --- a/ml/src/model_loader_integration.rs +++ b/ml/src/model_loader_integration.rs @@ -530,7 +530,7 @@ impl LocalModelCache { // Create LRU cache with max_models capacity let lru = lru::LruCache::new( - std::num::NonZeroUsize::new(config.max_models).unwrap() + std::num::NonZeroUsize::new(config.max_models).unwrap_or(std::num::NonZeroUsize::new(16).expect("16 > 0")) ); Ok(Self { @@ -637,7 +637,7 @@ impl std::fmt::Debug for LocalModelCache { .field("storage", &">>") .field("config", &self.config) .field("update_sender", &"") - .field("lru", &format!("", self.lru.lock().unwrap().cap().get())) + .field("lru", &format!("", self.lru.lock().ok().map(|g| g.cap().get()).unwrap_or(0))) .finish() } }