[Bugfix][Rust Frontend] Always include token_ids in completion stream choices by devshah-cohere · Pull Request #60286 · vllm-project/vllm · GitHub
Skip to content

[Bugfix][Rust Frontend] Always include token_ids in completion stream choices - #60286

Merged
BugenZhao merged 2 commits into
vllm-project:mainfrom
devshah-cohere:devshah/fix-rust-completion-stream-token-ids
Oct 8, 2026
Merged

BugenZhao merged 2 commits into
vllm-project:mainfrom
devshah-cohere:devshah/fix-rust-completion-stream-token-ids

Conversation

@devshah-cohere

@devshah-cohere devshah-cohere commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Overview

Ensure the Rust /v1/completions stream includes token_ids on every choice when return_token_ids=true.

Claims

  • Prompt chunks serialize token_ids: [] alongside prompt_token_ids.
  • Generated-token chunks preserve their actual token IDs.
  • Terminal chunks serialize token_ids: [].
  • Requests with return_token_ids=false are unchanged.

Validation

  • Manually verified the affected streaming behavior with return_token_ids=true.

  • Added completion_stream_serializes_requested_token_ids_on_every_choice, which serializes the prompt, generated-token, and terminal chunks and asserts their exact token_ids values.

  • The regression test is covered by the existing Rust Frontend Cargo CI for changes under rust/.

  • Focused pre-commit checks passed:

    pre-commit run --files rust/src/server/src/routes/openai/completions.rs
  • Rust formatting passed locally in a Rust 1.95 container:

    cargo fmt --manifest-path rust/Cargo.toml --all -- --check
  • The targeted regression test passed locally in a Rust 1.95 container:

    cargo test --manifest-path rust/Cargo.toml -p vllm-server \
      completion_stream_serializes_requested_token_ids_on_every_choice

Details

CompletionStreamChoice skips fields whose value is None. Generated deltas already populated token_ids, but prompt and terminal choices left the field as None, so it disappeared from serialized responses even when requested.

The Python frontend already enforces this contract in OpenAIServingCompletion.completion_stream_generator: every emitted CompletionResponseStreamChoice sets token_ids to as_list(output.token_ids) whenever return_token_ids is enabled. This explicitly supplies a list, including an empty list, instead of leaving the optional field unset. The Rust frontend only set the field on generated-token chunks, so prompt and terminal choices omitted it.

The existing stream-yield path now fills only missing token_ids values with an empty list when return_token_ids is enabled. Centralizing this at emission covers every completion choice while preserving real IDs already attached to generated-token chunks. The only payload change is an empty list on opt-in prompt and terminal chunks; no dependencies or public request fields change.


Pull Request Checklist
  • I used vLLM's /pr-checklist skill. (Mandatory for agents, optional for humans).

  • AI assistance was used during the creation of this PR.

  • Design Fit: Minimizes impact on core components, reuses existing functionality, and justifies added complexity.

  • Testing and Validation: Validates the change and ensures any added tests are meaningful and reliable, with CI coverage or documented CI resource constraints and validation performed outside CI.

  • Code Quality and Style: Keeps code and comments clear and concise, and updates relevant documentation and examples.

  • Pull Request Contents: Includes a brief summary and relevant links, supports claims with evidence, explains root causes and implementation trade-offs, and follows the contributing guide.

@mergify mergify Bot added rust bug Something isn't working labels Oct 6, 2026
@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown

Signed-off-by: devshah-cohere <dev.shah@cohere.com>
@devshah-cohere
devshah-cohere force-pushed the devshah/fix-rust-completion-stream-token-ids branch from 402e127 to 5435597 Compare October 6, 2026 19:31
@devshah-cohere
devshah-cohere marked this pull request as ready for review October 6, 2026 21:45

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@BugenZhao BugenZhao changed the title [Bugfix] Always include token_ids in completion stream choices [Bugfix][Rust Frontend] Always include token_ids in completion stream choices Oct 8, 2026
@BugenZhao BugenZhao added the ready ONLY add when PR is ready to merge/full CI is needed label Oct 8, 2026

@BugenZhao BugenZhao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown

✅ @devshah-cohere, CI is now available for this PR.

  • /ci run starts upstream CI; /amd-ci run starts AMD CI only.
  • Your branch must contain every commit currently on its upstream target branch. Merge or rebase onto the latest target branch, then rerun the command. Append --allow-stale to a run command to test an outdated branch at your own risk.
  • /ci retry retries failed jobs in the CI build for the current PR head. If the current head has no CI build, it starts a new CI build for the current head containing only jobs that failed in the latest earlier CI build for this PR.
  • /amd-ci retry retries failed jobs in AMD CI for the current PR head. Use /amd-ci run when the current head has no AMD CI build.
  • /ci cancel cancels scheduled or running CI builds for this PR branch; /amd-ci cancel does the same for AMD CI only.

@BugenZhao

Copy link
Copy Markdown
Member

/ci run

@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown

@BugenZhao
BugenZhao merged commit b49c921 into vllm-project:main Oct 8, 2026
31 checks passed
michael-gpu pushed a commit to practical-inference/vllm-ampere-extended that referenced this pull request Oct 20, 2026
… choices (vllm-project#60286)

Co-authored-by: Bugen Zhao <i@bugenzhao.com>
Signed-off-by: devshah-cohere <dev.shah@cohere.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ready ONLY add when PR is ready to merge/full CI is needed rust

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants