Repository navigation
[None][fix] Chat Completions: keep replayed tool calls in forwarded requests - #21155
JunyiXu-nv wants to merge 4 commits into
Conversation
…equests An assistant message's tool_calls is declared as an Iterable, which pydantic validates into a single-use iterator. The disaggregated orchestrator serializes a chat request to forward it, which consumes the iterator, so a resend after a failed attempt carries no tool calls. A client that rebuilds an assistant turn from a stream also keeps the streaming-only "index" key on each tool call. The OpenAI message types reject it, but only when the lazy tool_calls are read: the forwarded request silently leaves the call out, and a KV-cache-aware router cannot render the turn. Drop "index" from the tool calls of the request's messages before validation, and turn the validated tool calls into lists. Tool calls that fail the OpenAI types (object-valued function.arguments) stay lazy, so the aggregated chat route still reads them from the raw request body. Signed-off-by: JunyiXu-nv <[email protected]>
|
No actionable comments were generated in the recent review. WalkthroughChat completion request validation removes streaming-only ChangesTool-call request normalization
Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Bug fix Suggested reviewers: Merge Risk:
|
|
/bot run --disable-fail-fast |
|
PR_Github #81082 [ run ] triggered by Bot. Commit: |
|
PR_Github #81082 [ run ] completed with state
|
Local runtime validation remains incomplete; required matching-build and dependency CI remains pending. Signed-off-by: JunyiXu-nv <[email protected]>
|
/bot run |
|
PR_Github #85151 [ run ] triggered by Bot. Commit: |
|
PR_Github #85151 [ run ] completed with state
|
Local runtime validation remains incomplete; matching-build manifest/schema/API and native CI validation remains required. Signed-off-by: JunyiXu-nv <[email protected]>
|
/bot run |
|
PR_Github #85553 [ run ] triggered by Bot. Commit: |
|
PR_Github #85553 [ run ] completed with state
|
Signed-off-by: JunyiXu-nv <[email protected]>
|
/bot run |
|
PR_Github #87425 [ run ] triggered by Bot. Commit: |
|
PR_Github #87425 [ run ] completed with state
|
Description
A chat request whose history replays an assistant turn with tool calls can reach a disaggregated worker without those tool calls.
tool_callsas anIterable, which pydantic validates into a single-useValidatorIterator. The disaggregated orchestrator serializes the request each time it sends it to a worker (OpenAIHttpClient._post_with_retry), and the first serialization consumes the iterator: the resend after a failed attempt carriestool_calls: [], and the worker renders the turn without its tool calls. The Anthropic/v1/messagesroute on a disaggregated server builds the same chat request and is affected the same way.indexloses them on the first attempt. A client that rebuilds an assistant turn from a streamed response keepsindexon each tool call; only streamed tool-call deltas (ChoiceDeltaToolCall) have that key. The OpenAI message types reject it, buttool_callsis validated lazily, so the request is accepted. On a disaggregated server, serializing the request to forward it then leaves the call out without an error (with pydantic 2.11 and 2.13, the versions tried), and a KV-cache-aware router cannot render the turn and routes it on no token ids. The aggregated server is not affected: its chat route falls back to the raw request body.#19964 covered only the case where a router renders the request (and the call carries no
index):chat_utilswrites the materialized list back into the message.This PR fixes both in
ChatCompletionRequest:_drop_streaming_only_tool_call_index, amode="before"model validator, dropsindexfrom everymessages[*].tool_calls[*]before validation. The key has no meaning in a request, so it is dropped, not declared._materialize_lazy_message_fields, amode="wrap"validator onmessages, turns the validatedtool_callsinto lists, so every reader and every serialization sees the same calls. Tool calls that fail the OpenAI types (object-valuedfunction.arguments, as tau2-bench sends them) are left lazy as before, so the aggregated chat route still reads them from the raw request body instead of rejecting the request at validation; they are validated afresh for that, since the failed attempt consumed the first iterators.No API change: no field, default or YAML row changes. Behavior changes:
indexon a tool call of a request message is dropped.chat_utils._parse_assistant_message_content, which yields the same id, name and arguments; only the key order of the parsed call differs, which matters only to a chat template that serializes a whole call (none in this repository does). A custom (non-function) tool call in the history, which the chat route cannot render, is still answered with a 400; the message is nowtool_calls[0].function is required.instead of'function'.Not changed: tool calls that stay lazy (object-valued arguments) are still single-use, so forwarding such a request to a disaggregated worker still loses them, as on
main.Test Coverage
tests/unittest/disaggregated/test_disagg_openai_client.py::TestDisaggIdRegenOnRetry::test_retry_resends_the_tool_calls_of_a_replayed_turn[no_index|streamed_index](new): the first POST to the worker fails withaiohttp.ClientError, the second succeeds; both msgpack bodies carry the tool call, withoutindex. Onmain,no_indexsendstool_calls: []on the retry andstreamed_indexsendstool_calls: []on both attempts.tests/unittest/llmapi/apps/test_render_callers.py::TestRouterWriteBack::test_a_replayed_tool_call_index_is_dropped_and_its_calls_are_forwarded(new): a KV-cache-aware router renders a turn whose tool call carriesindexto the same token ids as the turn without it and forwards them; two dumps of the request are equal and carry the call withoutindex. Onmainthe router renders no ids.tests/unittest/llmapi/apps/test_render_callers.py::TestRouterWriteBack::test_object_valued_tool_arguments_are_routed_on_no_ids_not_on_a_partial_render(existing, unchanged) guards the lazy fallback: its request has object-valuedfunction.argumentsand must still validate.tests/unittest/llmapi/apps/test_chat_template_kwargs_guard.py::test_router_and_server_tool_call_tokenization_match(existing, updated): it pins which path eachfunction.argumentsshape takes, and asserted that strictly validated tool calls stay a lazy iterator, the behavior this PR removes. It now asserts that the strict model hands validated calls through as a list and leaves object-valued ones lazy; its router/server tokenization checks are unchanged.All three files are
cpu_onlyand already listed inl0_cpu.yml.Local runs with a CPU harness that stubs the compiled bindings:
mainthe 3 new cases and the updatedstring_arguments_strict_pathcase fail; the object-valued-arguments cases pass on both. On this branch all pass.cpu_onlyfile oftests/unittest/llmapi/appsandtests/unittest/disaggregated(74, leaving out three that need the compiled transfer bindings) plusapi_stability/test_serve_api.py:main3203 passed; this branch 3207 passed (the 3 new cases, andtest_transfer_ownership_regressions.py::test_cancel_after_publication_cannot_overtake_request_data, which failed once in themainrun and passes 3 of 3 times in isolation on both). The other 211 tests fail or error on both, nearly all because the harness stubs the compiled bindings; nothing that passes onmainfails here.indexfailsstreamed_indexand the router test; leavingtool_callslazy fails both retry cases; materializing without the lazy fallback fails the object-valued-arguments guard (the request is rejected at validation).PR Checklist
GitHub Bot Help
To see a list of available CI bot commands, please comment
/bot help.🤖 Generated with Claude Code
Dev Engineer Review
ChatCompletionRequestmessage validation removes the streaming-onlyindexkey from dictionary-valued tool calls before validation.tool_callsare materialized as lists. Repeated serialization and retries keep the calls.ValidationError, the validator reruns message validation on the original value. The existing raw-body fallback is kept.function.argumentsstay lazy so the aggregated chat route can read them from the raw body. The PR reports that disaggregated forwarding can still lose these calls. This is a known gap, not a fix.5cd788e: CI jobFAILURE, L0 pipelineUNSTABLE. The bot stated that multi-GPU tests require theci: full pre-merge approvedlabel.edf06b4: CI jobSUCCESS, L0 pipelineFAILURE. The bot requested investigation.49fe483: CI jobSUCCESS, L0 pipelineUNSTABLE. The bot repeated the multi-GPU label note.main. 211 other tests failed or errored on both, mostly from compiled-binding stubs.QA Engineer Review
Changed test files:
tests/unittest/disaggregated/test_disagg_openai_client.py: addsTestDisaggIdRegenOnRetry::test_retry_resends_the_tool_calls_of_a_replayed_turn, parameterized asno_indexandstreamed_index. Both retry attempts must serialize the tool call withoutindex.tests/unittest/llmapi/apps/test_render_callers.py: addsTestRouterWriteBack::test_a_replayed_tool_call_index_is_dropped_and_its_calls_are_forwarded. It checks token-ID parity with the call that has noindex, forwarding when worker fingerprints match, and stable serialization.tests/unittest/llmapi/apps/test_render_callers.py: addsTestRouterWriteBack::test_object_valued_tool_arguments_are_routed_on_no_ids_not_on_a_partial_render.tests/unittest/llmapi/apps/test_chat_template_kwargs_guard.py: updatestest_router_and_server_tool_call_tokenization_match. It builds a strictChatCompletionRequestand asserts thattool_callsis a list only when the input does not take the fallback path.Reported results:
mainand pass on this branch.Test-list placement: not verified. These are unit tests under
tests/unittest/. Thetest-db/andqa/lists were not checked.Gaps:
function.argumentsforwarding through disaggregated workers. The PR documents this path as lossy.Coverage verdict:
sufficientfor replayed tool calls with and withoutindex.needs follow-upfor object-valuedfunction.argumentsforwarding.Per-File QA Perspective
tensorrt_llm/serve/openai_protocol.py: Verify that request tool calls loseindex. Verify that validated calls stay stable across repeated serialization. Verify that invalid input still takes the raw-body fallback. Verify the changed error message for unsupported custom tool calls.tests/unittest/disaggregated/test_disagg_openai_client.py: Covers retry resend of replayed tool calls with and withoutindex. Test-list placement not verified.tests/unittest/llmapi/apps/test_render_callers.py: Covers router write-back,indexremoval, token-ID forwarding, object-valued arguments routing, and stable serialization. Test-list placement not verified.tests/unittest/llmapi/apps/test_chat_template_kwargs_guard.py: Covers strict-path tokenization with list-backedtool_callsand the fallback path. Test-list placement not verified.