Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

test(hcc): accept causally covered watch recovery

Alfredo Lopez30cd4ae9f6f3
diff --git a/scripts/e2e/_lib/hcc-watch-recovery-logs.sh b/scripts/e2e/_lib/hcc-watch-recovery-logs.sh
index a555b8636..f0857c3d5 100755
--- a/scripts/e2e/_lib/hcc-watch-recovery-logs.sh
+++ b/scripts/e2e/_lib/hcc-watch-recovery-logs.sh
@@ -71,7 +71,8 @@ recovery_cycle_used_fresh_host_inventory() {
hcc_recovery_logs | awk \
-v target="$cycle" -v host_namespace="$HOST_NS" -v expected="$expected_count" '
BEGIN {
- inventory_line = "Reconciling " expected " Host(s) for lifecycle after CommunicationChannel recovery"
+ channel_inventory = "Reconciling " expected " Host(s) for lifecycle after CommunicationChannel recovery"
+ host_inventory = "Reconciling " expected " Host(s) after Host watch recovery convergence"
succeeded = 0
}
/CommunicationChannel watch ended;/ {
@@ -80,7 +81,7 @@ recovery_cycle_used_fresh_host_inventory() {
if (inside) {
listed = 0
recovered = 0
- inventory_matched = 0
+ completion_mode = ""
}
next
}
@@ -90,11 +91,20 @@ recovery_cycle_used_fresh_host_inventory() {
inside && /Recovered [0-9]+ CommunicationChannel\(s\) into cache/ {
recovered = 1
}
- inside && index($0, inventory_line) > 0 {
- inventory_matched = 1
+ inside && listed && recovered && index($0, channel_inventory) > 0 {
+ completion_mode = "channel"
}
- inside && /Completed Host reconciliation after CommunicationChannel recovery$/ {
- succeeded = listed && recovered && inventory_matched
+ inside && listed && recovered && index($0, host_inventory) > 0 {
+ completion_mode = "host"
+ }
+ inside && completion_mode == "channel" &&
+ /Completed Host reconciliation after CommunicationChannel recovery$/ {
+ succeeded = 1
+ exit
+ }
+ inside && completion_mode == "host" &&
+ /Completed Host reconciliation after Host watch recovery convergence$/ {
+ succeeded = 1
exit
}
END {
@@ -102,3 +112,15 @@ recovery_cycle_used_fresh_host_inventory() {
}
'
}
+
+wait_recovery_cycle_fresh_host_inventory() {
+ local cycle=$1 expected_count=$2 timeout=$3 elapsed=0
+ while [ "$elapsed" -lt "$timeout" ]; do
+ require_hcc_recovery_log_stream || return 1
+ recovery_cycle_used_fresh_host_inventory "$cycle" "$expected_count" && return 0
+ sleep 2
+ elapsed=$((elapsed + 2))
+ done
+ hcc_recovery_logs >&2
+ return 1
+}
diff --git a/scripts/e2e/e2e-hcc-communicationchannel-watch-recovery.sh b/scripts/e2e/e2e-hcc-communicationchannel-watch-recovery.sh
index 530b0223a..42bfee3e2 100755
--- a/scripts/e2e/e2e-hcc-communicationchannel-watch-recovery.sh
+++ b/scripts/e2e/e2e-hcc-communicationchannel-watch-recovery.sh
@@ -261,14 +261,13 @@ ok "isolated Host fleet reached its baseline"
run_recovery_cycle() {
local cycle=$1 cycle_logs recovery_logs outage_started outage_seconds max_retry_failures list_pattern
- local host_list_pattern ended_before started_before recovered_before completed_before failed_before
+ local host_list_pattern ended_before started_before recovered_before failed_before
local list_before host_list_before expected_host_count
local failed_after retry_failures
cycle_logs="$(hcc_recovery_logs)"
ended_before="$(log_count_from "$cycle_logs" 'CommunicationChannel watch ended;')"
started_before="$(log_count_from "$cycle_logs" 'Starting CommunicationChannel watch')"
recovered_before="$(log_count_from "$cycle_logs" 'Recovered [0-9]+ CommunicationChannel\(s\) into cache')"
- completed_before="$(log_count_from "$cycle_logs" 'Completed Host reconciliation after CommunicationChannel recovery$')"
failed_before="$(log_count_from "$cycle_logs" 'cache recovery failed;')"
list_pattern="Listing all CommunicationChannels in namespace ${CHANNEL_NS}"
host_list_pattern="Listing all Hosts in namespace ${HOST_NS}"
@@ -312,10 +311,7 @@ run_recovery_cycle() {
max_retry_failures=$((
(outage_seconds + CC_RECOVERY_RETRY_SECONDS - 1) / CC_RECOVERY_RETRY_SECONDS + 2
))
- wait_log_count 'Completed Host reconciliation after CommunicationChannel recovery$' \
- "$((completed_before + 1))" 180 ||
- die "Host fleet did not converge after snapshot recovery in cycle ${cycle}"
- recovery_cycle_used_fresh_host_inventory "$cycle" "$expected_host_count" ||
+ wait_recovery_cycle_fresh_host_inventory "$cycle" "$expected_host_count" 180 ||
die "cycle ${cycle} did not reconcile the fresh ${expected_host_count}-Host inventory"
recovery_logs="$(hcc_recovery_logs)"
failed_after="$(log_count_from "$recovery_logs" 'cache recovery failed;')"
@@ -363,14 +359,18 @@ ended="$(log_count_from "$final_logs" 'CommunicationChannel watch ended;')"
started="$(log_count_from "$final_logs" 'Starting CommunicationChannel watch')"
recovered="$(log_count_from "$final_logs" 'Recovered [0-9]+ CommunicationChannel\(s\) into cache')"
failed="$(log_count_from "$final_logs" 'cache recovery failed;')"
-fleet_passes="$(log_count_from "$final_logs" 'Completed Host reconciliation after CommunicationChannel')"
+fleet_passes="$(
+ log_count_from "$final_logs" \
+ 'Completed Host reconciliation after (CommunicationChannel recovery|Host watch recovery convergence)$'
+)"
[ "$ended" = 2 ] && [ "$started" = 2 ] && [ "$recovered" = 2 ] && \
[ "$failed" = "$TOTAL_RETRY_FAILURES" ] && [ "$failed" -le "$TOTAL_RETRY_FAILURE_LIMIT" ] ||
die "unexpected watch lifecycle counts: ended=${ended}, started=${started}, recovered=${recovered}, failed=${failed}"
[ "$fleet_passes" -ge 2 ] && [ "$fleet_passes" -le 4 ] ||
die "unexpected successful fleet reconcile count ${fleet_passes}; expected 2..4 passes"
-# Each recovered snapshot requires one successful pass; at most one already
-# queued fail-closed pass may also finish per cycle. The deterministic
+# Each recovered snapshot requires one causally ordered successful pass; a
+# Host-watch recovery pass may cover the same fresh CC+Host inventories. At
+# most one already queued covering pass may also finish per cycle. The deterministic
# max-concurrency=1 proof stays in k8sClient unit tests where overlapping passes
# can be barrier-controlled.
diff --git a/scripts/tests/test-hcc-watch-recovery-gate.sh b/scripts/tests/test-hcc-watch-recovery-gate.sh
index 1c77d37c4..b73b3ccb3 100755
--- a/scripts/tests/test-hcc-watch-recovery-gate.sh
+++ b/scripts/tests/test-hcc-watch-recovery-gate.sh
@@ -459,6 +459,30 @@ else
fail "valid LIST-to-recovery ordering was rejected"
fi
+printf '%s\n' \
+ '[K8s] CommunicationChannel watch ended; holding stateless lifecycle active until snapshot recovery' \
+ '[K8s] Listing all Hosts in namespace mcp-host' \
+ '[K8s] Recovered 2 CommunicationChannel(s) into cache (ccCacheSynced=true)' \
+ '[K8s] Reconciling 5 Host(s) after Host watch recovery convergence' \
+ '[K8s] Completed Host reconciliation after Host watch recovery convergence' >"$MOCK_LOG_FILE"
+if recovery_cycle_used_fresh_host_inventory 1 5; then
+ pass "a causally ordered Host-watch pass may cover the recovered CC and fresh Host inventories"
+else
+ fail "a valid covering Host-watch recovery pass was rejected"
+fi
+
+printf '%s\n' \
+ '[K8s] CommunicationChannel watch ended; holding stateless lifecycle active until snapshot recovery' \
+ '[K8s] Listing all Hosts in namespace mcp-host' \
+ '[K8s] Reconciling 5 Host(s) after Host watch recovery convergence' \
+ '[K8s] Recovered 2 CommunicationChannel(s) into cache (ccCacheSynced=true)' \
+ '[K8s] Completed Host reconciliation after Host watch recovery convergence' >"$MOCK_LOG_FILE"
+if recovery_cycle_used_fresh_host_inventory 1 5; then
+ fail "a Host-watch pass selected before CC recovery satisfied the covering assertion"
+else
+ pass "covering Host-watch recovery requires recovered CC state before pass selection"
+fi
+
printf '%s\n' \
'[K8s] Listing all Hosts in namespace mcp-host' \
'[K8s] CommunicationChannel watch ended; holding stateless lifecycle active until snapshot recovery' \