Skip to content

[Bugfix][Core] fix KeyError in _update_waiting_for_remote_kv#25563

Closed
kebe7jun wants to merge 1 commit intovllm-project:mainfrom
kebe7jun:fix/keyerr
Closed

[Bugfix][Core] fix KeyError in _update_waiting_for_remote_kv#25563
kebe7jun wants to merge 1 commit intovllm-project:mainfrom
kebe7jun:fix/keyerr

Conversation

@kebe7jun
Copy link
Contributor

@kebe7jun kebe7jun commented Sep 24, 2025

Purpose

Fix #25562

Test Plan

N/A

Test Result

N/A


Essential Elements of an Effective PR Description Checklist
  • The purpose of the PR, such as "Fix some issue (link existing issues this PR will resolve)".
  • The test plan, such as providing test command.
  • The test results, such as pasting the results comparison before and after, or e2e results
  • (Optional) The necessary documentation update, such as updating supported_models.md and examples for a new model.
  • (Optional) Release notes update. If your change is user facing, please update the release notes draft in the Google Doc.

Signed-off-by: Kebe <mail@kebe7jun.com>
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request addresses a KeyError that can occur in _update_from_kv_xfer_finished due to a race condition with request abortion. The fix is to check if a request ID exists in self.requests before attempting to access it. The change is correct and effectively prevents the crash. I've suggested a minor refinement to use dict.get() for a slightly cleaner and more efficient implementation.

Comment on lines +1290 to 1293
if req_id not in self.requests:
continue
logger.debug("Finished sending KV transfer for request %s", req_id)
self._free_blocks(self.requests[req_id])
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The added check correctly prevents the KeyError if a request has been aborted and removed from self.requests. For a slight improvement in efficiency and conciseness, you could use dict.get() to perform the check and retrieval in a single operation. This avoids the double dictionary lookup (in followed by []).

Suggested change
if req_id not in self.requests:
continue
logger.debug("Finished sending KV transfer for request %s", req_id)
self._free_blocks(self.requests[req_id])
request = self.requests.get(req_id)
if request:
logger.debug("Finished sending KV transfer for request %s", req_id)
self._free_blocks(request)

logger.debug("Finished recving KV transfer for request %s", req_id)
self.finished_recving_kv_req_ids.add(req_id)
for req_id in (kv_connector_output.finished_sending or ()):
if req_id not in self.requests:
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe we could also add the existence check for for req_id in (kv_connector_output.finished_recving or ()):

@markmc
Copy link
Member

markmc commented Oct 1, 2025

Should be fixed by #25844

@github-actions
Copy link

github-actions bot commented Jan 1, 2026

This pull request has been automatically marked as stale because it has not had any activity within 90 days. It will be automatically closed if no further activity occurs within 30 days. Leave a comment if you feel this pull request should remain open. Thank you!

@github-actions github-actions bot added the stale Over 90 days of inactivity label Jan 1, 2026
@kebe7jun kebe7jun closed this Jan 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kv-connector stale Over 90 days of inactivity v1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: update_from_kv_xfer_finished raise KeyError when using NixlConnector

4 participants