server + ui: fix stream routes for model names containing a slash (#26137)

* server + ui: refactor resumable stream routes to query string conv_id

The conversation id can embed a model name containing slashes
(ggml-org/...) in router mode, which the decoded path splits before the
:conv_id param is captured, so stop and resume never matched the
session. Move the id to the conv_id query string on the public routes
and on the internal router -> child hop, where slashes survive
encoding. Handlers are unchanged since query and path params land in
the same map. Add a regression test with a slashed model name.

* server: move stream route docs to server-stream.h

Address review: ngxson wants the main server.cpp registration code kept
clean and simple, with route-level explanations living in the header.
Move the query string rationale and the lookup ownership note next to
the handler declarations in server-stream.h, and shorten the wiring
comment to a pointer.

* server: cancel a pending request when its stream is stopped during model load

The conversation was registered in the conv map only after the blocking
autoload wait, so a stop issued while the model loaded found nothing to
cancel and the request went on to generate an orphan once the load
ended. Register the conversation before the wait and give the entry a
ticket: a stop erases the entry, and the parked request checks its
ticket after the wait and aborts with 400 instead of starting. A newer
request on the same conversation replaces the entry, so only the
stopped request is cancelled. Add a regression test that stops during
the load window.

* server + ui: resume a stream after a page reload during model load

A pending request died with the client socket when the page was
reloaded while its model was loading, so no session ever existed and
the conversation had nothing to recover. A session request that waited
for a load now detaches from the client socket and reaches the child
regardless, the session buffer receives the generation, and the resume
route answers 503 while the owner is loading so the client retries
instead of dropping its state. The WebUI persists the pending stream at
send time, quietly polls on 503, and attaches once the session exists.
Add a regression test that drops the client during the load window.

* ui: show the model load progress again after a page refresh

The resume wait was invisible, so a conversation refreshed while its
model was loading showed nothing until the first byte. On a 503 from
the resume probe, mark the conversation as loading again so the
assistant row persisted at send time renders the processing info, and
target the model frozen in the persisted stream state for the
progress, since the row has no model yet and the dropdown may not be
restored.

* fix CI

* fix CI bis
This commit is contained in:
Pascal
2026-07-27 07:34:47 +02:00
committed by GitHub
parent 88b47a755c
commit d73c1d6b22
11 changed files with 345 additions and 55 deletions
+24 -7
View File
@@ -134,12 +134,24 @@ private:
// proxy_request forwards a POST carrying an X-Conversation-Id. best effort: a stale entry just
// makes the child answer not found and the client recovers. owns its lock, one mutex per struct
struct conv_model_tracker {
void remember(const std::string & conv_id, const std::string & model) {
// returns the ticket of this registration, 0 when nothing was registered. erasing or
// replacing the entry invalidates the ticket, which is how a stop cancels a request
// parked in the model load wait
uint64_t remember(const std::string & conv_id, const std::string & model) {
if (conv_id.empty() || model.empty()) {
return;
return 0;
}
std::lock_guard<std::mutex> lock(mu);
map[conv_id] = model;
uint64_t ticket = next_ticket++;
map[conv_id] = { model, ticket };
return ticket;
}
// false means a stop erased the entry or a newer request replaced it
bool alive(const std::string & conv_id, uint64_t ticket) {
std::lock_guard<std::mutex> lock(mu);
auto it = map.find(conv_id);
return it != map.end() && it->second.ticket == ticket;
}
std::optional<std::string> lookup(const std::string & conv_id) {
@@ -151,7 +163,7 @@ private:
if (it == map.end()) {
return std::nullopt;
}
return it->second;
return it->second.model;
}
void forget(const std::string & conv_id) {
@@ -163,8 +175,13 @@ private:
}
private:
std::mutex mu;
std::unordered_map<std::string, std::string> map;
struct entry_t {
std::string model;
uint64_t ticket;
};
std::mutex mu;
uint64_t next_ticket = 1;
std::unordered_map<std::string, entry_t> map;
};
common_preset_context ctx_preset;
@@ -249,7 +266,7 @@ public:
bool ensure_model_ready(const std::string & name);
// proxy an HTTP request to the model instance
server_http_res_ptr proxy_request(const server_http_req & req, const std::string & method, const std::string & name, bool update_last_used);
server_http_res_ptr proxy_request(const server_http_req & req, const std::string & method, const std::string & name, bool update_last_used, bool detached = false);
// handle message sent from server_child::notify_to_router()
// raw input must starts with CMD_CHILD_TO_ROUTER_STATE, followed by a JSON string