carlos / platform Public

root startup settles obsolete pending intents per intent (roster binding task 5b, N3)

With root's inventory actor fresh, a pending inventory-write or recovery
rebind intent stamped under the binding before a quarantine could never
replay: the startup recovery left it pending and
recoverRootInventoryStartup returned errRootMigrationBusy, aborting the
instance-control assembly and with it the stop and retirement service.

ClaimRootHTTP gains startupBinding, the box's binding in root's startup
roster read (the cleanup identity's), set by both constructions
(claimRootHTTP and the startup replay). recoverRootInventory compares
each pending intent's stamp (an inventory's, and its target's when it
carries one; a rebind's successor stamp) with it before any replay. A
different stamp is obsolete: it is settled through the existing
AbandonRootInventory (same host lock, exact intent bytes, installation
marked quarantined) with a predicate the binding difference satisfies,
and logged as "obsolete pending <inventory|rebind> intent: stamped <b0>
current <b1>". InventoryActor is never consulted for it, so a
quarantined box settles its own leftovers. Equal stamps replay as
before. Timer settlement (record to record) still runs first.
Cold-handover barriers (B3) are not pending installations; their
settlement is left to phase C and marked in the code.

openRootMigrationState wraps the root-owned migration directory open so
the startup function can run in a test.

Tests: N3 TestRootStartupSettlesObsoleteIntents, both settlement points
(recoverRootInventoryStartup with a completed migration, and the
restarted instance-control assembly's RecoverPending): a same-binding
interrupted intent replays and completes; an interrupted inventory write
and an interrupted rebind at B0, then quarantine and restart: both
settled and logged, root up, the B0 installation's stop answered;
readmission and restart: root up, the B0 installation refused at wake.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev e8e85119ee2a2797692a68ae3bc54da9e90adcdc parent 2dd412e
7 files changed, +309 −3
  • internal/host/claim_binding_assembly_linux_test.go +3 −0
  • internal/host/claim_binding_startup_linux_test.go +244 −0
  • internal/host/claimassembly.go +1 −1
  • internal/host/claimretire_transport.go +6 −0
  • internal/host/rootinventory.go +46 −0
  • internal/host/rootinventory_startup.go +2 −1
  • internal/host/rootmigration_startup.go +7 −1

CI failed — run details

diff --git a/internal/host/claim_binding_assembly_linux_test.go b/internal/host/claim_binding_assembly_linux_test.go
index 617fd7935..3c8f5fba7 100644
--- a/internal/host/claim_binding_assembly_linux_test.go
+++ b/internal/host/claim_binding_assembly_linux_test.go
@@ -75,6 +75,9 @@ type assemblyWorld struct {
// interrupt, while set, fails root's next record write after the
// numbered one (a crash after the intent is durable).
interrupt *int
+ // migrating, while set, makes root see a completed migration
+ // (migrationRequired).
+ migrating bool
}
// interruptibleDisk is a root authority directory whose writes can fail
diff --git a/internal/host/claim_binding_startup_linux_test.go b/internal/host/claim_binding_startup_linux_test.go
new file mode 100644
index 000000000..5c564d7be
--- /dev/null
+++ b/internal/host/claim_binding_startup_linux_test.go
@@ -0,0 +1,244 @@
+//go:build linux
+
+package host
+
+import (
+ "encoding/json"
+ "errors"
+ "strings"
+ "testing"
+ "time"
+
+ "github.com/carlosframework/platform/internal/hostbox"
+ "github.com/carlosframework/platform/internal/hostclaim"
+ "github.com/carlosframework/platform/internal/hostguard"
+ "github.com/carlosframework/platform/internal/hostops"
+ "github.com/carlosframework/platform/internal/provision"
+ "github.com/carlosframework/platform/internal/registry"
+ "github.com/carlosframework/platform/internal/rootparticipation"
+ "github.com/carlosframework/platform/internal/rootstate"
+)
+
+var errRootInterrupted = errors.New("root interrupted before its commit")
+
+func (w *assemblyWorld) pending() int {
+ w.t.Helper()
+ pending, err := w.assembly.Guard.Root.PendingInstallations()
+ if err != nil {
+ w.t.Fatal(err)
+ }
+ return len(pending)
+}
+
+// interruptedRegistration is the agent's state registration for rec through
+// root's commitRootInventory, with root dying after its intent is durable
+// and before it records the commit.
+func (w *assemblyWorld) interruptedRegistration(agent *bindingAgent, rec provision.Record, route registry.Route, actor hostbox.Actor) {
+ w.t.Helper()
+ before := w.pending()
+ *w.interrupt = 1
+ err := agent.registerState(rec.Host, route.DBPath, actor)
+ *w.interrupt = -1
+ if err == nil || w.pending() != before+1 {
+ w.t.Fatalf("registration was not interrupted after its intent: %v, pending %d", err, w.pending())
+ }
+}
+
+// interruptedRebind leaves a recovery rebind intent for rec's installation
+// stamped with stamp: the claim moves to a recovered successor stamp, and the
+// guard's RebindRootInventory (the write rebindRecoveryInventory makes)
+// persists the intent and is interrupted before its commit.
+func (w *assemblyWorld) interruptedRebind(rec provision.Record, stamp string) recoveryRebindRequest {
+ w.t.Helper()
+ ctx := w.t.Context()
+ o := w.claim(rec.Host)
+ prior := hostguard.Captured{Incarnation: o.Claim.Holder.Incarnation, Stamp: o.Claim.Holder.Stamp}
+ _, revision := w.inventory(rec.Host)
+ next, err := hostclaim.Update(ctx, w.store, o, func(c *hostclaim.Claim) error {
+ c.Holder.Stamp, c.Holder.Session, c.Holder.Generation, c.Holder.WriterBox = prior.Stamp+1, prior.Stamp+1, "recovered", "box-1"
+ c.Holder.Admissions = []hostclaim.AdmissionRecord{{Region: "ie", Session: prior.Stamp + 1, Box: "box-1", Generation: "recovered", Mode: "cold"}}
+ return nil
+ })
+ if err != nil {
+ w.t.Fatal(err)
+ }
+ h := next.Claim.Holder
+ _, recordETag, err := w.store.Get(ctx, h.Key)
+ if err != nil {
+ w.t.Fatal(err)
+ }
+ q := recoveryRebindRequest{V: 1, Prior: prior, Revision: revision, RecordKey: h.Key, RecordETag: recordETag, Next: hostbox.ColdSuccessor{Host: rec.Host, Incarnation: h.Incarnation, Stamp: h.Stamp, Session: h.Session, Generation: h.Generation, Box: "box-1", Enrollment: w.roster.row().Enrollment, DirectoryRevision: stamp, ETag: next.ETag}}
+ raw, err := json.Marshal(recoveryRebindIntent{Recovery: &q})
+ if err != nil {
+ w.t.Fatal(err)
+ }
+ installation := hostguard.RootInstallation{Host: rec.Host, Incarnation: h.Incarnation, Stamp: h.Stamp, Account: h.Account, App: h.App, Record: h.Key, Box: "box-1", Enrollment: q.Next.Enrollment, Migration: 1, InventoryRevision: 1}
+ before := w.pending()
+ err = w.assembly.Guard.RebindRootInventory(ctx, prior, revision, installation, raw, func(*hostclaim.Claim) error { return nil }, func() error { return errRootInterrupted })
+ if !errors.Is(err, errRootInterrupted) || w.pending() != before+1 {
+ w.t.Fatalf("rebind intent: %v, pending %d", err, w.pending())
+ }
+ return q
+}
+
+// migrationRequired gives root a completed Plan 14 migration for actor, seen
+// while startupRecovery runs, so the startup inventory recovery does its work
+// rather than returning early. The participation ledger and the migration
+// record are root-owned directories on a box; here they are test directories.
+func (w *assemblyWorld) migrationRequired(actor hostbox.Actor) {
+ w.t.Helper()
+ census := rootparticipation.Census{Schema: 1, Box: actor.Box, Enrollment: actor.Enrollment, Migration: 1, Revision: 1, LaunchRevision: 1, Complete: true}
+ participation := &rollbackDisk{dir: w.t.TempDir()}
+ raw, _ := json.Marshal(census)
+ if err := participation.Write("census.json", raw); err != nil {
+ w.t.Fatal(err)
+ }
+ now := time.Now().UTC()
+ record := rootMigrationRecord{Schema: 1, Identity: rootMigrationIdentity{Deployment: actor.ControlBucket, Box: actor.Box, Enrollment: actor.Enrollment, Generation: 1}, Phase: "complete", Snapshot: rootMigrationSnapshot{Complete: true, DirectoryRevision: 1, Exclusion: "exclusion", Items: []rootMigrationItem{},
+ Report: hostops.CensusReport{Box: actor.Box, Enrollment: actor.Enrollment, BootID: "boot", Reservation: "migration", DirectoryRevision: 1, CapturedAt: now, Complete: true, Installations: []hostops.CensusInstallation{}, Seeds: &hostops.CensusSeeds{Journaled: []string{}, Gated: []string{}}}}}
+ state := &rollbackDisk{dir: w.t.TempDir()}
+ raw, _ = json.Marshal(record)
+ if err := state.Write("migration.json", raw); err != nil {
+ w.t.Fatal(err)
+ }
+ original, originalState := openRootMigrationParticipation, openRootMigrationState
+ w.t.Cleanup(func() { openRootMigrationParticipation, openRootMigrationState = original, originalState })
+ openRootMigrationParticipation = func() (rootparticipation.Ledger, bool, error) {
+ if !w.migrating {
+ return rootparticipation.Ledger{}, false, nil
+ }
+ return rootparticipation.Ledger{State: participation}, true, nil
+ }
+ openRootMigrationState = func() (rootstate.Store, error) { return state, nil }
+}
+
+// startupRecovery is OpenProductionClaimAssembly's startup inventory
+// recovery (rootinventory_startup.go) as a restarted root runs it: its startup
+// actor is actorForConstruction's (the cleanup identity's read). The
+// assembly's root migration floor verification that follows it needs the
+// box's installed floor binaries and is not run here.
+func (w *assemblyWorld) startupRecovery() error {
+ w.t.Helper()
+ ctx := w.t.Context()
+ owners, err := w.owners.OpenClaimOwners(ctx, w.store, w.r)
+ if err != nil {
+ w.t.Fatal(err)
+ }
+ actor, err := owners.actorForConstruction(ctx, w.r.Mode)
+ if err != nil {
+ w.t.Fatal(err)
+ }
+ if err := w.assembly.Close(ctx); err != nil {
+ w.t.Fatal(err)
+ }
+ launches, err := openClaimRootJournal()
+ if err != nil {
+ w.t.Fatal(err)
+ }
+ defer launches.Close()
+ journals, err := hostbox.NewJournalService(launches)
+ if err != nil {
+ w.t.Fatal(err)
+ }
+ w.migrating = true
+ defer func() { w.migrating = false }()
+ return recoverRootInventoryStartup(ctx, w.store, w.r, owners, actor, journals, launches)
+}
+
+// N3 (roster binding task 5b): an interrupted inventory write and an
+// interrupted recovery rebind are left pending at B0; the box is quarantined
+// and root restarts. Each intent is settled as abandoned and logged, root
+// comes up (never errRootMigrationBusy), and its stop service answers a stop
+// of the B0 installation. After readmission and another restart root is still
+// up and the B0 installation is refused at wake. The control: an interrupted
+// intent whose binding did not change replays and completes.
+//
+// Two restarts settle pending intents in production: the startup inventory
+// recovery inside OpenProductionClaimAssembly, whose errRootMigrationBusy
+// aborts the assembly, and the service's RecoverPending. "startup" settles
+// through the first and then builds the assembly; "service" restarts the
+// assembly and settles through the root handler's RecoverPending.
+func TestRootStartupSettlesObsoleteIntents(t *testing.T) {
+ for _, path := range []string{"startup", "service"} {
+ t.Run(path, func(t *testing.T) {
+ ctx := t.Context()
+ w := newAssemblyWorld(t)
+ b0 := w.fresh()
+ if path == "startup" {
+ w.migrationRequired(b0)
+ }
+ w.mustStart()
+ agent := w.agent(b0)
+ recA, routeA := w.newHost("a")
+ recD, routeD := w.newHost("d")
+ recE, routeE := w.newHost("e")
+ for _, h := range []struct {
+ rec provision.Record
+ route registry.Route
+ }{{recA, routeA}, {recD, routeD}, {recE, routeE}} {
+ if err := agent.install(h.rec, h.route); err != nil {
+ t.Fatal(err)
+ }
+ }
+ recover := func(startup bool) error {
+ if startup {
+ if err := w.startupRecovery(); err != nil {
+ return err
+ }
+ return w.start()
+ }
+ if err := w.restart(); err != nil {
+ return err
+ }
+ return w.root.RecoverPending(ctx)
+ }
+
+ // Control: same binding, interrupted, replays and completes. (The
+ // startup function replays through root's creation history, a
+ // root-owned directory; the control runs through the service.)
+ w.roster.holdChurn()
+ _, before := w.inventory(recE.Host)
+ w.interruptedRegistration(agent, recE, routeE, w.fresh())
+ if err := recover(false); err != nil {
+ t.Fatal("restart with a same-binding intent:", err)
+ }
+ if _, after := w.inventory(recE.Host); w.pending() != 0 || after != before+1 {
+ t.Fatalf("same-binding intent: pending %d, inventory revision %d -> %d", w.pending(), before, after)
+ }
+
+ // Obsolete intents at B0, then quarantine and restart.
+ agent = w.agent(b0)
+ w.interruptedRegistration(agent, recA, routeA, w.fresh())
+ w.interruptedRebind(recD, b0.Binding)
+ w.roster.quarantine("loss_1")
+ logs := captureLog(t)
+ if err := recover(path == "startup"); err != nil {
+ t.Fatal("quarantined restart with obsolete intents:", err)
+ }
+ if w.pending() != 0 {
+ t.Fatalf("obsolete intents left pending: %d", w.pending())
+ }
+ for _, kind := range []string{"inventory", "rebind"} {
+ if !strings.Contains(logs(), "obsolete pending "+kind+" intent: stamped "+b0.Binding) {
+ t.Fatalf("no settlement log for the %s intent: %s", kind, logs())
+ }
+ }
+ if _, err := w.root.InventoryActor(ctx); err == nil {
+ t.Fatal("quarantined root admitted new work")
+ }
+ if _, err := w.noProcessStop(recA.Host, b0.Binding, w.roster.read().Roster.Revision); err != nil {
+ t.Fatal("stop service after settlement:", err)
+ }
+
+ // Readmission and another restart: up, the B0 installation refused.
+ w.roster.readmit()
+ if err := recover(path == "startup"); err != nil {
+ t.Fatal("readmitted restart:", err)
+ }
+ b1 := w.fresh()
+ if err := w.agent(b1).registerState(recE.Host, routeE.DBPath, b1); !errors.Is(err, hostbox.ErrTypedInventory) {
+ t.Fatalf("the B0 installation at wake after readmission: %v", err)
+ }
+ })
+ }
+}
diff --git a/internal/host/claimassembly.go b/internal/host/claimassembly.go
index d51864712..f0f4b20d1 100644
--- a/internal/host/claimassembly.go
+++ b/internal/host/claimassembly.go
@@ -410,7 +410,7 @@ func (assembly *ClaimAssembly) claimRootHTTP(actor hostbox.Actor, stop ClaimStop
reconcile := *assembly.Reconcile
reconcile.Box, reconcile.Enrollment = actor.Box, actor.Enrollment
reconcile.Census = &hostbox.EmptyInstallationCensus{Inventory: assembly.Reconcile.Inventory, Registry: assembly.Reconcile.Registry, Launches: assembly.Launches, Box: actor.Box, Enrollment: actor.Enrollment, DirectoryRevision: actor.Binding, Roots: assembly.ManagedRoots, SharedPaths: assembly.SharedPaths}
- return ClaimRootHTTP{inventoryIdentity: rootstate.ObjectIdentity, InventoryActor: assembly.Identity.Verify, Journals: assembly.Journals, RequireNewWork: func(ctx context.Context) error { _, err := assembly.Identity.Verify(ctx); return err }, Launches: assembly.Launches, Stop: stop, Reconcile: reconcile, Roots: assembly.ManagedRoots}
+ return ClaimRootHTTP{inventoryIdentity: rootstate.ObjectIdentity, InventoryActor: assembly.Identity.Verify, startupBinding: actor.Binding, Journals: assembly.Journals, RequireNewWork: func(ctx context.Context) error { _, err := assembly.Identity.Verify(ctx); return err }, Launches: assembly.Launches, Stop: stop, Reconcile: reconcile, Roots: assembly.ManagedRoots}
}
func claimMoveLocalAuthorizer(check func(context.Context) error, owner func(context.Context, hostclaim.Observed, hostclaim.Obligation) error) ClaimLocalParkAuthorizer {
diff --git a/internal/host/claimretire_transport.go b/internal/host/claimretire_transport.go
index 44c6dcb20..b2af45ff1 100644
--- a/internal/host/claimretire_transport.go
+++ b/internal/host/claimretire_transport.go
@@ -23,6 +23,11 @@ import (
"github.com/carlosframework/platform/internal/release"
)
+// ClaimRootHTTP is instance-control's root claim handler. startupBinding is
+// this box's binding in root's startup roster read (the cleanup identity's):
+// a pending inventory or rebind intent stamped with another binding is
+// obsolete and is settled, never replayed (roster binding N3). Empty skips
+// that check.
type ClaimRootHTTP struct {
servingParks *servingParkRuntime
inventoryIdentity func(*os.File) (rootstate.FileIdentity, error)
@@ -37,6 +42,7 @@ type ClaimRootHTTP struct {
Stop ClaimStopHTTP
Reconcile hostbox.ReconcileAdapter
Roots map[string]string
+ startupBinding string
}
func (h ClaimRootHTTP) Start(ctx context.Context) {
diff --git a/internal/host/rootinventory.go b/internal/host/rootinventory.go
index 209810034..3b3822020 100644
--- a/internal/host/rootinventory.go
+++ b/internal/host/rootinventory.go
@@ -359,6 +359,44 @@ func (h ClaimRootHTTP) verifyNewInventoryIdentities(prior, next hostbox.StopInve
return nil
}
+// obsoleteIntent reports whether a pending intent was stamped under a binding
+// other than the startup binding: an inventory's stamp (and its target's, when
+// it carries one) or a rebind's successor stamp. Replaying it would compare
+// the old binding with today's authority; it is settled instead (N3).
+func (h ClaimRootHTTP) obsoleteIntent(stamp string, more ...string) bool {
+ if h.startupBinding == "" {
+ return false
+ }
+ if stamp != h.startupBinding {
+ return true
+ }
+ for _, s := range more {
+ if s != "" && s != h.startupBinding {
+ return true
+ }
+ }
+ return false
+}
+
+// settleObsoleteIntent abandons an obsolete pending intent through the
+// guard's existing abandonment (same host lock, exact intent bytes, the
+// installation marked quarantined), whatever the claim says now: the binding
+// difference alone supersedes it. Its installation stays refused for new
+// work, because every fresh comparison needs the new binding. A settlement
+// failure is logged and leaves the intent pending, as any recovery failure
+// does. It never consults InventoryActor, so a quarantined box settles its
+// own leftovers.
+//
+// Cold-handover barriers (roster binding B3) are not pending installations
+// and are not settled here; their own fenced settlement is phase C's.
+func (h ClaimRootHTTP) settleObsoleteIntent(ctx context.Context, host string, raw []byte, kind, stamped string) {
+ err := h.Stop.Coordinator.Guard.AbandonRootInventory(ctx, host, raw, func(*hostclaim.Claim) bool { return true })
+ log.Printf("instance-control: %s: obsolete pending %s intent: stamped %s current %s", host, kind, stamped, h.startupBinding)
+ if err != nil {
+ log.Printf("instance-control: %s: obsolete pending %s intent not settled: %v", host, kind, err)
+ }
+}
+
func (h ClaimRootHTTP) recoverRootInventory(ctx context.Context) error {
authority := h.Stop.Coordinator.Guard.Root
if authority == nil {
@@ -374,6 +412,10 @@ func (h ClaimRootHTTP) recoverRootInventory(ctx context.Context) error {
return err
}
if recovery.Recovery != nil {
+ if next := recovery.Recovery.Next; h.obsoleteIntent(next.DirectoryRevision) {
+ h.settleObsoleteIntent(ctx, next.Host, raw, "rebind", next.DirectoryRevision)
+ continue
+ }
if err = h.rebindRecoveryInventory(ctx, *recovery.Recovery); err != nil {
n := recovery.Recovery.Next
if errors.Is(err, hostbox.ErrChanged) {
@@ -395,6 +437,10 @@ func (h ClaimRootHTTP) recoverRootInventory(ctx context.Context) error {
} else if settleErr != nil {
return settleErr
}
+ if h.obsoleteIntent(q.Inventory.DirectoryRevision, q.Target.DirectoryRevision) {
+ h.settleObsoleteIntent(ctx, q.Target.Host, raw, "inventory", q.Inventory.DirectoryRevision)
+ continue
+ }
if _, err = h.withRootInventoryHistory(ctx, q, true); err != nil {
if errors.Is(err, hostbox.ErrChanged) || errors.Is(err, hostbox.ErrJournalUncertain) {
err = errors.Join(err, h.Stop.Coordinator.Guard.AbandonRootInventory(ctx, q.Target.Host, raw, func(c *hostclaim.Claim) bool {
diff --git a/internal/host/rootinventory_startup.go b/internal/host/rootinventory_startup.go
index 99f8f8698..5167d6575 100644
--- a/internal/host/rootinventory_startup.go
+++ b/internal/host/rootinventory_startup.go
@@ -21,7 +21,7 @@ func recoverRootInventoryStartup(ctx context.Context, store release.Store, r Cla
if err != nil {
return err
}
- state, err := rootstate.Open(rootMigrationDir, false, false)
+ state, err := openRootMigrationState()
if err != nil {
return err
}
@@ -45,6 +45,7 @@ func recoverRootInventoryStartup(ctx context.Context, store release.Store, r Cla
h := ClaimRootHTTP{history: productionCreationHistory, inventoryIdentity: rootstate.ObjectIdentity, Journals: journals, Launches: launches, Roots: roots,
// Fresh authority (R2): the startup actor above pins only the census.
InventoryActor: owners.Identity.Verify,
+ startupBinding: actor.Binding,
Reconcile: hostbox.ReconcileAdapter{Registry: r.Registry, Inventory: journals.Inventory, Census: census, Box: actor.Box, Enrollment: actor.Enrollment},
Stop: ClaimStopHTTP{Coordinator: ClaimStopCoordinator{Guard: guard, Evidence: store}}}
if err := h.recoverRootInventory(ctx); err != nil {
diff --git a/internal/host/rootmigration_startup.go b/internal/host/rootmigration_startup.go
index 4f5413261..16ddbb0c5 100644
--- a/internal/host/rootmigration_startup.go
+++ b/internal/host/rootmigration_startup.go
@@ -14,6 +14,12 @@ const rootMigrationDir = "/var/lib/carlos-claims/authority/migration"
var openRootMigrationParticipation = rootparticipation.OpenForUpdate
+// openRootMigrationState opens the root-owned migration record directory
+// read-only. A variable so tests can stand in for the root-owned directory.
+var openRootMigrationState = func() (rootstate.Store, error) {
+ return rootstate.Open(rootMigrationDir, false, false)
+}
+
func verifyRootMigrationRetained(ctx context.Context, root *hostguard.RootAuthority, snapshot rootMigrationSnapshot) error {
views, err := root.MigrationInstallations(ctx)
if err != nil {
@@ -83,7 +89,7 @@ func verifyRootMigrationStartup(ctx context.Context, id rootFloorIdentity, inven
if err != nil {
return err
}
- state, err := rootstate.Open(rootMigrationDir, false, false)
+ state, err := openRootMigrationState()
if err != nil {
return err
}