Skip to content

[Rust Frontend] Accept duplicate reasoning aliases in chat messages - #63137

Merged
BugenZhao merged 4 commits into
vllm-project:mainfrom
world-executed:fix/rust-frontend-duplicate-reasoning-alias
Nov 2, 2026
Merged

BugenZhao merged 4 commits into
vllm-project:mainfrom
world-executed:fix/rust-frontend-duplicate-reasoning-alias

Conversation

@world-executed

@world-executed world-executed commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Overview

Fixes #63130: the Rust frontend rejected chat requests whose assistant message carries both reasoning and reasoning_content with an opaque serde duplicate field parse error, while the Python frontend accepts the identical body. This permanently breaks multi-turn agent loops because the offending assistant turn stays in history and every follow-up request fails.

The fix normalizes the reasoning aliases to the primary reasoning field in ChatMessage::deserialize before dispatching to the derived impl, mirroring the Python frontend's _normalize_messages_before (vllm/entrypoints/openai/chat_completion/protocol.py:556).

Claims

  • A chat request with an assistant message carrying reasoning + reasoning_content (in any key order, plus the thinking alias) is now accepted, matching the Python frontend's behavior matrix from the issue.
  • Non-null reasoning wins (including an empty string); a JSON-null reasoning falls back to reasoning_content, exactly mirroring the Python normalization semantics.
  • The thinking text is carried exactly once into the rendered assistant reasoning block.

Validation

Reproducer from the issue (both keys together) and the alias precedence matrix (key order, null and empty reasoning, wrong-type alias, thinking) are covered by one table-driven test at the deserialization layer, assistant_reasoning_aliases_fold_into_reasoning:

cargo test -p vllm-server --lib
# test result: ok. 504 passed; 0 failed

Regression proof: with the normalize_reasoning_aliases call removed, assistant_reasoning_aliases_fold_into_reasoning fails because alias values no longer reach reasoning; restored, all tests pass. cargo fmt --check and cargo clippy -p vllm-server --all-targets -- -D warnings are clean.

Details

Root cause. ChatMessage::Assistant declares reasoning with #[serde(alias = "reasoning_content")] / #[serde(alias = "thinking")]. Serde's derived Deserialize treats every key mapping to one field as a candidate and raises duplicate field when two of them appear, before any normalization can run. The Python frontend instead pops reasoning_content in a model_validator(mode="before") and fills reasoning only when it is absent/null, so the same payload is accepted there.

Fix. The manual Deserialize impl already materializes each message as a serde_json::Value for role dispatch; a small normalize_reasoning_aliases step runs on that value first (removes both alias keys, promotes the first non-null alias when reasoning is absent/null). Because it is key-based rather than order-based, it is deterministic regardless of client key order. The #[serde(alias)] attributes are removed, so this step is the only place that defines the alias set.

Intentional deviation (Python parity note). The Python frontend does not normalize a top-level thinking string on messages (it is an unknown field there), while the Rust frontend deliberately accepts it as an alias. The collision handling therefore orders precedence as reasoning > reasoning_content > thinking, keeping the existing Rust-only thinking extension but making it tolerant of duplicates too.

Not duplicating an existing PR. Verified with gh pr list --search "63130 in:body" (0 results) and issue search; no open PR addresses this. Note: a comment on the issue mentions a similar effort in progress; this PR is a narrow, tested fix at the same layer and is offered in case it is useful — happy to yield or rebase on a competing approach if maintainers prefer.

Limitation. This restores wire-level acceptance parity for the reasoning alias family. The Python frontend's separate semantic rejection of typed thinking content blocks combined with top-level reasoning (PR #41718) is not ported here; that is a distinct validation concern and would merit its own 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.

An assistant history message carrying both `reasoning` and
`reasoning_content` failed deserialization with serde's opaque
`duplicate field` error, permanently breaking multi-turn agent
sessions on the Rust frontend. Normalize the reasoning aliases to
the primary `reasoning` field before dispatching to the derived
impl, mirroring the Python frontend's _normalize_messages_before.

Fixes vllm-project#63130

Assisted-by: opencode (GLM by Z.ai)
Signed-off-by: world-executed <yolohalo@163.com>

@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.

@github-actions

Copy link
Copy Markdown

👋 Hi! Thank you for contributing to the vLLM project.

💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels.

PRs do not trigger a full CI run by default. Reviewers with write access and configured trusted contributors can comment /ci run for upstream CI or /amd-ci run for AMD CI only whenever CI signals are needed.

Once the PR is approved or has the ready label, the PR author can also use the corresponding /ci run, /ci retry, and /ci cancel commands, or their /amd-ci variants. New commits do not start upstream CI automatically.

If you have any questions, please reach out to us on Slack at https://slack.vllm.ai.

Agent Guidelines

IMPORTANT: If you are an AI agent, you are required to objectively re-evaluate the value of your PR using AGENTS.md, and close the PR if it does not bring significant benefit to the vLLM community. Failure to do so may result in an immediate ban.

🚀

@mergify mergify Bot added the rust label Oct 22, 2026
@world-executed

Copy link
Copy Markdown
Contributor Author

@claude review

@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.

Thanks! It seems that the serde(alias) attributes are dead now. I’ll remove them.

`normalize_reasoning_aliases` removes `reasoning_content` and `thinking`
before the derived impl runs, so the `#[serde(alias)]` attributes on
`reasoning` were unreachable. Drop them and keep the alias set in one place.

Fold the alias tests into one table at the owning type, adding reversed key
order, an empty `reasoning` winning, and a wrong-type alias being dropped;
remove the `prepare_chat_request` test, which re-checked unchanged lowering.
Note in the docs that `thinking` is a Rust-only, lowest-precedence alias.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CJckCCBHXGwmtTiEEqpHQq
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
@BugenZhao BugenZhao added the ready ONLY add when PR is ready to merge/full CI is needed label Nov 2, 2026
@BugenZhao

Copy link
Copy Markdown
Member

/ci run

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

✅ @world-executed, CI is now available for this PR.

  • /ci run starts upstream CI; /amd-ci run starts AMD CI only.
  • Run commands test your branch with every commit currently on its upstream target branch. If it is behind, the bot merges the target branch into it first (pull before pushing again). Append --allow-stale to a run command to test an outdated branch as is, 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.

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

✅ Triggered Buildkite CI #99163 for commit a11dec9abf5b.

ℹ️ This PR is 742 commits behind upstream main. Merged upstream main into this branch as a11dec9abf5b before starting CI. Pull the branch before pushing more changes.

@BugenZhao
BugenZhao merged commit 30565c3 into vllm-project:main Nov 2, 2026
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

[Bug]: Strict serde rejection of duplicate field reasoning breaks agent harnesses that echo both reasoning and reasoning_content

3 participants