Skip to content

fix(kv-router): break request-lease observer ownership cycle - #15258

Merged
jthomson04 merged 1 commit into
ai-dynamo:mainfrom
surajssd:suraj/kv-router-weak-request-lease-observer
Oct 1, 2026
Merged

jthomson04 merged 1 commit into
ai-dynamo:mainfrom
surajssd:suraj/kv-router-weak-request-lease-observer

Conversation

@surajssd

@surajssd surajssd commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Overview:

KvRouter::new hands the scheduler a strong Arc to the RequestLeaseManager as its replica observer, and the manager holds the scheduler's SchedulerBookingCleanup handle that it receives from set_scheduler. Both edges are strong, so neither side can drop once construction has wired them. A router that fails to construct after that point, or one that is dropped, leaks its scheduler actor and lease state. This PR replaces the strong observer with a weak one so the cycle is broken while callbacks still reach the manager for as long as it is alive.

This is the first of three independent PRs split out of #14965. That PR's Mooncake Store test for failed router construction depends on RequestLeaseManager::replica_observer from this change. The leak itself exists on main today and is not specific to Mooncake Store.

Details:

  • Add RequestLeaseManager::replica_observer, which returns an Arc<dyn ReplicaRequestLeaseObserver> backed by a Weak<RequestLeaseManagerInner>.
  • Replace the impl ReplicaRequestLeaseObserver for RequestLeaseManager with a private WeakRequestLeaseObserver. Each of admitted, progressed, and completed upgrades the weak reference and forwards to the existing register_remote, touch_booking, and complete_remote methods, or becomes a no-op once the manager is gone.
  • KvRouter::new passes request_leases.replica_observer() to the scheduler instead of Some(Arc::new(request_leases.clone())).
  • Add the regression test replica_observer_forwards_live_callbacks_without_retaining_manager. It admits a booking on a tracked router, drives the three callbacks through the observer and checks the lease record at each step, drops the router, and asserts the manager is released. It then calls the callbacks again on the dangling observer to confirm they are no-ops.
  • Make the tracked_router test helper in kv_router.rs pub(super) so the request_lease test module can reuse it.

Where should the reviewer start?

  • lib/llm/src/kv_router/request_lease.rs: replica_observer and WeakRequestLeaseObserver, then the new test at the top of the tests module.
  • lib/llm/src/kv_router.rs: the one-line change in KvRouter::new where the observer is handed to the scheduler.

Validation

cargo test -p dynamo-llm --no-default-features --lib -- kv_router::request_lease

Both tests in the module pass. The regression test was also run against the previous strong observer in a throwaway worktree, where the manager.upgrade().is_none() assertion fails, so the test does detect the cycle. cargo fmt --all --check is clean.

Related Issues

πŸ”— This PR is linked to an issue:

Summary by CodeRabbit

  • Bug Fixes
    • Improved reliability when replica activity updates arrive after request tracking has ended. These late updates are now safely ignored, while updates for active requests continue to be recorded and completed as expected.

@surajssd
surajssd requested a review from a team as a code owner September 24, 2026 15:42
@copy-pr-bot

copy-pr-bot Bot commented Sep 24, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@surajssd
surajssd temporarily deployed to external_collaborator September 24, 2026 15:42 — with GitHub Actions Inactive
@surajssd
surajssd temporarily deployed to external_collaborator September 24, 2026 15:42 — with GitHub Actions Inactive
@github-actions github-actions Bot added the fix label Sep 24, 2026
@github-actions

Copy link
Copy Markdown
Contributor

πŸ‘‹ Hi surajssd! Thank you for contributing to ai-dynamo/dynamo.

Just a reminder: The NVIDIA Test Github Validation CI runs an essential subset of the testing framework to quickly catch errors.Your PR reviewers may elect to test the changes comprehensively before approving your changes.

πŸš€

@github-actions github-actions Bot added external-contribution Pull request is from an external contributor router Relates to routing, KV-aware routing, etc. labels Sep 24, 2026
@coderabbitai

coderabbitai Bot commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack β†’

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. πŸŽ‰

ℹ️ Recent review info
βš™οΈ Run configuration

Configuration used: Repository: ai-dynamo/dynamo/.coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: c11153fa-9239-476c-8e41-05ccfa4ea400

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between a76e12e and c6c92af.

πŸ“’ Files selected for processing (2)
  • lib/llm/src/kv_router.rs
  • lib/llm/src/kv_router/request_lease.rs

Included review availability: Your plan provides up to 12 included reviews per hour; 11 remain after this review.


Walkthrough

The router now passes a weak-reference-backed replica observer to EmbeddedSelection. The observer forwards replica callbacks only while the request-lease manager exists. An async test checks lease updates and callbacks after manager destruction.

Changes

Replica Lease Observer

Layer / File(s) Summary
Observer wiring and lifecycle
lib/llm/src/kv_router/request_lease.rs, lib/llm/src/kv_router.rs
The request-lease manager creates a weak observer for replica callbacks, and the router passes it to EmbeddedSelection. The test checks lease registration, clock updates, completion, and callbacks after manager destruction. The tracked_router test helper is now visible to sibling modules.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: βšͺ Minimal Β· up to c6c92

The observer change appears ready to merge after normal checks.

πŸš₯ Pre-merge checks | βœ… 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 45.45% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
βœ… Passed checks (4 passed)
Check name Status Explanation
Description check βœ… Passed The description includes all required sections: Overview, Details, reviewer guidance, and Related Issues. It identifies issue #14965 and provides implementation details and validation results.
Title check βœ… Passed The title clearly and concisely describes the main change: breaking the request-lease observer ownership cycle in the KV router.
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.
  • Fix all pre-merge checks with AI

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

@jthomson04 jthomson04 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.

Reviewed the split from #14965. The weak observer breaks the ownership cycle and preserves live callbacks. The change is self-contained. No code findings from source review.

@jthomson04

Copy link
Copy Markdown
Contributor

/ok to test c6c92af

The scheduler holds the request-lease manager as its replica observer,
and the manager holds the scheduler booking cleanup handle it receives
from set_scheduler. Both edges are strong, so neither side can drop
once KvRouter construction has wired them, and a router that fails to
construct after that point leaks its scheduler and lease state.

Hand the scheduler a weak observer instead. Callbacks are forwarded
while the manager is alive and become no-ops once it is gone. The
regression test admits a booking, drives the three callbacks through
the observer, drops the router, and asserts the manager is released. It
fails against the strong observer.

Signed-off-by: Suraj Deshmukh <surajd.service@gmail.com>
@surajssd
surajssd force-pushed the suraj/kv-router-weak-request-lease-observer branch from c6c92af to 8737d74 Compare September 28, 2026 18:56
@surajssd
surajssd temporarily deployed to external_collaborator September 28, 2026 18:56 — with GitHub Actions Inactive
@jthomson04

Copy link
Copy Markdown
Contributor

/ok to test 8737d74

@jthomson04
jthomson04 merged commit 631d7c1 into ai-dynamo:main Oct 1, 2026
119 checks passed

This branch was previously deployed

1 inactive deployment
external_collaborator β€” 8737d743 Deployed Sep 28, 2026 by surajssd via ok-to-test #23354
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external-contribution Pull request is from an external contributor fix router Relates to routing, KV-aware routing, etc. size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants