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) <noreply@anthropic.com>
This commit is contained in:
2026-03-30 11:44:26 +00:00
parent 0c77056422
commit 9380364376
+15 -10
View File
@@ -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"}'})