carlos / platform Public

Revert "console: label a one-box fleet's records so stateless releases deploy"

This reverts commit ad35f1a58cc7712b82f7b0485c2db29599839f0b.
Paul Campbell pushed by claude agent, operated by paul@keymail.dev da71d0100378ab81173d1305f7afab15e0657aea parent ad35f1a
5 files changed, +10 −260
  • internal/console/fleetbox.go +5 −11
  • internal/console/fleetrelabel.go +5 −16
  • internal/console/fleetrelabel_test.go +0 −24
  • internal/console/replicacoordinator_test.go +0 −203
  • internal/console/replicaplacement_test.go +0 −6

Intent

Human

<task-notification> <task-id>bbxhff5sh</task-id> <tool-use-id>toolu_01AnbtLeJrzCZVLKR1SbBQ8m</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/195ef15b-aac6-42d6-b49b-41ffb7a4abbc/tasks/bbxhff5sh.output</output-file> <status>completed</status> <summary>Background command "Wait for F8 round 2" completed (exit code 0)</summary> </task-notification>

Human

<task-notification> <task-id>a89ef4e867d0f96f9</task-id> <tool-use-id>toolu_019tsfySnhKHjs6KuWyyXGw6</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/195ef15b-aac6-42d6-b49b-41ffb7a4abbc/tasks/a89ef4e867d0f96f9.output</output-file> <status>completed</status> <summary>Agent "F8 fix review" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>**Verdict: NEEDS FIXES.** The code does what the round 2 brief asked: first labelling runs on a one-box fleet under every existing gate, two-box behaviour is unchanged, and the meaning of `fleetView.Active` is unchanged. The problems are in the design. I re-ran six targeted tests, including the witness, the gone-box test and the read-budget test, and all pass. The full review is in `/home/paulca/.cache/sr-f8/review.md`. - **Critical C1** (`fleetrelabel.go:175` + `edge.go:3778`): records can go dark for good after a box swap. - Once labelled, a one-box fleet's records are routed only to the labelled box, with no fallback. - Suppose the only box dies. The owner detaches it with `--terminated` and attaches a replacement. - Each record stays labelled to the detached box and gets 503 until a second box is attached. Nothing is logged, because moves never run on a one-box fleet. - Before this change the unlabelled fallback served these records from the new box. - `TestRelabelOneBoxFleetDoesNotMoveGoneBoxRecords` pins this state as intended. The fix needs a manager decision: allow moves off a detached box on a complete one-box view, or at least alert on it. - **Important I1:** replacing a dead box by attaching the new one first now adds up to about 25 minutes of 503s. The record waits for the 20-minute lost threshold plus up to one 5-minute pass. Before, the fallback served it as soon as the new box connected. - **Important I2** (`fleetrelabel.go:129`): the new bucket reads repeat every 5 minutes, forever, for every one-box fleet. - They continue after all its records are labelled. - Each pass reads the fleet's inventory (two LISTs per placed app). - It also triggers the deployment-wide heartbeat read, which GETs every box's heartbeat. That is per-box polling in effect, and it was zero before for deployments with only one-box fleets. - It is avoidable with a per-fleet "needs first labelling" flag, set when a record is created or placed on the fleet and cleared after a pass finds nothing left to label. The review also has four minor findings: - The detach message tells one-box owners to drain first, which cannot succeed on one box. - One-box fleets now get the label-floor pause and its alert. - The witness's 404 body is Go's default, so it doesn't prove the console handled the refusal rather than the edge. - Existing deployment-wide gates could block the fix on dev. Check the live F8 fleet meets them before calling F8 fixed.</result> <usage><subagent_tokens>105477</subagent_tokens><tool_uses>21</tool_uses><duration_ms>308237</duration_ms></usage> </task-notification>

Human

<task-notification> <task-id>bnq1jklhi</task-id> <tool-use-id>toolu_01Uqh4dZHU9bG7Map4XzdREi</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/195ef15b-aac6-42d6-b49b-41ffb7a4abbc/tasks/bnq1jklhi.output</output-file> <status>completed</status> <summary>Background command "Wait for Task 2 fix round 1" completed (exit code 0)</summary> </task-notification>

diff --git a/internal/console/fleetbox.go b/internal/console/fleetbox.go
index c56a5ab33..6bc30ced3 100644
--- a/internal/console/fleetbox.go
+++ b/internal/console/fleetbox.go
@@ -44,8 +44,8 @@ import (
// Load counts assigned copies, or one for a legacy box label. Static
// records count toward neither (fleetLabelsRecord). Records is the
// inventory the view was built from (every record placed on the fleet,
-// static ones included). The relabel pass requests this inventory even on
-// one box; request-time callers may skip it while labelling is inactive.
+// static ones included), read only when the fleet has two or more active
+// boxes; the relabel worker and the drain act on it.
type fleetView struct {
Boxes []fleetBoxView
Active, HasSidecars, DeploymentCurrent bool
@@ -124,20 +124,14 @@ func (b fleetBoxView) destinationFor(rootfs bool) bool {
return !rootfs || (b.RootfsReady && b.AtRootfsFloor)
}
-// labelActive is the create-time activation gate: the console labels new
-// records only when the fleet has two or more active boxes and was read whole, has
+// labelActive is the activation gate: the console labels this fleet's
+// records only when it has two or more active boxes and was read whole, has
// no sidecars, the deployment and the console are at the label floor, and
// every record on it is one the platform can move.
func (v fleetView) labelActive() bool {
return v.Active && !v.HasSidecars && v.DeploymentCurrent && !v.Unmovable
}
-// First labelling follows an existing binding and needs no second box.
-// Create-time placement still uses labelActive.
-func (v fleetView) firstLabelActive() bool {
- return (v.Active || (v.Complete && len(v.Boxes) == 1)) && !v.HasSidecars && v.DeploymentCurrent && !v.Unmovable
-}
-
// chooseDestination is rule 1's choice: among the boxes that are fresh, not
// draining, at the label floor and not exclude (and, for a rootfs record,
// rootfs-ready at the rootfs floor), the one holding the fewest records,
@@ -288,7 +282,7 @@ func (s *Server) loadFleetViewAt(ctx context.Context, fleet string, now time.Tim
return s.loadFleetViewRequiredAt(ctx, fleet, now, false)
}
-// Count admission and the relabel pass need the complete view even on one box.
+// Count admission needs the complete view even when labelling is inactive.
func (s *Server) loadFleetViewRequiredAt(ctx context.Context, fleet string, now time.Time, requireComplete bool) (fleetView, error) {
v := fleetView{Load: map[string]int{}}
reg, err := s.openPassRegistry()
diff --git a/internal/console/fleetrelabel.go b/internal/console/fleetrelabel.go
index 1309f25cc..dc9a125ca 100644
--- a/internal/console/fleetrelabel.go
+++ b/internal/console/fleetrelabel.go
@@ -32,7 +32,7 @@ import (
// longer an active box of the fleet moves to chooseDestination(rootfs,
// its box) (rules 4 and 5). Moving needs no open activation gate
// (controller ruling 1).
-// - When first labelling is allowed (firstLabelActive): an unlabelled
+// - And when the activation gate is open (labelActive): an unlabelled
// record is labelled to the box its binding
// (fleets/<f>/bindings/<host>.json) names, when that binding was
// written for this record and the box is a valid destination. A record
@@ -124,17 +124,6 @@ func (s *Server) fleetRelabelPass(ctx context.Context, now time.Time) error {
jobFailed(ctx, err)
log.Printf("console: replica placement %s: %v", f.Name, err)
}
- // Only first labelling needs the inventory skipped by a one-box view.
- // Keep replica reconciliation above on its existing view.
- if len(v.Boxes) == 1 && !v.Complete {
- v, err = s.loadFleetViewRequiredAt(ctx, f.Name, now, true)
- if err != nil {
- log.Printf("console: fleet relabel %s: view: %v", f.Name, err)
- jobFailed(ctx, err)
- unlock()
- continue
- }
- }
if _, err := s.relabelFleet(ctx, f.Name, v, now); err != nil {
log.Printf("console: fleet relabel %s: %v", f.Name, err)
jobFailed(ctx, err)
@@ -161,8 +150,11 @@ func (s *Server) relabelFleet(ctx context.Context, fleet string, v fleetView, no
fleet, box, releaseOrUnknown(rel), release.FleetBoxLabelFloor)
return 0, nil
}
+ if !v.Active {
+ return 0, nil
+ }
var plan []relabel
- if v.firstLabelActive() {
+ if v.labelActive() {
first, err := s.planFirstLabelling(ctx, fleet, v)
if err != nil {
return 0, err
@@ -172,9 +164,6 @@ func (s *Server) relabelFleet(ctx context.Context, fleet string, v fleetView, no
}
plan = append(plan, first...)
}
- if !v.Active {
- return s.writeRelabels(ctx, fleet, plan, now), nil
- }
for _, rec := range v.Records {
if rec.ReplicaAssignment != nil || !fleetLabelsRecord(rec) || rec.FleetBox == "" {
continue
diff --git a/internal/console/fleetrelabel_test.go b/internal/console/fleetrelabel_test.go
index 36b3f0bc7..e3cf902f4 100644
--- a/internal/console/fleetrelabel_test.go
+++ b/internal/console/fleetrelabel_test.go
@@ -774,27 +774,3 @@ func TestDrainRefusedOnAHostClaimConsole(t *testing.T) {
t.Fatalf("drainBox on a host-claim console = %v", err)
}
}
-
-func TestRelabelOneBoxFleetDoesNotMoveGoneBoxRecords(t *testing.T) {
- fx, _, reg := fleetBoxWorld(t, "onebox-no-moves", "pi-1", "pi-2")
- if err := reg.SetFleetBoxStatus("pi", "pi-2", "detached"); err != nil {
- t.Fatal(err)
- }
- putFleetRecord(t, fx, "shop", "gone.example.com", func(r *provision.Record) { r.FleetBox = "pi-2" })
- putFleetRecord(t, fx, "shop", "bound.example.com", nil)
- bindTo(t, fx, "bound.example.com", "pi-1", time.Now())
- ctx := context.Background()
- key := provision.RecordKey(fx.sqid, "shop", "gone.example.com")
- before, _, err := fx.rel.Get(ctx, key)
- if err != nil {
- t.Fatal(err)
- }
- if err := fx.srv.RunFleetRelabelPass(ctx, time.Now()); err != nil {
- t.Fatal(err)
- }
- wantLabel(t, shopRec(t, fx, "bound.example.com"), "pi-1")
- after, _, err := fx.rel.Get(ctx, key)
- if err != nil || !bytes.Equal(before, after) {
- t.Fatalf("one-box pass moved or rewrote the gone box's record: %s, %v", after, err)
- }
-}
diff --git a/internal/console/replicacoordinator_test.go b/internal/console/replicacoordinator_test.go
index 58ca8cf2c..beabddf68 100644
--- a/internal/console/replicacoordinator_test.go
+++ b/internal/console/replicacoordinator_test.go
@@ -4,19 +4,14 @@ import (
"bytes"
"context"
"encoding/json"
- "errors"
"io"
"net/http"
- "net/http/httptest"
"strings"
- "sync/atomic"
"testing"
"time"
- "github.com/carlosframework/platform/internal/edge"
"github.com/carlosframework/platform/internal/provision"
"github.com/carlosframework/platform/internal/registry"
- "github.com/carlosframework/platform/internal/release"
"github.com/carlosframework/platform/internal/replicas"
)
@@ -339,201 +334,3 @@ func TestReplicaRetiredACKsUseLatestRevision(t *testing.T) {
t.Fatalf("ACKs: %+v %v", got, err)
}
}
-
-func TestReplicaCoordinatorOneBoxFleetFirstLabelling(t *testing.T) {
- for _, tc := range []struct {
- name string
- change func(*provision.Record, *fleetBinding)
- want int
- reads int32
- }{
- {name: "matching", want: 200, reads: 1},
- {name: "newer", change: func(_ *provision.Record, b *fleetBinding) { b.BoundAt++ }, want: 200, reads: 1},
- {name: "detached-box", change: func(_ *provision.Record, b *fleetBinding) { b.Box = "b2" }, want: 404, reads: 1},
- {name: "other-box", change: func(_ *provision.Record, b *fleetBinding) { b.Box = "missing" }, want: 404, reads: 1},
- {name: "older", change: func(_ *provision.Record, b *fleetBinding) { b.BoundAt-- }, want: 404, reads: 1},
- {name: "other-host", change: func(_ *provision.Record, b *fleetBinding) { b.Host = "other.example.com" }, want: 404, reads: 1},
- {name: "other-fleet", change: func(_ *provision.Record, b *fleetBinding) { b.Fleet = "away" }, want: 404, reads: 1},
- {name: "missing-binding", want: 404, reads: 1},
- {name: "binding-read-error", want: 404, reads: 1},
- {name: "sidecars", want: 404},
- {name: "deployment-not-current", want: 404},
- {name: "below-label-floor", want: 404},
- {name: "rootfs-not-ready", want: 404, reads: 1},
- {name: "below-rootfs-floor", want: 404},
- {name: "draining", want: 404, reads: 1},
- {name: "stale-heartbeat", want: 404, reads: 1},
- {name: "incomplete", want: 404},
- {name: "unmovable", change: func(r *provision.Record, _ *fleetBinding) { r.Addr = "127.0.0.1:1234" }, want: 404},
- } {
- t.Run(tc.name, func(t *testing.T) {
- fx := newIxFx(t, "replica-onebox")
- token, _, _ := ixFleetWorld(t, fx, fx.acct)
- ctx, now := context.Background(), time.Now()
- if err := fx.st.SetAppPlacement(fx.acctID, "shop", "fleet/home"); err != nil {
- t.Fatal(err)
- }
- fx.srv.consoleBuild = release.FleetBoxLabelFloor
- writeFleetBoxOn(t, fx.consoleFixture, "home", "b1", "", true, now, release.FleetBoxLabelFloor)
- reg, err := registry.Open(fx.regPath)
- if err != nil {
- t.Fatal(err)
- }
- t.Cleanup(func() { reg.Close() })
- boxes, err := reg.ListFleetBoxes("home")
- if err != nil {
- t.Fatal(err)
- }
- active := 0
- for _, b := range boxes {
- if b.Status == "active" {
- active++
- }
- }
- if active != 1 {
- t.Fatalf("active boxes = %d, want 1", active)
- }
- rec, _ := ixRecord(t, fx, ixHost)
- binding := fleetBinding{Fleet: "home", Host: ixHost, Box: "b1", BoundAt: rec.CreatedAt.UnixMilli()}
- if tc.change != nil {
- tc.change(&rec, &binding)
- ixPutRecord(t, fx, rec)
- }
- switch tc.name {
- case "sidecars":
- if err := provision.CreateSidecarRecord(ctx, fx.rel, provision.SidecarRecord{Schema: 1, Name: "bot", Host: provision.SidecarHost("bot", "shop", fx.acct), App: "shop", Account: fx.acct, Region: "fleet/home", Channel: "stable", CreatedAt: now}); err != nil {
- t.Fatal(err)
- }
- case "deployment-not-current":
- fx.srv.consoleBuild = "v0.32.0"
- case "below-label-floor":
- writeFleetBoxOn(t, fx.consoleFixture, "home", "b1", "", true, now, "v0.32.0")
- case "rootfs-not-ready":
- writeFleetBoxOn(t, fx.consoleFixture, "home", "b1", "", false, now, release.FleetBoxLabelFloor)
- case "below-rootfs-floor":
- writeFleetBoxOn(t, fx.consoleFixture, "home", "b1", "", true, now, "v0.28.16")
- case "draining":
- if _, err := reg.SetFleetBoxDraining("home", "b1", now.UnixNano()); err != nil {
- t.Fatal(err)
- }
- case "stale-heartbeat":
- writeFleetBoxOn(t, fx.consoleFixture, "home", "b1", "", true, now.Add(-time.Hour), release.FleetBoxLabelFloor)
- }
- inc, err := provision.Incarnation(rec.Account, rec.App, rec.Host, rec.CreatedAt)
- if err != nil {
- t.Fatal(err)
- }
- bindingKey := "fleets/home/bindings/" + ixHost + ".json"
- if tc.name != "missing-binding" {
- body, err := json.Marshal(binding)
- if err != nil {
- t.Fatal(err)
- }
- if _, err := fx.rel.Put(ctx, bindingKey, body, ""); err != nil {
- t.Fatal(err)
- }
- }
- var reads atomic.Int32
- ds := fx.rel.(*deletableStore)
- ds.setGetHook(func(_ context.Context, key string) error {
- if key == bindingKey {
- reads.Add(1)
- if tc.name == "binding-read-error" {
- return errors.New("injected binding read failure")
- }
- }
- if tc.name == "incomplete" && key == provision.RecordKey(fx.acct, "shop", ixHost) {
- return errors.New("injected inventory read failure")
- }
- return nil
- })
- t.Cleanup(func() { ds.setGetHook(nil) })
- if err := fx.srv.RunFleetRelabelPass(ctx, now); err != nil {
- t.Fatal(err)
- }
- if n := reads.Load(); n != tc.reads {
- t.Fatalf("pass binding reads = %d, want %d", n, tc.reads)
- }
- ds.setGetHook(func(_ context.Context, key string) error {
- if key == bindingKey {
- reads.Add(1)
- }
- return nil
- })
- after, _ := ixRecord(t, fx, ixHost)
- if tc.want == 200 {
- wantLabel(t, &after, "b1")
- boxes, err = reg.ListFleetBoxes("home")
- if err != nil {
- t.Fatal(err)
- }
- for _, b := range boxes {
- if b.Label == "b1" && b.LabelledAt == 0 {
- t.Fatal("first labelling did not mark the box labelled")
- }
- }
- } else {
- wantNoLabel(t, &after)
- }
- if err := reg.Upsert(registry.Route{Host: "console.test", App: "console", Unit: "console.service", Kind: "service", Addr: fx.ts.Listener.Addr().String(), Status: "ready"}); err != nil {
- t.Fatal(err)
- }
- e, err := edge.New(reg, nil)
- if err != nil {
- t.Fatal(err)
- }
- e.EnableTunnels(edge.NewTunnelHub("tunnel.test", nil))
- post := func(door string, payload any) []byte {
- t.Helper()
- _, before := ixRecord(t, fx, ixHost)
- body, err := json.Marshal(payload)
- if err != nil {
- t.Fatal(err)
- }
- reads.Store(0)
- req := httptest.NewRequest(http.MethodPost, "https://tunnel.test/api/fleet/replicas/"+fx.acct+"/shop/"+ixHost+"/"+door, bytes.NewReader(body))
- req.Header.Set("Authorization", "Bearer "+token)
- req.Header.Set("Carlos-Tunnel-Name", "home/b1")
- req.Header.Set("Content-Type", "application/json")
- w := httptest.NewRecorder()
- e.ServeHTTP(w, req)
- if n := reads.Load(); n != 0 {
- t.Errorf("%s: binding reads = %d, want 0", door, n)
- }
- if w.Code != tc.want || tc.want == 404 && w.Body.String() != "404 page not found\n" {
- t.Fatalf("%s: %d %s, want %d", door, w.Code, w.Body.String(), tc.want)
- }
- if tc.want == 404 {
- _, after := ixRecord(t, fx, ixHost)
- if !bytes.Equal(before, after) {
- t.Fatal("refused request changed the record")
- }
- }
- return w.Body.Bytes()
- }
- raw := post("coordinator", map[string]any{"incarnation": inc, "op": "acquire", "boot_id": "boot"})
- if tc.want == 404 {
- post("release", map[string]any{"incarnation": inc, "op": "begin"})
- return
- }
- var reply replicas.CoordinatorReply
- if err := json.Unmarshal(raw, &reply); err != nil {
- t.Fatal(err)
- }
- if reply.Lease.Box != "b1" || reply.RemainingMS <= 0 {
- t.Fatalf("coordinator reply: %+v", reply)
- }
- var deploy replicas.Deploy
- for _, op := range []string{"begin", "releasing", "released"} {
- raw = post("release", map[string]any{"incarnation": inc, "op": op, "id": "onebox-deploy", "term": reply.Lease.Term, "revision": deploy.Revision, "target": replicas.Build{Version: "v2", Digest: "digest"}})
- if err := json.Unmarshal(raw, &deploy); err != nil {
- t.Fatal(err)
- }
- }
- after, _ = ixRecord(t, fx, ixHost)
- if after.FleetBox != "b1" || after.ReplicaDeploy == nil || after.ReplicaDeploy.Phase != "released" {
- t.Fatalf("released record: %+v", after)
- }
- })
- }
-}
diff --git a/internal/console/replicaplacement_test.go b/internal/console/replicaplacement_test.go
index b7cc1ba5b..0754df905 100644
--- a/internal/console/replicaplacement_test.go
+++ b/internal/console/replicaplacement_test.go
@@ -297,12 +297,6 @@ func TestReplicaPlacementLegacyReadBudget(t *testing.T) {
if pass == 0 {
wantGets[provision.RecordKey(fx.sqid, "shop", "a.example.com")] = 1
}
- } else {
- wantLists = map[string]int{"fleets/pi/status/boxes/": 1, "status/boxes/": 1, provision.RecordsPrefix(fx.sqid, "shop"): 1, provision.SidecarsPrefix(fx.sqid, "shop"): 1}
- wantGets = map[string]int{"fleets/pi/status/boxes/pi-1.json": 1}
- if pass == 0 {
- wantGets[provision.RecordKey(fx.sqid, "shop", "a.example.com")] = 1
- }
}
if !reflect.DeepEqual(cs.gets, wantGets) || !reflect.DeepEqual(cs.lists, wantLists) || len(cs.puts) != 0 {
t.Fatalf("pass %d: gets %v lists %v puts %v; expected gets %v lists %v", pass, cs.gets, cs.lists, cs.puts, wantGets, wantLists)