From 3203ab47a61ae3d5422582bc98b6c99b66b947a5 Mon Sep 17 00:00:00 2001 From: Georgi Gerganov Date: Fri, 10 Jul 2026 16:49:57 +0300 Subject: [PATCH] server : prevent LRU eviction of models still loading In router mode with models_max, unload_lru() could select a model in LOADING state as the LRU victim. Because the child's stdin monitoring thread starts only after model loading completes, the exit command sits unread in the buffer and the stop_timeout expires before the child ever receives it, causing a force-kill. LOADING models still count toward capacity to prevent resource exhaustion from concurrent loads, but are excluded from eviction. --- tools/server/server-models.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/server/server-models.cpp b/tools/server/server-models.cpp index d1fdc06079..2919b6d7d4 100644 --- a/tools/server/server-models.cpp +++ b/tools/server/server-models.cpp @@ -751,6 +751,9 @@ void server_models::unload_lru() { for (const auto & m : mapping) { if (m.second.meta.is_running()) { count_active++; + if (m.second.meta.status == SERVER_MODEL_STATUS_LOADING) { + continue; + } if (m.second.meta.last_used < lru_last_used) { lru_model_name = m.first; lru_last_used = m.second.meta.last_used;