From 5fe48e4910df792fcd22d98f748b9c4218f502ad Mon Sep 17 00:00:00 2001 From: Tai An Date: Wed, 15 Jul 2026 23:54:35 -0700 Subject: [PATCH] fix(backend): don't crash the whole process on an invalid cutstrings/extract_regex (#10855) Finetune() compiled every model cutstrings/extract_regex entry via regexp.Compile and called xlog.Fatal on failure, which terminates the entire local-ai process. A single model config with an invalid regex (e.g. cutstrings: ["("]) turns one /v1/chat/completions request into a process-level denial of service. Log the compile error and skip the offending pattern instead. The mutex is released before continuing, and skipping avoids dereferencing the nil regexp that removing the fatal would otherwise leave behind. Fixes #10843 Signed-off-by: Tai An --- core/backend/llm.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/backend/llm.go b/core/backend/llm.go index 6d56f40f8..caf03f74d 100644 --- a/core/backend/llm.go +++ b/core/backend/llm.go @@ -463,7 +463,9 @@ func Finetune(config config.ModelConfig, input, prediction string) string { if !ok { r, err := regexp.Compile(c) if err != nil { - xlog.Fatal("failed to compile regex", "error", err) + mu.Unlock() + xlog.Error("failed to compile cutstrings regex, skipping", "error", err, "regex", c) + continue } cutstrings[c] = r reg = cutstrings[c] @@ -480,7 +482,9 @@ func Finetune(config config.ModelConfig, input, prediction string) string { if !ok { regex, err := regexp.Compile(r) if err != nil { - xlog.Fatal("failed to compile regex", "error", err) + mu.Unlock() + xlog.Error("failed to compile extract_regex regex, skipping", "error", err, "regex", r) + continue } cutstrings[r] = regex reg = regex