fix: default remaining to high quota for unknown models on startup and update AGENTS.md

This commit is contained in:
kim
2026-07-08 10:42:14 +08:00
parent 1c8ff7b569
commit 3dd97730b6
4 changed files with 39 additions and 25 deletions
+31 -18
View File
@@ -1025,14 +1025,36 @@ def active_monitor_loop():
beijing_time_ts = now + (8 * 3600)
today_str = time.strftime("%Y-%m-%d", time.gmtime(beijing_time_ts))
# Idle Check
usage_key_global = f"daily_usage:{today_str}:global_total"
current_usage_global = int(redis_client.get(usage_key_global) or 0)
last_usage_global = sum(last_usage_map.values()) if last_usage_map else 0
delta = current_usage_global - last_usage_global
# Idle Check - Only exit idle if a "low quota" model has usage
LOW_QUOTA_THRESHOLD = 800000 # 判定为“低额度”的阈值
model_usages = {}
any_low_quota_usage = False
for m in MONITORED_MODELS:
m_usage = 0
target_hashes = [p[1] for p in MONITORED_MODEL_PAIRS if p[0] == m]
for h in target_hashes:
val = redis_client.get(f"daily_usage:{today_str}:{m}:{h}")
if val: m_usage += float(val)
val_no_hash = redis_client.get(f"daily_usage:{today_str}:{m}")
if val_no_hash: m_usage += float(val_no_hash)
model_usages[m] = m_usage
# Calculate delta for this specific model
m_delta = m_usage - last_usage_map.get(m, 0.0)
# Check if this model is considered "low quota"
rem_key = f"limit:dynamic:volcengine:remaining:{m}"
rem_val = redis_client.get(rem_key)
# 未知额度视为充足,避免首次启动时所有模型被误判为"低额度"
remaining = float(rem_val) if rem_val is not None else float(LOW_QUOTA_THRESHOLD)
if m_delta > 0 and remaining < LOW_QUOTA_THRESHOLD:
any_low_quota_usage = True
time_diff = now - last_sync_time
if delta <= 0:
if not any_low_quota_usage:
if idle_start_time == 0:
idle_start_time = now
else:
@@ -1085,10 +1107,8 @@ def active_monitor_loop():
burst_reason = ""
for model in MONITORED_MODELS:
# 1. Get Current Usage
curr_usage_key = f"limit:dynamic:volcengine:usage:{model}"
curr_usage_val = redis_client.get(curr_usage_key)
curr_usage = float(curr_usage_val) if curr_usage_val else 0.0
# 1. Get Current Usage (calculated above)
curr_usage = model_usages.get(model, 0.0)
# 2. Get Last Synced Usage (Snapshot)
last_usage = last_usage_map.get(model, 0.0)
@@ -1325,15 +1345,8 @@ def active_monitor_loop():
global_min_remaining = temp_min_remaining
# Update snapshots for next iteration delta calculation
current_usage_global_snapshot = 0
for m in MONITORED_MODELS:
uk = f"limit:dynamic:volcengine:usage:{m}"
uv = redis_client.get(uk)
u_val = float(uv) if uv else 0.0
for m, u_val in model_usages.items():
last_usage_map[m] = u_val
current_usage_global_snapshot += u_val
last_usage_map["global"] = current_usage_global_snapshot
last_sync_time = now
if global_min_remaining > 800000: