Skip to content

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

TypeScript

fix(e2e): make a 200-with-stale-policy readiness observation fatal, not retryable [R3-B4]

Alfredo Lopezaf5863937f68
diff --git a/scripts/e2e/e2e-hcc-mcp-context-readiness.sh b/scripts/e2e/e2e-hcc-mcp-context-readiness.sh
index 7d610e72f..c3720290b 100755
--- a/scripts/e2e/e2e-hcc-mcp-context-readiness.sh
+++ b/scripts/e2e/e2e-hcc-mcp-context-readiness.sh
@@ -145,10 +145,18 @@ wait_until() {
wait_until_fast() {
local timeout=$1 description=$2
shift 2
- local deadline now
+ local deadline now rc
deadline=$(( $(date +%s) + timeout ))
while :; do
"$@" && return 0
+ rc=$?
+ # rc=2 is a fatal, non-retryable ordering violation (e.g. 200 observed with
+ # a stale policy still present): stop polling immediately so a later clean
+ # poll cannot mask it. rc=1 is benign "not ready yet".
+ if [ "$rc" -eq 2 ]; then
+ echo "FATAL ordering violation while waiting for ${description}: ${HCC_READY_PROBE_DIAGNOSTIC:-unset}" >&2
+ return 2
+ fi
now="$(date +%s)"
[ "$now" -lt "$deadline" ] || break
sleep 0.5
@@ -784,12 +792,24 @@ probe_new_hcc_ready_endpoint() {
}
hcc_ready_after_stale_policy_revoked() {
+ # A single poll that sees 200 WHILE the stale policy is still present is a
+ # safety-contract violation and must be FATAL, never retried: retrying lets a
+ # later poll (policy already revoked) turn the violation into a false PASS.
+ # rc=2 signals that fatal ordering violation to wait_until_fast; rc=1 is a
+ # benign "not ready yet, keep polling". The sub-0.5s window where revocation
+ # races the probe inside one poll stays unobservable on THIS signal — the
+ # third signal (M6, /metrics) covers it.
+ local policy_absent_before=0
+ external_egress_policy_absent && policy_absent_before=1
probe_new_hcc_ready_endpoint || return 1
if external_egress_policy_absent; then
- return 0
+ [ "$policy_absent_before" -eq 1 ] && return 0
+ # Revocation raced the probe inside this poll: the final state is clean but
+ # this poll cannot adjudicate the order. Retry to adjudicate cleanly.
+ return 1
fi
- HCC_READY_PROBE_DIAGNOSTIC="HCC_READY_PROBE category=stale-policy-present"
- return 1
+ HCC_READY_PROBE_DIAGNOSTIC="HCC_READY_PROBE category=ready-200-with-stale-policy-present"
+ return 2
}
hcc_restore_is_verified() {
diff --git a/scripts/tests/test-hcc-watch-recovery-gate.sh b/scripts/tests/test-hcc-watch-recovery-gate.sh
index b0e668f8a..d696ccc90 100755
--- a/scripts/tests/test-hcc-watch-recovery-gate.sh
+++ b/scripts/tests/test-hcc-watch-recovery-gate.sh
@@ -876,12 +876,41 @@ if (
probe_new_hcc_ready_endpoint() { return 0; }
external_egress_policy_absent() { return 1; }
eval "$hcc_ready_after_revoke_function"
- ! hcc_ready_after_stale_policy_revoked &&
- [ "$HCC_READY_PROBE_DIAGNOSTIC" = 'HCC_READY_PROBE category=stale-policy-present' ]
+ rc=0
+ hcc_ready_after_stale_policy_revoked || rc=$?
+ # A 200 observed WITH the stale policy present is a fatal ordering violation
+ # (rc=2), not a benign retryable "not ready" (rc=1).
+ [ "$rc" -eq 2 ] &&
+ [ "$HCC_READY_PROBE_DIAGNOSTIC" = 'HCC_READY_PROBE category=ready-200-with-stale-policy-present' ]
); then
- pass "global readiness evidence rejects a surviving divergent policy"
+ pass "global readiness evidence flags a surviving divergent policy as a fatal rc=2 ordering violation"
else
- fail "global readiness can self-confirm while a divergent policy survives"
+ fail "global readiness can self-confirm (or only soft-fail) while a divergent policy survives"
+fi
+# The loop must PROPAGATE the fatal rc=2 immediately, not retry until a later
+# clean poll turns the violation into a false PASS (the round-2 bug).
+wait_until_fast_function="$(
+ sed -n '/^wait_until_fast() {$/,/^}$/p' "$MCP_READINESS_GATE"
+)"
+if (
+ HCC_READY_PROBE_DIAGNOSTIC=""
+ POLL=0
+ probe_new_hcc_ready_endpoint() { return 0; }
+ # Stale policy present for the first polls, revoked only later. The buggy
+ # retry loop would poll past the fatal first observation and PASS here.
+ external_egress_policy_absent() { POLL=$((POLL + 1)); [ "$POLL" -gt 4 ]; }
+ eval "$hcc_ready_after_revoke_function"
+ eval "$wait_until_fast_function"
+ rc=0
+ wait_until_fast 10 "rc=2 propagation" hcc_ready_after_stale_policy_revoked || rc=$?
+ # rc must be the fatal 2, and it must have stopped inside the first predicate
+ # poll (which calls external_egress_policy_absent twice) — POLL<3 proves no
+ # retry occurred.
+ [ "$rc" -eq 2 ] && [ "$POLL" -lt 3 ]
+); then
+ pass "wait_until_fast propagates a fatal rc=2 on the first poll instead of retrying to a false PASS"
+else
+ fail "wait_until_fast retried past a fatal ordering violation to a later clean poll"
fi
if (
probe_new_hcc_ready_endpoint() { return 1; }