activator: a staged rootfs start asks root for the caller's tier (census P1-1)
startStagedRootfs filled g.Tier but spawnRootfs recomputed GenTier and sent that MemoryMax to root, so an overlap successor could run below the limit swapOverlap chose while the generation recorded the larger one. spawnRootfs now takes the tier; zero means GenTier's.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 files changed,
+38
−4
internal/activator/rootfs.go+12 −4internal/activator/rootfs_staged_test.go+26 −0
diff --git a/internal/activator/rootfs.go b/internal/activator/rootfs.go| index 0b63a70d0..e4a67779c 100644 |
| --- a/internal/activator/rootfs.go |
| +++ b/internal/activator/rootfs.go |
| @@ -265,7 +265,10 @@ func (b *ExecBackend) startStagedRootfs(ctx context.Context, rt registry.Route, |
| return g, nil, fmt.Errorf("%s: not started on %s: %w", rt.Host, id.Version, err) |
| } |
| sock := nestedGenSocketIn(b.pathsFor(rt).runDir, g.N) |
| - up, ver, err := b.spawnRootfs(ctx, rt, sock, g.N, id) |
| + // g.Tier is the limit the caller chose (a swap keeps the incumbent's |
| + // larger tier while a shrink waits for a cold start): root is asked |
| + // for exactly that limit (census P1-1), never a recomputed one. |
| + up, ver, err := b.spawnRootfs(ctx, rt, sock, g.N, id, g.Tier) |
| if err != nil { |
| if up != nil { |
| return g, up, err |
| @@ -282,7 +285,7 @@ func (b *ExecBackend) startStagedRootfs(ctx context.Context, rt registry.Route, |
| // stops the unit, as startUnitAt does, and carries RFS-2-C09. |
| func (b *ExecBackend) startRootfs(ctx context.Context, rt registry.Route, sock string, n uint64, id release.StagedIdentity) (Proc, string, error) { |
| began := time.Now() |
| - up, ver, err := b.spawnRootfs(ctx, rt, sock, n, id) |
| + up, ver, err := b.spawnRootfs(ctx, rt, sock, n, id, cgroup.Limit{}) |
| if err != nil { |
| return nil, "", err |
| } |
| @@ -322,7 +325,10 @@ func (b *ExecBackend) startRootfs(ctx context.Context, rt registry.Route, sock s |
| // runs. The failure handling is spawnUnitFrom's, with |
| // instancectl.ErrStagedImage (root's 403: nothing laid out or started) in |
| // ErrStagedExe's place; any other failure may have started the unit. |
| -func (b *ExecBackend) spawnRootfs(ctx context.Context, rt registry.Route, sock string, n uint64, id release.StagedIdentity) (*unitProc, string, error) { |
| +// tier is the limit root is asked for; a zero tier means GenTier's, so a |
| +// caller that chose a limit (startStagedRootfs, a swap's successor) has it |
| +// kept, as spawnChildFrom and spawnUnitFrom keep theirs. |
| +func (b *ExecBackend) spawnRootfs(ctx context.Context, rt registry.Route, sock string, n uint64, id release.StagedIdentity, tier cgroup.Limit) (*unitProc, string, error) { |
| var steps wakeSteps |
| steps.begin(time.Now()) |
| rc, err := b.rootfsControl() |
| @@ -337,7 +343,9 @@ func (b *ExecBackend) spawnRootfs(ctx context.Context, rt registry.Route, sock s |
| if err != nil { |
| return nil, "", err |
| } |
| - tier := b.GenTier(rt, id.Version) |
| + if tier == (cgroup.Limit{}) { |
| + tier = b.GenTier(rt, id.Version) |
| + } |
| steps.mark(time.Now(), "build") |
| var prep wakeSteps |
| p, ctl, logs, fileEnv, keyLayer, err := b.prepareKeyedAt(rt, instancectl.RoleRun, sock, gen, &prep) |
diff --git a/internal/activator/rootfs_staged_test.go b/internal/activator/rootfs_staged_test.go| index 25c0962a0..0c8e68514 100644 |
| --- a/internal/activator/rootfs_staged_test.go |
| +++ b/internal/activator/rootfs_staged_test.go |
| @@ -369,6 +369,32 @@ func TestStartStagedKeepsTheGenerationsTier(t *testing.T) { |
| } |
| } |
| +// [census P1-1] A tier the caller chose is the one root is asked for: a |
| +// swap that keeps the incumbent's larger tier (swapOverlap, while a shrink |
| +// waits for a cold start) must not see its successor started at the |
| +// smaller route-derived limit, and the generation records what root ran. |
| +func TestStartStagedRootfsKeepsASuppliedTier(t *testing.T) { |
| + t.Parallel() |
| + eb, ctl, rt := newStagedRootfsRig(t) |
| + id := stagedRootfsIdentity(t, eb, "v2") |
| + derived := eb.GenTier(rt, "v2") |
| + chosen := cgroup.Limit{MemoryMax: derived.MemoryMax * 4} |
| + if derived.MemoryMax == 0 || chosen.MemoryMax <= derived.MemoryMax { |
| + t.Fatalf("rig: derived tier %+v, chosen %+v; want chosen larger", derived, chosen) |
| + } |
| + g, p, err := eb.StartStaged(context.Background(), rt, Gen{N: 7, Build: "v2", StagedPath: id.StagedPath, Digest: id.Digest, Tier: chosen}) |
| + if err != nil { |
| + t.Fatalf("StartStaged: %v", err) |
| + } |
| + t.Cleanup(func() { p.Stop(context.Background()) }) //nolint:errcheck |
| + if g.Tier != chosen { |
| + t.Fatalf("the generation's tier is %+v, want the supplied %+v", g.Tier, chosen) |
| + } |
| + if s := onlyStart(t, ctl, id); s.memoryMax != chosen.MemoryMax || s.gen != 7 { |
| + t.Fatalf("root was asked for generation %d memory_max=%d, want 7 at the supplied %d (route-derived %d)", s.gen, s.memoryMax, chosen.MemoryMax, derived.MemoryMax) |
| + } |
| +} |
| + |
| // [Astra R1 2] StartStaged's contract: the process comes back as soon as |
| // it runs, with the full identity on the Gen, and the caller does the one |
| // bounded health check. The 120 s bound is left as it is and the web never |