修复(账号自动化): 租约 CK 续期不再冒充「首次登录」,补齐等待预算

排查「首次登录都关掉了为什么还在一直登录」时发现:

- 真正在跑登录的是 lease_ck_refresh(租约 CK 续期,每 600 秒一轮),
  account_onboarding 确实已关;两者都显示成「自动化·首次登录」,所以很难分辨
- 根因是分类逻辑:trigger_source=automation 一律落 onboarding。但租约续期的
  账号本来就有 CK,只是租约到期前提前续一次,不是首次登录
- 这批租约账号全部「等待验证码超时」失败,因为生产跑的还是旧镜像(60 秒
  等待窗口),而且 lease_ck_refresh 的单账号总时长硬编码 240 秒,连新的
  900 秒等待窗口都会被掐断

改动:

- 新增 lease_refresh 分类:页面显示「自动化·租约CK续期」,日预算归到普通
  重登(不再占用「首次登录」的 150/天额度)
- lease_ck_refresh 单账号总时长 240 → 1800 秒,覆盖实测 8~13 分钟的投递延迟
- 登录预算建议的成功率样本纳入 lease_refresh

验证:1728 passed / 6 skipped,前端 tsc -b 通过,pyright 生产代码 0 错误
This commit is contained in:
yml
2026-11-25 20:04:59 +08:00
parent 9473645548
commit da85373884
8 changed files with 94 additions and 2 deletions
@@ -24,6 +24,10 @@ CATEGORY_ONBOARDING = "onboarding"
CATEGORY_RELOGIN_HIGH = "relogin_high_value"
CATEGORY_RELOGIN_ORDINARY = "relogin_ordinary"
CATEGORY_ACCOUNT_CHECK = "account_check"
#: 租约 CK 续期:账号**已经有 CK**,只是租约到期前提前登录续一次。
#: 必须和「首次登录」分开 —— 两者触发方式都是 automation,但预算归属不同,
#: 页面标签也不同(曾经被显示成"自动化·首次登录",排查时非常误导)。
CATEGORY_LEASE_REFRESH = "lease_refresh"
BUSINESS_TZ = ZoneInfo("Asia/Shanghai")
@@ -48,7 +52,11 @@ def classify_login_category(
mode: str,
trigger_source: str = "manual",
now: datetime | None = None,
category: str = "",
) -> str:
# 调用方显式指定分类时优先用它(例如租约 CK 续期)。
if category:
return category
if mode == "check":
return CATEGORY_ACCOUNT_CHECK
if mode == "relogin":
@@ -160,6 +168,8 @@ def _category_limit(setting: LoginQuotaSetting, category: str) -> int:
CATEGORY_RELOGIN_ORDINARY: int(setting.relogin_ordinary_daily_limit),
CATEGORY_MANUAL: int(setting.manual_daily_limit),
CATEGORY_ACCOUNT_CHECK: int(setting.manual_daily_limit),
# 租约续期本质是「提前重登」,借用普通重登的日预算。
CATEGORY_LEASE_REFRESH: int(setting.relogin_ordinary_daily_limit),
}.get(category, int(setting.daily_attempt_limit))
@@ -172,6 +182,7 @@ def reserve_login_attempt(
batch_id: str,
created_by: int | None,
now: datetime | None = None,
category: str = "",
) -> QuotaDecision:
moment = now or datetime.now(UTC)
quota_day, quota_hour = _bucket(moment)
@@ -182,6 +193,7 @@ def reserve_login_attempt(
mode=mode,
trigger_source=trigger_source,
now=moment,
category=category,
)
attempt = LoginAttempt(
account_id=int(account.id),
@@ -239,6 +251,7 @@ def reserve_login_attempt(
mode=mode,
trigger_source=trigger_source,
now=moment,
category=category,
)
if _category_daily_total(db, quota_day, category) >= _category_limit(
setting, category
@@ -328,6 +341,7 @@ def cleanup_orphan_login_attempts(
__all__ = [
"CATEGORY_ACCOUNT_CHECK",
"CATEGORY_LEASE_REFRESH",
"CATEGORY_MANUAL",
"CATEGORY_ONBOARDING",
"CATEGORY_RELOGIN_HIGH",