Skip to content

fix: deflake //rs/tests/consensus/subnet_recovery:sr_app_no_upgrade_provision_write_access_test_colocate - #9153

Merged
basvandijk merged 4 commits into
masterfrom
ai/deflake-sr_app_no_upgrade_provision_write_access_test-2026-03-03
Mar 10, 2026
Merged

basvandijk merged 4 commits into
masterfrom
ai/deflake-sr_app_no_upgrade_provision_write_access_test-2026-03-03

Conversation

@basvandijk

@basvandijk basvandijk commented Mar 3, 2026 •

Copy link
Copy Markdown
Collaborator

Deflake the //rs/tests/consensus/subnet_recovery:sr_app_no_upgrade_provision_write_access_test_colocate test by increasing its DKG interval.

…rovision_write_access_test_colocate

Increase the per-test timeout from the default 600s (10 min) to 900s (15 min)
and add an overall timeout of 1200s (20 min) to give the subnet recovery test
more time to complete, fixing intermittent timeout flakes.
@github-actions github-actions Bot added the fix label Mar 3, 2026
@basvandijk
basvandijk marked this pull request as ready for review March 3, 2026 16:07
@basvandijk
basvandijk requested a review from a team as a code owner March 3, 2026 16:07
kpop-dfinity
kpop-dfinity previously approved these changes Mar 3, 2026
@pierugo-dfinity

pierugo-dfinity commented Mar 3, 2026 •

Copy link
Copy Markdown
Contributor

That won't help. All occurrences of the timeout were raised because we downloaded a state with a lower height than the CUP (example). This is explained in cases where the subnet stalls after creating a CUP but before creating the respective checkpoint. This problem is known and there is a draft PR intended to solve it by downloading the checkpoint corresponding to the latest CUP instead of the highest checkpoint in absolute, but it is far from being ready.

Just to lower the probability of the flake, I suggest increasing the DKG interval.

P.S.: There is a different flake (f.ex. here) where the highest checkpoint correctly corresponds to the latest CUP, though the state manager archives it because it is "unverified". I suppose this happens when the subnet stalls after creating the checkpoint but before updating the metadata in system_metadata.pbuf? Increasing the DKG interval will also help reduce the probability of the flake.

@pierugo-dfinity

Copy link
Copy Markdown
Contributor

I suggest increasing the DKG interval

That would increase the time of the test by a bit though

@pierugo-dfinity

Copy link
Copy Markdown
Contributor

the subnet stalls after creating a CUP but before creating the respective checkpoint

Actually, this is not possible, but the other way around is a different source of flakiness 😅 (when the subnet stalls after creating the checkpoint but before creating the CUP).

In the case observed by the original flakes, this can happen if the node where we download the state from is just slightly behind compared to the one where download the consensus pool from, I'd have to check again.

@basvandijk

Copy link
Copy Markdown
Collaborator Author

Thanks @pierugo-dfinity could you also update the PR description?

@kpop-dfinity

Copy link
Copy Markdown
Contributor

Ah, thanks @pierugo-dfinity, I didn't even look at the logs :P

Just to lower the probability of the flake, I suggest increasing the DKG interval.

I agree that increasing the DKG interval should help, but I'm not sure how much lower the probability is going to be if we increase the interval by only 2.5x and if it's enough

In the case observed by the original flakes, this can happen if the node where we download the state from is just slightly behind compared to the one where download the consensus pool from, I'd have to check again.

I bet this was the case (but I didn't look at the logs)

@kpop-dfinity
kpop-dfinity requested review from kpop-dfinity and removed request for kpop-dfinity March 3, 2026 17:16
@kpop-dfinity
kpop-dfinity dismissed their stale review March 3, 2026 17:24

I'll look at the PR again tomorrow

@pierugo-dfinity

Copy link
Copy Markdown
Contributor

P.S.: There is a different flake (f.ex. here) where the highest checkpoint correctly corresponds to the latest CUP, though the state manager archives it because it is "unverified". I suppose this happens when the subnet stalls after creating the checkpoint but before updating the metadata in system_metadata.pbuf? Increasing the DKG interval will also help reduce the probability of the flake.

Looking at it further, this happened because the node was stuck in a state sync loop and its last checkpoint was kept unverified because of the following log

Loading state sync checkpoint at 252 and skipping validation. The checkpoint will remain unverified.

Increasing the DKG interval would also help preventing state sync loops.

I agree that increasing the DKG interval should help, but I'm not sure how much lower the probability is going to be if we increase the interval by only 2.5x and if it's enough

Yeah it's not a perfect solution, but it would be an easy improvement before we can spend time thinking about a more robust solution.

@basvandijk

basvandijk commented Mar 6, 2026 •

Copy link
Copy Markdown
Collaborator Author

Since many tests under //rs/tests/consensus/subnet_recovery:... are flaky I asked Claude Opus 4.6 to figure out if there are some common reasons for the flakes mentioning this PR. Ignore failures containing failed to setup IC under test because they're caused by lack of resources. I instructed Claude to download all flaky logs of these tests in the last week using:

bazel run //ci/githubstats:query -- last --flaky //rs/tests/consensus/subnet_recovery:% --download-ic-logs --download-console-logs

Overview

29 total failures across 15 test variants were analyzed. ~7 were infra/setup failures (excluded per request). The remaining ~22 fall into 3 categories.

1. Test Timeouts — ~15 failures (dominant pattern)

Tests hit the 600s or 1800s timeout limit. Affected tests include sr_app_no_upgrade_*, sr_app_failover_nodes_*, sr_app_same_nodes_*, and sr_app_no_upgrade_with_chain_keys_* variants. The test appears to hang waiting for recovery/nodes that never complete.

Root cause (from PR #9153 discussion): Many of these timeouts, especially in provision_write_access tests, are caused by state being downloaded with a lower height than the CUP. This happens when:

  • The subnet stalls after creating a CUP but before the corresponding checkpoint, or
  • The subnet creates a checkpoint but stalls before the CUP

This causes a state sync loop where nodes keep trying to sync state but end up with unverified checkpoints, never catching up. PR #9153 mitigates this by increasing the DKG interval. Draft PR #8843 targets a proper fix (downloading the checkpoint corresponding to the latest CUP instead of the highest checkpoint).

2. Node Health / Reboot Failures — 2–3 failures

  • "Node's status endpoint didn't report healthy" — IC nodes never come up healthy after 500s+ of polling (timed out after 63–101 attempts). Source: rs/tests/consensus/utils/src/rw_message.rs ~L284.
  • "Replica did reboot, but never came back online!" — After an expected reboot, the replica fails to restart. Source: rs/tests/consensus/utils/src/upgrade.rs ~L117.

These may share the same underlying cause as the timeouts (state sync issues preventing nodes from recovering).

3. Specific Test Logic Failures — ~5 failures

Failure Test Duration Source
"Failed to read new message" sr_app_same_nodes_test (NotCorrupted) 64.6s rs/tests/consensus/utils/src/subnet.rs ~L71
"Writing messages still successful" sr_app_no_upgrade_with_chain_keys_test (CorruptedWithValidNiDkgId) 619s rs/tests/consensus/subnet_recovery/utils.rs ~L182
"Did not find recovery CUP on upload node" sr_app_same_nodes_with_chain_keys_test (WaitForCUP step) 854s rs/tests/consensus/subnet_recovery/utils.rs ~L217
"Could not create message canister: Timeout" sr_nns_failover_nodes_test 40s rs/tests/driver/src/util.rs ~L599

Notable:

  • "Writing messages still successful" — The test expects writes to fail after corruption/recovery begins, but they still succeed. This suggests the recovery process didn't stall the subnet as expected.
  • "Did not find recovery CUP on upload node" — The recovery CUP was never created or not propagated to the upload node, directly related to the CUP/checkpoint mismatch issue discussed in PR fix: deflake //rs/tests/consensus/subnet_recovery:sr_app_no_upgrade_provision_write_access_test_colocate #9153.
  • "Could not create message canister" — An early-stage failure suggesting the NNS subnet is not healthy enough to process canister creation requests.

Recommendations

  1. PR fix: deflake //rs/tests/consensus/subnet_recovery:sr_app_no_upgrade_provision_write_access_test_colocate #9153 (DKG interval increase) — Will help reduce the probability of CUP/checkpoint mismatch flakes, which likely accounts for most timeouts and the "recovery CUP not found" failures.
  2. PR refactor(recovery): [CON-1604] download the latest CUP checkpoint #8843 (proper fix) — Should be prioritized to eliminate the root cause rather than just reducing probability.
  3. Node health timeouts — Could benefit from better diagnostic logging when nodes fail to come up (currently just polls and gives up after N attempts).
  4. "Writing messages still successful" — May need investigation into whether the corruption/halt mechanism is reliable, or if this is also a timing issue.

@basvandijk

Copy link
Copy Markdown
Collaborator Author

@pierugo-dfinity I forgot I still had this open and asked AI again to deflake this test which resulted in #9248. I understand you're already working on a more comprehensive fix.

@basvandijk
basvandijk added this pull request to the merge queue Mar 10, 2026
Merged via the queue into master with commit 537fe45 Mar 10, 2026
40 checks passed
@basvandijk
basvandijk deleted the ai/deflake-sr_app_no_upgrade_provision_write_access_test-2026-03-03 branch March 10, 2026 13:36
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