fix(ai): restore models after successful circuit probe

This commit is contained in:
134 2026-08-27 17:09:33 +08:00 committed by root
parent ac1e586156
commit cb9a90d9ac

View File

@ -537,7 +537,12 @@ export async function recordAiModelHealthSuccess(params: {
if (!existing) return; if (!existing) return;
const now = new Date(); const now = new Date();
const isObservation = isObservationPoolModel(existing); // A request that started before the circuit opened can still prove the
// provider is reachable. Treat that success as the circuit's half-open
// probe instead of leaving the model disabled until the full cooldown.
const recoveredFromAutoDisable = existing.healthStatus === "auto_disabled";
const isObservation =
isObservationPoolModel(existing) || recoveredFromAutoDisable;
const nextRecoverySuccessStreak = isObservation const nextRecoverySuccessStreak = isObservation
? (existing.healthRecoverySuccessStreak || 0) + 1 ? (existing.healthRecoverySuccessStreak || 0) + 1
: 0; : 0;
@ -547,9 +552,7 @@ export async function recordAiModelHealthSuccess(params: {
const updateData: Partial<AiModel> = { const updateData: Partial<AiModel> = {
healthStatus: healthStatus:
existing.healthStatus === "auto_disabled" recoveredToHealthy
? "auto_disabled"
: recoveredToHealthy
? "healthy" ? "healthy"
: isObservation : isObservation
? "degraded" ? "degraded"
@ -566,12 +569,16 @@ export async function recordAiModelHealthSuccess(params: {
healthObservationStartedAt: recoveredToHealthy healthObservationStartedAt: recoveredToHealthy
? null ? null
: isObservation : isObservation
? existing.healthObservationStartedAt ? existing.healthObservationStartedAt || now
: null, : null,
healthUpdatedAt: now, healthUpdatedAt: now,
updatedAt: now, updatedAt: now,
}; };
if (recoveredFromAutoDisable) {
updateData.isEnabled = true;
}
if (recoveredToHealthy) { if (recoveredToHealthy) {
updateData.healthAutoDisabledAt = null; updateData.healthAutoDisabledAt = null;
updateData.healthAutoDisabledReason = null; updateData.healthAutoDisabledReason = null;