carlos / platform Public

activator: a proven release record stays the host's obligation until its cleanup is done

Astra R1 P1 on R1a-R1c. releaseProven deleted the record before giving
a failed wake's kept lease back and before writing the uncertain stop
history, so in that gap Shutdown's drain saw nothing owed and returned,
and FenceAndStop could fence over an earlier complete history. Now the
lease goes back first, off a.mu (a failed return lands in owedReleases
through giveBack while the record still stands), and the record goes in
the same critical section that writes the uncertain history.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 6746ab1c8d12f025cabc64a02aee022dd8193b06 parent 17a55e8
2 files changed, +185 −16
  • internal/activator/rootfsrelease.go +23 −16
  • internal/activator/rootfsrelease_test.go +162 −0
diff --git a/internal/activator/rootfsrelease.go b/internal/activator/rootfsrelease.go
index 6dbc4e81f..8cb33b3bf 100644
--- a/internal/activator/rootfsrelease.go
+++ b/internal/activator/rootfsrelease.go
@@ -654,35 +654,42 @@ func (a *Service) settleRelease(op *releaseOp) error {
}
// releaseProven is the proof's work, once, from runRelease or the hold's
-// onProven (the sweep's retry) [pf R1.9, R1.13]: the record goes if it is
-// still the host's, the supervisor ends, a failed wake's lease it kept
-// is given back (oweRelease on failure), an ownerless record leaves the
-// stop history uncertain as a retained failed wake's proof does
-// (reapUnprovenWake), and the generations file drops the build's pin.
+// onProven (the sweep's retry) [pf R1.9, R1.13]: the supervisor ends, a
+// failed wake's lease the record kept is given back (oweRelease on
+// failure), an ownerless record leaves the stop history uncertain as a
+// retained failed wake's proof does (reapUnprovenWake), and only then
+// does the record go, in the same critical section as the history, and
+// the generations file drop the build's pin. The record stays the host's
+// obligation until its cleanup is done (Astra R1 P1): Shutdown's drain
+// and FenceAndStop see the record, or the owed release giveBack recorded
+// before it went (owedReleases) together with the uncertain history,
+// never a gap. The lease's return is network I/O, off a.mu.
func (a *Service) releaseProven(op *releaseOp) {
op.ended.Do(func() {
+ close(op.done)
+ log.Printf("activator: %s: the release command of build %s is proven stopped", op.host, op.build.Version)
a.mu.Lock()
+ ours := a.releaseOps[op.host] == op
var owed Lease
- ownerless := false
- if a.releaseOps[op.host] == op {
- delete(a.releaseOps, op.host)
- owed, op.owed = op.owed, nil
- ownerless = op.owner == nil || a.entries[op.host] != op.owner
+ if ours {
+ owed = op.owed
}
a.mu.Unlock()
- close(op.done)
- log.Printf("activator: %s: the release command of build %s is proven stopped", op.host, op.build.Version)
released := true
if owed != nil {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
released = a.giveBack(ctx, op.host, owed)
cancel()
}
- if ownerless {
- a.mu.Lock()
- a.rememberStopLocked(op.host, &stopObservation{mainStop: true, mainExited: true, uncertain: true, leaseReleased: released})
- a.mu.Unlock()
+ a.mu.Lock()
+ if a.releaseOps[op.host] == op {
+ if op.owner == nil || a.entries[op.host] != op.owner {
+ a.rememberStopLocked(op.host, &stopObservation{mainStop: true, mainExited: true, uncertain: true, leaseReleased: released})
+ }
+ op.owed = nil
+ delete(a.releaseOps, op.host)
}
+ a.mu.Unlock()
_ = a.persistGenerations()
})
}
diff --git a/internal/activator/rootfsrelease_test.go b/internal/activator/rootfsrelease_test.go
index 06c0f11eb..8e5be15c3 100644
--- a/internal/activator/rootfsrelease_test.go
+++ b/internal/activator/rootfsrelease_test.go
@@ -1957,6 +1957,124 @@ func TestShutdownDrainsReleaseOps(t *testing.T) {
return unstick, owed
}
+ // Astra R1 P1: the record stays the host's obligation until its
+ // cleanup is done. A lease return that blocks after the proof keeps
+ // Shutdown waiting and a fence refused; a failed one hands the
+ // obligation to owedReleases with no gap.
+ t.Run("the lease's return blocks after the proof", func(t *testing.T) {
+ r := newConsumerRig(t, true)
+ unstick, _ := orphan(t, r)
+ gl := newGatedLease(nil)
+ r.a.mu.Lock()
+ r.a.releaseOps[r.rt.Host].owed = gl
+ r.a.rememberStopLocked(r.rt.Host, &stopObservation{mainStop: true, mainExited: true, sidecarStop: true, sidecarExited: true, replicaClosed: true, leaseReleased: true})
+ r.a.mu.Unlock()
+ unstick()
+ r.clk.advance(actStopTimeout)
+ done := shutdownIn(r.a, 10*time.Second)
+ select {
+ case <-gl.entered:
+ case <-time.After(5 * time.Second):
+ t.Fatal("the proven record's lease was never given back")
+ }
+ time.Sleep(300 * time.Millisecond)
+ if returned(done) {
+ t.Fatal("Shutdown returned while the proven record's lease return was in flight")
+ }
+ if r.record() == nil {
+ t.Fatal("the record went before its lease was given back")
+ }
+ fctx, fcancel := context.WithTimeout(context.Background(), 2*time.Second)
+ if _, err := r.a.FenceAndStop(fctx, r.rt.Host, 1); !errors.Is(err, ErrStopUnproven) {
+ t.Errorf("a fence during the lease return = %v, want ErrStopUnproven", err)
+ }
+ fcancel()
+ r.a.LiftFence(r.rt.Host, 1)
+ close(gl.gate)
+ select {
+ case <-done:
+ case <-time.After(5 * time.Second):
+ t.Fatal("Shutdown did not return once the lease was given back")
+ }
+ r.a.mu.Lock()
+ history := r.a.stopHistory[r.rt.Host]
+ left := r.a.releaseOps[r.rt.Host]
+ r.a.mu.Unlock()
+ if left != nil || history == nil || !history.uncertain || !history.leaseReleased {
+ t.Fatalf("record %v, history %+v; want the record gone over an uncertain history with the lease released", left, history)
+ }
+ })
+
+ t.Run("a failed lease return is handed to owedReleases", func(t *testing.T) {
+ r := newConsumerRig(t, true)
+ unstick, _ := orphan(t, r)
+ gl := newGatedLease(errors.New("store: DeleteObject timed out"))
+ gl.setRetryErr(errors.New("store: DeleteObject timed out"))
+ r.a.mu.Lock()
+ r.a.releaseOps[r.rt.Host].owed = gl
+ r.a.rememberStopLocked(r.rt.Host, &stopObservation{mainStop: true, mainExited: true, sidecarStop: true, sidecarExited: true, replicaClosed: true, leaseReleased: true})
+ r.a.mu.Unlock()
+ // Watch the obligation the whole way: the record, or the owed
+ // release over an uncertain history.
+ var gap atomic.Bool
+ stop := make(chan struct{})
+ watched := make(chan struct{})
+ go func() {
+ defer close(watched)
+ for {
+ r.a.mu.Lock()
+ owed := false
+ for o := range r.a.owedReleases {
+ owed = owed || o.host == r.rt.Host
+ }
+ h := r.a.stopHistory[r.rt.Host]
+ if r.a.releaseOps[r.rt.Host] == nil && (!owed || h == nil || !h.uncertain) {
+ gap.Store(true)
+ }
+ r.a.mu.Unlock()
+ select {
+ case <-stop:
+ return
+ default:
+ }
+ }
+ }()
+ unstick()
+ r.clk.advance(actStopTimeout)
+ r.sweepPass()
+ select {
+ case <-gl.entered:
+ case <-time.After(5 * time.Second):
+ t.Fatal("the proven record's lease was never given back")
+ }
+ close(gl.gate)
+ waitFor(t, "the record to go", func() bool { return r.record() == nil })
+ close(stop)
+ <-watched
+ if gap.Load() {
+ t.Fatal("the obligation had a gap: no record and no owed release over an uncertain history")
+ }
+ r.a.mu.Lock()
+ history := r.a.stopHistory[r.rt.Host]
+ r.a.mu.Unlock()
+ if history == nil || !history.uncertain || history.leaseReleased {
+ t.Fatalf("history %+v; want uncertain with the lease not released", history)
+ }
+ // Shutdown now waits on the owed release, and returns once its
+ // retry lands.
+ done := shutdownIn(r.a, 10*time.Second)
+ time.Sleep(300 * time.Millisecond)
+ if returned(done) {
+ t.Fatal("Shutdown returned with the lease release still owed")
+ }
+ gl.setRetryErr(nil)
+ select {
+ case <-done:
+ case <-time.After(5 * time.Second):
+ t.Fatal("Shutdown did not return once the retry landed")
+ }
+ })
+
t.Run("an ownerless record with an owed lease", func(t *testing.T) {
r := newConsumerRig(t, true)
unstick, _ := orphan(t, r)
@@ -2096,3 +2214,47 @@ func TestStopSettlesARunningRelease(t *testing.T) {
})
}
}
+
+// gatedLease is a lease whose Release blocks until gate closes (entered
+// closes as it is asked) and then answers err; RetryRelease answers the
+// retry error set at the time.
+type gatedLease struct {
+ gate chan struct{}
+ entered chan struct{}
+ once sync.Once
+ err error
+ mu sync.Mutex
+ retryErr error
+}
+
+func newGatedLease(err error) *gatedLease {
+ return &gatedLease{gate: make(chan struct{}), entered: make(chan struct{}), err: err}
+}
+
+func (l *gatedLease) Replicate(context.Context, string, time.Duration) (Rep, error) {
+ return nil, errors.New("not used")
+}
+
+func (l *gatedLease) Release(ctx context.Context) error {
+ l.once.Do(func() { close(l.entered) })
+ select {
+ case <-l.gate:
+ return l.err
+ case <-ctx.Done():
+ return ctx.Err()
+ }
+}
+
+func (l *gatedLease) RetryRelease(context.Context) error {
+ l.mu.Lock()
+ defer l.mu.Unlock()
+ return l.retryErr
+}
+
+func (l *gatedLease) setRetryErr(err error) {
+ l.mu.Lock()
+ l.retryErr = err
+ l.mu.Unlock()
+}
+
+var _ releaseRetrier = (*gatedLease)(nil)