Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/services/flow_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4709,6 +4709,9 @@ def _get_retry_reason(self, error_str: str) -> Optional[str]:
if "model_access_denied" in error_lower:
# 账号无对应模型权限,重试不会改变结果
return None
if "public_error_user_quota_reached" in error_lower:
# 账号额度不足,同号重试只会白白消耗打码;交给上层换号
return None
if "403" in error_lower:
return "403错误"
if "429" in error_lower or "too many requests" in error_lower:
Expand Down Expand Up @@ -4748,6 +4751,9 @@ def _get_retry_delay_seconds(self, error_str: str, retry_attempt: int) -> int:
return 2
if "recaptcha" in error_lower:
return 2
if "public_error_unusual_activity" in error_lower:
# 风控拒绝后立刻重试几乎必然再次被拒,留出打码服务自愈时间
return 3
return 1

def _resolve_recaptcha_runtime_settings(
Expand Down
37 changes: 36 additions & 1 deletion src/services/flow_current.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
from ..core.logger import debug_logger
from .browser_cookie_utils import validate_flow_cookie_storage

# 视频提交被 PUBLIC_ERROR_UNUSUAL_ACTIVITY 拒绝时,同账号最多再重试的次数;
# 之后交给上层切换账号(同账号同 IP 立刻重试大概率仍被风控)。
UNUSUAL_ACTIVITY_SAME_TOKEN_RETRIES = 1

def _safe_updated_flow_cookies(owner, original) -> str:
"""读取 Cookie 最新快照,缺失实现时安全降级。

Expand Down Expand Up @@ -548,6 +552,7 @@ async def _current_generate_video(
model_keys.append(model_keys[0].replace("_relaxed", ""))
attempt_budget = max(max_retries, len(model_keys))
fallback_model_key: Optional[str] = None
unusual_activity_hits = 0
last_error: Optional[Exception] = None
for retry_attempt in range(attempt_budget):
browser_id = None
Expand Down Expand Up @@ -610,7 +615,37 @@ async def _current_generate_video(
f"{request_model_key} -> {model_keys[-1]}"
)
continue
if retry_attempt >= max_retries - 1:
retry_handler = getattr(
self, "_handle_retryable_generation_error", None
)
if retry_handler is None:
if retry_attempt >= max_retries - 1:
raise
continue
if "public_error_unusual_activity" in error_text:
unusual_activity_hits += 1
if (
retry_attempt >= max_retries - 1
or unusual_activity_hits > UNUSUAL_ACTIVITY_SAME_TOKEN_RETRIES
):
# 不再同号重试,但仍需通知打码服务自愈(清缓存/重建浏览器)
await self._notify_browser_captcha_error(
browser_id=getattr(error, "browser_ref", None) or browser_id,
project_id=project_id,
error_reason=self._get_retry_reason(str(error))
or str(error)[:120],
error_message=str(error),
)
raise
should_retry = await retry_handler(
error,
retry_attempt,
max_retries,
browser_id,
project_id,
"[VIDEO] ",
)
if not should_retry:
raise
finally:
await self._notify_browser_captcha_request_finished(browser_id)
Expand Down
Loading