activator: count failed-wake reapers in Service.background
Astra review (request-changes, P2): reapUnprovenWake runs on its own goroutine, forgets the wake's obligation and then writes the generations file, so Shutdown can return between the two with the count at zero. It is now counted from before launch through its last write. TestStatelessStatefulFallbackUnprovenKeepsLease exercises it. Stress on DOCS-T1 (24 spinners, 16 cores): the five tests 0 of 200.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 files changed,
+20
−12
internal/activator/activator.go+4 −3internal/activator/background_test.go+9 −8internal/activator/opset.go+7 −1
diff --git a/internal/activator/activator.go b/internal/activator/activator.go| index 9588a46f5..b179097e4 100644 |
| --- a/internal/activator/activator.go |
| +++ b/internal/activator/activator.go |
| @@ -1619,9 +1619,10 @@ type Service struct { |
| // background counts work that can still write the box's files after |
| // its caller has its answer: wake goroutines (a wake closes e.ready and |
| - // then records the outcome and the generations file) and command settle |
| - // attempts with their proof's callbacks (cmdHold.settle). Nothing in |
| - // the agent waits on it; tests do, before their files go (#897). |
| + // then records the outcome and the generations file), command settle |
| + // attempts with their proof's callbacks (cmdHold.settle), and failed |
| + // wakes' reapers (reapUnprovenWake). Nothing in the agent waits on it; |
| + // tests do, before their files go (#897). |
| background atomic.Int64 |
| // schedMu guards schedFences, each host's schedule write fence |
diff --git a/internal/activator/background_test.go b/internal/activator/background_test.go| index a52ff26d4..04d42c456 100644 |
| --- a/internal/activator/background_test.go |
| +++ b/internal/activator/background_test.go |
| @@ -6,20 +6,21 @@ import ( |
| ) |
| // waitBackground waits until a has no background work in flight |
| -// (Service.background): no wake goroutine and no command settle attempt. |
| -// Both can write the generations file after their caller has its answer: |
| -// a wake records its outcome after it closes e.ready, and a release whose |
| -// stop was not proven settles later, its proof writing the file |
| -// (releaseProven) after the stop returned. A rig calls this |
| -// from a cleanup registered after its t.TempDir calls, so it runs before |
| -// they are removed; without it RemoveAll raced the write (#897: "TempDir |
| +// (Service.background): no wake goroutine, failed-wake reaper or command |
| +// settle attempt. Each can write the generations file after its caller |
| +// has its answer: a wake records its outcome after it closes e.ready, a |
| +// failed wake's reaper writes after Shutdown saw its obligation gone, and |
| +// a release whose stop was not proven settles later, its proof writing |
| +// the file (releaseProven) after the stop returned. A rig calls this from |
| +// a cleanup registered after its t.TempDir calls, so it runs before they |
| +// are removed; without it RemoveAll raced the write (#897: "TempDir |
| // RemoveAll cleanup: directory not empty"). |
| func waitBackground(t *testing.T, a *Service) { |
| t.Helper() |
| deadline := time.Now().Add(10 * time.Second) |
| for a.background.Load() > 0 { |
| if time.Now().After(deadline) { |
| - t.Errorf("%d wakes or settle attempts still in flight after 10s", a.background.Load()) |
| + t.Errorf("%d background tasks still in flight after 10s", a.background.Load()) |
| return |
| } |
| time.Sleep(time.Millisecond) |
diff --git a/internal/activator/opset.go b/internal/activator/opset.go| index d9628e1b3..e2c7e91fa 100644 |
| --- a/internal/activator/opset.go |
| +++ b/internal/activator/opset.go |
| @@ -869,7 +869,13 @@ func (a *Service) reapUnprovenWakesLocked() { |
| continue |
| } |
| u.busy = true |
| - go a.reapUnprovenWake(host, u) |
| + // Counted from before launch through its last write (Service.background): |
| + // it forgets the obligation, then writes the generations file. |
| + a.background.Add(1) |
| + go func(host string, u *unprovenWake) { |
| + defer a.background.Add(-1) |
| + a.reapUnprovenWake(host, u) |
| + }(host, u) |
| } |
| } |