serving reboot preparation survives roster writes (roster binding task 3b, N2)
The reboot preparation persists the bound actor (Revision cleared), so the persisted record, its replay comparison and the commit's comparison (prepare :136, commit :30 and :45) no longer carry the roster write counter. The immediate reread uses SameBinding, and the persisted actor's sanity check requires a binding instead of a non-zero revision. N2 TestServingRebootPreparationSurvivesHoldChurn: root's inventory actor is the production identity over a signed roster and every read follows a real hold Reserve and ReleaseFinishedHold. Prepare then commit passes, also across a root restart; a quarantine refuses, and after readmission the commit is refused (ErrTypedInventory, from the installation's stamp, before the preparation comparison).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 files changed,
+115
−4
internal/host/claimservingreboot_binding_linux_test.go+107 −0internal/host/claimservingreboot_prepare_linux.go+8 −4
diff --git a/internal/host/claimservingreboot_binding_linux_test.go b/internal/host/claimservingreboot_binding_linux_test.go| new file mode 100644 |
| index 000000000..090842fe9 |
| --- /dev/null |
| +++ b/internal/host/claimservingreboot_binding_linux_test.go |
| @@ -0,0 +1,107 @@ |
| +//go:build linux |
| + |
| +package host |
| + |
| +import ( |
| + "context" |
| + "errors" |
| + "testing" |
| + |
| + "github.com/carlosframework/platform/internal/hostactors" |
| + "github.com/carlosframework/platform/internal/hostbox" |
| +) |
| + |
| +// N2 (roster binding, task 3b). A serving park's reboot preparation persists |
| +// the actor it was prepared under and its commit compares that record with a |
| +// fresh one. Root's inventory actor here is the production identity over a |
| +// signed roster, and every read of it follows another console create's hold |
| +// churn (a real Reserve and ReleaseFinishedHold), so the preparation's reread, |
| +// its persisted copy and the commit all see a different roster revision. They |
| +// still match: the preparation stores the bound actor. A quarantine and a |
| +// readmission between prepare and commit change the binding and are refused |
| +// (the quarantine by Verify, the readmission by the installation's stamp). |
| +func TestServingRebootPreparationSurvivesHoldChurn(t *testing.T) { |
| + for _, step := range []string{"hold", "hold-root-restart", "quarantine-readmit"} { |
| + t.Run(step, func(t *testing.T) { |
| + ctx := t.Context() |
| + roster := newBindingRosterFixture(t, "box-1", "ie") |
| + identity := roster.identity() |
| + actor, err := identity.Verify(ctx) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if !hostactors.ValidBinding(actor.Binding) || actor.Binding != roster.binding() { |
| + t.Fatalf("production actor binding %q", actor.Binding) |
| + } |
| + f, r := servingRebootPreparationFixtureFor(t, "parked", actor) |
| + churning := func(identity hostbox.IdentityProvider) func(context.Context) (hostbox.Actor, error) { |
| + return func(ctx context.Context) (hostbox.Actor, error) { |
| + roster.holdChurn() |
| + return identity.Verify(ctx) |
| + } |
| + } |
| + f.p.root.InventoryActor = churning(identity) |
| + id := r.Authorization.ID |
| + before := roster.read().Roster.Revision |
| + if err := f.p.prepareServingReboot(ctx, id); err != nil { |
| + t.Fatal("prepare under hold churn:", err) |
| + } |
| + if after := roster.read().Roster.Revision; after < before+4 { |
| + t.Fatalf("prepare read the actor without churn: revision %d -> %d", before, after) |
| + } |
| + body, err := f.disk.Read(servingRebootPreparationName(id, servingOtherBoot)) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + var prep servingParkRebootPreparation |
| + if servingParkDecode(body, &prep) != nil || prep.Active == nil || prep.Active.Actor != actor.Bound() || prep.Active.Actor.Revision != 0 { |
| + t.Fatalf("persisted preparation actor: %+v", prep.Active) |
| + } |
| + roster.holdChurn() |
| + p := f.p |
| + switch step { |
| + case "hold-root-restart": |
| + // A restarted root: a new ledger and handler over the same |
| + // private state, with a newly built identity. |
| + ledger := *f.p.ledger |
| + root := f.p.root |
| + root.InventoryActor = churning(roster.identity()) |
| + p = &servingParkRoot{root: root, ledger: &ledger, empty: f.p.empty} |
| + case "quarantine-readmit": |
| + roster.quarantine("loss_1") |
| + if err := p.commitServingReboot(ctx, id); err == nil { |
| + t.Fatal("commit accepted while quarantined") |
| + } |
| + roster.readmit() |
| + if b := roster.binding(); b == actor.Binding { |
| + t.Fatal("readmission kept the binding") |
| + } |
| + } |
| + err = p.commitServingReboot(ctx, id) |
| + if step == "quarantine-readmit" { |
| + // The installation's stamp is the old binding, so the fresh |
| + // installed-state check (claimservingparksource_linux.go, the |
| + // inventory against actor.Binding) refuses before the persisted |
| + // preparation is compared: ErrTypedInventory, not ErrChanged. |
| + if !errors.Is(err, hostbox.ErrTypedInventory) { |
| + t.Fatalf("commit after readmission: %v, want ErrTypedInventory", err) |
| + } |
| + if _, err := f.disk.Read("current-namespace.json"); err == nil { |
| + t.Fatal("refused commit bound the namespace") |
| + } |
| + return |
| + } |
| + if err != nil { |
| + t.Fatal("commit after hold churn:", err) |
| + } |
| + fs := p.ledger.fs.(*servingParkFS) |
| + if err := fs.recoverRecordedNamespace(ctx); err != nil { |
| + t.Fatal(err) |
| + } |
| + current, err := p.ledger.read(id) |
| + if err != nil || current.Source.BootID != servingOtherBoot { |
| + t.Fatal("committed authority", err) |
| + } |
| + }) |
| + } |
| +} |
diff --git a/internal/host/claimservingreboot_prepare_linux.go b/internal/host/claimservingreboot_prepare_linux.go| index 8c11fe253..59cfd6ab3 100644 |
| --- a/internal/host/claimservingreboot_prepare_linux.go |
| +++ b/internal/host/claimservingreboot_prepare_linux.go |
| @@ -26,6 +26,10 @@ type servingParkRebootPreparation struct { |
| type servingParkRebootAuthority struct { |
| ClaimETag string |
| + // Actor is the bound actor (hostbox.Actor.Bound): the roster write counter |
| + // is cleared, so a preparation persisted before a hold or any other |
| + // unrelated roster write still equals one observed after it. Its Binding |
| + // still moves on a quarantine, readmission or re-enrolment. |
| Actor hostbox.Actor |
| Directory servingArtifactDirectory |
| Tags uint64 |
| @@ -78,7 +82,7 @@ func (p *servingParkRoot) prepareOrCommitServingReboot(ctx context.Context, id s |
| if err := p.validateServingRebootAuthority(ctx, o, view, actor, r); err != nil { |
| return err |
| } |
| - if err := prepare(&servingParkRebootAuthority{ClaimETag: o.ETag, Actor: actor, Directory: dir, Tags: tags}); err != nil { |
| + if err := prepare(&servingParkRebootAuthority{ClaimETag: o.ETag, Actor: actor.Bound(), Directory: dir, Tags: tags}); err != nil { |
| return err |
| } |
| fresh, err := p.root.Stop.Coordinator.Guard.Claims.Read(ctx, current.Host) |
| @@ -92,7 +96,7 @@ func (p *servingParkRoot) prepareOrCommitServingReboot(ctx context.Context, id s |
| if err != nil { |
| return err |
| } |
| - if nextActor != actor { |
| + if !hostbox.SameBinding(nextActor, actor) { |
| return hostbox.ErrChanged |
| } |
| if err := p.root.RequireNewWork(ctx); err != nil { |
| @@ -105,7 +109,7 @@ func (p *servingParkRoot) prepareOrCommitServingReboot(ctx context.Context, id s |
| return err |
| } |
| if commit { |
| - return copyLedger.commitRebootLocked(ctx, r, &servingParkRebootAuthority{ClaimETag: o.ETag, Actor: actor, Directory: dir, Tags: tags}) |
| + return copyLedger.commitRebootLocked(ctx, r, &servingParkRebootAuthority{ClaimETag: o.ETag, Actor: actor.Bound(), Directory: dir, Tags: tags}) |
| } |
| return nil |
| }) |
| @@ -184,7 +188,7 @@ func (l *servingParkLedger) observeRebootPreparation(ctx context.Context, saved |
| if active != nil { |
| a := r.activeAuthorization() |
| actor := active.Actor |
| - if active.ClaimETag == "" || !actor.Eligible || actor.Quarantined || actor.Enrollment == "" || actor.Revision == 0 || actor.Box != a.Successor.Box || actor.Region != a.Successor.Region || active.Directory != observation.Source || (active.Tags != a.TagsFrom && active.Tags != a.Successor.Stamp) { |
| + if active.ClaimETag == "" || !actor.Eligible || actor.Quarantined || actor.Enrollment == "" || actor.Binding == "" || actor.Box != a.Successor.Box || actor.Region != a.Successor.Region || active.Directory != observation.Source || (active.Tags != a.TagsFrom && active.Tags != a.Successor.Stamp) { |
| return zero, hostbox.ErrChanged |
| } |
| } |