Skip to content

[CB] Don't crash when a request in the running batch is cancelled - #51249

Open
SunMarc wants to merge 2 commits into
mainfrom
fix/cb-cancel-running-request
Open

SunMarc wants to merge 2 commits into
mainfrom
fix/cb-cancel-running-request

Conversation

@SunMarc

@SunMarc SunMarc commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

🤗 Transformers CI

What does this PR do?

Cancelling a request can kill the continuous batching loop:

Error in generation loop: 'req_70'
KeyError: 'req_70'

Why: with async batching, a cancelled request can still be in the batch that is running. Its cache blocks are freed right away, then the running batch's update tries to use them.

Fix: mark the cancelled request as FINISHED, so that update skips it.

In transformers serve, this happens when clients disconnect in the middle of a stream: the loop dies and request fails.

Tests

New test test_cancel_request_in_running_batch (100 requests added then cancelled while one keeps generating): fails on main with the KeyError, passes here.

@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

This branch has not been deployed

No deployments
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