carlos / platform Public

layout: never mint flat on a nested-default box with no gate armed

Hunt H2-M6. With no intent recorded and the nested default, a box whose
layout gate was never armed (a claim box, a box with no activator, the
window before the pass is built) minted fresh rows flat unless a managed
nested row already sat on the box. It now mints nested there too; the
row waits on the gate at wake. Only a build below the layout floor
still mints flat. Witness: hunt_H2_M6_test.go; the tests that pinned
the old answer now pin it below the floor or under the opt-out.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 8eeeed195f7141042acc37a718ddddddb35cdf46 parent 07280eb
4 files changed, +94 −31
  • internal/host/agent_layout_test.go +18 −12
  • internal/host/hunt_H2_M6_test.go +56 −0
  • internal/host/layoutleg.go +14 −13
  • internal/host/rootfs_advice_test.go +6 −6
diff --git a/internal/host/agent_layout_test.go b/internal/host/agent_layout_test.go
index fb3800c00..66b4a1dbd 100644
--- a/internal/host/agent_layout_test.go
+++ b/internal/host/agent_layout_test.go
@@ -654,10 +654,13 @@ func TestUnmanagedLayoutReportFencesAJournalledOrHeldHost(t *testing.T) {
}
// mintLayoutIntent (ReconcileConfig.Layout for this box): an absent intent
-// object is "" with no error, so mints proceed flat; only a real read
-// failure, or a request this binary cannot read, is an error that defers
-// them.
+// object is no error, so mints proceed, flat on a box that opted out
+// (CARLOS_LAYOUT_DEFAULT=flat; on the nested default the answer is nested,
+// TestStartupAndMintReadTheDefault); only a real read failure, or a
+// request this binary cannot read, is an error that defers them.
func TestMintLayoutIntentAbsentIsFlatAndUnreadableIsAnError(t *testing.T) {
+ resetLayoutGlobals(t)
+ t.Setenv(layoutDefaultEnv, "flat")
ctx := context.Background()
s := release.NewDirStore(t.TempDir())
if mode, err := mintLayoutIntent(ctx, s); err != nil || mode != "" {
@@ -987,9 +990,10 @@ func TestLayoutLegUsesTheDefaultWhenNoIntentIsRecorded(t *testing.T) {
// Startup recovery and the reconciler's mint read the same default: with
// no intent and a ready box both answer nested; with no intent and an
// armed box whose gate is not ready startup answers unreadable and the
-// mint answers nested (the wake gate waits, the tenant is never flat);
-// a box that cannot wake nested (no activator, below the floor) mints
-// flat unless a managed nested sibling proves the box has moved;
+// mint answers nested (the wake gate waits, the tenant is never flat),
+// with no gate armed too; a build below the floor, which cannot wake
+// nested, mints flat unless a managed nested sibling proves the box has
+// moved;
// CARLOS_LAYOUT_DEFAULT=flat answers none on a ready box.
func TestStartupAndMintReadTheDefault(t *testing.T) {
resetLayoutGlobals(t)
@@ -1021,12 +1025,14 @@ func TestStartupAndMintReadTheDefault(t *testing.T) {
if mode, err := mintLayoutIntent(ctx, s); err != nil || mode != release.LayoutModeNested {
t.Fatalf("mint, armed and not ready = %q %v, want nested", mode, err)
}
- // A box that can never wake nested mints flat: no activator armed, or a
- // release below the floor...
+ // No gate armed at all (a claim box, a box with no activator, or the
+ // window before the pass is built) is a gate that has not answered:
+ // still nested, never flat (hunt H2-M6). Only a release below the
+ // floor, which cannot wake nested, mints flat...
t.Setenv("CARLOS_DATA_DIR", "/data")
layoutDefaultGate.Store(nil)
- if mode, err := mintLayoutIntent(ctx, s); err != nil || mode != "" {
- t.Fatalf("mint, no activator = %q %v, want none", mode, err)
+ if mode, err := mintLayoutIntent(ctx, s); err != nil || mode != release.LayoutModeNested {
+ t.Fatalf("mint, no gate armed = %q %v, want nested", mode, err)
}
armDefaultGate(t, errors.New("not yet run"))
layoutBuild = func() string { return "v0.24.2" }
@@ -1044,10 +1050,10 @@ func TestStartupAndMintReadTheDefault(t *testing.T) {
return func() ([]registry.Route, error) { return rs, nil }
}
if mode, err := mintLayoutIntentWith(ctx, s, rows(flat, nestedUnflagged)); err != nil || mode != "" {
- t.Fatalf("mint, no activator, no managed nested row = %q %v, want none", mode, err)
+ t.Fatalf("mint, below the floor, no managed nested row = %q %v, want none", mode, err)
}
if mode, err := mintLayoutIntentWith(ctx, s, rows(flat, nestedManaged)); err != nil || mode != release.LayoutModeNested {
- t.Fatalf("mint, no activator, a managed nested row = %q %v, want nested", mode, err)
+ t.Fatalf("mint, below the floor, a managed nested row = %q %v, want nested", mode, err)
}
if _, err := mintLayoutIntentWith(ctx, s, func() ([]registry.Route, error) { return nil, errors.New("registry locked") }); err == nil {
t.Fatal("a registry that cannot be listed must defer the mint, not guess")
diff --git a/internal/host/hunt_H2_M6_test.go b/internal/host/hunt_H2_M6_test.go
new file mode 100644
index 000000000..e5dc4a194
--- /dev/null
+++ b/internal/host/hunt_H2_M6_test.go
@@ -0,0 +1,56 @@
+package host
+
+import (
+ "context"
+ "errors"
+ "testing"
+
+ "github.com/carlosframework/platform/internal/provision"
+ "github.com/carlosframework/platform/internal/registry"
+ "github.com/carlosframework/platform/internal/release"
+)
+
+// Hunt H2-M6 (verifier: fable). On a nested-default box with no recorded
+// intent, mintLayoutIntentWith (internal/host/layoutleg.go:718-749) asks
+// defaultLayoutIntent (layoutleg.go:127-150); while the nested gate has not
+// answered it returns "", and the mint falls back to nested only when the
+// registry already holds an activator-managed nested row. The secure
+// expectation asserted here: on a nested-default box a fresh record is
+// never minted flat while isolation is merely not-yet-probed; it is minted
+// nested (the wake still waits on the gate) or the mint is deferred. On
+// current code a box with zero nested rows returns LayoutModeNone (flat).
+func TestHunt_H2_M6_MintIsNotFlatWhileTheNestedGateIsUnanswered(t *testing.T) {
+ resetLayoutGlobals(t)
+ t.Setenv(layoutDefaultEnv, "nested")
+ t.Setenv("CARLOS_DATA_DIR", "/data")
+ prev := layoutBuild
+ t.Cleanup(func() { layoutBuild = prev })
+ layoutBuild = func() string { return "v0.25.0" }
+ ctx := context.Background()
+ s := release.NewDirStore(t.TempDir())
+ noRows := func() ([]registry.Route, error) { return nil, nil }
+
+ // The window the finding names: a pass is armed, the control service
+ // has not yet probed, so the gate answers "not ready".
+ armDefaultGate(t, errors.New("isolation not ready: the control service has not probed yet"))
+ mode, err := mintLayoutIntentWith(ctx, s, noRows)
+ if err == nil && mode != release.LayoutModeNested {
+ t.Errorf("gate unanswered, zero nested rows: mint = %q, want nested or a deferral; the record is minted flat (layoutleg.go:744-746)", mode)
+ }
+
+ // The same box with one managed nested row mints nested: the fallback
+ // the design relies on, which a box with no nested tenants lacks.
+ managed := registry.Route{Host: "a.example.com", Kind: "instance", Hibernate: true,
+ DBPath: provision.NestedDBPath("/data", "a.example.com"), Socket: provision.NestedSocket("a.example.com")}
+ if mode, err := mintLayoutIntentWith(ctx, s, func() ([]registry.Route, error) { return []registry.Route{managed}, nil }); err != nil || mode != release.LayoutModeNested {
+ t.Fatalf("gate unanswered, one managed nested row: mint = %q %v, want nested", mode, err)
+ }
+
+ // Before any pass is armed (a fresh process, before newLayoutPass): the
+ // gate is nil and the default answers "" too.
+ layoutDefaultGate.Store(nil)
+ mode, err = mintLayoutIntentWith(ctx, s, noRows)
+ if err == nil && mode != release.LayoutModeNested {
+ t.Errorf("no gate armed, zero nested rows: mint = %q, want nested or a deferral", mode)
+ }
+}
diff --git a/internal/host/layoutleg.go b/internal/host/layoutleg.go
index 909082b7d..8d5d666dc 100644
--- a/internal/host/layoutleg.go
+++ b/internal/host/layoutleg.go
@@ -825,18 +825,19 @@ func mintLayoutIntent(ctx context.Context, store release.Store) (string, error)
// mintLayoutIntentWith is mintLayoutIntent with the box's own rows in hand
// (nil: no registry to ask). With no intent recorded and the deployment's
-// default nested, the default's gate is asked. A box that could wake
-// nested (an activator armed, at or above the floor) whose gate has not
-// answered yet, or answers not ready, still mints nested: the first
-// reconcile after an agent restart runs before the control service's
-// first probe, and a box short of a mount is fixed, not downgraded. A new
-// tenant minted flat there would run with the agent's uid beside its
-// nested siblings, the exposure the default exists to end; minted nested
-// it waits, with the gate's reason in status, until the box is ready or
-// an operator records flat. The gate still guards every wake. A box that
-// can never wake nested (no activator, below the floor) mints flat, as
-// under CARLOS_LAYOUT_DEFAULT=flat, unless its registry already holds an
-// activator-managed row at the nested paths: the box has evidently moved.
+// default nested, the default's gate is asked. A box at or above the floor
+// whose gate has not answered, answers not ready, or is not armed at all
+// still mints nested: the first reconcile after an agent restart can run
+// before the control service's first probe, a claim box and a box with no
+// activator never arm the gate, and a box short of a mount is fixed, not
+// downgraded. A new tenant minted flat there would run with the agent's
+// uid beside its siblings (hunt H2-M6), the exposure the default exists to
+// end; minted nested it waits, with the gate's reason in status, until the
+// box is ready or an operator records flat. The gate still guards every
+// wake. Only a build below the floor, which cannot wake nested at all,
+// mints flat, as under CARLOS_LAYOUT_DEFAULT=flat, unless its registry
+// already holds an activator-managed row at the nested paths: the box has
+// evidently moved.
func mintLayoutIntentWith(ctx context.Context, store release.Store, routes func() ([]registry.Route, error)) (string, error) {
in, found, err := release.LoadLayoutIntent(ctx, store, BoxLabel())
switch {
@@ -848,7 +849,7 @@ func mintLayoutIntentWith(ctx context.Context, store release.Store, routes func(
return mode, nil
}
if def, invalid := layoutDefault(os.Getenv); def == release.LayoutModeNested && invalid == "" {
- if layoutDefaultGate.Load() != nil && !release.BelowFloor(layoutBuild(), release.LayoutFloor) {
+ if !release.BelowFloor(layoutBuild(), release.LayoutFloor) {
return release.LayoutModeNested, nil
}
if routes != nil {
diff --git a/internal/host/rootfs_advice_test.go b/internal/host/rootfs_advice_test.go
index 84d1e7c5c..911b4637b 100644
--- a/internal/host/rootfs_advice_test.go
+++ b/internal/host/rootfs_advice_test.go
@@ -371,7 +371,7 @@ func TestLayoutLegIsQuietAboutKeptRootfsRows(t *testing.T) {
}
// TestMintEvidenceIgnoresRootfsRows (task 5 fix round 1): with no intent,
-// the nested default and no activator armed, a binary row is minted
+// the nested default and a build below the floor, a binary row is minted
// flat unless a binary managed row already sits at the nested paths. A
// resident or an unknown runtime there is no such proof: rootfs rows are
// nested by construction. Not parallel: it sets env and the layout globals.
@@ -380,11 +380,11 @@ func TestMintEvidenceIgnoresRootfsRows(t *testing.T) {
t.Setenv(layoutDefaultEnv, "")
prev := layoutBuild
t.Cleanup(func() { layoutBuild = prev })
- layoutBuild = func() string { return "v0.25.0" }
+ layoutBuild = func() string { return "v0.24.2" }
t.Setenv("CARLOS_DATA_DIR", "/data")
- // No activator armed: the one case the mint still asks the registry
- // for a nested sibling (an armed box mints nested whatever the gate
- // says, TestStartupAndMintReadTheDefault).
+ // Below the floor: the one case the mint still asks the registry for
+ // a nested sibling (any other box mints nested whatever the gate says,
+ // TestStartupAndMintReadTheDefault).
layoutDefaultGate.Store(nil)
ctx := context.Background()
s := release.NewDirStore(t.TempDir())
@@ -403,7 +403,7 @@ func TestMintEvidenceIgnoresRootfsRows(t *testing.T) {
} {
rows := func() ([]registry.Route, error) { return []registry.Route{c.rt}, nil }
if mode, err := mintLayoutIntentWith(ctx, s, rows); err != nil || mode != c.want {
- t.Errorf("mint, no activator, only %s as evidence = %q, %v; want %q", name, mode, err, c.want)
+ t.Errorf("mint, below the floor, only %s as evidence = %q, %v; want %q", name, mode, err, c.want)
}
}
}