carlos / platform Public

console: a box with no edges total takes its memory total from its own fresh status report

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 76c1f69e0307614b4eebf3eebd781497f56c889b parent f1152b2
2 files changed, +57 −5
  • internal/console/policysize.go +20 −5
  • internal/console/policysize_test.go +37 −0
diff --git a/internal/console/policysize.go b/internal/console/policysize.go
index 76bdcb0fb..c5ded6bc8 100644
--- a/internal/console/policysize.go
+++ b/internal/console/policysize.go
@@ -5,9 +5,11 @@
//
// The boxes come from the box listings, not from edges files (Astra plan
// R2-5): the platform's status reports and the account's fleet rosters.
-// The totals come from the edges files, joined on the file's box. Fleet
-// boxes publish no edges file, so their totals are unknown and only small
-// and standard can be set while one can take the app.
+// The totals come from the edges files, joined on the file's box, and
+// otherwise from the box's own fresh status report. Fleet boxes publish no
+// edges file, so theirs come from their fleet's status reports; a box with
+// neither is unknown, and only small and standard can be set while it can
+// take the app.
//
// Request budget (spec §3a, ruling 11): everything here is read only by a
// policy PUT that changes a size, never on an egress-only change and never
@@ -71,8 +73,9 @@ type sizeCommittedBox struct {
// With no records (an app default before any instance), every non-stale
// platform box and every active fleet box of the account.
//
-// A box's total is its edges file's box_mem_total_mib, else region HA's
-// headroom mem_total_mib (ruling C3); no file, or neither field, is 0.
+// A box's total is, in order: its edges file's box_mem_total_mib; region
+// HA's headroom mem_total_mib (ruling C3); its own status report's
+// mem_total_bytes, when that report is not stale. None of them is 0.
//
// complete is false when a status report could not be read, the registry
// or a fleet's roster could not be read, or an edges file could not be read
@@ -163,6 +166,18 @@ func (s *Server) sizeBoxes(ctx context.Context, acct *Account, recs []provision.
boxes = append(boxes, sb)
}
}
+ // A box with no total in an edges file falls back to its own status
+ // report's memory total, when the report is fresh (ruling, Task 9
+ // review): fleet boxes publish no edges file, so this is their total.
+ for i := range boxes {
+ b := &boxes[i]
+ if b.TotalMiB > 0 || b.report == nil || status.BoxStale(*b.report, now, status.SnapshotPeriod) {
+ continue
+ }
+ if m := b.report.Metrics; m != nil && m.MemTotalBytes != nil && *m.MemTotalBytes > 0 {
+ b.TotalMiB = *m.MemTotalBytes >> 20
+ }
+ }
slices.SortStableFunc(boxes, func(a, b sizeBox) int { return strings.Compare(a.Box, b.Box) })
return boxes, complete, nil
}
diff --git a/internal/console/policysize_test.go b/internal/console/policysize_test.go
index 9fbf92ee6..819123b5f 100644
--- a/internal/console/policysize_test.go
+++ b/internal/console/policysize_test.go
@@ -225,6 +225,43 @@ func TestSizeCapacityRefusesForAnEligibleBoxWithNoEdgesFile(t *testing.T) {
}
}
+// Ruling (Task 9 review): with no total in an edges file, a box's own fresh
+// status report gives it, so a fleet box (which publishes no edges file)
+// can take large when it reports its memory. No report, or a stale one, is
+// unknown.
+func TestSizeCapacityReadsATotalFromTheBoxsStatusReport(t *testing.T) {
+ t.Parallel()
+ fx, acct := sizeFx(t)
+ sixteen := int64(16) << 30
+ fresh := &status.BoxMetrics{MemTotalBytes: &sixteen}
+ putSizeReport(t, fx.rel, "annie", "", time.Now(), fresh) // no edges file
+ sizeFleet(t, fx, "fx", fx.sqid, "bx-1")
+ fleet := release.NewPrefixStore(fx.rel, "fleets/fx/")
+ recs := []provision.Record{sizeRecord(t, fx.rel, fx.sqid, "shop", shopHost, "")}
+
+ // bx-1 has no report yet.
+ if r := checkSizes(t, fx.srv, acct, recs, "large")["large"]; r == nil || r.Status != http.StatusConflict ||
+ !strings.HasPrefix(r.Msg, "bx-1 does not publish its memory total") {
+ t.Fatalf("large with no report from bx-1 = %+v, want 409 naming bx-1", r)
+ }
+ putSizeReport(t, fleet, "bx-1", "", time.Now(), fresh)
+ boxes, complete, err := fx.srv.sizeBoxes(context.Background(), acct, recs)
+ if err != nil || !complete {
+ t.Fatalf("sizeBoxes = %v, %v", complete, err)
+ }
+ if want := []sizeBox{{Box: "annie", TotalMiB: 16384}, {Box: "bx-1", TotalMiB: 16384, fleet: "fx"}}; !reflect.DeepEqual(noReports(boxes), want) {
+ t.Fatalf("boxes = %+v, want %+v", boxes, want)
+ }
+ if r := checkSizes(t, fx.srv, acct, recs, "large")["large"]; r != nil {
+ t.Fatalf("large with bx-1 reporting 16 GiB = %+v, want it to pass", r)
+ }
+ putSizeReport(t, fleet, "bx-1", "", time.Now().Add(-time.Hour), fresh)
+ if r := checkSizes(t, fx.srv, acct, recs, "large")["large"]; r == nil || r.Status != http.StatusConflict ||
+ !strings.HasPrefix(r.Msg, "bx-1 does not publish its memory total") {
+ t.Fatalf("large with bx-1's report stale = %+v, want 409 naming bx-1", r)
+ }
+}
+
func TestSizeBoxesComeFromTheListingsNotTheEdgesFiles(t *testing.T) {
t.Parallel()
fx, acct := sizeFx(t)