Skip to content

fix: deflake //rs/tests/consensus/subnet_recovery:sr_app_no_upgrade_enable_chain_keys_test_farm_colocate - #11818

Merged
basvandijk merged 3 commits into
masterfrom
ai/deflake-sr_app_no_upgrade_enable_chain_keys_test_farm_colocate-2026-10-11
Oct 12, 2026
Merged

basvandijk merged 3 commits into
masterfrom
ai/deflake-sr_app_no_upgrade_enable_chain_keys_test_farm_colocate-2026-10-11

Conversation

@basvandijk

@basvandijk basvandijk commented Oct 11, 2026 •

Copy link
Copy Markdown
Collaborator

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, on PR #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 #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 (#8464, reverted in #10001, re-landed as #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 #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

…nable_chain_keys_test_farm_colocate

ic-replay read the hash of the latest state once and treated any error as
"the state exists in memory only", falling back to the latest CUP. Since
the state manager publishes a checkpoint's manifest from a WaitForManifest
request that commit_and_certify enqueues only after the new height is
visible, wait_for_state's flush can return before the root hash is
published and the fallback reports the CUP's height instead of the
checkpoint just created. Poll for the hash instead; only a permanent error
means the state is in memory only.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@github-actions github-actions Bot added the fix label Oct 11, 2026
@basvandijk
basvandijk requested a balanced review from Copilot October 11, 2026 14:08
@basvandijk basvandijk added the CI_ALL_BAZEL_TARGETS Runs all bazel targets label Oct 11, 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 addresses the identified race while preserving existing fallback behavior.

0 open findings

What changed in this PR

Fixes replay flakiness by waiting for asynchronously computed checkpoint hashes instead of prematurely falling back to CUP state.

Changes:

  • Reuses hash polling for latest state parameters.
  • Adds coverage for non-fully-certified states.
File Description
rs/​replay/​src/​player.rs Polls transient hash errors and tests the fallback case.

🧠 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 11, 2026 14:33
@basvandijk
basvandijk requested a review from a team as a code owner October 11, 2026 14:33
…ht 0

Review follow-ups: the no-consensus-pool branch read the highest
checkpoint's hash once and would panic on the same transient error;
height 0 is never a checkpoint, so polling there would never end.

Co-Authored-By: Claude Fable 5.1 <[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 change correctly handles transient hash publication and preserves existing fallback behavior.

0 open findings

🧠 Review effort: Balanced

@pierugo-dfinity pierugo-dfinity 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.

Makes sense thanks!

Comment thread rs/replay/src/player.rs Resolved
Review follow-up: the helper now returns None for height 0 itself, so
no caller can poll a height the state manager never reports, and the
call site no longer needs a guard or a comment about the poll.

Co-Authored-By: Claude Fable 5.1 <[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 change correctly addresses the identified race and covers the relevant edge cases.

0 open findings

🧠 Review effort: Balanced

@basvandijk
basvandijk added this pull request to the merge queue Oct 12, 2026
Merged via the queue into master with commit 649156c Oct 12, 2026
44 checks passed
@basvandijk
basvandijk deleted the ai/deflake-sr_app_no_upgrade_enable_chain_keys_test_farm_colocate-2026-10-11 branch October 12, 2026 15:51
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