mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[GH-ISSUE #5448] [Engine] serve: an asked include_usage never gets the usage chunk of its own; spec-following clients count 0 tokens #3256
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#3256
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?
Originally created by @wornet-che on GitHub (Nov 7, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/5448
Problem: a streamed completion asked for stream_options.include_usage never gets
OpenAI's final usage chunk of its own. The usage rides on the finish chunk, whose
choices stay filled (delta {}, finish_reason stop). The contract's last chunk carries
empty choices with the usage block, and llama.cpp's server answers that way. A client
that reads usage from that chunk - the shape the OpenAI docs and llama.cpp clients
expect - sees no usage at all and falls back to estimating.
Environment: Strata 0.2.10 (commit
ffa80d73, engine 0.1.56) and current main(
9f7d977d), Linux x86_64. The serving engines run strata withQwen3.8-Flash-Next IQ3_S, 262k context. The repro needs no GPU and no model - it
uses the repository's own mock engine.
Reproduce (no GPU, about ten seconds):
Expected: the second-to-last event is a chunk with "choices": [] carrying the usage
block - OpenAI's streaming contract, as llama.cpp serves it.
Actual: no choice-less chunk is ever sent. Observed tail (
ffa80d73, mock engine,shortened):
Effect on us, measured on two serving hosts: a gateway that counts completion tokens
only from the spec chunk (ours injects include_usage towards the host
and drops the chunk again for clients that did not ask) accounts every stream from
its character estimate instead. Tool-call-only turns - most of an agent's turns -
carry no content characters, and the estimate gives 0. In a 24 h window, 204 of 310
completion rows for this model logged completion_tokens 0 while the engine's own
DONE lines reported roughly 100 to 1300 generated tokens each; the per-model speed
column fell to about 2 tok/s against a real 40-45 tok/s decode. With a local eight-
line patch that adds the spec chunk, the same gateway logs exact prompt and completion
counts on every row and its usage-reported flag flips.
Reproduction status: reproduced locally - mock engine at two revisions, live serve
on two hosts.
@wornet-che commented on GitHub (Nov 7, 2026):
PR #5450 carries exactly our tested workaround, with the measurements from this issue.
@bahooo22 commented on GitHub (Nov 7, 2026):
Confirmed on this fork's serve (engine 0.1.56, Windows 11, RTX 3060 Ti 8 GiB, qwen35moe KAT
IQ4_XS,
stream=true,stream_options.include_usage=true): 10 SSEdata:frames — the first 9carry
choices=[{..., finish_reason: null}]and no usage, the last carriesfinish_reason=lengthWITH the usage block. There is no final frame with
choices=[]and usage, i.e. the shape theOpenAI docs and llama.cpp clients read; a client that takes usage only from that empty-choices
frame sees none and estimates.
Repro: any streamed request with
{"stream": true, "stream_options": {"include_usage": true}};inspect the last
data:frame —choicesstays filled.