Skip to content

feat: forward one tenant-scoped session id on /v1/messages - #488

Merged
maralbahari merged 8 commits into
vllm-project:mainfrom
sohom-cs:feat/messages-session-identity
Nov 18, 2026
Merged

maralbahari merged 8 commits into
vllm-project:mainfrom
sohom-cs:feat/messages-session-identity

Conversation

@sohom-cs

@sohom-cs sohom-cs commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes #159, as proposed in my comment there. #360 and #364 build on it.

/v1/messages and /v1/messages/count_tokens now read every x-claude-code-session-id and X-Session-ID value and forward one gateway-derived X-Session-ID, which vLLM reads as the request's session id. Before this change the client's X-Session-ID reached vLLM unchanged, with no tenant scope and no check against x-claude-code-session-id.

  • One value, or equal values, give one session id. Empty values count as absent. With no value, no X-Session-ID is forwarded.
  • Tenant: the verified OIDC principal (issuer and subject) when OIDC is on, otherwise the default tenant. No client header picks it (Enforce user and tenant ownership for persisted state #107).
  • x-claude-code-session-id, the other headers and the body pass through unchanged. All Messages paths forward the handler's headers, so proxy.rs and the executor are not touched.
  • With neither header, a non-empty vllm_xargs.session_id string in the body is scoped into X-Session-ID the same way. The body is forwarded unchanged, and vLLM prefers the header.
  • A Connection header 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.

  1. Scoping format: lowercase hex SHA-256 over length-prefixed fields (a version tag, tenant, client id), in 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.
  2. Conflicts: different values (across the two headers, or a repeated X-Session-ID), non-ASCII values and values over 256 bytes return 400 invalid_request_error before any upstream call. Preferring x-claude-code-session-id instead is one branch in session_identity.rs plus the conflict test cases.

Test Plan

  • Unit: the derivation (known-answer vectors checked with Python 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, including count_tokens, and the 400s on the proxy, gateway-loop, streaming-loop and count_tokens paths with no upstream request. oidc_auth_test.rs: two principals with the same client id get different values; one principal keeps its value.
  • Before the review fix, the Connection cases got 200 and the body case forwarded no X-Session-ID. Now messages_test 18/18 and oidc_auth_test 23/23 pass.
  • cargo fmt --check, cargo clippy --all-targets -- -D warnings, cargo test and pre-commit run --all-files pass.

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]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-27T04:57:55.726285Z
We couldn’t complete this review. Comment @codex review to try again.
639c2fd PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@sohom-cs

sohom-cs commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

@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: /v1/messages forwards one tenant-scoped X-Session-ID instead of the client's header, and #360 and #364 build on it.

@maralbahari maralbahari left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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 maralbahari left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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]>
@sohom-cs
sohom-cs requested a review from maralbahari November 15, 2026 19:13

@maralbahari maralbahari left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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]>
@maralbahari
maralbahari merged commit 19b392c into vllm-project:main Nov 18, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Claude Code - Stage 4] Normalize Messages session identity for cache-aware routing

2 participants