Fix KeyError on batch requests whose state is freed before it is read (#36638)

This commit is contained in:
Mohammad Miadh Angkad
2026-08-28 12:57:07 -07:00
committed by GitHub
parent c7879af887
commit 70088aa5db
2 changed files with 39 additions and 2 deletions
@@ -1688,13 +1688,22 @@ class TokenizerManager(TokenizerControlMixin, TokenizerManagerScoreMixin):
return None
async def _wait_one_response(
def _wait_one_response(
self,
obj: Union[GenerateReqInput, EmbeddingReqInput],
request: Optional[fastapi.Request] = None,
):
"""Wait for the response of one request."""
# Batch dispatch builds every waiter before advancing any.
# Both removers append the output after the del, so the ReqState stays valid.
state = self.rid_to_state[obj.rid]
return self._stream_one_response(obj=obj, state=state, request=request)
async def _stream_one_response(
self,
obj: Union[GenerateReqInput, EmbeddingReqInput],
state: ReqState,
request: Optional[fastapi.Request] = None,
):
# Not all request types have `stream` (e.g., EmbeddingReqInput). Default to non-streaming.
is_stream = getattr(obj, "stream", False)
while True: