Skip to content

Conversation

@pcastonguay
Copy link
Collaborator

@pcastonguay pcastonguay commented Oct 1, 2025

Summary by CodeRabbit

  • New Features

    • Added ability to cancel in-flight KV cache transfer requests.
    • Introduced readiness signaling across sender/receiver and agent connections.
    • Exposed cancel_request in Python bindings and executor interfaces.
  • Refactor

    • Centralized cache-transfer error detection and handling in the executor.
    • Streamlined synchronization and locking behavior during transfer and cancellation.
  • Tests

    • Added unit tests for notification/serialization paths, including readiness signals.
    • Added test covering canceling a context transfer mid-flight and subsequent request behavior.

Description

Test Coverage

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

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

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

GitHub Bot Help

/bot [-h] ['run', 'kill', 'skip', 'reuse-pipeline'] ...

Provide a user friendly way for developers to interact with a Jenkins server.

Run /bot [-h|--help] to print this help message.

See details below for each supported subcommand.

run [--reuse-test (optional)pipeline-id --disable-fail-fast --skip-test --stage-list "A10-PyTorch-1, xxx" --gpu-type "A30, H100_PCIe" --test-backend "pytorch, cpp" --add-multi-gpu-test --only-multi-gpu-test --disable-multi-gpu-test --post-merge --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" --detailed-log --debug(experimental)]

Launch build/test pipelines. All previously running jobs will be killed.

--reuse-test (optional)pipeline-id (OPTIONAL) : Allow the new pipeline to reuse build artifacts and skip successful test stages from a specified pipeline or the last pipeline if no pipeline-id is indicated. If the Git commit ID has changed, this option will be always ignored. The DEFAULT behavior of the bot is to reuse build artifacts and successful test results from the last pipeline.

--disable-reuse-test (OPTIONAL) : Explicitly prevent the pipeline from reusing build artifacts and skipping successful test stages from a previous pipeline. Ensure that all builds and tests are run regardless of previous successes.

--disable-fail-fast (OPTIONAL) : Disable fail fast on build/tests/infra failures.

--skip-test (OPTIONAL) : Skip all test stages, but still run build stages, package stages and sanity check stages. Note: Does NOT update GitHub check status.

--stage-list "A10-PyTorch-1, xxx" (OPTIONAL) : Only run the specified test stages. Examples: "A10-PyTorch-1, xxx". Note: Does NOT update GitHub check status.

--gpu-type "A30, H100_PCIe" (OPTIONAL) : Only run the test stages on the specified GPU types. Examples: "A30, H100_PCIe". Note: Does NOT update GitHub check status.

--test-backend "pytorch, cpp" (OPTIONAL) : Skip test stages which don't match the specified backends. Only support [pytorch, cpp, tensorrt, triton]. Examples: "pytorch, cpp" (does not run test stages with tensorrt or triton backend). Note: Does NOT update GitHub pipeline status.

--only-multi-gpu-test (OPTIONAL) : Only run the multi-GPU tests. Note: Does NOT update GitHub check status.

--disable-multi-gpu-test (OPTIONAL) : Disable the multi-GPU tests. Note: Does NOT update GitHub check status.

--add-multi-gpu-test (OPTIONAL) : Force run the multi-GPU tests in addition to running L0 pre-merge pipeline.

--post-merge (OPTIONAL) : Run the L0 post-merge pipeline instead of the ordinary L0 pre-merge pipeline.

--extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" (OPTIONAL) : Run the ordinary L0 pre-merge pipeline and specified test stages. Examples: --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx".

--detailed-log (OPTIONAL) : Enable flushing out all logs to the Jenkins console. This will significantly increase the log volume and may slow down the job.

--debug (OPTIONAL) : Experimental feature. Enable access to the CI container for debugging purpose. Note: Specify exactly one stage in the stage-list parameter to access the appropriate container environment. Note: Does NOT update GitHub check status.

For guidance on mapping tests to stage names, see docs/source/reference/ci-overview.md
and the scripts/test_to_stage_mapping.py helper.

kill

kill

Kill all running builds associated with pull request.

skip

skip --comment COMMENT

Skip testing for latest commit on pull request. --comment "Reason for skipping build/test" is required. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.

reuse-pipeline

reuse-pipeline

Reuse a previous pipeline to validate current commit. This action will also kill all currently running builds associated with the pull request. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.

Shunkang and others added 3 commits October 1, 2025 07:46
Signed-off-by: Shunkang <[email protected]>
Signed-off-by: Patrice Castonguay <[email protected]>
@pcastonguay pcastonguay requested review from a team as code owners October 1, 2025 14:48
@pcastonguay pcastonguay changed the title Cancel request pd [None][feat] Support for cancelling requests with disaggregation Oct 1, 2025
@pcastonguay
Copy link
Collaborator Author

Supersedes #6587

@pcastonguay
Copy link
Collaborator Author

/bot run --disable-fail-fast

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 1, 2025

📝 Walkthrough

Walkthrough

Adds request-cancellation and readiness-signal capabilities across KV cache transmission: new cancelRequest APIs at transceiver/sender/receiver layers, readiness signaling between agents, Python bindings and executor integration for cancellation, plus serialization support and tests. CacheTransceiver routes cancellations based on request type; executor attempts cancel during in-flight transmissions.

Changes

Cohort / File(s) Summary
Transceiver interfaces
cpp/include/tensorrt_llm/batch_manager/cacheTransceiver.h
Adds BaseCacheTransceiver::cancelRequest and CacheTransceiver override.
Transceiver impl routing
cpp/tensorrt_llm/batch_manager/cacheTransceiver.cpp
Implements CacheTransceiver::cancelRequest: delegates to sender for context-only, receiver for generation-only; otherwise returns false.
Data transceiver: sender/receiver logic
cpp/tensorrt_llm/batch_manager/dataTransceiver.h, cpp/tensorrt_llm/batch_manager/dataTransceiver.cpp
Adds cancelRequest to CacheSender/CacheReceiver; introduces readiness signaling (kREADY_SIGNAL_TAG, sendReadySignal, receiveReadySignal); tracks cancellations; adjusts locking; handles completion paths for cancelled vs non-cancelled requests; adds default process info.
Agent connection protocol
cpp/tensorrt_llm/executor/cache_transmission/agent_utils/connection.h, cpp/tensorrt_llm/executor/cache_transmission/agent_utils/connection.cpp
Adds ReadySignalInfo and integrates into NotificationInfo variant; serialization/deserialization and size handling; AgentConnection send/recv ready signal; templated waitForNotification; updates waitForSyncInfo; adds waitForReadySignal.
C++ Python bindings (nanobind/pybind)
cpp/tensorrt_llm/nanobind/batch_manager/cacheTransceiver.cpp, cpp/tensorrt_llm/pybind/batch_manager/cacheTransceiver.cpp
Exposes cancel_request on BaseCacheTransceiver; PyCacheTransceiver implements cancelRequest override.
Py torch executor bindings
tensorrt_llm/_torch/pyexecutor/kv_cache_transceiver.py
Adds abstract cancel_request and implementation delegating to underlying impl.
Executor cancellation/error handling
tensorrt_llm/_torch/pyexecutor/py_executor.py
Centralizes disagg transfer error checks; adds in-transmission detection; adds _try_cancel_request using kv_cache_transceiver.cancel_request; updates cancellation flow.
C++ serialization tests
cpp/tests/unit_tests/executor/serializeUtilsTest.cpp
Tests for RequestAndBufferInfo, ReadySignalInfo, NotificationSyncInfo, and NotificationInfo variants.
Python KV-cache tests
tests/unittest/others/test_kv_cache_transceiver.py
Adds cancel-in-transmission test; validates generation request transitions to DISAGG_TRANS_ERROR after prior context cancellation.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User as Executor
  participant CT as CacheTransceiver
  participant CS as CacheSender
  participant CR as CacheReceiver

  rect rgb(235,245,255)
  note over User,CT: Cancel request routing
  User->>CT: cancelRequest(req)
  alt Context-only request
    CT->>CS: cancelRequest(req)
    CS-->>CT: bool cancelled
  else Generation-only request
    CT->>CR: cancelRequest(req)
    CR-->>CT: bool cancelled
  else Other
    CT-->>User: false
  end
  CT-->>User: bool
  end
Loading
sequenceDiagram
  autonumber
  participant CS as CacheSender
  participant ACM as AgentConnectionManager
  participant AC as AgentConnection
  participant CR as CacheReceiver

  rect rgb(245,255,245)
  note over CS,CR: Readiness signaling
  CS->>AC: sendReadySignal(ctx, isReady)
  AC-->>ACM: notification(ReadySignalInfo)
  ACM->>CR: waitForReadySignal(remote, ReadySignalInfo)
  CR-->>ACM: aggregated isReady
  ACM-->>CR: return
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The pull request description remains the untouched template with placeholder comments and lacks any concrete summary of the changes, explanation of the implementation, or details on test coverage, leaving reviewers without the necessary context to understand or verify the work. Please replace the template placeholders with a clear summary of what was changed and why, detail which tests cover the new cancellation and readiness signaling code paths, and remove any unused template comments so that the PR description fully documents the work.
Docstring Coverage ⚠️ Warning Docstring coverage is 6.02% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title Check ✅ Passed The title “[None][feat] Support for cancelling requests with disaggregation” follows the repository’s tagging convention and concisely highlights the primary new feature of request cancellation in a disaggregated setting, making it clear to reviewers what the main change entails without unnecessary detail.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@tensorrt-cicd
Copy link
Collaborator

PR_Github #20468 [ run ] triggered by Bot

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
cpp/tests/unit_tests/executor/serializeUtilsTest.cpp (1)

2-2: Update copyright year to 2025.

The copyright header reflects 2023-2024, but this file is being modified in 2025.

Apply this diff:

-* SPDX-FileCopyrightText: Copyright (c) 2023-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+* SPDX-FileCopyrightText: Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.

Based on coding guidelines.

cpp/tensorrt_llm/nanobind/batch_manager/cacheTransceiver.cpp (1)

44-44: Fix NB_TRAMPOLINE count to include the new pure virtual.

You now have 7 NB_OVERRIDE_PURE methods (including cancelRequest) but NB_TRAMPOLINE is still set to 6. This can misconfigure the trampoline/vtable and break overrides.

Apply this diff:

-    NB_TRAMPOLINE(tb::BaseCacheTransceiver, 6);
+    NB_TRAMPOLINE(tb::BaseCacheTransceiver, 7);

Also applies to: 76-79

tensorrt_llm/_torch/pyexecutor/py_executor.py (1)

1893-1908: Always clear canceled request IDs after processing
Unconditionally invoke executor_request_queue.clear_canceled_req_ids() after the cancellation loop (not only when enable_attention_dp is true) to avoid accumulating stale IDs in non-ADP runs.

🧹 Nitpick comments (5)
cpp/tests/unit_tests/executor/serializeUtilsTest.cpp (1)

1073-1083: Consider reusing the existing serializeDeserialize template.

The new serializeDeserializeNotification helper duplicates logic already present in the generic serializeDeserialize template (lines 169-178). The only difference is the call to static member functions (T::serialize/T::deserialize) versus free functions.

If the notification types support the same serialization interface as other types, consider unifying under the existing template to reduce duplication.

cpp/tensorrt_llm/nanobind/batch_manager/cacheTransceiver.cpp (1)

81-81: Namespace end comment nit.

Prefer a precise comment for anonymous namespace:

-} // namespace
+} // anonymous namespace
cpp/tensorrt_llm/batch_manager/dataTransceiver.h (1)

18-18: Add project-standard include guards.

Guidelines require include guards named TRTLLM_DATATRANSCEIVER_H for headers. Keep pragma once if you like, but add guards for consistency.

+#ifndef TRTLLM_DATATRANSCEIVER_H
+#define TRTLLM_DATATRANSCEIVER_H
 #pragma once
 ...
 } // namespace tensorrt_llm::batch_manager
+
+#endif // TRTLLM_DATATRANSCEIVER_H

Please confirm whether this repository consistently uses include guards in other headers; if so, adopt the same pattern here. As per coding guidelines.

Also applies to: 311-311

tensorrt_llm/_torch/pyexecutor/py_executor.py (1)

1862-1882: Cancellation helper behavior looks correct; consider tiny polish.

Logic is clear: if no transceiver or not in transmission, allow cancel; otherwise delegate. Optionally add a brief docstring and return type hint for readability.

cpp/tensorrt_llm/batch_manager/dataTransceiver.cpp (1)

509-545: Ready-signal dispatch and conditional send look correct.

The isReady gate, signal dispatch, and cleanup paths are coherent. Minor nit: variable name shadowing for 'it' below this scope can be avoided for readability.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ba8abea and 3daa2fc.

📒 Files selected for processing (12)
  • cpp/include/tensorrt_llm/batch_manager/cacheTransceiver.h (2 hunks)
  • cpp/tensorrt_llm/batch_manager/cacheTransceiver.cpp (1 hunks)
  • cpp/tensorrt_llm/batch_manager/dataTransceiver.cpp (15 hunks)
  • cpp/tensorrt_llm/batch_manager/dataTransceiver.h (3 hunks)
  • cpp/tensorrt_llm/executor/cache_transmission/agent_utils/connection.cpp (7 hunks)
  • cpp/tensorrt_llm/executor/cache_transmission/agent_utils/connection.h (8 hunks)
  • cpp/tensorrt_llm/nanobind/batch_manager/cacheTransceiver.cpp (2 hunks)
  • cpp/tensorrt_llm/pybind/batch_manager/cacheTransceiver.cpp (2 hunks)
  • cpp/tests/unit_tests/executor/serializeUtilsTest.cpp (2 hunks)
  • tensorrt_llm/_torch/pyexecutor/kv_cache_transceiver.py (2 hunks)
  • tensorrt_llm/_torch/pyexecutor/py_executor.py (3 hunks)
  • tests/unittest/others/test_kv_cache_transceiver.py (3 hunks)
🧰 Additional context used
📓 Path-based instructions (8)
**/*.{h,hpp,hh,hxx,cpp,cxx,cc,cu,cuh}

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

**/*.{h,hpp,hh,hxx,cpp,cxx,cc,cu,cuh}: Namespace closing braces must include a trailing comment with the namespace name (e.g., '} // namespace foo').
Prefer const or constexpr variables over #define for constants.
Declare variables that are not modified after initialization as const.
Avoid magic literals in code; except for 0, nullptr, true, false. Use named constants for comparisons and logic.
Use Allman brace style for formatting.
Place the semicolon of an empty for/while loop on a new line.
Bodies of switch/while/do-while/for must be compound statements (brace-delimited), and if/else must always be followed by brace-delimited statements.
Type names (e.g., classes) must be CamelCase starting with an uppercase letter (e.g., FooBar).
Local variables, methods, and namespaces use lowerCamelCase (e.g., localFooBar).
Non-magic-number global variables that are non-static and not in an anonymous namespace must be lowerCamelCase prefixed with 'g' (e.g., gDontUseGlobalFoos).
Non-magic-number globals that are static or in an anonymous namespace use lowerCamelCase prefixed with 's' (e.g., sMutableStaticGlobal).
Locally visible static variables use lowerCamelCase with 's' prefix (e.g., static std::once_flag sFlag).
Private/protected member variables use 'm' prefix with CamelCase (e.g., mNbFooValues). Public members may omit, but 'm' is encouraged for clarity.
Constants (enums, global constants, static constants, and function-scope magic/literal constants) use uppercase SNAKE_CASE with 'k' prefix (e.g., kDIGIT_NUM).
Function-scope constants that are not magic numbers or literals are named like non-constant variables (e.g., bool const pass = a && b).
If macros are necessary, name them in UPPER_SNAKE_CASE (e.g., FOO_VERSION) and prefer constants over #define.
Use LLVM clang-format; wrap lines at a maximum of 120 columns; use '// clang-format off/on' sparingly with justification.
Use smart pointers for heap allocations; prefer unique_ptr for sole ownership, shared_ptr for shared...

Files:

  • cpp/include/tensorrt_llm/batch_manager/cacheTransceiver.h
  • cpp/tensorrt_llm/batch_manager/dataTransceiver.h
  • cpp/tensorrt_llm/batch_manager/dataTransceiver.cpp
  • cpp/tensorrt_llm/executor/cache_transmission/agent_utils/connection.h
  • cpp/tests/unit_tests/executor/serializeUtilsTest.cpp
  • cpp/tensorrt_llm/nanobind/batch_manager/cacheTransceiver.cpp
  • cpp/tensorrt_llm/batch_manager/cacheTransceiver.cpp
  • cpp/tensorrt_llm/pybind/batch_manager/cacheTransceiver.cpp
  • cpp/tensorrt_llm/executor/cache_transmission/agent_utils/connection.cpp
**/*.{cpp,cxx,cc,cu,h,hpp,hh,hxx,cuh}

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

C++ filenames should be lowerCamelCase (first letter lowercase) and must be case-insensitive unique within a compilation target.

Files:

  • cpp/include/tensorrt_llm/batch_manager/cacheTransceiver.h
  • cpp/tensorrt_llm/batch_manager/dataTransceiver.h
  • cpp/tensorrt_llm/batch_manager/dataTransceiver.cpp
  • cpp/tensorrt_llm/executor/cache_transmission/agent_utils/connection.h
  • cpp/tests/unit_tests/executor/serializeUtilsTest.cpp
  • cpp/tensorrt_llm/nanobind/batch_manager/cacheTransceiver.cpp
  • cpp/tensorrt_llm/batch_manager/cacheTransceiver.cpp
  • cpp/tensorrt_llm/pybind/batch_manager/cacheTransceiver.cpp
  • cpp/tensorrt_llm/executor/cache_transmission/agent_utils/connection.cpp
**/*.{h,hpp,hh,hxx,cpp,cxx,cc,cu,cuh,py}

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

Use only spaces, no tabs; indent with 4 spaces.

Files:

  • cpp/include/tensorrt_llm/batch_manager/cacheTransceiver.h
  • cpp/tensorrt_llm/batch_manager/dataTransceiver.h
  • tensorrt_llm/_torch/pyexecutor/kv_cache_transceiver.py
  • tests/unittest/others/test_kv_cache_transceiver.py
  • cpp/tensorrt_llm/batch_manager/dataTransceiver.cpp
  • tensorrt_llm/_torch/pyexecutor/py_executor.py
  • cpp/tensorrt_llm/executor/cache_transmission/agent_utils/connection.h
  • cpp/tests/unit_tests/executor/serializeUtilsTest.cpp
  • cpp/tensorrt_llm/nanobind/batch_manager/cacheTransceiver.cpp
  • cpp/tensorrt_llm/batch_manager/cacheTransceiver.cpp
  • cpp/tensorrt_llm/pybind/batch_manager/cacheTransceiver.cpp
  • cpp/tensorrt_llm/executor/cache_transmission/agent_utils/connection.cpp
**/*.{h,hpp,hh,hxx}

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

Document new class interfaces and function prototypes with Doxygen; use //! for single-line and //!< for members.

Files:

  • cpp/include/tensorrt_llm/batch_manager/cacheTransceiver.h
  • cpp/tensorrt_llm/batch_manager/dataTransceiver.h
  • cpp/tensorrt_llm/executor/cache_transmission/agent_utils/connection.h
**/*.{h,hpp,hh,hxx,cpp,cxx,cc}

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

**/*.{h,hpp,hh,hxx,cpp,cxx,cc}: Prefer anonymous namespaces over 'static' for internal linkage of functions.
All templates (class/function/member/static) must be instantiated at least once; non-POD classes should have private data members.

Files:

  • cpp/include/tensorrt_llm/batch_manager/cacheTransceiver.h
  • cpp/tensorrt_llm/batch_manager/dataTransceiver.h
  • cpp/tensorrt_llm/batch_manager/dataTransceiver.cpp
  • cpp/tensorrt_llm/executor/cache_transmission/agent_utils/connection.h
  • cpp/tests/unit_tests/executor/serializeUtilsTest.cpp
  • cpp/tensorrt_llm/nanobind/batch_manager/cacheTransceiver.cpp
  • cpp/tensorrt_llm/batch_manager/cacheTransceiver.cpp
  • cpp/tensorrt_llm/pybind/batch_manager/cacheTransceiver.cpp
  • cpp/tensorrt_llm/executor/cache_transmission/agent_utils/connection.cpp
**/*.{h,hpp,hh,hxx,cuh}

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

Use include guards named 'TRTLLM_<FILE_NAME_IN_CAPS_WITH_UNDERSCORES>_H' (no leading or trailing underscore; directory names excluded).

Files:

  • cpp/include/tensorrt_llm/batch_manager/cacheTransceiver.h
  • cpp/tensorrt_llm/batch_manager/dataTransceiver.h
  • cpp/tensorrt_llm/executor/cache_transmission/agent_utils/connection.h
**/*.{cpp,cxx,cc,h,hpp,hh,hxx,cu,cuh,py}

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

Prepend the NVIDIA Apache-2.0 copyright header with current year to the top of all source files (e.g., .cpp, .h, .cu, .py).

Files:

  • cpp/include/tensorrt_llm/batch_manager/cacheTransceiver.h
  • cpp/tensorrt_llm/batch_manager/dataTransceiver.h
  • tensorrt_llm/_torch/pyexecutor/kv_cache_transceiver.py
  • tests/unittest/others/test_kv_cache_transceiver.py
  • cpp/tensorrt_llm/batch_manager/dataTransceiver.cpp
  • tensorrt_llm/_torch/pyexecutor/py_executor.py
  • cpp/tensorrt_llm/executor/cache_transmission/agent_utils/connection.h
  • cpp/tests/unit_tests/executor/serializeUtilsTest.cpp
  • cpp/tensorrt_llm/nanobind/batch_manager/cacheTransceiver.cpp
  • cpp/tensorrt_llm/batch_manager/cacheTransceiver.cpp
  • cpp/tensorrt_llm/pybind/batch_manager/cacheTransceiver.cpp
  • cpp/tensorrt_llm/executor/cache_transmission/agent_utils/connection.cpp
**/*.py

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

**/*.py: Python code must target Python 3.8+.
Indent Python code with 4 spaces; do not use tabs.
Maintain module namespace when importing; prefer 'from package.subpackage import foo' then 'foo.SomeClass()' instead of importing the class directly.
Python filenames should be snake_case (e.g., some_file.py).
Python classes use PascalCase names.
Functions and methods use snake_case names.
Local variables use snake_case; prefix 'k' for variables that start with a number (e.g., k_99th_percentile).
Global variables use upper SNAKE_CASE prefixed with 'G' (e.g., G_MY_GLOBAL).
Constants use upper SNAKE_CASE (e.g., MY_CONSTANT).
Avoid shadowing variables from an outer scope.
Initialize all externally visible members of a class in the constructor.
Prefer docstrings for interfaces that may be used outside a file; comments for in-function or file-local interfaces.
Use Google-style docstrings for classes and functions (Sphinx-parsable).
Document attributes and variables inline so they render under the class/function docstring.
Avoid reflection when a simpler, explicit approach suffices (e.g., avoid dict(**locals()) patterns).
In try/except, catch the most specific exceptions possible.
For duck-typing try/except, keep the try body minimal and use else for the main logic.

Files:

  • tensorrt_llm/_torch/pyexecutor/kv_cache_transceiver.py
  • tests/unittest/others/test_kv_cache_transceiver.py
  • tensorrt_llm/_torch/pyexecutor/py_executor.py
🧠 Learnings (1)
📚 Learning: 2025-08-06T08:18:28.669Z
Learnt from: zhengd-nv
PR: NVIDIA/TensorRT-LLM#6633
File: cpp/tensorrt_llm/batch_manager/dataTransceiverImpl.cpp:145-155
Timestamp: 2025-08-06T08:18:28.669Z
Learning: In cpp/tensorrt_llm/batch_manager/dataTransceiverImpl.cpp, the existing `mMtxForMap` mutex in DataSenderImpl is sufficient to synchronize measurement file operations in the `release` method, as all file operations occur within the same critical section that protects the `mRequestToSession` map access.

Applied to files:

  • cpp/tensorrt_llm/batch_manager/dataTransceiver.cpp
🧬 Code graph analysis (12)
cpp/include/tensorrt_llm/batch_manager/cacheTransceiver.h (3)
cpp/tensorrt_llm/batch_manager/dataTransceiver.cpp (19)
  • cancelRequest (1120-1123)
  • cancelRequest (1120-1120)
  • cancelRequest (1153-1156)
  • cancelRequest (1153-1153)
  • llmRequest (267-267)
  • llmRequest (369-380)
  • llmRequest (369-369)
  • llmRequest (382-399)
  • llmRequest (382-382)
  • llmRequest (691-691)
  • llmRequest (697-697)
  • llmRequest (748-830)
  • llmRequest (748-748)
  • llmRequest (832-848)
  • llmRequest (832-832)
  • llmRequest (862-889)
  • llmRequest (862-862)
  • llmRequest (932-954)
  • llmRequest (932-932)
cpp/tensorrt_llm/batch_manager/cacheTransceiver.cpp (2)
  • cancelRequest (570-581)
  • cancelRequest (570-570)
cpp/tensorrt_llm/pybind/batch_manager/cacheTransceiver.cpp (1)
  • llmRequest (42-45)
cpp/tensorrt_llm/batch_manager/dataTransceiver.h (3)
cpp/tensorrt_llm/batch_manager/dataTransceiver.cpp (32)
  • cancelRequest (1120-1123)
  • cancelRequest (1120-1120)
  • cancelRequest (1153-1156)
  • cancelRequest (1153-1153)
  • llmRequest (267-267)
  • llmRequest (369-380)
  • llmRequest (369-369)
  • llmRequest (382-399)
  • llmRequest (382-382)
  • llmRequest (691-691)
  • llmRequest (697-697)
  • llmRequest (748-830)
  • llmRequest (748-748)
  • llmRequest (832-848)
  • llmRequest (832-832)
  • llmRequest (862-889)
  • llmRequest (862-862)
  • llmRequest (932-954)
  • llmRequest (932-932)
  • sendReadySignal (1125-1128)
  • sendReadySignal (1125-1125)
  • requestId (294-294)
  • requestId (301-318)
  • requestId (301-301)
  • requestId (401-423)
  • requestId (401-401)
  • receiveReadySignal (1158-1161)
  • receiveReadySignal (1158-1158)
  • session (731-746)
  • session (731-731)
  • session (891-916)
  • session (891-891)
cpp/tensorrt_llm/batch_manager/cacheTransceiver.cpp (2)
  • cancelRequest (570-581)
  • cancelRequest (570-570)
cpp/tensorrt_llm/executor/cache_transmission/agent_utils/connection.cpp (2)
  • sendReadySignal (183-190)
  • sendReadySignal (183-183)
tensorrt_llm/_torch/pyexecutor/kv_cache_transceiver.py (2)
tensorrt_llm/_torch/pyexecutor/py_executor.py (1)
  • cancel_request (405-411)
tensorrt_llm/_torch/pyexecutor/llm_request.py (1)
  • LlmRequest (293-467)
tests/unittest/others/test_kv_cache_transceiver.py (4)
tensorrt_llm/_torch/pyexecutor/llm_request.py (1)
  • LlmRequest (293-467)
cpp/include/tensorrt_llm/batch_manager/llmRequest.h (1)
  • LlmRequestState (45-207)
tensorrt_llm/_torch/distributed/communicator.py (1)
  • MPIDist (325-389)
tensorrt_llm/_torch/pyexecutor/kv_cache_transceiver.py (7)
  • create_kv_cache_transceiver (31-64)
  • respond_and_send_async (70-71)
  • respond_and_send_async (119-120)
  • cancel_request (94-95)
  • cancel_request (137-138)
  • request_and_receive_async (78-79)
  • request_and_receive_async (125-126)
cpp/tensorrt_llm/batch_manager/dataTransceiver.cpp (3)
cpp/tensorrt_llm/executor/cache_transmission/agent_utils/connection.cpp (2)
  • sendReadySignal (183-190)
  • sendReadySignal (183-183)
cpp/tensorrt_llm/common/envUtils.cpp (2)
  • getEnvRequestKVCacheConcurrent (321-325)
  • getEnvRequestKVCacheConcurrent (321-321)
cpp/tensorrt_llm/batch_manager/cacheTransceiver.cpp (2)
  • cancelRequest (570-581)
  • cancelRequest (570-570)
tensorrt_llm/_torch/pyexecutor/py_executor.py (3)
cpp/include/tensorrt_llm/batch_manager/llmRequest.h (1)
  • LlmRequestState (45-207)
tensorrt_llm/_torch/pyexecutor/kv_cache_transceiver.py (6)
  • check_context_transfer_status (82-83)
  • check_context_transfer_status (128-129)
  • check_gen_transfer_status (86-87)
  • check_gen_transfer_status (131-132)
  • cancel_request (94-95)
  • cancel_request (137-138)
tensorrt_llm/_torch/pyexecutor/executor_request_queue.py (1)
  • get_canceled_req_ids (762-763)
cpp/tensorrt_llm/executor/cache_transmission/agent_utils/connection.h (2)
cpp/tensorrt_llm/batch_manager/dataTransceiver.h (1)
  • executor (230-309)
cpp/tensorrt_llm/executor/cache_transmission/agent_utils/connection.cpp (14)
  • deserialize (85-92)
  • deserialize (85-85)
  • sendReadySignal (183-190)
  • sendReadySignal (183-183)
  • recvReadySignal (192-197)
  • recvReadySignal (192-192)
  • waitForNotification (450-526)
  • waitForNotification (450-450)
  • waitForNotification (529-530)
  • waitForNotification (531-532)
  • waitForSyncInfo (534-537)
  • waitForSyncInfo (534-534)
  • waitForReadySignal (539-542)
  • waitForReadySignal (539-539)
cpp/tests/unit_tests/executor/serializeUtilsTest.cpp (3)
cpp/tensorrt_llm/batch_manager/dataTransceiver.cpp (3)
  • iss (337-337)
  • deserialize (221-229)
  • deserialize (221-221)
cpp/tensorrt_llm/executor/cache_transmission/agent_utils/connection.cpp (2)
  • deserialize (85-92)
  • deserialize (85-85)
cpp/tensorrt_llm/executor/cache_transmission/agent_utils/connection.h (1)
  • deserialize (163-186)
cpp/tensorrt_llm/nanobind/batch_manager/cacheTransceiver.cpp (3)
cpp/tensorrt_llm/batch_manager/dataTransceiver.cpp (12)
  • llmRequest (267-267)
  • llmRequest (369-380)
  • llmRequest (369-369)
  • llmRequest (382-399)
  • llmRequest (382-382)
  • llmRequest (691-691)
  • llmRequest (697-697)
  • llmRequest (748-830)
  • cancelRequest (1120-1123)
  • cancelRequest (1120-1120)
  • cancelRequest (1153-1156)
  • cancelRequest (1153-1153)
cpp/tensorrt_llm/pybind/batch_manager/cacheTransceiver.cpp (8)
  • llmRequest (42-45)
  • llmRequest (42-42)
  • llmRequest (47-50)
  • llmRequest (47-47)
  • llmRequest (52-55)
  • llmRequest (52-52)
  • llmRequest (72-75)
  • llmRequest (72-72)
cpp/tensorrt_llm/batch_manager/cacheTransceiver.cpp (2)
  • cancelRequest (570-581)
  • cancelRequest (570-570)
cpp/tensorrt_llm/batch_manager/cacheTransceiver.cpp (1)
cpp/tensorrt_llm/batch_manager/dataTransceiver.cpp (19)
  • cancelRequest (1120-1123)
  • cancelRequest (1120-1120)
  • cancelRequest (1153-1156)
  • cancelRequest (1153-1153)
  • llmRequest (267-267)
  • llmRequest (369-380)
  • llmRequest (369-369)
  • llmRequest (382-399)
  • llmRequest (382-382)
  • llmRequest (691-691)
  • llmRequest (697-697)
  • llmRequest (748-830)
  • llmRequest (748-748)
  • llmRequest (832-848)
  • llmRequest (832-832)
  • llmRequest (862-889)
  • llmRequest (862-862)
  • llmRequest (932-954)
  • llmRequest (932-932)
cpp/tensorrt_llm/pybind/batch_manager/cacheTransceiver.cpp (2)
cpp/tensorrt_llm/nanobind/batch_manager/cacheTransceiver.cpp (8)
  • llmRequest (46-49)
  • llmRequest (46-46)
  • llmRequest (51-54)
  • llmRequest (51-51)
  • llmRequest (56-59)
  • llmRequest (56-56)
  • llmRequest (76-79)
  • llmRequest (76-76)
cpp/tensorrt_llm/batch_manager/cacheTransceiver.cpp (4)
  • checkGenTransferComplete (565-568)
  • checkGenTransferComplete (565-565)
  • cancelRequest (570-581)
  • cancelRequest (570-570)
cpp/tensorrt_llm/executor/cache_transmission/agent_utils/connection.cpp (2)
cpp/tensorrt_llm/batch_manager/dataTransceiver.cpp (10)
  • sendReadySignal (1125-1128)
  • sendReadySignal (1125-1125)
  • serialize (212-219)
  • serialize (212-212)
  • deserialize (221-229)
  • deserialize (221-221)
  • it (500-547)
  • it (500-500)
  • it (630-641)
  • it (630-630)
cpp/tensorrt_llm/executor/cache_transmission/agent_utils/connection.h (1)
  • deserialize (163-186)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Pre-commit Check
🔇 Additional comments (12)
cpp/tests/unit_tests/executor/serializeUtilsTest.cpp (1)

1085-1238: LGTM! Comprehensive serialization tests.

The new test cases for RequestAndBufferInfo, ReadySignalInfo, NotificationSyncInfo, and NotificationInfo provide thorough coverage of round-trip serialization/deserialization, including edge cases like nullopt metadata and empty strings.

cpp/include/tensorrt_llm/batch_manager/cacheTransceiver.h (2)

75-75: LGTM! Consistent API addition.

The pure virtual cancelRequest method is correctly declared in the base class interface, following the same pattern as other virtual methods.


116-116: LGTM! Proper override declaration.

The override is correctly declared with the override keyword and matches the base class signature.

cpp/tensorrt_llm/pybind/batch_manager/cacheTransceiver.cpp (2)

72-75: LGTM! Proper pybind11 trampoline implementation.

The cancelRequest override correctly uses PYBIND11_OVERRIDE_PURE to forward calls to Python implementations, consistent with other pure virtual overrides in this trampoline class.


88-88: LGTM! Python binding correctly exposed.

The cancel_request binding follows Python naming conventions (snake_case) and is consistent with other method bindings in this class.

cpp/tensorrt_llm/batch_manager/cacheTransceiver.cpp (1)

570-581: LGTM! Clear cancellation routing logic.

The implementation correctly routes cancellation to the appropriate component based on request type. The branching is straightforward and matches the expected behavior.

Consider whether a null check for llmRequest is needed. The method signature doesn't indicate nullability, but if callers might pass nullptr, add a guard:

bool CacheTransceiver::cancelRequest(LlmRequest* llmRequest)
{
    if (!llmRequest)
    {
        return false;
    }
    // ... existing logic
}

Verify whether other methods in this class (e.g., respondAndSendAsync, requestAndReceiveSync) perform null checks, and apply consistent handling.

tensorrt_llm/_torch/pyexecutor/kv_cache_transceiver.py (2)

93-95: LGTM! Abstract method correctly declared.

The cancel_request abstract method is properly decorated and follows the same pattern as other abstract methods in the KvCacheTransceiver ABC.


137-138: LGTM! Clean delegation to C++ implementation.

The concrete implementation correctly delegates to the underlying C++ binding, consistent with other methods in BindKvCacheTransceiver.

cpp/tensorrt_llm/batch_manager/dataTransceiver.h (1)

147-148: READY_SIGNAL tag addition looks good.

kREADY_SIGNAL_TAG introduces an explicit named constant (avoids magic numbers). LGTM.

tensorrt_llm/_torch/pyexecutor/py_executor.py (1)

1664-1669: Good centralization of cache-transfer error handling.

_new helpers and call sites simplify logic and keep behavior consistent. LGTM.

Also applies to: 1670-1677, 1681-1687

cpp/tensorrt_llm/batch_manager/dataTransceiver.cpp (2)

382-399: Sender-side cancel path is safe under mSenderMutex.

Queue-check and exclusion of the current request prevent mid-send cancellation. LGTM.


940-947: Receiver marks canceled via ready-signal as DISAGG_TRANS_ERROR.

This aligns with the Python-side consolidated error handler. LGTM.

@tensorrt-cicd
Copy link
Collaborator

PR_Github #20468 [ run ] completed with state SUCCESS
/LLM/main/L0_MergeRequest_PR pipeline #15434 completed with status: 'FAILURE'

@pcastonguay
Copy link
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd
Copy link
Collaborator

PR_Github #20487 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #20487 [ run ] completed with state SUCCESS
/LLM/main/L0_MergeRequest_PR pipeline #15452 completed with status: 'SUCCESS'
Pipeline passed with automatic retried tests. Check the rerun report for details.

@achartier achartier merged commit fefa7d8 into NVIDIA:main Oct 2, 2025
8 of 11 checks passed
evezhier pushed a commit to evezhier/TensorRT-LLM that referenced this pull request Oct 3, 2025
…DIA#8114)

Signed-off-by: Shunkang <[email protected]>
Signed-off-by: Patrice Castonguay <[email protected]>
Co-authored-by: Shunkang <[email protected]>
faradawn pushed a commit to faradawn/TensorRT-LLM that referenced this pull request Oct 3, 2025
…DIA#8114)

Signed-off-by: Shunkang <[email protected]>
Signed-off-by: Patrice Castonguay <[email protected]>
Co-authored-by: Shunkang <[email protected]>
Signed-off-by: Faradawn Yang <[email protected]>
dominicshanshan pushed a commit to dominicshanshan/TensorRT-LLM that referenced this pull request Nov 1, 2025
…DIA#8114)

Signed-off-by: Shunkang <[email protected]>
Signed-off-by: Patrice Castonguay <[email protected]>
Co-authored-by: Shunkang <[email protected]>
dominicshanshan pushed a commit to dominicshanshan/TensorRT-LLM that referenced this pull request Nov 3, 2025
…DIA#8114)

Signed-off-by: Shunkang <[email protected]>
Signed-off-by: Patrice Castonguay <[email protected]>
Co-authored-by: Shunkang <[email protected]>
dominicshanshan pushed a commit to dominicshanshan/TensorRT-LLM that referenced this pull request Nov 3, 2025
…DIA#8114)

Signed-off-by: Shunkang <[email protected]>
Signed-off-by: Patrice Castonguay <[email protected]>
Co-authored-by: Shunkang <[email protected]>
dominicshanshan pushed a commit to dominicshanshan/TensorRT-LLM that referenced this pull request Nov 3, 2025
…DIA#8114)

Signed-off-by: Shunkang <[email protected]>
Signed-off-by: Patrice Castonguay <[email protected]>
Co-authored-by: Shunkang <[email protected]>
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.

4 participants