fix(healing): judge post-heal verification against the pre-heal decisions
CI / Unit tests (push) Successful in 3s
CI / Unit tests (pull_request) Successful in 3s

A decision issued in the seconds between a heal and its verification is
missing from the kernel until the bouncer's next poll, so verification
reported the heal as failed even though it had fixed the drift it was
started for. Seen on a node: a metadata heal fixed a stale TTL, a new
ban arrived inside the 5 s window, and the heal was logged as failed;
the next audit found the node in sync.

reconcile() now records the decision values it saw (last_truth_values)
and takes an optional baseline_truth. Post-heal verification passes the
values the drift was found against; values whose LAPI membership changed
since then are left out of the drift, logged with a count, returned as
lapi_changed_values, and checked by the next regular audit. Drift on
decisions that existed when the heal started still fails verification.
The regular audit and the membership re-check are unchanged.

Tests: baseline handling in reconcile, the verification call, and a
replay of the logged sequence (failed before, success now). 78 tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
patrickandClaude Opus 5.5 committed 2026-11-13 23:32:41 -05:00
1 parent 6cb7fae06a
commit 16338a2507
5 files changed
+161 -4

No files matched your search

+1
View File
@@ -355,6 +355,7 @@ See [Range decisions](#range-decisions).
- This agent is best suited for hosts where CrowdSec enforcement correctness matters enough to justify active reconciliation.
- It is intentionally conservative about repeated heals and uses drift fingerprints to suppress flap loops.
- Post-heal verification is part of the design, not an optional extra: a restart is not treated as success unless state actually converges.
- Verification is judged against the decisions the heal started from. A decision issued or removed during the verification window (which the bouncer applies on its next poll) is logged as `lapi_changed` and left to the next audit, so it is not counted as a failed heal. Drift on decisions that existed when the heal started still fails verification.
- `doctor.py` should be run before first deployment or after major environment changes.
---