diff --git a/volc_limit_sync.py b/volc_limit_sync.py index f4e74e2..556c7aa 100644 --- a/volc_limit_sync.py +++ b/volc_limit_sync.py @@ -1189,6 +1189,16 @@ class DailyLimitHandler(CustomLogger): level="DEBUG", ) + # 幂等防重:litellm 对同一请求可能调用两次 async_pre_call_hook + # (proxy 级 + deployment 级),第二次预扣会重复占 inflight 且 + # 结算只释放一次 → 残留累积。已有 reserve 标记时跳过预扣直接放行。 + try: + _existing_meta = data.get("metadata") or {} + if isinstance(_existing_meta, dict) and PREBLOCK_RESERVE_META_KEY in _existing_meta: + return data + except Exception: + pass + blocked = _check_request_block(data["model"], reserve=reserve) if not blocked: # 放行:Lua 原子闸门已把 reserve 预扣进 inflight 账户。