Skip to content

Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.

C++

serve: /slots reports n_prompt_tokens, and one entry per slot with --batch (#562)

Niko12210b576686f620
diff --git a/docs/DETAILS.md b/docs/DETAILS.md
index d031f541e..43da2ffe8 100644
--- a/docs/DETAILS.md
+++ b/docs/DETAILS.md
@@ -533,12 +533,12 @@ The server listens on `http://127.0.0.1:8080` (change with `--port` in setup, or
| OpenAI Responses (stream and non-stream, tools; stateless, [below](#the-responses-api-and-codex-cli)) | `POST /v1/responses` |
| Model list / health | `GET /v1/models`, `GET /models`, `GET /health` |
| Model properties | `GET /props` (also accepts `?model=<loaded-model-id>`) |
-| What the model is doing right now | `GET /status`, `GET /slots` (single slot, busy or idle) |
+| What the model is doing right now | `GET /status`, `GET /slots` (busy or idle, with `n_prompt_tokens`; one entry per slot with `--batch`) |
| Save / restore the conversation to a file (session files, below) | `POST /slots/0?action=save\|restore` |
| Everything the Monitor tab shows (engine, live state, last requests, hardware) | `GET /metrics` |
| The MCP servers, their state and tools ([below](#tools-from-mcp-servers)) | `GET /mcp` |
-`/models` and `/v1/models` list only the loaded model, with its context limit and input modalities. `/props` exposes the original chat template, context limit, configured generation defaults (shared settings take precedence), model path and engine version when available. Context means the full engine context, not the resident KV window. `n_predict: -1` means no fixed output cap. Unconfigured sampling fields are omitted. `autoload` has no effect; an unknown `model` returns 404. These metadata endpoints and `/slots` require the API key when one is configured. They do not load, unload or restart models.
+`/models` and `/v1/models` list only the loaded model, with its context limit and input modalities. `/props` exposes the original chat template, context limit, configured generation defaults (shared settings take precedence), model path and engine version when available. Context means the full engine context, not the resident KV window. `n_predict: -1` means no fixed output cap. Unconfigured sampling fields are omitted. `/slots` uses llama.cpp's names: `n_ctx` and `n_prompt_tokens` (the running request's prompt size, kept after it ends: what a front-end's context meter divides by `n_ctx`). `total_slots` in `/props` is the number of `--batch` slots (1 without). `autoload` has no effect; an unknown `model` returns 404. These metadata endpoints and `/slots` require the API key when one is configured. They do not load, unload or restart models.
`chat_template_caps` uses llama.cpp's field names. Strata checks them when loading the active template by rendering
small requests; a rejected or omitted feature is `false`, and a template that fails a probe in any way only turns that
diff --git a/serve/server.py b/serve/server.py
index 3a3343437..f73327d13 100644
--- a/serve/server.py
+++ b/serve/server.py
@@ -3953,8 +3953,20 @@ def make_handler(svc: Service):
loaded = not hasattr(svc.engine, "alive") or svc.engine.alive()
with svc.status_lock:
busy = bool(svc.status.get("busy"))
- slot = {"id": 0, "n_ctx": svc.engine.max_context, "is_processing": busy}
- self._json(200, [slot] if loaded else [])
+ # llama.cpp's name for what the slot's context holds: the running request's prompt size,
+ # kept after it ends (the conversation cache carries it on). A front-end's context meter
+ # divides it by n_ctx; without the key it reads 0 % against Strata forever (#562).
+ in_use = int(svc.status.get("prompt_tokens") or 0)
+ if getattr(svc.engine, "batch", 0) and hasattr(svc.engine, "slots_view"):
+ # --batch: one entry per slot (the same view /metrics has), not one for the whole engine
+ n_ctx = svc.engine.max_context
+ slots = [{"id": s["slot"], "n_ctx": n_ctx, "is_processing": s["state"] != "idle",
+ "n_prompt_tokens": int(s.get("prompt_tokens") or s.get("held_tokens") or 0)}
+ for s in svc.engine.slots_view()]
+ else:
+ slots = [{"id": 0, "n_ctx": svc.engine.max_context, "is_processing": busy,
+ "n_prompt_tokens": in_use}]
+ self._json(200, slots if loaded else [])
elif path == "/v1/status":
if self._authorized():
self._json(200, svc.v1_status())
diff --git a/serve/test_server.py b/serve/test_server.py
index 98919b940..164e94cae 100644
--- a/serve/test_server.py
+++ b/serve/test_server.py
@@ -2289,6 +2289,31 @@ class WebApp(unittest.TestCase):
finally:
self.svc.template = original
+ def test_slot_reports_the_context_in_use(self):
+ """/slots in llama.cpp's names: a front-end's context meter divides n_prompt_tokens by n_ctx, so a server
+ that leaves the key out shows 0 % no matter how full the context is."""
+ with self.svc.status_lock:
+ self.svc.status["prompt_tokens"] = 1234
+ try:
+ slot = json.loads(self.get("/slots")[2])[0]
+ self.assertEqual((slot["n_ctx"], slot["n_prompt_tokens"]), (CTX, 1234))
+ finally:
+ with self.svc.status_lock:
+ self.svc.status.pop("prompt_tokens", None)
+ self.assertEqual(json.loads(self.get("/slots")[2])[0]["n_prompt_tokens"], 0)
+
+ def test_slots_lists_every_batch_slot(self):
+ engine = self.svc.engine
+ engine.batch, engine.max_context = 2, CTX
+ engine.slots_view = lambda: [{"slot": 0, "state": "decoding", "prompt_tokens": 500},
+ {"slot": 1, "state": "idle", "held_tokens": 77}]
+ try:
+ slots = json.loads(self.get("/slots")[2])
+ finally:
+ del engine.batch, engine.slots_view
+ self.assertEqual(slots, [{"id": 0, "n_ctx": CTX, "is_processing": True, "n_prompt_tokens": 500},
+ {"id": 1, "n_ctx": CTX, "is_processing": False, "n_prompt_tokens": 77}])
+
def test_props_total_slots_follows_the_batch_slots(self):
# llama.cpp clients read total_slots as the number of requests the server runs at once
engine, had = self.svc.engine, hasattr(self.svc.engine, "batch")
@@ -2325,7 +2350,8 @@ class WebApp(unittest.TestCase):
self.svc.status["busy"] = busy
code, _, body = self.get("/slots")
self.assertEqual(code, 200)
- self.assertEqual(json.loads(body), [{"id": 0, "n_ctx": CTX, "is_processing": busy}])
+ self.assertEqual(json.loads(body), [{"id": 0, "n_ctx": CTX, "is_processing": busy,
+ "n_prompt_tokens": 0}])
finally:
with self.svc.status_lock:
self.svc.status["busy"] = False