[Bugfix]:Cached_tokens always returns -1 - #229
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: aa708696d9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| for (name, value) in resp_headers.iter() { | ||
| response_builder = response_builder.header(name, value); | ||
| } |
There was a problem hiding this comment.
Drop stale Content-Length after serializing discovery responses
In discovery mode, every non-streaming decoder response is now deserialized and serialized before this loop. If that changes the byte count—for example, for pretty-printed JSON or when cached_tokens is added or changes width—the old Content-Length is sent with merged_body, causing clients to receive a truncated/malformed response or a connection error. The direct-worker branch at vllm_pd_router.rs:1537-1540 already strips this header; apply the same filtering or set the new length here.
Useful? React with 👍 / 👎.
| let mut decode_json: Value = | ||
| serde_json::from_slice(&decode_body).map_err(|e| PDRouterError::NetworkError { | ||
| message: format!("Failed to parse decode response as JSON: {}", e), | ||
| })?; |
There was a problem hiding this comment.
Preserve non-JSON decoder error bodies
For a non-streaming decoder response that is not JSON, this parse error escapes process_vllm_two_stage_request and callers convert it to a generic 500 (vllm_pd_router.rs:1996-2002), discarding the decoder's original status/body. This affects supported transparent /v1/rerank requests: its mock worker explicitly returns the plain-text Simulated failure on failure (tests/common/mock_worker.rs:809-824); the discovery helper now has the same unconditional parse at lines 730-731. Normalize only successful JSON responses, or fall back to forwarding the original body.
Useful? React with 👍 / 👎.
…ed_tokens always returns -1 in the end. Signed-off-by: chasted <jiang1713399@gmail.com>
Signed-off-by: chasted <jiang1713399@gmail.com>
Purpose
In PD disaggregation mode, ensure that "usage.prompt_tokens_details.cached_tokens" preferentially uses the valid value returned by the prefill stage.
If the "cached_tokens" value returned by the decode stage is missing or invalid (e.g., "< 0"), automatically fall back to the prefill value.
Preserve the existing "logprobs" merging logic without introducing regressions.
Add regression tests to ensure the fix remains effective.
Test Plan
This test plan is designed to verify the PD (Prefill/Decode) disaggregation fix for
cached_tokenshandling.Objective
Ensure that the final response keeps the valid prefill-side
cached_tokensvalue instead of allowing an invalid decode-side value such as-1to override it.Core scenarios to cover
cached_tokens = 50cached_tokens = -150cached_tokens = 50cached_tokens = 1212cached_tokensinput_tokens_details.cached_tokensTest Result
Result summary
-
6 passed-
0 failedEvidence
The test run output included: