Skip to content

fix(router): carry the worker's true generated-token count over the disaggregated wire protocol #387

Closed

Description

@inureyes

Problem

The disaggregated router (src/server/router_front.rs) derives completion_tokens (and the chat equivalent) by counting emitted text frames: one increment per ResultFrame text entry in the per-request on_token callback. This equals the worker's true generated-token count for byte-level-BPE tokenizers (e.g. Qwen), but can UNDER-COUNT for byte-fallback tokenizers (e.g. Gemma, which emit multi-frame <0xXX> byte sequences for a single token, or where one model token maps to multiple emitted text pieces).

Because finish_reason is computed as completion_tokens >= max_tokens ? "length" : "stop" (matching src/server/model_worker.rs ~line 1401), an under-count can also flip the reported finish_reason between "length" and "stop", and makes the router's usage diverge from the single-node /v1/completions and /v1/chat/completions responses for those tokenizers.

Scope / why it is a separate issue

PR #386 intentionally kept byte-identity for byte-level-BPE tokenizers (validated via the disaggregated_router_completions_match_single_node E2E test on qwen3-0.6b-4bit) and documented this limitation rather than expanding scope. A correct fix requires extending the disaggregated serving wire protocol to carry the worker's authoritative generated-token count (and likely the worker-computed finish_reason) from the decode node to the router, which touches src/distributed/disaggregated/serving_protocol.rs plus both the prefill and decode emit paths and the router demux. That is a protocol change, separate from the byte-parity feature PR (one PR, one logical change).

Proposed direction

Add the worker's true generated-token count (and optionally its finish_reason) to the result/serving protocol frames, and have the router use those authoritative values for usage.completion_tokens / finish_reason instead of frame-counting. Then extend the E2E parity test to a byte-fallback tokenizer (e.g. a small Gemma checkpoint) to assert usage + finish_reason parity with single-node.

Acceptance Criteria

  • The router's usage.completion_tokens and finish_reason for /v1/completions and /v1/chat/completions match single-node for a byte-fallback tokenizer (e.g. Gemma), not just byte-level-BPE.
  • The disaggregated wire protocol carries the worker's authoritative token count.
  • An E2E test asserts the parity on a byte-fallback tokenizer.

References

Activity

  1. added
    type:bug
    area:architecture
    priority:low
    status:backlog
    status:in-progress
    status:review
    status:done
    and removed
    status:backlog
    status:in-progress
    status:review
    on Jun 21, 2026
  2. added a commit that references this issue on Jun 21, 2026
    455ed8d
  3. self-assigned this
    on Jun 25, 2026
  4. added 2 commits that reference this issue on Oct 27, 2026
    96fad96
    53e8273
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:architecturepriority:lowstatus:donetype:bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions