Skip to content

[None][fix] Disaggregated Responses: a relayed stream cut before its terminal event ends with response.failed - #22034

Draft
JunyiXu-nv wants to merge 6 commits into
NVIDIA:mainfrom
JunyiXu-nv:dev-junyix-fix-disagg-responses-cut-relay-failed
Draft

JunyiXu-nv wants to merge 6 commits into
NVIDIA:mainfrom
JunyiXu-nv:dev-junyix-fix-disagg-responses-cut-relay-failed

Conversation

@JunyiXu-nv

Copy link
Copy Markdown
Collaborator

Stacked on #21452 ([None][fix] Disaggregated Responses: open the stream and keep it alive while the context phase runs): the first commits below belong to that PR and disappear from this diff when it merges; this PR's own change is the last commit.

Description

A streamed /v1/responses request through the disaggregated server whose context phase finishes within the start wait has the generation worker's own stream relayed as it is, response.created included. When that stream broke before its terminal event, the relay ended it with a bare error event: it holds no response of its own to report as failed, and the worker, being gone, sends no response.failed. A client waiting for a terminal response.* event saw none and had to read the transport error instead. This was seen in production agent traffic to a disaggregated Kimi K3 deployment: generation workers killed mid-stream by job preemption left relayed streams ending without a terminal response.* event; three such streams were reported by the client side. A stream the server opened itself because the context phase outlasted the wait already ends with error and response.failed (#21452); the relayed case was the one left.

The worker answers under the request's id, which the disaggregated server forwards to every worker, so the processor the server builds from the request already names the response the request names. Its get_stream_failed_events is now the terminal-events callback of the relayed-stream guard too, instead of stream_error_event: a cut relay ends with error and then response.failed for that response (status failed, no output, the cause and message in error), numbered on from the frames the worker sent. The processor is built before the fast-path return, which is the only reordering in the handler; a request no processor can be built from is answered by its pipeline as before, and a cut relay of it still ends on the bare error.

Behavior change: on the disaggregated server, a streamed Responses request whose context phase finished within the start wait and whose generation worker's stream fails before its terminal event now ends with error followed by response.failed, where it ended with error alone. The error event is unchanged. The response.failed snapshot is built from the request on this server: its id is the one the worker answers under (the same id as the worker's response.created), its status is failed, its output is empty and its error.code is server_error with the error event's message; its other fields (created_at, model, temperature, top_p, ...) are the request's as this server sees them and can differ from the worker's response.created, as they do for the stream the server opens itself when the context phase outlasts the wait. A worker stream that breaks before its first frame ends with error and response.failed for a response the client never saw created, where it ended on the bare error. Streams that complete, and every other route, are unchanged.

Test Coverage

tests/unittest/disaggregated/test_disagg_responses_api.py (CPU, no network; collected by l0_cpu.yml through unittest/disaggregated):

  • test_a_relayed_generation_stream_that_fails_ends_with_error_and_response_failed[context_first|generation_first]: a generation worker whose connection fails after its first output; the client receives the worker's opening and output, then error (upstream_error, ClientPayloadError) and response.failed whose response has the opened id, status failed, no output and error.code server_error, numbered 0 to 4.
  • test_a_cut_relay_with_no_processor_to_fail_the_response_ends_on_the_bare_error[context_first|generation_first]: with the processor made to fail on construction (ResponsesStreamingProcessor patched to raise ValueError; a request the processor itself rejects is rejected by the workers too, so no relayed stream of one exists), the cut relay still ends on the bare error, numbered as before.

The first test fails on the base (the stream ends after error, four events); the second passes on the base and pins the fallback. The whole file passes. GPU runs are left to CI.

Reviewers by CODEOWNERS: @NVIDIA/trt-llm-disagg-devs and @NVIDIA/trt-llm-runtime-devs (tensorrt_llm/serve/openai_disagg_server.py, tests/unittest/disaggregated), @NVIDIA/trt-llm-doc-owners (docs).

PR Checklist

Please review the following before submitting your PR:

  • PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.

  • PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.

  • Test cases are provided for new code paths (see test instructions)

  • Any new dependencies have been scanned for license and vulnerabilities

  • CODEOWNERS updated if ownership changes

  • Documentation updated as needed

  • Update tava architecture diagram if there is a significant design change in PR.

  • The reviewers assigned automatically/manually are appropriate for the PR.

  • Please check this after reviewing the above items as appropriate for this PR.

🤖 Generated with Claude Code

…e while the context phase runs

On the disaggregated server, a streamed /v1/responses request receives no
bytes at all, not even the HTTP status line, until the context phase is
done: the route awaits the pipeline before it creates the streaming
response, and the pipeline returns its stream only once the context worker
has answered, in both schedule orders. Queueing plus prefill of a long
agent prompt can take minutes, and a client or gateway that drops a stream
without a first event loses the request (Codex behind a gateway gives up
after about 120 s); its retry starts the prefill over. An aggregated server
sends response.created at once and repeats response.in_progress while the
stream is silent.

A streamed request now waits for its pipeline for at most
_RESPONSES_STREAM_START_WAIT_S (1 s). A pipeline that answers within the
wait is answered as before, its failures with their HTTP status. For one
still running, the stream starts with response.created and
response.in_progress built from the request, and
keep_responses_stream_alive repeats response.in_progress whenever the
stream is silent. The worker's stream follows without its own opening
events, numbered to continue the sequence the client has. The request id
is forwarded to the workers, so that they answer under the id the opening
named. A pipeline that fails after the stream started ends it with error
and response.failed, which carry the message of the HTTP error the request
would otherwise have received. A client that disconnects first cancels the
pipeline, and a cancelled context phase releases a generation server
reserved for the request.

Non-streamed requests and the other routes are unchanged.

Signed-off-by: JunyiXu-nv <[email protected]>
Describe in the disaggregated serving guide how a streamed /v1/responses
request whose context phase is still running gets its opening from the
server, and how a later failure is reported. Import AsyncIterator from
typing, with the module's other typing names.

Signed-off-by: JunyiXu-nv <[email protected]>
… its opening only

Once the server had opened a stream, the relay still passed the generation
worker's own keepalives, its repeats of response.in_progress, on to the
client. They carry the worker's response object, created on the worker's
clock, not the one the client was opened with, while an aggregated server
repeats the stream's first response.in_progress exactly. They also came on
top of the keepalives this server sends, so a silent worker had the client
kept alive twice.

The relay now drops every response.created and response.in_progress of the
worker's, wherever it comes. That loses nothing, since a worker's keepalive
repeats its own opening: the client is kept alive by this server alone,
with the opening's response.in_progress and the next sequence number.

Signed-off-by: JunyiXu-nv <[email protected]>
…er stream breaks, close it when abandoned

A delayed stream guards the generation worker's stream with the processor's
failed events, so a read failure before the terminal event ends the stream with
one error and one response.failed for the response it opened with, and the
stream then ends cleanly. A stream the pipeline answered with inside the start
wait keeps the bare error event. The delayed response closes the stream its
pipeline answered with however the response ends, also when the body never
started.

Signed-off-by: JunyiXu-nv <[email protected]>
…a late failure; always forward request_id

A context-length rejection that arrives after an opened Responses stream has
started now ends the stream with error and response.failed carrying
context_length_exceeded, the error response's own code, instead of
upstream_error and server_error, so agent clients can compact their history and
retry. response.failed is built the same way the in-stream over-length
rejection builds it, because the SDK's ResponseError does not list that code.
The body forwarded to a worker now always includes a Responses request's
request_id, replacing a self-assignment that only worked through pydantic's
fields-set tracking.

Signed-off-by: JunyiXu-nv <[email protected]>
…terminal event ends with response.failed

A streamed Responses request whose context phase finished within the start
wait has the generation worker's own stream relayed as it is. When that
stream broke before its terminal event, the relay ended it with a bare
error event: it held no response of its own to report as failed, and the
worker, being gone, sent no response.failed. A client waiting for a
terminal response.* event saw none. Seen in production agent traffic when
generation workers were killed mid-stream.

The worker answers under the request's id, which the server forwards to
every worker, so the processor the server builds from the request already
names the response the worker opened. Its stream-failed events are now the
relayed guard's terminal events too: a cut relay ends with error and then
response.failed for that response, status failed and no output, numbered
on from the frames the worker sent. The processor is built before the
fast-path return; a request no processor can be built from is answered by
its pipeline as before, and a cut relay of it still ends on the bare error.

Signed-off-by: JunyiXu-nv <[email protected]>

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant