From e01919e59fa7b803f6191e1677abcbd752c331e8 Mon Sep 17 00:00:00 2001 From: BISAM20 Date: Fri, 20 Mar 2026 13:38:31 +0100 Subject: [PATCH] fix: throttle index builder and handle 429 rate limit errors - Add 1.5s sleep between repos in build_full_index() to stay under HF's 500 req/300s unauthenticated rate limit (~2 API calls per repo) - Retry list_repo_files() after 429, honouring the Retry-after value Co-Authored-By: Claude Sonnet 4.6 --- model_manager.py | 20 ++++++++++++++++++-- pyproject.toml | 2 +- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/model_manager.py b/model_manager.py index ed5f2b4..f555542 100644 --- a/model_manager.py +++ b/model_manager.py @@ -5,6 +5,7 @@ file classification, downloading. import os import re import threading +import time import uuid import requests from pathlib import Path @@ -395,6 +396,7 @@ def build_full_index() -> None: except Exception: pass _index_status["done"] += 1 + time.sleep(1.5) # ~2 HF API calls per repo; stay well under 500 req/300s limit except Exception as e: _index_status["error"] = str(e) finally: @@ -561,8 +563,22 @@ def list_repo_files(repo_id: str, include_workflows: bool = False) -> list[dict] try: all_files = list(api.list_repo_files(repo_id)) except Exception as e: - print(f"[ModelDownloader] Error listing files for {repo_id}: {e}") - return [] + err_str = str(e) + if "429" in err_str: + # Extract retry-after seconds if present, default to 60 + import re as _re + m = _re.search(r"Retry after (\d+) seconds", err_str) + wait = int(m.group(1)) if m else 60 + print(f"[ModelDownloader] Rate limited on {repo_id}, retrying after {wait}s…") + time.sleep(wait) + try: + all_files = list(api.list_repo_files(repo_id)) + except Exception as e2: + print(f"[ModelDownloader] Error listing files for {repo_id} after retry: {e2}") + return [] + else: + print(f"[ModelDownloader] Error listing files for {repo_id}: {e}") + return [] readme_hints = fetch_readme_hints(repo_id) result = [] diff --git a/pyproject.toml b/pyproject.toml index ebb8bfb..ae2d1c6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "comfyui-advanced-model-manager" -version = "1.0.5" +version = "1.0.6" description = "Advanced Model Manager for ComfyUI — browse, search and download models from HuggingFace and GitHub workflows directly from the ComfyUI interface." license = { file = "LICENSE" } dependencies = [