Repository navigation
test: [DSM-126] Add synchronous commit_and_certify for tests - #10131
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces synchronous, test-only wrappers around StateManagerImpl operations that previously required explicit flush_hash_channel() calls, and updates state manager integration tests to use these wrappers for determinism.
Changes:
- Add
commit_and_certify_sync,commit_and_certify_at_height_sync, andfetch_state_synctoic_state_manager::testing::StateManagerTesting. - Implement these wrappers for
StateManagerImplby delegating to the existing async methods and then flushing the hash channel. - Refactor
rs/state_manager/tests/state_manager.rsto replacecommit_and_certify/commit_and_certify_at_height+flush_hash_channelcall pairs with the new synchronous helpers.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 10 comments.
| File | Description |
|---|---|
| rs/state_manager/tests/state_manager.rs | Replaces explicit hash-channel flushing patterns with new synchronous test helpers. |
| rs/state_manager/src/lib.rs | Adds and implements synchronous test-only helpers that flush the hash channel after committing/fetching. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
schneiderstefan
approved these changes
May 15, 2026
michael-weigelt
enabled auto-merge
May 15, 2026 09:20
pull Bot
pushed a commit
to bit-cook/ic
that referenced
this pull request
Sep 3, 2026
) ## Root cause Since async hashing (dfinity#8464, re-landed in dfinity#10071 on 2026-05-08), `commit_and_certify` with `CertificationScope::Metadata` returns before the `HashThread` has pushed the new state into `states.snapshots`, inserted its `certifications_metadata` entry and bumped `latest_state_height`. Only `Full`-scope commits await the hash thread. Four tests commit a loop whose last height is `Metadata` scope, call `flush_tip_channel()` and then assert `list_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: ``` thread 'can_purge_intermediate_snapshots' panicked at rs/state_manager/tests/state_manager.rs:2347:9: assertion `left == right` failed left: [0, 1, ..., 20, 21] right: [0, 1, ..., 20, 21, 22] ``` Only the last height can ever be missing, because each subsequent `commit_and_certify` needs the previous state hash and blocks on a `HashRequest::Wait` for 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 and `commit_and_certify` inserted the snapshot synchronously. dfinity#10131 introduced `commit_and_certify_sync` and 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 the `HashThread`'s `HashState` arm: 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 is `commit_and_certify` followed by `flush_hash_channel()`. Remove the misleading "wait for hashing" comments (also from `cannot_remove_latest_height_or_checkpoint`, which already used `_sync`). The `flush_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 300s` failure mode, where the filesystem-wide `syncfs` in `finalize_and_remove_unverified_marker` blocks every checkpoint validation in the process while the CI runner's disk drains unrelated dirty pages. ## Verification ``` bazel test --test_output=errors --runs_per_test=3 --jobs=3 //rs/state_manager:state_manager_integration ``` 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 build` and `bazel test --test_output=errors` on the directly affected targets. With a temporary 3 s delay injected into the hash thread for `Metadata`-scope requests, the four tests fail deterministically on `master` and pass with this change. --- This PR was created following the steps in `.claude/skills/fix-flaky-tests/SKILL.md`. Co-authored-by: Claude Fable 5.1 <[email protected]>
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.
Co-authored by Claude