Skip to content

fix(e2e): stop treating a failed etcd read as "the mirror expired" (#597) - #871

Merged
bpalermo merged 1 commit into
mainfrom
fix/597-mirror-read-failure
Sep 20, 2026
Merged

bpalermo merged 1 commit into
mainfrom
fix/597-mirror-read-failure

Conversation

@bpalermo

Copy link
Copy Markdown
Owner

Closes #597.

It was never a flake in the sense everyone assumed

The replicator e2e went red on 09-18 and 09-19 after sixteen consecutive green runs. The decisive datum: 09-17 and 09-18 built the same commit 0459c2a4 with opposite outcomes, so no bisect could ever have found it. Both standing hypotheses — an intermittent stall, and a 30 s budget that is too tight — predict exactly that pattern, which is why more observation could not separate them.

Neither is the cause.

mirror_present() {
    docker exec ... etcdctl get --prefix ... --keys-only 2>/dev/null | grep -q .
}

Stderr is discarded and the pipeline's status is grep's. A docker exec that could not start, or an etcdctl that timed out, produces no output — and is therefore indistinguishable from "the keys are gone". Step 3's expiry loop breaks on the first "gone", so a single hiccup on a contended runner (two kind clusters, 2× SPIRE, 2× etcd on ubuntu-latest) made the harness declare the mirror expired while it was still there, and start its 30 s stopwatch up to ~29 s before the event it claims to measure.

Reconstructed from the 09-18 logs, the mesh withdrew in ~150 ms. The harness was timing the wrong interval.

What changes

  • mirror_state() replaces the boolean with three values — present / absent / read failed. Read failures are loud on stderr, carry --command-timeout=5s, and can never mean "absent". Only a successful read that finds nothing may anchor the stopwatch.
  • The origin-data check had the same defect somewhere worse: a failed read made it report "region's ORIGIN data vanished from its own etcd" — a spurious hard failure asserting data loss. Now distinguished.
  • Step 3 measures instead of only judging. Samples at ~1 s rather than 6×5 s and prints AETHER_METRIC replicator_withdraw_seconds on every run, pass or fail. Budget stays 30 s; the cap is 120 s so a run that blows the budget still yields a number. A red run now says how far past it went — which discriminates the hypotheses on a single failure rather than needing a distribution over twenty runs.

Also: a vacuous gate in the same file

dump_failover_state() concluded "Envoy STILL holds echo hosts" from grep -i echo | head -40 over admin /clusters. But /clusters prints ~15 config rows per cluster before any host row, and there are three echo clusters — so head -40 can never reach one. It printed that verdict on the 09-18 dump, which contains zero host rows. The verdict was asserted on no evidence. Now filtered to rows carrying an address (::<ip>:<port>::).

Verification — by reproducing the bug, not by inspection

The original implementation, run verbatim against stubbed failures:

MODE      | old verdict | expiry loop would...
present   | present     | keep waiting (correct)
absent    | ABSENT      | ANCHOR THE STOPWATCH
execfail  | ABSENT      | ANCHOR THE STOPWATCH  <-- wrong: read failed
timeout   | ABSENT      | ANCHOR THE STOPWATCH  <-- wrong: read failed

mirror_state() returns 0 / 1 / 2 / 2 on those same four inputs.

Host-row filter, both directions:

dump new filter old filter
config rows only (withdrawal succeeded) 0 rows ✅ 17 rows → verdict fires on zero hosts ❌
with host rows (withdrawal stalled) 3 rows ✅ —

bash -n clean; bazel build --config=lint --@aspect_rules_lint//lint:fail_on_violation //e2e:all passes and does actually lint the target (Linting //e2e:e2e_shell with ShellCheck), which is not something I take for granted after #853.

What this deliberately does not do

It does not widen the budget. Measured end to end the path is ~150 ms; after this fix 30 s should come down, not up. Only a correctly-anchored measurement landing repeatedly in the 20–35 s band would justify widening — and now we will have the numbers to tell.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

)

The replicator e2e went red on 2026-09-18 and 09-19 after sixteen consecutive
green runs. 09-17 and 09-18 built the SAME commit (0459c2a) with opposite
outcomes, so no bisect could have found it, and the two standing hypotheses --
an intermittent stall, or a 30s budget that is too tight -- both predict
exactly that pattern. Neither is what happened.

    mirror_present() {
        docker exec ... etcdctl get --prefix ... --keys-only 2>/dev/null | grep -q .
    }

Stderr is discarded and the pipeline's status is grep's, so a docker exec that
could not start, or an etcdctl that timed out, produces no output and is
INDISTINGUISHABLE from "the keys are gone". Step 3's expiry loop breaks on the
first "gone", so one hiccup on a contended runner made the harness declare the
mirror expired while it was still there -- and start its 30s stopwatch up to
~29s before the event it claims to measure. Reconstructed from the 09-18 logs,
the mesh actually withdrew in ~150ms.

  - mirror_state() replaces it with three values: present / absent / READ
    FAILED. Read failures are loud on stderr, carry --command-timeout=5s, and
    can never mean "absent". Only a successful read that finds nothing may
    anchor the stopwatch.
  - The origin-data check had the same defect in a worse place: a failed read
    made it report "region's ORIGIN data vanished from its own etcd", a
    spurious hard failure. It now distinguishes the two.
  - Step 3 samples the client call at ~1s instead of 6x5s and prints
    AETHER_METRIC replicator_withdraw_seconds on EVERY run, pass or fail. The
    budget stays 30s; the cap is 120s, so a run that blows the budget still
    yields a number. A red run now says how far past it went, which separates
    the hypotheses on a single failure instead of needing twenty runs.

Also fixes a vacuous gate in the same file. dump_failover_state() decided
"Envoy STILL holds echo hosts" from `grep -i echo | head -40` over admin
/clusters -- but /clusters prints ~15 config rows per cluster before any host
row, and there are three echo clusters, so head -40 can never reach one. It
printed that verdict on the 09-18 dump, which contains zero host rows. Now
filtered to rows carrying an address.

Verified by reproducing the bug rather than by inspection:

  MODE      | old verdict | expiry loop would...
  present   | present     | keep waiting (correct)
  absent    | ABSENT      | ANCHOR THE STOPWATCH
  execfail  | ABSENT      | ANCHOR THE STOPWATCH  <-- wrong
  timeout   | ABSENT      | ANCHOR THE STOPWATCH  <-- wrong

and mirror_state returns 0/1/2/2 on those same four inputs. The host-row
filter returns 0 rows on a config-only dump and 3 on one with hosts, where the
old filter returned 17 rows on the config-only dump -- i.e. fired the verdict
on zero hosts.

Deliberately does NOT widen the budget: measured end to end the path is
~150ms, so after this fix 30s should come down, not up.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
@bpalermo
bpalermo merged commit c6b7198 into main Sep 20, 2026
22 checks passed
@bpalermo
bpalermo deleted the fix/597-mirror-read-failure branch September 20, 2026 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

flaky: replicator e2e — endpoint withdrawal >30s when the designed path is watch-speed (sub-second)

1 participant