Skip to content

fix: deflake //rs/tests/consensus/subnet_recovery:sr_nns_failover_nodes_test_local - #11795

Merged
basvandijk merged 1 commit into
masterfrom
ai/deflake-sr_nns_failover_nodes_test_local-2026-10-08
Oct 8, 2026
Merged

basvandijk merged 1 commit into
masterfrom
ai/deflake-sr_nns_failover_nodes_test_local-2026-10-08

Conversation

@basvandijk

Copy link
Copy Markdown
Collaborator

Problem

//rs/tests/consensus/subnet_recovery:sr_nns_failover_nodes_test_local flaked twice in the week up to 2026-10-08 (2 of 78 runs, both on master). Both times it failed the same way in the ProposeCUP step: all three of ic-admin's connection attempts to the parent NNS node's :8080 timed out (Failed to connect to [...]:8080: Elapsed(()), then None of the provided NNS urls are reachable). In the passing retries the step took 2-4 s.

Root cause

The Local backend creates each group's bridge with ip link add name {bridge} type bridge, without specifying a MAC address. It creates each VM's TAP with ip tuntap add, which gives the TAP a random MAC. A Linux bridge whose MAC was not set explicitly takes the lowest MAC among its ports, and recomputes it whenever a port is added or removed (br_stp_recalculate_bridge_id). The bridge's MAC is the MAC of the gateway <prefix>1, through which GuestOS reaches the driver's addresses.

Right before ProposeCUP, the test starts the httpbin universal VM that serves the registry tarball. Its TAP is the 10th on the bridge, so in about 1 of 10 runs it has the lowest MAC and the gateway's MAC changes under the running guests:

  • Their neighbour-cache entries for the gateway keep the old MAC, which still belongs to another TAP.
  • So the bridge passes their frames up as PACKET_OTHERHOST, and IPv6 input drops them. The one exception is the guest behind the TAP that owns the old MAC, whose frames still match.
  • A guest only recovers once its own entry for the gateway expires and is re-resolved. The entry stays REACHABLE for a random 15-45 s, then goes STALE. The next packets go through 5 s of DELAY and 3 unicast probes before a multicast solicitation finds the new MAC. The host's neighbour solicitations come from the bridge's link-local address, so they don't refresh the entry for <prefix>1.
  • New connections therefore get through again about 23-53 s after the flip. Long-lived TCP streams resume only at their next retransmission, after about 53 s or about 107 s.

ic-admin gives up 40 s after its first connection attempt. So the test fails when the parent NNS node is cut off and its random reachable time is long.

Both failed attempts show this fingerprint. The driver streams the journald of the restored IC's 5 nodes. In each failure, within about 0.3 s of the httpbin TAP being attached, 4 of those 5 streams stopped. Five of these eight streams resumed together, 52.6-52.9 s after the attach. The other three were still silent when the test ended, including the second failure's parent NNS node. Meanwhile the serial consoles, the driver and VM-to-VM traffic carried on. The backlog that the first failure's parent NNS node delivered once its stream resumed shows its replica finalizing blocks throughout the gap. The passing retries show no stall.

The MAC flip is as old as the Local backend; what changed is how long the outage lasts.

  • We have logs for 162 passing attempts of this test and its _head_nns variant from before fix(orchestrator): make NNS Recovery on Failover Nodes retry-safe #11768. In 21 of them (13%), ProposeCUP took 11-40 s instead of 2-4 s.
  • These durations mostly match ic-admin connecting on a later try: it tries at 0, 15 and 30 s, for up to 10 s each. Seven attempts got through only on the third and last try, and two of those (39 s and 40 s) only seconds before it would have given up.
  • In those 21 attempts, the parent NNS node's last traffic with the driver before the flip was the DownloadParentNNSStore rsync. It had ended 15-37 s earlier, so the parent's gateway entry had less REACHABLE time left when the MAC changed.

#11768 dropped the name of the restored IC, so the driver now streams its nodes' journald. That stream keeps the parent's gateway entry fresh until the very moment of the flip. Of the 40 attempts that ran with this change, 4 show the fingerprint of a MAC flip. In 3 of those the parent NNS node was cut off, and 2 of the 3 failed. #11778, merged 8 minutes before #11768, also added guest traffic to <prefix>1 by serving NTS there, and CI can't tell the two changes apart.

Fix

Give the bridge a fixed, deterministic MAC at creation (ip link add name {bridge} address {mac} type bridge). This sets addr_assign_type to NET_ADDR_SET, after which the kernel never recomputes the MAC.

The MAC is 6a:ff: followed by the first 4 bytes of the digest that also names the bridge. It can't equal a VM's MAC. VM MACs have a NodeType index as their second byte, both in the backend (vm_mac: 6a:01:…) and in IC-OS (calculate_deterministic_mac: 6a:<index>:… or 7a:<index>:…), and 0xff is not a NodeType index.

This also covers VM restarts and reboots: start_vm deletes and recreates the VM's TAP, so a restart could move the gateway MAC too.

Verification

  • Kernel source and namespace reproductions. I checked the kernel source (v6.8 and master) and reproduced the bug in unprivileged network namespaces on the devenv's kernel 6.8.
    • The largest reproduction used a bridge set up like create_group, with 9 veth "guests" streaming TCP to an off-link address on lo.
    • In 4 of 4 runs, attaching a TAP with the lowest MAC cut 8 of the 9 guests off from the host, for about 53 s or about 107 s. VM-to-VM traffic was unaffected.
    • With a fixed bridge MAC, the MAC never changed and no guest lost connectivity.
  • A/B runs of the real test on the devenv. These used throwaway instrumentation, not part of this PR. It gives the httpbin TAP a MAC lower than any random TAP MAC (02:00:00:00:00:01) and logs the bridge's MAC around every TAP attach.
    • Without the fix, attaching httpbin's TAP moved the bridge MAC in 2 of 2 runs (e.g. 0e:3d:07:9f:24:f2 → 02:00:00:00:00:01). In both runs the journald streams of 4 of the 5 streamed VMs stopped for 53-55 s. The one survivor was each time the VM whose TAP held the old bridge MAC.
      • In the first run, the parent NNS node was among the stalled VMs, and ProposeCUP took 32 s because 2 of ic-admin's 3 tries failed.
      • In the second run, the parent NNS node was the survivor, and ProposeCUP took 3.6 s.
    • With the fix, the bridge kept its 6a:ff:… MAC through every TAP attach, including httpbin's 02:00:00:00:00:01, in 2 of 2 runs. No journald stream stalled (largest gap 5.5 s), and ProposeCUP took 3.6 s and 2.1 s.
    • The runs were sequential. On the 64-core devenv, 3 concurrent runs of this test (27 VMs with 6 vCPUs each) slowed the VMs so much that the NNS canister installation timed out (300 s) in setup.
  • This PR as is. bazel test --runs_per_test=3 --local_test_jobs=1 //rs/tests/consensus/subnet_recovery:sr_nns_failover_nodes_test_local passed 3 of 3, with ProposeCUP taking 2.1-4.8 s.
  • //rs/tests/driver:unit_tests and //rs/tests/idx:test_e2e_scenarios pass, and ci/scripts/rust-lint.sh is clean.

This PR was created following the steps in .claude/skills/fix-flaky-tests/SKILL.md.

🤖 Generated with Claude Code

@basvandijk basvandijk added the CI_ALL_BAZEL_TARGETS Runs all bazel targets label Oct 8, 2026
@basvandijk
basvandijk requested a balanced review from Copilot October 8, 2026 14:37
@github-actions github-actions Bot added the fix label Oct 8, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused change correctly prevents bridge MAC recalculation and aligns with the documented root cause and verification.

0 open findings

What changed in this PR

Stabilizes local system tests by preventing Linux bridge MAC changes when TAP devices are attached or removed.

Changes:

  • Derives a deterministic, non-VM bridge MAC from the group name.
  • Assigns that MAC explicitly during bridge creation.
File Description
rs/​tests/​driver/​src/​driver/​local_backend.rs Adds and applies the deterministic bridge MAC.

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

@basvandijk
basvandijk marked this pull request as ready for review October 8, 2026 14:47
@basvandijk
basvandijk requested a review from a team as a code owner October 8, 2026 14:47
@github-actions github-actions Bot added the @infra label Oct 8, 2026
@basvandijk
basvandijk enabled auto-merge October 8, 2026 14:59
@basvandijk
basvandijk added this pull request to the merge queue Oct 8, 2026
Merged via the queue into master with commit 3d2e891 Oct 8, 2026
44 checks passed
@basvandijk
basvandijk deleted the ai/deflake-sr_nns_failover_nodes_test_local-2026-10-08 branch October 8, 2026 15:36
AleDema pushed a commit to AleDema/ic that referenced this pull request Oct 18, 2026
…nable_chain_keys_test_farm_colocate (dfinity#11818)

## Problem


`//rs/tests/consensus/subnet_recovery:sr_app_no_upgrade_enable_chain_keys_test_farm_colocate`
flaked once in the week up to 2026-10-11 ([2026-10-05 16:19
UTC](https://dash.dm1-idx1.dfinity.network/invocation/b6dca5c2-ade4-4df4-94c4-d5d47bda5ff1?target=//rs/tests/consensus/subnet_recovery:sr_app_no_upgrade_enable_chain_keys_test_farm_colocate),
on PR dfinity#11744's branch). The recovery tool failed in
`ValidateReplayOutput`:

```
Execution of step ValidateReplayOutput failed: Output error: Invalid output: Replay height smaller than certification height.
```

`ic-replay` had replayed 45 batches up to height 245 (the certification
height), delivered the extra checkpointing batch 246 and logged `Created
unverified checkpoint @246`, `Computed root hash ... of state @246` and
`Validated checkpoint @246`. Yet its `ReplayOutput` reported the latest
CUP's state, `StateParams { height: 200, hash: f3f4ff1b... }`, so the
validation compared 200 - 1 against 245. In the passing attempts `Height
after replay` is the certification height + 1, as intended since dfinity#11203.

## Root cause

`Player::get_latest_state_params` read the hash of the latest state once
and treated *any* `Err` from `get_state_hash_at` as "the latest state
exists in memory only", falling back to the latest CUP. That read can
fail transiently for a checkpoint that already exists on disk:

- For a checkpoint round, `commit_and_certify` enqueues
`ComputeManifest` and `ValidateReplicatedStateAndFinalize` on the tip
channel, then has the hash thread insert `states_metadata[height]`
(without a manifest yet) and publish the new `latest_state_height`,
waits for it, and only then enqueues the follow-up `WaitForManifest`
request that publishes the manifest (and `ResetTipAndMerge`).
- `ic-replay`'s `wait_for_state` polls `latest_state_height` every 500
ms and then calls `flush_tip_channel`. If it observes the new height
before `WaitForManifest` is enqueued, its `Wait` request lands between
`ValidateReplicatedStateAndFinalize` and `WaitForManifest`: the flush
returns as soon as the checkpoint is validated, while the root hash is
still unpublished, and `get_state_hash_at` returns
`Transient(HashNotComputedYet)`.

The failing log shows this interleaving. Checkpoint 246 was created and
its certification hash computed at 16:19:36.635; `ic-replay` saw height
246 at .664 (one poll later) and its flush returned at .797, right after
`Validated checkpoint @246`; two further `wait_for_state` calls at .797
and .798 returned immediately, so `WaitForManifest` was still not
enqueued; `ReplayOutput { height: 200 }` was printed at .975, and
`ResetTipAndMerge` (enqueued together with `WaitForManifest`) ran at
.969, during the state manager's drop. Why `commit_and_certify` needed
more than 160 ms between publishing the height and enqueueing the
follow-ups is inferred, not shown: the hash thread persists the states
metadata with an fsync before it answers, and this run's checkpoint
creation took 470 ms against 10 ms in the passing attempt.

The window exists since async hashing moved the height publication onto
the hash thread (dfinity#8464, reverted in dfinity#10001, re-landed as dfinity#10071 on
2026-05-08); the single read in `ic-replay` dates from 2022.

This is not only a flake: the recovery tool went on to delete every
checkpoint but the highest (246) while the state params it would put
into the recovery CUP were those of height 200. `ValidateReplayOutput`
caught it here, but the corrupted-CUP recoveries skip that step.

## Fix

Read the hash with the existing `get_state_hash` helper, which retries
transient errors every second and returns `None` only for
`StateNotFullyCertified`, i.e. a state that really exists in memory
only; the fallback to the CUP (or, without a consensus pool, to the
highest checkpoint, now read the same way) is unchanged for that case.
The helper answers height 0, which is never a checkpoint, with `None`
without polling (an empty state directory would otherwise make the state
manager report it as not committed yet forever), so
`update-registry-local-store` on an empty state fails as before instead
of waiting. Unit tests pin both `None` cases down.

Behaviour changes to be aware of: a `StateRemoved` error for the latest
state, which cannot happen, now panics instead of silently reporting the
CUP; and like `verify_latest_cup`, which already used the helper, the
poll is unbounded, so a manifest that is never published would make
`ic-replay` log "Waiting for state hash" every second rather than report
a wrong height.

Follow-up for the state manager (not in this PR): `flush_tip_channel` is
documented to finish "all asynchronous checkpointing operations,
including ... manifest computation", but a caller on another thread can
flush before `commit_and_certify` has enqueued `WaitForManifest`.
`ic-replay` was the only such caller; the other callers flush from the
committing thread.

Not related to dfinity#11795: that change only touches the Local backend's
bridge, and this run was colocated on Farm.

## Testing

- `cargo check --all-targets --all-features -p ic-replay`, `cargo fmt`,
`./ci/scripts/rust-lint.sh`.
- `bazel build //rs/replay:replay`; `bazel test
//rs/recovery:recovery_test //rs/replay:player_integration_tests
//rs/replay:replay_doc_test //rs/replay:replay_test` (rerun after each
review follow-up).
- `bazel test --runs_per_test=3 --jobs=3
//rs/tests/consensus/subnet_recovery:sr_app_no_upgrade_enable_chain_keys_test_farm_colocate`:
3/3 passed on Farm (372 s, 390 s, 380 s), each with `Height after
replay` = certification height + 1. Passing runs cannot exercise the
window, which needs the checkpoint's I/O to be slow; the evidence for
the fix is the log analysis above and the unit tests.

This PR was created following the steps in
`.claude/skills/fix-flaky-tests/SKILL.md`.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Fable 5.1 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants