Skip to content

[None][fix] Fix disagg KV cache assertion failures with enable_partial_reuse - #12641

Closed
achartier wants to merge 1 commit into
NVIDIA:mainfrom
achartier:fix/disagg-kv-cache-addnextblock-assertion
Closed

[None][fix] Fix disagg KV cache assertion failures with enable_partial_reuse#12641
achartier wants to merge 1 commit into
NVIDIA:mainfrom
achartier:fix/disagg-kv-cache-addnextblock-assertion

Conversation

@achartier

Copy link
Copy Markdown
Collaborator

@coderabbitai summary

Description

Fixes three chained assertion failures in disaggregated serving when enable_partial_reuse=True (the default) and requests lack a common prefix.

  1. Duplicate block IDs in storeBlocks (kvCacheManager.cpp): The same physical block can appear at multiple positions in a sequence's block list. storeBlocks now skips insertion when the block is already the current searchRoot, preventing self-referential tree corruption.

  2. addNextBlock silent no-op (kvCacheManager.cpp): After PR [TRTLLM-11159][feat] Wire KVCacheBlock to UnifiedBlockTree, replacing mPrevBlock/mNextBlocks with lookup-node pointers. #11919 replaced setPrevBlock() with lookup-node navigation, addNextBlock silently skipped attachment when a slot was occupied. Changed to evict-and-replace: detach the existing block and attach the new one, keeping getPrevBlock() consistent.

  3. fromReuseTree fallback (kvCacheUtils.h, cacheFormatter.cpp): When storeBlocks skips a duplicate, the reuse tree is incomplete. Changed fromReuseTree to return std::optional and fall back to fromAllBlockIds in getBlockRangeForSending. Resolves the existing TODO about handling missing blocks.

  4. Termination race (py_executor.py): When enable_partial_reuse_for_disagg was True, _handle_responses terminated requests without checking is_disagg_context_transmission_state, racing with the async CacheSender thread. Unified the termination guard to always check transmission state before terminating.

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

  • 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.

GitHub Bot Help

To see a list of available CI bot commands, please comment /bot help.

…l_reuse

Fixes three chained assertion failures in disaggregated serving when
enable_partial_reuse=True (the default) and requests lack a common prefix.

1. Duplicate block IDs in storeBlocks (kvCacheManager.cpp):
   The same physical block can appear at multiple positions in a
   sequence's block list. storeBlocks now skips insertion when the block
   is already the current searchRoot, preventing self-referential tree
   corruption.

2. addNextBlock silent no-op (kvCacheManager.cpp):
   After PR NVIDIA#11919 replaced setPrevBlock() with lookup-node navigation,
   addNextBlock silently skipped attachment when a slot was occupied.
   Changed to evict-and-replace: detach the existing block and attach
   the new one, keeping getPrevBlock() consistent.

3. fromReuseTree fallback (kvCacheUtils.h, cacheFormatter.cpp):
   When storeBlocks skips a duplicate, the reuse tree is incomplete.
   Changed fromReuseTree to return std::optional and fall back to
   fromAllBlockIds in getBlockRangeForSending. Resolves the existing
   TODO about handling missing blocks.

4. Termination race (py_executor.py):
   When enable_partial_reuse_for_disagg was True, _handle_responses
   terminated requests without checking is_disagg_context_transmission_state,
   racing with the async CacheSender thread. Unified the termination
   guard to always check transmission state before terminating.

Signed-off-by: Aurelien Chartier <2567591+achartier@users.noreply.github.com>
# then we need to terminate the request. TODO: Remove this once disagg support from KVCache reuse
# path is fixed.
if self.enable_partial_reuse_for_disagg and not self.kv_cache_manager.is_vswa and self.dist.pp_size == 1:
if not request.is_disagg_context_transmission_state:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Terminating the request is intentional since the blocks associated with that request are pinned (the refcount increased by 1) before termination to not evict those blocks until KVCache transfer is completed.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Agreed, I don't think this is correct. Closing this workaround PR in favor of !12648

@achartier achartier closed this Apr 1, 2026
@achartier
achartier deleted the fix/disagg-kv-cache-addnextblock-assertion branch April 1, 2026 14:54
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.

2 participants