Repository navigation
feat(model): send a nonleading system message of a Messages request as a user message - #6905
alexandery-nvidia wants to merge 33 commits into
Conversation
The model server answers a streamed /v1/messages request only when the whole generation has returned, so the client receives no byte until then. Claude Code 2.1.312 gives a request up after about 360 seconds without a response byte and sends it again. API_TIMEOUT_MS does not lengthen that wait. A longer generation therefore runs twice, and the answer of the first run is lost. A stream that is open and then silent is given up after 300 seconds. A stream that carries a ping event every 15 seconds is kept for as long as the events come. stream_keepalive_s now applies to /v1/messages as it does to /v1/responses. A call that is still running after one interval opens the stream with a ping event and sends another at every interval. The events of the message follow unchanged. A call that ends within the first interval is served as before, so its failure keeps its HTTP status. A call that fails after the stream has opened ends it with an error event. Its type is invalid_request_error for a refusal that the server propagates and for another 4xx status, rate_limit_error for 429, and api_error otherwise. Claude Code answers an error event that precedes message_start by sending the request once more with "stream": false, and that request gets the HTTP status. No event can hold that request open: Claude Code gives it up after about 300 seconds without a response. A client that leaves cancels the backend call, in the first interval and after the stream has opened, as for /v1/responses. A server whose response ids come from an upstream Responses API refuses the setting at startup, as before, so it holds no Messages stream open either. Model-call capture does not count a ping event as the first token. The checkpoint gate of a policy model server does not take a ping event for the start of the answer. As after the lifecycle events of a /v1/responses stream, a checkpoint holds such a call instead of waiting for it, and the ledger row of the call is published when the message starts. Signed-off-by: alexandery <[email protected]> Co-Authored-By: Claude Fable 5.2 <[email protected]>
The Anthropic Messages route of a model server converts a request to the Responses API and calls the server's own `responses()`. The conversion dropped `output_config.effort`, so the reasoning effort of a Claude Code session never reached the backend, where a /v1/responses request with `reasoning.effort` reaches the engine as `reasoning_effort`. A model server now has the setting `forward_anthropic_reasoning_effort`. With it, the conversion states the effort as the Responses `reasoning.effort`, and the Chat Completions conversion sends it to the engine as it does for a Responses request. The setting is off by default, which keeps the effort dropped: Claude Code states an effort in every request, `high` unless it is configured otherwise, and an engine can refuse a level that it does not serve. Signed-off-by: alexandery <[email protected]> Co-Authored-By: Claude Fable 5.2 <[email protected]>
…s a user message An Anthropic Messages request can hold a `system` message after messages of another role. Claude Code 2.1.312 describes its environment and lists its skills in such a message after the prompt. The Messages route passed it on with the role `system`, so the backend received a system message after a user message, which a chat template can refuse. A model server now has the setting `anthropic_nonleading_system_note`. With it, the conversion hands each nonleading `system` message to the backend as a user message, which begins with the text of the setting in a text block of its own. The system messages that open a conversation keep their role. A converted message that precedes a user message of tool results is placed after it, so the results still follow their tool calls. A message whose content is neither a string nor a list keeps its role, so the conversion handles malformed content as it does without the setting. The setting is unset by default, which passes every system message on with its role. `fold_nonleading_system_messages` of vllm_model, proposed in #4010, names the same messages. It changes the role alone, in place, for the chat messages of every route of that server, and it covers `developer` messages too. This setting applies to the Messages route of every model server, before the conversion to the Responses API. It adds a text that tells the model where the message came from, and it moves a message that would separate tool results from their tool calls. A server can state either setting or both: after this conversion no nonleading system message of a Messages request is left for the other one. Signed-off-by: alexandery <[email protected]> Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
/ok to test 6f62a05 |
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
SHIP WITH CARE.
I reviewed all 13 changed files and their connected conversion, streaming, capture and checkpoint paths. I found two RISKs and two optional NOTEs; no BLOCKER.
Validation: CI checks attached to the reviewed head show Lint check, Unit tests / Test, all four core shards, and all eight server-suite shards passing. Harness conformance and Environment Server compliance checks are red and explicitly non-blocking. I have not attributed those failures to this change.
I ran focused CPU probes in 766267172432.dkr.ecr.us-east-1.amazonaws.com/gym:ba3eeeb0a60df9a7cd3bb9d2c1f36cabb0a493b5, the base CI image, because the head's container build was skipped. I installed the repository's declared root dependencies into a throwaway virtual environment after initial imports found missing packages. Final probes exercised the admitted source:
- Converter probes reproduced split parallel-tool results being interrupted by the injected note, and malformed
output_configproducing HTTP 500 with forwarding disabled. - Streaming probes passed cancellation, asynchronous cleanup, completion-before-first-chunk, request-cookie preservation and finalization-error propagation checks.
- A checkpoint probe passed with one held call and one committed ledger row after resume; pings did not count as answer delivery.
- Failure probes reproduced lost classification and typed failure identity after pings. The same delayed typed failure on base kept its failure header and selected failure ID.
I relied on CI for existing suites rather than rerunning them. I did not run a live model, GPU workload or Claude Code rollout.
Review generated by codex. This was a full review. Request a full review with /review reset=true.
| and isinstance(content[0], dict) | ||
| and content[0].get("type") == "tool_result" | ||
| ) | ||
| converted += [message, *pending] if holds_tool_results else [*pending, message] |
There was a problem hiding this comment.
RISK: defer the note until the whole tool-result batch has passed.
Could you keep pending across consecutive tool-result messages? For assistant calls a and b, followed by a system note and two separate user result messages, this insertion produces assistant(a,b), tool(a), user(note), tool(b). Packing the same results into one user message produces assistant(a,b), tool(a), tool(b), user(note) instead. The installed Anthropic SDK explicitly permits consecutive user turns and says they are combined.
The public converter-to-Chat probe at /workspace/review-probes/converter-1/edge-probe.py reproduced roles ['user', 'assistant', 'tool', 'user', 'tool'], leaving call b outstanding when the note appears. This defeats the option's tool-result ordering protection for backends requiring an uninterrupted result batch; I did not test a live provider rejection.
Keep appending the consecutive result messages before flushing notes. Add a regression with two parallel calls and separate result messages, asserting both results precede the note after Chat conversion. Preserve the existing single-result, combined-result and leading-system behavior.
There was a problem hiding this comment.
I reproduced this: two parallel calls, a system message and two separate user messages of results gave the Responses items function_call(a), function_call(b), function_call_output(a), user, function_call_output(b) and the chat roles user, assistant, tool, user, tool.
Commit cb9a847 holds a converted message until a message follows that holds no tool results, so it is placed after the last result. test_nonleading_system_message_follows_every_result_of_parallel_tool_calls asserts the order for results in separate messages and for results in one message. It asserts on the Responses items that this conversion returns: the chat roles follow from that order (user, assistant, tool, tool, user for both layouts after the change), and the conversion to chat messages is not touched here. The single-result and leading-system cases of the existing test pass unchanged.
| response = await pending | ||
| except Exception as exc: | ||
| # The stream is already open, so only an event can report the failure. | ||
| yield _ANTHROPIC_CONVERTER.anthropic_error_to_sse(*self._streamed_messages_failure(exc)) |
There was a problem hiding this comment.
RISK: preserve failure evidence when converting a late exception to SSE.
Could you retain the original exception's classification and typed failure report before swallowing it here? Capture sees HTTP 200 plus terminal error and records every such failure as upstream_error in capture normalization.
The public-route probe capture-1/probe.py recorded a delayed 429 as (429, rate_limit) without keepalive but (200, upstream_error) after pings. classify_probe.py then changed is_server_fault_call from false to true. A 504 also lost its timeout category. My leader/observed_failure_probe.py additionally showed a typed failure losing its selected failure_id in capture and carrying neither a failure header nor terminal failure-report field; base kept the ID.
Preserve the original status/category and selected cause in request-local capture state, and carry the bounded failure report through the Messages terminal/capture path. Keep HTTP 200 once headers are committed and retain the Anthropic error event. Acceptance should compare fast versus post-ping 429, timeout and typed-failure cases: classification and cause identity must agree, while successful answer capture and ping timing stay unchanged.
There was a problem hiding this comment.
I reproduced this. It is the same finding as on #6903 and #6904, because the code is the keepalive path of #6903.
The failure report is fixed there in commit 2477ee8, which this branch holds through the merge c24f4d1. The terminal event of a stream that ping events opened carries the request's report, and StreamFailureReportReader and the rollout reader read it for Messages (test_a_keepalive_messages_stream_reports_late_failures_on_its_terminal_event, and the messages cases of test_actual_stream_capture_survives_collection_and_store).
The capture category is not changed. A delayed 429 or 504 is recorded as (200, upstream_error) on a /v1/responses stream under stream_keepalive_s and on a streamed chat completion as well, and test_actual_stream_capture_survives_collection_and_store asserts that category for both, so keeping the original category is a change to capture for all three dialects and not to the Messages route.
| params["temperature"] = anthropic_body["temperature"] | ||
| if anthropic_body.get("top_p") is not None: | ||
| params["top_p"] = anthropic_body["top_p"] | ||
| effort = (anthropic_body.get("output_config") or {}).get("effort") |
There was a problem hiding this comment.
NOTE, suggestion: avoid inspecting the ignored effort field when forwarding is off.
This lookup runs before checking forward_reasoning_effort. A truthy non-object output_config, such as "high" or ["effort"], was ignored on base but now raises AttributeError with the default settings. The focused converter-1/malformed-probe.py and route-probe.py reproduced the base/head difference and HTTP 500.
These inputs are malformed, so this is defensive hardening rather than a normal-client defect. Consider moving the lookup inside the forwarding branch and checking the mapping shape when enabled. Acceptance: the disabled option leaves the field ignored, and enabled wrong-shaped input receives a deliberate validation response rather than an unhandled attribute error.
There was a problem hiding this comment.
I reproduced this: with the default settings, the output_config values "high", ["effort"] and 3 returned HTTP 500 where main returns 200.
The line is #6904's. Commit a3d3da5 there reads output_config only when the effort is forwarded, and this branch holds it through the merge c24f4d1. test_output_config_is_not_read_when_the_effort_is_dropped covers the three values.
A validation response for a wrong-shaped value when forwarding is on is not added. The conversion validates no field of the Messages body (a wrong-shaped tools, system or tool_choice and a content block that is no object each return 500 too), so this field would be the only one with a check of its own.
| await asyncio.gather(call, return_exceptions=True) | ||
|
|
||
| assert [message.get("body") for message in sent[1:]] == [ping, message_start] | ||
| assert sent_at_publication == [2], "published before the message leaves" |
There was a problem hiding this comment.
NOTE, suggestion: assert a committed row rather than only a publication call.
The publication assertion observes the wrapper invocation, but this test creates PolicyModelParticipant() without a ledger or capture context. Consequently the real publish() returns immediately. It would still pass if deferred-row publication broke.
Keep the useful liveness/fence assertions, but consider replacing the spy-only assertion with a real deferred capture row and FileLineageStore, as the neighboring Responses test does. Assert zero committed rows while prepared, then exactly one row and context.committed after resume. My focused capture-1/checkpoint_probe.py exercised that integration successfully, so this is a coverage improvement, not a demonstrated runtime defect.
There was a problem hiding this comment.
This suggestion is not taken. The test is #6903's, and the change that it covers is one condition of PolicyAdmissionMiddleware: a ping chunk is not the first chunk of the answer.
The test shows that a checkpoint holds the call after a ping, and that the gate's publication step runs when the first event of the message arrives and before that event leaves. What the publication step writes is the same code for every dialect. test_a_call_s_ledger_row_is_published_at_its_first_answer_chunk_not_at_headers_or_keepalives and test_responses_lifecycle_events_are_liveness_not_the_answer assert the committed row with a FileLineageStore, so they fail if the publication of a deferred row breaks. A third copy with a ledger would assert nothing about the condition that changed.
A streamed /v1/messages call that outlasts one interval of stream_keepalive_s opens its stream with a ping event, so its HTTP headers go out before the backend call ends. The failure that ended such a call, and the failures that the call observed, were then not reported to the client: the failure header was already sent, and the stream carried no failure report. A keepalive /v1/responses stream and a streamed chat completion carry the report on their terminal event in that case. The terminal event of a Messages stream that ping events opened now carries the request's failure report in the same field, nemo_gym_failure_report: the error event of a call that failed, and message_stop of a call that answered. The report selects the failure that ended the call and holds the failures that the call observed, such as an attempt that a retry replaced. A request with nothing to report sends its events unchanged. StreamFailureReportReader accepts a report on these two event types. Rollout collection reads the report from a captured Messages stream as it does for the two other dialects, so the events reach the rollout's row. The function that adds the report to an event takes the event types from the reader, so they are stated once. Signed-off-by: alexandery <[email protected]> Co-Authored-By: Claude Fable 5.2 <[email protected]>
This branch is stacked on alexandery/messages-stream-keepalive. The merge brings in that branch's commit "fix(model): carry the failure report on a keepalive Messages stream", so the terminal event of a Messages stream that ping events opened carries the request's failure report here too. Signed-off-by: alexandery <[email protected]> Co-Authored-By: Claude Fable 5.2 <[email protected]>
The conversion of a Messages request read `output_config.effort` before it checked whether the effort is forwarded. A request whose `output_config` is not an object, such as a string or a list, therefore failed with an AttributeError and HTTP 500 on a model server that drops the effort, where the field was ignored before the setting existed. The conversion now reads `output_config` only with `forward_anthropic_reasoning_effort`. Without the setting, the field is ignored whatever its value is. Signed-off-by: alexandery <[email protected]> Co-Authored-By: Claude Fable 5.2 <[email protected]>
vllm_model accepted `forward_anthropic_reasoning_effort` together with `use_completions_api`. A /v1/completions request has no `reasoning_effort`, so the server answered a Messages request with HTTP 200 and sent the engine no effort, although the setting says that the effort is forwarded. The configuration now refuses the combination at startup, with the check that already refuses `forward_unvalidated_reasoning_effort` with `use_completions_api` for the same reason. The documentation of the setting states the requirement. Signed-off-by: alexandery <[email protected]> Co-Authored-By: Claude Fable 5.2 <[email protected]>
This branch is stacked on alexandery/messages-reasoning-effort, which is stacked on alexandery/messages-stream-keepalive. The merge brings in their commits "fix(model): carry the failure report on a keepalive Messages stream", "fix(model): read output_config of a Messages request only to forward it" and "fix(model): refuse Messages effort forwarding with the Completions API", so this branch holds the three fixes too. Signed-off-by: alexandery <[email protected]> Co-Authored-By: Claude Fable 5.2 <[email protected]>
With `anthropic_nonleading_system_note`, a system message that precedes a user message of tool results is placed after that message. When the results of parallel tool calls came in separate user messages, the converted message was placed after the first of them only. The backend then received a user message between the results, so the second result no longer followed its tool call. A converted message now waits until a message follows that holds no tool results, so it is placed after the last result. Results in one user message are placed as before. The documentation of the setting says "after the last of them". Signed-off-by: alexandery <[email protected]> Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
/ok to test cb9a847 |
|
/review reset=true |
VLLMModelConfig refused forward_anthropic_reasoning_effort whenever use_completions_api was on. With is_responses_native also on, a Messages request goes to /v1/responses, which takes reasoning.effort, so that server could apply the setting and did not start. The configuration now states its reason through reasoning_effort_unsupported_reason: the setting is refused only with use_completions_api=true and without is_responses_native=true, where a Messages request goes to /v1/completions. The check of its own in the validator is removed, so that validator is the one of main again. One test starts a server with all three settings on and expects the effort of a Messages request in the /v1/responses request. The other expects the refusal with use_completions_api alone. Signed-off-by: alexandery <[email protected]> Co-Authored-By: Claude Fable 5.2 <[email protected]>
The effort forwarding branch rewrote the lines that document forward_anthropic_reasoning_effort in two pages under fern/versions/latest/pages/model-server, and this branch added the lines of anthropic_nonleading_system_note directly below them. Both branches also added a test at the same place of tests/unit_tests/models/test_responses_api_model_messages.py. The merge keeps both in each file: the rewritten line with the added line below it, and the two tests. The lines that this branch adds and removes against the effort forwarding branch are the same as before the merge. Signed-off-by: alexandery <[email protected]> Co-Authored-By: Claude Fable 5.2 <[email protected]>
A nonleading system message that becomes a user message waits until the tool results that follow it have passed. The wait looked at the first block of each user message only, so a user message of a tool result followed by text was passed on whole and the converted message came after its text. The same content in two user messages put the converted message between the result and the text. _nonleading_system_messages_as_user now counts the tool_result blocks with which a user message begins. When the message holds more than those, it is split after them: the results, then the converted message, then the rest. A user message of tool results only is passed on as before, and so is every message while no converted message waits. The test converts both layouts and expects the same Responses input: the tool result, the converted message, the text. Signed-off-by: alexandery <[email protected]> Co-Authored-By: Claude Fable 5.2 <[email protected]>
A nonleading system message can hold a mid_conv_system block, which wraps text blocks. With anthropic_nonleading_system_note set, the block was copied into the user message, where the conversion of the messages refuses its type, so the Messages route answered HTTP 500 without calling the backend. _system_message_blocks now builds the blocks of the user message from the content of the system message. A string becomes one text block, the text blocks that a mid_conv_system block wraps take its place, and every other block is passed on as it is. A mid_conv_system block whose content is no list is passed on too, so the conversion refuses it as it does without a note. One test expects the wrapped text blocks after the note, in their order. One posts such a request to the Messages route and expects 200. The case of the content that is no list joins the test that compares the errors with and without a note. Signed-off-by: alexandery <[email protected]> Co-Authored-By: Claude Fable 5.2 <[email protected]>
The sentence on nonleading system messages in the Anthropic Messages page began with "It", which stood for the conversion named in the sentence before. The effort forwarding branch added a sentence about the model server between the two, so the sentence now names the conversion itself. Signed-off-by: alexandery <[email protected]> Co-Authored-By: Claude Fable 5.2 <[email protected]>
The rule read that a model server which sends its backend no reasoning effort refuses forward_anthropic_reasoning_effort, and one page said that base_model and agentic_if_text send none. agentic_if_text does send an effort, the one of its own reasoning_effort setting. It refuses the setting because it never sends the effort of a request. The two pages, the description of the setting and the docstring of reasoning_effort_unsupported_reason now say that a server refuses the setting when it does not send its backend the reasoning effort of a request. Signed-off-by: alexandery <[email protected]> Co-Authored-By: Claude Fable 5.2 <[email protected]>
The effort forwarding branch reworded the lines that document forward_anthropic_reasoning_effort in two pages under fern/versions/latest/pages/model-server. This branch has the lines of anthropic_nonleading_system_note directly below them. The merge keeps both in each page: the reworded line with this branch's line below it. The lines that this branch adds and removes against the effort forwarding branch are the same as before the merge. Signed-off-by: alexandery <[email protected]> Co-Authored-By: Claude Fable 5.2 <[email protected]>
With anthropic_nonleading_system_note set, a nonleading system message whose content is an empty list became a user message that held the note alone. So did one whose only block is a mid_conv_system block without text blocks. _nonleading_system_messages_as_user now adds the user message only when the system message yields at least one block, and drops the system message otherwise. A system message whose content is an empty string is converted as before. The test converts both forms and expects no user message beside the one of the request. Signed-off-by: alexandery <[email protected]> Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
/ok to test e955ce5 |
|
/review reset=true |
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
LGTM, but please take a look at the following findings:
- Failures after a ping lose their original classification in saved model calls.
- Malformed
output_configreturns HTTP 500 when effort forwarding is enabled.
Review generated by codex. This was a full review. Request a full review with /review reset=true.
| except Exception as exc: | ||
| # The stream is already open, so only an event can report the failure. | ||
| error = _ANTHROPIC_CONVERTER.anthropic_error_to_sse(*self._streamed_messages_failure(exc)) | ||
| yield _with_stream_report(error, _stream_report(failure_log, exc)) |
There was a problem hiding this comment.
RISK (medium risk)
What I tested
I repeated the reported 429 case before and after a ping through /v1/messages on CPU. I also exercised timeouts and typed failures.
What I found
After this catch, 429 / rate_limit / server_fault=false becomes 200 / upstream_error / server_fault=true. Typed errors also lose failure_report.failure_id in saved calls. Capture-based reliability and recovery decisions therefore depend on response timing.
What I recommend
Keep the original failure and category in request-local capture state. Keep HTTP 200 after headers commit. Add fast-versus-post-ping tests for 429, timeout and typed failures.
There was a problem hiding this comment.
Reproduced through an app with the middlewares that run_webserver installs: on /v1/messages a 422 was saved as 422 / client_error, not a server fault, before the first ping, and as 200 / upstream_error, a server fault, after it; a 429 lost rate_limit and a timeout lost timeout in the same way. Commit 0d83184 lets the Messages route note the failure in the request state (note_stream_failure, nemo_gym/models/model_call_capture.py:131, called at nemo_gym/models/base_responses_api_model.py:1082), and the capture middleware then saves the call with the category that it gives a failure that a route raises, with the HTTP status of the backend as upstream_status_code, and with status_code 200 (nemo_gym/models/model_call_capture.py:1637). tests/unit_tests/models/test_stream_failure_capture.py:184 sends a 422, a 429, the error that the model client raises with its observed attempt as cause, a timeout and a typed failure with keepalive off, on before the first ping and on after it, and expects equal category, server fault, status of the backend and failure events in the saved rows; tests/unit_tests/models/test_stream_failure_capture.py:210 covers a late HTTPException. The same record on the keepalive streams of /v1/responses and /v1/chat/completions is unchanged in this pull request.
Reproduced: a typed failure with one cause, raised after a ping, was saved with failure_id: null and no events, while the same failure before the ping kept its id and its cause. With commit 0d83184 the capture middleware passes the noted failure to the saved failure report (nemo_gym/models/model_call_capture.py:1679), so the late call selects the failure's Gym failure event, when it has one, with its causes, in ng_model_call_capture.calls and in the trajectory metadata. tests/unit_tests/models/test_stream_failure_capture.py:220 reads the row back from its JSON text, expects the id and the cause link in the saved call, and expects the episode's own selected failure unchanged. tests/unit_tests/rollouts/test_streamed_capture_reports.py:93 asserts the selected id in the saved call and in the trajectory metadata after a collection run. As for finding A, the /v1/responses and /v1/chat/completions streams are unchanged here.
The fix is commit 0d83184 of #6903, which this branch holds by a merge.
| if anthropic_body.get("top_p") is not None: | ||
| params["top_p"] = anthropic_body["top_p"] | ||
| if forward_reasoning_effort: | ||
| effort = (anthropic_body.get("output_config") or {}).get("effort") |
There was a problem hiding this comment.
NOTE (low risk, optional)
What I tested
I posted output_config: "high", ["effort"] and 3 with forwarding enabled in both stream modes.
What I found
The effort lookup raises AttributeError and returns HTTP 500 before calling the backend. This reported hardening gap affects malformed requests when forward_anthropic_reasoning_effort is enabled.
What I recommend
Consider requiring an object and returning a deliberate 4xx when forwarding is enabled. Add malformed-input tests while keeping disabled inputs ignored and valid efforts forwarded.
There was a problem hiding this comment.
Reproduced: with forward_anthropic_reasoning_effort on, an output_config of "high", ["effort"] or 3 raised AttributeError, and the route answered HTTP 500 in both stream modes without calling the backend. An effort outside the list of the pinned OpenAI SDK did the same through the validation of the Responses request. Commit c13b0e8 validates the field in the route before the conversion (_validate_forwarded_output_config, nemo_gym/models/base_responses_api_model.py:1172, called at nemo_gym/models/base_responses_api_model.py:1011) and refuses a value that is neither null nor an object with FastAPI's standard 422, as a /v1/responses body is refused, with output_config or output_config.effort as the location. With the setting off the field is still not read. The tests post the three values and two unlisted efforts in both stream modes and expect the 422, the location and no call of responses() (tests/unit_tests/models/test_responses_api_model_messages.py:166), and they expect 200 for the three values with the setting off (tests/unit_tests/models/test_responses_api_model_messages.py:186).
The fix is commit c13b0e8 of #6904, which this branch holds by a merge.
A streamed /v1/messages request with stream_keepalive_s has sent its HTTP status 200 before its backend call ends, so a later failure reaches the client as an error event. Model-call capture saved every such call as upstream_error with no selected failure. A 422 or a 429 of the backend then counted as a server fault, a timeout lost its category, and a typed failure lost its id and its causes, while the same failure before the first ping event was saved with them. note_stream_failure stores the failure in the request state, where the capture middleware already reads what a route notes. For a call with a noted failure the middleware takes the category from the expression that it uses for a failure that a route raises (_classify_failure), passes the failure to the saved failure report, and saves the HTTP status of the backend as upstream_status_code where the adapter noted none. status_code stays 200, the status that the client received. The status of an HTTPException is this server's own and is not saved as the backend's. Only the Messages route notes its failure. The keepalive streams of /v1/responses and /v1/chat/completions are saved as before. The tests send the same failure before and after the first keepalive event through the middlewares that run_webserver installs, for a 422, a 429, the error that the model client raises with its observed attempt as cause, a timeout and a typed failure. They compare the category, the server fault, the status of the backend and the failure events of the saved rows, and they state which failure the late call selects. One test covers a late HTTPException, and one reads a typed failure back from the saved row and checks that the episode keeps its own selected failure. Signed-off-by: alexandery <[email protected]> Co-Authored-By: Claude Fable 5.2 <[email protected]>
The keepalive Messages branch now saves a failure that arrives after a ping event with the category, the status of the backend and the failure report of the failure. The merge brings that state. Git merged every file without a conflict, and the lines that this branch adds and removes against the keepalive branch are the same as before the merge. Signed-off-by: alexandery <[email protected]> Co-Authored-By: Claude Fable 5.2 <[email protected]>
With forward_anthropic_reasoning_effort on, the conversion of a Messages request reads the effort of output_config. An output_config that is not an object raised AttributeError there, and an effort that the pinned OpenAI SDK does not list failed the validation of the Responses request, so the route answered HTTP 500 without calling the backend. The route now validates output_config before the conversion when the setting is on (_validate_forwarded_output_config). A value that is neither null nor an object, and an effort outside the SDK's list, are refused with FastAPI's standard 422, as a /v1/responses body is. The error names output_config or output_config.effort as its location. With the setting off the field is not read, as before. The tests post three values that are no object and two efforts that are not listed, streamed and not streamed, and expect the 422, the location and no call of responses(). With the setting off the same three values are answered with 200. Signed-off-by: alexandery <[email protected]> Co-Authored-By: Claude Fable 5.2 <[email protected]>
The effort forwarding branch holds two changes since the last merge. The keepalive Messages branch saves a failure that arrives after a ping event with the classification of the failure. The effort forwarding branch refuses a malformed output_config with 422 when the effort is forwarded. That branch added a sentence to the line that documents forward_anthropic_reasoning_effort in fern/versions/latest/pages/model-server/vllm.mdx, and this branch has the line of anthropic_nonleading_system_note directly below it. The merge keeps both. The lines that this branch adds and removes against the effort forwarding branch are the same as before the merge. Signed-off-by: alexandery <[email protected]> Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
/ok to test 100b547 |
|
/review reset=true |
yaoyu-33
left a comment
There was a problem hiding this comment.
The regression cases cover the two layouts I asked about: the converted system note follows all leading tool results and precedes the next user text, whether the caller sends one message or two. The converter also unwraps mid_conv_system text and drops empty wrappers. That addresses my review.
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
LGTM, but please take a look at the following findings:
Review generated by codex. This was a full review. Request a full review with /review reset=true.
| await asyncio.gather(call, return_exceptions=True) | ||
|
|
||
| assert [message.get("body") for message in sent[1:]] == [ping, message_start] | ||
| assert sent_at_publication == [2], "published before the message leaves" |
There was a problem hiding this comment.
NOTE (low risk, optional)
What I tested
I read this test and ran a Messages checkpoint probe with a real ledger on CPU.
What I found
This assertion counts a publish() call, but ticket.capture is absent. publish() returns without writing, so this assertion cannot detect a missing deferred row. The probe writes one row successfully.
What I recommend
Consider extending _staged_call for this Messages case with a ledger. Assert zero rows while paused and one committed row before the answer leaves.
There was a problem hiding this comment.
Agreed: the assertion counts the publish() call, and without ticket.capture that call writes nothing, so the test cannot detect a missing deferred row. The test belongs to #6903, which this branch contains. I will extend _staged_call for the Messages case with a ledger there, with zero rows while the call is paused and one committed row before the answer leaves, in the next push to #6903, so that the two approved branches above it do not change for an optional note.
There was a problem hiding this comment.
Done in 9b1db2a on #6903. test_messages_ping_events_are_liveness_not_the_answer now sends its call through the capture middleware with a file ledger. It expects no ledger row while the checkpoint holds the call and one committed row before the first event of the message leaves, and it fails when the gate does not write the deferred row.
Signed-off-by: svcnemo-autobot <[email protected]>
|
/ok to test 946db97 |
|
The repository's automation merged |
What does this PR do?
This PR follows #6904. Until that one is merged, the diff of this PR also shows its commits.
An Anthropic Messages request can hold a
systemmessage after messages of another role. Without--bare, Claude Code 2.1.312 describes its environment in such a message after the prompt. The Messages route of a model server passes it on with its role, so the backend receives a system message after a user message, which a chat template can refuse. This PR adds a setting that hands such a message to the backend as a user message. It serves a Claude Code session behind a model whose chat template accepts a system message only at the start.What changes:
anthropic_nonleading_system_note, unset by default.systemmessage that follows a message of another role becomes a user message. That message begins with the text of the setting in a text block of its own, and the blocks of the system message follow. The text blocks that amid_conv_systemblock wraps take the place of that block, and a system message that is left without a block is dropped.What does not change: without the setting every system message is passed on with its role.
fold_nonleading_system_messagesofvllm_model, proposed in #4010, names the same messages. It changes the role alone, for the chat messages of every route of that server, and it coversdevelopermessages too. This setting applies to the Messages route of every model server, adds the text, and keeps tool results behind their tool calls.Validation
pytest tests/unit_tests/models: 2811 passed, where the base branch has 2797.pytest responses_api_models/vllm_model: 1317 passed, as on the base branch.ruff checkandruff format --check(ruff 0.9.9) on the changed Python files: no finding.pre-commit run --all-fileswas not run. Its box below is unticked.anthropic_converter.pyandbase_responses_api_model.pyof the base branch.Rollouts
One task ran with a real model at an earlier head of this branch and at
main:vllm_model,claude_code_agentwith Claude Code 2.1.312 andbare: false,single_agent_turn_legacyand a Docker sandbox ofubuntu:24.04. The model is an OpenAI model behind an OpenAI-compatible endpoint. A process in front of the endpoint recorded the role of each message that the model server sent.systemmessage.mainthe endpoint received the rolessystem,user,systemin the first request.system,user,user, and the third message begins with the text of the setting.healthyin both rollouts. This endpoint accepts a system message after a user message, so the rollouts show the request and not a refusal.With
--bare, the agent's default, Claude Code sent no such message. No request held a system message in front of tool results. The unit tests cover that placement.Compatibility and benchmark impact
None. The setting is new and unset by default.
Checklist
pre-commit run --all-files) (so CI lint/format checks pass).git commit -s) (so the DCO check passes).🤖 Generated with Claude Code