Skip to content

Commit ae8b628

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 889859d commit ae8b628

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
@@ -386,13 +386,13 @@ def _delay(resp, attempt):
386386
except StopIteration as e:
387387
if not e.value and not streamed: raise requests.ConnectionError("empty response")
388388
return e.value or []
389-
except (requests.Timeout, requests.ConnectionError) as e:
389+
except (requests.Timeout, requests.ConnectionError, requests.exceptions.ChunkedEncodingError) as e:
390390
#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')
391391
err = f"!!!Error: {type(e).__name__}: {e}" if str(e) else f"!!!Error: {type(e).__name__}"
392392
if attempt < sess.max_retries:
393393
d = _delay(None, attempt)
394394
print(f"[LLM Retry] {type(e).__name__}, retry in {d:.1f}s ({attempt+1}/{sess.max_retries+1})")
395-
yield err; time.sleep(d); continue
395+
time.sleep(d); continue
396396
yield err; return [{"type": "text", "text": err}]
397397
except Exception as e:
398398
err = f"\n\n[!!! 流异常中断 {type(e).__name__}: {e} !!!]" if streamed else f"!!!Error: {type(e).__name__}: {e}"

0 commit comments

Comments
 (0)