mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #4232] [GUI] API monitor: show the tokens held in the engine's KV cache #4966
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#4966
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/4232
Author: @qwertie
Created: 10/26/2026
Status: 🔄 Open
Base:
main← Head:api-monitor-context📝 Commits (1)
ea2e453API monitor: show the tokens held in the engine's KV cache📊 Changes
10 files changed (+463 additions, -17 deletions)
View changed files
📝
SECURITY.md(+2 -2)📝
docs/DETAILS.md(+36 -2)📝
serve/server.py(+144 -11)📝
serve/test_monitor.py(+129 -1)📝
serve/test_parallel.py(+35 -0)📝
serve/web/app.css(+3 -0)📝
serve/web/app.js(+1 -0)📝
serve/web/index.html(+5 -1)📝
serve/web/monitor.html(+5 -0)📝
serve/web/monitor.js(+103 -0)📄 Description
Problem and result
The API monitor shows each request's body, output and reasoning, but there is no way to view entire context windows, or to see the requests in the form the model sees them.
This PR lets users see, for each slot in VRAM, the raw tokens the engine holds in its KV caches. Seeing them answers questions the request bodies can't. For example,
<|im_start|>system Reasoning effort is set to xhigh..., which is a bad practice because it forces a change of effort to re-read the whole conversation (unless"effort_position": "end"is set).This PR adds a Context in VRAM panel to
/api-monitor, so it's on only with"api_monitor": trueand nothing changes otherwise:The main page links to the monitor (Sampling panel, Monitor tab) only when it is on.
/healthadds"api_monitor": trueonly then, so its default answer is unchanged.Related discussion
none
Approach by Opus 5.5
The engine has no command that returns its cache, so the server mirrors it from what it sends and reads. Every
GENcarries the whole prompt, so afterwards the cache holds the prompt plus every printed token except the last, which is never fed back. I checked the rules againstgenerate.cpp,q36_engine.cuandds4_main.cpp:STOPcount too. DeepSeek's engine has also fed its last printed token when it honours aSTOP(stop_feeds_last).ERRkeeps the previous list. A stop while the prompt is being read, a restored disk session, non-finite logits, or a lost engine make the list unknown, and the panel says why.--batch, a request that is alone runs on the solo path.generate.cppreads every admission in its own session before copying it into a slot, so that session is listed next to the slots: three sessions with--batch 2. The Qwen3.6 path has no session of its own (own_solo_session).Colours: a fixed, seeded palette of 4,096 per theme, sampled evenly by OKLab volume over the colours that keep 7:1 contrast with the theme's text. A hash of the id picks the colour, so muted colours, which take up less of that space, come up less often. The page builds the palette once (about 5 ms) and gives each span both themes' colours. The coloured view is paged because painting 150K spans into one
<pre>froze the tab.Compatibility: with the monitor off, request handling is unchanged apart from keeping this list of ids per request (one list copy of the prompt, next to the comma-joined prompt the server already builds).
Validation
Passed:
python -m unittest discover -s serve -t . -p "test_*.py"on c70189fa, Windows 11, Python 3.14.6: 1048 tests OK (21 skipped). This includes the new tests: the end-of-request rules (prompt and all but the last token, tokens drained after a STOP, DeepSeek's STOP, a stop while the prompt is read, ERR, non-finite logits), the endpoint and its key check, per-token text with a character split across tokens, and with a fake--batchengine a lone request in the solo session and two at once in the slots.node --check serve/web/monitor.js serve/web/app.json c70189fa."parallel": 2, with Codex and Claude Code as clients. Run on this branch's server code: the later commits change onlymonitor.html,monitor.jsand the docs. The panel showed the solo session after a lone request, including a sub-agent's conversation while its parent waited (both slots empty), and the full history after a client-side compaction. The colored view of a 150K-token cache: 517 ms to the first page, 58 ms per page change (a Chromium-based browser).Failed:
none observed
Not run:
stop_feeds_last,own_solo_session); the tests use stub engines.Limits
The list is the server's mirror, not a dump of the GPU's memory. Where it differs (also in docs/DETAILS.md):
<|im_end|>\n<|endoftext|>already in the cache.--batchslot in use shows its list when its request ends.Showing these exactly needs engine commands that list the sessions and the parked conversations. A working version of that exists; it changes the engine, so it would go through an issue before a PR.
🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.