From 82fce65d8be40ba55048e06f2e14a01deb363d41 Mon Sep 17 00:00:00 2001 From: Jesse LaRose Date: Thu, 9 Jul 2026 12:37:39 -0400 Subject: [PATCH] server : move chat-template thinking probe inside the init try/catch (#24093) A model whose chat template parses at init but fails parser generation at apply time (e.g. uses {% call %}) throws std::invalid_argument from common_chat_templates_support_enable_thinking(), which ran outside the try/catch guarding common_chat_templates_init(). The throw was uncaught and llama-cli aborted (SIGABRT) instead of failing to load. Moved the probe inside that try/catch so an apply-time error fails load the same way an init parse error does. Signed-off-by: Jesse LaRose --- tools/server/server-context.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/server/server-context.cpp b/tools/server/server-context.cpp index eb41acc5b4..98d0cca1cc 100644 --- a/tools/server/server-context.cpp +++ b/tools/server/server-context.cpp @@ -1444,6 +1444,7 @@ private: // populate chat template params { common_chat_templates_ptr chat_templates; + bool enable_thinking = false; try { chat_templates = common_chat_templates_init(model_tgt, params_base.chat_template); @@ -1451,6 +1452,12 @@ private: SRV_TRC("%s: chat template, example_format: '%s'\n", __func__, common_chat_format_example(chat_templates.get(), params_base.use_jinja, params_base.default_template_kwargs).c_str()); + // thinking is enabled if: + // 1. It's not explicitly disabled via --reasoning off + // 2. The chat template supports it + const bool template_supports_thinking = params_base.use_jinja && common_chat_templates_support_enable_thinking(chat_templates.get()); + enable_thinking = params_base.enable_reasoning != 0 && template_supports_thinking; + SRV_TRC("%s: chat template, thinking = %d\n", __func__, enable_thinking); } catch (const std::exception & e) { SRV_ERR("%s: chat template parsing error: %s\n", __func__, e.what()); SRV_ERR("%s: please consider disabling jinja via --no-jinja, or use a custom chat template via --chat-template\n", __func__); @@ -1458,13 +1465,6 @@ private: return false; } - // thinking is enabled if: - // 1. It's not explicitly disabled via --reasoning off - // 2. The chat template supports it - const bool template_supports_thinking = params_base.use_jinja && common_chat_templates_support_enable_thinking(chat_templates.get()); - const bool enable_thinking = params_base.enable_reasoning != 0 && template_supports_thinking; - SRV_TRC("%s: chat template, thinking = %d\n", __func__, enable_thinking); - // IMPORTANT: chat_params is reused across sleeping / resuming states, // never store llama_context/llama_model pointers in chat_params, // as they may be invalidated after sleeping