fix(healing): handle post-heal verify exceptions without crashing loop

This commit is contained in:
patrick committed 2026-03-01 21:14:59 -05:00
1 parent 9edce6b31d
commit 9b53a4c491
2 files changed
+39 -1

No files matched your search

+15
View File
@@ -105,6 +105,7 @@ def execute_heal_and_verify(auditor, reporter, count, drift, heal_verify_delay):
f"(pre_fingerprint={drift.get('fingerprint', '')})."
)
time.sleep(heal_verify_delay)
try:
post_is_synced, post_count, post_drift = auditor.reconcile()
heal_result = "success" if post_is_synced else "failed"
verify_error = None if post_is_synced else "Post-heal verification failed"
@@ -118,6 +119,20 @@ def execute_heal_and_verify(auditor, reporter, count, drift, heal_verify_delay):
f"extra={post_drift.get('extra_count', 0)} "
f"metadata={post_drift.get('metadata_drift_count', 0)}"
)
except Exception as e:
heal_result = "verify_error"
reporter.update_status(False, count, last_error=f"Post-heal verify error: {e}")
post_drift = {
"reason": "verify_error",
"missing_count": 0,
"extra_count": 0,
"metadata_drift_count": 0,
"fingerprint": "",
}
logging.error(
"Post-heal verification crashed "
f"(pre_fingerprint={drift.get('fingerprint', '')}): {e}"
)
else:
reporter.update_status(False, count, last_error="Bouncer restart failed")
logging.error(
+24 -1
View File
@@ -15,9 +15,10 @@ class FakeReporter:
class FakeAuditor:
def __init__(self, heal_ok=True, reconcile_result=None):
def __init__(self, heal_ok=True, reconcile_result=None, reconcile_exception=None):
self.heal_ok = heal_ok
self.reconcile_result = reconcile_result
self.reconcile_exception = reconcile_exception
self.last_heal_drift = None
def heal(self):
@@ -28,6 +29,8 @@ class FakeAuditor:
return self.heal_ok
def reconcile(self):
if self.reconcile_exception:
raise self.reconcile_exception
return self.reconcile_result
@@ -108,6 +111,26 @@ class PostHealVerificationTests(unittest.TestCase):
self.assertEqual("not_verified", returned_post_drift["reason"])
self.assertEqual([(False, 7, "Bouncer restart failed")], reporter.update_calls)
@patch("healing.time.sleep", return_value=None)
def test_execute_heal_and_verify_verify_exception(self, _sleep):
reporter = FakeReporter()
auditor = FakeAuditor(heal_ok=True, reconcile_exception=RuntimeError("boom"))
heal_result, returned_post_drift = execute_heal_and_verify(
auditor,
reporter,
count=7,
drift={"fingerprint": "pre123"},
heal_verify_delay=0,
)
self.assertEqual("verify_error", heal_result)
self.assertEqual("verify_error", returned_post_drift["reason"])
self.assertEqual(1, len(reporter.update_calls))
self.assertFalse(reporter.update_calls[0][0])
self.assertEqual(7, reporter.update_calls[0][1])
self.assertIn("Post-heal verify error: boom", reporter.update_calls[0][2])
if __name__ == "__main__":
unittest.main()