Skip to content

[#20367][fix] Accept prompt_cache_key in Chat Completions requests - #20368

Open
lucifer1004 wants to merge 6 commits into
NVIDIA:mainfrom
lucifer1004:upstream/chat-prompt-cache-key
Open

lucifer1004 wants to merge 6 commits into
NVIDIA:mainfrom
lucifer1004:upstream/chat-prompt-cache-key

Conversation

@lucifer1004

@lucifer1004 lucifer1004 commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Fixes #20367.

ChatCompletionRequest is extra="forbid", so a request carrying OpenAI's standard prompt_cache_key field was rejected with HTTP 400 (extra_forbidden). This PR adds the field as Optional[str] = None, accepted and otherwise ignored, like user and parallel_tool_calls: KV cache reuse needs no client hint, and cache_salt remains the field that isolates cached prefixes. ResponsesRequest already accepts the field through extra="allow".

Other unknown fields are still rejected, and non-string values of prompt_cache_key fail validation.

  • tensorrt_llm/serve/openai_protocol.py: new field on ChatCompletionRequest.
  • tests/unittest/api_stability/references/trtllm_serve_api.yaml: the matching reference row (kind: openai, status: stable).

Test Coverage

  • New tests/unittest/llmapi/apps/test_openai_protocol_prompt_cache_key.py (CPU only), registered in l0_cpu.yml: accepted as keyword and from JSON, default None, non-string values rejected, other fields unchanged by it, unknown fields still rejected.
  • tests/unittest/api_stability/test_serve_api.py covers the reference row.
  • An equivalent change (with a stricter variant of these tests) passed our CPU test run of the serve unit tests; this branch's new test file has not been run yet (no local environment with the package built); I will report the result here.
  • pre-commit on the changed files: clean.

PR Checklist

  • PR description clearly explains what and why.
  • PR follows the TRT-LLM coding guidelines to the best of my knowledge.
  • Test cases are provided for new code paths.
  • API change: one new optional OpenAI-compatible request field (backward compatible); the serve API reference YAML is updated.
  • No new dependencies, no CODEOWNERS changes.
  • Please check this after reviewing the above items as appropriate for this PR.

Dev Engineer Review

ChatCompletionRequest adds optional prompt_cache_key: str, defaulting to None, so chat-completion requests can include this OpenAI field without changing other request data. The field is accepted for compatibility and ignored; other unknown fields remain rejected. The stable API reference records the field as optional.

QA Engineer Review

The new CPU-only test file covers string values, including an empty string; the None default; JSON input; invalid types; unchanged fields; and rejection of unknown fields. The test is listed in tests/integration/test_lists/test-db/l0_cpu.yml. CI comments report that the new test passed, and a later pipeline completed successfully. The tests cover model validation but not endpoint-level serving behavior. Coverage: needs follow-up for endpoint-level behavior.

Per-File QA Perspective

  • tensorrt_llm/serve/openai_protocol.py: Verify chat-completion requests accept and ignore prompt_cache_key, default it to None, and continue to reject invalid types and other unknown fields.
  • tests/unittest/llmapi/apps/test_openai_protocol_prompt_cache_key.py: Covers accepted values, defaults, JSON input, invalid types, unchanged fields, and unknown-field rejection. Listed in the CPU CI test list.
  • tests/integration/test_lists/test-db/l0_cpu.yml: Adds the new CPU-only test to the CI list.
  • tests/unittest/api_stability/references/trtllm_serve_api.yaml: Adds prompt_cache_key as a stable optional API field. Verify that the reference stays consistent with the request model.

ChatCompletionRequest forbids unknown fields, so requests carrying OpenAI's
standard prompt_cache_key were rejected with 400. Accept the field and
ignore it, like user and parallel_tool_calls.

Signed-off-by: Zihua Wu <13583761+lucifer1004@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between d33a514 and fb68c1e.

Files selected for processing: 2
  • tensorrt_llm/serve/openai_protocol.py
  • tests/integration/test_lists/test-db/l0_cpu.yml

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.

Walkthrough

ChatCompletionRequest accepts an optional prompt_cache_key string and ignores it. The change adds API stability metadata and CPU tests for parsing, defaults, validation, and preservation of other fields.

Changes

Chat completion request compatibility

Layer / File(s) Summary
Add and validate the request field
tensorrt_llm/serve/openai_protocol.py, tests/unittest/api_stability/references/trtllm_serve_api.yaml, tests/unittest/llmapi/apps/test_openai_protocol_prompt_cache_key.py, tests/integration/test_lists/test-db/l0_cpu.yml
ChatCompletionRequest accepts the optional prompt_cache_key field and ignores it. The API stability reference records the field as optional and stable. CPU tests cover valid strings, the default value, JSON parsing, unchanged other fields, and rejection of unknown fields and non-string values. The CPU test list includes the new test module.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related issues

Possibly related PRs

  • NVIDIA/TensorRT-LLM#20864: Adds an optional ignored store field to ChatCompletionRequest using the same schema, stability-reference, and test pattern.
  • NVIDIA/TensorRT-LLM#20963: Adds an optional ignored safety_identifier field to ChatCompletionRequest using the same schema, stability-reference, and validation-test pattern.
Merge Risk: Minimal · up to fb68c

No actionable merge-blocking risk remains for this compatibility change.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 2 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly identifies the issue, uses the required [#20367][fix] format, and accurately summarizes the primary change.
Description check Passed The description explains the problem and solution, identifies the API change, documents relevant test coverage, and includes the repository checklist. It is sufficiently complete for review.
Linked Issues check Passed Issue #20367 is active and directly linked. ChatCompletionRequest adds prompt_cache_key: Optional[str] = None and retains extra="forbid". The change accepts and ignores the OpenAI field while pr…
Out of Scope Changes check Passed The source change directly addresses issue #20367. The tests verify the required compatibility and validation behavior. The CPU test registration and stable API reference entry support the same public…
Full details: Linked Issues check

Explanation

Issue #20367 is active and directly linked. ChatCompletionRequest adds prompt_cache_key: Optional[str] = None and retains extra="forbid". The change accepts and ignores the OpenAI field while preserving rejection of other unknown fields. The added tests cover keyword and JSON input, the default, non-string rejection, unchanged fields, and unknown-field rejection. The API reference entry and CPU test registration are included.

Full details: Out of Scope Changes check

Explanation

The source change directly addresses issue #20367. The tests verify the required compatibility and validation behavior. The CPU test registration and stable API reference entry support the same public API change. The supplied whole-PR summary shows no unrelated changes.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 2 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@lucifer1004 lucifer1004 added the api-compatible Accepted LLM API contract change that is backwards-compatible label Oct 15, 2026
@lucifer1004

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #78107 [ run ] triggered by Bot. Commit: 5569215 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #78107 [ run ] completed with state FAILURE. Commit: 5569215
/LLM/main/L0_MergeRequest_PR pipeline #64378 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

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

Stamp on behalf of runtime devs, delegating proper review to @NVIDIA/trt-llm-noncommitted-api-review-committee

@lucifer1004

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #78261 [ run ] triggered by Bot. Commit: 5569215 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #78261 [ run ] completed with state FAILURE. Commit: 5569215
/LLM/main/L0_MergeRequest_PR pipeline #64511 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

Signed-off-by: Zihua Wu <13583761+lucifer1004@users.noreply.github.com>
@lucifer1004

lucifer1004 commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator Author

The last CI run failed only on tests that this PR does not touch. unittest/_torch/compilation/test_phase_selective_forward.py monkeypatches moe_a2a_steady_state_budget_for_capture, which does not exist at the main commit this branch was based on; #20362 has since fixed the test on main. The other failures were fail-fast aborts. I merged current main into the branch and am re-running CI.

@lucifer1004

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #78355 [ run ] triggered by Bot. Commit: da36bed Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #78355 [ run ] completed with state FAILURE. Commit: da36bed
/LLM/main/L0_MergeRequest_PR pipeline #64585 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@lucifer1004

Copy link
Copy Markdown
Collaborator Author

CI #78355 failed outside this PR. The CPU failure is test_trtllm_serve_config_schemas.py::test_checked_in_schemas_are_current: main's checked-in serve schemas do not include the kv_pool_rebalance_config fields added in #19077 (details there), so every PR based on current main hits it. This PR's own test passed. The B200 / B300 attention suites failed with a sticky CUDA driver error: 201 (invalid device context) from the KV cache manager in sparse / attention-backend tests, and the H100 failures are in test_e2e_capture.py and the cache-transceiver tests. None of these touch openai_protocol.py. I'll re-run once the schemas are refreshed on main; a re-run before that would fail on the same test.

Signed-off-by: Zihua Wu <13583761+lucifer1004@users.noreply.github.com>
@lucifer1004

lucifer1004 commented Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator Author

CI #78860 failed outside this PR:

Rerunning.

@lucifer1004

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #78926 [ run ] triggered by Bot. Commit: d33a514 Link to invocation

@github-actions

Copy link
Copy Markdown

Automatically added "ci: full pre-merge approved" because this PR has satisfied the required GitHub review approvals. Unresolved review conversations and other required checks remain independent merge requirements.

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #78926 [ run ] completed with state SUCCESS. Commit: d33a514
/LLM/main/L0_MergeRequest_PR pipeline #65025 completed with status: 'SUCCESS'
Pipeline passed with automatic retried tests. Check the rerun report for details.

CI Report

Link to invocation

Signed-off-by: Zihua Wu <13583761+lucifer1004@users.noreply.github.com>
@lucifer1004

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #80461 [ run ] triggered by Bot. Commit: fb68c1e Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #80461 [ run ] completed with state SUCCESS. Commit: fb68c1e
/LLM/main/L0_MergeRequest_PR pipeline #66232 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@lucifer1004

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #80474 [ run ] triggered by Bot. Commit: fb68c1e Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #80474 [ run ] completed with state SUCCESS. Commit: fb68c1e
/LLM/main/L0_MergeRequest_PR pipeline #66243 completed with status: 'SUCCESS'
Pipeline passed with automatic retried tests. Check the rerun report for details.

CI Report

Link to invocation

Signed-off-by: Zihua Wu <13583761+lucifer1004@users.noreply.github.com>
@lucifer1004

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #80549 [ run ] triggered by Bot. Commit: 7dc1606 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #80549 [ run ] completed with state FAILURE. Commit: 7dc1606
/LLM/main/L0_MergeRequest_PR pipeline #66313 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@lucifer1004

Copy link
Copy Markdown
Collaborator Author

CI #80549 failed for reasons unrelated to this PR (it only adds prompt_cache_key to ChatCompletionRequest):

  • CPU-Generic-x86-1: unittest/_torch/modeling_v2/test_modeling_v2_deepseek_default_shards.py::test_load_reads_only_the_rank_share[ws8-tp-moetp4-moeep2] reported "Test terminated unexpectedly" and passed on rerun in the same pipeline. It also passes in the other recent pipelines.
  • DGX_H100-PyTorch-6: several unittest/disaggregated/test_kv_transfer.py cases hit CUDA driver error: 201 (invalid device context) in KvCacheManager teardown and passed on rerun.
  • B300-PyTorch-2 and CPU-Generic-arm-1 were aborted by fail-fast.

This PR's test_openai_protocol_prompt_cache_key.py did not fail.

@lucifer1004

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #80607 [ run ] triggered by Bot. Commit: 7dc1606 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #80607 [ run ] completed with state SUCCESS. Commit: 7dc1606
/LLM/main/L0_MergeRequest_PR pipeline #66365 completed with status: 'SUCCESS'

CI Report

Link to invocation

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

api-compatible Accepted LLM API contract change that is backwards-compatible ci: full pre-merge approved

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: trtllm-serve /v1/chat/completions rejects the standard OpenAI field prompt_cache_key with 400

6 participants