From c35189d83c91aad780aba62b89f2830cb2916223 Mon Sep 17 00:00:00 2001 From: gapeleon <191471103+gapeleon@users.noreply.github.com> Date: Mon, 18 May 2026 01:26:45 +1000 Subject: [PATCH] fix(server): reset chat parser on slot reuse to prevent crash (#1763) (#1794) If a slot is reused for a standard completion (`/v1/completions`) after being used for a chat completion (`/v1/chat/completions`), the previous chat's PEG parser would remain active in the slot's parameters. This caused standard text completions to throw on the raw text. --- examples/server/server-context.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/server/server-context.cpp b/examples/server/server-context.cpp index 69217ba2..b91149ce 100644 --- a/examples/server/server-context.cpp +++ b/examples/server/server-context.cpp @@ -1624,6 +1624,9 @@ bool server_context::launch_slot_with_task(server_slot& slot, server_task& task) slot.params.chat_parser_params.parse_tool_calls = json_value(data, "parse_tool_calls", false); if (data.contains("chat_parser")) { slot.params.chat_parser_params.parser.load(data.at("chat_parser").get()); + } else { + // Reset to default; otherwise a reused slot would apply the previous chat's PEG parser to non-chat outputs (e.g., /v1/completions). + slot.params.chat_parser_params.parser = defaults.chat_parser_params.parser; } } {