Skip to content

fix: deflake //rs/nns/governance:governance_integration_test - #12259

Merged
basvandijk merged 3 commits into
masterfrom
ai/deflake-governance_integration_test-2026-11-24
Nov 24, 2026
Merged

basvandijk merged 3 commits into
masterfrom
ai/deflake-governance_integration_test-2026-11-24

Conversation

@basvandijk

@basvandijk basvandijk commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

//rs/nns/governance:governance_integration_test flaked in about 7% of its executions on Namespace RBE, and never on the self-hosted runners. All 9 failed attempts last week died the same way. The RBE worker's kernel OOM killer SIGKILLed the test binary, which Bazel prints as FAIL: ... (Killed).

The test's 23 TLA-checked tests run in parallel, and each started up to 10 Apalache JVMs at once (MAX_THREADS per perform_trace_check call). So all 99 JVMs ran together, and the test needed about 33-38 GiB. RBE workers have 64 GiB, no swap and 16 action slots. When the other actions on the worker held another 22-31 GiB, it ran out of memory. Since #12052 moved CI Main's tests to RBE, these flakes show up in CI Main.

Changes

  • run_apalache in rs/tla_instrumentation now holds a permit from a process-wide counting semaphore while its Apalache process runs. The semaphore is a std Mutex and Condvar.
  • So at most MAX_CONCURRENT_APALACHE_PROCESSES (8) Apalache processes run at the same time per process. Further checks wait until one exits.
  • A new tla_instrumentation_test target runs the crate's unit tests under Bazel:
    • new tests of the semaphore;
    • the existing tla_state test, which no target ran before.

Behaviour changes

Peak memory and wall time of governance_integration_test for different limits, measured locally on 32 CPUs:

Concurrent Apalache processes Peak memory Wall time
unlimited (before) 33.4 GiB 120.0 s
16 10.9 GiB 96.5 s
8 (this PR) 8.1 GiB 95.7 s
4 7.6 GiB 166.0 s

The limit applies to every test that checks TLA traces:

  • merge_neurons_test;
  • the rs/nns/integration_tests tests that call perform_trace_check;
  • the rs/tla_instrumentation tests.

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

🤖 Generated with Claude Code

Cap the number of Apalache processes that run at the same time in a process
to 8, with a process-wide semaphore that run_apalache holds while Apalache
runs.

governance_integration_test started all 99 of its Apalache JVMs at once (23
TLA-checked tests in parallel, up to 10 JVMs each) and needed about 33-38 GiB,
so the 64 GiB, swapless Namespace RBE workers it shares with 15 other actions
ran out of memory and OOM-killed it. With the cap it peaks at about 8 GiB.

Co-Authored-By: Claude Opus 5.5 <[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 semaphore OOM fix lacks regression tests for its concurrency bound, waiter wake-up, and permit restoration after unwinding, with coverage also needing Bazel test wiring.

1 open issue
What changed in this PR

This PR reduces memory pressure behind governance integration-test flakes on Namespace remote build workers by limiting concurrent Apalache processes in the shared TLA checker.

Changes:

  • Adds a process-wide semaphore limiting each test binary to eight concurrent Apalache processes.
  • Holds a permit throughout process execution and releases it automatically when the checker returns.
  • Documents the checker’s new capacity-waiting behavior.
File Description
rs/​tla_instrumentation/​tla_instrumentation/​src/​checker.rs Adds the semaphore, guards Apalache execution, and documents the concurrency limit.

Review effort: Balanced

Test the semaphore's permit accounting, that a waiter wakes up when a permit
is released, and that a permit is released when its holder panics. Add the
tla_instrumentation_test target, which runs the crate's unit tests under
Bazel, including the existing tla_state test.

Co-Authored-By: Claude Opus 5.5 <[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 review identifies no active issues in the change limiting concurrent Apalache processes to reduce memory pressure.

1 open issue

Review effort: Balanced

@basvandijk
basvandijk marked this pull request as ready for review November 24, 2026 08:28
@basvandijk
basvandijk requested a review from a team as a code owner November 24, 2026 08:28

@pierugo-dfinity pierugo-dfinity 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.

Thank you!

Wait with Condvar::wait_while, propagate a poisoned lock as a panic, and
document the wait on run_apalache, where the permit is taken.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 24, 2026 13:32

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

No active review issues are reported for the change limiting concurrent Apalache processes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@basvandijk
basvandijk enabled auto-merge November 24, 2026 13:37
@basvandijk
basvandijk added this pull request to the merge queue Nov 24, 2026
Merged via the queue into master with commit c228e1a Nov 24, 2026
44 checks passed
@basvandijk
basvandijk deleted the ai/deflake-governance_integration_test-2026-11-24 branch November 24, 2026 14:52
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