Skip to content

[Bugfix][KV Offload] Do not offload the partially computed block of a request that finished with an error - #63937

Merged
orozery merged 2 commits into
vllm-project:mainfrom
sohom-cs:fix/offload-error-finish-partial-block
Oct 29, 2026
Merged

orozery merged 2 commits into
vllm-project:mainfrom
sohom-cs:fix/offload-error-finish-partial-block

Conversation

@sohom-cs

@sohom-cs sohom-cs commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Overview

When a request finishes with an error before its prefill is complete, the block it was computing is stored under the hash of the full block. A later request with that prefix hits the offloaded block and loads KV for tokens that were never computed. One-expression fix in _build_store_jobs; sibling of #59096 and #59329.

Claims

  • A request that ends in FINISHED_ERROR mid-prefill stores only the blocks it fully computed, as FINISHED_ABORTED already does.
  • Requests that finished normally are unchanged: they computed their whole prompt, so the clamp is a no-op.

Validation

python -m pytest tests/v1/kv_connector/unit/offloading_connector/test_scheduler.py -q -k finish_mid_prefill
python -m pytest tests/v1/kv_connector/unit/offloading_connector/test_scheduler.py -q
pre-commit run --from-ref origin/main --to-ref HEAD

test_finish_mid_prefill_stores_only_computed_blocks[FINISHED_ERROR|FINISHED_ABORTED] runs a 16-token prompt through chunked prefill at 6 tokens a step (block size 4), finishes the request after the first chunk, and checks that the finish step stores nothing beyond the one full block step 1 already stored.

On main (6fe3d44) the FINISHED_ERROR case fails:

AssertionError: FINISHED_ERROR: stored 1 blocks [2] but only 1 full block(s) were computed (num_computed_tokens=6, prompt=16)

With the fix both cases pass; the file's other tests still pass (CPU only, macOS, no GPU run). Model outputs are unaffected, so no evals.

Details

_build_store_jobs (offloading/scheduler.py:1874-1883) clamps the storable token count to num_computed_tokens only for FINISHED_ABORTED; every other finish uses max(num_prompt_tokens, num_tokens - 1), which is the whole prompt for a request that produced no output. storable_chunks then only bounds by allocated blocks, so the half-written block goes out under its full hash. A request can finish this way mid-prefill through finish_requests(..., FINISHED_ERROR) (sched/scheduler.py:2525-2540): an encoder-cache mismatch, or a failed KV load under the fail policy.

Fix: min(req.num_computed_tokens, max(req.num_prompt_tokens, req.num_tokens - 1)). The spec-decode clamp is kept.

Not a duplicate: #63010 (store cursor reset on a restart from token 0) and #60810 (the block table of a resumed streaming session), both merged on 10-25, and the open #62795 (flush promotions before a request's tiers are finalized) are adjacent; none touches this clamp.

AI assistance: I used an AI coding assistant (Claude) to trace this path and write the test; I reviewed every changed line and ran the tests myself.


Pull Request Checklist
  • I used vLLM's /pr-checklist skill. (Mandatory for agents, optional for humans).

  • AI assistance was used during the creation of this PR.

  • Design Fit: Minimizes impact on core components, reuses existing functionality, and justifies added complexity.

  • Testing and Validation: Validates the change and ensures any added tests are meaningful and reliable, with CI coverage or documented CI resource constraints and validation performed outside CI.

  • Code Quality and Style: Keeps code and comments clear and concise, and updates relevant documentation and examples.

  • Pull Request Contents: Includes a brief summary and relevant links, supports claims with evidence, explains root causes and implementation trade-offs, and follows the contributing guide.

… request that finished with an error

_build_store_jobs clamps the storable token count to num_computed_tokens
only for FINISHED_ABORTED. Any other finish uses
max(num_prompt_tokens, num_tokens - 1), which is the whole prompt for a
request that produced no output, so a request that finished with an
error mid-prefill stored its half-written block under the full block
hash. Clamp finished requests to num_computed_tokens as well; for a
request that finished normally the clamp is a no-op.

Co-authored-by: Claude <noreply@anthropic.com>
Signed-off-by: Sohom Chakraborty <16609933+sohom-cs@users.noreply.github.com>

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-29T02:12:58.301786Z
We couldn’t complete this review. Comment @codex review to try again.
e4c6e42 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@mergify mergify Bot added bug Something isn't working kv-connector labels Oct 27, 2026
@sohom-cs

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

An unknown error occurred
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@sohom-cs

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

An unknown error occurred
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@orozery orozery added the ready ONLY add when PR is ready to merge/full CI is needed label Oct 29, 2026
@orozery

orozery commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

/ci run

@github-actions

Copy link
Copy Markdown

✅ @sohom-cs, CI is now available for this PR.

  • /ci run starts upstream CI; /amd-ci run starts AMD CI only.
  • Run commands test your branch with every commit currently on its upstream target branch. If it is behind, the bot merges the target branch into it first (pull before pushing again). Append --allow-stale to a run command to test an outdated branch as is, at your own risk.
  • /ci retry retries failed jobs in the CI build for the current PR head. If the current head has no CI build, it starts a new CI build for the current head containing only jobs that failed in the latest earlier CI build for this PR.
  • /amd-ci retry retries failed jobs in AMD CI for the current PR head. Use /amd-ci run when the current head has no AMD CI build.
  • /ci cancel cancels scheduled or running CI builds for this PR branch; /amd-ci cancel does the same for AMD CI only.

@github-actions

Copy link
Copy Markdown

✅ Triggered Buildkite CI #98257 for commit b3d6356c7863.

ℹ️ This PR is 198 commits behind upstream main. Merged upstream main into this branch as b3d6356c7863 before starting CI. Pull the branch before pushing more changes.

@orozery
orozery merged commit 429eb22 into vllm-project:main Oct 29, 2026
43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working kv-connector ready ONLY add when PR is ready to merge/full CI is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants