Agent: the group reference, the claims shutdown limit and the run unit cgroup are its own
host.groupReferenceOf is hostactors.GroupBoxReference's hash and host.claimsShutdownLimit is hostbox.RequestLimit's two minutes, so the agent no longer imports hostactors or hostbox for them; golden tests hold each to its claim twin. instancectl.RunUnitControlGroup is the run unit's cgroup path, which the offline round now calls; ClaimUnitControlGroup delegates to it for the claim code.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
7 files changed,
+57
−14
internal/host/agent.go+7 −2internal/host/boxreference.go+16 −3internal/host/claimsoff_golden_test.go+6 −2internal/host/movesoffline.go+1 −1internal/instancectl/claimunit.go+3 −6internal/instancectl/names.go+10 −0internal/instancectl/rununit_golden_test.go+14 −0
CI failed — run details
diff --git a/internal/host/agent.go b/internal/host/agent.go| index 42dbceabd..3245308c3 100644 |
| --- a/internal/host/agent.go |
| +++ b/internal/host/agent.go |
| @@ -188,7 +188,6 @@ import ( |
| "github.com/carlosframework/platform/internal/edge" |
| "github.com/carlosframework/platform/internal/edgesfile" |
| "github.com/carlosframework/platform/internal/fleetapi" |
| - "github.com/carlosframework/platform/internal/hostbox" |
| "github.com/carlosframework/platform/internal/hostwrite" |
| "github.com/carlosframework/platform/internal/instancectl" |
| "github.com/carlosframework/platform/internal/instancefs" |
| @@ -4960,7 +4959,7 @@ func runAdoptUnderRootRelease(args []string, buildClaims ClaimFactory, ensureUni |
| } |
| } |
| defer func() { |
| - ctx, cancel := context.WithTimeout(context.Background(), hostbox.RequestLimit) |
| + ctx, cancel := context.WithTimeout(context.Background(), claimsShutdownLimit) |
| defer cancel() |
| if err := claims.close(ctx); err != nil { |
| log.Printf("adopt: host claims shutdown: %v", err) |
| @@ -5268,3 +5267,9 @@ func runAdoptUnderRootRelease(args []string, buildClaims ClaimFactory, ensureUni |
| } |
| return passErr |
| } |
| + |
| +// claimsShutdownLimit bounds the adopt pass's host-claim shutdown. It is |
| +// hostbox.RequestLimit's value (two minutes), kept here since claims |
| +// cleanup R1 so the agent no longer imports hostbox for it |
| +// (TestClaimsShutdownLimitGolden). |
| +const claimsShutdownLimit = 120 * time.Second |
diff --git a/internal/host/boxreference.go b/internal/host/boxreference.go| index 47bbf843f..7dce6ce52 100644 |
| --- a/internal/host/boxreference.go |
| +++ b/internal/host/boxreference.go |
| @@ -2,7 +2,9 @@ package host |
| import ( |
| "context" |
| + "crypto/sha256" |
| "encoding/base64" |
| + "encoding/hex" |
| "encoding/json" |
| "errors" |
| "fmt" |
| @@ -11,7 +13,6 @@ import ( |
| "sync" |
| "time" |
| - "github.com/carlosframework/platform/internal/hostactors" |
| "github.com/carlosframework/platform/internal/hostenv" |
| "github.com/carlosframework/platform/internal/registry" |
| "github.com/carlosframework/platform/internal/release" |
| @@ -19,7 +20,7 @@ import ( |
| ) |
| // A box its region's group launched is referenced by its group reference |
| -// (census ruling region-ha-2b): hostactors.GroupBoxReference of its account |
| +// (census ruling region-ha-2b): groupReferenceOf its account |
| // and instance, "g-" and 20 hex digits. Its host.env says so: |
| // carlos system host-env write adds CARLOS_BOX_REFERENCE=group. Status |
| // labels come from 1,600 values and identity records are never deleted, so |
| @@ -83,10 +84,22 @@ func resolveGroupBoxReference() (string, error) { |
| if err != nil { |
| return "", err |
| } |
| - groupRef.ref = hostactors.GroupBoxReference(account, instance) |
| + groupRef.ref = groupReferenceOf(account, instance) |
| return groupRef.ref, nil |
| } |
| +// groupReferenceOf is the reference of a box its region's group launched: |
| +// "g-" and the first 20 hex digits of |
| +// sha256("carlos-box-ref-v1|" + account + "|" + instance). It is |
| +// hostactors.GroupBoxReference, which the console's claim activation |
| +// derives again from the instance it proved; it moved here in claims |
| +// cleanup R1 so the agent no longer imports hostactors, and |
| +// TestGroupBoxReferenceGolden holds the two to one vector. |
| +func groupReferenceOf(account, instance string) string { |
| + sum := sha256.Sum256([]byte("carlos-box-ref-v1|" + account + "|" + instance)) |
| + return "g-" + hex.EncodeToString(sum[:])[:20] |
| +} |
| + |
| // errNoGroupReference is a tick of a group box whose reference has not |
| // resolved: it publishes nothing. |
| var errNoGroupReference = errors.New("this group box's reference could not be read, so it publishes no status report this tick") |
diff --git a/internal/host/claimsoff_golden_test.go b/internal/host/claimsoff_golden_test.go| index 50580d726..e7c5a3a50 100644 |
| --- a/internal/host/claimsoff_golden_test.go |
| +++ b/internal/host/claimsoff_golden_test.go |
| @@ -14,6 +14,8 @@ import ( |
| // sha256("carlos-box-ref-v1|123456789012|i-0a61f580df1acfa65"). |
| func TestGroupBoxReferenceGolden(t *testing.T) { |
| impls := map[string]func(string, string) string{ |
| + "groupReferenceOf": groupReferenceOf, |
| + // The claim activation's twin, until claims cleanup deletes hostactors. |
| "hostactors.GroupBoxReference": hostactors.GroupBoxReference, |
| } |
| for name, f := range impls { |
| @@ -24,7 +26,9 @@ func TestGroupBoxReferenceGolden(t *testing.T) { |
| } |
| func TestClaimsShutdownLimitGolden(t *testing.T) { |
| - if hostbox.RequestLimit != 120*time.Second { |
| - t.Fatalf("hostbox.RequestLimit = %v, want 2m0s", hostbox.RequestLimit) |
| + for name, d := range map[string]time.Duration{"claimsShutdownLimit": claimsShutdownLimit, "hostbox.RequestLimit": hostbox.RequestLimit} { |
| + if d != 120*time.Second { |
| + t.Errorf("%s = %v, want 2m0s", name, d) |
| + } |
| } |
| } |
diff --git a/internal/host/movesoffline.go b/internal/host/movesoffline.go| index aafd2a173..0859e78b7 100644 |
| --- a/internal/host/movesoffline.go |
| +++ b/internal/host/movesoffline.go |
| @@ -403,7 +403,7 @@ func fenceAsWith(svc *activator.Service) func(ctx context.Context, host string, |
| // systemd slice under cgroupRoot (the cgroup v2 mount): every role and |
| // generation unit of the host runs in it. |
| func hostSliceCgroup(cgroupRoot, host string) string { |
| - return filepath.Join(cgroupRoot, filepath.FromSlash(path.Dir(instancectl.ClaimUnitControlGroup(host)))) |
| + return filepath.Join(cgroupRoot, filepath.FromSlash(path.Dir(instancectl.RunUnitControlGroup(host)))) |
| } |
| // offlineRound is the moves pass's round for a record with an offline move, |
diff --git a/internal/instancectl/claimunit.go b/internal/instancectl/claimunit.go| index 5d099ab3d..5abb6eba4 100644 |
| --- a/internal/instancectl/claimunit.go |
| +++ b/internal/instancectl/claimunit.go |
| @@ -5,7 +5,6 @@ import ( |
| "errors" |
| "fmt" |
| "os" |
| - "path" |
| "path/filepath" |
| "strconv" |
| "strings" |
| @@ -58,11 +57,9 @@ var ( |
| ErrClaimUnit = errors.New("instance control: the claim unit did not start as requested") |
| ) |
| -// ClaimUnitControlGroup is the host's run unit cgroup, relative to the |
| -// cgroup root. |
| -func ClaimUnitControlGroup(host string) string { |
| - return path.Join(parentSlices, SliceName(host), UnitName(RoleRun, host)) |
| -} |
| +// ClaimUnitControlGroup is RunUnitControlGroup, under the name the claim |
| +// code calls it by. |
| +func ClaimUnitControlGroup(host string) string { return RunUnitControlGroup(host) } |
| func claimTier(n int64) (cgroup.Limit, bool) { |
| switch n { |
diff --git a/internal/instancectl/names.go b/internal/instancectl/names.go| index f2adb04f9..d22c21677 100644 |
| --- a/internal/instancectl/names.go |
| +++ b/internal/instancectl/names.go |
| @@ -15,6 +15,7 @@ package instancectl |
| import ( |
| "errors" |
| "fmt" |
| + "path" |
| "path/filepath" |
| "strconv" |
| "strings" |
| @@ -138,6 +139,15 @@ func SliceName(host string) string { |
| return "carlos-instances-" + Escape(provision.InstanceID(host)) + ".slice" |
| } |
| +// RunUnitControlGroup is the host's run unit cgroup, relative to the |
| +// cgroup root: <parentSlices>/<SliceName>/<UnitName(RoleRun)>. The offline |
| +// move round reads the host's slice from it. It was ClaimUnitControlGroup |
| +// until claims cleanup R1, which keeps that name as a delegate for the |
| +// claim code. |
| +func RunUnitControlGroup(host string) string { |
| + return path.Join(parentSlices, SliceName(host), UnitName(RoleRun, host)) |
| +} |
| + |
| // UnitPrefixGen is the generation template (zero-downtime deploys spec |
| // §7.6): one instance per spawn of a host's run role. The four templates |
| // above stay for every box and binary still running them. |
diff --git a/internal/instancectl/rununit_golden_test.go b/internal/instancectl/rununit_golden_test.go| new file mode 100644 |
| index 000000000..27a3b2fb4 |
| --- /dev/null |
| +++ b/internal/instancectl/rununit_golden_test.go |
| @@ -0,0 +1,14 @@ |
| +package instancectl |
| + |
| +import "testing" |
| + |
| +// The run unit's cgroup, relative to the cgroup root. The offline move |
| +// round finds a host's slice from it (claims cleanup R1 renamed it from |
| +// ClaimUnitControlGroup, which the claim code still calls). |
| +func TestRunUnitControlGroupGolden(t *testing.T) { |
| + host := "alpha.shop.example.com" |
| + const want = "carlos.slice/carlos-instances.slice/carlos-instances-alpha.shop.example.com.slice/carlos-instance@alpha.shop.example.com.service" |
| + if got := RunUnitControlGroup(host); got != want || got != ClaimUnitControlGroup(host) { |
| + t.Fatalf("RunUnitControlGroup = %q, ClaimUnitControlGroup = %q, want %q", got, ClaimUnitControlGroup(host), want) |
| + } |
| +} |