[Bugfix][Frontend] Fix run_batch upload retrying on success and unawaited error body (#50588)

Signed-off-by: Chao Tan <chaos.tc@gmail.com>
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Tan Chao
2026-08-24 11:33:44 +00:00
committed by GitHub
co-authored by Claude
parent 0ecc284790
commit e239947777
2 changed files with 64 additions and 3 deletions
@@ -20,6 +20,7 @@ from vllm.entrypoints.openai.run_batch import (
BatchTranscriptionRequest,
download_bytes_from_url,
make_transcription_wrapper,
upload_data,
)
from vllm.exceptions import VLLMValidationError
from vllm.utils.mem_constants import MiB_bytes
@@ -1052,3 +1053,60 @@ async def test_transcription_wrapper_rejects_oversized_http_before_handler(
assert isinstance(response, ErrorResponse)
assert "Maximum file size exceeded" in response.error.message
handler.assert_not_awaited()
# ---------------------------------------------------------------------------
# Unit tests for upload_data retry behavior
# ---------------------------------------------------------------------------
def _make_aiohttp_put_session(status: int = 200, body_text: str = ""):
"""Mock an aiohttp.ClientSession whose PUT returns the given status."""
mock_resp = MagicMock()
mock_resp.status = status
mock_resp.text = AsyncMock(return_value=body_text)
mock_resp.__aenter__ = AsyncMock(return_value=mock_resp)
mock_resp.__aexit__ = AsyncMock(return_value=False)
mock_session = MagicMock()
mock_session.put = MagicMock(return_value=mock_resp)
mock_session.__aenter__ = AsyncMock(return_value=mock_session)
mock_session.__aexit__ = AsyncMock(return_value=False)
return mock_session
@pytest.mark.asyncio
async def test_upload_data_uploads_once_on_success():
"""A successful upload must not be retried (regression guard)."""
session = _make_aiohttp_put_session(status=200)
with patch(
"vllm.entrypoints.openai.run_batch.aiohttp.ClientSession",
return_value=session,
):
await upload_data(
"https://example.com/output.jsonl", "payload", from_file=False
)
assert session.put.call_count == 1
@pytest.mark.asyncio
async def test_upload_data_error_includes_awaited_response_body():
"""A failed upload must surface the awaited response body, not a coroutine."""
session = _make_aiohttp_put_session(status=500, body_text="server-error-detail")
with (
patch(
"vllm.entrypoints.openai.run_batch.aiohttp.ClientSession",
return_value=session,
),
patch(
"vllm.entrypoints.openai.run_batch.asyncio.sleep",
AsyncMock(),
),
pytest.raises(Exception) as exc_info,
):
await upload_data(
"https://example.com/output.jsonl", "payload", from_file=False
)
message = str(exc_info.value)
assert "server-error-detail" in message
assert "coroutine" not in message
+6 -3
View File
@@ -393,20 +393,23 @@ async def upload_data(output_url: str, data_or_file: str, from_file: bool) -> No
with open(data_or_file, "rb") as file:
async with session.put(output_url, data=file) as response:
if response.status != 200:
error_text = await response.text()
raise Exception(
f"Failed to upload file.\n"
f"Status: {response.status}\n"
f"Response: {response.text()}"
f"Response: {error_text}"
)
else:
async with session.put(output_url, data=data_or_file) as response:
if response.status != 200:
error_text = await response.text()
raise Exception(
f"Failed to upload data.\n"
f"Status: {response.status}\n"
f"Response: {response.text()}"
f"Response: {error_text}"
)
# Upload succeeded; do not retry.
return
except Exception as e:
if attempt < max_retries:
logger.error(