feat(reporter): persist drift metrics and last heal result in state snapshot

This commit is contained in:
patrick committed 2026-03-05 20:35:18 -05:00
1 parent c698d01c40
commit b34ac69ac1
5 files changed
+160 -14

No files matched your search

+32 -4
View File
@@ -86,8 +86,9 @@ def execute_heal_and_verify(auditor, reporter, count, drift, heal_verify_delay):
"""
Executes heal + post-heal verification and persists reporter state.
"""
drift = drift or {}
if hasattr(auditor, "heal_with_drift"):
heal_ok = auditor.heal_with_drift(drift or {})
heal_ok = auditor.heal_with_drift(drift)
else:
heal_ok = auditor.heal()
heal_result = "restart_failed"
@@ -109,7 +110,16 @@ def execute_heal_and_verify(auditor, reporter, count, drift, heal_verify_delay):
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"
reporter.update_status(post_is_synced, post_count, last_error=verify_error)
reporter.update_status(
post_is_synced,
post_count,
last_error=verify_error,
missing_count=post_drift.get("missing_count", 0),
extra_count=post_drift.get("extra_count", 0),
metadata_drift_count=post_drift.get("metadata_drift_count", 0),
last_drift_fingerprint=post_drift.get("fingerprint", ""),
last_heal_result=heal_result,
)
logging.warning(
"Post-heal verification result "
@@ -121,7 +131,16 @@ def execute_heal_and_verify(auditor, reporter, count, drift, heal_verify_delay):
)
except Exception as e:
heal_result = "verify_error"
reporter.update_status(False, count, last_error=f"Post-heal verify error: {e}")
reporter.update_status(
False,
count,
last_error=f"Post-heal verify error: {e}",
missing_count=0,
extra_count=0,
metadata_drift_count=0,
last_drift_fingerprint=drift.get("fingerprint", ""),
last_heal_result=heal_result,
)
post_drift = {
"reason": "verify_error",
"missing_count": 0,
@@ -134,7 +153,16 @@ def execute_heal_and_verify(auditor, reporter, count, drift, heal_verify_delay):
f"(pre_fingerprint={drift.get('fingerprint', '')}): {e}"
)
else:
reporter.update_status(False, count, last_error="Bouncer restart failed")
reporter.update_status(
False,
count,
last_error="Bouncer restart failed",
missing_count=drift.get("missing_count", 0),
extra_count=drift.get("extra_count", 0),
metadata_drift_count=drift.get("metadata_drift_count", 0),
last_drift_fingerprint=drift.get("fingerprint", ""),
last_heal_result=heal_result,
)
logging.error(
f"Heal restart failed; skipping verification "
f"(pre_fingerprint={drift.get('fingerprint', '')})."