Repository navigation
feat: forward one tenant-scoped session id on /v1/messages - #488
Conversation
Closes vllm-project#159. Claude Code names its session with x-claude-code-session-id and other clients may send X-Session-ID. The gateway forwarded both unchanged, so a client chose the X-Session-ID that vLLM reads as the request's typed session_id, with no tenant scope and no check that the two agree. The Messages handlers now read every value of both headers before the body is read. Empty values count as absent; one value, or equal values, give one session id. Different values, non-ASCII values and values over 256 bytes return 400 invalid_request_error before any upstream call. The gateway removes any client X-Session-ID and forwards one derived value: lowercase hex SHA-256 over length-prefixed fields (a version tag, the verified OIDC principal or the default tenant, the client id). The proxy, the gateway loop and the streaming loop all forward the handler's headers, so one step covers every path. x-claude-code-session-id and the body pass through unchanged. Signed-off-by: sohomchakraborty <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
…-identity Signed-off-by: Sohom Chakraborty <[email protected]>
|
@franciscojavierarceo could you approve the workflow runs on this PR when you have time? All seven are waiting for maintainer approval, so CI hasn't run yet. The PR closes #159 as proposed in my comment there: |
maralbahari
left a comment
There was a problem hiding this comment.
Thanks, for contribution. added inline comments
…-identity CHANGELOG: the vllm-project#159 entry moves under [Unreleased] after the 0.10.0 cut. Signed-off-by: Sohom Chakraborty <[email protected]>
- scope_session_id returns SessionIdError, turned into the Anthropic 400 by one From impl, so the result_large_err allow goes away. - types::session is now types::session_id, and TERMINOLOGY.md defines the session ID apart from response sessions and KV-cache identity. - A Connection header that lists x-session-id or x-claude-code-session-id gets the same 400: forwarding drops the headers it lists, which would drop the derived X-Session-ID. - With neither session header, a non-empty vllm_xargs.session_id string in the body is scoped into X-Session-ID. vLLM prefers the header, so the body is forwarded unchanged and the value vLLM reads is always derived. The check now runs after the body is read. Signed-off-by: Sohom Chakraborty <[email protected]>
maralbahari
left a comment
There was a problem hiding this comment.
Thanks for addressing the earlier comments: the Connection case and the body fallback are handled and tested, the docs now match what the code enforces, the lint suppression is gone, and the types::session_id name and TERMINOLOGY.md entry read well. One thing is left in how the body fallback reads vllm_xargs.session_id, and one small duplication; details inline.
…he hex helper The body fallback parsed the whole request into a serde_json::Value. It now reads only vllm_xargs.session_id through a small deserializer that skips the other keys and keeps the last of repeated keys, as vLLM does. ScopedSessionId and the migration checksum test share utils::common::lowercase_hex. Signed-off-by: Sohom Chakraborty <[email protected]>
maralbahari
left a comment
There was a problem hiding this comment.
Thanks for the update; the shared lowercase_hex helper is good. The typed view is the remaining point. Details inline.
body_session_id now deserializes BodyView and XargsView, two derived structs, as asked in review. The hand-written visitors, OrOther, last_value_of and the repeated-key test cases are gone: clients do not send vllm_xargs or session_id twice. The outdated-schema test imports lowercase_hex with use. Signed-off-by: Sohom Chakraborty <[email protected]>
…-identity main added the typed require_approval entry (vllm-project#520) under a new Changed heading of the unreleased changelog, where this branch adds its session id entry under Added. Both are kept, Added first. Signed-off-by: Sohom Chakraborty <[email protected]>
Summary
Closes #159, as proposed in my comment there. #360 and #364 build on it.
/v1/messagesand/v1/messages/count_tokensnow read everyx-claude-code-session-idandX-Session-IDvalue and forward one gateway-derivedX-Session-ID, which vLLM reads as the request's session id. Before this change the client'sX-Session-IDreached vLLM unchanged, with no tenant scope and no check againstx-claude-code-session-id.X-Session-IDis forwarded.x-claude-code-session-id, the other headers and the body pass through unchanged. All Messages paths forward the handler's headers, soproxy.rsand the executor are not touched.vllm_xargs.session_idstring in the body is scoped intoX-Session-IDthe same way. The body is forwarded unchanged, and vLLM prefers the header.Connectionheader that lists either session header gets the same 400: forwarding drops the headers it lists, the derived one included.Two decisions from my comment, with the defaults I chose. Either is a small change if you prefer the other.
ScopedSessionId::new. Fixed length, and the OIDC subject does not reach vLLM. A readable{tenant}:{session}prefix would replace only that function and its known-answer tests; the keyed HMAC in docs: specify server-managed prompt cache state for Messages #195 also needs a key setting.X-Session-ID), non-ASCII values and values over 256 bytes return 400invalid_request_errorbefore any upstream call. Preferringx-claude-code-session-idinstead is one branch insession_identity.rsplus the conflict test cases.Test Plan
hashlib, tenant separation, field boundaries), the header parsing (every case above, 256/257 bytes) and the body fallback.messages_test.rs: forwarding on every path, includingcount_tokens, and the 400s on the proxy, gateway-loop, streaming-loop andcount_tokenspaths with no upstream request.oidc_auth_test.rs: two principals with the same client id get different values; one principal keeps its value.Connectioncases got 200 and the body case forwarded noX-Session-ID. Nowmessages_test18/18 andoidc_auth_test23/23 pass.cargo fmt --check,cargo clippy --all-targets -- -D warnings,cargo testandpre-commit run --all-filespass.