carlos / platform Public

activator: with an operator size, a swap's successor starts at the larger of its size and the incumbent's

Spec §5.4 rev 8: when the route has a size, or the incumbent runs at a
tier other than its build's own (a size in force at its start, or grown
live, since cleared), succTier = MaxLimit(succTier, incumbent.Tier), so
the raise and restore never lower memory. With no operator size each
artifact keeps its own tier, as on main. The swap fake's GenTier now
reads the size column first, as ExecBackend.GenTier does.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 9ba744f3a3a27274a7d86bdf190c2a3a8a92537f parent ad00afa
3 files changed, +85 −4
  • internal/activator/swap.go +12 −0
  • internal/activator/swap_fixture_test.go +5 −4
  • internal/activator/swap_overlap_test.go +68 −0
diff --git a/internal/activator/swap.go b/internal/activator/swap.go
index 629c3145c..2cded1bc0 100644
--- a/internal/activator/swap.go
+++ b/internal/activator/swap.go
@@ -499,6 +499,18 @@ func (a *Service) swapOverlap(ctx context.Context, gb SwapBackend, at Attempt, n
incumbent.Tier = gb.GenTier(rt, incumbent.Build)
}
succTier := gb.GenTier(rt, at.Build)
+ // With an operator size the successor starts at the larger of its own
+ // effective size and the incumbent's captured tier (spec §5.4 rev 8,
+ // R1-3). That applies when the route has a size now, or when the
+ // incumbent runs at a tier other than its build's own (a size was in
+ // force at its start, or it was grown live, and has since been cleared).
+ // The raise and the restore then never lower memory: a shrink waits for
+ // a cold start. It is conditional so that a host with no operator size
+ // keeps each artifact's own tier, byte-identical to main: a release that
+ // drops children still restores to 512 MiB at the swap.
+ if rt.Size != "" || incumbent.Tier != gb.GenTier(rt, incumbent.Build) {
+ succTier = cgroup.MaxLimit(succTier, incumbent.Tier)
+ }
a.mu.Lock()
if e.gen.N == incumbent.N {
e.gen.Tier = incumbent.Tier
diff --git a/internal/activator/swap_fixture_test.go b/internal/activator/swap_fixture_test.go
index a3b2d25a1..f459eecf2 100644
--- a/internal/activator/swap_fixture_test.go
+++ b/internal/activator/swap_fixture_test.go
@@ -122,14 +122,15 @@ func (g *fakeSwapBackend) StartStaged(ctx context.Context, _ registry.Route, gen
return gen, proc, nil
}
-// GenTier answers from tiers (by build), and the default tier otherwise.
-func (g *fakeSwapBackend) GenTier(_ registry.Route, build string) cgroup.Limit {
+// GenTier answers from tiers (by build), and the default tier otherwise,
+// with the route's size column first, as ExecBackend.GenTier does.
+func (g *fakeSwapBackend) GenTier(rt registry.Route, build string) cgroup.Limit {
g.gmu.Lock()
defer g.gmu.Unlock()
if t, ok := g.tiers[build]; ok {
- return t
+ return SizedLimit(rt, t)
}
- return cgroup.TierDefault
+ return SizedLimit(rt, cgroup.TierDefault)
}
func (g *fakeSwapBackend) GenReady(registry.Route, Gen, Proc) {}
diff --git a/internal/activator/swap_overlap_test.go b/internal/activator/swap_overlap_test.go
index d95a8de93..bd9070654 100644
--- a/internal/activator/swap_overlap_test.go
+++ b/internal/activator/swap_overlap_test.go
@@ -99,6 +99,74 @@ func TestSwapOverlapUsesEachArtifactsTier(t *testing.T) {
})
}
+// With an operator size, now or in force at the incumbent's start, the
+// successor starts at the larger of its own effective size and the
+// incumbent's captured tier, so the restore never lowers memory (spec §5.4
+// rev 8). With no operator size each artifact keeps its own tier, as on
+// main: case (c) is TestSwapOverlapUsesEachArtifactsTier/switched.
+func TestSwapSuccessorStartsAtTheLargerSizeOnlyWithAnOperatorSize(t *testing.T) {
+ t.Parallel()
+ const half, gib, two = int64(1 << 29), int64(1 << 30), int64(2 << 30)
+ for _, tc := range []struct {
+ name string
+ size string // the route's size column at the swap
+ tiers map[string]cgroup.Limit // each build's own tier
+ inc int64 // the incumbent's captured tier; 0 = not captured
+ succ int64 // the successor's tier, and the restore
+ raise string
+ }{
+ // The operator grew the host to large; the incumbent started at 512 MiB.
+ {"a: operator size large over a standard incumbent", "large", nil, half, gib,
+ fmt.Sprintf("raise:%d+%d", half, gib)},
+ // Grown live to xlarge, then the operator chose standard: the shrink
+ // waits for a cold start.
+ {"b: operator size standard under an xlarge incumbent", "standard", nil, two, two,
+ fmt.Sprintf("raise:%d+%d", two, two)},
+ // No operator size: each artifact's own tier, byte-identical to main.
+ {"c: no operator size keeps each artifact's tier", "",
+ map[string]cgroup.Limit{"v1": cgroup.TierChildren, "v2": cgroup.TierDefault}, 0, half,
+ fmt.Sprintf("raise:%d+%d", gib, half)},
+ // Grown live to xlarge, then the size cleared: the incumbent runs
+ // above its build's tier, so the swap never lowers it.
+ {"d: cleared size under an xlarge incumbent", "", nil, two, two,
+ fmt.Sprintf("raise:%d+%d", two, two)},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ f := newSwapFixture(t)
+ f.b.tiers = tc.tiers
+ inc := f.incumbent
+ inc.Tier = cgroup.Limit{MemoryMax: tc.inc}
+ setCurrentGen(t, f.a, f.host, inc)
+ f.a.mu.Lock()
+ f.a.entries[f.host].route.Size = tc.size
+ f.a.mu.Unlock()
+
+ res := f.a.Swap(context.Background(), f.attempt(ModeOverlap), f.newest)
+ if res.Outcome != SwapDone || res.Gen.Tier.MemoryMax != tc.succ {
+ t.Fatalf("Swap = %+v, want done at %d", res, tc.succ)
+ }
+ if g, _ := f.b.lastGen(); g.Tier.MemoryMax != tc.succ {
+ t.Fatalf("the successor spawned at %d, want %d", g.Tier.MemoryMax, tc.succ)
+ }
+ ev := f.b.events()
+ if indexPrefix(ev, tc.raise) < 0 {
+ t.Fatalf("events %v: want %s", ev, tc.raise)
+ }
+ // A bare "restore" is the wake's data restore; "restore:" is the
+ // parent's. There is exactly one, to the successor's tier.
+ var restores []string
+ for _, e := range ev {
+ if strings.HasPrefix(e, "restore:") {
+ restores = append(restores, e)
+ }
+ }
+ if want := fmt.Sprintf("restore:%d", tc.succ); len(restores) != 1 || restores[0] != want {
+ t.Fatalf("parent restores %v, want only %s", restores, want)
+ }
+ })
+ }
+}
+
// The "swapped" event carries the retiring generation's drain time (spec
// §9.4), so the result measures it: from SIGTERM to the proven exit.
func TestSwapOverlapReportsTheDrainTime(t *testing.T) {