Skip to content

Commit 2eaca66

Browse files
committed
fix(llmcore): suppress intermediate error yield during retry and handle ChunkedEncodingError
When the LLM stream encounters a transient network error (ConnectionError, Timeout, SSLError, ProxyError), the retry path yielded the error string back to the caller on every attempt. This caused the UI to display a wall of '!!!Error: ProxyError!!!Error: ConnectionError!!!Error: SSLError' strings during a network blip, even when the retry ultimately succeeded. Match the existing HTTP retry path (which sleeps without yielding) by removing the intermediate yield so the caller only sees the final error if retries are exhausted. Retry attempts remain visible via the existing '[LLM Retry] ...' stdout log. Also extend the exception tuple to include ChunkedEncodingError. Without it, a truncated chunked response falls through to the bare 'except Exception' branch and aborts the stream with no retry, even though the transport-level error is transient and recoverable. Closes #571
1 parent b1e173d commit 2eaca66

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

llmcore.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,13 +387,13 @@ def _delay(resp, attempt):
387387
except StopIteration as e:
388388
if not e.value and not streamed: raise requests.ConnectionError("empty response")
389389
return e.value or []
390-
except (requests.Timeout, requests.ConnectionError) as e:
390+
except (requests.Timeout, requests.ConnectionError, requests.exceptions.ChunkedEncodingError) as e:
391391
#pathlib.Path(__file__).parent.joinpath('temp','bad_requests.json').write_text(json.dumps({"url":url,"headers":headers,"payload":payload,"err":str(e),"t":time.time()},ensure_ascii=False),encoding='utf-8')
392392
err = f"!!!Error: {type(e).__name__}: {e}" if str(e) else f"!!!Error: {type(e).__name__}"
393393
if attempt < sess.max_retries:
394394
d = _delay(None, attempt)
395395
print(f"[LLM Retry] {type(e).__name__}, retry in {d:.1f}s ({attempt+1}/{sess.max_retries+1})")
396-
yield err; time.sleep(d); continue
396+
time.sleep(d); continue
397397
yield err; return [{"type": "text", "text": err}]
398398
except Exception as e:
399399
err = f"\n\n[!!! 流异常中断 {type(e).__name__}: {e} !!!]" if streamed else f"!!!Error: {type(e).__name__}: {e}"

0 commit comments

Comments
 (0)