Repository navigation
fix: deflake //rs/tests/consensus/subnet_recovery:sr_nns_failover_nodes_test_local - #11795
Merged
basvandijk merged 1 commit intoOct 8, 2026
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Contributor
There was a problem hiding this comment.
🟢 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.
dfinityianblenke
approved these changes
Oct 8, 2026
basvandijk
enabled auto-merge
October 8, 2026 14:59
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
//rs/tests/consensus/subnet_recovery:sr_nns_failover_nodes_test_localflaked twice in the week up to 2026-10-08 (2 of 78 runs, both on master). Both times it failed the same way in theProposeCUPstep: all three ofic-admin's connection attempts to the parent NNS node's:8080timed out (Failed to connect to [...]:8080: Elapsed(()), thenNone 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 withip 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 thehttpbinuniversal 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: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.<prefix>1.ic-admingives 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.
_head_nnsvariant from before fix(orchestrator): make NNS Recovery on Failover Nodes retry-safe #11768. In 21 of them (13%),ProposeCUPtook 11-40 s instead of 2-4 s.ic-adminconnecting 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.DownloadParentNNSStorersync. 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>1by 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 setsaddr_assign_typetoNET_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 aNodeTypeindex as their second byte, both in the backend (vm_mac:6a:01:…) and in IC-OS (calculate_deterministic_mac:6a:<index>:…or7a:<index>:…), and 0xff is not aNodeTypeindex.This also covers VM restarts and reboots:
start_vmdeletes and recreates the VM's TAP, so a restart could move the gateway MAC too.Verification
create_group, with 9 veth "guests" streaming TCP to an off-link address onlo.02:00:00:00:00:01) and logs the bridge's MAC around every TAP attach.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.ProposeCUPtook 32 s because 2 ofic-admin's 3 tries failed.ProposeCUPtook 3.6 s.6a:ff:…MAC through every TAP attach, including httpbin's02:00:00:00:00:01, in 2 of 2 runs. No journald stream stalled (largest gap 5.5 s), andProposeCUPtook 3.6 s and 2.1 s.bazel test --runs_per_test=3 --local_test_jobs=1 //rs/tests/consensus/subnet_recovery:sr_nns_failover_nodes_test_localpassed 3 of 3, withProposeCUPtaking 2.1-4.8 s.//rs/tests/driver:unit_testsand//rs/tests/idx:test_e2e_scenariospass, andci/scripts/rust-lint.shis clean.This PR was created following the steps in
.claude/skills/fix-flaky-tests/SKILL.md.🤖 Generated with Claude Code