Skip to content

[https://nvbugs/6418912][fix] Fix KV-cache lifecycle test failures - #16019

Merged
chienchunhung merged 3 commits into
NVIDIA:mainfrom
chienchunhung:codex/nvbug-6418912-ci-integration
Jul 9, 2026
Merged

[https://nvbugs/6418912][fix] Fix KV-cache lifecycle test failures#16019
chienchunhung merged 3 commits into
NVIDIA:mainfrom
chienchunhung:codex/nvbug-6418912-ci-integration

Conversation

@chienchunhung

@chienchunhung chienchunhung commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

Resolves NVBUG 6418912 by fixing the BufferIndexHolder move-assignment deadlock and the related KV-cache lifecycle and test failures discovered while validating batch_manager-80.

This is the intended merge candidate for the bug. It consolidates the fixes originally developed in:

Changes

  • Configure two concurrently usable buffer indices before exercising BufferIndexHolder move assignment, preventing the recv and send variants from waiting indefinitely.
  • Clear stale prevBlockInSeq links when zero-reference detached KV-cache blocks are recycled.
  • Align eviction, partial-copy, block-ID reuse, cache-salt, event-stream, and reusable-token accounting tests with the corrected lifecycle behavior.
  • Isolate GDS partial-copy scratch directories by process and data type.
  • Add the dedicated A30-CPP-1 pre-merge stage and move cpp/test_unit_tests.py::test_unit_tests[batch_manager-80] from post-merge to pre-merge.
  • Remove the broad NVBUG 6422415 A30 batch-manager waiver so the suite executes in CI.

Validation

Targeted unwaived validation on the tree-equivalent pre-rewrite head 68748060 passed in pipeline #46726:

  • A30-CPP-1: 524 passed, 0 failed, 2 skipped
  • CTest: 519/519 executed tests passed; 6 additional tests were disabled
  • SideVariants/BufferIndexHolderLifecycleTest.MoveAssignReleasesPriorThenTransfers/send: passed
  • SideVariants/BufferIndexHolderLifecycleTest.MoveAssignReleasesPriorThenTransfers/recv: passed
  • All modified kvCacheManagerTest.cpp cases passed, including detached-block recycling, partial copy, reuse accounting, and FillKvCacheWithRequestsAndCompleteOneByOne/5

The branch was subsequently consolidated into three signed commits and rebased onto upstream 50423007d; the current head is e27882e0. A fresh full CI run was requested here and launched as pipeline #46909.

The earlier full pipeline #46737 reused the same-head A30 result and marked A30-CPP-1 as skipped. Its failures were unrelated current-main PyTorch attention-contract failures, known NVBUG 6427411 failures, and infrastructure cancellations; no NVBUG 6418912 or changed-file fingerprint appeared in those failures.

Bug

NVBUG 6418912

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast --stage-list "A30-CPP-1"

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57861 [ run ] triggered by Bot. Commit: 1e866b2 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57861 [ run ] completed with state SUCCESS. Commit: 1e866b2
/LLM/main/L0_MergeRequest_PR pipeline #46557 (Partly Tested) 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 --stage-list "A30-CPP-1"

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57889 [ run ] triggered by Bot. Commit: 656e9e6 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57889 [ run ] completed with state FAILURE. Commit: 656e9e6
/LLM/main/L0_MergeRequest_PR pipeline #46583 (Partly Tested) 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 --stage-list "A30-CPP-1"

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57931 [ run ] triggered by Bot. Commit: 1248a18 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57931 [ run ] completed with state SUCCESS. Commit: 1248a18
/LLM/main/L0_MergeRequest_PR pipeline #46619 (Partly Tested) completed with status: 'SUCCESS'

CI Report

Link to invocation

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57951 [ run ] triggered by Bot. Commit: 1248a18 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57951 [ run ] completed with state SUCCESS. Commit: 1248a18
/LLM/main/L0_MergeRequest_PR pipeline #46632 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 chienchunhung changed the title [None][test] NVBUG 6418912 integration validation (DO NOT MERGE) [https://nvbugs/6418912][fix] NVBUG 6418912 integration validation Jul 7, 2026
@chienchunhung
chienchunhung marked this pull request as ready for review July 7, 2026 17:35
@chienchunhung
chienchunhung requested a review from a team as a code owner July 7, 2026 17:35
@chienchunhung
chienchunhung requested a review from a team July 7, 2026 17:35
@chienchunhung
chienchunhung requested a review from a team as a code owner July 7, 2026 17:35

@thorjohnsen thorjohnsen 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

@chienchunhung

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@thorjohnsen
thorjohnsen enabled auto-merge (squash) July 7, 2026 17:36

chienchunhung commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator Author

Duplicate trigger avoided; using the earlier full CI request at #16019 (comment).

@dpitman-nvda dpitman-nvda 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.

Approve for CI touches

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #58050 [ run ] triggered by Bot. Commit: 192e5ed Link to invocation

@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR fixes a stale prev-in-sequence pointer for detached KV cache blocks in WindowBlockManager::releaseBlocks, updates extensive KV cache manager unit tests to match revised reuse/eviction/accounting behavior, adjusts a buffer index holder test for concurrency preconditions, and adds an A30-CPP-1 Jenkins stage with a corresponding test-db pre_merge/post_merge reassignment.

Changes

KV Cache Manager Fix and Test Updates

Layer / File(s) Summary
Detached block prev-pointer fix
cpp/tensorrt_llm/batch_manager/kvCacheManager.cpp
Clears prevBlockInSeq on detached blocks before recycling and uses computed isDetached for the toFront flag in eviction release.
Prev-pointer and detached recycling assertions
cpp/tests/unit_tests/batch_manager/kvCacheManagerTest.cpp
Adds nullptr prevBlockInSeq check after release, updates detached-block recycling expectations, and revises event-stream accounting for block replacement.
Partial-copy test rework
cpp/tests/unit_tests/batch_manager/kvCacheManagerTest.cpp
Switches GDS offload directory naming to per-process/dtype, introduces dedicated partialCopyBlockId, updates expected block ids, and changes onboarding verification to KvCacheTransferMode::DRAM.
Reuse block-id expectation updates
cpp/tests/unit_tests/batch_manager/kvCacheManagerTest.cpp
Updates recycled/new cache-block id expectations across extra-id, multimodal-hash, LoRA task-id, and cache-salt reuse test suites.
Reusable token accounting updates
cpp/tests/unit_tests/batch_manager/kvCacheManagerTest.cpp
Revises estimatedReusableTokens/neededOneStep assertions so free-but-cached blocks credit reusable tokens.
Buffer index holder concurrency setup
cpp/tests/unit_tests/batch_manager/bufferIndexHolderTest.cpp
Adds environment configuration for concurrent index usage and a precondition assertion for available buffer slots before move-assignment.

CI Test Stage Addition

Layer / File(s) Summary
Jenkins stage and test-db reassignment
jenkins/L0_Test.groovy, tests/integration/test_lists/test-db/l0_a30.yml
Adds A30-CPP-1 stage config and moves batch_manager-80 C++ unit test from post_merge to pre_merge.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Suggested reviewers: xinhe-nv, pengbowang-nv, yuxianq, QiJune

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Title check ✅ Passed Matches the required [ticket][type] summary format and accurately reflects the main fix in the PR.
Description check ✅ Passed It covers summary, changes, validation, and bug context, but it does not follow the template's explicit Description/Test Coverage/PR Checklist headings.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
cpp/tests/unit_tests/batch_manager/kvCacheManagerTest.cpp (1)

920-1041: 📐 Maintainability & Code Quality | 🔵 Trivial

Mechanical block-id expectation updates look consistent with the recycling fix.

These updates shift expected recycled/new block ids (e.g., reused block 3 instead of a freshly-allocated block 4) to reflect that detached blocks are now correctly recycled to the front of the free queue rather than being kept alive by a stale prevBlockInSeq chain. As per path instructions for tests/**, one gap worth calling out: none of these updated tests explicitly assert the complementary branch — that a block still registered in the lookup tree (non-detached, stored for reuse) keeps a non-null getPrevBlockInSeq() after release. Consider adding one such assertion (e.g., in BlockManagerReuseTest, right after a block is stored for reuse) to fully pin down both branches of the new conditional in WindowBlockManager::releaseBlocks.

Based on path instructions for tests/**: "Act as a QA engineer reviewing test changes and coverage for TensorRT-LLM. Keep feedback actionable: suggest concrete list file names and whether coverage is sufficient, insufficient, or needs follow-up outside the PR."

Also applies to: 1246-1264, 1317-1327, 1347-1357, 1510-1520, 1548-1559, 1681-1861, 2320-2351, 3067-3068, 4090-4122

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cpp/tests/unit_tests/batch_manager/kvCacheManagerTest.cpp` around lines 920 -
1041, The updated block-id expectations are fine, but the test coverage is
missing the complementary case for the new release path. In the relevant KV
cache manager tests (for example around KvCacheManagerTest and any
BlockManagerReuseTest coverage), add an assertion after releasing a block that
is still registered for reuse to verify its prevBlockInSeq remains non-null, so
both branches of WindowBlockManager::releaseBlocks are covered. Use the existing
reuse/release setup in addSequenceBatch, releaseBlocks, and getPrevBlockInSeq to
place the check where the stored-for-reuse block is returned.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cpp/tests/unit_tests/batch_manager/kvCacheManagerTest.cpp`:
- Around line 479-491: The partial-copy verification is hardcoded to the DRAM
path, so the GDS templated instantiation never exercises this test. Update the
partial-copy check around blockManager.offloadBlock and the later copy
verification to use the existing transferMode/directory plumbing, or split the
assertion into a DRAM-only branch if that behavior is intentional, so the
kvCacheManagerTest coverage matches the templated transfer mode.

---

Nitpick comments:
In `@cpp/tests/unit_tests/batch_manager/kvCacheManagerTest.cpp`:
- Around line 920-1041: The updated block-id expectations are fine, but the test
coverage is missing the complementary case for the new release path. In the
relevant KV cache manager tests (for example around KvCacheManagerTest and any
BlockManagerReuseTest coverage), add an assertion after releasing a block that
is still registered for reuse to verify its prevBlockInSeq remains non-null, so
both branches of WindowBlockManager::releaseBlocks are covered. Use the existing
reuse/release setup in addSequenceBatch, releaseBlocks, and getPrevBlockInSeq to
place the check where the stored-for-reuse block is returned.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 72cca991-0eec-4a5d-a8a8-392419829510

📥 Commits

Reviewing files that changed from the base of the PR and between 148bf8a and 192e5ed.

📒 Files selected for processing (5)
  • cpp/tensorrt_llm/batch_manager/kvCacheManager.cpp
  • cpp/tests/unit_tests/batch_manager/bufferIndexHolderTest.cpp
  • cpp/tests/unit_tests/batch_manager/kvCacheManagerTest.cpp
  • jenkins/L0_Test.groovy
  • tests/integration/test_lists/test-db/l0_a30.yml

Comment thread cpp/tests/unit_tests/batch_manager/kvCacheManagerTest.cpp
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #58051 [ run ] triggered by Bot. Commit: 192e5ed Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #58050 [ run ] completed with state ABORTED. Commit: 192e5ed

Link to invocation

@thorjohnsen
thorjohnsen disabled auto-merge July 7, 2026 17:55

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast --stage-list "A30-CPP-1"

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #58059 [ run ] triggered by Bot. Commit: 6874806 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #58051 [ run ] completed with state ABORTED. Commit: 192e5ed

Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #58059 [ run ] completed with state SUCCESS. Commit: 6874806
/LLM/main/L0_MergeRequest_PR pipeline #46726 (Partly Tested) completed with status: 'SUCCESS'

CI Report

Link to invocation

@chienchunhung

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #58072 [ run ] triggered by Bot. Commit: 6874806 Link to invocation

@chienchunhung
chienchunhung enabled auto-merge (squash) July 7, 2026 19:42
Comment thread cpp/tests/unit_tests/batch_manager/bufferIndexHolderTest.cpp
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #58072 [ run ] completed with state FAILURE. Commit: 6874806
/LLM/main/L0_MergeRequest_PR pipeline #46737 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 chienchunhung changed the title [https://nvbugs/6418912][fix] NVBUG 6418912 integration validation [https://nvbugs/6418912][fix] Fix KV-cache lifecycle test failures Jul 8, 2026
Provision two fixture slots for BufferIndexHolder move assignment so the second acquisition cannot deadlock. Clear stale predecessor links before detached KV-cache blocks return to the front of the eviction queue.

Signed-off-by: Chien-Chun Hung <2679986+chienchunhung@users.noreply.github.com>
Update detached-block eviction, partial-copy inspection, recycled block IDs, event-stream accounting, and cached-prefix reuse expectations to match the corrected lifecycle behavior.

Signed-off-by: Chien-Chun Hung <2679986+chienchunhung@users.noreply.github.com>
Register A30-CPP-1, move batch_manager-80 from post-merge to pre-merge, and remove the broad A30 batch-manager waiver so lifecycle regressions are exercised before landing.

Signed-off-by: Chien-Chun Hung <2679986+chienchunhung@users.noreply.github.com>
@chienchunhung
chienchunhung force-pushed the codex/nvbug-6418912-ci-integration branch from 6874806 to e27882e Compare July 8, 2026 17:30

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #58271 [ run ] triggered by Bot. Commit: e27882e Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #58271 [ run ] completed with state SUCCESS. Commit: e27882e
/LLM/main/L0_MergeRequest_PR pipeline #46909 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 #58483 [ run ] triggered by Bot. Commit: e27882e Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #58483 [ run ] completed with state SUCCESS. Commit: e27882e
/LLM/main/L0_MergeRequest_PR pipeline #47092 completed with status: 'SUCCESS'

CI Report

Link to invocation

@chienchunhung
chienchunhung merged commit dca857f into NVIDIA:main Jul 9, 2026
13 checks passed
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.

5 participants