fix(ui): widget key 按项目隔离,避免滚动卡死/加载串项目;fix(img): 最小180s+失败码重试3次

This commit is contained in:
Tony Zhang
2025-12-18 00:31:37 +08:00
parent c6436da17e
commit 3d1fb37769
2 changed files with 59 additions and 25 deletions

View File

@@ -28,11 +28,12 @@ def _env_int(name: str, default: int) -> int:
# Tunables: slow channels can be hot; default conservative but adjustable.
IMG_SUBMIT_TIMEOUT_S = _env_int("IMG_SUBMIT_TIMEOUT_S", 180)
IMG_POLL_TIMEOUT_S = _env_int("IMG_POLL_TIMEOUT_S", 30)
IMG_MAX_RETRIES = _env_int("IMG_MAX_RETRIES", 3)
IMG_POLL_INTERVAL_S = _env_int("IMG_POLL_INTERVAL_S", 2)
IMG_POLL_MAX_RETRIES = _env_int("IMG_POLL_MAX_RETRIES", 90) # 90*2s ~= 180s
# IMPORTANT: we enforce minimums to avoid accidental misconfig (e.g. 120s) causing flaky UX.
IMG_SUBMIT_TIMEOUT_S = max(_env_int("IMG_SUBMIT_TIMEOUT_S", 180), 180)
IMG_POLL_TIMEOUT_S = max(_env_int("IMG_POLL_TIMEOUT_S", 30), 10)
IMG_MAX_RETRIES = max(_env_int("IMG_MAX_RETRIES", 3), 3)
IMG_POLL_INTERVAL_S = max(_env_int("IMG_POLL_INTERVAL_S", 2), 1)
IMG_POLL_MAX_RETRIES = max(_env_int("IMG_POLL_MAX_RETRIES", 90), 90) # 90*2s ~= 180s
def _is_retryable_exception(e: Exception) -> bool:
@@ -43,6 +44,22 @@ def _is_retryable_exception(e: Exception) -> bool:
# Transient provider errors often contain these keywords
if any(k in msg for k in ["timeout", "temporarily", "temporarily unavailable", "gateway", "rate", "try again"]):
return True
# Treat common HTTP transient status codes as retryable when they bubble up as RuntimeError text
# Examples from our code: "Shubiaobiao 提交失败 (429): ..." / "Doubao Image Failed (502): ..."
try:
import re
m = re.search(r"\((\d{3})\)", msg)
if not m:
# sometimes formatted like "429:" without parentheses
m = re.search(r"\b(\d{3})\b", msg)
if m:
code = int(m.group(1))
if code in (408, 409, 425, 429, 500, 502, 503, 504):
return True
if 500 <= code <= 599:
return True
except Exception:
pass
return False