fix(reconcile): gate heal flapping by drift fingerprint instead of kernel count
This commit is contained in:
1 parent
3d7c1b3f2a
commit
e342d83a70
3 files changed
+100
-17
No files matched your search
@@ -18,7 +18,7 @@ logging.basicConfig(
|
||||
#### Helpers ###
|
||||
################
|
||||
|
||||
def should_heal(history_file, current_count, min_interval=900):
|
||||
def should_heal(history_file, drift_fingerprint, min_interval=900):
|
||||
"""
|
||||
Prevents heal flapping by suppressing repeated no-op heals.
|
||||
"""
|
||||
@@ -35,13 +35,19 @@ def should_heal(history_file, current_count, min_interval=900):
|
||||
last = lines[-1]
|
||||
ts_str, msg = last.split(" - ", 1)
|
||||
last_time = datetime.fromisoformat(ts_str)
|
||||
last_count = int(msg.split("desync of")[1].split("IPs")[0])
|
||||
last_fingerprint = ""
|
||||
marker = "drift_fingerprint="
|
||||
if marker in msg:
|
||||
last_fingerprint = msg.split(marker, 1)[1].split()[0].strip()
|
||||
|
||||
if not drift_fingerprint:
|
||||
return True
|
||||
|
||||
# If healed recently AND nothing changed, suppress
|
||||
if datetime.now() - last_time < timedelta(seconds=min_interval):
|
||||
if last_count == current_count:
|
||||
if last_fingerprint and last_fingerprint == drift_fingerprint:
|
||||
logging.warning(
|
||||
f"Heal suppressed (recent identical heal: {last_count} IPs)"
|
||||
"Heal suppressed (recent identical drift fingerprint)."
|
||||
)
|
||||
return False
|
||||
|
||||
@@ -73,21 +79,39 @@ def main():
|
||||
|
||||
while True:
|
||||
try:
|
||||
is_synced, count = auditor.reconcile()
|
||||
is_synced, count, drift = auditor.reconcile()
|
||||
reporter.update_status(is_synced, count)
|
||||
|
||||
status_msg = f"Audit Success: {count} IPs in sync." if is_synced else f"DESYNC: {count} in kernel. Healing..."
|
||||
if is_synced:
|
||||
status_msg = f"Audit Success: {count} IPs in sync."
|
||||
else:
|
||||
status_msg = (
|
||||
f"DESYNC: kernel={count}, missing={drift['missing_count']}, "
|
||||
f"extra={drift['extra_count']}, metadata={drift['metadata_drift_count']}. "
|
||||
"Healing..."
|
||||
)
|
||||
print(f"[+] {status_msg}") # This will show up in your terminal!
|
||||
|
||||
if not is_synced:
|
||||
logging.warning(f"Desync detected ({count} IPs in kernel).")
|
||||
logging.warning(
|
||||
"Desync detected "
|
||||
f"(kernel={count}, missing={drift['missing_count']}, "
|
||||
f"extra={drift['extra_count']}, metadata={drift['metadata_drift_count']})."
|
||||
)
|
||||
|
||||
history_file = reporter.state_file.replace(".json", ".history")
|
||||
|
||||
if should_heal(history_file, count):
|
||||
if should_heal(history_file, drift.get("fingerprint", "")):
|
||||
logging.warning("Healing approved.")
|
||||
auditor.heal()
|
||||
reporter.log_heal_event(count)
|
||||
reporter.log_heal_event(
|
||||
count,
|
||||
drift.get("missing_count", 0),
|
||||
drift.get("extra_count", 0),
|
||||
drift.get("metadata_drift_count", 0),
|
||||
drift.get("fingerprint", ""),
|
||||
drift.get("reason", "unknown"),
|
||||
)
|
||||
else:
|
||||
logging.warning("Healing skipped to prevent flapping.")
|
||||
else:
|
||||
|
||||
Reference in new issue
Block a user