Skip to content

Live view: the controller carries its engines' live figures; the Performance page was empty behind it - #1

Open
AgentSparko wants to merge 2 commits into
TandemLLM:mainfrom
AgentSparko:fix/proxy-live-speed-relay
Open

AgentSparko wants to merge 2 commits into
TandemLLM:mainfrom
AgentSparko:fix/proxy-live-speed-relay

Conversation

@AgentSparko

@AgentSparko AgentSparko commented Nov 20, 2026 •

Copy link
Copy Markdown

Live view: the controller carries its engines' live figures — the Performance page was empty behind it

The problem

With the App in front of a TandemLLM engine, the dashboard's Performance page charts
decode and prefill speed stay empty, and every in-flight request row reads null for
its live rates. The same page on the engine itself is alive.

Root cause

The Performance page reads decode_live_now_tps / decode_live_avg_tps from the
in-flight rows and decode_live_tps / prefill_live_tps from the live stream's sample
ring (dashboard/dist/assets/app-*.js). All four come off the engine's decode loop:
LiveRegistry samples BlockStats and the per-request token ring (tandemapp/live.py).
The controller has no decode loop to sample — proxy/app.py builds its registry with
blocks=lambda: None, activity=False, and a relayed record counts frames, not tokens
(proxy/measure.py: track is never used, decode_anchor is never set). So the proxy's
live stream carried the requests (arrival, first frame, frames — all real) but no speed
figures, and the charts had nothing to plot.

The fix

proxy/liverelay.py (new). One subscriber thread per enabled tandemllm backend
reads the engine's own /v1/dashboard/live SSE (the same stream the dashboard reads,
with the backend's key when it has one) and keeps, fresh for 5 s: the in-flight rows by
engine request id, the engine's now block, its newest sample and its engine block. A
supervisor thread syncs the subscribers with the backend table; reconnects back off
1/2/5/10/30 s. Started from app.build unless TANDEM_LIVE_RELAY=off; stopped with the
service.

The join. The engine keys its live rows by its request id — which is the id its
answer carries (Stamps.response_id, already documented as SRV-733: "our engine's is
its ledger row's request_id"). The relay now stamps that id onto the record while the
stream runs (proxy/relay.py, one additive line in the pump loop right after
read_frame; _finish still writes the final value), so a relayed row joins to its
engine row from its first frame on. The engine's phase is deliberately not carried —
the row keeps the phase the controller's own stamps say.

The prefill phase. Until now a request still waiting for its first token had no id
to join with and its row stayed exactly what the controller measured — the Performance
page showed a prefilling row with no figures. Two additions, one rule: exact when the
header is there, heuristic only when unambiguous, null otherwise.

  • Exact: the sibling TandemEngine PR puts the engine's live request id in the response
    header at stream open (X-Tandem-Request-Id). proxy/relay.py reads it from the
    upstream headers before the pump starts and stamps rec.upstream_request from it, so
    the row joins through the whole prefill. The first-frame stamp stays as the fallback
    for an engine that sends no header, and _finish no longer overwrites a stamped id
    with null when a stream dies before its first frame.
  • Heuristic (old engines): while a relayed request has no answer id yet and no first
    token, LiveRelay.sole_prefill(backend) answers with the prefill figures of the
    backend's live rows only when exactly one prefill row is open — then it can only
    be this request's. Two prefill rows is ambiguous and the row stays null; the relay
    never guesses. The figures carried are the engine's activity.prefill ones, named as
    the proxy's row carries them: prefill_live_tps (its live rate over the chunk marks),
    prefill_elapsed_ms and prefill_eta_ms. proxy/app.py's enrich hook applies the
    rule; the module docstring states it.

tandemapp/live.py, two additive providers, default None. enrich(rec) -> dict is
merged into each in-flight row; live_rates() -> dict fills the nulls of the history
sample and of now (decode_tps / prefill_tps / decode_live_tps /
prefill_live_tps). A hook that raises never costs the tick its row. The engine
builds its registry without them, so the engine-side payload is byte-identical
— the
engine keeps its own mirror of this module (server/api/live.py) and passes neither
provider; with enrich=None, live_rates=None every code path is the old one.

The controller's engine block (_live_engine) gains the model, the KV window, the
memory and the store of the engine behind it — what only the engine knows.

Whole-engine figures (rates, engine block) come from one backend: the default one when
it is a fresh TandemLLM backend, else the freshest; per-request rows join exactly, each
to the engine that answered it. Documented in the module docstring.

Test evidence

New standalone test (house idiom: run() + prints + exit code):

$ python3 tests/test_proxy_liverelay.py
  test_hooks_default_off_and_a_raising_hook_costs_nothing          ok
  test_no_join_no_enrichment                                       ok
  test_reconnect_after_the_engine_drops_the_stream                 ok
  test_relayed_row_carries_the_engine_rates_and_goes_stale         ok
  test_the_header_join_wins_over_the_heuristic                     ok
  test_the_header_stamps_the_join_before_the_first_frame           ok
  test_the_sole_prefill_row_joins_a_request_still_prefilling       ok
  test_two_prefill_rows_are_ambiguous_and_stay_null                ok
8 passed in 10.0 s

The prefill tests drive the controller's own enrich hook (proxy/app.py _live_enrich): the header stamp is proven end to end through a real controller and a
fake engine that answers with X-Tandem-Request-Id and holds its first frame for 2 s —
with two prefill rows open on the engine, so the figure the row shows before the first
frame can only come from the header. The heuristic is proven with one prefill row
(joins), with two (stays null), and with a header-stamped id the engine has no row for
(stays null: exact join missed, never guess).

Existing suites over the touched wiring, all green:

tests/test_live.py            30 passed   (LiveRegistry, hooks default off)
tests/test_parallel.py         9 passed
tests/test_proxy_relay.py     13 passed   (the pump loop, byte-identical streams)
tests/test_proxy_messages.py  22 passed

Live proof — a throwaway controller on 127.0.0.1:8081 (fresh state dir) in front of a
live engine, one streamed chat request through it, its live stream captured during
generation (full SSE in .wip/live-proof.sse, 60 events, 4 enriched decode rows).
Excerpt of one event mid-decode:

{"seq": 57,
 "row": {"request_id": "chatcmpl-px-b383ee98041946ab83d609ee", "phase": "decode",
         "decode_live_now_tps": 53.77, "decode_live_avg_tps": 53.77,
         "decode_warmup": {"tokens": 119, "reached": true},
         "model": "spark-brain", "backend": "engine",
         "ttft_ms": 239.41, "elapsed_ms": 2510.96},
 "now": {"decode_live_tps": 53.77, "prefill_tps": 4510.0, "prefill_live_tps": null},
 "sample": {"decode_live_tps": 55.74, "prefill_tps": 4510.0, "running": 1},
 "engine": {"model": "qwen3.8-flash03.05", "version": "0.16.0",
            "kv": {"length": 1146, "max_len": 262144},
            "memory": {"mem_available_gib": 10.1, "rss_gib": 12.5}}}

Before the fix the same row read decode_live_now_tps: null, now.decode_live_tps: null, sample.decode_live_tps: null, engine.model: null.

Prefill proof — the same throwaway controller in front of the live engine (which does
not yet send X-Tandem-Request-Id, so this is the heuristic path), one streamed
request with a ~10k-token prompt and max_tokens: 30, its live stream captured during
the prefill (full SSE in .wip/prefill-proof.sse, 40 events). The engine was carrying
other traffic at the same time, which shows the never-guess rule working: the prefill
ticks at seq 14–20 read prefill_live_tps: null (another request was prefilling too —
two rows could be it), and the figures appear at seq 21, ~2 s before the first token,
once the other prefill finished and this one was the only row open:

{"seq": 21,
 "row": {"request_id": "chatcmpl-px-f4d011ecdf55433c994dfa61", "phase": "prefill",
         "prefill_live_tps": 1197.21, "prefill_elapsed_ms": 6868.3,
         "prefill_eta_ms": 1458.4, "ttft_ms": null, "decode_live_now_tps": null,
         "model": "qwen3.8-flash03.05", "backend": "engine",
         "elapsed_ms": 7948.47}}

(The engine's ledger row for it: ttft_ms: 8517.4, prompt 9938, completion 30 — the
figures joined while ttft_ms was still null.)

Caveats

  • A relayed row's own tokens stays the controller's frame count (0 mid-stream —
    pre-existing); only the named rate fields are merged.
  • The controller's own decode_tps (its sample ring and now) reads 0.0 while a relay
    streams — pre-existing (it counts tokens it never sees), and 0.0 is not null, so the
    fill leaves it. The live series the Performance charts plot are the filled ones.
  • Non-streamed relayed requests get no in-flight enrichment: their answer id exists
    only when the response arrives.
  • Whole-engine figures come from one engine (default, else freshest); with several
    engines the rates are one engine's, named by its model.
  • If the engine live stream needs a key (a backend key is set), the subscriber sends
    the backend's key from the config store, the same header the chat-engine pass-through
    uses.
  • The prefill heuristic shows the engine's one running prefill's figures: if the
    controller's own request is still queued behind it on the engine, the rate shown is
    the prefill the engine is running now. It is a heuristic only for engines that send
    no X-Tandem-Request-Id; with the header the join is exact and the heuristic is
    never consulted.

Pairs with the engine-side PR: TandemLLM/TandemEngine#178 — the controller reads X-Tandem-Request-Id when an engine sends it (exact prefill join) and falls back to the sole-prefill heuristic otherwise. The two land together.

…ormance page was empty behind it

The Performance page reads decode_live_now_tps and decode_live_avg_tps
from the in-flight rows and decode_live_tps / prefill_live_tps from the
live stream's sample ring. Those come off the engine's decode loop, and
the controller has none: its LiveRegistry is built with blocks=None,
activity=False, so behind a TandemLLM backend the charts were empty and
every in-flight row read null.

proxy/liverelay.py subscribes to each enabled tandemllm backend's
/v1/dashboard/live and keeps its rows, its `now`, its newest sample and
its engine block fresh for 5 s. The join is the answer's own id: the
engine keys its live rows by its request id, which is the id its answer
carries (Stamps.response_id, SRV-733), so the relay stamps it onto the
record while the stream runs (proxy/relay.py) and the row joins to the
engine's from its first frame on. LiveRegistry takes two additive
providers, default None: `enrich` merges a dict into each in-flight row
and `live_rates` fills the nulls of the history sample and of `now`;
the engine builds its registry without them, so its payload is
byte-identical. The controller's engine block gains the model, the KV
window and the memory of the engine behind it. TANDEM_LIVE_RELAY=off
leaves the live view exactly as it was. tests/test_proxy_liverelay.py
drives a fake engine stream: enrichment, the join miss, the TTL, the
reconnect, and the hooks-off build.
…n; the one prefill row joins when there is no id to join with

The prefill-phase rows could not join: the engine's id reached the controller
only with the first streamed frame, after the prefill had ended, and the
Performance page showed a running prefill with no figures.

proxy/relay.py reads `X-Tandem-Request-Id` (the sibling TandemEngine PR names
the engine's live request id in the response header at stream open) from the
upstream headers before the pump starts and stamps it onto the record: the
join is exact through the whole prefill. The first-frame stamp stays the
fallback for an engine that sends no header, and `_finish` no longer writes
null over a stamped id when a stream dies before its first frame.

For old engines proxy/liverelay.py adds `sole_prefill`: the prefill figures of
the backend's live rows (its `activity.prefill` live rate, elapsed and ETA,
carried as `prefill_live_tps`, `prefill_elapsed_ms`, `prefill_eta_ms`) — but
only when exactly one prefill row is open on that backend, when it can only be
this request's. Two is ambiguous and the row stays exactly what the controller
measured. proxy/app.py's enrich hook applies the rule, stated in the module
docstring: exact when the header is there, heuristic only when unambiguous,
null otherwise.

tests/test_proxy_liverelay.py drives the controller's own enrich hook: the
header stamp end to end through a real controller and a fake engine that holds
its first frame for 2 s with two prefill rows open (the figure can only come
from the header), the heuristic with one row (joins), with two (null), and with
a header-stamped id the engine has no row for (null: never guess). Live proof:
a throwaway controller in front of the live engine (no header yet — the
heuristic path), one ~10k-token prefill; the figures appear on the
phase=prefill row ~2 s before the first token, and the ticks with a concurrent
engine prefill correctly read null.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant