Fix retry syntax: async generator can't use return, use break+try/finally

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-23 22:37:32 +08:00
parent daeb95eca0
commit a7514fc3d5

View File

@@ -446,7 +446,7 @@ async def _handle_combined(api, req_data, token_ids, input_length, session_id, h
async def generate():
prefill_done = False
last_err = None
try:
for attempt in range(MAX_STREAM_RETRIES):
try:
async with inst.client.stream("POST", api, json=req_data, headers=headers) as resp:
@@ -459,15 +459,11 @@ async def _handle_combined(api, req_data, token_ids, input_length, session_id, h
prefill_done = True
yield chunk
inst.record_prefix(token_ids)
return
except (httpx.ConnectError, httpx.RemoteProtocolError) as e:
last_err = e
if prefill_done:
break
except (httpx.ConnectError, httpx.RemoteProtocolError):
if prefill_done or attempt >= MAX_STREAM_RETRIES - 1:
raise
if attempt < MAX_STREAM_RETRIES - 1:
await asyncio.sleep(RETRY_DELAY_S)
if last_err:
raise last_err
finally:
if not prefill_done:
inst.pending_prefill_tokens -= estimated_new