fix: harden sub2api codex pool failover

This commit is contained in:
Codex
2026-06-11 20:06:50 +00:00
parent 8b66f6fa95
commit 5b8b3e50d3
5 changed files with 176 additions and 355 deletions
@@ -804,16 +804,6 @@ class Sub2ApiAdmin:
self.request("POST", f"/api/v1/admin/accounts/{account['id']}/schedulable", {"schedulable": bool(schedulable)})
return {"accountId": account.get("id"), "schedulable": bool(schedulable)}
def recover_state(self, account_name):
account = self.account(account_name)
if not account or account.get("id") is None:
return {"skipped": True, "reason": "account-not-found"}
try:
self.request("POST", f"/api/v1/admin/accounts/{account['id']}/recover-state", {})
return {"ok": True, "accountId": account.get("id")}
except Exception as exc:
return {"ok": False, "accountId": account.get("id"), "error": str(exc)}
def upstream_base_url(base_url):
base = str(base_url).rstrip("/")
return base if base.endswith("/v1") else base + "/v1"
@@ -1228,18 +1218,20 @@ def apply_result(result, state, config, now, admin, profile):
was_recovery = bool(quarantine and quarantine.get("active") is True)
action = {"taken": False, "type": None}
if result.get("ok") is True:
quality_gate = account_state.get("qualityGate") if isinstance(account_state.get("qualityGate"), dict) else None
if was_recovery:
if actions_enabled and quarantine.get("applied") is True:
try:
action = {"taken": True, "type": "restore", "result": admin.set_schedulable(name, True), "recoverState": admin.recover_state(name)}
action = {"taken": True, "type": "restore", "result": admin.set_schedulable(name, True)}
except Exception as exc:
action = {"taken": False, "type": "restore-failed", "error": str(exc)}
account_state["quarantine"] = {"active": False, "clearedAt": iso(now), "lastApplied": quarantine.get("applied") is True}
quality_gate = account_state.get("qualityGate") if isinstance(account_state.get("qualityGate"), dict) else None
if quality_gate and quality_gate.get("pending") is True:
account_state["qualityGate"] = {**quality_gate, "pending": False, "clearedAt": iso(now)}
account_state["successStreak"] = 0
account_state["successIntervalMinutes"] = 0
elif isinstance(quarantine, dict) and quarantine.get("active") is not True:
account_state["quarantine"] = {"active": False, "clearedAt": iso(now), "lastApplied": quarantine.get("applied") is True}
if quality_gate and quality_gate.get("pending") is True:
account_state["qualityGate"] = {**quality_gate, "pending": False, "clearedAt": iso(now)}
interval = next_success_interval(account_state, config, profile)
account_state["successStreak"] = int(account_state.get("successStreak") or 0) + 1
account_state["successIntervalMinutes"] = interval