Skip to content

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

Closed
basvandijk wants to merge 1 commit into
masterfrom
ai/deflake-sr_app_no_upgrade_provision_write_access_test-2026-03-08
Closed

basvandijk wants to merge 1 commit into
masterfrom
ai/deflake-sr_app_no_upgrade_provision_write_access_test-2026-03-08

Conversation

@basvandijk

@basvandijk basvandijk commented Mar 8, 2026 •

Copy link
Copy Markdown
Collaborator

The test sr_app_no_upgrade_provision_write_access_test_colocate often times out:

$ bazel run //ci/githubstats:query -- last --flaky \
    //rs/tests/consensus/subnet_recovery:sr_app_no_upgrade_provision_write_access_test_colocate \
    --columns=last_started_at,errors
...
╒════╤═════════════════════════╤═══════════════════════════════╕
│    │   last started at (UTC) │ errors per attempt            │
╞════╪═════════════════════════╪═══════════════════════════════╡
│  0 │ Sat 2026-03-07 00:44:18 │ 1: test: Timeout after 600s   │
├────┼─────────────────────────┼───────────────────────────────┤
...
├────┼─────────────────────────┼───────────────────────────────┤
│  2 │ Tue 2026-03-03 17:35:28 │ 1: test: Timeout after 600s   │
├────┼─────────────────────────┼───────────────────────────────┤
│  3 │ Mon 2026-03-02 13:42:53 │ 1: test: Timeout after 600s   │
╘════╧═════════════════════════╧═══════════════════════════════╛

It consitently times out during subnet recovery, during the ic-replay step, while waiting for the state hash to be committed:

2026-03-07 00:34:52.503 INFO[test:rs/tests/consensus/subnet_recovery/common.rs:728:0] Starting recovery of subnet lwdph-32ekx-5fdr4-f2gf6-m6ibg-bqzij-4ivmz-qguyh-nsrnj-imv5d-yqe with AppSubnetRecoveryArgs { subnet_id: lwdph-32ekx-5fdr4-f2gf6-m6ibg-bqzij-4ivmz-qguyh-nsrnj-imv5d-yqe, upgrade_version: None, upgrade_image_url: Some(Url { scheme: "http", cannot_be_a_base: false, username: "", password: None, host: Some(Domain("zh1-idx1.artifacts.proxy-global.dfinity.network")), port: Some(8080), path: "/cas/d977d4a6d6497bda164d16feb9e7964c401235d3c7d5d89a26f68f8be61af03d", query: None, fragment: None }), upgrade_image_hash: Some("d977d4a6d6497bda164d16feb9e7964c401235d3c7d5d89a26f68f8be61af03d"), upgrade_image_launch_measurements_path: Some("/home/root/test/tests/test/guest_launch_measurements.json"), replacement_nodes: Some([]), replay_until_height: Some(173), readonly_pub_key: Some("ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDn80z4rIxUfa2tOgiPpR42fZFOxPOBsMxCNNCPAogyK readonly"), readonly_key_file: Some("/home/root/test/tests/test/ssh/authorized_priv_keys/readonly"), write_node_id_and_pub_key: Some((33nar-a3xkm-thmg6-6pmv5-ytkf5-ehr4s-j6kcc-wegzt-s5nrg-tjykf-qae, "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIH9g6pKaoE+A7tXfK2U+assMuyBxfQcVm47lLMIUVMUT recovery")), recovery_key_file: Some("/home/root/test/tests/test/ssh/authorized_priv_keys/recovery"), download_pool_node: Some(2602:fb2b:110:10:5043:89ff:feec:86ba), download_state_method: Some(Remote(2602:fb2b:110:10:5040:eeff:fe97:f958)), keep_downloaded_state: Some(false), upload_method: Some(Remote(2602:fb2b:110:10:5040:eeff:fe97:f958)), wait_for_cup_node: Some(2602:fb2b:110:10:5040:eeff:fe97:f958), chain_key_subnet_id: None, next_step: None, skip: None }
...
2026-03-07 00:35:07.227 INFO[test:rs/recovery/src/cli.rs:198:0] ####################
2026-03-07 00:35:07.227 INFO[test:rs/recovery/src/cli.rs:199:0] V     ICReplay     V
2026-03-07 00:35:07.227 INFO[test:rs/recovery/src/cli.rs:200:0] ####################
...
2026-03-07 00:35:08.620 INFO[test:StdOut] {"log_entry":{"level":"INFO","utc_time":"2026-03-07T00:35:08.620Z","message":"Polling the state manager for height: 168.","crate_":"ic_replay","module":"player","line":1617,"node_id":"","subnet_id":""}}
2026-03-07 00:35:08.620 INFO[test:StdOut] {"log_entry":{"level":"WARN","utc_time":"2026-03-07T00:35:08.620Z","message":"Waiting for state hash: state at height 168 is not committed yet. Retrying in 1 seconds.","crate_":"ic_replay","module":"player","line":1623,"node_id":"","subnet_id":""}}
...
2026-03-07 00:43:48.728 INFO[test:StdOut] {"log_entry":{"level":"WARN","utc_time":"2026-03-07T00:43:48.728Z","message":"Waiting for state hash: state at height 168 is not committed yet. Retrying in 1 seconds.","crate_":"ic_replay","module":"player","line":1623,"node_id":"","subnet_id":""}}
...
2026-03-07 00:43:50.494 DEBG[rs/tests/driver/src/driver/task_scheduler.rs:137:21] Task Timeout("test") failed due to: Timeout after 600s

Claude Opus 4.6 concluded:

Root Cause

The bug is in verify_latest_cup() in rs/replay/src/player.rs. During subnet recovery, replay_consensus_pool() calls verify_latest_cup() before deliver_batches(). When the downloaded checkpoint is from an earlier DKG interval than the CUP in the consensus pool (e.g. checkpoint at height 147, CUP at height 168), verify_latest_cup calls get_state_hash(168) but the state at that height hasn't been produced yet. The state manager returns a transient error ("state at height 168 is not committed yet") and get_state_hash loops until the test's 600s timeout fires.

This happens intermittently because it depends on timing — whether the subnet has progressed past the downloaded checkpoint's DKG interval by the time the consensus pool artifacts are also downloaded.

Fix

Added a condition in verify_latest_cup() to skip the state hash comparison when the CUP height is above the latest state height (mirroring the existing skip for the reverse case). The CUP's cryptographic signature is still verified. The state hash will be verified later during redeliver_certifications() which runs after deliver_batches() and wait_for_state().

This is not a timeout tuning issue — no amount of waiting would help because the state at the CUP height can never be committed without first replaying blocks, and blocks can't be replayed until verify_latest_cup returns. It's a deadlock in the execution flow.


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

…rovision_write_access_test_colocate

Skip state hash comparison in verify_latest_cup() when CUP height is above the
latest state height. This fixes a deadlock where replay_consensus_pool() calls
verify_latest_cup() before deliver_batches(), but the state at the CUP height
cannot be committed until batches are delivered.

When the downloaded checkpoint is from an earlier DKG interval than the CUP in
the consensus pool (e.g. checkpoint at 147, CUP at 168), get_state_hash()
loops forever waiting for the state to be committed, causing the 600s test
timeout. The CUP signature is still verified; the state hash will be checked
later via redeliver_certifications() after batches are delivered.

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.

Pull request overview

Prevents rs/replay’s Player::verify_latest_cup() from deadlocking during subnet recovery replays when the consensus pool’s latest CUP height is ahead of the locally produced state height, which intermittently causes the referenced deflake test to time out.

Changes:

  • Add an early-return guard in verify_latest_cup() when CUP.height() > latest_state_height() to skip the state-hash comparison in that case.
  • Emit an informational log explaining the skip and why it occurs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread rs/replay/src/player.rs
Comment on lines +1166 to +1179
if last_cup.height() > self.state_manager.latest_state_height() {
// The CUP references a height that hasn't been reached yet (e.g. the downloaded
// checkpoint is from an earlier DKG interval than the CUP in the consensus pool).
// We cannot verify the state hash until batches up to the CUP height have been
// delivered. The state hash will be verified later via `redeliver_certifications`.
info!(
self.log,
"The CUP height {} is strictly above the latest state height {}. \
Skipping state hash comparison as the state has not been produced yet.",
last_cup.height(),
self.state_manager.latest_state_height()
);
return Ok(());
}

Copilot AI Mar 8, 2026

Copy link

Choose a reason for hiding this comment

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

This early-return skips not only the state-hash comparison but also the replica-version/upgrade check that occurs later in verify_latest_cup(). In the scenario where the CUP is ahead of the local state, it would still be useful (and in some call paths, important) to run the replica version check based solely on the CUP content before returning.

Copilot uses AI. Check for mistakes.
Comment thread rs/replay/src/player.rs
Comment on lines +1166 to +1177
if last_cup.height() > self.state_manager.latest_state_height() {
// The CUP references a height that hasn't been reached yet (e.g. the downloaded
// checkpoint is from an earlier DKG interval than the CUP in the consensus pool).
// We cannot verify the state hash until batches up to the CUP height have been
// delivered. The state hash will be verified later via `redeliver_certifications`.
info!(
self.log,
"The CUP height {} is strictly above the latest state height {}. \
Skipping state hash comparison as the state has not been produced yet.",
last_cup.height(),
self.state_manager.latest_state_height()
);

Copilot AI Mar 8, 2026

Copy link

Choose a reason for hiding this comment

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

The log/branch compares against self.state_manager.latest_state_height() multiple times. If the latest height can change between calls, the condition and the logged value can disagree; even if not, this repeats work. Consider reading latest_state_height once into a local variable and using it for both the comparison and the log message.

Copilot uses AI. Check for mistakes.
Comment thread rs/replay/src/player.rs
// The CUP references a height that hasn't been reached yet (e.g. the downloaded
// checkpoint is from an earlier DKG interval than the CUP in the consensus pool).
// We cannot verify the state hash until batches up to the CUP height have been
// delivered. The state hash will be verified later via `redeliver_certifications`.

Copilot AI Mar 8, 2026

Copy link

Choose a reason for hiding this comment

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

The inline comment says the state hash will be verified later via redeliver_certifications, but verify_latest_cup() is also used in flows (e.g., backup restore) where redeliver_certifications is not part of the path. Consider rewording to avoid referencing a specific caller, and instead say the state-hash check will occur later once replay has produced the state at the CUP height.

Suggested change
// delivered. The state hash will be verified later via `redeliver_certifications`.
// delivered. The state hash will be verified later once replay has produced the
// state at the CUP height.

Copilot uses AI. Check for mistakes.
@pierugo-dfinity

Copy link
Copy Markdown
Contributor

Like Copilot commented, I don't think all callers of the function would be happy with that change. Also, claiming that the state hash would be verified later in redeliver_certifications is wrong since certifications certify only part of the state, not its entirety.

Even then, if we skipped checking the hash, we would not have the required artifacts to go from the latest state to the latest CUP, since replicas delete artifacts below the CUP height once they reach it. So it just shifts the problem.

@basvandijk
basvandijk deleted the ai/deflake-sr_app_no_upgrade_provision_write_access_test-2026-03-08 branch October 9, 2026 09:52
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