Display both rates in t/s with independent graph scales and a darker
prefill curve. Expose prefill_tok_s_mean using the engine's existing
rate, excluding cached tokens.
Co-authored-by: Codex (gpt-6-astra-medium) <noreply@openai.com>
Expose loaded-model metadata through /models and /v1/models.
Add /props and single-slot /slots responses with existing API-key
enforcement and regression coverage.
Validation: all 30 server tests pass. Pi 0.87.1 discovered the loaded
model with 262144-token context and thinking support, and completed
a chat smoke test successfully.
Fixes#117.
Co-authored-by: Codex (gpt-6-astra-medium) <noreply@openai.com>
The conversation cache's reuse is kept per request (GET /metrics shows it),
but the APIs did not report it, so clients showed a cached prompt as 0%:
- OpenAI: usage.prompt_tokens_details.cached_tokens, streamed and not.
- Anthropic: the final usage splits input_tokens from
cache_read_input_tokens (message_start can only know the whole prompt).
- llama.cpp's `timings` block on the last chunk and on a whole reply
(prompt_n, cache_n, prompt/predicted ms and per second), from the
engine's own clock: what llama.cpp's clients already show as speed.
- GET /v1/status (with the API key when one is set): the model and its
window, images, the APIs, whether a request is running, the last
request's timings and the GPU and RAM from the telemetry, for a
front-end that polls its server rather than guessing.
An engine without a clock (MockEngine) reports no timings and 0 cached.
Tests: serve/test_server.py UsageAndStatus.
live.tok_s returned `generated / (now - first_token)`: a cumulative mean whose
first sample is 1/elapsed. Against an engine paced at 25 tokens/s the Speed
card, the header pill and the tok_s sparkline read 27,235.7 tok/s at that first
sample - about 1090x the real rate - and then undershot for the first second of
every answer (one token counted over up to a second of elapsed time). Because
the sparkline scales to the maximum of its 60-sample ring, one such sample also
flattened the Speed graph for a minute.
tok_s is now the rate over the last RATE_WINDOW_S (2 s), with the mean so far
reported only while a request is younger than RATE_MIN_SPAN_S (0.25 s) and its
span floored there, so no sample can diverge. The old formula is kept as
_tok_s_mean() and still reported (live.tok_s_mean, status.tokens_per_s_mean).
The same request fixes a second mis-attribution: a request that ended without a
DONE line (engine death, error, client disconnect) recorded the PREVIOUS
request's generated/decode_ms as its own decode_tok_s. The engine's counters
are now trusted only when its DONE replaced the object captured at request
start, and the row carries the engine's own token count as engine_generated.
Tests: serve/test_server.py::LiveRate paces a mock engine and polls GET /metrics
at 10 ms. Both cases fail without the server.py change (990.0 tok/s recorded
for a request that never finished) and pass with it; the rest of the suite is
unchanged at 28 tests, OK. The engine's own per-request counters - what the
Speed card shows for "last request" - are untouched, and the server's progress
and summary log lines keep their whole-request mean on purpose.
tools/calibrate.py starts the engine through serve's StrataEngine and measures decode speed with the
three settings that depend on the machine: --pcie-frac and --spec-min-p through new per-request GEN
keys (pcie_frac=, spec_min_p=; the server forwards a request's "strata_tune"), then 2-3 worker counts
(a restart each). A setting is kept only when it beats the product default by more than 3% in an
interleaved re-measurement. Setup offers it after an interactive install and runs it with --calibrate;
the result is saved per PC + model + context in the settings file and re-applied when a config is
written, so updates keep it. The engine's INFO line now says pool_workers, pcie_frac and spec_min_p.
tools/test_calibrate.py tests it with a stand-in engine (no GPU).
- serve: a verify window samples T rows, but only row 0's penalty history was staged; rows 1..T-1 read
unwritten slots (past the allocation at penalty_last_n=4096). Every row now gets its own history
(strata::kernels::penalty_rows: the consumed tail, the fed-back token, the drafts before that row).
- prompt windows (their picks are discarded) skip the head sampling: Verifier::set_head_sampling.
- sampler: history ids outside [0, n_vocab) are ignored (they set bits past the shared bitmap); sampled
top_k 0 or > 64 means 64 and every row is written (0 used to leave the row unwritten).
- server: a client's top_k 0 or > 64 is sent as 64 (it fell back to the default 20).
- CLI: the speculative loop gets the CLI's sampling (it was always greedy), the per-token path draws
Philox(seed, position) like a verify window, and the effective sampling is printed.
- sampler_parity: fixtures 12-15 (per-row histories T=1..8 x H=1..4096, out-of-vocab ids, the top_k
contract, penalty_rows); outputs are pre-filled so an unwritten row fails.
- setup requires engine 0.1.19.
Found by the engineering performance review (C1, C2).
- A config's "gpu" (or the server's --gpu N) runs the engine and the image
encoder on that card: CUDA_VISIBLE_DEVICES=N with CUDA_DEVICE_ORDER=PCI_BUS_ID,
so N means what nvidia-smi and the Monitor's NVML mean (CUDA's own default,
fastest first, can number the cards differently). The Monitor reads that card.
- setup lists every NVIDIA GPU, picks the one with the most VRAM (or --gpu N),
says so when there is more than one, and saves the choice; START-HERE.bat
--gpu N also overrides it when starting. A number that does not exist stops
with the list of cards. Configs without "gpu" run as before.
- Tests: the child environment; the choice on a simulated 4060 + 5070 PC; end to
end on the real engine with --gpu 0.
- POST routes ignore the query string (Claude Code calls /v1/messages?beta=true
and got a 404, which it reports as a model problem); /settings too.
- A system (or late developer) message after the first one becomes a user
message in place: the chat template only takes a system message at the start
and raised "System message must be at the beginning" (the client saw a dropped
connection). Kept in place, not merged into the first, so the conversation
cache still reuses the prompt.
- Tests with the issues' own requests (they fail on the old code); DETAILS:
how to point Claude Code at Strata.
- The --serve stdin reader reads the descriptor instead of std::cin: glibc's
exit() waits for stdin's lock, which getline held while waiting for input,
so an engine ending on any error hung in exit() and the server waited forever.
- session_init fails when a QSA layer could not pin its KV streaming copy; it
used to continue half-built and hit an illegal memory access at the first
request (seen under WSL, where the driver pins only about 1 GiB). The message
says how much was pinned and what to change.
- setup: no KV streaming under WSL (new installs and existing configs).
- server: an engine ERR after an SSE stream started is sent as an error event
(it was a 400 response written into the open stream: an empty answer), and
the request is recorded as "error".
A switch in the Sampling drawer. With it on, Apply stores the drawer's
settings on the server (POST /settings): thinking level, temperature,
top-p, top-k, seed, max tokens and the experimental speed projection. omp
and other API clients then get them for anything they don't send
themselves, from their next request (no restart); what a client sends still
wins. Off again, clients use their own settings.
- Kept between starts in <config>.shared-settings.json next to the run
config; the server window says what other apps use.
- Only Strata's own page can change them: JSON only (a cross-site form or
simple request can't send it without a CORS preflight, which this server
never grants), no foreign Origin, and the API key when one is set.
- Values are checked (bad ones are a 400 naming the setting).
- Tests: defaults reach the engine, a client's own values win, off clears
them and the file, 415/403/400/401.
On Linux with too little RAM for the model's experts (IQ3_XXS on 47 GB), the
out-of-memory killer ended the engine mid-answer. The server then recorded
the reply as "length" ("Max tokens" in the Monitor, no tok/s), the stream
was cut with a traceback, and every later request failed on the dead pipe.
- The engine's death is EngineDied: the reply ends with a clear error event
(OpenAI and Anthropic streams; 503 before the answer), the Monitor says
Error, and the server window names the likely cause (RAM; dmesg).
- The next request starts the engine again (same command) instead of
failing forever; the engine counts as gone as soon as its output closes,
and a failed write to it is not mistaken for the client leaving.
- The engine's INFO line reports its expert arena (arena_mib); at start the
server warns when less than ~6 GB of RAM is left beside it.
- Test: a fake engine dies mid-stream -> error event + [DONE], Monitor
"error", the next request restarts it and answers. End to end with Q2_0:
strata.exe killed mid-answer -> error (exit code 1); next request restarts
it (31 s) and answers.
- A prompt that leaves no room at all is still the clear 400 with the flag
on (it clamped to 1 token, which the engine then refused as over the
context).
- "fit_max_tokens": true in the run config switches it on too, since the
run scripts are generated by setup.
- Tests: an overshoot is clamped to the room on both APIs, a budget that
fits is unchanged, no room is a 400. Documented in DETAILS.
The browser page at http://127.0.0.1:8080 is now the Strata app, in the
Strata design language (serve/web, same origin, no CDN):
- Chat: streaming answers, collapsible thinking, Markdown with code copy,
images when enabled, sampling/thinking settings, export, new chat.
- Monitor: live model state (reading with progress / generating at tok/s),
GPU load, VRAM, temperature, power, PCIe traffic, CPU, RAM, disk, the
context fill and the last requests, each with a minute of history.
- About: the model and engine settings, this PC, the API addresses.
Server: GET /metrics (API key when set), /web/* app files, /fonts/* only
when installed locally (not shipped; the page falls back to the system
font). serve/telemetry.py reads NVML via ctypes and psutil (new setup
dependency) with fallbacks. The engine prints an INFO line before READY
(kv, expert slots, speculation); older servers ignore it and the server
works with older engines.
Based on the dashboard idea in PR #22 by code-martin.
A missing, null, 0 or -1 max_tokens / max_completion_tokens now means the
rest of the context (minus the 8-token margin strata --serve keeps), so
replies no longer stop at 1024 tokens. prepare() resolves the budget after
tokenizing and returns it; an explicit budget is honoured exactly and still
rejected when prompt + budget exceeds the context. Adds serve/test_server.py.