carlos / platform Public

rollout: hold-ran tests wait for done() itself, and leave no gated derivation to race (#425)

Two flakes from one cause: an attempt's done() frees the host's slot
(scheduler.go s.q.finish, under s.mu) before it has finished. After
s.mu.Unlock it still makes the pointer read due (m.pointerReadDue) and
pokes the scheduler. The tests waited only for !attemptRunning.

- TestAnInstallOntoTheGoodBuildMakesTheRollbackReadDueAtOnce ("after the
  pass the marker stands: true", main 50c0cb14): the pass ran between the
  slot freeing and pointerReadDue, so it did not read the pointers. It now
  waits for the read to be due too (pointerReadIsDue, test-only).

- TestAMoveOntoTheInstalledGoodBuildWaitsForASignedRollback ("timed out
  waiting for the move onto v1", #425): done()'s poke can start a
  derivation at any time. The test advanced the clock past the abandon
  deferral before the pass cleared the marker, so that derivation could be
  gated a third time and defer the host another 15 s of fake time, and
  nothing moved the clock again. The clock now goes first to the pointer
  read's due time, still inside the deferral, where a derivation admits
  nothing; the pass clears the marker; only then does the clock leave the
  deferral. The test checks the constants still allow that timeline.

In production the poke and the next pass converge on their own; nothing
is changed there.

Under load (2 cores, 4 busy loops, nice 19, -cpu 1,2,4): before 1 failure
in 180 runs, after 0 in 600.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 38bf593a5f9608187b70301d2b31c19714d2072c parent 71bf7e7
2 files changed, +40 −2
  • internal/rollout/fake_test.go +9 −0
  • internal/rollout/holdran_test.go +31 −2
diff --git a/internal/rollout/fake_test.go b/internal/rollout/fake_test.go
index fa5528d89..0bbbc486a 100644
--- a/internal/rollout/fake_test.go
+++ b/internal/rollout/fake_test.go
@@ -530,6 +530,15 @@ func (h *harness) flushAcks() {
waitFor(h.t, "the ack writer to finish", h.m.acks.idle)
}
+// pointerReadIsDue reports whether the next pass reads k's pointers whatever
+// the clock says (pointerReadDue has run since the last read).
+func (m *Manager) pointerReadIsDue(k appKey) bool {
+ m.mu.Lock()
+ defer m.mu.Unlock()
+ _, read := m.pointerRead[k]
+ return !read
+}
+
func waitFor(t *testing.T, what string, cond func() bool) {
t.Helper()
deadline := time.Now().Add(5 * time.Second)
diff --git a/internal/rollout/holdran_test.go b/internal/rollout/holdran_test.go
index 2eb2aa930..1558fff88 100644
--- a/internal/rollout/holdran_test.go
+++ b/internal/rollout/holdran_test.go
@@ -616,7 +616,13 @@ func TestAnInstallOntoTheGoodBuildMakesTheRollbackReadDueAtOnce(t *testing.T) {
h.pass() // the newer desire supersedes the attempt
h.advance(5 * time.Second)
close(gate)
- waitFor(t, "h's attempt to finish", func() bool { return !h.m.attemptRunning("h") })
+ // The attempt's done() frees the slot and sets the marker, then
+ // makes the read due once it has let go of the scheduler's lock:
+ // a pass in between does not read (CI 2026-10-27, "after the pass
+ // the marker stands"). So the wait is for both.
+ waitFor(t, "h's attempt to finish and make the pointer read due", func() bool {
+ return !h.m.attemptRunning("h") && h.m.pointerReadIsDue(appKey{"bab", "blog"})
+ })
got, ok := h.book.HoldRanOn("h")
if !ok || !got.same(markV2) || !got.At.Equal(start) {
t.Fatalf("marker = %+v, %v: want v2's, stamped at the attempt's dispatch %v", got, ok, start)
@@ -787,12 +793,35 @@ func TestAMoveOntoTheInstalledGoodBuildWaitsForASignedRollback(t *testing.T) {
// `carlos rollback` signs v1; the pointer pass clears the marker,
// and the next derivation moves h onto v1.
+ //
+ // The second gated attempt's done() pokes the scheduler after its
+ // slot is free, so a derivation can run at any moment from here.
+ // The clock goes first to the pointer read's due time, which is
+ // still inside the host's abandon deferral: a derivation then
+ // admits nothing, and the pass clears the marker. Only then does
+ // the clock leave the deferral. Advancing straight past both let
+ // that derivation run between the advance and the pass, be gated
+ // a third time and defer the host for another abandonDeferral
+ // (CI 2026-10-26, "timed out waiting for the move onto v1").
+ // pointer() is signed at the gated attempt's time, so it is newer
+ // than the marker either way.
+ // Times from the first pass, which read the pointers; the second
+ // gated attempt deferred h until abandonDeferral after it ran.
+ deferredUntil := abandonDeferral + time.Second + abandonDeferral
+ if pointerReadEvery >= deferredUntil {
+ t.Fatalf("pointerReadEvery %s no longer falls inside the deferral ending at %s; re-derive this timeline", pointerReadEvery, deferredUntil)
+ }
h.pointer("stable", "v1", h.clock())
- h.advance(pointerReadEvery)
+ h.advance(pointerReadEvery - (abandonDeferral + time.Second))
h.pass()
if got, ok := h.book.HoldRanOn("h"); ok {
t.Fatalf("marker %+v survived the signed rollback", got)
}
+ if n := moves(); n != 0 || gatedTimes() != 2 {
+ t.Fatalf("%d moves and %d gated attempts inside the deferral, want 0 and 2", n, gatedTimes())
+ }
+ h.advance(deferredUntil - pointerReadEvery + time.Second)
+ h.pass()
waitFor(t, "the move onto v1", func() bool { return moves() == 1 })
if calls, _, _ := h.act.snapshot(); len(calls) == 1 && (worker || calls[0].a.Build != "v1") {
t.Fatalf("swap %+v: want one onto v1 (and none for a worker)", calls[0].a)