Commit b04489040 for llama.cpp

commit b0448904084fb28b363b3491a2922ee3360d9bbd
Author: Xuan-Son Nguyen <son@huggingface.co>
Date:   Wed Nov 18 23:48:02 2026 +0100

    server: fix sleep state for v1/realtime (#32567)

diff --git a/tools/server/README-dev.md b/tools/server/README-dev.md
index afe729878..997b8137d 100644
--- a/tools/server/README-dev.md
+++ b/tools/server/README-dev.md
@@ -323,6 +323,8 @@ Call stack on waking up:

 Endpoints created with `create_response(true)` (`/health`, `/props`, `/models`, `/metrics`) skip `wait_until_no_sleep`, so they answer from the cached responses instead of waking the server.

+IMPORTANT: any handler that touches the model or contexts (`ctx_server.mctx`, `ctx_server.vocab`, etc.) must call `create_response()` before that access, and keep the returned object alive until it is done with them. While sleeping, these pointers are freed, so using them before waking up leads to a crash. The returned object also holds an inflight count (released in its destructor) that prevents the server from going back to sleep. This applies to every route type, not only HTTP routes: for example, the `/v1/realtime` websocket handler calls `create_response()` first and holds it for the whole session.
+
 ### Notable Related PRs

 - Initial server implementation: https://github.com/ggml-org/llama.cpp/pull/1443
diff --git a/tools/server/server-context.cpp b/tools/server/server-context.cpp
index 0b479fc69..36082df89 100644
--- a/tools/server/server-context.cpp
+++ b/tools/server/server-context.cpp
@@ -6106,6 +6106,9 @@ void server_routes::init_routes() {
     // audio is PCM16 mono at the model sample rate, sent as base64 in input_audio_buffer.append events
     // input_audio_buffer.commit with "final": true ends the input, closing the socket also ends it
     this->ws_realtime = [this](const server_http_req & req, server_http_context::ws_conn & conn) {
+        // make sure sleep state is handled by create_response()
+        auto res = create_response();
+
         auto send_event = [&conn](json ev) {
             ev["event_id"] = "event_" + random_string();
             conn.send(safe_json_to_str(ev));
@@ -6150,7 +6153,6 @@ void server_routes::init_routes() {
             }}}},
         };

-        auto res = create_response();
         auto & rd = res->rd;
         {
             server_task task(SERVER_TASK_TYPE_TRANSCRIBE_RT);