Skip to content

Commit c7b383c

Browse files
Anai-Guorichiejp
authored andcommitted
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 <antai12232931@outlook.com> Signed-off-by: Richard Palethorpe <io@richiejp.com>
1 parent be3d263 commit c7b383c

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

core/backend/llm.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,9 @@ func Finetune(config config.ModelConfig, input, prediction string) string {
463463
if !ok {
464464
r, err := regexp.Compile(c)
465465
if err != nil {
466-
xlog.Fatal("failed to compile regex", "error", err)
466+
mu.Unlock()
467+
xlog.Error("failed to compile cutstrings regex, skipping", "error", err, "regex", c)
468+
continue
467469
}
468470
cutstrings[c] = r
469471
reg = cutstrings[c]
@@ -480,7 +482,9 @@ func Finetune(config config.ModelConfig, input, prediction string) string {
480482
if !ok {
481483
regex, err := regexp.Compile(r)
482484
if err != nil {
483-
xlog.Fatal("failed to compile regex", "error", err)
485+
mu.Unlock()
486+
xlog.Error("failed to compile extract_regex regex, skipping", "error", err, "regex", r)
487+
continue
484488
}
485489
cutstrings[r] = regex
486490
reg = regex

0 commit comments

Comments
 (0)