Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
fix(release): bound transient convergence API read retries
pulse-triage[bot]a6f90ec181f8
diff --git a/scripts/release_control/reconcile_release_convergence.py b/scripts/release_control/reconcile_release_convergence.pyindex 727d696068..6f40e4f832 100644--- a/scripts/release_control/reconcile_release_convergence.py+++ b/scripts/release_control/reconcile_release_convergence.py@@ -13,6 +13,7 @@ import reimport subprocessimport sysimport tempfile+import timefrom typing import Any, Iterable@@ -214,18 +215,34 @@ class GitHub:*,output: bool = True,token: str = "",+ retry_read: bool = False,) -> str:env = Noneif token:env = os.environ.copy()env["GH_TOKEN"] = token- result = subprocess.run(- [self.gh, *arguments],- check=False,- capture_output=output,- text=True,- env=env,- )+ # Only api()/pages() opt in: never replay an uncertain mutation,+ # download, log-reader refusal, or authentication/authorisation failure.+ for attempt in range(3 if retry_read else 1):+ result = subprocess.run(+ [self.gh, *arguments],+ check=False,+ capture_output=output,+ text=True,+ env=env,+ )+ if (+ result.returncode == 0+ or not retry_read+ or attempt == 2+ or re.search(r"\bHTTP (502|503|504)\b", result.stderr or "") is None+ ):+ break+ print(+ f"Transient GitHub API read failure; retry {attempt + 1}/2.",+ file=sys.stderr,+ )+ time.sleep(attempt + 1)if result.returncode != 0:detail = result.stderr.strip().splitlines() if output else []suffix = f": {detail[-1]}" if detail else ""@@ -249,6 +266,7 @@ class GitHub:endpoint,],token=token,+ retry_read=True,))except json.JSONDecodeError as exc:@@ -258,7 +276,7 @@ class GitHub:return valuedef pages(self, endpoint: str, *, token: str = "") -> list[object]:- output = self._run(["api", "--paginate", endpoint], token=token)+ output = self._run(["api", "--paginate", endpoint], token=token, retry_read=True)decoder = json.JSONDecoder()value: list[object] = []offset = 0diff --git a/scripts/release_control/reconcile_release_convergence_test.py b/scripts/release_control/reconcile_release_convergence_test.pyindex 85502a133f..6661aa02f3 100644--- a/scripts/release_control/reconcile_release_convergence_test.py+++ b/scripts/release_control/reconcile_release_convergence_test.py@@ -50,6 +50,61 @@ def run(}+class TransientReadTests(unittest.TestCase):+ def result(self, code=0, stdout="{}", stderr=""):+ return subprocess.CompletedProcess([], code, stdout=stdout, stderr=stderr)++ def test_pages_discards_partial_output_before_retry(self):+ github = subject.GitHub("rcourtman/Pulse", "gh")+ results = [+ self.result(1, '[{"id": 1}]', "gh: gateway timeout (HTTP 504)"),+ self.result(0, '[{"id": 1}]\n[{"id": 2}]'),+ ]+ with patch.object(subject.subprocess, "run", side_effect=results) as command, patch("time.sleep") as sleep:+ self.assertEqual([[{"id": 1}], [{"id": 2}]], github.pages("repos/example/releases"))+ self.assertEqual(2, command.call_count)+ sleep.assert_called_once_with(1)++ def test_api_retries_transient_errors_with_bounded_backoff(self):+ github = subject.GitHub("rcourtman/Pulse", "gh")+ for status in (502, 503, 504):+ with self.subTest(status=status):+ failure = self.result(1, stderr=f"gh: unavailable (HTTP {status})")+ with patch.object(subject.subprocess, "run", side_effect=[failure, failure, self.result()]) as command, patch("time.sleep") as sleep:+ self.assertEqual({}, github.api("repos/example"))+ self.assertEqual(3, command.call_count)+ self.assertEqual([1, 2], [call.args[0] for call in sleep.call_args_list])++ def test_exhausted_reads_fail_closed(self):+ github = subject.GitHub("rcourtman/Pulse", "gh")+ with patch.object(subject.subprocess, "run", return_value=self.result(1, stderr="gh: timeout (HTTP 504)")) as command, patch("time.sleep") as sleep:+ with self.assertRaisesRegex(subject.ReconciliationError, "HTTP 504"):+ github.pages("repos/example/releases")+ self.assertEqual(3, command.call_count)+ self.assertEqual(2, sleep.call_count)++ def test_nontransient_errors_are_not_retried(self):+ github = subject.GitHub("rcourtman/Pulse", "gh")+ for detail in ("HTTP 401", "HTTP 403", "HTTP 404", "HTTP 429", "terminal escape sequences refused"):+ with self.subTest(detail=detail):+ with patch.object(subject.subprocess, "run", return_value=self.result(1, stderr=detail)) as command, patch("time.sleep") as sleep:+ error = subject.GitHubNotFound if detail == "HTTP 404" else subject.ReconciliationError+ with self.assertRaises(error):+ github.api("repos/example")+ self.assertEqual(1, command.call_count)+ sleep.assert_not_called()++ def test_mutations_are_not_retried(self):+ github = subject.GitHub("rcourtman/Pulse", "gh")+ for payload in (None, {"ref": "main"}):+ with self.subTest(payload=payload):+ with patch.object(subject.subprocess, "run", return_value=self.result(1, stderr="HTTP 504")) as command, patch("time.sleep") as sleep:+ with self.assertRaises(subject.ReconciliationError):+ github.post("repos/example/actions/dispatches", payload)+ self.assertEqual(1, command.call_count)+ sleep.assert_not_called()++class LatestFailedRunsTests(unittest.TestCase):def select(self, releases, runs):return subject.latest_failed_runs(