Skip to content

[TRTLLM-17083][feat] Cancel paired GEN on CTX failure or cancellation - #20491

Merged
chienchunhung merged 2 commits into
NVIDIA:mainfrom
chienchunhung:dev/pact-early-paired-cancellation
Oct 31, 2026
Merged

chienchunhung merged 2 commits into
NVIDIA:mainfrom
chienchunhung:dev/pact-early-paired-cancellation

Conversation

@chienchunhung

@chienchunhung chienchunhung commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Generation-first serving can leave one worker waiting after its paired request fails or the caller cancels. Cancel and drain pending sibling work while preserving worker errors and already-completed GEN responses.

Scope

  • Paired orchestration watches both legs, cancels pending work on failure/cancellation, and preserves completed non-streaming GEN responses without swallowing cancellation.
  • SSE observation detects completion and Responses API errors without altering forwarded bytes; incremental scanning and a mutable buffer avoid repeated copying/scanning of fragmented large events.
  • HTTP diagnostics preserve worker status and a bounded 2,048-byte streaming error prefix; streaming status errors remain non-retryable.
  • Delegated placement cleanup drains cancelled selection before queuing /finish with the original request ID, including content-key selection, without dispatching inference.

HTTP cancellation does not prove physical KV quiescence or authorize memory reuse. Other retry behavior, including main's safeguards from #20938, is unchanged; coordinated paired retries remain separate work. Coordinator cleanup retains asynchronous expiry fallback on outages/queue overflow; local timeout does not fence remote selection.

Verification

Current head: ca7ca1e5bda9b5f37da532b63e73297288029290.

  • Service tests cover failure/cancellation races, completed responses and fragmented SSE. Five new SSE cases cover a 1 MiB event's scan bound, split delimiters and buffered error tails.
  • Client tests cover diagnostics and retry compatibility; seven real-HTTP cases check abort delivery/reservation release, and ten router cases check cancellation/selection races.
  • Historical native evidence at 708ff2707d: CI #66922 passed 407 tests on x86 and 407 on ARM across these four modules. These are module results, not a full-pipeline pass or verification of the new SSE fix.
  • Current-head full self-review, independent review and applicable pre-commit checks passed. Native targeted execution was blocked by unavailable PyTorch. Full CI requested with fail-fast disabled; Blossom is queued for authorization/scanning, so Jenkins launch and test results remain pending.

Notes

Complements #20459 on release/1.3; this PR targets main. #20702 handles idle-worker cancellation separately; physical retirement safeguards such as #19674 remain necessary.

Unchanged follow-up: streaming CTX placement acquired before GEN selection can remain until expiry if cancellation occurs before CTX dispatch.

  • Reviewed the contribution checklist; scope and verification limitations are documented.

@chienchunhung chienchunhung changed the title [None][fix] Cancel paired GEN requests when CTX terminates [None][fix] Cancel paired GEN on CTX failure or cancellation Oct 16, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #78549 [ run ] triggered by Bot. Commit: 4df975b Link to invocation

@chienchunhung chienchunhung changed the title [None][fix] Cancel paired GEN on CTX failure or cancellation [TRTLLM-17083[fix] Cancel paired GEN on CTX failure or cancellation Oct 16, 2026
@chienchunhung chienchunhung changed the title [TRTLLM-17083[fix] Cancel paired GEN on CTX failure or cancellation [TRTLLM-17083][feature] Cancel paired GEN on CTX failure or cancellation Oct 16, 2026
@chienchunhung chienchunhung changed the title [TRTLLM-17083][feature] Cancel paired GEN on CTX failure or cancellation [TRTLLM-17083][feat] Cancel paired GEN on CTX failure or cancellation Oct 16, 2026
@chienchunhung
chienchunhung marked this pull request as ready for review October 16, 2026 22:54
@chienchunhung
chienchunhung requested review from a team as code owners October 16, 2026 22:54
@coderabbitai

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

The HTTP client now handles errors for streaming and non-streaming responses. The generation-first service coordinates context and generation requests, detects in-band generation SSE errors, and cleans up unfinished tasks.

Changes

Paired request handling

Layer / File(s) Summary
Streaming coordination and SSE error detection
tensorrt_llm/serve/openai_disagg_service.py, tests/unittest/disaggregated/test_openai_disagg_service.py
The service observes complete generation SSE error events across chunks while preserving the original stream. It runs context and generation work concurrently and cancels pending context work when it detects a generation error. Tests cover event parsing, stream forwarding, failures, and cancellation.
Non-streaming coordination and cleanup
tensorrt_llm/serve/openai_disagg_service.py, tests/unittest/disaggregated/test_openai_disagg_service.py, tests/unittest/disaggregated/test_paired_request_cancellation.py
The service can return a completed generation response after a context failure. Other failures and cancellations remain observable, and unfinished tasks are cancelled and drained. Tests cover task outcomes and paired worker cancellation.

HTTP client error responses

Layer / File(s) Summary
Shared HTTP status handling
tensorrt_llm/serve/openai_client.py, tests/unittest/disaggregated/test_disagg_openai_client.py
The client handles HTTP status errors before the streaming and non-streaming response branches. Streaming diagnostic reads are limited to 2048 bytes. Read errors after a streaming rejection propagate without retry. Tests check error details, retry behavior, and request cleanup.

Priority: Normal

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant OpenAIDisaggService
  participant ContextRequest
  participant GenerationRequest
  Client->>OpenAIDisaggService: Send generation-first streaming request
  OpenAIDisaggService->>ContextRequest: Start context request
  OpenAIDisaggService->>GenerationRequest: Start generation stream
  GenerationRequest-->>OpenAIDisaggService: Forward chunks and inspect SSE events
  OpenAIDisaggService->>ContextRequest: Cancel after detecting a generation error event
  OpenAIDisaggService-->>Client: Return generation stream
Loading
Merge Risk: Low · up to 9edf8

Rejected streaming responses now read a bounded error body, and paired work is cancelled on failure. A short worker error body that arrives in several fragments may be cut off in the reported error message. This does not affect the success path or cancellation behavior, so the change is mergeable with a small follow-up.

Pre-merge checks: Passed 4
Check name Status Explanation
Title check Passed The title clearly identifies the main change: canceling paired GEN work when CTX fails or is canceled. It uses the required ticket and type format and is concise.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description is complete and relevant. It explains the problem, solution scope, limitations, test coverage, CI status, and checklist review. It uses equivalent headings instead of the template's ex…
Full details: Description check

Explanation

The description is complete and relevant. It explains the problem, solution scope, limitations, test coverage, CI status, and checklist review. It uses equivalent headings instead of the template's exact "Description" and "Test Coverage" headings, but the required information is present.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #78549 [ run ] completed with state FAILURE. Commit: 4df975b
/LLM/main/L0_MergeRequest_PR pipeline #64727 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@mikeiovine mikeiovine left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Stamp on behalf of runtime devs, delegating proper review to @NVIDIA/trt-llm-disagg-devs

@chienchunhung
chienchunhung force-pushed the dev/pact-early-paired-cancellation branch from 4df975b to f870cd4 Compare October 20, 2026 00:04

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #79059 [ run ] triggered by Bot. Commit: f870cd4 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #79059 [ run ] completed with state FAILURE. Commit: f870cd4
/LLM/main/L0_MergeRequest_PR pipeline #65127 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@chienchunhung

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #79328 [ run ] triggered by Bot. Commit: f870cd4 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #79328 [ run ] completed with state SUCCESS. Commit: f870cd4
/LLM/main/L0_MergeRequest_PR pipeline #65335 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@chienchunhung

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@nv-xtf nv-xtf left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #80780 [ run ] completed with state SUCCESS. Commit: 41e8f0a
/LLM/main/L0_MergeRequest_PR pipeline #66520 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

Signed-off-by: Chien-Chun Hung <2679986+chienchunhung@users.noreply.github.com>
@chienchunhung
chienchunhung force-pushed the dev/pact-early-paired-cancellation branch from 41e8f0a to 708ff27 Compare October 28, 2026 18:48

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #81232 [ run ] triggered by Bot. Commit: 708ff27 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #81232 [ run ] completed with state FAILURE. Commit: 708ff27
/LLM/main/L0_MergeRequest_PR pipeline #66922 completed with status: 'FAILURE'

CI Report

⚠️ Resource Maintenance — Test Coverage Reduced:

Resource maintenance in LLM/main/L0_Test-x86_64-Single-GPU #10093: L40S-PyTorch-2 is temporarily paused due to Kubernetes agent provisioning and node issues.
Affected stages:
L40S-PyTorch-2

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #81475 [ run ] triggered by Bot. Commit: 708ff27 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #81475 [ run ] completed with state SUCCESS. Commit: 708ff27
/LLM/main/L0_MergeRequest_PR pipeline #67146 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

Signed-off-by: Chien-Chun Hung <2679986+chienchunhung@users.noreply.github.com>
@chienchunhung
chienchunhung force-pushed the dev/pact-early-paired-cancellation branch from 708ff27 to ca7ca1e Compare October 30, 2026 17:55

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@chienchunhung
chienchunhung enabled auto-merge (squash) October 30, 2026 18:02
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #81727 [ run ] triggered by Bot. Commit: ca7ca1e Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #81727 [ run ] completed with state SUCCESS. Commit: ca7ca1e
/LLM/main/L0_MergeRequest_PR pipeline #67387 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #81778 [ run ] triggered by Bot. Commit: ca7ca1e Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #81778 [ run ] completed with state SUCCESS. Commit: ca7ca1e
/LLM/main/L0_MergeRequest_PR pipeline #67436 completed with status: 'SUCCESS'

CI Report

Link to invocation

@chienchunhung
chienchunhung merged commit 5ec25c5 into NVIDIA:main Oct 31, 2026
14 checks passed
SimengLiu-nv added a commit to SimengLiu-nv/TensorRT-LLM that referenced this pull request Nov 3, 2026
…t chunk with an HTTP error

A generation server whose KV-cache transfer fails raises in its stream
generator after the 200 headers. The disaggregated server relayed that
as a 200 whose body was cut off, so the client saw a truncated stream
instead of an error.

_wrap_entry_point now pulls a relayed stream's first chunk before it
sends the headers. A chat or completion stream that fails before its
first chunk reaches _handle_exception and becomes an HTTP error. The
returned relay is already started, so closing it before it is iterated
still closes the upstream stream and releases the router reservation.
Responses streams keep their 200 plus an `error` event, because
guard_responses_stream stays inside the first-chunk pull. /v1/messages
keeps sending its headers at once: its reframed stream pings until the
first chunk, and a failure before that chunk ends in an Anthropic
`error` event, as before. total_responses now counts a held stream only
once its first chunk arrived.

The client's retry rules for generation legs are main's (NVIDIA#20938, NVIDIA#20491).
The client tests gain the cases main does not cover: the chat and
Responses request kinds failing after the headers over a real
connection, the transient retry budget and TRTLLM_DISAGG_NO_RETRY for an
undelivered leg, and three more possibly-delivered errors.
disagg-serving.md describes the retry rules, including the
frontend-affinity fallback that TRTLLM_DISAGG_NO_RETRY does not disable.

Signed-off-by: Simeng Liu <simengl@nvidia.com>
SimengLiu-nv added a commit to SimengLiu-nv/TensorRT-LLM that referenced this pull request Nov 4, 2026
…t chunk with an HTTP error

A generation server whose KV-cache transfer fails raises in its stream
generator after the 200 headers. The disaggregated server relayed that
as a 200 whose body was cut off, so the client saw a truncated stream
instead of an error.

_wrap_entry_point now pulls a relayed stream's first chunk before it
sends the headers. A chat or completion stream that fails before its
first chunk reaches _handle_exception and becomes an HTTP error. The
returned relay is already started, so closing it before it is iterated
still closes the upstream stream and releases the router reservation.
Responses streams keep their 200 plus an `error` event, because
guard_responses_stream stays inside the first-chunk pull. /v1/messages
keeps sending its headers at once: its reframed stream pings until the
first chunk, and a failure before that chunk ends in an Anthropic
`error` event, as before. total_responses now counts a held stream only
once its first chunk arrived.

The client's retry rules for generation legs are main's (NVIDIA#20938, NVIDIA#20491).
The client tests gain the cases main does not cover: the chat and
Responses request kinds failing after the headers over a real
connection, the transient retry budget and TRTLLM_DISAGG_NO_RETRY for an
undelivered leg, and three more possibly-delivered errors.
disagg-serving.md describes the retry rules, including the
frontend-affinity fallback that TRTLLM_DISAGG_NO_RETRY does not disable.

Signed-off-by: Simeng Liu <simengl@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants