feat(healing): add post-restart verification and heal outcome telemetry

This commit is contained in:
patrick committed 2026-02-10 21:55:43 -05:00
1 parent b2c489602a
commit 234224a5c6
3 files changed
+46 -2

No files matched your search

+39 -1
View File
@@ -74,6 +74,7 @@ def main():
node_name = os.getenv("SERVER_NAME", "Unknown Node")
CHECK_INTERVAL = 600
HEAL_VERIFY_DELAY = 5
print(f"[*] Agent started. Check interval: {CHECK_INTERVAL}s")
logging.info(f"Threat Engine Agent initialized on {node_name}.")
@@ -103,7 +104,42 @@ def main():
if should_heal(history_file, drift.get("fingerprint", "")):
logging.warning("Healing approved.")
auditor.heal()
heal_ok = auditor.heal()
heal_result = "restart_failed"
post_drift = {
"reason": "not_verified",
"missing_count": 0,
"extra_count": 0,
"metadata_drift_count": 0,
"fingerprint": "",
}
if heal_ok:
logging.info(
f"Post-heal verification in {HEAL_VERIFY_DELAY}s "
f"(pre_fingerprint={drift.get('fingerprint', '')})."
)
time.sleep(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)
logging.warning(
"Post-heal verification result "
f"result={heal_result} pre={drift.get('fingerprint', '')} "
f"post={post_drift.get('fingerprint', '')} "
f"missing={post_drift.get('missing_count', 0)} "
f"extra={post_drift.get('extra_count', 0)} "
f"metadata={post_drift.get('metadata_drift_count', 0)}"
)
else:
reporter.update_status(False, count, last_error="Bouncer restart failed")
logging.error(
f"Heal restart failed; skipping verification "
f"(pre_fingerprint={drift.get('fingerprint', '')})."
)
reporter.log_heal_event(
count,
drift.get("missing_count", 0),
@@ -111,6 +147,8 @@ def main():
drift.get("metadata_drift_count", 0),
drift.get("fingerprint", ""),
drift.get("reason", "unknown"),
heal_result,
post_drift.get("fingerprint", ""),
)
else:
logging.warning("Healing skipped to prevent flapping.")