Repository navigation
feat(vllm_model): add opt-in fold_nonleading_system_messages - #4010
linj-glitch wants to merge 6 commits into
Conversation
9eae98e to
a396650
Compare
Some harnesses inject system messages mid-conversation; Claude Code, for example, appends background-task notices with role=system after tool turns. Chat templates that only admit a system message at the start (e.g. "System message must be at the beginning") reject the whole request, which the harness sees as a server error. Add `fold_nonleading_system_messages` to VLLMModelConfig (default off). When set, every system/developer message after the leading system block is sent as a user message with identical content, so the model still reads it in chronological position. It runs after `replace_developer_role_with_system` and, like that option, raises NotImplementedError on the Responses-native path. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Lin Jia <[email protected]>
a396650 to
d42f056
Compare
Signed-off-by: Lin Jia <[email protected]>
|
/ok to test 6c73d74 |
Signed-off-by: Lin Jia <[email protected]>
|
/ok to test 8ce785a |
Only responses_api_models/vllm_model/tests/test_app.py conflicted: both sides added names to its import from responses_api_models.vllm_model.app. The resolution keeps the names of both sides, so every test of both sides stays. Signed-off-by: alexandery <[email protected]> Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
I merged On current A sandbox session of Codex needs this setting for a chat template that accepts an instruction message only at the start: after Codex compacts its history in place, it can put an instruction message after other messages. |
|
/ok to test 6cb5acb |
|
|
||
| @staticmethod | ||
| def _messages() -> list[dict[str, Any]]: | ||
| return [ |
There was a problem hiding this comment.
Nit: Codex and Claude Code requests reach the fold with a single leading system message, because the conversion merges the rest (chat_completions_converter.py#L564-L575 (
Gym/nemo_gym/models/chat_completions_converter.py
Lines 564 to 575 in 6cb5acb
system, developer, so Qwen3.5 refuses the lists the tests expect. Suggest starting with one system message and putting the developer message after the tool result; L9282, L9296 and L9301 then expect["system", "user", "assistant", "tool", "user", "user"].
There was a problem hiding this comment.
I checked this in the conversion: with instructions set, it merges the leading system and developer messages into one system message (nemo_gym/models/chat_completions_converter.py:567-575), and the Messages route passes system on as instructions (nemo_gym/models/anthropic_converter.py:328-330). A request of Codex or of Claude Code therefore reaches the fold with one leading system message. Commit 28d9319 changes the fixture as you suggest: it starts with one system message and has the developer message after the tool result (responses_api_models/vllm_model/tests/test_app.py:9265-9279), and the three tests expect ["system", "user", "assistant", "tool", "user", "user"] (test_app.py:9284, 9307, 9312). The tests now cover the fold of a later developer message, and test_leading_system_and_developer_messages_are_kept (test_app.py:9291-9298) keeps one case with two leading messages, which a /v1/chat/completions request can still send because it is not converted. That case states the fold's rule and not what a chat template accepts: I did not render any list with the Qwen3.5 chat template.
| raise NotImplementedError | ||
| if self.config.replace_developer_role_with_system: | ||
| raise NotImplementedError | ||
| if self.config.fold_nonleading_system_messages: |
There was a problem hiding this comment.
To match the other chat-only settings, could this be refused at startup by adding it to _validate_chat_conversion_options (
Gym/responses_api_models/vllm_model/app.py
Lines 949 to 954 in 6cb5acb
There was a problem hiding this comment.
Done in 8b63638: fold_nonleading_system_messages is in the list of _validate_chat_conversion_options (responses_api_models/vllm_model/app.py:950), so a configuration that also sets is_responses_native is refused when it loads, with the same message as the other chat-only settings. I removed the check from _responses_native, because it can no longer be reached: responses() is the only caller and calls it only under is_responses_native (app.py:1510-1511), and a server changes neither setting after its configuration has loaded. test_responses_native_rejects_fold constructs the refused configuration (responses_api_models/vllm_model/tests/test_app.py:9314-9316). One behavior changes: a server with both settings used to start and applied the fold to /v1/chat/completions requests, and it no longer starts. With use_completions_api: true the fold is skipped without a message (app.py:2119-2120); three of the other four settings in that list are refused there too (app.py:960-974), and I can add the same refusal for the fold here if you want it.
The Responses conversion merges a request's `instructions` and its leading system and developer messages into one system message, and the Messages route passes `system` on as `instructions`. A request of the Codex CLI or of Claude Code therefore reaches `fold_nonleading_system_messages` with a single leading system message. The fixture of the fold's tests has that form: one system message at the start, and the developer message after the tool result, before the later system message. The three tests that read the fixture expect the roles system, user, assistant, tool, user, user, which hold one system message, at the start. The later developer message makes the tests cover the fold of that role too. `test_leading_system_and_developer_messages_are_kept` covers a request with two leading messages, which the fold leaves as they are: a Chat Completions request is not converted, so it can reach the fold with them. Signed-off-by: alexandery <[email protected]> Co-Authored-By: Claude Fable 5.2 <[email protected]>
… Responses route at startup A configuration that sets `fold_nonleading_system_messages` together with `is_responses_native` is refused when it loads, by `_validate_chat_conversion_options`, like the other settings that apply to the Chat Completions conversion. The native Responses route forwards a request without the chat messages that the fold changes. `_responses_native` no longer checks the setting on each request. `responses()` is its only caller and calls it only when `is_responses_native` is set, and a server changes neither setting after its configuration has loaded, so with the startup check that request-time check cannot be reached. A server with both settings used to start. It applied the fold to requests of `/v1/chat/completions` and failed each request of `/v1/responses` and `/v1/messages` with `NotImplementedError`: the reply was HTTP 500 with the body `"NotImplementedError()"`, or a `response.failed` event for a `/v1/responses` request with `stream: true`. It no longer starts. Signed-off-by: alexandery <[email protected]> Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
/ok to test 8b63638 |
Claude Code can insert a system notice after a tool turn, which causes Qwen-style chat templates to reject the request with
System message must be at the beginning.Enabling
fold_nonleading_system_messageschanges later system/developer messages to user messages while preserving their content, chronological position, and the leading system block, after applyingreplace_developer_role_with_system.The option defaults to false and rejects the Responses-native path; enabling it deliberately changes those prompt roles.
Head
8ce785af39a50ca2e63cb025a8b424243b2ecd5cincludes an additive DCO-signed merge of mainf36e126547866601bee9c0671c9b59484ef83723to pick up the existing mini-SWE dependency-isolation and terminal-test fixes, with the folding behavior unchanged.Validation on Python 3.13.14 with imports verified from this checkout passed all 573 vLLM tests,
pre-commit run --all-files, the private guardwords scan of this PR's diff and description, andgit diff --check.The author's historical GRPO rollout with Claude Code SWE agents and a Qwen-family policy reported that affected requests were served when enabled; this AI-assisted integration adds no new real-model rollout evidence, and normal GitHub review and current-head CI gates still apply.