carlos / platform Public

console: name the coordinator the label writer found (M2 review P2)

SetRecordFirstFleetBox refuses a live coordinator elsewhere with a
*FleetBoxCoordinatedError carrying its box (it unwraps to
ErrFleetBoxCoordinated). The door fills coordinator_box from it, so
C24 names the box when the coordinator appeared after the judged read.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 2b146b6722ec1e406b88fdd48193490fbd4510c4 parent a0171bf
4 files changed, +46 −3
  • internal/console/instancelabel.go +5 −0
  • internal/console/instancelabel_test.go +18 −0
  • internal/provision/fleetbox.go +18 −3
  • internal/provision/fleetbox_first_test.go +5 −0
diff --git a/internal/console/instancelabel.go b/internal/console/instancelabel.go
index d1aadb4bc..85e207fe5 100644
--- a/internal/console/instancelabel.go
+++ b/internal/console/instancelabel.go
@@ -262,6 +262,11 @@ func (s *Server) handleAPIInstanceLabel(w http.ResponseWriter, r *http.Request)
refuseLabel(&ans, labelWhyImport)
case errors.Is(err, provision.ErrFleetBoxCoordinated):
refuseLabel(&ans, labelWhyCoordinated)
+ // C24 names the box; the writer's error carries the one it read.
+ var ce *provision.FleetBoxCoordinatedError
+ if errors.As(err, &ce) {
+ ans.CoordinatorBox = ce.Box
+ }
case errors.Is(err, provision.ErrFleetBoxMoved), errors.Is(err, os.ErrNotExist):
refuseLabel(&ans, labelWhyChanged)
case err != nil:
diff --git a/internal/console/instancelabel_test.go b/internal/console/instancelabel_test.go
index 56c7572bb..3b2f5272e 100644
--- a/internal/console/instancelabel_test.go
+++ b/internal/console/instancelabel_test.go
@@ -702,3 +702,21 @@ func TestLabelDoorRefusesAUnitWhateverItsHibernation(t *testing.T) {
})
}
}
+
+// M2 review P2 (Astra): a coordinator that appears after the door judged
+// the record is found by the writer. The answer is coordinated and names
+// the coordinating box (C24's blank), and nothing is written.
+func TestLabelDoorCoordinatorFoundByTheWriterIsNamed(t *testing.T) {
+ fx, token, reg, created := labelWorld(t, "code-ld-coord-writer", "pi-1", "pi-2")
+ servingEvidence(t, fx, reg, created, "pi-1")
+ fx.srv.labelBeforeMark = func(string) {
+ editShop(t, fx, func(r *provision.Record) {
+ r.Coordinator = &replicas.Coordinator{Term: "t1", Box: "pi-2", BootID: "b", ExpiresAt: time.Now().Add(time.Hour)}
+ })
+ }
+ a := labelPost(t, fx, token, "pi-1", false)
+ wantRefused(t, fx, a, "coordinated")
+ if a.CoordinatorBox != "pi-2" {
+ t.Fatalf("answer %+v; want coordinator_box pi-2", a)
+ }
+}
diff --git a/internal/provision/fleetbox.go b/internal/provision/fleetbox.go
index 288627ae2..42b17779d 100644
--- a/internal/provision/fleetbox.go
+++ b/internal/provision/fleetbox.go
@@ -97,6 +97,20 @@ var (
ErrFleetBoxCoordinated = errors.New("provision: another box coordinates the record")
)
+// FleetBoxCoordinatedError is SetRecordFirstFleetBox's ErrFleetBoxCoordinated
+// with the box the record's live coordinator named when it was refused, so
+// the caller can name it (M2 review P2). errors.Is(err,
+// ErrFleetBoxCoordinated) holds for it.
+type FleetBoxCoordinatedError struct {
+ Box string
+}
+
+func (e *FleetBoxCoordinatedError) Error() string {
+ return ErrFleetBoxCoordinated.Error() + ": " + e.Box
+}
+
+func (e *FleetBoxCoordinatedError) Unwrap() error { return ErrFleetBoxCoordinated }
+
// firstLabelBeforeWrite, when set, runs in SetRecordFirstFleetBox's
// mutation after the record it read passed every check and before the
// write's CAS (tests only: an interleaving seam). Nil in production.
@@ -120,8 +134,9 @@ var firstLabelBeforeWrite func(host string)
// - Move is nil (ErrFleetBoxMoveInFlight);
// - the seed does not block a move (ErrFleetBoxImportInFlight, wrapping a
// *SeedMoveError);
-// - no unexpired Coordinator names another box (ErrFleetBoxCoordinated).
-// A coordinator with no expiry counts as unexpired.
+// - no unexpired Coordinator names another box (ErrFleetBoxCoordinated,
+// as a *FleetBoxCoordinatedError naming that box). A coordinator with
+// no expiry counts as unexpired.
//
// It answers the record as written.
func SetRecordFirstFleetBox(ctx context.Context, s release.Store, acct, app, host string, want FleetBoxExpect, label string, at time.Time) (*Record, error) {
@@ -148,7 +163,7 @@ func SetRecordFirstFleetBox(ctx context.Context, s release.Store, acct, app, hos
return fmt.Errorf("%w: %w", ErrFleetBoxImportInFlight, &SeedMoveError{Block: b})
}
if c := rec.Coordinator; c != nil && c.Box != label && (c.ExpiresAt.IsZero() || time.Now().Before(c.ExpiresAt)) {
- return ErrFleetBoxCoordinated
+ return &FleetBoxCoordinatedError{Box: c.Box}
}
rec.FleetBox = label
rec.FleetBoxAt = at.UTC().Format(time.RFC3339Nano)
diff --git a/internal/provision/fleetbox_first_test.go b/internal/provision/fleetbox_first_test.go
index daca95184..64d65fcdc 100644
--- a/internal/provision/fleetbox_first_test.go
+++ b/internal/provision/fleetbox_first_test.go
@@ -152,6 +152,11 @@ func TestFirstLabelRefusesALiveCoordinatorElsewhere(t *testing.T) {
if !errors.Is(err, ErrFleetBoxCoordinated) {
t.Fatalf("err = %v, want ErrFleetBoxCoordinated", err)
}
+ // M2 review P2: the refusal names the coordinating box it read.
+ var ce *FleetBoxCoordinatedError
+ if !errors.As(err, &ce) || ce.Box != "pi-2" {
+ t.Fatalf("err = %v, want a *FleetBoxCoordinatedError naming pi-2", err)
+ }
wantUnlabelled(t, s)
}