Skip to content

Require a sustained run before recording a route flap - #174

Merged
lance0 merged 4 commits into
masterfrom
fix/route-flap-hysteresis
Nov 14, 2026
Merged

lance0 merged 4 commits into
masterfrom
fix/route-flap-hysteresis

Conversation

@lance0

@lance0 lance0 commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

Symptom

On a hop where a router balances per packet, ! route-change history kept growing even though the hop was already classified as per-packet ECMP (E). A simulated 600-round run with responders chosen 50/50 at random recorded 9 route changes. The opposite failure also existed: after 200 rounds on one router, 20 rounds on a new one recorded no change at all.

Strict round-robin (A, B, A, B...) did not reproduce on master. Its cumulative counts never differ by 2. The false alarms need the random interleaving a real balancer shows once other traffic shares it.

Root cause

record_response_detecting_flaps_with_extensions switched its tracked primary when another responder's cumulative count led by 2. Under random per-packet balancing the count difference is a random walk that keeps crossing zero, so the tracked primary flipped repeatedly. A real change was only seen once the new responder outnumbered the old one's whole history. The main table hid ! behind E, which masked the false alarms, but the hop detail view and JSON export still carried them. It also hid real changes: after a genuine move, the cumulative split can drop below 70% for a long time.

Fix

  • A responder must answer FLAP_CONFIRM_RESPONSES (5) times in a row to become the hop's stable responder or to replace it. Blips and alternation never qualify. A real change is recorded 5 rounds after it happens, however long the old path was in use.
  • No change is recorded if, when the new run began, no responder held 70% of the hop's responses. That is the same ratio test E uses, applied to the history before the run, so the new path's own responses can't hide it, and without the 8-response minimum, so warm-up balancing is covered too. The tracked primary still moves, so later changes compare against the current path.
  • MIN_RESPONSES_FOR_FLAP and the margin are gone; a change now needs at least 10 responses anyway.
  • ! is no longer suppressed by E. Both can show on a hop where a recorded genuine change later made the split look balanced.
  • The auto host-column width now reserves room for the widest marker set ( E!~^+, 6 columns, derived from build_hop_indicators). It reserved 5 before, which truncated a hostname by one character once E and ! could appear together.
  • Docs: docs/FEATURES.md (marker table and Route Flap Detection), help legend, --help, and a KNOWN_ISSUES.md "By Design" entry: path changes on an already per-packet balanced hop are not flagged, weighted balancing at or above 70% can still record a change after 5 minority replies in a row, a move back after a genuine change is missed once the combined history falls below 70% (for example 100 rounds on A, 100 on B, then back to A), and an evenly balanced hop can record one change during warm-up.

Tests

  • test_route_flap_per_packet_balancing_never_flaps: 2- and 3-way round-robin plus a deterministic 50/50 random sequence (asserts the hop is PerPacket and has no route changes). Fails on master (9 flaps).
  • test_route_flap_genuine_change_records_one_flap: 200 x A then 20 x B gives exactly one A to B change at response 205; 5 x A then 10 x B also gives one. Fails on master (0 flaps).
  • test_route_flap_brief_blip_does_not_flap: 20 x A, 4 x B, 20 x A gives no change (passes on master too).
  • Removed the three margin-based tests; the new ones cover their scenarios. Updated the indicator tests for E!.
  • widest_indicator_set_fits_host_column: renders a hop with every marker and checks the hostname is followed by E!~^+ untruncated. Fails with the old + 5 reserve (core1.example.n… E!~^+).

Gates: cargo fmt --check, cargo clippy --all-targets -- -D warnings (with and without default features) and cargo test all pass.

Behavior across balancing patterns

A model of the old and new rules over 2000 random 600-round sequences per row (flaps per run, then share of runs with any flap):

Responder split Before After
50/50 4.49 / 89% 0.06 / 6% (almost all in the first 40 responses)
70/30 0.32 / 27% 0.71 / 39%
80/20 0.13 / 12% 0.27 / 13%
90/10 0.03 / 3% 0.02 / 1%
3-way even 5.62 / 96% 0.003 / 0.3%

Weighted splits near 70% are the one case that records more flaps than before. That is documented in KNOWN_ISSUES.md.

Not verified

No live check. The change is confined to hop state, and replay runs the same function. I did not build the fake per-packet router harness because the unit tests reproduce both failures directly. Replaying an old recording now uses the new rules, so its route-change history can differ from what was shown live.

Flap detection compared cumulative response counts with a margin of 2.
On a per-packet balanced hop those counts take turns leading, so route
changes accumulated on hops already marked E; and a genuine change was
only recorded once the new responder outnumbered the old one's whole
history.

A responder now needs 5 consecutive responses to become, or replace, the
hop's stable responder, and no change is recorded while the hop's
responses were split per-packet before the new run began (the E test).
The ! marker is no longer hidden when E is shown, so a recorded change
stays visible.
With E and ! able to appear together, the widest marker string is now
" E!~^+" (6 columns), but the auto host width still reserved 5, so a
hostname at the column limit was truncated by one character. Derive the
reserve from build_hop_indicators with every marker set.
The guard judges per-packet balancing on the hop's whole history, so a
later move back after a genuine change, weighted balancing near 70%, and
warm-up on an evenly balanced hop are not handled. Say so in KNOWN_ISSUES,
soften the --help wording, and tighten the CHANGELOG entry.
@lance0
lance0 marked this pull request as ready for review November 14, 2026 20:31
@lance0
lance0 merged commit db29f2e into master Nov 14, 2026
7 checks passed
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.

1 participant