Repository navigation
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
Open
AgentSparko wants to merge 2 commits into
AgentSparko wants to merge 2 commits into
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
nullforits live rates. The same page on the engine itself is alive.
Root cause
The Performance page reads
decode_live_now_tps/decode_live_avg_tpsfrom thein-flight rows and
decode_live_tps/prefill_live_tpsfrom the live stream's samplering (
dashboard/dist/assets/app-*.js). All four come off the engine's decode loop:LiveRegistrysamplesBlockStatsand the per-request token ring (tandemapp/live.py).The controller has no decode loop to sample —
proxy/app.pybuilds its registry withblocks=lambda: None, activity=False, and a relayed record counts frames, not tokens(
proxy/measure.py:trackis never used,decode_anchoris never set). So the proxy'slive 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 enabledtandemllmbackendreads the engine's own
/v1/dashboard/liveSSE (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
nowblock, its newest sample and its engine block. Asupervisor thread syncs the subscribers with the backend table; reconnects back off
1/2/5/10/30 s. Started from
app.buildunlessTANDEM_LIVE_RELAY=off; stopped with theservice.
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 isits 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 afterread_frame;_finishstill writes the final value), so a relayed row joins to itsengine row from its first frame on. The engine's
phaseis 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.
header at stream open (
X-Tandem-Request-Id).proxy/relay.pyreads it from theupstream headers before the pump starts and stamps
rec.upstream_requestfrom it, sothe row joins through the whole prefill. The first-frame stamp stays as the fallback
for an engine that sends no header, and
_finishno longer overwrites a stamped idwith null when a stream dies before its first frame.
token,
LiveRelay.sole_prefill(backend)answers with the prefill figures of thebackend'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.prefillones, named asthe proxy's row carries them:
prefill_live_tps(its live rate over the chunk marks),prefill_elapsed_msandprefill_eta_ms.proxy/app.py'senrichhook applies therule; the module docstring states it.
tandemapp/live.py, two additive providers, default None.enrich(rec) -> dictismerged into each in-flight row;
live_rates() -> dictfills the nulls of the historysample and of
now(decode_tps/prefill_tps/decode_live_tps/prefill_live_tps). A hook that raises never costs the tick its row. The enginebuilds 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 neitherprovider; with
enrich=None, live_rates=Noneevery code path is the old one.The controller's engine block (
_live_engine) gains the model, the KV window, thememory 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):The prefill tests drive the controller's own
enrichhook (proxy/app.py _live_enrich): the header stamp is proven end to end through a real controller and afake engine that answers with
X-Tandem-Request-Idand 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:
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 streamedrequest with a ~10k-token prompt and
max_tokens: 30, its live stream captured duringthe prefill (full SSE in
.wip/prefill-proof.sse, 40 events). The engine was carryingother 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 — thefigures joined while
ttft_mswas still null.)Caveats
tokensstays the controller's frame count (0 mid-stream —pre-existing); only the named rate fields are merged.
decode_tps(its sample ring andnow) reads 0.0 while a relaystreams — 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.
only when the response arrives.
engines the rates are one engine's, named by its model.
the backend's key from the config store, the same header the chat-engine pass-through
uses.
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 isnever consulted.
Pairs with the engine-side PR: TandemLLM/TandemEngine#178 — the controller reads
X-Tandem-Request-Idwhen an engine sends it (exact prefill join) and falls back to the sole-prefill heuristic otherwise. The two land together.