From 261e4daa15561e52ddab84a228815cd5c2dfcfdb Mon Sep 17 00:00:00 2001 From: loulanyue <260355617@qq.com> Date: Sat, 22 Aug 2026 07:00:19 +0800 Subject: [PATCH] server: observe resumable stream cancellation during first result wait (#27481) --- tools/server/server-context.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/server/server-context.cpp b/tools/server/server-context.cpp index 1293c8640267..b09553ae8122 100644 --- a/tools/server/server-context.cpp +++ b/tools/server/server-context.cpp @@ -4298,10 +4298,13 @@ std::unique_ptr server_routes::handle_completions_impl( // in streaming mode, the first error must be treated as non-stream response // this is to match the OAI API behavior // ref: https://github.com/ggml-org/llama.cpp/pull/16486#discussion_r2419657309 - auto first_result = rd.next(req.should_stop); + auto first_should_stop = [res_this = res.get()]() { + return res_this->should_stop(); + }; + auto first_result = rd.next(first_should_stop); if (first_result == nullptr) { - GGML_ASSERT(req.should_stop()); - return res; // connection is closed + GGML_ASSERT(first_should_stop()); + return res; // connection is closed or stream cancelled } if (first_result->is_error()) {