From eb3abe2ccaeba4bcdba00731eb84eb8e358f3a55 Mon Sep 17 00:00:00 2001 From: Holden Date: Sun, 14 Jun 2026 01:23:46 +0000 Subject: [PATCH] Fix misleading HTTP 500 detail and RuntimeWarning on single-image selection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - HTTP 500 errors from Frigate no longer echo the response body to the user (Frigate's generic message says 'Try restarting Frigate' which is wrong — 500s on upload are almost always image-specific, not a health issue). The detail is now logged at debug level. HTTP 400 detail is still shown since 'No face was detected' is genuinely useful. - np.median on empty upper triangle (n=1 after quality filtering) no longer emits RuntimeWarning; _compute_adaptive_threshold returns the floor (0.05) immediately when there are no pairwise distances to sample. - k-medoids cluster count floor raised to 1 (was 0 when n < 3), preventing k=0 being passed to _kmedoids. --- winnow/diversity.py | 4 +++- winnow/executor.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/winnow/diversity.py b/winnow/diversity.py index 711846c..8976d0d 100644 --- a/winnow/diversity.py +++ b/winnow/diversity.py @@ -373,6 +373,8 @@ def _compute_adaptive_threshold(emb_normed: np.ndarray, entity_type: str) -> flo # Compute pairwise cosine distances for the sample pairwise = 1 - sample @ sample.T upper_tri = pairwise[np.triu_indices(len(sample), k=1)] + if len(upper_tri) == 0: + return 0.05 median_dist = float(np.median(upper_tri)) # Faces: 20% of median (tighter — want fewer, more distinct images) @@ -421,7 +423,7 @@ def _cluster_aware_selection( target = Config.MAX_AUTO_IMAGES if limit == "auto" else limit # --- Stage 1: K-Medoids clustering --- - k = min(max(5, target // 4), n // 3, n) # e.g., 5-20 clusters + k = min(max(5, target // 4), max(1, n // 3), n) # e.g., 1-20 clusters logger.debug(f"Clustering {n} embeddings into {k} groups (K-Medoids)...") # Compute full cosine distance matrix diff --git a/winnow/executor.py b/winnow/executor.py index 2a56521..ab0402e 100644 --- a/winnow/executor.py +++ b/winnow/executor.py @@ -580,10 +580,12 @@ def upload_to_frigate(jobs: list[dict]) -> None: ) try: error_detail = resp.json().get("message", resp.text[:100]) - progress.console.print(f" [dim]{error_detail}[/dim]") except Exception: error_detail = resp.text[:100] + if resp.status_code == 400: progress.console.print(f" [dim]{error_detail}[/dim]") + else: + logger.debug(f"{fname} HTTP {resp.status_code}: {error_detail}") if resp.status_code == 400 and "face" in error_detail.lower(): asset_id = asset_map.get(fname) if asset_id: