carlos / platform Public

console: refuse moves out of the leftover rail's sight (H3-M6)

A never-woken instance moved to another region stages nothing, so the
target's first wake restores the target's own prefix: a deleted
record's replica of the same host, whoever's it was. The activator
witness TestH3M6MoveOfANeverWokenHostLandsOnTheTargetsLeftover runs the
legacy round and the wake and shows it.

Every move start (legacy request, Phase 1 request, offline start and
stage) now uses the create doors' rule: a destination this console
cannot check is refused 409 unless the hostname history is active, and
an unreadable mode is S2. A destination in sight passes.

Also: a fleet variant of the create refusal (no region to suggest
instead), a test for "the home region" wording, and the proofExempt
comment now gives the real reason a fleet file seed is safe.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 6d0ca2756db4bc69fbc6bfed51c7b3716334c315 parent 9fced9c
7 files changed, +331 −8
  • internal/activator/move_h3m6_test.go +70 −0
  • internal/console/apiinstancemove.go +11 −0
  • internal/console/apiinstancemove_offline.go +5 −0
  • internal/console/createleftovers.go +29 −7
  • internal/console/createleftovers_h3m6_test.go +15 −1
  • internal/console/moveleftovers.go +61 −0
  • internal/console/moveleftovers_h3m6_test.go +140 −0
diff --git a/internal/activator/move_h3m6_test.go b/internal/activator/move_h3m6_test.go
new file mode 100644
index 000000000..5ff854b15
--- /dev/null
+++ b/internal/activator/move_h3m6_test.go
@@ -0,0 +1,70 @@
+package activator
+
+// Hunt H3-M6, the move route (Fable round 1 P1 candidate, Astra P1-2):
+// shopapp creates acme.example.com in a region whose bucket is clean,
+// never wakes it, and moves it to the region where titogo's deleted
+// record of the same host left its replica. This witness runs the box
+// half of a legacy move as it runs in production: the source round mirrors
+// the source's own prefix into the target's moves/<host>/ (movespass.go
+// legacyMoveRound, lease.MirrorPrefix), and the target's first wake is
+// Restore. A never-woken host has nothing in the source prefix, so the
+// round stages nothing, the promotion has nothing to promote, and the wake
+// restores the target's own prefix: titogo's database. The console's move
+// doors refuse such a move (hunt H3-M6, internal/console/moveleftovers.go);
+// the box cannot tell whose the prefix is.
+
+import (
+ "context"
+ "path/filepath"
+ "testing"
+
+ "github.com/carlosframework/platform/internal/lease"
+ "github.com/carlosframework/platform/internal/registry"
+)
+
+func TestH3M6MoveOfANeverWokenHostLandsOnTheTargetsLeftover(t *testing.T) {
+ ctx := context.Background()
+ b := testExecBackend(t) // the target box
+ f := newFakeMirrorStore()
+ b.Mirror = f
+ host := "acme.example.com"
+ const sourceBucket = "source-region-data"
+
+ // titogo's deleted record left its replica in the target's bucket.
+ leftover := b.Cfg.hibernatePrefix(host) + "/ltx/0/0000000000000001-0000000000000001.ltx"
+ f.put(b.Cfg.Bucket, leftover, "titogo")
+
+ // The source's round for shopapp's never-woken host: nothing to copy.
+ round, err := lease.MirrorPrefix(ctx, f, sourceBucket, HibernatePrefix("", host), b.Cfg.Bucket, MovesPrefix(host), lease.Receipts{})
+ if err != nil {
+ t.Fatal(err)
+ }
+ if round.Changed != 0 {
+ t.Fatalf("the round staged %d objects for a host that never woke", round.Changed)
+ }
+
+ var restoredFrom []string
+ setKnob(t, &restoreReplica, func(_ context.Context, dbPath, bucket, prefix, _ string) (bool, error) {
+ objs, _ := f.List(context.Background(), bucket, prefix)
+ if len(objs) == 0 {
+ return false, nil
+ }
+ restoredFrom = append(restoredFrom, bucket+"/"+prefix)
+ return true, writeMinimalSQLite(dbPath)
+ })
+ // shopapp's record, landed: its first wake on the target.
+ rt := registry.Route{Host: host, Kind: "instance", Account: "acct", App: "shopapp", Socket: filepath.Join(t.TempDir(), "i.sock")}
+ fresh, err := b.Restore(ctx, rt)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if fresh || len(restoredFrom) != 1 || restoredFrom[0] != b.Cfg.Bucket+"/"+b.Cfg.hibernatePrefix(host) {
+ t.Fatalf("fresh %v, restored from %v", fresh, restoredFrom)
+ }
+ if own, _ := f.List(ctx, b.Cfg.Bucket, b.Cfg.hibernatePrefix(host)); own[leftover].ETag != "titogo" {
+ t.Fatalf("own prefix = %v", own)
+ }
+ // Witnessed: shopapp's first wake restored titogo's replica. This is
+ // the box behaving as designed for a host with no owner stamp
+ // (docs/superpowers/notes/2026-11-30-h3-m6-box-owner-binding.md).
+}
diff --git a/internal/console/apiinstancemove.go b/internal/console/apiinstancemove.go
index 48ebd5170..b44b1d182 100644
--- a/internal/console/apiinstancemove.go
+++ b/internal/console/apiinstancemove.go
@@ -472,6 +472,11 @@ func (s *Server) legacyHandleAPIInstanceMoveRequest(w http.ResponseWriter, r *ht
jsonError(w, http.StatusBadRequest, "moves to the home region are not supported yet — the home publishes no staging lane")
return
}
+ // The leftover rail (H3-M6, moveleftovers.go).
+ if ref := s.moveLeftoverRefusal(r.Context(), host, to); ref != nil {
+ jsonError(w, ref.Status, ref.Msg)
+ return
+ }
// The armed gate is MANDATORY for moves — unlike create there is no
// dormant path, because a move needs a live target box to restore on;
// a deployment with no armed placements cannot be a move target at all.
@@ -664,6 +669,12 @@ func (s *Server) handleAPIInstanceMoveRequest(w http.ResponseWriter, r *http.Req
jsonError(w, http.StatusConflict, "the instance is already in "+toName)
return
}
+ // The leftover rail (H3-M6, moveleftovers.go), before any policy
+ // read or claim write.
+ if ref := s.moveLeftoverRefusal(ctx, host, to); ref != nil {
+ jsonError(w, ref.Status, ref.Msg)
+ return
+ }
// Both policy reads fail closed (round-4 finding 13): an unreadable
// manifest or storage binding is a 503, never a pass.
m, err := provision.GetManifest(ctx, s.cfg.Releases, acct.Sqid, app)
diff --git a/internal/console/apiinstancemove_offline.go b/internal/console/apiinstancemove_offline.go
index 53bf81cf2..56f265f6f 100644
--- a/internal/console/apiinstancemove_offline.go
+++ b/internal/console/apiinstancemove_offline.go
@@ -676,6 +676,11 @@ func (s *Server) offlineBeginChecks(w http.ResponseWriter, r *http.Request, d of
jsonError(w, http.StatusConflict, "the instance is already in "+region)
return "", offlineFleet{}, false, false
}
+ // The leftover rail (H3-M6, moveleftovers.go): start and stage alike.
+ if ref := s.moveLeftoverRefusal(ctx, host, to); ref != nil {
+ jsonError(w, ref.Status, ref.Msg)
+ return "", offlineFleet{}, false, false
+ }
m, err := provision.GetManifest(ctx, s.cfg.Releases, d.acct.Sqid, d.app)
if err != nil && !errors.Is(err, os.ErrNotExist) {
log.Printf("console: offline move %s: manifest: %v", host, err)
diff --git a/internal/console/createleftovers.go b/internal/console/createleftovers.go
index 796d4e815..456c2a525 100644
--- a/internal/console/createleftovers.go
+++ b/internal/console/createleftovers.go
@@ -19,8 +19,10 @@
// mark step refuses any host that has ever held data, whoever's (S1), on a
// region or fleet activation examined (S4). A pooled record keeps no
// replica of its own and is created unchecked. Leftovers in this region
-// under a host created elsewhere are not seen either, and a later move of
-// that instance into this region would land on top of them. A console with
+// under a host created elsewhere are not seen either. A move is held to
+// the same rule (moveleftovers.go): out of sight it is refused unless the
+// history is active, because a never-woken instance's move lands on the
+// target's own prefix. A console with
// no data bucket configured checks nothing. Plain HA data creates instead
// require home, unpooled data with a bounded whole-prefix proof and retain
// the staging check. Uninspectable home data fails closed; remote and
@@ -106,6 +108,13 @@ func (s *Server) outOfSightRefusal(ctx context.Context, c leftoverCreate) *doorR
}
log.Printf("console: %s: refused: %s would keep its data in %q, which this console cannot check for a deleted record's replica, and the hostname history is %s (H3-M6)",
c.logTag, c.host, c.region, mode)
+ if _, fleet := registry.FleetPlacement(c.region); fleet {
+ // The app's fleet placement chose where it goes, so there is no
+ // region to suggest instead (Fable round 1).
+ return &doorRefusal{Status: http.StatusConflict, Msg: msgCreateOutOfSightFleet(subject, kind, s.offlinePlace(c.region))}
+ }
+ // here is "the home region" on a console with no region name
+ // (regionlabel.ForCode).
return &doorRefusal{Status: http.StatusConflict,
Msg: msgCreateOutOfSight(subject, kind, s.offlinePlace(c.region), s.offlinePlace(s.cfg.Region))}
}
@@ -240,11 +249,17 @@ type leftoverCreate struct {
// (msgCreateOutOfSight): "the sidecar <name>", or the host when "".
subject string
// proofExempt is a create that needs no proof out of sight. A --from
- // or import create: its own door refuses every region but this
- // console's, with its own sentence ("a copy stays in its source's
- // region", "an import runs in this console's region"), before any
- // record is written. A static or service record: it never wakes a
- // database, and its kind cannot change (provision.ErrKindChange).
+ // copy or a region import: its own door refuses every region but this
+ // console's ("a copy stays in its source's region", "an import runs in
+ // this console's region"), so it is never out of sight and the rail
+ // checks it as usual. A file seed on a fleet IS admitted out of sight
+ // (seedfile.go beginFileSeed), and is safe only because its box refuses
+ // it over anything it cannot attribute to this seed: a replica without
+ // this seed's placement marker (fleetSeedNotOwn), anything staged for
+ // the host (fleetSeedStagingRefusal), and a local database this seed did
+ // not place (seedOverUnattributedData, H3-M6 round 2). A static or
+ // service record: it never wakes a database, and its kind cannot
+ // change (provision.ErrKindChange).
proofExempt bool
}
@@ -256,6 +271,13 @@ func msgCreateOutOfSight(subject, kind, place, here string) string {
kind + ". Create it in " + here + ", or ask an operator."
}
+// msgCreateOutOfSightFleet is msgCreateOutOfSight for a create placed on
+// a fleet: place is "fleet <name>", and the caller cannot pick another.
+func msgCreateOutOfSightFleet(subject, kind, place string) string {
+ return subject + " can't be created on " + place + " yet, because this console can't check the fleet for data left by a deleted " +
+ kind + ". Ask an operator."
+}
+
// leftoverReplicaRefusal is the rail as the doors call it. It answers nil
// when the create may go ahead: the record is unchecked here (pooled, or no
// data bucket), the host holds no replica data, or the record is out of
diff --git a/internal/console/createleftovers_h3m6_test.go b/internal/console/createleftovers_h3m6_test.go
index ab0746124..870b244d3 100644
--- a/internal/console/createleftovers_h3m6_test.go
+++ b/internal/console/createleftovers_h3m6_test.go
@@ -85,7 +85,7 @@ func TestH3M6FleetPlacedCreateIsRefused(t *testing.T) {
}
status, _, out := rawReq(t, http.MethodPost, instancesURL(fx.consoleFixture, "bab", "shopapp"), fx.token,
`{"host":"acme.go.tito.io","region":"ie"}`)
- if status != http.StatusConflict || !strings.Contains(out, "can't be created in fleet eleven "+outOfSightRefusal) {
+ if status != http.StatusConflict || errorText(out) != "acme.go.tito.io can't be created on fleet eleven yet, because this console can't check the fleet for data left by a deleted instance. Ask an operator." {
t.Fatalf("fleet-placed create = %d %s, want the out-of-sight 409", status, out)
}
if shopappRecord(t, fx, "acme.go.tito.io") {
@@ -183,3 +183,17 @@ func TestLeftoverOutOfSight(t *testing.T) {
}
}
}
+
+// On a console whose own region has no name (the home, with no
+// CARLOS_HOME_REGION name), the region it offers instead is "the home
+// region" (regionlabel.ForCode), never an empty word.
+func TestH3M6RefusalOnAnUnnamedHomeConsole(t *testing.T) {
+ fx := leftoverFixture(t, "code-h3m6-unnamed")
+ fx.srv.cfg.Region = ""
+ status, _, out := rawReq(t, http.MethodPost, instancesURL(fx.consoleFixture, "bab", "titogo"), fx.token,
+ `{"host":"acme.go.tito.io","region":"ie"}`)
+ want := "acme.go.tito.io can't be created in ie yet, because this console can't check there for data left by a deleted instance. Create it in the home region, or ask an operator."
+ if status != http.StatusConflict || errorText(out) != want {
+ t.Fatalf("create = %d %s, want 409 %q", status, out, want)
+ }
+}
diff --git a/internal/console/moveleftovers.go b/internal/console/moveleftovers.go
new file mode 100644
index 000000000..9cc4487d8
--- /dev/null
+++ b/internal/console/moveleftovers.go
@@ -0,0 +1,61 @@
+package console
+
+import (
+ "context"
+ "log"
+ "net/http"
+
+ "github.com/carlosframework/platform/internal/provision"
+)
+
+// The leftover rail on the move doors (hunt H3-M6, round 2). A move lands
+// an instance on the target region's copy of its host's prefix. When the
+// source has nothing to stage (an instance that never woke), the legacy
+// target's first wake promotes nothing and restores the target's own
+// prefix, which may hold a deleted record's replica, whoever's it was
+// (activator TestH3M6MoveOfANeverWokenHostLandsOnTheTargetsLeftover). The
+// box has no owner stamp to refuse it with
+// (docs/superpowers/notes/2026-11-30-h3-m6-box-owner-binding.md).
+//
+// So a move is held to the create doors' rule: a destination this console
+// cannot check (leftoverOutOfSight: another region's bucket) is refused
+// until the hostname history is active, when the instance's create was
+// proved free of every examined target's leftovers (S1). Every door that
+// starts a move asks: the legacy request, the Phase 1 request and the
+// offline start and stage. A destination in sight passes without a check:
+// without an active history this instance was created in sight (out of
+// sight creates are refused), its prefix here was checked clean then, and
+// no other record could write it while this one holds the host. A move
+// back home after an earlier stay finds its own lineage, which the staged
+// copy replaces. Records created out of sight before this rule are not
+// covered: the rule cannot tell them apart. Fleet and pooled records never
+// reach here (moveGate refuses both).
+//
+// Phase 1 consoles cannot activate the history (it refuses while claims or
+// Phase 1 moves are on), so there every move out of sight is refused.
+
+// msgMoveOutOfSight is the 409 for such a move. place is the destination's
+// label.
+func msgMoveOutOfSight(host, place string) string {
+ return host + " can't move to " + place + " yet, because this console can't check there for data left by a deleted instance. Ask an operator."
+}
+
+// moveLeftoverRefusal is nil when a move of host to the region code to may
+// start, else the refusal: 409 out of sight without an active history,
+// 503 (S2) when the history's mode cannot be read. It reads only the held
+// history state, never a bucket.
+func (s *Server) moveLeftoverRefusal(ctx context.Context, host, to string) *doorRefusal {
+ if !s.leftoverOutOfSight(to, "") {
+ return nil
+ }
+ mode, err := s.hostsMode(ctx)
+ if err != nil {
+ log.Printf("console: move %s: read the hostname history's mode: %v", host, err)
+ return &doorRefusal{Status: http.StatusServiceUnavailable, Msg: msgHostUnchecked(host)}
+ }
+ if mode == provision.HostsModeActive {
+ return nil
+ }
+ log.Printf("console: move %s: refused: %q is out of this console's sight and the hostname history is %s (H3-M6)", host, to, mode)
+ return &doorRefusal{Status: http.StatusConflict, Msg: msgMoveOutOfSight(host, s.offlinePlace(to))}
+}
diff --git a/internal/console/moveleftovers_h3m6_test.go b/internal/console/moveleftovers_h3m6_test.go
new file mode 100644
index 000000000..f157ec052
--- /dev/null
+++ b/internal/console/moveleftovers_h3m6_test.go
@@ -0,0 +1,140 @@
+package console
+
+// Hunt H3-M6, the move route (Fable round 1 P1 candidate). An instance
+// created where the rail could check (this console's region, clean), never
+// woken, and moved to a region this console cannot read lands on whatever
+// a deleted record of the same host left there: its source has nothing to
+// stage, so the target's first wake restores the target's own prefix
+// (activator TestH3M6MoveOfANeverWokenHostLandsOnTheTargetsLeftover). So
+// every move door refuses a destination out of the rail's sight until the
+// hostname history is active, exactly as the create doors do: the legacy
+// door, the Phase 1 door, and the offline start and stage doors. The tests
+// go through the production doors.
+
+import (
+ "context"
+ "net/http"
+ "strings"
+ "testing"
+
+ "github.com/carlosframework/platform/internal/provision"
+)
+
+const moveOutOfSightWords = "acme.go.tito.io can't move to uk yet, because this console can't check there for data left by a deleted instance."
+
+// moveFixture is leftoverFixture (a data bucket, this console in ie) with
+// titogo's acme created in ie, where the rail checked it clean.
+func moveFixture(t *testing.T, code string) (*leftoverFx, string) {
+ t.Helper()
+ fx := leftoverFixture(t, code)
+ u := instancesURL(fx.consoleFixture, "bab", "titogo")
+ m := titoManifest()
+ m.Regions, m.Pool = nil, ""
+ enableInstances(t, fx.consoleFixture, "titogo", m)
+ if c, _, out := rawReq(t, http.MethodPost, u, fx.token, `{"host":"acme.go.tito.io","region":"ie"}`); c != http.StatusCreated {
+ t.Fatalf("create = %d %s", c, out)
+ }
+ return fx, u + "/acme.go.tito.io/move"
+}
+
+func noMoveOnRecord(t *testing.T, fx *leftoverFx) {
+ t.Helper()
+ rec, err := provision.GetRecord(context.Background(), fx.rel, "bab", "titogo", "acme.go.tito.io")
+ if err != nil {
+ t.Fatal(err)
+ }
+ if rec.Move != nil {
+ t.Fatalf("a refused move wrote %+v", rec.Move)
+ }
+}
+
+func activeHistory(t *testing.T, fx *leftoverFx) {
+ t.Helper()
+ forceHostsState(t, fx.srv, provision.HostsState{Mode: provision.HostsModeActive, Examined: []string{"region:ie", "region:uk"}})
+}
+
+func TestH3M6LegacyMoveOutOfSightIsRefused(t *testing.T) {
+ fx, moveURL := moveFixture(t, "code-h3m6-move-legacy")
+ if _, err := fx.rel.Put(context.Background(), "control/edges/uk-box.json",
+ []byte(`{"v":1,"box":"uk-box","eip":"1.2.3.4","placement":"uk","data_bucket":"data-uk","data_bucket_region":"eu-west-2","hosts":{}}`), ""); err != nil {
+ t.Fatal(err)
+ }
+ code, _, out := rawReq(t, http.MethodPost, moveURL, fx.token, `{"region":"uk"}`)
+ if code != http.StatusConflict || !strings.Contains(out, moveOutOfSightWords) {
+ t.Fatalf("move to uk = %d %s, want the out-of-sight 409", code, out)
+ }
+ noMoveOnRecord(t, fx)
+ // Once the history is active the host was proved free when it was
+ // created (S1), and the move goes ahead.
+ activeHistory(t, fx)
+ if code, _, out := rawReq(t, http.MethodPost, moveURL, fx.token, `{"region":"uk"}`); code != http.StatusAccepted {
+ t.Fatalf("move with the history active = %d %s, want 202", code, out)
+ }
+}
+
+func TestH3M6Phase1MoveOutOfSightIsRefused(t *testing.T) {
+ fx, moveURL := moveFixture(t, "code-h3m6-move-p1")
+ if err := fx.st.SetOperator("alice@keymail.dev", true); err != nil {
+ t.Fatal(err)
+ }
+ enableMovesPhase1(fx.consoleFixture)
+ armMoveFleet(t, fx.consoleFixture, ieBox("ie-box"), ukBox("uk-box"))
+ claimFor(t, fx.consoleFixture, "acme.go.tito.io", "ie-box", "ie")
+ code, _, out := rawReq(t, http.MethodPost, moveURL, fx.token, `{"region":"uk"}`)
+ if code != http.StatusConflict || !strings.Contains(out, moveOutOfSightWords) {
+ t.Fatalf("move to uk = %d %s, want the out-of-sight 409", code, out)
+ }
+ noMoveOnRecord(t, fx)
+ activeHistory(t, fx)
+ if code, _, out := rawReq(t, http.MethodPost, moveURL, fx.token, `{"region":"uk"}`); code != http.StatusAccepted {
+ t.Fatalf("move with the history active = %d %s, want 202", code, out)
+ }
+}
+
+// The offline doors, start and stage: refused out of sight with nothing
+// written, and admitted once the history is active.
+func TestH3M6OfflineMoveOutOfSightIsRefused(t *testing.T) {
+ for _, path := range []string{"", "/stage"} {
+ t.Run("door"+path, func(t *testing.T) {
+ w := newOfflineWorld(t, oneEach...)
+ w.fx.srv.cfg.HibernateBucket, w.fx.srv.cfg.Region = "data-ie", "ie"
+ w.refused(http.MethodPost, path, `{"region":"uk"}`, http.StatusConflict,
+ offlineHost+" can't move to uk yet, because this console can't check there for data left by a deleted instance. Ask an operator.")
+ forceHostsState(t, w.fx.srv, provision.HostsState{Mode: provision.HostsModeActive, Examined: []string{"region:ie", "region:uk"}})
+ if code, out := w.req(http.MethodPost, path, `{"region":"uk"}`); code != http.StatusAccepted {
+ t.Fatalf("POST %s with the history active = %d %s, want 202", path, code, out)
+ }
+ })
+ }
+}
+
+// A move into this console's own region is in the rail's sight: the
+// instance was checked when it was created, wherever it went since, and
+// no other record can have written the host's prefix here while it held
+// the host. It is not refused (a move back home keeps working).
+func TestH3M6MoveIntoTheConsolesRegionIsNotRefused(t *testing.T) {
+ w := newOfflineWorld(t, oneEach...)
+ w.fx.srv.cfg.HibernateBucket, w.fx.srv.cfg.Region = "data-uk", "uk"
+ w.start()
+}
+
+// The refusal and the place it names, for every shape of destination.
+func TestMoveOutOfSight(t *testing.T) {
+ s := &Server{}
+ for _, c := range []struct {
+ to, console, bucket string
+ want bool
+ }{
+ {"uk", "ie", "data-test", true},
+ {"", "ie", "data-test", true},
+ {"ie", "ie", "data-test", false},
+ {"", "", "data-test", false},
+ {"uk", "", "data-test", true},
+ {"uk", "ie", "", false},
+ } {
+ s.cfg.Region, s.cfg.HibernateBucket = c.console, c.bucket
+ if got := s.leftoverOutOfSight(c.to, ""); got != c.want {
+ t.Errorf("move to %q on console %q (bucket %q) = %v, want %v", c.to, c.console, c.bucket, got, c.want)
+ }
+ }
+}