carlos / platform Public

console: one admission rule for every data transfer (H3-M6)

Paul's ruling 2026-11-30: refuse up front with one shared rule. Every
door that binds a data-kind record to storage asks dataTransferRefusal
before its first write: create (instance, sidecar), legacy, Phase 1 and
offline move start and stage, and apps place in both directions.

In sight it is the bucket check. Out of sight it admits only under an
active hostname history that examined the destination and still covers
it (hostsTargetRefusal, hostsCoverageRefusal: a region added since, or
a changed data bucket, refuses). Otherwise 409 saying what an operator
runs. Pooled and no-bucket stay the box's to close. A place with no
data-kind record still goes ahead.

TestEveryDataTransferDoorAsksTheSharedRule reads the package source and
fails a function that calls SetRecordRegion or builds a move start, or
a listed door, that does not reach the rule. Witnesses: place onto a
fleet, unplace home over a leftover, active history with an unexamined
region and with a changed bucket. HA pool tests whose legacy control
creates went out of sight (409 since round 1) now make the history
active first.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 614824e753f3487e385b093b8127aae72ad545ef parent 2d6d212
15 files changed, +703 −256
  • internal/console/apiinstancemove.go +4 −4
  • internal/console/apiinstancemove_offline.go +2 −2
  • internal/console/apiinstances.go +0 −1
  • internal/console/apiinstances_haenable_test.go +4 −0
  • internal/console/createleftovers.go +68 −138
  • internal/console/createleftovers_h3m6_test.go +7 −30
  • internal/console/createleftovers_test.go +1 −1
  • internal/console/datatransfer.go +149 −0
  • internal/console/datatransfer_guard_test.go +177 −0
  • internal/console/fleets.go +20 −0
  • internal/console/ha_pool_scope_test.go +27 −1
  • internal/console/hapool_test.go +3 −0
  • internal/console/moveleftovers.go +28 −49
  • internal/console/moveleftovers_h3m6_test.go +87 −30
  • internal/console/placeleftovers_h3m6_test.go +126 −0
diff --git a/internal/console/apiinstancemove.go b/internal/console/apiinstancemove.go
index b44b1d182..bb08ad0d0 100644
--- a/internal/console/apiinstancemove.go
+++ b/internal/console/apiinstancemove.go
@@ -472,8 +472,8 @@ 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 {
+ // The shared data-transfer rule (H3-M6, datatransfer.go).
+ if ref := s.moveTransferRefusal(r.Context(), "api instance move "+acct.Sqid+"/"+app, rec, to); ref != nil {
jsonError(w, ref.Status, ref.Msg)
return
}
@@ -669,9 +669,9 @@ 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
+ // The shared data-transfer rule (H3-M6, datatransfer.go), before any policy
// read or claim write.
- if ref := s.moveLeftoverRefusal(ctx, host, to); ref != nil {
+ if ref := s.moveTransferRefusal(ctx, "api instance move "+acct.Sqid+"/"+app, rec, to); ref != nil {
jsonError(w, ref.Status, ref.Msg)
return
}
diff --git a/internal/console/apiinstancemove_offline.go b/internal/console/apiinstancemove_offline.go
index 56f265f6f..6cd57f288 100644
--- a/internal/console/apiinstancemove_offline.go
+++ b/internal/console/apiinstancemove_offline.go
@@ -676,8 +676,8 @@ 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 {
+ // The shared data-transfer rule (H3-M6, datatransfer.go): start and stage alike.
+ if ref := s.moveTransferRefusal(ctx, "offline move "+d.acct.Sqid+"/"+d.app, rec, to); ref != nil {
jsonError(w, ref.Status, ref.Msg)
return "", offlineFleet{}, false, false
}
diff --git a/internal/console/apiinstances.go b/internal/console/apiinstances.go
index a0ce72222..f3d3241cc 100644
--- a/internal/console/apiinstances.go
+++ b/internal/console/apiinstances.go
@@ -2485,7 +2485,6 @@ func (s *Server) handleAPIInstanceCreate(w http.ResponseWriter, r *http.Request)
HAData: s.shouldStampHA(rec) && !seeded && rec.DerivesPaths(),
logTag: "api instances create " + acct.Sqid + "/" + app,
host: host, region: region, pool: rec.Pool, proofExempt: seeded || !rec.DataKind(),
- appRegion: regionFrom == "app",
exists: func(ctx context.Context) (bool, error) {
// Judged when admitted on (a nil judge is GetRecord): a stale
// body is no record, and the create replaces it.
diff --git a/internal/console/apiinstances_haenable_test.go b/internal/console/apiinstances_haenable_test.go
index d4051ac3c..3dddb524a 100644
--- a/internal/console/apiinstances_haenable_test.go
+++ b/internal/console/apiinstances_haenable_test.go
@@ -550,6 +550,10 @@ func TestStaleRouteNeverPlacesHAApp(t *testing.T) {
if code, res := w.enable(t, "legacy", `{}`); code != http.StatusOK {
t.Fatalf("legacy enable = %d %v", code, res)
}
+ // The legacy control creates land on fleet pi, out of the leftover
+ // rail's sight: the shared data-transfer rule (H3-M6) admits them only
+ // under an active history that examined pi.
+ forceHostsState(t, w.srv, provision.HostsState{Mode: provision.HostsModeActive, Examined: []string{"region:us", "fleet:pi"}})
create := func(app string) *provision.Record {
t.Helper()
host := haEnableHost(app)
diff --git a/internal/console/createleftovers.go b/internal/console/createleftovers.go
index c2ffddc64..bbbbfed64 100644
--- a/internal/console/createleftovers.go
+++ b/internal/console/createleftovers.go
@@ -18,23 +18,18 @@
// those is proved safe here; they are the box owner binding's to close
// (docs/superpowers/notes/2026-11-30-h3-m6-box-owner-binding.md).
//
-// For legacy creates the check only sees THIS console's region. A record
-// homed in another region, or placed on a customer fleet, keeps its data
-// somewhere this console's role cannot read (resolveReplica's residency
-// rules), so nothing here can prove its host free: such a create is
-// refused (hunt H3-M6) unless the hostname history is active, when the
-// 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 here: its leftovers are
-// local, on the pool box, and not this rail's to see. Leftovers in this region
-// 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, which does not make its boxes' local leftovers safe. 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
-// pooled data is refused.
+// For legacy creates the check only sees THIS console's region. The create
+// doors, the move doors and the place door all go through one admission
+// rule (dataTransferRefusal, datatransfer.go): in sight, this bucket check;
+// out of sight (another region's bucket, a fleet), an active hostname
+// history that examined the destination and still covers it, else 409
+// (hunt H3-M6). A pooled record keeps no replica of its own and is created
+// unchecked here: its leftovers are local, on the pool box, and not this
+// rail's to see. A console with no data bucket configured checks nothing,
+// which does not make its boxes' local leftovers safe. 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 pooled data is refused.
package console
@@ -92,48 +87,6 @@ func (s *Server) leftoverOutOfSight(region, pool string) bool {
return region != s.cfg.Region
}
-// outOfSightRefusal is the rail for an out-of-sight create (H3-M6) whose
-// record is not already there. Nothing this console can read proves the
-// host free: the replica of a deleted record, whatever its app or account,
-// would sit in a bucket it cannot list, and the new record's first wake
-// would restore it. The one proof is an active hostname history: every
-// host that has held data is marked, and the mark step refuses a marked
-// host (S1) after the doors' S4 check refused an unexamined target. So an
-// active history passes; any other mode refuses 409, and a mode that cannot
-// be read refuses 503 (unsure). No mark's body is read: the mark's presence
-// is the fact, never who wrote it (hostsused.go).
-func (s *Server) outOfSightRefusal(ctx context.Context, c leftoverCreate) *doorRefusal {
- mode, err := s.hostsMode(ctx)
- if err != nil {
- log.Printf("console: %s: read the hostname history's mode for %s: %v", c.logTag, c.host, err)
- return &doorRefusal{Status: http.StatusServiceUnavailable, Msg: c.unsure}
- }
- if mode == provision.HostsModeActive {
- return nil
- }
- kind, subject := "instance", c.subject
- if c.sidecar {
- kind = "sidecar"
- }
- if subject == "" {
- subject = c.host
- }
- 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))}
- }
- if c.appRegion {
- return &doorRefusal{Status: http.StatusConflict, Msg: msgCreateOutOfSightAppRegion(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))}
-}
-
// hostHoldsReplicaData reports whether host's replica prefix or its move
// staging prefix holds any LTX file, at any level from 0 to the snapshot
// level. It stops at the first file. Every error is returned, never treated
@@ -260,11 +213,8 @@ type leftoverCreate struct {
duplicate, readFailed doorRefusal
// taken and unsure are the rail's 409 and 503 sentences.
taken, unsure string
- // appRegion is a create whose region is the app's own region, not one
- // the caller named, so the refusal suggests no other region.
- appRegion bool
- // subject names what is created in the out-of-sight refusal
- // (msgCreateOutOfSight): "the sidecar <name>", or the host when "".
+ // subject names what is created in the shared rule's refusals
+ // (dataTransferRefusal): "the sidecar <name>", or the host when "".
subject string
// proofExempt is a create that needs no proof out of sight. A --from
// copy or a region import: its own door refuses every region but this
@@ -281,37 +231,13 @@ type leftoverCreate struct {
proofExempt bool
}
-// msgCreateOutOfSight is the 409 for a create whose data would live where
-// this console cannot look for a deleted record's leftovers (H3-M6). place
-// is where it was asked for; here is the console's own region.
-func msgCreateOutOfSight(subject, kind, place, here string) string {
- return subject + " can't be created in " + place + " yet, because this console can't check there for data left by a deleted " +
- 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."
-}
-
-// msgCreateOutOfSightAppRegion is msgCreateOutOfSight for a create placed
-// in the app's own region: the caller did not choose it, so no other
-// region is suggested.
-func msgCreateOutOfSightAppRegion(subject, kind, place string) string {
- return subject + " can't be created in " + place + ", this app's region, yet, because this console can't check there 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
-// this console's sight (leftoverOutOfSight) and the hostname history is
-// active (outOfSightRefusal). Otherwise it answers 409 with taken or
-// msgCreateOutOfSight, or 503 with unsure when the bucket or the history's
-// mode could not be read. The store's own error is logged and never
-// returned: it carries the bucket name.
+// data bucket; exempt out of sight), or the shared admission rule
+// (dataTransferRefusal) admits it. A prospective HA data create keeps its
+// own whole-prefix proof. Otherwise it answers 409 or 503: taken and
+// unsure in sight, the rule's own sentences out of sight. The store's own
+// error is logged and never returned: it carries the bucket name.
//
// It reads the record first. A create retried after a lost response finds
// its own record there, and that record's live replica fills the prefix,
@@ -326,12 +252,9 @@ func msgCreateOutOfSightAppRegion(subject, kind, place string) string {
// some of. The door must likewise take a fresh budget for its write after
// this returns.
func (s *Server) leftoverReplicaRefusal(parent context.Context, c leftoverCreate) *doorRefusal {
- outOfSight := false
- if !c.HAData && !s.leftoverCheckApplies(c.region, c.pool) {
- if c.proofExempt || !s.leftoverOutOfSight(c.region, c.pool) {
- return nil
- }
- outOfSight = true
+ if !c.HAData && !s.leftoverCheckApplies(c.region, c.pool) &&
+ (c.proofExempt || !s.leftoverOutOfSight(c.region, c.pool)) {
+ return nil
}
ctx, cancel := context.WithTimeout(parent, instanceStoreTimeout)
defer cancel()
@@ -343,47 +266,54 @@ func (s *Server) leftoverReplicaRefusal(parent context.Context, c leftoverCreate
if exists {
return &c.duplicate
}
- if outOfSight {
- return s.outOfSightRefusal(ctx, c)
- }
- unsure := c.unsure
- taken := c.taken
- var held bool
- if c.HAData {
- kind := "instance"
- if c.sidecar {
- kind = "sidecar"
- }
- name := s.offlinePlace(c.region)
- if s.haScopeInvalid {
- return &doorRefusal{Status: http.StatusServiceUnavailable, Msg: fmt.Sprintf(haCapacityUnknownRefusal, name), haCapacityRetryAfter: 60}
- }
- if len(s.haPools[s.homeRegionOut(c.region)]) > 0 {
- return s.scopedHALeftoverRefusal(ctx, c, kind, name)
- }
- if s.homeRegionIn(c.region) != "" || c.pool != "" {
- return &doorRefusal{Status: http.StatusConflict, Msg: fmt.Sprintf("high availability data creation is not available yet in %s. use the console's home region without a pool.", name)}
- }
- unsure = fmt.Sprintf("could not check this %s's data in %s. nothing was created. try again. persistent failures may require an operator to check data access for this region.", kind, name)
- if s.cfg.SeedData == nil || !s.leftoverCheckApplies(c.region, c.pool) {
- return &doorRefusal{Status: http.StatusServiceUnavailable, Msg: unsure}
+ if !c.HAData {
+ // The shared admission rule (datatransfer.go): the bucket check in
+ // sight, with this door's own sentences; an active, examined and
+ // covering history out of sight.
+ subject := c.subject
+ if subject == "" {
+ subject = c.host
}
- prefix := activator.HibernatePrefix(s.cfg.HibernatePrefix, c.host) + "/"
- class, proofErr := firstHALeftover(ctx, s.cfg.SeedData, prefix)
- if proofErr != nil {
- log.Printf("console: %s: HA prefix check for %s: %v", c.logTag, c.host, proofErr)
- return &doorRefusal{Status: http.StatusServiceUnavailable, Msg: unsure}
- }
- if class != "" {
- return &doorRefusal{Status: http.StatusConflict, Msg: fmt.Sprintf("%s still holds %s from a deleted %s. choose another address, or ask an operator to purge it.", c.host, class, kind)}
- }
- // The whole-prefix proof covered every instance level. Move staging
- // remains a separate prefix and must still be checked at all levels.
- held, err = s.replicaPrefixesHoldData(ctx, strings.TrimSuffix(activator.MovesPrefix(c.host), "/"))
- taken = fmt.Sprintf("%s still holds replica from a deleted %s. choose another address, or ask an operator to purge it.", c.host, kind)
- } else {
- held, err = s.hostHoldsReplicaData(ctx, c.host)
+ return s.dataTransferRefusal(ctx, dataTransfer{
+ logTag: c.logTag,
+ recs: []provision.Record{{Host: c.host, Pool: c.pool}},
+ to: c.region,
+ what: func(place string) string { return subject + " can't be created in " + place },
+ taken: func(string) string { return c.taken },
+ unsure: c.unsure,
+ })
+ }
+ kind := "instance"
+ if c.sidecar {
+ kind = "sidecar"
+ }
+ name := s.offlinePlace(c.region)
+ if s.haScopeInvalid {
+ return &doorRefusal{Status: http.StatusServiceUnavailable, Msg: fmt.Sprintf(haCapacityUnknownRefusal, name), haCapacityRetryAfter: 60}
+ }
+ if len(s.haPools[s.homeRegionOut(c.region)]) > 0 {
+ return s.scopedHALeftoverRefusal(ctx, c, kind, name)
+ }
+ if s.homeRegionIn(c.region) != "" || c.pool != "" {
+ return &doorRefusal{Status: http.StatusConflict, Msg: fmt.Sprintf("high availability data creation is not available yet in %s. use the console's home region without a pool.", name)}
+ }
+ unsure := fmt.Sprintf("could not check this %s's data in %s. nothing was created. try again. persistent failures may require an operator to check data access for this region.", kind, name)
+ if s.cfg.SeedData == nil || !s.leftoverCheckApplies(c.region, c.pool) {
+ return &doorRefusal{Status: http.StatusServiceUnavailable, Msg: unsure}
+ }
+ prefix := activator.HibernatePrefix(s.cfg.HibernatePrefix, c.host) + "/"
+ class, proofErr := firstHALeftover(ctx, s.cfg.SeedData, prefix)
+ if proofErr != nil {
+ log.Printf("console: %s: HA prefix check for %s: %v", c.logTag, c.host, proofErr)
+ return &doorRefusal{Status: http.StatusServiceUnavailable, Msg: unsure}
+ }
+ if class != "" {
+ return &doorRefusal{Status: http.StatusConflict, Msg: fmt.Sprintf("%s still holds %s from a deleted %s. choose another address, or ask an operator to purge it.", c.host, class, kind)}
}
+ // The whole-prefix proof covered every instance level. Move staging
+ // remains a separate prefix and must still be checked at all levels.
+ held, err := s.replicaPrefixesHoldData(ctx, strings.TrimSuffix(activator.MovesPrefix(c.host), "/"))
+ taken := fmt.Sprintf("%s still holds replica from a deleted %s. choose another address, or ask an operator to purge it.", c.host, kind)
if err != nil {
log.Printf("console: %s: leftover replica check for %s: %v", c.logTag, c.host, err)
return &doorRefusal{Status: http.StatusServiceUnavailable, Msg: unsure}
diff --git a/internal/console/createleftovers_h3m6_test.go b/internal/console/createleftovers_h3m6_test.go
index d5873d3d7..53fef5e37 100644
--- a/internal/console/createleftovers_h3m6_test.go
+++ b/internal/console/createleftovers_h3m6_test.go
@@ -19,7 +19,11 @@ import (
"github.com/carlosframework/platform/internal/provision"
)
-const outOfSightRefusal = "yet, because this console can't check there for data left by a deleted"
+// msgCreateUnchecked is the shared rule's refusal of a create out of sight
+// with the history not active.
+func msgCreateUnchecked(subject, place, host string) string {
+ return msgTransferUnchecked(subject+" can't be created in "+place, place, host)
+}
// shopappFixture is leftoverFixture with a second app of the same account,
// shopapp, enabled for unpooled instances on titogo's instance domain (an
@@ -50,7 +54,7 @@ func TestH3M6CrossAppCreateOnALeftoverHost(t *testing.T) {
for _, c := range []struct {
name, console, want string
}{
- {"out-of-region", "uk", "acme.go.tito.io can't be created in ie " + outOfSightRefusal + " instance. Create it in uk, or ask an operator."},
+ {"out-of-region", "uk", msgCreateUnchecked("acme.go.tito.io", "ie", "acme.go.tito.io")},
{"same-region", "ie", "acme.go.tito.io still holds data from a deleted instance."},
} {
t.Run(c.name, func(t *testing.T) {
@@ -85,7 +89,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 || 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." {
+ if status != http.StatusConflict || errorText(out) != msgCreateUnchecked("acme.go.tito.io", "fleet eleven", "acme.go.tito.io") {
t.Fatalf("fleet-placed create = %d %s, want the out-of-sight 409", status, out)
}
if shopappRecord(t, fx, "acme.go.tito.io") {
@@ -183,30 +187,3 @@ 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)
- }
-}
-
-// A create whose region is the app's own (nearest-region app regions, the
-// door's regionFrom "app") is refused without suggesting another region:
-// the caller did not choose it.
-func TestH3M6AppRegionRefusalSuggestsNoRegion(t *testing.T) {
- fx := leftoverFixture(t, "code-h3m6-appregion")
- fx.srv.cfg.Region = "uk"
- ref := fx.srv.outOfSightRefusal(context.Background(), leftoverCreate{host: "acme.go.tito.io", region: "ie", appRegion: true, logTag: "test"})
- want := "acme.go.tito.io can't be created in ie, this app's region, yet, because this console can't check there for data left by a deleted instance. Ask an operator."
- if ref == nil || ref.Status != http.StatusConflict || ref.Msg != want {
- t.Fatalf("refusal = %+v, want 409 %q", ref, want)
- }
-}
diff --git a/internal/console/createleftovers_test.go b/internal/console/createleftovers_test.go
index c160da56b..43bb92449 100644
--- a/internal/console/createleftovers_test.go
+++ b/internal/console/createleftovers_test.go
@@ -195,7 +195,7 @@ func TestCreateRefusesAnotherRegionUntilTheHistoryIsActive(t *testing.T) {
fx.leaveReplica(t, d.host)
}
status, _, out := rawReq(t, http.MethodPost, d.url(fx.consoleFixture), fx.token, d.body)
- if status != http.StatusConflict || !strings.Contains(out, "can't be created in ie yet, because this console can't check there") {
+ if status != http.StatusConflict || !strings.Contains(out, "can't be created in ie: this console can't check ie") {
t.Fatalf("create = %d %s, want the out-of-sight 409", status, out)
}
if d.exists(t, fx.consoleFixture) {
diff --git a/internal/console/datatransfer.go b/internal/console/datatransfer.go
new file mode 100644
index 000000000..b9dddd82a
--- /dev/null
+++ b/internal/console/datatransfer.go
@@ -0,0 +1,149 @@
+package console
+
+import (
+ "context"
+ "log"
+ "net/http"
+
+ "github.com/carlosframework/platform/internal/provision"
+)
+
+// The one admission rule for binding data-kind records to storage (hunt
+// H3-M6, Paul's ruling 2026-11-30: refuse up front, one shared rule).
+//
+// A box keeps a record's database under its HOST alone, and a deleted
+// record's data stays where it was. Any door that puts a data-kind record
+// on storage it was not on (a create, a move's start or stage, an app's
+// placement onto a fleet or back home) can hand that record another
+// owner's data unless the destination is proved free of it. Every such
+// door calls dataTransferRefusal before its first write;
+// TestEveryDataTransferDoorAsksTheSharedRule fails a door that does not.
+//
+// The rule, per record, by where the destination's data lives:
+// - In sight (a data bucket here, unpooled, the console's own region):
+// the bucket's replica and staging prefixes are checked for each host
+// (hostHoldsReplicaData). Held is 409, unreadable is 503.
+// - Out of sight (another region's bucket, a fleet): admitted only when
+// the hostname history is active AND the destination was examined and
+// is still covered: hostsTargetRefusal (examined, not closed) and
+// hostsCoverageRefusal (no box or bucket added since), the facts a
+// create already meets. Every host that ever held data in an examined
+// target was marked, and a record holds a host only once its mark is
+// new (S1). Anything else is 409, telling an operator what to run;
+// an unreadable history is 503.
+// - Neither (a pooled record, a console with no data bucket): the data a
+// deleted record left is on a box's disk, which the console cannot
+// read. Not proved safe; it is the box owner binding's to refuse
+// (docs/superpowers/notes/2026-11-30-h3-m6-box-owner-binding.md).
+//
+// A transfer with no data-kind record admits at once.
+
+// dataTransfer is one door's request, as the rule needs it.
+type dataTransfer struct {
+ logTag string
+ // recs are the data-kind records the door binds at to: Host and Pool
+ // are read. A create passes the record it would write.
+ recs []provision.Record
+ // to is the destination in the record's Region form ("" home,
+ // "fleet/<name>").
+ to string
+ // what opens every refusal: "acme can't move to uk", given the
+ // destination's label.
+ what func(place string) string
+ // taken and unsure, when set, replace the in-sight answers (the create
+ // doors' approved sentences).
+ taken func(host string) string
+ unsure string
+}
+
+func (s *Server) dataTransferRefusal(ctx context.Context, t dataTransfer) *doorRefusal {
+ if len(t.recs) == 0 {
+ return nil
+ }
+ place := s.offlinePlace(t.to)
+ what := t.what(place)
+ outOfSight := ""
+ for _, rec := range t.recs {
+ switch {
+ case s.leftoverCheckApplies(t.to, rec.Pool):
+ held, err := s.hostHoldsReplicaData(ctx, rec.Host)
+ if err != nil {
+ log.Printf("console: %s: leftover replica check for %s: %v", t.logTag, rec.Host, err)
+ msg := what + ": the data in " + place + " could not be checked. Try again."
+ if t.unsure != "" {
+ msg = t.unsure
+ }
+ return &doorRefusal{Status: http.StatusServiceUnavailable, Msg: msg}
+ }
+ if held {
+ log.Printf("console: %s: refused: %s still holds replica data from a deleted record (H3-M6)", t.logTag, rec.Host)
+ msg := msgTransferHeld(what, rec.Host, place)
+ if t.taken != nil {
+ msg = t.taken(rec.Host)
+ }
+ return &doorRefusal{Status: http.StatusConflict, Msg: msg}
+ }
+ case s.leftoverOutOfSight(t.to, rec.Pool):
+ if outOfSight == "" {
+ outOfSight = rec.Host
+ }
+ }
+ }
+ if outOfSight == "" {
+ return nil
+ }
+ return s.outOfSightTransfer(ctx, t, what, place, outOfSight)
+}
+
+// outOfSightTransfer is the out-of-sight half: an active history that
+// examined and still covers the destination, or a refusal.
+func (s *Server) outOfSightTransfer(ctx context.Context, t dataTransfer, what, place, host string) *doorRefusal {
+ unreadable := &doorRefusal{Status: http.StatusServiceUnavailable, Msg: msgTransferUnreadable(what, place)}
+ mode, err := s.hostsMode(ctx)
+ if err != nil {
+ log.Printf("console: %s: read the hostname history's mode: %v", t.logTag, err)
+ return unreadable
+ }
+ if mode != provision.HostsModeActive {
+ log.Printf("console: %s: refused: %s's data would be in %q, out of this console's sight, and the hostname history is %s (H3-M6)", t.logTag, host, t.to, mode)
+ if s.cfg.HostClaim || s.cfg.MovesEnabled {
+ return &doorRefusal{Status: http.StatusConflict, Msg: msgTransferNeverChecked(what, place, host)}
+ }
+ return &doorRefusal{Status: http.StatusConflict, Msg: msgTransferUnchecked(what, place, host)}
+ }
+ for _, check := range []func(context.Context, string) *doorRefusal{s.hostsTargetRefusal, s.hostsCoverageRefusal} {
+ if ref := check(ctx, t.to); ref != nil {
+ if ref.Status == http.StatusServiceUnavailable {
+ return unreadable
+ }
+ log.Printf("console: %s: refused: %q was not examined, or is not covered as recorded, by the active hostname history (H3-M6)", t.logTag, t.to)
+ return &doorRefusal{Status: http.StatusConflict, Msg: msgTransferUncovered(what, place)}
+ }
+ }
+ return nil
+}
+
+// The rule's sentences. what is the door's opening ("acme can't move to
+// uk"), place the destination's label, host the record's hostname.
+func msgTransferHeld(what, host, place string) string {
+ return what + ": " + host + " still holds data a deleted record left in " + place + ". An operator has to remove that data first."
+}
+
+func msgTransferUnreadable(what, place string) string {
+ return what + ": the hostname history, or what " + place + " runs on, could not be read. Try again."
+}
+
+func msgTransferUnchecked(what, place, host string) string {
+ return what + ": this console can't check " + place + " for data a deleted record left under " + host +
+ ". An operator can allow it by completing the hostname history (console hosts-used) with " + place + " scanned."
+}
+
+func msgTransferNeverChecked(what, place, host string) string {
+ return what + ": this console can't check " + place + " for data a deleted record left under " + host +
+ ", and its hostname history can't be completed while host claims or Phase 1 moves are on."
+}
+
+func msgTransferUncovered(what, place string) string {
+ return what + ": " + place + " was not scanned when the hostname history was completed, or its boxes or data bucket have changed since." +
+ " An operator can allow it by completing the history again with " + place + " scanned."
+}
diff --git a/internal/console/datatransfer_guard_test.go b/internal/console/datatransfer_guard_test.go
new file mode 100644
index 000000000..3eefab381
--- /dev/null
+++ b/internal/console/datatransfer_guard_test.go
@@ -0,0 +1,177 @@
+package console
+
+// The guard for the shared data-transfer rule (H3-M6, datatransfer.go): no
+// console door may bind a data-kind record to storage without asking
+// dataTransferRefusal. It reads the package's own source. A function that
+// rewrites a record's region (SetRecordRegion) or builds a move's start
+// (MoveRequest, MoveStartTransition, OfflineStart, OfflineStage) must reach
+// the rule through this package's calls, and so must every door named in
+// transferDoors (the create doors write through helpers the sinks do not
+// name). A new door that skips the rule fails here.
+
+import (
+ "go/ast"
+ "go/parser"
+ "go/token"
+ "os"
+ "path/filepath"
+ "sort"
+ "strings"
+ "testing"
+)
+
+// transferSinks are the provision calls that put an existing record on
+// other storage, or begin to.
+var transferSinks = map[string]bool{
+ "SetRecordRegion": true, "MoveRequest": true, "MoveStartTransition": true,
+ "OfflineStart": true, "OfflineStage": true,
+}
+
+// transferDoors must reach the rule whatever they call.
+var transferDoors = []string{
+ "handleAPIInstanceCreate", "handleAPISidecarCreate",
+ "legacyHandleAPIInstanceMoveRequest", "handleAPIInstanceMoveRequest",
+ "handleAPIInstanceOfflineStart", "handleAPIInstanceOfflineStage",
+ "placeAppTarget",
+}
+
+const transferRule = "dataTransferRefusal"
+
+// transferGraph is each declared function's (or method's, by name) set of
+// referenced names, and the sinks it calls.
+type transferGraph struct {
+ refs map[string]map[string]bool
+ sinks map[string][]string
+}
+
+func buildTransferGraph(fset *token.FileSet, files []*ast.File) transferGraph {
+ g := transferGraph{refs: map[string]map[string]bool{}, sinks: map[string][]string{}}
+ for _, f := range files {
+ for _, d := range f.Decls {
+ fd, ok := d.(*ast.FuncDecl)
+ if !ok || fd.Body == nil {
+ continue
+ }
+ name := fd.Name.Name
+ if g.refs[name] == nil {
+ g.refs[name] = map[string]bool{}
+ }
+ ast.Inspect(fd.Body, func(n ast.Node) bool {
+ switch x := n.(type) {
+ case *ast.SelectorExpr:
+ g.refs[name][x.Sel.Name] = true
+ if id, ok := x.X.(*ast.Ident); ok && id.Name == "provision" && transferSinks[x.Sel.Name] {
+ g.sinks[name] = append(g.sinks[name], x.Sel.Name+"@"+fset.Position(x.Pos()).String())
+ }
+ case *ast.Ident:
+ g.refs[name][x.Name] = true
+ }
+ return true
+ })
+ }
+ }
+ return g
+}
+
+// reaches reports whether from refers, directly or through the package's
+// own functions, to the rule.
+func (g transferGraph) reaches(from string) bool {
+ seen := map[string]bool{}
+ stack := []string{from}
+ for len(stack) > 0 {
+ f := stack[len(stack)-1]
+ stack = stack[:len(stack)-1]
+ if seen[f] {
+ continue
+ }
+ seen[f] = true
+ for r := range g.refs[f] {
+ if r == transferRule {
+ return true
+ }
+ if _, declared := g.refs[r]; declared && !seen[r] {
+ stack = append(stack, r)
+ }
+ }
+ }
+ return false
+}
+
+// transferProblems is every sink function and named door that does not
+// reach the rule.
+func transferProblems(g transferGraph, doors []string) []string {
+ var out []string
+ for f, sites := range g.sinks {
+ if f != transferRule && !g.reaches(f) {
+ out = append(out, f+" writes a record's storage ("+strings.Join(sites, ", ")+") without asking "+transferRule)
+ }
+ }
+ for _, d := range doors {
+ if _, ok := g.refs[d]; !ok {
+ out = append(out, "door "+d+" is gone: update transferDoors")
+ } else if !g.reaches(d) {
+ out = append(out, "door "+d+" does not ask "+transferRule)
+ }
+ }
+ sort.Strings(out)
+ return out
+}
+
+func TestEveryDataTransferDoorAsksTheSharedRule(t *testing.T) {
+ fset := token.NewFileSet()
+ paths, err := filepath.Glob("*.go")
+ if err != nil {
+ t.Fatal(err)
+ }
+ var files []*ast.File
+ for _, p := range paths {
+ if strings.HasSuffix(p, "_test.go") {
+ continue
+ }
+ f, err := parser.ParseFile(fset, p, nil, 0)
+ if err != nil {
+ t.Fatal(err)
+ }
+ files = append(files, f)
+ }
+ g := buildTransferGraph(fset, files)
+ if len(g.sinks) < 4 {
+ t.Fatalf("found sinks only in %v: the walk is broken", g.sinks)
+ }
+ if p := transferProblems(g, transferDoors); len(p) > 0 {
+ t.Fatalf("data-transfer guard:\n %s", strings.Join(p, "\n "))
+ }
+}
+
+// The guard fails a door that skips the rule, directly or through a
+// helper, and passes one that asks it through a helper.
+func TestDataTransferGuardRejectsASkippingDoor(t *testing.T) {
+ src := `package console
+func (s *Server) openDoor() { provision.SetRecordRegion(nil, nil, "", "", "", "") }
+func (s *Server) helperDoor() { s.rewrite() }
+func (s *Server) rewrite() { provision.OfflineStart("", "", "", "", 0) }
+func (s *Server) goodDoor() { if s.check() == nil { provision.MoveRequest("", 0) } }
+func (s *Server) check() *doorRefusal { return s.dataTransferRefusal(nil, dataTransfer{}) }
+func (s *Server) dataTransferRefusal(any, any) *doorRefusal { return nil }
+`
+ dir := t.TempDir()
+ p := filepath.Join(dir, "x.go")
+ if err := os.WriteFile(p, []byte(src), 0o600); err != nil {
+ t.Fatal(err)
+ }
+ fset := token.NewFileSet()
+ f, err := parser.ParseFile(fset, p, nil, 0)
+ if err != nil {
+ t.Fatal(err)
+ }
+ got := transferProblems(buildTransferGraph(fset, []*ast.File{f}), []string{"helperDoor", "goodDoor", "missingDoor"})
+ want := []string{"door helperDoor does not ask", "door missingDoor is gone", "openDoor writes", "rewrite writes"}
+ if len(got) != len(want) {
+ t.Fatalf("problems = %q, want %d", got, len(want))
+ }
+ for i, w := range want {
+ if !strings.HasPrefix(got[i], w) {
+ t.Errorf("problem %d = %q, want prefix %q", i, got[i], w)
+ }
+ }
+}
diff --git a/internal/console/fleets.go b/internal/console/fleets.go
index d6c144d3d..7761e0f92 100644
--- a/internal/console/fleets.go
+++ b/internal/console/fleets.go
@@ -1029,6 +1029,26 @@ func (s *Server) placeAppTarget(ctx context.Context, acct *Account, app, target
if len(stale) > 0 {
return http.StatusConflict, staleSealedRefusal(app, stale)
}
+ // The shared data-transfer rule (H3-M6, datatransfer.go), before the
+ // claim's start and before any write: a place re-homes every changed
+ // record onto the target's storage, in both directions (onto a fleet,
+ // and back to "" home), and a data-kind record there could inherit a
+ // deleted record's data under its host. An app whose changed records
+ // are all exempt kinds (static, service) places as before.
+ var moving []provision.Record
+ for _, rec := range changed {
+ if rec.DataKind() {
+ moving = append(moving, rec)
+ }
+ }
+ if ref := s.dataTransferRefusal(ctx, dataTransfer{
+ logTag: "place " + acct.Sqid + "/" + app,
+ recs: moving,
+ to: target,
+ what: func(place string) string { return app + "'s instances can't move to " + place },
+ }); ref != nil {
+ return ref.Status, ref.Msg
+ }
// An app with a fleet size moves only to a fleet of the account's own
// whose every box has room for it (#892 S2 P7, PS-2-C14), before
// anything is written. A host-claim console hands the walk to the
diff --git a/internal/console/ha_pool_scope_test.go b/internal/console/ha_pool_scope_test.go
index 30624128e..8e49c3dfa 100644
--- a/internal/console/ha_pool_scope_test.go
+++ b/internal/console/ha_pool_scope_test.go
@@ -188,6 +188,15 @@ func haPoolWorldNew(t *testing.T, region, pool string, tweak func(*Config)) *haP
return w
}
+// legacyAdmitted makes the hostname history active over the world's region
+// as it is now, so a legacy (non-HA, unpooled) control create there passes
+// the shared data-transfer rule (H3-M6): the region is out of the home
+// console's sight.
+func (w *haPoolWorld) legacyAdmitted(t *testing.T) {
+ t.Helper()
+ forceHostsState(t, w.srv, provision.HostsState{Mode: provision.HostsModeActive, Examined: []string{"region:" + w.region}})
+}
+
func (w *haPoolWorld) edge(t *testing.T, ref string, edit func(map[string]any)) {
t.Helper()
body := haEdit(t, haGolden(t), func(m map[string]any) {
@@ -408,6 +417,7 @@ func TestHAPoolLegacyMatchesDisabled(t *testing.T) {
}
})
w.srv.haCapacity.Store(nil)
+ w.legacyAdmitted(t)
code, _, out := w.post(t, sidecar, w.body(sidecar))
if code != 201 {
t.Fatalf("legacy=%d %s", code, out)
@@ -473,6 +483,9 @@ func TestHAPoolShapeAndDevScope(t *testing.T) {
m := titoSidecarManifest()
m.Pool, m.Regions, m.Hibernate = pool, nil, &no
enableSidecars(t, w.consoleFixture, "titogo", m)
+ if pool == "" {
+ w.legacyAdmitted(t)
+ }
w.track()
code, _, out := w.post(t, true, w.body(true))
if pool == "ha" {
@@ -526,6 +539,7 @@ func TestHAPoolMixedStorage(t *testing.T) {
m := titoManifest()
m.Pool, m.Regions = "", nil
enableInstances(t, w.consoleFixture, "titogo", m)
+ w.legacyAdmitted(t)
code, _, out = w.post(t, false, `{"host":"plain.go.tito.io","region":"us"}`)
if code != 201 {
t.Fatalf("plain create blocked by mixed storage=%d %s", code, out)
@@ -578,6 +592,10 @@ func TestHAPoolTransfersRemainRegional(t *testing.T) {
if err := w.st.SetOperator("alice@keymail.dev", true); err != nil {
t.Fatal(err)
}
+ // A legacy create out of the console's region is admitted by the
+ // shared data-transfer rule (H3-M6) only under an active history
+ // that examined it.
+ forceHostsState(t, w.srv, provision.HostsState{Mode: provision.HostsModeActive, Examined: []string{"region:ie", "region:us"}})
code, _, out := w.post(t, false, fmt.Sprintf(`{"host":"acme.go.tito.io","region":%q}`, from))
if code != 201 {
t.Fatalf("legacy setup=%d %s", code, out)
@@ -639,7 +657,15 @@ func TestHAPoolUnprovenStorage(t *testing.T) {
m := titoManifest()
m.Pool, m.Regions = "", nil
enableInstances(t, w.consoleFixture, "titogo", m)
- if code, _, out = w.post(t, false, `{"host":"plain.go.tito.io","region":"us"}`); code != 201 {
+ // The plain control runs with no data bucket, which the shared
+ // data-transfer rule (H3-M6) leaves to the box: an active history
+ // would refuse it here, since the unproven box's edges file does
+ // not read complete.
+ bucket := w.srv.cfg.HibernateBucket
+ w.srv.cfg.HibernateBucket = ""
+ code, _, out = w.post(t, false, `{"host":"plain.go.tito.io","region":"us"}`)
+ w.srv.cfg.HibernateBucket = bucket
+ if code != 201 {
t.Fatalf("plain create blocked=%d %s", code, out)
}
})
diff --git a/internal/console/hapool_test.go b/internal/console/hapool_test.go
index f53679f80..e5e2ae513 100644
--- a/internal/console/hapool_test.go
+++ b/internal/console/hapool_test.go
@@ -116,6 +116,9 @@ func haPoolGateWorld(t *testing.T, region, pool string, tweak func(*Config)) *ha
w := haPoolWorldNew(t, region, pool, tweak)
list := w.srv.cfg.HAPoolAccounts
w.srv.cfg.HAPoolAccounts = []string{"bab"}
+ if pool == "" {
+ w.legacyAdmitted(t)
+ }
if code, _, out := w.post(t, false, fmt.Sprintf(`{"host":%q,"region":%q}`, haGateProbeHost, region)); code != http.StatusCreated {
t.Fatalf("fixture success control (instance) = %d %s", code, out)
}
diff --git a/internal/console/moveleftovers.go b/internal/console/moveleftovers.go
index 9cc4487d8..6fd21d0c1 100644
--- a/internal/console/moveleftovers.go
+++ b/internal/console/moveleftovers.go
@@ -2,60 +2,39 @@ 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).
+// The move doors' use of the shared admission rule (datatransfer.go, hunt
+// H3-M6). 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). Every door that
+// starts a move asks the rule before its first write: the legacy request,
+// the Phase 1 request, and the offline start and stage
+// (offlineBeginChecks).
//
-// 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."
-}
+// A destination in sight gets the bucket check, as a create does: an
+// instance created out of sight before the rule existed was never checked
+// there. A move back to a region whose prefix still holds this instance's
+// own lineage from an earlier stay is refused with it, until an operator
+// removes that copy (the staged copy would have replaced it). Fleet and
+// pooled records never reach here (moveGate refuses both).
-// 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
+// moveTransferRefusal is nil when a move of rec to the region code to may
+// start, else the shared rule's refusal.
+func (s *Server) moveTransferRefusal(ctx context.Context, logTag string, rec *provision.Record, to string) *doorRefusal {
+ var recs []provision.Record
+ if rec.DataKind() {
+ recs = []provision.Record{*rec}
}
- 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))}
+ return s.dataTransferRefusal(ctx, dataTransfer{
+ logTag: logTag,
+ recs: recs,
+ to: to,
+ what: func(place string) string { return rec.Host + " can't move to " + place },
+ })
}
diff --git a/internal/console/moveleftovers_h3m6_test.go b/internal/console/moveleftovers_h3m6_test.go
index f157ec052..ac196c6ad 100644
--- a/internal/console/moveleftovers_h3m6_test.go
+++ b/internal/console/moveleftovers_h3m6_test.go
@@ -1,26 +1,29 @@
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.
+// Hunt H3-M6, the move route. An instance never woken and moved lands on
+// whatever a deleted record of the same host left at the destination: its
+// source has nothing to stage, so the target's first wake restores the
+// target's own prefix (activator
+// TestH3M6MoveOfANeverWokenHostLandsOnTheTargetsLeftover). Every move door
+// asks the shared data-transfer rule (datatransfer.go): out of sight, an
+// active history that examined the destination and still covers it; in
+// sight, the bucket check. The tests go through the production doors.
import (
"context"
"net/http"
+ "path/filepath"
"strings"
"testing"
+ lsfile "github.com/benbjohnson/litestream/file"
+
+ "github.com/carlosframework/platform/internal/activator"
+ "github.com/carlosframework/platform/internal/dbdoor/dbdoortest"
"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."
+func moveWhat(host, place string) string { return host + " can't move to " + place }
// moveFixture is leftoverFixture (a data bucket, this console in ie) with
// titogo's acme created in ie, where the rail checked it clean.
@@ -53,25 +56,59 @@ func activeHistory(t *testing.T, fx *leftoverFx) {
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 {
+const ukEdges = `{"v":1,"box":"uk-box","eip":"1.2.3.4","placement":"uk","data_bucket":"data-uk","data_bucket_region":"eu-west-2","hosts":{}}`
+
+func legacyMoveFixture(t *testing.T, code string) (*leftoverFx, string) {
+ t.Helper()
+ fx, moveURL := moveFixture(t, code)
+ if _, err := fx.rel.Put(context.Background(), "control/edges/uk-box.json", []byte(ukEdges), ""); err != nil {
t.Fatal(err)
}
+ return fx, moveURL
+}
+
+func TestH3M6LegacyMoveOutOfSightIsRefused(t *testing.T) {
+ fx, moveURL := legacyMoveFixture(t, "code-h3m6-move-legacy")
+ want := msgTransferUnchecked(moveWhat("acme.go.tito.io", "uk"), "uk", "acme.go.tito.io")
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)
+ if code != http.StatusConflict || errorText(out) != want {
+ t.Fatalf("move to uk = %d %s, want 409 %q", code, out, want)
}
noMoveOnRecord(t, fx)
- // Once the history is active the host was proved free when it was
- // created (S1), and the move goes ahead.
+ // Active, with uk examined and covered as it is now: admitted.
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)
}
}
+// Active history is not enough by itself (round 2, Astra P1-2): a region
+// added after activation was never examined, and a region whose data
+// bucket changed since is not covered as recorded. Both are refused, with
+// nothing written.
+func TestH3M6ActiveHistoryMoveNeedsTheDestinationCovered(t *testing.T) {
+ for _, c := range []struct {
+ name string
+ st provision.HostsState
+ }{
+ {"region added after activation", provision.HostsState{Mode: provision.HostsModeActive, Examined: []string{"region:ie"},
+ RegionTargets: []string{"box:ie-box"}}},
+ {"bucket changed since", provision.HostsState{Mode: provision.HostsModeActive, Examined: []string{"region:ie", "region:uk"},
+ RegionTargets: []string{"box:uk-box", "bucket:data-uk-old"}}},
+ } {
+ t.Run(c.name, func(t *testing.T) {
+ fx, moveURL := legacyMoveFixture(t, "code-h3m6-move-cov-"+strings.ReplaceAll(c.name, " ", "-"))
+ forceHostsState(t, fx.srv, c.st)
+ want := msgTransferUncovered(moveWhat("acme.go.tito.io", "uk"), "uk")
+ code, _, out := rawReq(t, http.MethodPost, moveURL, fx.token, `{"region":"uk"}`)
+ if code != http.StatusConflict || errorText(out) != want {
+ t.Fatalf("move = %d %s, want 409 %q", code, out, want)
+ }
+ noMoveOnRecord(t, fx)
+ })
+ }
+}
+
func TestH3M6Phase1MoveOutOfSightIsRefused(t *testing.T) {
fx, moveURL := moveFixture(t, "code-h3m6-move-p1")
if err := fx.st.SetOperator("alice@keymail.dev", true); err != nil {
@@ -80,9 +117,11 @@ func TestH3M6Phase1MoveOutOfSightIsRefused(t *testing.T) {
enableMovesPhase1(fx.consoleFixture)
armMoveFleet(t, fx.consoleFixture, ieBox("ie-box"), ukBox("uk-box"))
claimFor(t, fx.consoleFixture, "acme.go.tito.io", "ie-box", "ie")
+ // Phase 1 is on, so the history can never be completed here.
+ want := msgTransferNeverChecked(moveWhat("acme.go.tito.io", "uk"), "uk", "acme.go.tito.io")
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)
+ if code != http.StatusConflict || errorText(out) != want {
+ t.Fatalf("move to uk = %d %s, want 409 %q", code, out, want)
}
noMoveOnRecord(t, fx)
activeHistory(t, fx)
@@ -92,14 +131,14 @@ func TestH3M6Phase1MoveOutOfSightIsRefused(t *testing.T) {
}
// The offline doors, start and stage: refused out of sight with nothing
-// written, and admitted once the history is active.
+// written, and admitted once the history is active and covers uk.
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.")
+ msgTransferUnchecked(moveWhat(offlineHost, "uk"), "uk", offlineHost))
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)
@@ -108,17 +147,35 @@ func TestH3M6OfflineMoveOutOfSightIsRefused(t *testing.T) {
}
}
-// 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) {
+// fileReplicas points srv's replica reader at a directory, as
+// leftoverFixture does, and returns it.
+func fileReplicas(t *testing.T, srv *Server) string {
+ t.Helper()
+ root := t.TempDir()
+ srv.cfg.HibernatePrefix = "instances"
+ srv.dbReplica = rootReplica(func(_ context.Context, prefix string) (replicaReader, error) {
+ return lsfile.NewReplicaClient(filepath.Join(root, prefix)), nil
+ })
+ return root
+}
+
+// A move into this console's own region gets the bucket check a create
+// gets: a clean prefix admits it, a deleted record's replica refuses it.
+func TestH3M6MoveIntoTheConsolesRegionIsChecked(t *testing.T) {
w := newOfflineWorld(t, oneEach...)
w.fx.srv.cfg.HibernateBucket, w.fx.srv.cfg.Region = "data-uk", "uk"
- w.start()
+ root := fileReplicas(t, w.fx.srv)
+ dbdoortest.Replicate(t, filepath.Join(root, activator.HibernatePrefix("instances", offlineHost)), 1)
+ w.refused(http.MethodPost, "", `{"region":"uk"}`, http.StatusConflict,
+ msgTransferHeld(moveWhat(offlineHost, "uk"), offlineHost, "uk"))
+
+ clean := newOfflineWorld(t, oneEach...)
+ clean.fx.srv.cfg.HibernateBucket, clean.fx.srv.cfg.Region = "data-uk", "uk"
+ fileReplicas(t, clean.fx.srv)
+ clean.start()
}
-// The refusal and the place it names, for every shape of destination.
+// Which destinations are out of the rail's sight.
func TestMoveOutOfSight(t *testing.T) {
s := &Server{}
for _, c := range []struct {
diff --git a/internal/console/placeleftovers_h3m6_test.go b/internal/console/placeleftovers_h3m6_test.go
new file mode 100644
index 000000000..82f951bf7
--- /dev/null
+++ b/internal/console/placeleftovers_h3m6_test.go
@@ -0,0 +1,126 @@
+package console
+
+// Hunt H3-M6, the place route (round 2, Astra P1-1 and Fable P1): `carlos
+// apps place` re-homes every existing record of an app onto the target's
+// storage. Onto a fleet, the fleet box's first wake restores the fleet
+// bucket's prefix for the host; back home, the home bucket's. Both
+// directions ask the shared data-transfer rule before any write.
+
+import (
+ "context"
+ "net/http"
+ "testing"
+
+ "github.com/carlosframework/platform/internal/provision"
+)
+
+func placeWhat(app, place string) string { return app + "'s instances can't move to " + place }
+
+// placeFixture is leftoverFixture on a home console (region ""), with
+// fleet eleven, and the owner's token (place is owner-only).
+func h3m6PlaceFixture(t *testing.T, code string) (*leftoverFx, string) {
+ t.Helper()
+ fx := leftoverFixture(t, code)
+ fx.srv.cfg.Region = ""
+ m := titoManifest()
+ m.Regions, m.Pool = nil, ""
+ enableInstances(t, fx.consoleFixture, "titogo", m)
+ if status, body := postJSON(t, fx.ts.URL+"/api/cli/fleets/bab/new",
+ map[string]string{"name": "eleven", "bucket": "eleven-fleet-data"}, fx.token); status != http.StatusOK {
+ t.Fatalf("create fleet = %d %v", status, body)
+ }
+ return fx, cliToken(t, fx.consoleFixture, "paul@keymail.dev", code+"-owner")
+}
+
+func h3m6Place(t *testing.T, fx *leftoverFx, owner, target string) (int, map[string]any) {
+ t.Helper()
+ return postJSON(t, fx.ts.URL+"/api/cli/apps/bab/titogo/place", map[string]string{"target": target}, owner)
+}
+
+func acmeRegion(t *testing.T, fx *leftoverFx) string {
+ t.Helper()
+ rec, err := provision.GetRecord(context.Background(), fx.rel, "bab", "titogo", "acme.go.tito.io")
+ if err != nil {
+ t.Fatal(err)
+ }
+ return rec.Region
+}
+
+func createAcme(t *testing.T, fx *leftoverFx) {
+ t.Helper()
+ if c, _, out := rawReq(t, http.MethodPost, instancesURL(fx.consoleFixture, "bab", "titogo"), fx.token,
+ `{"host":"acme.go.tito.io"}`); c != http.StatusCreated {
+ t.Fatalf("create = %d %s", c, out)
+ }
+}
+
+// Onto a fleet: the fleet's bucket is out of sight, so with the history
+// not active the place is refused before any write, the app's placement
+// and the record's region left as they were.
+func TestH3M6PlaceOntoAFleetIsRefused(t *testing.T) {
+ fx, owner := h3m6PlaceFixture(t, "code-h3m6-place-fleet")
+ createAcme(t, fx) // home, in sight, checked clean
+ status, body := h3m6Place(t, fx, owner, "fleet/eleven")
+ want := msgTransferUnchecked(placeWhat("titogo", "fleet eleven"), "fleet eleven", "acme.go.tito.io")
+ if status != http.StatusConflict || body["error"] != want {
+ t.Fatalf("place = %d %v, want 409 %q", status, body, want)
+ }
+ if r := acmeRegion(t, fx); r != "" {
+ t.Fatalf("a refused place re-homed the record to %q", r)
+ }
+ if p, _, err := fx.st.appPlacementRow(context.Background(), OpsAccountID, "titogo"); err != nil || p != "" {
+ t.Fatalf("a refused place wrote the placement %q (%v)", p, err)
+ }
+}
+
+// Back home: the home bucket is in sight, so a deleted record's replica
+// under the host refuses the unplace, and a clean one admits it.
+func TestH3M6UnplaceBackHomeIsChecked(t *testing.T) {
+ fx, owner := h3m6PlaceFixture(t, "code-h3m6-place-home")
+ // Put acme on the fleet the way a console with no data bucket would,
+ // which checks nothing (the box owner binding's case).
+ bucket := fx.srv.cfg.HibernateBucket
+ fx.srv.cfg.HibernateBucket = ""
+ createAcme(t, fx)
+ if status, body := h3m6Place(t, fx, owner, "fleet/eleven"); status != http.StatusOK {
+ t.Fatalf("place with no data bucket = %d %v", status, body)
+ }
+ fx.srv.cfg.HibernateBucket = bucket
+ if r := acmeRegion(t, fx); r != "fleet/eleven" {
+ t.Fatalf("record region = %q", r)
+ }
+ fx.leaveReplica(t, "acme.go.tito.io") // another record's, deleted
+ status, body := h3m6Place(t, fx, owner, "")
+ want := msgTransferHeld(placeWhat("titogo", "the home region"), "acme.go.tito.io", "the home region")
+ if status != http.StatusConflict || body["error"] != want {
+ t.Fatalf("unplace = %d %v, want 409 %q", status, body, want)
+ }
+ if r := acmeRegion(t, fx); r != "fleet/eleven" {
+ t.Fatalf("a refused unplace re-homed the record to %q", r)
+ }
+}
+
+func TestH3M6UnplaceOntoACleanHomeIsAdmitted(t *testing.T) {
+ fx, owner := h3m6PlaceFixture(t, "code-h3m6-place-clean")
+ bucket := fx.srv.cfg.HibernateBucket
+ fx.srv.cfg.HibernateBucket = ""
+ createAcme(t, fx)
+ if status, body := h3m6Place(t, fx, owner, "fleet/eleven"); status != http.StatusOK {
+ t.Fatalf("place = %d %v", status, body)
+ }
+ fx.srv.cfg.HibernateBucket = bucket
+ if status, body := h3m6Place(t, fx, owner, ""); status != http.StatusOK {
+ t.Fatalf("unplace onto a clean home = %d %v, want 200", status, body)
+ }
+ if r := acmeRegion(t, fx); r != "" {
+ t.Fatalf("record region = %q, want home", r)
+ }
+}
+
+// An app with no data-kind record places as before.
+func TestH3M6PlaceWithNoDataRecordIsAdmitted(t *testing.T) {
+ fx, owner := h3m6PlaceFixture(t, "code-h3m6-place-empty")
+ if status, body := h3m6Place(t, fx, owner, "fleet/eleven"); status != http.StatusOK {
+ t.Fatalf("place = %d %v, want 200", status, body)
+ }
+}