Skip to content

test(vmpool): make the deferred-reap gate test's select deterministic - #845

Merged
webchang merged 1 commit into
rossoctl:mainfrom
webchang:pr/i805-deterministic-select
Nov 17, 2026
Merged

webchang merged 1 commit into
rossoctl:mainfrom
webchang:pr/i805-deterministic-select

Conversation

@webchang

Copy link
Copy Markdown
Member

Closes #805

What changed and why

  • remote-worker/internal/vmpool/deferred_reap_test.go, TestDeferredReapOpensTheGateAtTheBarrierNotAfterTheReap: the select that waits on the second Exec raced two channels that can both be ready. The fake Run sends on entered (buffered) and returns at once, so the second Exec can finish and fill done before the test goroutine reaches the select. With both cases ready Go picks one at random, and picking done failed the test with second Exec returned without entering Run: <nil> even though Run had been entered.
  • Run's send on entered happens before Exec returns, so done with nothing on entered is the only real "returned without entering Run". The done case now checks entered without blocking before failing, and carries the Exec's error over to the final check (which used to read done again).
  • The code under test is unchanged. The flake is the test's: when it fired, the gate had opened and Run had run. The NOT VACUOUS check after the select (barrier passed, reap still outstanding) is unchanged and still pins that the gate opens at the barrier, not after the reap.

Validation

In remote-worker, with a race-enabled test binary of ./internal/vmpool, run under CPU load (12 busy-loop processes), -test.count=3000 -test.cpu 1,2,4,8 -test.run TestDeferredReapOpensTheGateAtTheBarrierNotAfterTheReap (12,000 runs):

  • Before (main): 4 failures, each deferred_reap_test.go:138: second Exec returned without entering Run: <nil>.
  • After: 0 failures, PASS.

Without load, go test -race -count=500 -cpu 1,2,4 did not reproduce it on main (1,500 runs passed), which matches CI seeing it only now and then.

After the change:

  • go test -race -count=500 -run TestDeferredReapOpensTheGateAtTheBarrierNotAfterTheReap ./internal/vmpool: ok.
  • go test -race ./internal/vmpool: ok.
  • go vet ./...: clean.

Every commit is signed off (DCO).

Assisted-By: Claude Code

TestDeferredReapOpensTheGateAtTheBarrierNotAfterTheReap waited on the
second Exec with a select over entered and done. The fake Run sends on
entered (buffered) and returns at once, so the second Exec can finish
and fill done before the test goroutine reaches the select. With both
cases ready Go picks one at random, and picking done failed the test
with "second Exec returned without entering Run: <nil>" although Run
had been entered.

Run's send happens before Exec returns, so done with nothing on entered
is the only real skipped-Run case. The done case now checks entered
without blocking before failing, and carries the Exec's error over to
the final check. The code under test is unchanged, and the NOT VACUOUS
check (barrier passed, reap outstanding) still pins that the gate opens
at the barrier.

Closes rossoctl#805

Assisted-By: Claude Code
Signed-off-by: Rong Chang <[email protected]>
@webchang
webchang requested a review from pdettori as a code owner November 17, 2026 02:44
@pdettori pdettori added the ready-for-ai-review Request automated AI code review from clawgenti label Nov 17, 2026

@clawgenti clawgenti left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Test-only fix for the flaky deferred-reap gate test (#805): the waiting select raced two ready channels, so Go could pick done and fail the test even though Run had been entered. The nested non-blocking check of entered inside the done case is the right shape — Run's send on entered is ordered before Exec returns, so done with an empty entered is the only genuine failure — and carrying secondErr to the final check avoids the second read of done. The NOT VACUOUS barrier/reap assertion is untouched, so the property the test pins (the gate opens at the barrier, not after the reap) is preserved. The empirical validation in the PR body (12,000 race-enabled runs under CPU load, 4→0 failures) is exactly the evidence a flake fix should carry. No findings; clean test change.

Author: webchang (MEMBER — maintainer)
Areas reviewed: Go (test)
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, all signed-off: yes
CI status: passing

Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).

@ingpaolodettori-dev ingpaolodettori-dev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test fix is correct. Run's send on entered happens before Exec returns, and that return happens before the send on done. So if done is ready while entered is empty, Run really was not entered, and checking entered without blocking before failing is enough to remove the random-select false positive from #805. The second Exec's error still reaches the final check, and the NOT VACUOUS barrier/reap assertion is unchanged.

Something I noticed that this PR neither causes nor needs to fix: the NOT VACUOUS check (reaps != 0) still depends on the 250 ms bound in reapingVM.Reap. If the test goroutine stalls for more than 250 ms after the first Exec, the first reap finishes and the test fails for a reason unrelated to the gate. That window is far wider than the select race, and the author's 12,000 runs under load saw no failures, so this is only a pointer in case #805-style reports keep coming.

Author: webchang (MEMBER, maintainer)
Areas reviewed: Go (test only)
Agent/IDE config (.claude/.vscode): none
Commits: 1, signed off
CI status: all 17 checks passing

Assisted-By: Claude Code

@webchang
webchang merged commit c428685 into rossoctl:main Nov 17, 2026
17 checks passed

@clawgenti clawgenti left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

webchang added a commit to webchang/moca that referenced this pull request Nov 17, 2026
Brings rossoctl#845 (vmpool: the deferred-reap gate test's select is
deterministic) and rossoctl#846 (harness: opt-in SH_PROMPT_CACHE /
SH_GATEWAY_CACHE switches turn turn caching off). No conflicts.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
@pdettori pdettori added this to the v0.11.0 milestone Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-ai-review Request automated AI code review from clawgenti

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vmpool: TestDeferredReapOpensTheGateAtTheBarrierNotAfterTheReap fails intermittently (the test's select races two ready channels)

4 participants