carlos / platform Public

activator: a read size column reaches the route before the CPU and IO call, so a swap after a failed call starts at the new memory (Task 12a review)

The client test keeps a synthetic 409 as a refusal.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev c4c5f2bbefdb04be60eec780f29d2b88c07cd998 parent 31da426
3 files changed, +44 −16
  • internal/activator/size.go +13 −11
  • internal/activator/size_live_test.go +12 −3
  • internal/instancectl/client_test.go +19 −2

CI failed — run details

diff --git a/internal/activator/size.go b/internal/activator/size.go
index f56a0d208..7bdcada4c 100644
--- a/internal/activator/size.go
+++ b/internal/activator/size.go
@@ -212,12 +212,13 @@ func (a *Service) endSizeCheck(e *actEntry, redo bool) {
// With no operator change (the column is what the entry last acted on) and
// no write owed it ends after the registry read, with no root call.
// Otherwise it sends the effective size once: root sets the slice's CPU
-// and IO shares and never memory (spec §5.4 rev 10). It is applied when
-// the read-back shows the size's shares; anything else leaves the write
-// owed, and the next sweep sends it again. A refusal (root under host
-// claims, a host with no live change) is not retried. In both cases the
-// size is recorded on the route, and the next start, an overlap
-// successor's included, sizes its memory from it (Astra plan R6-1).
+// and IO shares and never memory (spec §5.4 rev 10). Before the call the
+// size is recorded on the route, whatever the call's outcome, and the next
+// start, an overlap successor's included, sizes its memory from it (Astra
+// plan R6-1). The call is applied when the read-back shows the size's
+// shares; anything else leaves the CPU and IO write owed, and the next
+// sweep sends it again. A refusal (root under host claims, a host with no
+// live change) is not retried.
func (a *Service) sizePass(e *actEntry, s sizeSnap) {
host := s.rt.Host
fresh := s.rt
@@ -251,6 +252,11 @@ func (a *Service) sizePass(e *actEntry, s sizeSnap) {
a.mu.Unlock()
return
}
+ // The column is read and the entry is the one the snapshot was taken
+ // from: the route records it now, whatever the CPU and IO write below
+ // does, so the next start or swap sizes its memory from it. Only the
+ // CPU and IO write can be owed.
+ e.sizeSeen, e.route.Size = fresh.Size, fresh.Size
done := make(chan struct{})
e.ops.resizing, e.ops.resizeDone = true, done
a.mu.Unlock()
@@ -264,11 +270,7 @@ func (a *Service) sizePass(e *actEntry, s sizeSnap) {
applied := err == nil && rb.CPUQuotaPercent == sh.CPUQuotaPercent && rb.CPUWeight == sh.CPUWeight && rb.IOWeight == sh.IOWeight
a.mu.Lock()
- if applied || refused {
- e.sizeSeen, e.route.Size, e.sizeOwed = fresh.Size, fresh.Size, false
- } else {
- e.sizeOwed = true
- }
+ e.sizeOwed = !applied && !refused
e.ops.resizing, e.ops.resizeDone, e.sizeChecking = false, nil, false
a.mu.Unlock()
close(done)
diff --git a/internal/activator/size_live_test.go b/internal/activator/size_live_test.go
index e5f3eafca..31bef3d86 100644
--- a/internal/activator/size_live_test.go
+++ b/internal/activator/size_live_test.go
@@ -340,7 +340,9 @@ func TestSwapRefusedOnlyWhileResizing(t *testing.T) {
// A failed call, or one whose read-back does not show the size's shares,
// is owed: the next sweep sends it again with no operator change, and no
-// swap is held back meanwhile. Once applied, nothing more is sent.
+// swap is held back meanwhile. The route records the new size anyway, so
+// a swap admitted in between starts its successor at the new memory. Once
+// applied, nothing more is sent.
func TestAFailedLiveSizeRetriesNextSweep(t *testing.T) {
t.Parallel()
for _, tc := range []struct {
@@ -365,8 +367,15 @@ func TestAFailedLiveSizeRetriesNextSweep(t *testing.T) {
})
f.operatorSets("xlarge")
f.sweep(t)
- if res := f.a.Swap(context.Background(), f.attempt(ModeOverlap), f.newest); res.Outcome != SwapDone {
- t.Fatalf("Swap = %+v after a failed call, want done: only a call in flight holds a swap", res)
+ // The column was read, so the route carries it whatever the CPU
+ // and IO write did: the swap admitted now starts its successor
+ // at xlarge's memory.
+ res := f.a.Swap(context.Background(), f.attempt(ModeOverlap), f.newest)
+ if res.Outcome != SwapDone || res.Gen.Tier.MemoryMax != two {
+ t.Fatalf("Swap = %+v after a failed call, want done at %d: only a call in flight holds a swap", res, two)
+ }
+ if ev := f.b.events(); indexPrefix(ev, fmt.Sprintf("raise:%d+%d", half, two)) < 0 {
+ t.Fatalf("events %v: want the raise to 512 MiB + 2 GiB", ev)
}
f.sweep(t) // still failing: owed again
failing.Store(false)
diff --git a/internal/instancectl/client_test.go b/internal/instancectl/client_test.go
index c9fede6a5..db11a7bd1 100644
--- a/internal/instancectl/client_test.go
+++ b/internal/instancectl/client_test.go
@@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"errors"
+ "net"
"net/http"
"os"
"path/filepath"
@@ -198,8 +199,8 @@ func TestClientEgressVerbs(t *testing.T) {
}
}
-// Size and ReadSize: a refusal before any write (400 shape, 503 with host
-// claims on) wraps ErrSizeRefused; a 502 (systemd failed, the slice may
+// Size and ReadSize: a refusal before any write (400 shape, 409, 503 with
+// host claims on) wraps ErrSizeRefused; a 502 (systemd failed, the slice may
// be written) does not.
func TestClientSizeMapsRefusalsToErrSizeRefused(t *testing.T) {
ctx := context.Background()
@@ -216,6 +217,20 @@ func TestClientSizeMapsRefusalsToErrSizeRefused(t *testing.T) {
t.Fatalf("ReadSize = %+v, %v", rb, err)
}
+ // No root handler answers /size with 409 today, but the client's
+ // contract keeps it a refusal: a synthetic socket answers 409.
+ conflict := filepath.Join(t.TempDir(), "c.sock")
+ ln, err := net.Listen("unix", conflict)
+ if err != nil {
+ t.Fatal(err)
+ }
+ srv := &http.Server{Handler: http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
+ http.Error(w, "conflict", http.StatusConflict)
+ })}
+ go srv.Serve(ln)
+ t.Cleanup(func() { srv.Close() })
+ c409 := NewClient(conflict)
+
_, claimed := newClient(t, sizeCtl(""), func(s *Server) {
s.ClaimStop = http.HandlerFunc(func(http.ResponseWriter, *http.Request) {})
})
@@ -229,6 +244,8 @@ func TestClientSizeMapsRefusalsToErrSizeRefused(t *testing.T) {
}{
"Size 400": {func() error { _, err := c.Size(ctx, sizeHost, "huge"); return err }, true},
"ReadSize 400": {func() error { _, err := c.ReadSize(ctx, "../etc"); return err }, true},
+ "Size 409": {func() error { _, err := c409.Size(ctx, sizeHost, "large"); return err }, true},
+ "ReadSize 409": {func() error { _, err := c409.ReadSize(ctx, sizeHost); return err }, true},
"Size 503": {func() error { _, err := claimed.Size(ctx, sizeHost, "large"); return err }, true},
"ReadSize 503": {func() error { _, err := claimed.ReadSize(ctx, sizeHost); return err }, true},
"Size 502": {func() error { _, err := cf.Size(ctx, sizeHost, "large"); return err }, false},