From 938036437628ac4730b58ac9c11c46d5d80dafd7 Mon Sep 17 00:00:00 2001 From: Chaim Date: Mon, 30 Mar 2026 11:44:26 +0000 Subject: [PATCH] fix: stale deploy check only looks at latest deploy per extension+customer Was showing all historical deploys causing noise. Now uses DISTINCT ON to get only the most recent deploy for each extension+customer pair. Co-Authored-By: Claude Opus 4.6 (1M context) --- server.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/server.py b/server.py index 698e044..6a7eac3 100644 --- a/server.py +++ b/server.py @@ -535,16 +535,21 @@ def health_check_all(): customer_results.append(cr) - # 3. Check for stale deployments (status ok but installed_version not updated) - stale = query("""SELECT dl.version as deployed_version, e.name as extension, c.name as customer, - ce.installed_version, dl.started_at - FROM deployment_log dl - JOIN extensions e ON dl.extension_id = e.id - JOIN customers c ON dl.customer_id = c.id - LEFT JOIN customer_extensions ce ON ce.customer_id = dl.customer_id AND ce.extension_id = dl.extension_id - WHERE dl.status = 'ok' AND dl.started_at > NOW() - INTERVAL '24 hours' - AND (ce.installed_version IS NULL OR ce.installed_version != dl.version) - ORDER BY dl.started_at DESC""") + # 3. Check for stale deployments (latest deploy per extension+customer says ok but version doesn't match) + stale = query("""SELECT latest.version as deployed_version, e.name as extension, c.name as customer, + ce.installed_version, latest.started_at + FROM ( + SELECT DISTINCT ON (customer_id, extension_id) + customer_id, extension_id, version, status, started_at + FROM deployment_log + WHERE started_at > NOW() - INTERVAL '24 hours' + ORDER BY customer_id, extension_id, started_at DESC + ) latest + JOIN extensions e ON latest.extension_id = e.id + JOIN customers c ON latest.customer_id = c.id + LEFT JOIN customer_extensions ce ON ce.customer_id = latest.customer_id AND ce.extension_id = latest.extension_id + WHERE latest.status = 'ok' + AND (ce.installed_version IS NULL OR ce.installed_version != latest.version)""") for s in stale: issues.append({'check': 'stale_deploy', 'extension': s['extension'], 'severity': 'warning', 'message': f'{s["customer"]}: deployed {s["deployed_version"]} but installed shows {s["installed_version"] or "NULL"}'})