Repository navigation
fix: deflake //rs/state_manager:state_manager_integration - #11436
Merged
basvandijk merged 1 commit intoSep 3, 2026
Merged
Conversation
Since async hashing (#10071), `commit_and_certify` with `Metadata` scope returns before the `HashThread` has pushed the new snapshot. Four tests committed a loop ending in a `Metadata`-scope height, called `flush_tip_channel()` (which drains the tip thread, not the hash thread) and then asserted `list_state_heights(CERT_ANY)` on the full height list, so the last height was missing whenever the hash thread was descheduled. Switch the four loops to `commit_and_certify_sync` and drop the outdated "wait for hashing" comments. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The targeted synchronization correctly addresses the documented race without changing production behavior.
Pull request overview
Deflakes state-manager integration tests by ensuring asynchronous hashing completes before assertions and pruning.
Changes:
- Uses
commit_and_certify_syncin four affected test loops. - Removes outdated hashing comments while retaining required tip-thread flushing.
File summaries
| File | Description |
|---|---|
rs/state_manager/tests/state_manager.rs |
Synchronizes hash completion in pruning tests and cleans up stale comments. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 0
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
✅ No security or compliance issues detected. Reviewed everything up to e6f3649. Security OverviewDetected Code Changes
|
michael-weigelt
approved these changes
Sep 3, 2026
basvandijk
enabled auto-merge
September 3, 2026 13:49
basvandijk
deleted the
ai/deflake-state_manager_integration-2026-09-03
branch
September 3, 2026 14:26
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.
Root cause
Since async hashing (#8464, re-landed in #10071 on 2026-05-08),
commit_and_certifywithCertificationScope::Metadatareturns before theHashThreadhas pushed the new state intostates.snapshots, inserted itscertifications_metadataentry and bumpedlatest_state_height. OnlyFull-scope commits await the hash thread.Four tests commit a loop whose last height is
Metadatascope, callflush_tip_channel()and then assertlist_state_heights(CERT_ANY)equals every committed height:can_purge_intermediate_snapshots(failed 3x on CI in the last week)can_keep_the_latest_snapshot_after_removal(1x)remove_inmemory_states_below_can_keep_extra_states(1x)can_remove_checkpoints_and_noncheckpoints_separately(identical shape, not yet observed)flush_tip_channel()drains the tip thread (checkpointing, manifest, validation), not the hash thread, so when the hash thread is descheduled on a loaded CI runner the assertion sees the last height missing:Only the last height can ever be missing, because each subsequent
commit_and_certifyneeds the previous state hash and blocks on aHashRequest::Waitfor it.The comment above the
flush_tip_channel()calls ("We need to wait for hashing to complete...") dates from 2023, when the tip thread did the manifest hashing andcommit_and_certifyinserted the snapshot synchronously. #10131 introducedcommit_and_certify_syncand converted most tests, but left these four loops on the async variant.Reproduced deterministically by inserting a 3 s sleep for
Metadata-scope requests at the top of theHashThread'sHashStatearm: all four tests fail with byte-identical output to CI; with a hash-thread barrier they pass under the same delay.Fix
Switch the four loops to
commit_and_certify_sync, which iscommit_and_certifyfollowed byflush_hash_channel(). Remove the misleading "wait for hashing" comments (also fromcannot_remove_latest_height_or_checkpoint, which already used_sync). Theflush_tip_channel()calls stay: the pruning assertions that follow still depend on checkpointing having finished.Not addressed here (separate root cause, 1 of the last 6 flaky runs): the 19-test
Checkpoint @N didn't complete in 300sfailure mode, where the filesystem-widesyncfsinfinalize_and_remove_unverified_markerblocks every checkpoint validation in the process while the CI runner's disk drains unrelated dirty pages.Verification
All 3 runs pass (172 passed each, 40 to 41 s). Also run:
cargo check --all-targets --all-features -p ic-state-manager,cargo fmt,./ci/scripts/rust-lint.sh(clean),bazel buildandbazel test --test_output=errorson the directly affected targets.With a temporary 3 s delay injected into the hash thread for
Metadata-scope requests, the four tests fail deterministically onmasterand pass with this change.This PR was created following the steps in
.claude/skills/fix-flaky-tests/SKILL.md.