[PR #4636] [GUI] Monitor: KV context ring with a legend lamp that follows the Model-state badges #5124

Open
opened 2026-11-07 16:32:53 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4636
Author: @thisisspartan
Created: 10/29/2026
Status: 🔄 Open

Base: main ← Head: feat/kv-monitor-full


📝 Commits (5)

  • f41400e Monitor: KV context donut with a state legend lamp; live.reused reports the resumed prefix
  • 246ab4e webtest: drive the Context ring lamp, kvTokens geometry and a chronological /metrics stream through the served page
  • 6f6f592 Monitor UI: keep only one-line why-comments in the KV ring code; add legend tone threshold cases (85% warn, 84.9% none, 90% warn) to the browser test
  • 0fa4cd1 Monitor UI: drop the unmeasured AA-readable claim from the legend dim-row comment
  • cb62a6d Monitor: scope the Context ring to the serving engine's telemetry

📊 Changes

10 files changed (+569 additions, -26 deletions)

View changed files

📝 serve/replicas.py (+29 -2)
📝 serve/server.py (+14 -0)
📝 serve/split.py (+7 -1)
📝 serve/test_replicas.py (+48 -0)
📝 serve/test_server.py (+107 -0)
📝 serve/test_split.py (+20 -0)
📝 serve/web/app.css (+35 -6)
📝 serve/web/app.js (+64 -10)
📝 serve/web/index.html (+22 -7)
📝 tools/webtest/browser_test.mjs (+223 -0)

📄 Description

Problem and result

While a request runs, the Monitor's Context card shows one number -- used / window. Nothing about a
prompt that reuses a cached prefix is visible during the request: how much of the prompt was served
from cache, how many tokens are being read now, how much was generated, and how much headroom is
left. Reuse appears only after the request finishes, in the Reused column.

After this change the Context card is a four-arc ring -- Cached (prefix), Reading (prefill),
Generating (decode), Free -- whose legend rows carry the token counts, plus a legend lamp: exactly
one legend row is lit. The lamp follows the effective state key used by renderMonitor: when no
local load/unload operation is active and live.queued > 0 the key is queued, otherwise
live.state; the key maps reading to Prefill, generating to Decode, and every other value
(including queued) to Free. The Cached legend row is never selected. The center keeps the exact
usage figure and percent; a warn tone starts at 85 % of the window and the danger tone applies only
on a real overflow against a known window. The cached arc is live during the request because
/metrics now carries reused for the running request (additive live.reused line; previously
that counter existed only in finished-request records).

The four ring numbers are request-scoped and must not mix one request's telemetry with another's. A
review of the first head found three places where they could: the replica progress/rate fell back to
the first replica reporting a value even after that request had finished, the split-serve hand-over
briefly exposed the decode engine's stale last request, and the idle Cached arc was drawn from the
last finished record without checking whether the engine had restarted since (after a restart the KV
cache is gone). The final head closes these:

  • serve/replicas.py reads progress/prefill_tok_s_mean only from a replica with a request in
    flight, and reports gen as None on the status thread instead of replica 0's.
  • serve/split.py keeps cur on the prefill engine through the decode engine's session restore.
  • serve/server.py parses RESUME n so a batch admission reports its real reused count, and marks
    the engine generation on /metrics and on history records.
  • serve/web/app.js clears the idle Context arc when the record's generation predates the engine's.

Scope

The ring, the legend lamp, the live reused field, and the telemetry-scoping correction -- nothing
else. The in-flight request row, the speed card and the mtp_acc draft-acceptance metric are out of
scope; if they are wanted they will be proposed separately after maintainer feedback. The diff is 10
files, +569/-26 against main, all in serve/ and tools/webtest/. Existing behavior is untouched:
the native basement bars, the request table and every other card stay as they were.

This narrows #4636 to the items above. The earlier wide draft of this branch (head
a2610a1d45c2d71e8a73dc752047738cfa7b2480) is marked Superseded in my 2026-10-31 comment on this PR.
#4297 proposed this four-segment context donut with percent and token counts; it has had no
maintainer response yet (open, 0 comments). The telemetry-scoping correction addresses a self-review
finding and needs no separate issue. Full raw validation logs for the first head, the complete run
table and the red-demo runs are in the comment
https://github.com/Niko1221/Strata/pull/4636#issuecomment-6587766382

Approach

All arcs draw from data the engine already produces: prompt_tokens, prompt_read, generated,
and the request's reused (the same source as the Reused column). serve/server.py adds one
additive reused field to the live request entry, and both the live entry and finished records gain
a gen field carrying the engine process generation. Attribution in the normal case follows the
active request: the value is the prefix-cache counter of the engine currently serving it -- with a
single engine holding one request in flight, that is the request whose state is displayed; under
split serve, serve/split.py reports it from cur, the prefill side during prefill and the decode
side during decode, and cur stays on the prefill side through the decode engine's session restore.
With several concurrent replicas the /metrics handler runs without a request-local view, and
serve/replicas.py reads the running counters only from a replica with a request in flight, so a
finished replica's stale value can no longer leak into the ring; the value still belongs to whichever
in-flight replica is read first, not necessarily to the request whose state is displayed -- Limits
states this caveat. The batch per-slot and split-serve decode-side attributions remain
runtime-unvalidated. The ring scales those four numbers to max_context; when used exceeds the
window the arcs scale down so the ring still represents the proportions, and the percent goes to the
danger tone. The idle Cached arc uses the last finished record only while its gen equals the
engine's current gen -- after a restart the record is older and the ring stays empty rather than
showing a cache that no longer exists. The lamp follows on, the same local value the card uses to
light its state badges in the same render pass. No new colors: arc colors are existing kit tokens, so
the ring follows the theme automatically. Existing test files gain additions only --
serve/test_server.py, serve/test_replicas.py, serve/test_split.py and
tools/webtest/browser_test.mjs; git diff upstream/main removes zero lines from them; #4297
expected the existing test files to stay untouched, this update does not meet that expectation.

Validation

Tested at cb62a6d6a2 on base c62d5e3a; Ubuntu 24.04.4 LTS,
Python 3.12.3, Node v22.22.3. Every command below exists in the repo.

Passed

  • node --check serve/web/app.js and node --check tools/webtest/browser_test.mjs -- clean.
  • python3 -m unittest serve.test_monitor serve.test_replicas serve.test_split -- Ran 65, OK.
  • python3 -m unittest serve.test_server -- Ran 363, OK.
  • Full suite python3 -m unittest $(ls serve/test_*.py | sed 's|/|.|g; s|\.py$||' | tr '\n' ' ')
    -- Ran 1308, OK (skipped=28); the same command on the unmodified base c62d5e3a ran 1303, OK
    (skipped=28) -- 5 added tests, no other failures.
  • The 5 new tests, explicit:
    python3 -m unittest serve.test_replicas.ReusedRouting.test_progress_is_read_from_the_replica_in_flight serve.test_replicas.ReusedRouting.test_prefill_rate_is_read_from_the_replica_in_flight serve.test_server.ControlLineReading.test_resume_line_sets_reused serve.test_server.EngineGenerationMarker.test_history_and_engine_carry_the_generation serve.test_split.Handover.test_cur_stays_on_the_prefill_engine_during_the_restore -- Ran 5, OK.
  • Standalone web tests node serve/test_web_history.js, node serve/test_web_i18n.js,
    node serve/test_web_math.js, node serve/test_web_preview.js -- 34 ok, 0 fail.
  • GitHub Actions CI on cb62a6d6, the submitted revision: title pass, Linux / runtime requirements only pass (8 m 22 s).

Failed

None observed.

Not run

  • Browser harness node tools/webtest/browser_test.mjs (documented in that file's header;
    WEBTEST_MODULES and CHROME_BIN point at the local puppeteer-core and Chromium) -- this
    environment has no Chromium/Chrome and no puppeteer-core, so it could not run on cb62a6d6. The
    ring-geometry, lamp-matrix and chronological-stream cases were validated 3/3 at the previous head
    0fa4cd12 (raw output in the comment linked above); this head changes none of that code except one
    added idle edge case, which is source-level only and not browser-run here.
  • Execution against a real model and GPU: the ring and lamp were verified with scripted /metrics
    only; live behavior on a running engine is not verified, including multi-replica reused
    attribution under concurrent load and batch per-slot attribution.
  • 28 skipped Python tests, same count on base and head (Pillow/anthropic/pack/DSV41/browser-part/
    Windows-only skips, none touched by this diff).
  • Hardware builds (CUDA/HIP/SYCL): the diff touches serve/ (Python) and tools/webtest/
    (JavaScript) only, no backend C++ files.

Limits

  • In multi-replica concurrent workloads, the live /metrics reused value is not guaranteed to belong
    to the request whose state is displayed. The current fallback selects the first in-flight replica
    reporting a non-zero value. Per-request DONE accounting is separate and unaffected. Batch per-slot
    attribution and split-serve decode-side reporting have not been validated.
  • The reused shown during a request comes from the engine's prefix-cache accounting; on a resumed
    session after a restart it reports the restored prefix.
  • The ring only updates while the Monitor tab is rendering; on a poll failure the card keeps its
    last state. The center percent is the exact usage figure and is not capped: on overflow it can
    read above 100 % (the previous gauge capped at 100 %).
  • The lamp follows the same local on value the state badges use in the same render pass, so Free
    is lit whenever Queued is lit -- also while a request is reading or generating (the queue outranks
    the state badge).
  • Contrast measured from the rendered page itself (headless Chromium getComputedStyle, WCAG 1.4.11
    ratio against the measured Context-card background). Arcs below the 3:1 graphical-object
    threshold: light theme -- decode 2.54:1, Cached 1.27:1, Free 1.00:1; dark theme -- Cached 1.31:1,
    Free 1.00:1. Every arc is additionally identified by its legend row and token count.
  • The 3 new browser cases add about 26 s to the browser suite (measured 1532 + 1216 + 23446 ms at
    0fa4cd12).

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/4636 **Author:** [@thisisspartan](https://github.com/thisisspartan) **Created:** 10/29/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `feat/kv-monitor-full` --- ### 📝 Commits (5) - [`f41400e`](https://github.com/Niko1221/Strata/commit/f41400ebe2ab4acedf78a1c792d09f3106b67994) Monitor: KV context donut with a state legend lamp; live.reused reports the resumed prefix - [`246ab4e`](https://github.com/Niko1221/Strata/commit/246ab4e78bf0eee2c5770863260c22f1cbc96b68) webtest: drive the Context ring lamp, kvTokens geometry and a chronological /metrics stream through the served page - [`6f6f592`](https://github.com/Niko1221/Strata/commit/6f6f5927bd4f4af21eec1dccfca6280d8fb455f9) Monitor UI: keep only one-line why-comments in the KV ring code; add legend tone threshold cases (85% warn, 84.9% none, 90% warn) to the browser test - [`0fa4cd1`](https://github.com/Niko1221/Strata/commit/0fa4cd12fcb1571dafface05016ff10188ada0c8) Monitor UI: drop the unmeasured AA-readable claim from the legend dim-row comment - [`cb62a6d`](https://github.com/Niko1221/Strata/commit/cb62a6d6a24d09b387a514cf8fb7647d7bfd2296) Monitor: scope the Context ring to the serving engine's telemetry ### 📊 Changes **10 files changed** (+569 additions, -26 deletions) <details> <summary>View changed files</summary> 📝 `serve/replicas.py` (+29 -2) 📝 `serve/server.py` (+14 -0) 📝 `serve/split.py` (+7 -1) 📝 `serve/test_replicas.py` (+48 -0) 📝 `serve/test_server.py` (+107 -0) 📝 `serve/test_split.py` (+20 -0) 📝 `serve/web/app.css` (+35 -6) 📝 `serve/web/app.js` (+64 -10) 📝 `serve/web/index.html` (+22 -7) 📝 `tools/webtest/browser_test.mjs` (+223 -0) </details> ### 📄 Description ## Problem and result While a request runs, the Monitor's Context card shows one number -- used / window. Nothing about a prompt that reuses a cached prefix is visible during the request: how much of the prompt was served from cache, how many tokens are being read now, how much was generated, and how much headroom is left. Reuse appears only after the request finishes, in the Reused column. After this change the Context card is a four-arc ring -- Cached (prefix), Reading (prefill), Generating (decode), Free -- whose legend rows carry the token counts, plus a legend lamp: exactly one legend row is lit. The lamp follows the effective state key used by `renderMonitor`: when no local load/unload operation is active and `live.queued > 0` the key is `queued`, otherwise `live.state`; the key maps `reading` to Prefill, `generating` to Decode, and every other value (including `queued`) to Free. The Cached legend row is never selected. The center keeps the exact usage figure and percent; a warn tone starts at 85 % of the window and the danger tone applies only on a real overflow against a known window. The cached arc is live during the request because `/metrics` now carries `reused` for the running request (additive `live.reused` line; previously that counter existed only in finished-request records). The four ring numbers are request-scoped and must not mix one request's telemetry with another's. A review of the first head found three places where they could: the replica progress/rate fell back to the first replica reporting a value even after that request had finished, the split-serve hand-over briefly exposed the decode engine's stale last request, and the idle Cached arc was drawn from the last finished record without checking whether the engine had restarted since (after a restart the KV cache is gone). The final head closes these: - `serve/replicas.py` reads `progress`/`prefill_tok_s_mean` only from a replica with a request in flight, and reports `gen` as None on the status thread instead of replica 0's. - `serve/split.py` keeps `cur` on the prefill engine through the decode engine's session restore. - `serve/server.py` parses `RESUME n` so a batch admission reports its real reused count, and marks the engine generation on `/metrics` and on history records. - `serve/web/app.js` clears the idle Context arc when the record's generation predates the engine's. ## Scope The ring, the legend lamp, the live `reused` field, and the telemetry-scoping correction -- nothing else. The in-flight request row, the speed card and the `mtp_acc` draft-acceptance metric are out of scope; if they are wanted they will be proposed separately after maintainer feedback. The diff is 10 files, +569/-26 against `main`, all in `serve/` and `tools/webtest/`. Existing behavior is untouched: the native basement bars, the request table and every other card stay as they were. ## Related discussion This narrows #4636 to the items above. The earlier wide draft of this branch (head a2610a1d45c2d71e8a73dc752047738cfa7b2480) is marked Superseded in my 2026-10-31 comment on this PR. #4297 proposed this four-segment context donut with percent and token counts; it has had no maintainer response yet (open, 0 comments). The telemetry-scoping correction addresses a self-review finding and needs no separate issue. Full raw validation logs for the first head, the complete run table and the red-demo runs are in the comment https://github.com/Niko1221/Strata/pull/4636#issuecomment-6587766382 ## Approach All arcs draw from data the engine already produces: `prompt_tokens`, `prompt_read`, `generated`, and the request's `reused` (the same source as the Reused column). `serve/server.py` adds one additive `reused` field to the live request entry, and both the live entry and finished records gain a `gen` field carrying the engine process generation. Attribution in the normal case follows the active request: the value is the prefix-cache counter of the engine currently serving it -- with a single engine holding one request in flight, that is the request whose state is displayed; under split serve, `serve/split.py` reports it from `cur`, the prefill side during prefill and the decode side during decode, and `cur` stays on the prefill side through the decode engine's session restore. With several concurrent replicas the `/metrics` handler runs without a request-local view, and `serve/replicas.py` reads the running counters only from a replica with a request in flight, so a finished replica's stale value can no longer leak into the ring; the value still belongs to whichever in-flight replica is read first, not necessarily to the request whose state is displayed -- Limits states this caveat. The batch per-slot and split-serve decode-side attributions remain runtime-unvalidated. The ring scales those four numbers to `max_context`; when used exceeds the window the arcs scale down so the ring still represents the proportions, and the percent goes to the danger tone. The idle Cached arc uses the last finished record only while its `gen` equals the engine's current `gen` -- after a restart the record is older and the ring stays empty rather than showing a cache that no longer exists. The lamp follows `on`, the same local value the card uses to light its state badges in the same render pass. No new colors: arc colors are existing kit tokens, so the ring follows the theme automatically. Existing test files gain additions only -- `serve/test_server.py`, `serve/test_replicas.py`, `serve/test_split.py` and `tools/webtest/browser_test.mjs`; `git diff upstream/main` removes zero lines from them; #4297 expected the existing test files to stay untouched, this update does not meet that expectation. ## Validation Tested at cb62a6d6a24d09b387a514cf8fb7647d7bfd2296 on base c62d5e3a; Ubuntu 24.04.4 LTS, Python 3.12.3, Node v22.22.3. Every command below exists in the repo. **Passed** - `node --check serve/web/app.js` and `node --check tools/webtest/browser_test.mjs` -- clean. - `python3 -m unittest serve.test_monitor serve.test_replicas serve.test_split` -- Ran 65, OK. - `python3 -m unittest serve.test_server` -- Ran 363, OK. - Full suite `python3 -m unittest $(ls serve/test_*.py | sed 's|/|.|g; s|\.py$||' | tr '\n' ' ')` -- Ran 1308, OK (skipped=28); the same command on the unmodified base c62d5e3a ran 1303, OK (skipped=28) -- 5 added tests, no other failures. - The 5 new tests, explicit: `python3 -m unittest serve.test_replicas.ReusedRouting.test_progress_is_read_from_the_replica_in_flight serve.test_replicas.ReusedRouting.test_prefill_rate_is_read_from_the_replica_in_flight serve.test_server.ControlLineReading.test_resume_line_sets_reused serve.test_server.EngineGenerationMarker.test_history_and_engine_carry_the_generation serve.test_split.Handover.test_cur_stays_on_the_prefill_engine_during_the_restore` -- Ran 5, OK. - Standalone web tests `node serve/test_web_history.js`, `node serve/test_web_i18n.js`, `node serve/test_web_math.js`, `node serve/test_web_preview.js` -- 34 ok, 0 fail. - GitHub Actions CI on cb62a6d6, the submitted revision: `title` pass, `Linux / runtime requirements only` pass (8 m 22 s). **Failed** None observed. **Not run** - Browser harness `node tools/webtest/browser_test.mjs` (documented in that file's header; `WEBTEST_MODULES` and `CHROME_BIN` point at the local puppeteer-core and Chromium) -- this environment has no Chromium/Chrome and no puppeteer-core, so it could not run on cb62a6d6. The ring-geometry, lamp-matrix and chronological-stream cases were validated 3/3 at the previous head 0fa4cd12 (raw output in the comment linked above); this head changes none of that code except one added idle edge case, which is source-level only and not browser-run here. - Execution against a real model and GPU: the ring and lamp were verified with scripted `/metrics` only; live behavior on a running engine is not verified, including multi-replica `reused` attribution under concurrent load and batch per-slot attribution. - 28 skipped Python tests, same count on base and head (Pillow/anthropic/pack/DSV41/browser-part/ Windows-only skips, none touched by this diff). - Hardware builds (CUDA/HIP/SYCL): the diff touches `serve/` (Python) and `tools/webtest/` (JavaScript) only, no backend C++ files. ## Limits - In multi-replica concurrent workloads, the live /metrics reused value is not guaranteed to belong to the request whose state is displayed. The current fallback selects the first in-flight replica reporting a non-zero value. Per-request DONE accounting is separate and unaffected. Batch per-slot attribution and split-serve decode-side reporting have not been validated. - The `reused` shown during a request comes from the engine's prefix-cache accounting; on a resumed session after a restart it reports the restored prefix. - The ring only updates while the Monitor tab is rendering; on a poll failure the card keeps its last state. The center percent is the exact usage figure and is not capped: on overflow it can read above 100 % (the previous gauge capped at 100 %). - The lamp follows the same local `on` value the state badges use in the same render pass, so Free is lit whenever Queued is lit -- also while a request is reading or generating (the queue outranks the state badge). - Contrast measured from the rendered page itself (headless Chromium `getComputedStyle`, WCAG 1.4.11 ratio against the measured Context-card background). Arcs below the 3:1 graphical-object threshold: light theme -- decode 2.54:1, Cached 1.27:1, Free 1.00:1; dark theme -- Cached 1.31:1, Free 1.00:1. Every arc is additionally identified by its legend row and token count. - The 3 new browser cases add about 26 s to the browser suite (measured 1532 + 1216 + 23446 ms at 0fa4cd12). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#5124
No description provided.