Skip to content

test: [DSM-126] Add synchronous commit_and_certify for tests - #10131

Merged
michael-weigelt merged 5 commits into
masterfrom
mwe/sync_cc2
May 15, 2026
Merged

michael-weigelt merged 5 commits into
masterfrom
mwe/sync_cc2

Conversation

@michael-weigelt

@michael-weigelt michael-weigelt commented May 8, 2026 •

Copy link
Copy Markdown
Contributor

Co-authored by Claude

@github-actions github-actions Bot added the test label May 8, 2026
@michael-weigelt
michael-weigelt marked this pull request as ready for review May 8, 2026 09:01
@michael-weigelt
michael-weigelt requested a review from a team as a code owner May 8, 2026 09:01
Comment thread rs/state_manager/src/lib.rs Resolved
Comment thread rs/state_manager/src/lib.rs Resolved

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

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, and fetch_state_sync to ic_state_manager::testing::StateManagerTesting.
  • Implement these wrappers for StateManagerImpl by delegating to the existing async methods and then flushing the hash channel.
  • Refactor rs/state_manager/tests/state_manager.rs to replace commit_and_certify/commit_and_certify_at_height + flush_hash_channel call 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.

Comment thread rs/state_manager/src/lib.rs Resolved
Comment thread rs/state_manager/src/lib.rs Resolved
Comment thread rs/state_manager/src/lib.rs Resolved
Comment thread rs/state_manager/tests/state_manager.rs Resolved
Comment thread rs/state_manager/tests/state_manager.rs Resolved
Comment thread rs/state_manager/tests/state_manager.rs Resolved
Comment thread rs/state_manager/tests/state_manager.rs Resolved
Comment thread rs/state_manager/tests/state_manager.rs Resolved
Comment thread rs/state_manager/tests/state_manager.rs Resolved
Comment thread rs/state_manager/tests/state_manager.rs Resolved
@michael-weigelt
michael-weigelt enabled auto-merge May 15, 2026 09:20
@michael-weigelt
michael-weigelt added this pull request to the merge queue May 15, 2026
Merged via the queue into master with commit bde9b4e May 15, 2026
35 checks passed
@michael-weigelt
michael-weigelt deleted the mwe/sync_cc2 branch May 15, 2026 09:54
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]>
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