Repository navigation
fix: deflake //rs/tests/consensus/tecdsa:tschnorr_message_sizes_test_head_nns_local - #11848
Merged
basvandijk merged 4 commits intoOct 14, 2026
Conversation
…head_nns_local The test flaked on master on 2026-10-13 on RBE (run 18d6da50): in attempt 1 every task passed and the driver started tearing the group down, yet the attempt failed. Its log ends with the ninth `Stopping QEMU (pid ...) via SIGTERM` at 09:39:30, and attempt 2 began 896 s after attempt 1's first log line, i.e. when the target's `long` (900 s) timeout killed attempt 1. `//rs/tests/message_routing/xnet:xnet_cloud_engine_isolation_test_local` failed identically in the same run. Root cause: the worker was stalled for the whole run (105 `starvation detected` warnings across all nine VMs, every task 1.5-1.8x slower than in the passed attempt) and none of the nine QEMUs exited within the 5 s SIGTERM grace period of `LocalBackend::stop_qemu`: the SIGTERMs are 5.01 s apart (0.1 s in the passed attempt). The escalation to SIGKILL for that case never ran. Its PID-reuse guard checks that `/proc/<pid>/comm` starts with `qemu-`, but `comm` is the basename of the exec'd path, and QEMU is exec'd through the runfiles symlink `<sha256>-qemu-system-x86_64` that `run_systest.sh` creates, so `comm` is the first 15 characters of the hash (`7f5ccae48c39d1b` in this run). The guard therefore always fails closed and the VMs are left running, and the action does not complete until Bazel's timeout. Fix: identify the process by its command line instead. The QEMU `start_vm` launched for a VM has that VM's pid-file as its `-pidfile` argument, which also makes the guard specific to this VM rather than to any QEMU. A unit test covers the helper. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The PID guard matches the path anywhere in argv, allowing an unrelated reused process to receive SIGKILL.
1 open finding
What changed in this PR
Updates local QEMU teardown to identify stalled VMs via their pid-file command-line argument.
Changes:
- Replaces the ineffective
/proc/<pid>/commcheck. - Adds command-line matching and unit coverage.
| File | Description |
|---|---|
rs/tests/driver/src/driver/local_backend.rs |
Revises QEMU PID validation and adds a test. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…VM's QEMU Matching the pid-file path anywhere in argv would also match an unrelated process that reused the PID and merely names the file (Copilot review finding). Match the `-pidfile <path>` pair that `start_vm` passes instead, and make the unit test spawn that argument sequence. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…lls child-free Review findings: a skipped escalation left no trace in the test log, which is how the dead `comm` check went unnoticed, so log it. The unit test's `sleep 60` grandchildren outlived the test with its stdio, and a failing assertion skipped the kill loop; the shells now block in the `read` builtin on a pipe the test holds, and the assertion runs after the kill loop. Co-Authored-By: Claude Fable 5.1 <[email protected]>
A stop can take the whole 5 s SIGTERM grace period before the SIGKILL, so stopping the VMs one after the other made the teardown of a stalled nine-VM group take 45 s. Fan the stops out over scoped threads so it takes about one grace period regardless of the number of VMs. Co-Authored-By: Claude Fable 5.1 <[email protected]>
rzakrzyk
approved these changes
Oct 14, 2026
basvandijk
deleted the
ai/deflake-tschnorr_message_sizes_test_head_nns-2026-10-14
branch
October 14, 2026 11:59
AleDema
pushed a commit
to AleDema/ic
that referenced
this pull request
Oct 18, 2026
## Root cause `driver::local_backend::tests::qemu_cmdline_names_pidfile_requires_the_pidfile_argument_pair` (added in dfinity#11848) spawns three `sh -c 'read _' sh <args>` children and then checks each child's `/proc/<pid>/cmdline`. Every failure is the same: ``` assertion `left == right` failed left: [false, false, false] right: [true, false, false] ``` Since the test landed on 2026-10-14 it failed in 3 of ~180 runs. Two were flaky runs on master (self-hosted runners). The third was an RBE @ Namespace invocation on dfinity#11872 where all 3 attempts failed: it ran 599 of 698 tests on a cold cache, with 200-330 actions running during the attempts. Its re-run, with at most 52 actions running, passed. `Command::spawn` can return before the child's `/proc/<pid>/cmdline` shows its new argv: 1. Rust's std spawns this `Command` with glibc's `posix_spawnp`, which uses `clone3(CLONE_VM | CLONE_VFORK)`. So the parent resumes as soon as the child's `execve` wakes it. 2. The kernel wakes it (`exec_mmap()` → `exec_mm_release()` → `complete_vfork_done()`) *before* it switches the child to its new mm. If the child is preempted right there, `/proc/<pid>/cmdline` reads the still-shared address space, i.e. the test's own argv. 3. After the switch, `get_mm_cmdline()` returns nothing until `create_elf_tables()` has recorded where the new argv is. The test reads child 1's cmdline only after spawning the other two, which normally gives child 1 time to finish its exec. Under CPU contention child 1 can still be in one of these windows, and then it doesn't match. ## Reproduction On an idle devenv (Linux 6.8, glibc 2.39), reading `/proc/<pid>/cmdline` right after `spawn()` returned nothing in 1966 of 2000 spawns. Copies of the real test binary, run concurrently and pinned to a few CPUs, fail with exactly the CI assertion: | contention | before | after | |---|---|---| | only this test, 8 copies on 2 CPUs | 54 / 12000 | 0 / 12000 | | only this test, 16 copies on 4 CPUs | 57 / 12000 | 0 / 12000 | | all 49 tests, 16 copies on 4 CPUs | 7 / 640 | 0 / 640 | A standalone copy of the test that dumps the cmdline on failure showed the parent's argv and `comm` every time (step 2). ## Fix Each child now runs `echo; read _` with stdout piped, and the test waits for that newline before it reads the child's cmdline. `sh` can only print once its exec has completed, so its argv is in place by then. `echo` is a builtin like `read`, so the shell still doesn't fork. If `sh` exits before it prints, `read_exact` fails at that point instead of producing the flake's assertion. The production caller, `stop_qemu`, is not affected. It checks the cmdline of the QEMU that wrote the pid-file, at least 5 s after sending it SIGTERM. This PR was created following the steps in `.claude/skills/fix-flaky-tests/SKILL.md`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 <[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.

Problem
//rs/tests/consensus/tecdsa:tschnorr_message_sizes_test_head_nns_localflaked on master on 2026-10-13 on RBE (run18d6da50): attempt 1 (first log line 09:33:03 UTC) failed and attempt 2 (started 09:47:59) passed. In attempt 1 every task passed:and the driver went on to tear the group down at 09:38:50, yet the attempt failed: its log ends with the ninth
Stopping QEMU (pid ...) via SIGTERMat 09:39:30, and Bazel's summary in the RBE job log (run 38375493843,Bazel Test All on RBE) readsFLAKY, failed in 1 out of 2 in 900.0s, i.e. attempt 1 ran into the target'slong(900 s) timeout.//rs/tests/message_routing/xnet:xnet_cloud_engine_isolation_test_localfailed identically in the same run (all tasks passed, five SIGTERMs from 09:36:15 to 09:36:35, log ends there,FLAKY, failed in 1 out of 2 in 900.1s).Root cause
The worker was slow for the whole run: every task took 1.5-1.8x as long as in the passed attempt (setup 115 s vs 63 s, the tests 112 s and 114 s vs 67 s and 78 s), and the nine replica nodes logged 105
starvation detectedwarnings between 09:34:13 and 09:38:46 (36 in the passed attempt). Under that load none of the nine QEMUs left/procwithin the 5 s SIGTERM grace period ofLocalBackend::stop_qemu(rs/tests/driver/src/driver/local_backend.rs): the SIGTERMs are 5.01 s apart, while in the passed attempt, on the same worker, they are 0.1 s apart. (The log cannot distinguish a QEMU still running from one exited but not yet reaped; the latter is improbable given that the same worker reaped them within 0.1 s minutes later.)stop_qemuis meant to escalate to SIGKILL in that case, but the escalation never runs. Before killing, it guards against PID reuse by checking that/proc/<pid>/commstarts withqemu-.commis the basename of the exec'd path, and the backend execs QEMU through the runfiles symlink thatrs/tests/run_systest.shcreates,<sha256>-qemu-system-x86_64, socommis the first 15 characters of the hash (7f5ccae48c39d1bin this run; verified on the dev VM by exec'ing bash through such a symlink). The guard therefore always fails closed, silently, which "defers to the teardown of the test action's execution environment", and the VMs are left running; the hash-prefixed links predate the QEMU backend (#8449 vs #10642), so the escalation has never fired. What held the action for the remaining ~8.5 min is not in the log; the lingering VMs are the only difference from the passed attempt. Nothing else indelete_groupblocks:ip link delof a TAP that a process holds open returns at once (verified).Fix
Identify the process by its command line instead: the QEMU that
start_vmlaunched for a VM has the argument pair-pidfile <that VM's pid-file>, which also makes the PID-reuse guard specific to this VM rather than to any QEMU. With it, a VM that overruns the grace period is SIGKILLed as intended and teardown completes; a process that overruns it but is not that QEMU is now logged instead of silently skipped. A unit test covers the helper.delete_groupalso stops the group's VMs concurrently (scoped threads) instead of one after the other: a stop can take the whole 5 s grace period, so a stalled nine-VM group took 45 s to stop and now takes about 5 s.Not covered: the stall itself; whether the 5 s grace period should be longer; and what exactly the RBE executor does with a VM left running, which the dev VM cannot reproduce because Bazel's linux-sandbox PID namespace reaps it when the test process exits.
Verification
cargo check --all-targets --all-features -p ic-system-test-driver,cargo fmtand./ci/scripts/rust-lint.share clean after every commit;bazel build //rs/tests/driver:ic-system-test-driverandbazel test //rs/tests/driver:unit_tests(46 tests, including the new one) pass on the final code.<sha256>-qemu-system-x86_64symlink to bash hascomm=7f5ccae48c39d1bwhile itscmdlineholds the full argv;ip link delof a TAP that a process holds open returns at once.-pidfilepair guard, and the concurrent stop)://rs/tests/consensus:max_xnet_payload_size_test_localwith both QEMUs SIGSTOPped 5 s before teardown, so that they cannot act on SIGTERM (as the stalled VMs on CI did not). Every time both VMs overran the grace period and were killed (QEMU (pid 373) survived the SIGTERM grace period; sending SIGKILL, likewise the other VM), teardown completed, no QEMU process was left behind and the test passed (88.6 s, 78.2 s, 67.2 s). With the concurrent stop both SIGTERMs were logged in the same millisecond (09:29:15.722) and both SIGKILLs 5.01 s later (09:29:20.734), where the sequential version took 10 s for the two VMs. The old guard would not have matched either process (commis the hash prefix), so neither would have been killed.CI_ALL_BAZEL_TARGETS, so every_localsystem test exercises the teardown.This PR was created following the steps in
.claude/skills/fix-flaky-tests/SKILL.md.🤖 Generated with Claude Code