carlos / platform Public

Offline move door: its claim, admission and backfill checks are console-local

offlineClaimEvidence reads control/hosts/<host>.json,
apps/<acct>/<app>/admission.json and control/hosts-backfill.json itself
instead of through hostclaim and hostops. Tests hold the keys to the
claim packages' and the backfill plan type to hostops.BackfillPlan field
for field, and classify every plan as hostops.CheckCreateFreeze does.

One edge differs: a claim object that is present but does not decode and
validate as a claim was a 502, and is now refused as present (409).
Nothing is written either way. Every failed read is still a 502.

The six hostops sentinel comparisons on shared domain, scan and system
paths stay: they never match claims off, but claims-on tests pin two of
them, so they go with R6.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev d4417afbefd04c79e11f81214f2cb49b3eb68f13 parent 1491703
4 files changed, +256 −13
  • docs/superpowers/plans/2026-10-25-claims-cleanup-r1.md +2 −2
  • internal/console/apiinstancemove_offline.go +13 −11
  • internal/console/apiinstancemove_offline_absence.go +82 −0
  • internal/console/apiinstancemove_offline_absence_test.go +159 −0
diff --git a/docs/superpowers/plans/2026-10-25-claims-cleanup-r1.md b/docs/superpowers/plans/2026-10-25-claims-cleanup-r1.md
index 1b3f70a7c..309d912e6 100644
--- a/docs/superpowers/plans/2026-10-25-claims-cleanup-r1.md
+++ b/docs/superpowers/plans/2026-10-25-claims-cleanup-r1.md
@@ -52,13 +52,13 @@
- [ ] `offlineClaimEvidence` reads `control/hosts/<host>.json`, `apps/<acct>/<app>/admission.json` and `control/hosts-backfill.json` itself (`offlineHostClaimKey`, `offlineAdmissionKey`, `offlineBackfillKey`, `offlineBackfillPlan` mirroring `hostops.BackfillPlan`).
- [ ] Tests: keys equal hostops'/hostclaim's; a signed `hostops.BackfillPlan` reads locally; malformed claim present gives 409; unreadable gives 502.
-- [ ] Delete the `hostops.ErrPending`/`ErrContract` comparisons at `domainattach.go` (record delete, claim delete), `apidomains.go` (attach, detach), `apisystem.go`, `scandeliver.go`: each error source is `domains`/`provision`/`objstore`/`appconfig` on an ungated store when `HostClaim` is false.
+- [ ] ~~Delete the `hostops.ErrPending`/`ErrContract` comparisons at `domainattach.go`, `apidomains.go`, `apisystem.go`, `scandeliver.go`.~~ Not done: each never matches claims off (the sources are `domains`/`provision`/`objstore`/`appconfig` on an ungated store), but each does match claims on, and `TestClaimScanCallbackContentionAndSettlement` and `TestClaimScanMasterRotationSkipsBusyApp` pin two of them. Deleting them changes claims-on behaviour, so they go with R6, when their sources do.
- [ ] Run console `-run 'Offline|Domain|Scan|System'`; commit.
### Task 5: RequestLimit, GroupBoxReference, the unit control group
- [ ] `host.claimsShutdownLimit = 120 * time.Second` replaces `hostbox.RequestLimit` in `agent.go`; `host.groupBoxReference` replaces `hostactors.GroupBoxReference` in `boxreference.go`; golden tests pin both against the claim twins.
-- [ ] Rename `instancectl.ClaimUnitControlGroup` to `RunUnitControlGroup` (all callers).
+- [ ] `instancectl.RunUnitControlGroup` in `names.go`; the offline round calls it; `ClaimUnitControlGroup` stays as a delegate for its ~25 claim callers (renaming them all would edit census authority units for no live gain). Golden test pins the path.
- [ ] Run host `-run 'BoxReference|Joining|Group'`, instancectl, activator `-run RoleLaunch`; commit.
### Task 6: Census, builds, push
diff --git a/internal/console/apiinstancemove_offline.go b/internal/console/apiinstancemove_offline.go
index 103ac3927..ac8b7ba3f 100644
--- a/internal/console/apiinstancemove_offline.go
+++ b/internal/console/apiinstancemove_offline.go
@@ -17,8 +17,6 @@ import (
"time"
"github.com/carlosframework/platform/internal/domains"
- "github.com/carlosframework/platform/internal/hostclaim"
- "github.com/carlosframework/platform/internal/hostops"
"github.com/carlosframework/platform/internal/moves"
"github.com/carlosframework/platform/internal/provision"
"github.com/carlosframework/platform/internal/release"
@@ -438,13 +436,17 @@ func (s *Server) offlineClaimEvidence(ctx context.Context, d offlineDoor) *offli
if d.rec.Acquisition != "" {
return has
}
- obs, err := hostclaim.Read(ctx, s.cfg.Releases, d.host)
- if err != nil {
- log.Printf("console: offline move %s: claim read: %v", d.host, err)
+ // Any claim object at all refuses; a read that fails is never absence.
+ claimKey, ok := offlineHostClaimKey(d.host)
+ if !ok {
+ log.Printf("console: offline move %s: claim read: invalid host", d.host)
return unreadable
}
- if !obs.Absent {
+ if _, _, err := s.cfg.Releases.Get(ctx, claimKey); err == nil {
return has
+ } else if !errors.Is(err, os.ErrNotExist) {
+ log.Printf("console: offline move %s: claim read: %v", d.host, err)
+ return unreadable
}
if c, err := domains.GetClaim(ctx, s.cfg.Releases, d.host); err == nil && c.Acquisition != "" {
return has
@@ -452,9 +454,9 @@ func (s *Server) offlineClaimEvidence(ctx context.Context, d offlineDoor) *offli
log.Printf("console: offline move %s: domains claim read: %v", d.host, err)
return unreadable
}
- key, err := hostops.AdmissionKey(d.acct.Sqid, d.app)
- if err != nil {
- log.Printf("console: offline move %s: admission key: %v", d.host, err)
+ key, ok := offlineAdmissionKey(d.acct.Sqid, d.app)
+ if !ok {
+ log.Printf("console: offline move %s: admission key: invalid account or app", d.host)
return unreadable
}
if _, _, err := s.cfg.Releases.Get(ctx, key); err == nil {
@@ -465,9 +467,9 @@ func (s *Server) offlineClaimEvidence(ctx context.Context, d offlineDoor) *offli
}
// A plan at done is allowed; one that has begun, or that cannot be
// verified, is not.
- switch err := hostops.CheckCreateFreeze(ctx, s.cfg.Releases, s.cfg.ReleasePub); {
+ switch err := offlineBackfillFreeze(ctx, s.cfg.Releases, s.cfg.ReleasePub); {
case err == nil:
- case errors.Is(err, hostops.ErrPending), errors.Is(err, hostops.ErrIdentity):
+ case errors.Is(err, errOfflineBackfillBegun):
return &offlineRefusal{status: http.StatusConflict, msg: "offline moves are not available while host claims or Phase 1 moves are on"}
default:
log.Printf("console: offline move %s: backfill plan read: %v", d.host, err)
diff --git a/internal/console/apiinstancemove_offline_absence.go b/internal/console/apiinstancemove_offline_absence.go
new file mode 100644
index 000000000..05bd9128b
--- /dev/null
+++ b/internal/console/apiinstancemove_offline_absence.go
@@ -0,0 +1,82 @@
+package console
+
+import (
+ "context"
+ "crypto/ed25519"
+ "errors"
+ "os"
+ "time"
+
+ "github.com/carlosframework/platform/internal/controlname"
+ "github.com/carlosframework/platform/internal/release"
+)
+
+// The offline move door's absence checks (MV-O20, MV-O29), read here and
+// not through the host claim packages since claims cleanup R1: host claims
+// are off everywhere and their packages are going, but a deployment that
+// ever wrote one of these objects must still be refused. Each key is the
+// claim packages' own (TestOfflineAbsenceKeysAreTheClaimKeys).
+
+// offlineBackfillKey is the host-claim backfill plan (hostops.BackfillKey).
+const offlineBackfillKey = "control/hosts-backfill.json"
+
+// offlineHostClaimKey is a host's claim object (hostclaim.Key); false for a
+// host that is not host-shaped.
+func offlineHostClaimKey(host string) (string, bool) {
+ if !controlname.ValidHostShape(host) {
+ return "", false
+ }
+ return "control/hosts/" + host + ".json", true
+}
+
+// offlineAdmissionKey is an app's claim admission (hostops.AdmissionKey);
+// false for an account or app that is not well formed.
+func offlineAdmissionKey(account, app string) (string, bool) {
+ if !controlname.ValidAccount(account) || !controlname.ValidApp(app) {
+ return "", false
+ }
+ return "apps/" + account + "/" + app + "/admission.json", true
+}
+
+// offlineBackfillPlan and offlineBackfillHost are hostops.BackfillPlan and
+// hostops.BackfillHost field for field: the plan is a signed root envelope
+// whose payload must re-encode byte for byte, so the shapes cannot differ
+// (TestOfflineBackfillPlanReadsTheClaimPlan).
+type offlineBackfillHost struct {
+ Key string `json:"key"`
+ ETag string `json:"etag"`
+ Acquisition string `json:"acq"`
+ Region string `json:"region"`
+ Box string `json:"box"`
+}
+type offlineBackfillPlan struct {
+ V int `json:"v"`
+ ID string `json:"id"`
+ Phase string `json:"phase"`
+ DirectoryRevision uint64 `json:"directory_revision"`
+ CreatedAt time.Time `json:"created_at"`
+ Reports map[string]string `json:"reports"`
+ Hosts map[string]offlineBackfillHost `json:"hosts"`
+}
+
+// errOfflineBackfillBegun is a backfill plan that has begun, or that does
+// not verify under the release key (hostops.ErrPending, hostops.ErrIdentity).
+var errOfflineBackfillBegun = errors.New("console: the host-claim backfill has begun")
+
+// offlineBackfillFreeze is hostops.CheckCreateFreeze: nil with no plan or a
+// verified plan at done, errOfflineBackfillBegun for any other plan, and the
+// read's own error when the plan cannot be read.
+func offlineBackfillFreeze(ctx context.Context, s release.Store, pub ed25519.PublicKey) error {
+ raw, _, err := s.Get(ctx, offlineBackfillKey)
+ if errors.Is(err, os.ErrNotExist) {
+ return nil
+ }
+ if err != nil {
+ return err
+ }
+ var plan offlineBackfillPlan
+ if release.VerifyRootEnvelope(pub, raw, &plan) != nil || plan.V != 1 || plan.ID == "" || plan.Phase != "done" {
+ return errOfflineBackfillBegun
+ }
+ return nil
+}
diff --git a/internal/console/apiinstancemove_offline_absence_test.go b/internal/console/apiinstancemove_offline_absence_test.go
new file mode 100644
index 000000000..eb7fe77b6
--- /dev/null
+++ b/internal/console/apiinstancemove_offline_absence_test.go
@@ -0,0 +1,159 @@
+package console
+
+import (
+ "context"
+ "errors"
+ "net/http"
+ "reflect"
+ "testing"
+ "time"
+
+ "github.com/carlosframework/platform/internal/hostclaim"
+ "github.com/carlosframework/platform/internal/hostops"
+ "github.com/carlosframework/platform/internal/release"
+)
+
+// The console-local keys are the claim packages' keys, for well-formed and
+// malformed inputs alike. The hostclaim and hostops halves go when those
+// packages are deleted; the literals stay.
+func TestOfflineAbsenceKeysAreTheClaimKeys(t *testing.T) {
+ for _, want := range []string{"control/hosts-backfill.json", hostops.BackfillKey} {
+ if offlineBackfillKey != want {
+ t.Fatalf("backfill key = %q, want %q", offlineBackfillKey, want)
+ }
+ }
+ for _, host := range []string{offlineHost, "a.b", "", "../x", "UPPER.example.com", "x/y.example.com"} {
+ got, ok := offlineHostClaimKey(host)
+ want, err := hostclaim.Key(host)
+ if ok != (err == nil) || got != want {
+ t.Errorf("claim key %q = %q %v; hostclaim.Key = %q %v", host, got, ok, want, err)
+ }
+ if ok && got != "control/hosts/"+host+".json" {
+ t.Errorf("claim key %q = %q", host, got)
+ }
+ }
+ for _, c := range []struct{ acct, app string }{{"bab", "shop"}, {"BAB", "shop"}, {"bab", ""}, {"", "shop"}, {"bab", "../x"}} {
+ got, ok := offlineAdmissionKey(c.acct, c.app)
+ want, err := hostops.AdmissionKey(c.acct, c.app)
+ if ok != (err == nil) || got != want {
+ t.Errorf("admission key %q/%q = %q %v; hostops.AdmissionKey = %q %v", c.acct, c.app, got, ok, want, err)
+ }
+ if ok && got != "apps/"+c.acct+"/"+c.app+"/admission.json" {
+ t.Errorf("admission key %q/%q = %q", c.acct, c.app, got)
+ }
+ }
+}
+
+// The local plan type is hostops.BackfillPlan field for field, and the
+// local freeze check classifies every plan as hostops.CheckCreateFreeze
+// does: nil, begun (ErrPending or ErrIdentity), or the read's own error.
+func TestOfflineBackfillPlanReadsTheClaimPlan(t *testing.T) {
+ sameShape(t, reflect.TypeOf(offlineBackfillPlan{}), reflect.TypeOf(hostops.BackfillPlan{}))
+ fx, _ := instanceFixture(t, "code-offline-backfill")
+ signed := func(p hostops.BackfillPlan) []byte {
+ t.Helper()
+ raw, err := release.SignRootEnvelope(release.RootSigner(fx.priv), p)
+ if err != nil {
+ t.Fatal(err)
+ }
+ return raw
+ }
+ full := hostops.BackfillPlan{V: 1, ID: "plan-1", Phase: "done", DirectoryRevision: 7, CreatedAt: time.Date(2026, 10, 1, 12, 0, 0, 5, time.UTC),
+ Reports: map[string]string{"ie-box": "sha"}, Hosts: map[string]hostops.BackfillHost{offlineHost: {Key: "k", ETag: "e", Acquisition: "a", Region: "ie", Box: "ie-box"}}}
+ variant := func(f func(*hostops.BackfillPlan)) []byte { p := full; f(&p); return signed(p) }
+ cases := map[string][]byte{
+ "done, full": signed(full),
+ "done, minimal": signed(hostops.BackfillPlan{V: 1, ID: "plan-1", Phase: "done"}),
+ "collecting": variant(func(p *hostops.BackfillPlan) { p.Phase = "collecting" }),
+ "adopting": variant(func(p *hostops.BackfillPlan) { p.Phase = "adopting" }),
+ "version 2": variant(func(p *hostops.BackfillPlan) { p.V = 2 }),
+ "no id": variant(func(p *hostops.BackfillPlan) { p.ID = "" }),
+ "not an envelope": []byte("not an envelope"),
+ }
+ ctx := context.Background()
+ for name, raw := range cases {
+ offlinePut(t, fx.rel, offlineBackfillKey, raw)
+ local := offlineBackfillFreeze(ctx, fx.rel, fx.srv.cfg.ReleasePub)
+ claim := hostops.CheckCreateFreeze(ctx, fx.rel, fx.srv.cfg.ReleasePub)
+ begun := errors.Is(claim, hostops.ErrPending) || errors.Is(claim, hostops.ErrIdentity)
+ if (local == nil) != (claim == nil) || errors.Is(local, errOfflineBackfillBegun) != begun {
+ t.Errorf("%s: local %v, hostops %v", name, local, claim)
+ }
+ }
+ if err := fx.rel.Delete(ctx, offlineBackfillKey); err != nil {
+ t.Fatal(err)
+ }
+ if err := offlineBackfillFreeze(ctx, fx.rel, fx.srv.cfg.ReleasePub); err != nil {
+ t.Fatalf("no plan = %v", err)
+ }
+ boom := errors.New("boom")
+ if err := offlineBackfillFreeze(ctx, offlineFaultStore{fx.rel, offlineBackfillKey, boom}, fx.srv.cfg.ReleasePub); !errors.Is(err, boom) || errors.Is(err, errOfflineBackfillBegun) {
+ t.Fatalf("unreadable plan = %v", err)
+ }
+}
+
+func sameShape(t *testing.T, a, b reflect.Type) {
+ t.Helper()
+ if a.Kind() != b.Kind() {
+ t.Fatalf("%v is a %v, %v a %v", a, a.Kind(), b, b.Kind())
+ }
+ switch a.Kind() {
+ case reflect.Struct:
+ if a.NumField() != b.NumField() {
+ t.Fatalf("%v has %d fields, %v %d", a, a.NumField(), b, b.NumField())
+ }
+ for i := 0; i < a.NumField(); i++ {
+ fa, fb := a.Field(i), b.Field(i)
+ if fa.Name != fb.Name || fa.Tag != fb.Tag {
+ t.Fatalf("%v field %d = %s %q, %v's = %s %q", a, i, fa.Name, fa.Tag, b, fb.Name, fb.Tag)
+ }
+ sameShape(t, fa.Type, fb.Type)
+ }
+ case reflect.Map:
+ sameShape(t, a.Key(), b.Key())
+ sameShape(t, a.Elem(), b.Elem())
+ default:
+ if a != b {
+ t.Fatalf("%v != %v", a, b)
+ }
+ }
+}
+
+// offlineFaultStore fails every Get of one key.
+type offlineFaultStore struct {
+ release.Store
+ key string
+ err error
+}
+
+func (s offlineFaultStore) Get(ctx context.Context, key string) ([]byte, string, error) {
+ if key == s.key {
+ return nil, "", s.err
+ }
+ return s.Store.Get(ctx, key)
+}
+
+// Any object at the claim key refuses, a well-formed claim or not; any
+// failed read of the three objects is a 502 and never an absence. (Before
+// claims cleanup R1 a claim object that did not decode and validate as a
+// claim was a 502; it is now refused as present, a 409. Either way nothing
+// is written.)
+func TestOfflineDoorAbsenceChecksRefuseAndFail(t *testing.T) {
+ const body = `{"region":"uk"}`
+ claimKey, _ := offlineHostClaimKey(offlineHost)
+ w := newOfflineWorld(t, oneEach...)
+ offlinePut(t, w.fx.rel, claimKey, []byte("not json"))
+ w.refused(http.MethodPost, "", body, http.StatusConflict, msgO29)
+ if err := w.fx.rel.Delete(context.Background(), claimKey); err != nil {
+ t.Fatal(err)
+ }
+ admission, _ := offlineAdmissionKey("bab", "shop")
+ real := w.fx.srv.cfg.Releases
+ for _, key := range []string{claimKey, admission, offlineBackfillKey} {
+ w.fx.srv.cfg.Releases = offlineFaultStore{real, key, errors.New("boom")}
+ w.refused(http.MethodPost, "", body, http.StatusBadGateway, "could not read the host claim")
+ w.refused(http.MethodPost, "/stage", body, http.StatusBadGateway, "could not read the host claim")
+ }
+ w.fx.srv.cfg.Releases = real
+ w.start()
+}