Skip to content

docs: specify server-managed prompt cache state for Messages - #195

Draft
franciscojavierarceo wants to merge 2 commits into
mainfrom
codex/messages-cache-state-rfc
Draft

franciscojavierarceo wants to merge 2 commits into
mainfrom
codex/messages-cache-state-rfc

Conversation

@franciscojavierarceo

@franciscojavierarceo franciscojavierarceo commented Aug 21, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • define private, non-authoritative server-managed cache state for the Messages API
  • preserve the conversation-stateless public Messages contract while coordinating affinity, checkpoints, retention, branches, and provider cache artifacts
  • reconcile the proposal with the existing Claude Code integration design
  • define the ownership boundary: Agentic API derives trusted logical coordinates and lifecycle policy, llm-d owns routed worker selection, and vLLM owns physical KV execution
  • link the reproducible affine KV benchmark evidence and qualify the uncommitted Claude Code capture
  • provide staged rollout, failure semantics, security controls, observability, benchmarks, and acceptance criteria

Test Plan

  • cargo test
  • uv run --with-requirements docs/requirements.txt mkdocs build --strict
  • git diff --check origin/main...HEAD
  • verify linked vLLM, llm-d, affine ADR, and raw benchmark sources resolve

maralbahari added a commit that referenced this pull request Nov 18, 2026
## 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 (#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 #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.

---------

Signed-off-by: sohomchakraborty <[email protected]>
Signed-off-by: Sohom Chakraborty <[email protected]>
Co-authored-by: Maral <[email protected]>

This branch has not been deployed

No deployments
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.

1 participant