carlos / platform Public

Regional domains (#447): T10 fix round 1 (P1: floor judgment held through publication)

The regional floor's binding judgment and the conditional pointer write
now run together under regionalMu (regionalFloorPublish) on promote,
rollback and the held-rollback retry. A held reservation that has not
been published is judged again; one that already landed keeps its
idempotent answer. The placements PUT barrier also refuses (RD-45,
draft) while a system channel that fresh boxes follow is published
below the floor. Spec §11 rows rev 5.3.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 151d1acd7a81a8b30ceffa6bada9155d0457bd88 parent 4d469ff
9 files changed, +409 −28
  • docs/superpowers/plans/2026-10-28-regional-domains-447-copy.md +1 −0
  • docs/superpowers/specs/2026-10-28-regional-domains-447-design.md +3 −3
  • internal/console/apiplacements.go +59 −1
  • internal/console/apiplacements_put_test.go +66 −1
  • internal/console/hostactivation.go +37 −10
  • internal/console/regionalfloor.go +58 −0
  • internal/console/regionalfloor_test.go +166 −9
  • internal/console/rootfsfloor.go +12 −4
  • internal/console/server.go +7 −0

Intent

Human

<task-notification> <task-id>af17d5e1dbe1fd0b0</task-id> <tool-use-id>toolu_018fLXdwfiKFMrBkZzCu1YSb</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/c2acaf22-306d-491b-b2b6-addbf33b8e87/tasks/af17d5e1dbe1fd0b0.output</output-file> <status>completed</status> <summary>Agent "Controller: build regional domains #447" is waiting on its own background work</summary> <note>This agent stopped with background work of its own still running. It may resume on its own when that work completes or reports, and the same task-id notifies again if it does; the result below may be interim.</note> <result>I'm waiting for the Task 10 fix to be committed. If nothing lands within the 20-minute watch, I'll prompt the agent to commit.</result> <usage><subagent_tokens>357460</subagent_tokens><tool_uses>14</tool_uses><duration_ms>6262432</duration_ms></usage> </task-notification>

Human

<task-notification> <task-id>af17d5e1dbe1fd0b0</task-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/c2acaf22-306d-491b-b2b6-addbf33b8e87/tasks/af17d5e1dbe1fd0b0.output</output-file> <status>completed</status> <summary>Agent "Controller: build regional domains #447" is waiting on its own background work</summary> <note>This agent stopped with background work of its own still running. It may resume on its own when that work completes or reports, and the same task-id notifies again if it does; the result below may be interim.</note> <result>I've asked the agent to commit now and am watching for the commit.</result> <usage><subagent_tokens>358237</subagent_tokens><tool_uses>16</tool_uses><duration_ms>7469367</duration_ms></usage> </task-notification>

diff --git a/docs/superpowers/plans/2026-10-28-regional-domains-447-copy.md b/docs/superpowers/plans/2026-10-28-regional-domains-447-copy.md
index 4e10a4ed1..30d0d7909 100644
--- a/docs/superpowers/plans/2026-10-28-regional-domains-447-copy.md
+++ b/docs/superpowers/plans/2026-10-28-regional-domains-447-copy.md
@@ -86,6 +86,7 @@ count.
| RD-40 | internal/console/apiplacements.go | given a regional domain | draft |
| RD-41 | internal/console/apiplacements.go | <box> does not say which release it runs. try again when every server runs <floor> or later. | draft |
| RD-44 | internal/console/apiplacements.go | <host> is a regional domain. carlos domains placements shows the addresses to point DNS at in each region. | draft |
+| RD-45 | internal/console/apiplacements.go | servers on the <channel> channel are moving to <release>, which cannot serve regional domains. try again when they move to <floor> or later. | draft |
## Release floor (operators: internal/release, internal/console, system.go)
diff --git a/docs/superpowers/specs/2026-10-28-regional-domains-447-design.md b/docs/superpowers/specs/2026-10-28-regional-domains-447-design.md
index 1b5d5eb0d..8a5b5713e 100644
--- a/docs/superpowers/specs/2026-10-28-regional-domains-447-design.md
+++ b/docs/superpowers/specs/2026-10-28-regional-domains-447-design.md
@@ -999,14 +999,14 @@ A the deployment's accounts and K their apps:
| Act | Reads | Writes |
|---|---|---|
-| PUT (rev 4, recounted for R3 P2-1 and P2-2) | (1) claim GET with ETag (step 4). (2) Overlap GETs (§6.7): `domains/*.X.json` always, plus `domains/P.json` and `domains/*.P.json` when P has an interior dot: 1 or 3. (3) Binding records (step 3): 1 LIST + R bodies, as `listRecords` makes them (plus each record's lifetime slot when lifetimes are on). (4) Declared-ownership walk (step 5): 1 LIST of `accounts/` + A manifest GETs, then 1 ListDirs of `apps/` + A ListDirs + K LISTs of `instances/`, keys only, no record bodies (on a store without bucket ListDirs, `listAppSubtree`'s fallback: the `apps/` listing). (5) One snapshot: edges 1 LIST + B GETs, heartbeats 1 ListMod (or LIST) + H GETs; collision, never-served, overlap, `aliases_read`, barrier and the response all read it. (6) On create, one DNS TXT lookup. (7) (rev 5, R4 P2-1) `PendingForHost`: one query on the console's own SQLite, no bucket request. (8) (rev 5, ruling 6) On create with `wildcard`: one DNS CNAME lookup (the enabling gate's); with `catchall`: the descendant scan, one `domains/` ListMod through `s.claims` plus a GET per key whose mod time moved (cold cache: one per claim). Nothing else: no `heldElsewhere`, so no `DeploymentRoutes` fold, no `ForeignInstanceCatchall` GET and no catch-all app's records; `customDomainRefusal` reads the console's own database | claim PUT and the existing serial bump, only when bytes change |
+| PUT (rev 4, recounted for R3 P2-1 and P2-2) | (1) claim GET with ETag (step 4). (2) Overlap GETs (§6.7): `domains/*.X.json` always, plus `domains/P.json` and `domains/*.P.json` when P has an interior dot: 1 or 3. (3) Binding records (step 3): 1 LIST + R bodies, as `listRecords` makes them (plus each record's lifetime slot when lifetimes are on). (4) Declared-ownership walk (step 5): 1 LIST of `accounts/` + A manifest GETs, then 1 ListDirs of `apps/` + A ListDirs + K LISTs of `instances/`, keys only, no record bodies (on a store without bucket ListDirs, `listAppSubtree`'s fallback: the `apps/` listing). (5) One snapshot: edges 1 LIST + B GETs, heartbeats 1 ListMod (or LIST) + H GETs; collision, never-served, overlap, `aliases_read`, barrier and the response all read it. (6) On create, one DNS TXT lookup. (7) (rev 5, R4 P2-1) `PendingForHost`: one query on the console's own SQLite, no bucket request. (8) (rev 5, ruling 6) On create with `wildcard`: one DNS CNAME lookup (the enabling gate's); with `catchall`: the descendant scan, one `domains/` ListMod through `s.claims` plus a GET per key whose mod time moved (cold cache: one per claim). Nothing else: no `heldElsewhere`, so no `DeploymentRoutes` fold, no `ForeignInstanceCatchall` GET and no catch-all app's records; `customDomainRefusal` reads the console's own database. (9) (rev 5.3) The barrier's channel check: one system pointer GET per channel the fresh heartbeats follow (canary and stable: at most 2), under `regionalMu` | claim PUT and the existing serial bump, only when bytes change |
| GET | claim GET; one snapshot as above | none |
| `Catchall` turned on; instance catch-all attach | as today, plus one `domains/` ListMod through `s.claims`, and a GET per key whose mod time moved (cold cache: one per claim in the deployment) | as today |
| (rev 5) A capability write on a regional claim | the claim GET the door already makes (`apidomains.go:669`), then `SetClaimCapabilities`' own claim GET only for the same values; refused changes make no DNS lookup | none |
| Instance create | as today (`hostClaimHolder` already reads the claim), (rev 4) plus one claim GET for the recheck under the host exclusion (§6.3) | as today |
| `carlos add` on a box (rev 4) | 0 or 1 claim GET per run (§7.3); no polling | as today |
-| System update crossing the floor | door preflight: one ListMod through `s.claims` (+ GETs as above); promotion: another | as today |
-| Rollback crossing the floor | one ListMod (+ GETs as above) | as today |
+| System update crossing the floor | door preflight: one ListMod through `s.claims` (+ GETs as above); promotion: another; (rev 5.3) without the override and with no regional claim found, one more under `regionalMu` just before the pointer write | as today |
+| Rollback crossing the floor | one ListMod (+ GETs as above); (rev 5.3) without the override and with no regional claim found, one more under `regionalMu` just before the pointer write; a retry that meets its own unpublished reservation: one pointer GET, then that ListMod when it crosses | as today |
| Update or rollback not crossing the floor | none | as today |
## 12. Provider boundary
diff --git a/internal/console/apiplacements.go b/internal/console/apiplacements.go
index 0e2ed5479..e32969479 100644
--- a/internal/console/apiplacements.go
+++ b/internal/console/apiplacements.go
@@ -376,6 +376,12 @@ func placementsBelowFloorMsg(box, rel, floor string) string {
return fmt.Sprintf("%s runs %s, which cannot serve regional domains. try again when every server runs %s or later.", box, rel, floor)
}
+// RD-45: a system channel the fresh boxes follow is published below the
+// floor (regionalChannelRefusal).
+func placementsChannelBelowFloorMsg(channel, rel, floor string) string {
+ return fmt.Sprintf("servers on the %s channel are moving to %s, which cannot serve regional domains. try again when they move to %s or later.", channel, rel, floor)
+}
+
// RD-41: RD-23 for a box whose heartbeat names no release.
func placementsNoReleaseMsg(box, floor string) string {
return fmt.Sprintf("%s does not say which release it runs. try again when every server runs %s or later.", box, floor)
@@ -423,7 +429,8 @@ type placementsPutBody struct {
// walk and the pending-operation read, each failing closed;
// 6. the never-served evidence, the collision and overlap tests, and on a
// create with catchall the descendant scan, all the neutral 409;
-// 7. the activation barrier (§10.3) on the heartbeats step 5 loaded;
+// 7. the activation barrier (§10.3) on the heartbeats step 5 loaded,
+// then the system pointers the fresh boxes follow (one GET each);
// 8. proof and, with wildcard, the enabling gate, when the write creates;
// 9. the write, audited and announced only when bytes changed;
// 10. the GET body, built from the step-5 snapshot. No further reads.
@@ -600,6 +607,10 @@ func (s *Server) handleAPIDomainPlacementsPut(w http.ResponseWriter, r *http.Req
jsonError(w, ref.Status, ref.Msg)
return
}
+ if ref := s.regionalChannelRefusal(ctx, boxes, now); ref != nil {
+ jsonError(w, ref.Status, ref.Msg)
+ return
+ }
// Steps 8 and 9.
next := domains.Claim{Host: host, Account: acct.Sqid, App: app, Placements: set}
@@ -915,6 +926,53 @@ func regionalReadyRefusal(boxes []status.Box, now time.Time) *doorRefusal {
return nil
}
+// regionalChannelRefusal is the barrier's second half (#447 T10 R1 P1),
+// run under regionalMu after regionalReadyRefusal has passed every fresh
+// box: a box at the floor today still follows its system channel, so a
+// channel whose published pointer names a release below the floor (or one
+// that does not parse) is a downgrade on its way to boxes the heartbeats
+// still show at the floor. The PUT refuses it, 409 RD-45 naming the first
+// such channel. One pointer GET per channel the fresh heartbeats follow
+// (a box that names none follows stable, as boxSystemChannel does): a
+// channel with no pointer has nothing on its way; a pointer that cannot
+// be read or verified is incomplete evidence, 503 RD-22. The promotion
+// doors publish under the same mutex (regionalFloorPublish), so a
+// downgrade is either published before this read or judged after the
+// claim is written.
+func (s *Server) regionalChannelRefusal(ctx context.Context, boxes []status.Box, now time.Time) *doorRefusal {
+ followed := map[string]bool{}
+ for _, b := range freshHeartbeats(boxes, now) {
+ ch := ""
+ if b.Metrics != nil {
+ ch = b.Metrics.SystemChannel
+ }
+ if ch == "" {
+ ch = release.RungStable
+ }
+ followed[ch] = true
+ }
+ channels := make([]string, 0, len(followed))
+ for ch := range followed {
+ channels = append(channels, ch)
+ }
+ sort.Strings(channels)
+ floor := "v" + release.RegionalDomainsFloor.String()
+ for _, ch := range channels {
+ p, _, err := release.GetSystemPointer(ctx, s.cfg.Releases, s.cfg.ReleasePub, release.SystemComponentRouter, ch)
+ if errors.Is(err, os.ErrNotExist) {
+ continue
+ }
+ if err != nil {
+ log.Printf("console: regional barrier: system pointer %s: %v", ch, err)
+ return &doorRefusal{http.StatusServiceUnavailable, placementsUnreadableMsg}
+ }
+ if v, ok := release.ParseReleaseVersion(p.Current.Version); !ok || v.Compare(release.RegionalDomainsFloor) < 0 {
+ return &doorRefusal{http.StatusConflict, placementsChannelBelowFloorMsg(ch, p.Current.Version, floor)}
+ }
+ }
+ return nil
+}
+
// parentOf is host without its first label ("" for a one-label host).
func parentOf(host string) string {
_, parent, ok := strings.Cut(host, ".")
diff --git a/internal/console/apiplacements_put_test.go b/internal/console/apiplacements_put_test.go
index e3faece44..a99715d9e 100644
--- a/internal/console/apiplacements_put_test.go
+++ b/internal/console/apiplacements_put_test.go
@@ -63,6 +63,8 @@ type regionalBox struct {
// NoMetrics writes a heartbeat with no metrics object; NoEdges writes
// no edges file.
NoMetrics, NoEdges bool
+ // Channel is the heartbeat's metrics.system_channel ("" follows stable).
+ Channel string
}
// rdBox is a fresh box at the floor whose alias read succeeded, publishing
@@ -96,7 +98,7 @@ func (w *regionalWorld) putBox(t *testing.T, b regionalBox) {
t.Helper()
hb := status.Box{GeneratedAt: b.At, Label: b.Label, Region: "eu-west-1"}
if !b.NoMetrics {
- hb.Metrics = &status.BoxMetrics{Release: b.Release, AliasesRead: b.AliasesRead, Aliases: b.Aliases}
+ hb.Metrics = &status.BoxMetrics{Release: b.Release, AliasesRead: b.AliasesRead, Aliases: b.Aliases, SystemChannel: b.Channel}
}
if err := status.WriteBox(context.Background(), w.fx.rel, hb); err != nil {
t.Fatal(err)
@@ -869,6 +871,69 @@ func TestPlacementsRefusesWithABoxBelowTheFloor(t *testing.T) {
})
}
+// [T10 R1 P1, test (c)] The barrier's second half: a downgrade already
+// published on a system channel the fresh boxes follow refuses the PUT
+// while their heartbeats still show the floor release, RD-45 naming the
+// channel. Only the channels fresh boxes follow are read, one pointer GET
+// each; a channel nobody follows, or one with no pointer, never refuses;
+// a pointer that cannot be verified is incomplete evidence.
+func TestPlacementsRefusesBelowAPublishedChannel(t *testing.T) {
+ floor := rdFloor()
+ t.Run("a downgrade published, boxes still at the floor", func(t *testing.T) {
+ w := regionalWorldOnStable(t, "code-rdput-chan-down")
+ if p, err := w.fx.srv.rollbackHostUpdate(t.Context(), "router", "stable", "operator", false, false); err != nil || p.Current.Version != "v0.30.2" {
+ t.Fatalf("the downgrade = %+v, %v", p, err)
+ }
+ st := w.wrap()
+ code, out := w.put(t, rdHost, rdBoth())
+ requireRefusal(t, "stable published at v0.30.2", code, out, http.StatusConflict, placementsChannelBelowFloorMsg("stable", "v0.30.2", floor))
+ w.requireNoClaim(t, rdHost, "a published downgrade")
+ if !st.got(release.SystemPointerKey("router", "stable")) || st.got(release.SystemPointerKey("router", "canary")) {
+ t.Fatalf("pointer reads = %v, want stable's alone", st.gets)
+ }
+ })
+ t.Run("at the floor", func(t *testing.T) {
+ w := regionalWorldOnStable(t, "code-rdput-chan-floor")
+ w.mustPut(t, rdHost, rdBoth())
+ })
+ t.Run("a channel no fresh box follows", func(t *testing.T) {
+ w := regionalWorldOnStable(t, "code-rdput-chan-unfollowed")
+ rel := release.SystemRelease{Version: "v0.30.2", Source: "release:v0.30.2", ReleaseTag: "v0.30.2", Artifacts: map[string]release.SystemArtifact{"linux-amd64": {Key: release.SystemArtifactKey("v0.30.2", "linux-amd64"), SHA256: strings.Repeat("a", 64)}}}
+ if _, err := release.PromoteSystem(t.Context(), w.fx.rel, release.RootSigner(w.fx.priv), "router", "canary", rel, release.SystemPromoteOptions{}); err != nil {
+ t.Fatal(err)
+ }
+ // A stale box on canary does not count.
+ b := rdBox("carol", "uk", "203.0.113.30", rdUK)
+ b.Channel, b.At = "canary", time.Now().Add(-time.Hour)
+ w.putBox(t, b)
+ w.mustPut(t, rdHost, rdBoth())
+ })
+ t.Run("a fresh box on canary", func(t *testing.T) {
+ w := regionalWorldOnStable(t, "code-rdput-chan-canary")
+ rel := release.SystemRelease{Version: "v0.30.2", Source: "release:v0.30.2", ReleaseTag: "v0.30.2", Artifacts: map[string]release.SystemArtifact{"linux-amd64": {Key: release.SystemArtifactKey("v0.30.2", "linux-amd64"), SHA256: strings.Repeat("a", 64)}}}
+ if _, err := release.PromoteSystem(t.Context(), w.fx.rel, release.RootSigner(w.fx.priv), "router", "canary", rel, release.SystemPromoteOptions{}); err != nil {
+ t.Fatal(err)
+ }
+ b := rdBox("betty", "uk", "203.0.113.20", rdUK)
+ b.Channel = "canary"
+ w.putBox(t, b)
+ code, out := w.put(t, rdHost, rdBoth())
+ requireRefusal(t, "canary published at v0.30.2", code, out, http.StatusConflict, placementsChannelBelowFloorMsg("canary", "v0.30.2", floor))
+ w.requireNoClaim(t, rdHost, "canary below the floor")
+ })
+ t.Run("no pointer at all", func(t *testing.T) {
+ w := newRegionalWorld(t, "code-rdput-chan-none")
+ w.mustPut(t, rdHost, rdBoth())
+ })
+ t.Run("an unverifiable pointer", func(t *testing.T) {
+ w := newRegionalWorld(t, "code-rdput-chan-forged")
+ putFixtureObject(t, w.fx.rel, release.SystemPointerKey("router", "stable"), []byte(`{"payload":"x","sig":"y"}`))
+ code, out := w.put(t, rdHost, rdBoth())
+ requireRefusal(t, "an unverifiable pointer", code, out, http.StatusServiceUnavailable, placementsUnreadableMsg)
+ w.requireNoClaim(t, rdHost, "an unverifiable pointer")
+ })
+}
+
// TestPlacementsPutNormalisesInput (Review Focus 2): hosts and regions are
// lower-cased and trimmed, the home region's name is stored as "", and an
// empty or unknown region is RD-20.
diff --git a/internal/console/hostactivation.go b/internal/console/hostactivation.go
index 0b05fe793..9abb5a926 100644
--- a/internal/console/hostactivation.go
+++ b/internal/console/hostactivation.go
@@ -205,7 +205,7 @@ func (s *Server) reserveHostUpdate(ctx context.Context, rel *release.SystemRelea
func (s *Server) promoteHostUpdate(ctx context.Context, rel release.SystemRelease, component, channel string, options release.SystemPromoteOptions) (*release.SystemPointer, error) {
// The floor decision binds the snapshot it judged: preparation, here
// or in the unreserved fallback, refuses a pointer that moved since.
- etag, err := s.systemFloorGate(ctx, component, channel, rel.Version, options.AllowBelowRootfsFloor, options.AllowBelowRegionalFloor)
+ cur, etag, err := s.systemFloorSnapshot(ctx, component, channel, rel.Version, options.AllowBelowRootfsFloor, options.AllowBelowRegionalFloor)
if err != nil {
return nil, err
}
@@ -213,11 +213,18 @@ func (s *Server) promoteHostUpdate(ctx context.Context, rel release.SystemReleas
if err != nil {
return nil, err
}
- if id == "" {
- return release.PromoteSystem(ctx, s.cfg.Releases, release.RootSigner(s.cfg.Key), component, channel, rel, options, etag)
- }
+ // The regional floor is judged again on the same snapshot under
+ // regionalMu, with the write (#447 T10 R1 P1). A reservation held from
+ // an earlier attempt binds the same snapshot through its expected ETag,
+ // and one already published judged here as its own target, which never
+ // crosses, so it keeps its idempotent answer.
d := hostactors.Directory{Store: s.cfg.Releases, PublicKey: release.RootSigner(s.cfg.Key).RootPublicKey(), Bucket: s.cfg.Bucket}
- return d.PublishActivation(ctx, id)
+ return s.regionalFloorPublish(ctx, channel, judgedPointer(cur), rel.Version, options.AllowBelowRegionalFloor, func() (*release.SystemPointer, error) {
+ if id == "" {
+ return release.PromoteSystem(ctx, s.cfg.Releases, release.RootSigner(s.cfg.Key), component, channel, rel, options, etag)
+ }
+ return d.PublishActivation(ctx, id)
+ })
}
func (s *Server) rollbackHostUpdate(ctx context.Context, component, channel, actor string, allowBelowRootfsFloor, allowBelowRegionalFloor bool) (*release.SystemPointer, error) {
@@ -245,7 +252,25 @@ func (s *Server) rollbackHostUpdate(ctx context.Context, component, channel, act
if held.AllowBelowRootfsFloor != allowBelowRootfsFloor || held.AllowBelowRegionalFloor != allowBelowRegionalFloor {
return nil, activationHeldError{id: id, component: component, channel: channel}
}
- return d.PublishActivation(ctx, id)
+ // An unpublished rollback is judged again under regionalMu
+ // before it publishes (#447 T10 R1 P1): a regional claim may
+ // have been created since it was reserved. It is judged on the
+ // pointer as it stands: the one it replaces, or, once it has
+ // landed, itself, which never crosses, so a publication already
+ // committed keeps its idempotent answer. Any other pointer fails
+ // the publication's CAS whatever the judgment. The rootfs floor
+ // needs no second look: it depends on the pointer alone, which
+ // the CAS binds.
+ standing := func() (*release.SystemPointer, error) {
+ p, _, err := release.GetSystemPointer(ctx, s.cfg.Releases, d.PublicKey, component, channel)
+ if errors.Is(err, os.ErrNotExist) {
+ return nil, nil
+ }
+ return p, err
+ }
+ return s.regionalFloorPublish(ctx, channel, standing, held.Current.Version, allowBelowRegionalFloor, func() (*release.SystemPointer, error) {
+ return d.PublishActivation(ctx, id)
+ })
}
} else if !errors.Is(err, os.ErrNotExist) {
return nil, err
@@ -272,10 +297,12 @@ func (s *Server) rollbackHostUpdate(ctx context.Context, component, channel, act
if err != nil {
return nil, err
}
- if id == "" {
- return release.RollbackSystem(ctx, s.cfg.Releases, release.RootSigner(s.cfg.Key), component, channel, options, etag)
- }
- return d.PublishActivation(ctx, id)
+ return s.regionalFloorPublish(ctx, channel, judgedPointer(current), target.Version, allowBelowRegionalFloor, func() (*release.SystemPointer, error) {
+ if id == "" {
+ return release.RollbackSystem(ctx, s.cfg.Releases, release.RootSigner(s.cfg.Key), component, channel, options, etag)
+ }
+ return d.PublishActivation(ctx, id)
+ })
}
// handleAPISystemActivationCancel is the operator's way out of an executable
diff --git a/internal/console/regionalfloor.go b/internal/console/regionalfloor.go
index f67e5ca78..d264209c5 100644
--- a/internal/console/regionalfloor.go
+++ b/internal/console/regionalfloor.go
@@ -25,6 +25,19 @@ import (
// part of an activation request's identity, as the rootfs one is; boxes
// do not read it.
+// (#447 T10 R1 P1) A judgment that no regional claim exists is not bound
+// by the pointer's ETag: a claim can appear while the pointer stands
+// still. So the judgment that counts is made again under s.regionalMu,
+// the mutex the placements PUT holds from its evidence to its claim write,
+// and the pointer is written before the mutex is released
+// (regionalFloorPublish). The PUT's barrier reads the system pointers
+// under the same mutex (regionalChannelRefusal), so either the downgrade
+// is published first and the PUT sees it, or the claim is written first
+// and the judgment sees it. The console is one process per deployment, so
+// an in-process mutex is the whole exclusion. regionalMu is taken last:
+// no caller of regionalFloorPublish holds the app, host or plan locks, and
+// nothing under it takes them.
+
// consoleRegionalFloorRefusal (RD-30) takes the channel, its current
// release, the floor and the target.
const consoleRegionalFloorRefusal = "%s runs %s and this deployment has a regional domain, so it takes only %s or later. %s is not one. to move it there anyway, pass --allow-below-regional-floor"
@@ -75,3 +88,48 @@ func (s *Server) regionalFloorJudge(ctx context.Context, channel string, cur *re
}
return regionalFloorError{msg: fmt.Sprintf(consoleRegionalFloorRefusal, channel, cur.Current.Version, floor, target)}
}
+
+// regionalFloorHooks are test seams: beforeLock runs after every earlier
+// judgment and reservation and before regionalMu is taken; locked runs
+// under regionalMu after the judgment and before the publication.
+type regionalFloorHooks struct {
+ beforeLock, locked func()
+}
+
+// regionalFloorPublish runs publish, the conditional write of channel's
+// pointer, under s.regionalMu, after judging the regional floor again on
+// the pointer current returns (the one the write replaces; nil for none)
+// moving to target. An earlier judgment (systemFloorGate, before any
+// reservation) refuses early; this one is the one that binds. With allow
+// nothing a new claim does changes the answer, so current is not called
+// and the claims are not read again; nor are they when the move does not
+// cross the floor (regionalFloorJudge reads none). Only the judgment and
+// the write are under the mutex, never a download or a reservation.
+func (s *Server) regionalFloorPublish(ctx context.Context, channel string, current func() (*release.SystemPointer, error), target string, allow bool, publish func() (*release.SystemPointer, error)) (*release.SystemPointer, error) {
+ if hook := s.regionalFloorHooks.beforeLock; hook != nil {
+ hook()
+ }
+ s.regionalMu.Lock()
+ defer s.regionalMu.Unlock()
+ if !allow {
+ cur, err := current()
+ if err != nil {
+ return nil, err
+ }
+ if cur != nil {
+ if err := s.regionalFloorJudge(ctx, channel, cur, target, false); err != nil {
+ return nil, err
+ }
+ }
+ }
+ if hook := s.regionalFloorHooks.locked; hook != nil {
+ hook()
+ }
+ return publish()
+}
+
+// judgedPointer is a regionalFloorPublish current for a pointer already
+// read and bound by the publication's expected ETag.
+func judgedPointer(p *release.SystemPointer) func() (*release.SystemPointer, error) {
+ return func() (*release.SystemPointer, error) { return p, nil }
+}
diff --git a/internal/console/regionalfloor_test.go b/internal/console/regionalfloor_test.go
index 8621202ea..96f913255 100644
--- a/internal/console/regionalfloor_test.go
+++ b/internal/console/regionalfloor_test.go
@@ -3,8 +3,10 @@ package console
import (
"context"
"errors"
+ "net/http"
"strings"
"testing"
+ "time"
"github.com/carlosframework/platform/internal/domains"
"github.com/carlosframework/platform/internal/release"
@@ -302,29 +304,38 @@ func TestRegionalFloorCountsAnUnreadClaim(t *testing.T) {
// [W7, spec §11] Claims are read only when the move crosses the floor: a
// channel moving at or above it, or one already below it, makes no claims
-// listing on promote or rollback. One that crosses makes exactly one.
+// listing on promote or rollback. One that crosses with the override makes
+// exactly one. (T10 R1) One that crosses without it and finds no regional
+// claim makes two: the early judgment, and the binding one under
+// regionalMu just before the pointer write (spec §11 rev 5.3).
func TestRegionalFloorReadsNoClaimsWhenNotCrossing(t *testing.T) {
for _, c := range []struct {
name, from, to string
+ regional bool
lists int
}{
- {"above", "v0.31.0", "v0.32.0", 0},
- {"below", "v0.30.0", "v0.30.2", 0},
- {"crossing", "v0.31.0", "v0.30.2", 1},
+ {"above", "v0.31.0", "v0.32.0", true, 0},
+ {"below", "v0.30.0", "v0.30.2", true, 0},
+ {"crossing", "v0.31.0", "v0.30.2", true, 1},
+ {"crossing-without-a-regional-claim", "v0.31.0", "v0.30.2", false, 2},
} {
for _, mode := range []string{"promote", "rollback"} {
t.Run(c.name+"/"+mode, func(t *testing.T) {
s, d, target := activationFixtureAt(t, c.from, c.to, "v0.28.0")
- putRegionalClaim(t, d.Store, rdFloorClaimHost, "acct", "shop", rdHomeHost, false, false)
+ if c.regional {
+ putRegionalClaim(t, d.Store, rdFloorClaimHost, "acct", "shop", rdHomeHost, false, false)
+ }
counter := &claimListCounter{Store: d.Store}
s.cfg.Releases = counter
- // The override lets the crossing case publish, so each case
- // runs the whole promotion.
+ // With a regional claim the override lets the crossing case
+ // publish, so each case runs the whole promotion; without
+ // one none is needed.
+ allow := c.regional
var err error
if mode == "rollback" {
- _, err = s.rollbackHostUpdate(t.Context(), "router", "stable", "operator", false, true)
+ _, err = s.rollbackHostUpdate(t.Context(), "router", "stable", "operator", false, allow)
} else {
- _, err = s.promoteHostUpdate(t.Context(), target, "router", "stable", release.SystemPromoteOptions{AllowBelowRegionalFloor: true})
+ _, err = s.promoteHostUpdate(t.Context(), target, "router", "stable", release.SystemPromoteOptions{AllowBelowRegionalFloor: allow})
}
if err != nil {
t.Fatal(err)
@@ -339,3 +350,149 @@ func TestRegionalFloorReadsNoClaimsWhenNotCrossing(t *testing.T) {
}
}
}
+
+// [T10 R1 P1, test (a)] The judgment that no regional claim exists holds
+// through the pointer write. A regional claim written after the early
+// judgment (and, reserved, after the reservation) and before the
+// publication refuses the downgrade: the regional floor is judged again
+// under regionalMu with the write. Promote and rollback, reserved and
+// unreserved.
+func TestRegionalFloorJudgesAgainAtPublication(t *testing.T) {
+ for _, mode := range []string{"promote", "rollback"} {
+ for _, reserved := range []bool{true, false} {
+ name := mode + "/unreserved"
+ if reserved {
+ name = mode + "/reserved"
+ }
+ t.Run(name, func(t *testing.T) {
+ s, d, target := activationFixtureAt(t, "v0.31.0", "v0.30.2", "v0.28.0")
+ if !reserved {
+ unreserved(t, d)
+ }
+ ran := false
+ s.regionalFloorHooks.beforeLock = func() {
+ ran = true
+ putRegionalClaim(t, d.Store, rdFloorClaimHost, "acct", "shop", rdHomeHost, false, false)
+ }
+ var err error
+ if mode == "rollback" {
+ _, err = s.rollbackHostUpdate(t.Context(), "router", "stable", "operator", false, false)
+ } else {
+ _, err = s.promoteHostUpdate(t.Context(), target, "router", "stable", release.SystemPromoteOptions{})
+ }
+ if !ran {
+ t.Fatal("the hook never ran: nothing sat between the judgment and the publication")
+ }
+ if want := rdFloorWant("v0.31.0", "v0.30.2"); !errors.Is(err, errRegionalFloorPromotion) || err.Error() != want {
+ t.Fatalf("%s with a claim written before the publication = %v\nwant %q", mode, err, want)
+ }
+ if v := currentVersion(t, s, d); v != "v0.31.0" {
+ t.Fatalf("the downgrade published: the pointer is at %s", v)
+ }
+ })
+ }
+ }
+}
+
+// [T10 R1 P1, test (b)] A rollback reserved without either override whose
+// pointer write failed is judged again when it is retried: a regional
+// claim created in between refuses it, on a restarted console too. A
+// publication that had already landed keeps its idempotent answer. The
+// promote's retry meets the early judgment on the same pointer.
+func TestRegionalFloorJudgesAHeldRollbackAgain(t *testing.T) {
+ for _, mode := range []string{"rollback", "promote"} {
+ for _, landed := range []bool{false, true} {
+ name := mode + "/unpublished"
+ if landed {
+ name = mode + "/landed"
+ }
+ t.Run(name, func(t *testing.T) {
+ s, d, target := activationFixtureAt(t, "v0.31.0", "v0.30.2", "v0.28.0")
+ move := func(s *Server) (*release.SystemPointer, error) {
+ if mode == "rollback" {
+ return s.rollbackHostUpdate(t.Context(), "router", "stable", "operator", false, false)
+ }
+ return s.promoteHostUpdate(t.Context(), target, "router", "stable", release.SystemPromoteOptions{})
+ }
+ // The first attempt reserves and its write fails, or lands
+ // with its answer lost.
+ s.cfg.Releases = &activationFaultStore{Store: d.Store, fail: true, commit: landed, hide: landed}
+ if _, err := move(s); err == nil {
+ t.Fatal("the failed publication succeeded")
+ }
+ o, err := d.Read(t.Context())
+ if err != nil || len(o.Roster.Activations) != 1 {
+ t.Fatalf("after the failed publication: %v, %v", o.Roster.Activations, err)
+ }
+ putRegionalClaim(t, d.Store, rdFloorClaimHost, "acct", "shop", rdHomeHost, false, false)
+ restarted := &Server{cfg: s.cfg}
+ restarted.cfg.Releases = d.Store
+ p, err := move(restarted)
+ if landed {
+ if err != nil || p.Current.Version != "v0.30.2" {
+ t.Fatalf("the retry of a landed %s = %+v, %v; want its idempotent answer", mode, p, err)
+ }
+ return
+ }
+ if want := rdFloorWant("v0.31.0", "v0.30.2"); !errors.Is(err, errRegionalFloorPromotion) || err.Error() != want {
+ t.Fatalf("the retry of a held %s after a claim = %v\nwant %q", mode, err, want)
+ }
+ if v := currentVersion(t, restarted, d); v != "v0.31.0" {
+ t.Fatalf("the held %s published: the pointer is at %s", mode, v)
+ }
+ })
+ }
+ }
+}
+
+// regionalWorldOnStable is the placements world with the stable system
+// channel published at v0.31.0 over v0.30.2 (the unreserved mode: no host
+// floor), which every world box follows (its heartbeat names no channel).
+func regionalWorldOnStable(t *testing.T, code string) *regionalWorld {
+ t.Helper()
+ w := newRegionalWorld(t, code)
+ sg := release.RootSigner(w.fx.priv)
+ for _, v := range []string{"v0.30.2", rdFloor()} {
+ rel := release.SystemRelease{Version: v, Source: "release:" + v, ReleaseTag: v, Artifacts: map[string]release.SystemArtifact{"linux-amd64": {Key: release.SystemArtifactKey(v, "linux-amd64"), SHA256: strings.Repeat("a", 64)}}}
+ if _, err := release.PromoteSystem(t.Context(), w.fx.rel, sg, "router", "stable", rel, release.SystemPromoteOptions{}); err != nil {
+ t.Fatal(err)
+ }
+ }
+ return w
+}
+
+// [T10 R1 P1, test (a), the mutex] A placements PUT that arrives while a
+// downgrade is between its judgment and its pointer write waits for the
+// write and then meets the downgraded pointer at its barrier: refused, no
+// claim. The hook holds the publication inside its critical section for up
+// to a second while the PUT runs; under regionalMu the PUT cannot finish
+// in that time, so the answer does not depend on timing. Without the
+// mutex the PUT would create the claim and the downgrade would publish
+// over it.
+func TestRegionalFloorPublicationHoldsRegionalMu(t *testing.T) {
+ w := regionalWorldOnStable(t, "code-rdfloor-mutex")
+ var put <-chan rdAnswer
+ w.fx.srv.regionalFloorHooks.locked = func() {
+ put = w.putAsync(rdHost)
+ select {
+ case r := <-put:
+ done := make(chan rdAnswer, 1)
+ done <- r
+ put = done
+ case <-time.After(time.Second):
+ }
+ }
+ p, err := w.fx.srv.rollbackHostUpdate(t.Context(), "router", "stable", "operator", false, false)
+ if err != nil || p.Current.Version != "v0.30.2" {
+ t.Fatalf("the rollback = %+v, %v; want v0.30.2 (no regional claim when it was judged)", p, err)
+ }
+ if put == nil {
+ t.Fatal("the hook never ran")
+ }
+ r := <-put
+ if r.err != nil {
+ t.Fatal(r.err)
+ }
+ requireRefusal(t, "a PUT racing the downgrade", r.code, r.out, http.StatusConflict, placementsChannelBelowFloorMsg("stable", "v0.30.2", rdFloor()))
+ w.requireNoClaim(t, rdHost, "a PUT racing the downgrade")
+}
diff --git a/internal/console/rootfsfloor.go b/internal/console/rootfsfloor.go
index e90a18e7b..e424562db 100644
--- a/internal/console/rootfsfloor.go
+++ b/internal/console/rootfsfloor.go
@@ -50,17 +50,25 @@ func (e rootfsFloorError) Unwrap() error { return errRootfsFloorPromotion }
// a channel that moved in between (say to the floor) fails the CAS, never
// takes a release nobody checked against it (whole-branch review P1-3).
func (s *Server) systemFloorGate(ctx context.Context, component, channel, target string, allowRootfs, allowRegional bool) (string, error) {
+ _, etag, err := s.systemFloorSnapshot(ctx, component, channel, target, allowRootfs, allowRegional)
+ return etag, err
+}
+
+// systemFloorSnapshot is systemFloorGate returning the judged pointer too
+// (nil for none): promoteHostUpdate judges the regional floor on it again
+// under regionalMu just before it publishes (regionalFloorPublish).
+func (s *Server) systemFloorSnapshot(ctx context.Context, component, channel, target string, allowRootfs, allowRegional bool) (*release.SystemPointer, string, error) {
cur, etag, err := release.GetSystemPointer(ctx, s.cfg.Releases, release.RootSigner(s.cfg.Key).RootPublicKey(), component, channel)
if errors.Is(err, os.ErrNotExist) {
- return etag, nil
+ return nil, etag, nil
}
if err != nil {
- return "", err
+ return nil, "", err
}
if err := rootfsFloorJudge(channel, cur, target, allowRootfs); err != nil {
- return etag, err
+ return cur, etag, err
}
- return etag, s.regionalFloorJudge(ctx, channel, cur, target, allowRegional)
+ return cur, etag, s.regionalFloorJudge(ctx, channel, cur, target, allowRegional)
}
// rootfsFloorJudge is the rootfs half of systemFloorGate's decision, on a
diff --git a/internal/console/server.go b/internal/console/server.go
index 81fb8231b..69c6d7218 100644
--- a/internal/console/server.go
+++ b/internal/console/server.go
@@ -1377,7 +1377,14 @@ type Server struct {
// and every door that could create a covering catch-all takes it too,
// so neither can slip in between the other's check and write. Acquired
// after any app or host lock, never before. The zero value is ready.
+ // (#447 T10 R1) Every system pointer publication the regional floor
+ // judges also takes it, from its last judgment to its pointer write
+ // (regionalFloorPublish), and the PUT's barrier reads the system
+ // pointers under it, so a claim and a downgrade cannot cross.
regionalMu sync.Mutex
+ // regionalFloorHooks are test seams around regionalFloorPublish's
+ // critical section; nil in production.
+ regionalFloorHooks regionalFloorHooks
// The trash sweep's clock (lifetimes_purge.go) and the box floor
// watch's memory (lifetimes_floor.go).
trashSweepState