server: a request log at the info level

docker logs answered nothing about traffic: the only lines the server
wrote on a request were the kernel recordings, and a refusal left no
trace at all, so a client reporting "rejected" could not be matched to
anything. Two lines per request now, at info: one when it is admitted
(id, endpoint, peer, model, message and tool counts, prompt tokens, n,
max_tokens) and one from record() when it ends (finish reason, prompt
tokens and what the prefix cache spared, generated and reasoning
tokens, time to first token, decode rate, wall). Every refusal logs its
status, type and message with the peer -- 4xx at info, 5xx as a
warning. The debug level adds the last user message's opening, one
bounded line, so a log line can be matched to what was typed; the
daily's info level never prints prompt text.

HttpRequest carries the peer (httplib's remote_addr:port; empty
in-process), OaiRequest carries what the parse already walked past
(message and tool counts, the last user message) and the peer.

(cherry picked from commit 067facd47e2b0c0afeefe79166e77f01c33d588f)
This commit is contained in:
baKon authored and StillDeadcode committed 2026-10-05 19:30:45 +02:00
1 parent a4845834ea
commit ee65352d7d
6 files changed
+96 -10

No files matched your search

+19
View File
@@ -1273,6 +1273,24 @@ int parse_chat_request(const std::string& body, const OaiDeps& d, const OaiLimit
auto mit = b.find("messages");
if (mit == b.end()) { *err = err_bad("messages", "is required"); return RAD_E_INVAL; }
json messages = *mit;
if (messages.is_array()) {
out->n_messages = (int)messages.size();
for (auto it = messages.rbegin(); it != messages.rend(); ++it) {
if (!it->is_object() || !it->contains("role") || it->at("role") != "user") continue;
const auto cit = it->find("content");
if (cit == it->end()) break;
std::string t;
if (cit->is_string()) t = cit->get<std::string>();
else if (cit->is_array())
for (const auto& part : *cit)
if (part.is_object() && part.value("type", "") == "text")
t += part.value("text", "");
for (char& c : t) if (c == '\n' || c == '\r' || c == '\t') c = ' ';
if (t.size() > 160) { t.resize(157); t += "..."; }
out->last_user = std::move(t);
break;
}
}
/* tools and tool_choice. */
json tools = json::array();
@@ -1290,6 +1308,7 @@ int parse_chat_request(const std::string& body, const OaiDeps& d, const OaiLimit
}
}
tools = *tit;
out->n_tools = (int)tools.size();
}
/* FORCING A CALL IS REFUSED, and not because the grammar is out of reach -- the template