Skip to content

fix: deflake //rs/tests/consensus/tecdsa:tschnorr_message_sizes_test_head_nns_local - #11848

Merged
basvandijk merged 4 commits into
masterfrom
ai/deflake-tschnorr_message_sizes_test_head_nns-2026-10-14
Oct 14, 2026
Merged

basvandijk merged 4 commits into
masterfrom
ai/deflake-tschnorr_message_sizes_test_head_nns-2026-10-14

Conversation

@basvandijk

@basvandijk basvandijk commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

//rs/tests/consensus/tecdsa:tschnorr_message_sizes_test_head_nns_local flaked on master on 2026-10-13 on RBE (run 18d6da50): attempt 1 (first log line 09:33:03 UTC) failed and attempt 2 (started 09:47:59) passed. In attempt 1 every task passed:

Task setup                            PASSED  in 114.87s
Task test_xnet_limit                  PASSED  in 111.76s
Task test_local_limit                 PASSED  in 113.59s
Task assert_no_metrics_errors         PASSED  in   1.51s
Task assert_no_unallowed_log_patterns PASSED  in   5.13s

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 SIGTERM at 09:39:30, and Bazel's summary in the RBE job log (run 38375493843, Bazel Test All on RBE) reads FLAKY, failed in 1 out of 2 in 900.0s, i.e. attempt 1 ran into the target's long (900 s) timeout.

//rs/tests/message_routing/xnet:xnet_cloud_engine_isolation_test_local failed 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 detected warnings between 09:34:13 and 09:38:46 (36 in the passed attempt). Under that load none of the nine QEMUs left /proc within the 5 s SIGTERM grace period of LocalBackend::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_qemu is 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>/comm starts with qemu-. comm is the basename of the exec'd path, and the backend execs QEMU through the runfiles symlink that rs/tests/run_systest.sh creates, <sha256>-qemu-system-x86_64, so comm is the first 15 characters of the hash (7f5ccae48c39d1b in 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 in delete_group blocks: ip link del of a TAP that a process holds open returns at once (verified).

Fix

Identify the process by its command line instead: the QEMU that start_vm launched 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_group also 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 fmt and ./ci/scripts/rust-lint.sh are clean after every commit; bazel build //rs/tests/driver:ic-system-test-driver and bazel test //rs/tests/driver:unit_tests (46 tests, including the new one) pass on the final code.
  • On the dev VM: a process exec'd through a <sha256>-qemu-system-x86_64 symlink to bash has comm = 7f5ccae48c39d1b while its cmdline holds the full argv; ip link del of a TAP that a process holds open returns at once.
  • End-to-end on the dev VM, run three times (first commit, the -pidfile pair guard, and the concurrent stop): //rs/tests/consensus:max_xnet_payload_size_test_local with 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 (comm is the hash prefix), so neither would have been killed.
  • CI: the PR carries CI_ALL_BAZEL_TARGETS, so every _local system test exercises the teardown.

This PR was created following the steps in .claude/skills/fix-flaky-tests/SKILL.md.

🤖 Generated with Claude Code

…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]>
@basvandijk basvandijk added the CI_ALL_BAZEL_TARGETS Runs all bazel targets label Oct 14, 2026
@github-actions github-actions Bot added the fix label Oct 14, 2026
@basvandijk
basvandijk requested a balanced review from Copilot October 14, 2026 08:30

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.

🟡 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>/comm check.
  • 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]>

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.

🟡 Changes recommended

The unit test leaves three orphaned sleep processes after completion.

1 open finding
1 resolved since last review

🧠 Review effort: Balanced

…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]>

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 fix addresses the documented teardown failure and includes appropriate regression coverage.

0 open findings

1 resolved since last review

🧠 Review effort: Balanced

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]>

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 implementation addresses the diagnosed teardown failure with focused safeguards and appropriate test coverage.

0 open findings

🧠 Review effort: Balanced

@basvandijk
basvandijk marked this pull request as ready for review October 14, 2026 09:34
@basvandijk
basvandijk requested a review from a team as a code owner October 14, 2026 09:34
@basvandijk
basvandijk added this pull request to the merge queue Oct 14, 2026
Merged via the queue into master with commit 5e797c7 Oct 14, 2026
43 checks passed
@basvandijk
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants