Skip to content

fix: deflake //rs/tests/consensus:cup_explorer_test - #11841

Merged
basvandijk merged 3 commits into
masterfrom
ai/deflake-cup_explorer_test-2026-10-13
Oct 13, 2026
Merged

basvandijk merged 3 commits into
masterfrom
ai/deflake-cup_explorer_test-2026-10-13

Conversation

@basvandijk

Copy link
Copy Markdown
Collaborator

//rs/tests/consensus:cup_explorer_test flaked 4 times in 182 runs since #11786 (2026-10-09), across _farm, _local and _head_nns_farm, and always the same way. The test task fails with assertion left == right failed, left: 5, right: 4 because the RecoverSubnet proposal ends Failed instead of Executed. Its failure reason: the registry canister traps at do_recover_subnet.rs:124, because the system subnet answered the recovery's setup_initial_dkg request with Attempts to run this DKG repeatedly failed.

Root cause

The system subnet rejects the request because it uses up its attempts while it still cannot use the request's registry version:

  1. do_recover_subnet sends SetupInitialDKG with the registry canister's latest version (pre_call_registry_version). The test created that version 3.5-4.2 s earlier with its "Update DKG length" proposal, the one that puts a registry version between halting and recovery.
  2. Blocks only include dealings and transcripts for a remote DKG request once the block's registry version has reached the request's version (build_callback_id_config_map, remote.rs:185). The block maker only uses a version that has been in the replica's registry client for at least POLLING_PERIOD + poll_delay_duration_ms = 10 s (get_stable_registry_version). Before that, the orchestrator's registry replicator has to store the version (it polls every 5 s), and the replica's registry client has to pick it up from the local store (also every 5 s). So the request cannot be served until 10-20 s after the version is created. Each failed replicator poll adds up to ~10 s.
  3. Meanwhile, every DKG summary increments the request's attempt counter, whether or not the request could be served (get_updated_remote_dkg_attempts). The request is rejected at the 5th summary after it arrives (MAX_REMOTE_DKG_ATTEMPTS), i.e. after 4 to 5 DKG intervals.
  4. feat(cup_explorer): extract the threshold master public keys of a CUP #11786 set the system subnet's DKG interval to 14 so that the subnet generates its vetKD key quickly. On this fast single-node subnet a 15-block interval lasts 3.5-4 s, so the request was rejected only 15-17 s after it arrived.
  5. Measured from the creation of the version, that budget is ~20-21 s, minus the ~3 blocks the DKG needs once it can use the version. That is about the worst case of point 2, so the request is rejected whenever both pollers pick the version up late.

That is what happened in the 4 failures:

  • The replicator stored the new version 4.5-5.3 s after its creation, the top of its range.
  • The version became usable at most ~1.2 s too late for the DKG to finish before the 5th summary.
  • In the 4 passing retries, the remote transcripts were created 10.9-15.6 s after the version was stored, as point 2 predicts.
  • Apart from the two errors that carry the rejection itself, no system-node log shows any DKG dealing or transcript error.

Fix

Give the system subnet its own DKG interval of 49 instead of 14. The app subnet keeps 14, so it still halts quickly.

  • Not shorter. The subnet makes at most 5 blocks/s, because a single node notarizes after initial_notary_delay = 200 ms. At that rate, 4 intervals of 50 blocks give the request at least ~40 s. That is about twice the 10-20 s of point 2, with room left for one failed replicator poll.
  • Not much longer. The system subnet's first signed CUP has to exist before test_extract_master_public_keys downloads its first CUP, 40-50 s after genesis. While no CUP verifies, explore() writes nothing, and extract_master_public_keys then panics on the empty file instead of retrying.
    • With 49, that first CUP is at height 50. It exists 12-19 s after genesis and already holds all keys, the vetKD key included.
    • With 99, the first CUP would be at height 100. In the slowest attempts it would come only a few seconds before the download.

History

This test has hit the same failure before:

The new comment above the constant explains why the interval must not be shortened again.

Verification

On a devenv, bazel test --runs_per_test=3 of the 4 non-manual variants passed 12 out of 12 runs: _farm, _head_nns_farm, _local and _head_nns_local.

  • The recovery's remote DKG. In the 6 _local runs, the test log includes the system node's journal. There the remote DKG transcripts were created 8.6-12.6 s after the request, before or during the first DKG interval that counted it. The 5th summary would only have come 65-90 s after the request; the devenv makes fewer blocks per second than CI.
    • One run hit the failures' unlucky phase: the version was stored 0.3 s after the request arrived. It still finished after 12.6 s.
  • The key extraction. In all 12 runs, test_extract_master_public_keys got a CUP holding all keys (height 100) on its first attempt.

Possible follow-ups (not in this PR)

  • Consensus: get_updated_remote_dkg_attempts could stop counting a request while the summary's registry version hasn't reached the request's version, as before feat: CON-1445 Start remote DKG as soon as request appears in state #10055. Requests would then no longer be rejected as "repeatedly failed" without being attempted. This matters little for subnets with long DKG intervals, such as the 499-block default, where 4 intervals last far longer than the ~20 s registry delay.
  • CUP explorer: explore() could report whether it wrote a CUP, and read_and_verify_cup could return errors instead of panicking. test_extract_master_public_keys could then retry while no CUP verifies yet, which would lift the upper bound on the system subnet's DKG interval in this test.

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

🤖 Generated with Claude Code

The RecoverSubnet proposal of the test failed whenever the system subnet
rejected the recovery's `setup_initial_dkg` request with "Attempts to run
this DKG repeatedly failed". Consensus rejects a remote DKG request at
the 5th DKG summary after it arrives, i.e. after 4 to 5 DKG intervals,
and also counts the intervals in which it cannot serve the request yet
because the block's registry version hasn't reached the request's
version. The test creates that registry version right before the
recovery, and it normally takes 10-20s (longer if a registry replicator
poll fails) to become usable. Since #11786 the system subnet's DKG
interval is 14, so on this fast single-node subnet the request is
rejected only ~15-17s after it arrives.

Give the system subnet its own DKG interval of 49. At no more than 5
blocks/s, 4 intervals of 50 blocks leave the request at least ~40s. The
subnet's first signed CUP, at height 50, already holds all keys, its
vetKD key included, and exists long before
`test_extract_master_public_keys` first downloads a CUP, which it must,
as that test panics while no CUP verifies.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@basvandijk basvandijk added the CI_ALL_BAZEL_TARGETS Runs all bazel targets label Oct 13, 2026
Co-Authored-By: Claude Opus 5.5 <[email protected]>

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 timing adjustment addresses the documented failure while preserving the application subnet’s fast halt behavior.

0 open findings

What changed in this PR

Increases the system subnet’s DKG interval to prevent recovery requests from exhausting retries before registry propagation completes.

Changes:

  • Separates application and system subnet DKG intervals.
  • Documents timing constraints behind the 49-block interval.
File Description
rs/​tests/​consensus/​cup_explorer_test.rs Uses a longer system-subnet DKG interval to deflake recovery.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@basvandijk
basvandijk marked this pull request as ready for review October 13, 2026 14:18
@basvandijk
basvandijk requested a review from a team as a code owner October 13, 2026 14:18
Comment thread rs/tests/consensus/cup_explorer_test.rs Resolved
@basvandijk
basvandijk enabled auto-merge October 13, 2026 14:37
@basvandijk
basvandijk added this pull request to the merge queue Oct 13, 2026
Merged via the queue into master with commit 7da17b8 Oct 13, 2026
38 checks passed
@basvandijk
basvandijk deleted the ai/deflake-cup_explorer_test-2026-10-13 branch October 13, 2026 16:01
aodl pushed a commit to aodl/ic that referenced this pull request Nov 16, 2026
…finity#12102)

`//rs/tests/consensus/tecdsa:tecdsa_add_nodes_test_local` flaked on
master on 2026-11-12
([run](https://github.com/dfinity/ic/actions/runs/43221760931/attempts/1),
commit 931cce5). Over the last month, that was the only flake in ~1000
runs across all variants of this test (1 in 224 runs of `_local`). The
`test` task itself passed. The post-test metrics check failed:

```
Task assert_no_metrics_errors FAILED -- The metric `critical_errors{error="master_key_transcript_missing"}` on node kvchs-... exceeded the maximum allowed value: 4 > 0.
```

## Root cause

The test adds 3 unassigned nodes to a 4-node subnet that holds 4 IDKG
keys.

**How the critical error arises**
- The first summary block whose validation context uses the new registry
version starts resharing the IDKG keys from the 4 old nodes to all 7
nodes.
- Each reshare dealing needs `verification_threshold` = 2f+1 = 5 support
shares from the 7 receivers. There are only 4 old nodes, so at least one
*new* node must be caught up and supporting.
- If the reshare isn't done when the next summary block is made, that
block's maker raises `master_key_transcript_missing` once per key
(`create_summary_payload_helper` in
`rs/consensus/idkg/src/payload_builder.rs`) and the reshare carries over
to the next interval.
- With the shared `DKG_INTERVAL` of 19, the reshare gets only 20 blocks,
~8 s on this subnet.

**What delays the new nodes**
- The reshare can start as soon as the new registry version is 10 s old
in the block maker's registry client (the stable registry version age).
- A new node first has to notice its assignment (the orchestrator checks
every 10 s), start its replica, get connected (failed dials are retried
on a 10 s cycle) and follow the chain past the reshare params.

**Timeline of the failed attempt** (old nodes 6dfqk, ln4rn, g54hf,
kvchs; new nodes k2bxb, say7m, ymoxn):

| Time | Event |
|---|---|
| 13:10:17.4 | `AddNodesToSubnet` executed (registry version 5). kvchs's
orchestrator stores v5 at 13:10:18.2 and the new nodes' at 13:10:19.4. |
| 13:10:27.4–27.8 | The new nodes' orchestrators detect the assignment,
~8 s after storing v5. Their replicas start at 13:10:27.7–28.2. |
| 13:10:28.3 | Summary block @180 (made by kvchs) is the first to use
v5: `Noticed subnet membership or mega encryption key change ... will
start key_transcript_creation: height = 180` for all 4 IDKG keys. Block
181 holds the `ReshareOfUnmasked` params (4 old dealers, 7 receivers). |
| 13:10:30.6–31.1 | The old nodes' connections to the new nodes come up
(their first dials at 13:10:20.6 timed out). |
| 13:10:34.6 | The new nodes reach CUP @180. |
| 13:10:36.3 | Summary block @200 (made by kvchs): the reshare hasn't
completed, so kvchs logs `master_key_transcript_missing` 4 times (one
per IDKG key) and its metric reaches 4. |
| 13:10:43.6 | The reshare completes in block 201 (made by the new node
k2bxb). The rest of the test passes. |

In the passing retry, the new replicas started ~10 s before the summary
block that began the reshare, and the reshare completed at height 184,
inside its interval.

## Fix

Give this test its own `DKG_INTERVAL` of 49 instead of the shared 19. 50
blocks last ~19–25 s at the block rates seen in the logs (0.38–0.49
s/block). That covers the new nodes' worst-case join delay, and the
strict `critical_errors` check and the 4+3 scenario stay as they are.

This follows earlier fixes:
- dfinity#9039 raised DKG intervals for this same critical error in 4 other
tests.
- dfinity#9153 and dfinity#11841 also settled on an interval of 49.

**Why 49 and not something else**
- A timing model of the race reproduces the observed flake rate at 19.
At 49 it shows no misses under realistic stress (fastest observed
blocks, delayed registry polls).
- 29 and 39 leave too little margin.
- 59 and 79 add another ~17 s and ~50 s per run for no measurable gain.

**Cost**
- Two steps of the test scale with the interval: initial key creation
(~1.5 intervals) and `await_subnet_earliest_topology_version` (~2.5
intervals).
- That adds roughly 45–60 s per run. Measured below.

**Side effect:** the new nodes are fully caught up before the 7-node
committee takes over, so the ~7 s notarization stall at the start of
that interval also goes away.

## Alternatives considered

- **Tolerate only
`critical_errors{error="master_key_transcript_missing"}` in this test.**
It costs no runtime, but:
- It would accept a critical error in the only system test that reshares
IDKG keys to newly added nodes.
- It needs a change to the shared test driver. The default check is the
prefix `critical_errors`, entries must be prefix-free, and there is no
replica-side `update_*_metrics_to_check`.

Note that the hint printed by the driver,
`remove_metrics_to_check("critical_errors{error=...}")`, is a no-op in
this case. That may be worth a separate follow-up.
- **Add 2 nodes instead of 3.** With 6 receivers (f=1) the 4 old nodes
meet every IDKG threshold by themselves, so the race disappears at no
cost. But the test would then no longer require the new nodes to take
part in IDKG, and f would no longer grow from 1 to 2.

## Verification

- Checks: `cargo check`, `cargo fmt` and `./ci/scripts/rust-lint.sh`
(exit 0) all pass, and `bazel build
//rs/tests/consensus/tecdsa:tecdsa_add_nodes_test_bin` succeeds.
- Ran `bazel test
--runs_per_test=//rs/tests/consensus/tecdsa:tecdsa_add_nodes_test_farm@3
--jobs=4 //rs/tests/consensus/tecdsa:tecdsa_add_nodes_test_farm
//rs/tests/consensus/tecdsa:tecdsa_add_nodes_test_head_nns_farm`.
  - All 4 runs passed every task, including `assert_no_metrics_errors`.
  - The `test` task took 203–212 s; the whole test took 285–292 s.
- Successful `_farm` runs on CI over the past week had a median of
~3:54, so the fix adds ~55 s per run, as estimated.
- These runs used a revision that differed only in the wording of two
comment lines.
- The `_local` variants were not run locally because the environment I
used lacks KVM access. CI runs them on this PR.

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 Opus 5.5 <[email protected]>
Co-authored-by: Leo Eichhorn <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants