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.
This commit is contained in:
gapeleon
2026-05-17 18:26:45 +03:00
committed by GitHub
parent 0ab9bdf793
commit c35189d83c
+3
View File
@@ -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<std::string>());
} 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;
}
}
{