system: hold-edit floor counts silent and unread boxes, audits first
RC-guard P2s. The floor guard reads the inventory with its completeness (systemBoxesInventory): a heartbeat that could not be read refuses unless the override is passed, and the override's audit row says the inventory was incomplete. A box last known below the floor keeps blocking when it stops reporting, named "(not reporting)", until it reports at the floor or is taken out (a detached fleet row, a departed group member); other-channel boxes are still left out. An applied hold edit is audited, override included, before the reservation check after the write, and a failed check gets its own row.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4 files changed,
+202
−39
docs/site/cli.md+1 −1internal/console/apisystemhold.go+43 −22internal/console/apisystemhold_test.go+135 −6internal/console/apisystemupdate.go+23 −10
diff --git a/docs/site/cli.md b/docs/site/cli.md| index 80ecf1225..f19c67f3c 100644 |
| --- a/docs/site/cli.md |
| +++ b/docs/site/cli.md |
| @@ -3720,7 +3720,7 @@ A hold lasts 2 hours unless you pass `--for`, and at most 24 hours, so a forgott |
| Every console that can write the channel must run a release with holds before you rely on them: an older console drops every hold when it updates or rolls back the channel. Holds are not available on a deployment that reserves each platform update for its boxes: `update --hold`, `hold` and `release` are refused there. |
| -A box running a release before v0.44.0 takes any hold change for a new update. If it rolled that update back, it tries it again, once for every change. So `carlos system hold` and `carlos system release` are refused while a reporting box on the channel runs a release before v0.44.0, and the refusal names those boxes. To move a channel with older boxes onto holds: |
| +A box running a release before v0.44.0 takes any hold change for a new update. If it rolled that update back, it tries it again, once for every change. So `carlos system hold` and `carlos system release` are refused while a box on the channel runs a release before v0.44.0, and the refusal names those boxes. To move a channel with older boxes onto holds: |
| 1. Stop changing holds on the channel. |
| 2. Update every console that writes the channel to v0.44.0 or later. |
diff --git a/internal/console/apisystemhold.go b/internal/console/apisystemhold.go| index be9718f58..e5aa538ad 100644 |
| --- a/internal/console/apisystemhold.go |
| +++ b/internal/console/apisystemhold.go |
| @@ -202,25 +202,24 @@ func (s *Server) refuseHoldsWithReservations(ctx context.Context) error { |
| return nil |
| } |
| -// holdEditReadersBelowFloor names each reporting box on channel whose |
| -// release is below release.SystemMovedAtFloor, as "<box> runs <release>": |
| -// a box that reads a hold edit as a new promote (SystemMovedAtFloor's |
| -// comment). Only reporting boxes count, as only they can be held |
| -// (systemHoldTarget): a box whose heartbeat is older than the window |
| -// `carlos system status` calls UNREACHABLE beyond is left out, and so is a |
| -// box on another channel. A fleet whose heartbeats cannot be read is an |
| -// error, since its boxes could not be judged. |
| -func (s *Server) holdEditReadersBelowFloor(ctx context.Context, channel string) ([]string, error) { |
| - boxes, fleets, _, err := s.systemBoxesTagged(ctx, true, false) |
| +// holdEditReadersBelowFloor names each box on channel whose release is |
| +// below release.SystemMovedAtFloor, as "<box> runs <release>": a box that |
| +// reads a hold edit as a new promote (SystemMovedAtFloor's comment). A box |
| +// that has stopped reporting still counts on its last report, named with |
| +// "(not reporting)": it may still read the channel, or come back after the |
| +// edit, so silence is not a compatible reader. It stops counting when it |
| +// reports at or above the floor, or is taken out: a fleet box its registry |
| +// row holds detached, a platform group member that has departed |
| +// (activeStatusRows). A box on another channel is left out. complete is |
| +// false when any heartbeat listed could not be read, so a box went |
| +// unjudged; a fleet whose heartbeats cannot be read at all is an error. |
| +func (s *Server) holdEditReadersBelowFloor(ctx context.Context, channel string) (old []string, complete bool, err error) { |
| + boxes, fleets, _, complete, err := s.systemBoxesInventory(ctx, true, true) |
| if err != nil { |
| - return nil, err |
| + return nil, false, err |
| } |
| now := time.Now() |
| - var old []string |
| for i, b := range boxes { |
| - if status.BoxStale(b, now, status.SnapshotPeriod) { |
| - continue |
| - } |
| follows, running := release.RungStable, "" |
| if b.Metrics != nil { |
| running = b.Metrics.Release |
| @@ -234,9 +233,13 @@ func (s *Server) holdEditReadersBelowFloor(ctx context.Context, channel string) |
| if running == "" { |
| running = "an unknown release" |
| } |
| - old = append(old, release.SystemHoldBox(fleets[i], b.Label)+" runs "+running) |
| + name := release.SystemHoldBox(fleets[i], b.Label) + " runs " + running |
| + if status.BoxStale(b, now, status.SnapshotPeriod) { |
| + name += " (not reporting)" |
| + } |
| + old = append(old, name) |
| } |
| - return old, nil |
| + return old, complete, nil |
| } |
| // holdEditFloorNamed caps how many boxes the refusal lists. |
| @@ -256,6 +259,13 @@ func holdEditFloorRefusal(channel string, old []string) holdRefusal { |
| "update those boxes to " + release.SystemMovedAtFloor + " or later first, or pass --" + release.SystemHoldEditFloorOverrideFlag + " to change the holds anyway"} |
| } |
| +// holdEditInventoryRefusal is the hold and release doors' answer when a |
| +// heartbeat could not be read, so a box on channel could not be judged. |
| +func holdEditInventoryRefusal(channel string) holdRefusal { |
| + return holdRefusal{http.StatusConflict, "nothing was changed. some box heartbeats could not be read, so it is not known whether every box on " + channel + " runs " + release.SystemMovedAtFloor + |
| + " or later. pass --" + release.SystemHoldEditFloorOverrideFlag + " to change the holds anyway"} |
| +} |
| + |
| // writeSystemHolds is the hold and release doors' shared write: the slot, |
| // the activation check, the moved_at floor (allowOld is the operator's |
| // override), the holds-only rewrite, the audit row and the serial bump |
| @@ -272,7 +282,7 @@ func (s *Server) writeSystemHolds(ctx context.Context, addr, channel, action, de |
| } |
| // The override skips the floor, not the reading: what it overrode goes |
| // on the audit row. |
| - old, err := s.holdEditReadersBelowFloor(ctx, channel) |
| + old, complete, err := s.holdEditReadersBelowFloor(ctx, channel) |
| switch { |
| case err != nil && !allowOld: |
| return fmt.Errorf("reading the box heartbeats to check every box on %s can read a hold change: %w", channel, err) |
| @@ -280,8 +290,16 @@ func (s *Server) writeSystemHolds(ctx context.Context, addr, channel, action, de |
| detail += "; override: allowed below " + release.SystemMovedAtFloor + " without reading every box (" + err.Error() + ")" |
| case len(old) > 0 && !allowOld: |
| return holdEditFloorRefusal(channel, old) |
| - case len(old) > 0: |
| - detail += "; override: allowed below " + release.SystemMovedAtFloor + " (" + strings.Join(old, "; ") + ")" |
| + case !complete && !allowOld: |
| + return holdEditInventoryRefusal(channel) |
| + case len(old) > 0 || !complete: |
| + detail += "; override: allowed below " + release.SystemMovedAtFloor |
| + if len(old) > 0 { |
| + detail += " (" + strings.Join(old, "; ") + ")" |
| + } |
| + if !complete { |
| + detail += " with an incomplete box inventory: some box heartbeats could not be read" |
| + } |
| } |
| var lastErr error |
| for attempt := 0; attempt < 3; attempt++ { |
| @@ -298,15 +316,18 @@ func (s *Server) writeSystemHolds(ctx context.Context, addr, channel, action, de |
| case lastErr != nil: |
| return lastErr |
| } |
| + // The write stands from here, so its audit row, with any override, |
| + // goes in before anything else can fail. |
| + s.auditSystem(addr, action, detail) |
| // After the write, the reservations check again: a host floor or |
| // roster that started between the first check and the write would |
| // otherwise sit beside this hold. Its writer clears holds it finds |
| // after its own write, so one side always sees the other; this side |
| - // takes its hold back. |
| + // takes its hold back. A failed check gets its own row. |
| if err := s.afterHoldWrite(ctx, "hold"); err != nil { |
| + s.auditSystem(addr, action, "after the write: "+err.Error()) |
| return err |
| } |
| - s.auditSystem(addr, action, detail) |
| s.bumpSerial(ctx) |
| return nil |
| } |
diff --git a/internal/console/apisystemhold_test.go b/internal/console/apisystemhold_test.go| index 45172eaf5..5d4b14aab 100644 |
| --- a/internal/console/apisystemhold_test.go |
| +++ b/internal/console/apisystemhold_test.go |
| @@ -585,17 +585,17 @@ func TestHoldEditsWaitForEveryReaderAtTheMovedAtFloor(t *testing.T) { |
| } |
| } |
| -// TestHoldEditsPassWhenEveryReportingReaderIsAtTheFloor: with every |
| -// reporting box on the channel at or above the floor the doors write |
| -// without the override, and say nothing of one. A box that is not |
| -// reporting, or follows another channel, is not counted even when it is |
| -// below the floor: it cannot be held on this channel either. |
| +// TestHoldEditsPassWhenEveryReportingReaderIsAtTheFloor: with every box |
| +// on the channel at or above the floor the doors write without the |
| +// override, and say nothing of one. A box that follows another channel is |
| +// not counted even when it is below the floor, and neither is a fleet box |
| +// the registry holds detached. |
| func TestHoldEditsPassWhenEveryReportingReaderIsAtTheFloor(t *testing.T) { |
| fx := newConsoleFixture(t) |
| owner := cliToken(t, fx, "paul@keymail.dev", "code-sys-hold-moved-at-ok") |
| updateHoldFleetWithPlat(t, fx, release.SystemMovedAtFloor, release.SystemMovedAtFloor) |
| - seedStaleBox(t, fx, "old-dark", "stable", "v0.43.11") |
| seedBox(t, fx, "old-canary", "linux-arm64", "canary", "v0.43.11") |
| + seedDetachedFleetBox(t, fx, "gone", "v0.43.11") |
| if _, err := release.PromoteSystem(context.Background(), fx.rel, release.RootSigner(fx.priv), "router", "stable", holdTestRelease("v0.44.0"), release.SystemPromoteOptions{}); err != nil { |
| t.Fatal(err) |
| } |
| @@ -611,3 +611,132 @@ func TestHoldEditsPassWhenEveryReportingReaderIsAtTheFloor(t *testing.T) { |
| } |
| } |
| } |
| + |
| +// seedDetachedFleetBox adds label to fleet pi running rel on stable, silent |
| +// for 20 minutes, with its registry row detached (carlos fleets |
| +// detach-box): a box taken out of the fleet. |
| +func seedDetachedFleetBox(t *testing.T, fx *consoleFixture, label, rel string) { |
| + t.Helper() |
| + reg := openTestReg(t, fx) |
| + defer reg.Close() |
| + if err := reg.AddFleetBox(registry.FleetBox{Fleet: "pi", Label: label, TokenHash: strings.Repeat("b", 64)}); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := reg.SetFleetBoxStatus("pi", label, "detached"); err != nil { |
| + t.Fatal(err) |
| + } |
| + b := status.CollectBox(nil, status.Probes{Release: rel, Platform: "linux-arm64", SystemChannel: "stable"}, time.Now().Add(-20*time.Minute)) |
| + b.Label = label |
| + if err := status.WriteBox(context.Background(), release.NewPrefixStore(fx.rel, "fleets/pi/"), b); err != nil { |
| + t.Fatal(err) |
| + } |
| +} |
| + |
| +// TestHoldEditsWaitForASilentBoxBelowTheFloor: a box that stopped |
| +// reporting may still read the channel, or come back after the edit, so |
| +// heartbeat silence does not make it a compatible reader. While its last |
| +// report is below the floor the doors refuse and name it as not |
| +// reporting; the refusal writes nothing. |
| +func TestHoldEditsWaitForASilentBoxBelowTheFloor(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + owner := cliToken(t, fx, "paul@keymail.dev", "code-sys-hold-silent") |
| + updateHoldFleetWithPlat(t, fx, release.SystemMovedAtFloor, release.SystemMovedAtFloor) |
| + seedStaleBox(t, fx, "old-dark", "stable", "v0.43.11") |
| + ctx := context.Background() |
| + if _, err := release.PromoteSystem(ctx, fx.rel, release.RootSigner(fx.priv), "router", "stable", holdTestRelease("v0.44.0"), release.SystemPromoteOptions{}); err != nil { |
| + t.Fatal(err) |
| + } |
| + before, _, _ := fx.rel.Get(ctx, release.SystemPointerKey("router", "stable")) |
| + for door, in := range map[string]map[string]any{ |
| + "/api/cli/system/hold": {"channel": "stable", "boxes": []string{"pi/a"}}, |
| + "/api/cli/system/hold/release": {"channel": "stable", "box": "pi/a"}, |
| + } { |
| + st, out := postJSON(t, fx.ts.URL+door, in, owner) |
| + msg := fmt.Sprint(out["error"]) |
| + if st != http.StatusConflict || !strings.Contains(msg, "old-dark runs v0.43.11 (not reporting)") { |
| + t.Errorf("%s with silent old-dark below the floor = %d %q, want 409 naming old-dark as not reporting", door, st, msg) |
| + } |
| + } |
| + if after, _, _ := fx.rel.Get(ctx, release.SystemPointerKey("router", "stable")); !bytes.Equal(before, after) { |
| + t.Fatal("a refused hold edit wrote the pointer") |
| + } |
| +} |
| + |
| +// TestHoldEditsRefuseAnIncompleteBoxInventory: a heartbeat that cannot be |
| +// read is a box that cannot be judged, on the platform's reports or a |
| +// fleet's. The doors refuse and write nothing; the override writes, and |
| +// its audit row says the inventory was incomplete. |
| +func TestHoldEditsRefuseAnIncompleteBoxInventory(t *testing.T) { |
| + for name, key := range map[string]string{ |
| + "platform": "status/boxes/broken.json", |
| + "fleet": "fleets/pi/status/boxes/broken.json", |
| + } { |
| + t.Run(name, func(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + owner := cliToken(t, fx, "paul@keymail.dev", "code-sys-hold-partial-"+name) |
| + updateHoldFleetWithPlat(t, fx, release.SystemMovedAtFloor, release.SystemMovedAtFloor) |
| + ctx := context.Background() |
| + if _, err := fx.rel.Put(ctx, key, []byte("{not json"), ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, err := release.PromoteSystem(ctx, fx.rel, release.RootSigner(fx.priv), "router", "stable", holdTestRelease("v0.44.0"), release.SystemPromoteOptions{}); err != nil { |
| + t.Fatal(err) |
| + } |
| + before, _, _ := fx.rel.Get(ctx, release.SystemPointerKey("router", "stable")) |
| + st, out := postJSON(t, fx.ts.URL+"/api/cli/system/hold", map[string]any{"channel": "stable", "boxes": []string{"pi/a"}}, owner) |
| + msg := fmt.Sprint(out["error"]) |
| + if st != http.StatusConflict || !strings.Contains(msg, "could not be read") || !strings.Contains(msg, "--"+release.SystemHoldEditFloorOverrideFlag) { |
| + t.Fatalf("hold with an unreadable heartbeat = %d %q, want 409 saying so and naming the override", st, msg) |
| + } |
| + if after, _, _ := fx.rel.Get(ctx, release.SystemPointerKey("router", "stable")); !bytes.Equal(before, after) { |
| + t.Fatal("a refused hold edit wrote the pointer") |
| + } |
| + if rows := holdAudits(t, fx, "system-hold"); len(rows) != 0 { |
| + t.Fatalf("a refused hold edit was audited: %+v", rows) |
| + } |
| + if st, out := postJSON(t, fx.ts.URL+"/api/cli/system/hold", map[string]any{"channel": "stable", "boxes": []string{"pi/a"}, "allow_below_hold_edit_floor": true}, owner); st != http.StatusOK { |
| + t.Fatalf("hold with the override = %d %v", st, out) |
| + } |
| + if rows := holdAudits(t, fx, "system-hold"); len(rows) != 1 || !strings.Contains(rows[0].Detail, "override") || !strings.Contains(rows[0].Detail, "incomplete") { |
| + t.Fatalf("audit = %+v, want one row naming the override and the incomplete inventory", rows) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// TestHoldOverrideIsAuditedWhenTheCheckAfterFails: once the holds are |
| +// written, the audit row names the change and the override before the |
| +// reservation check after the write runs, and a second row records that |
| +// the check failed, so an applied override is always attributable. |
| +func TestHoldOverrideIsAuditedWhenTheCheckAfterFails(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + owner := cliToken(t, fx, "paul@keymail.dev", "code-sys-hold-audit-after") |
| + updateHoldFleet(t, fx, release.SystemMovedAtFloor) |
| + ctx := context.Background() |
| + if _, err := release.PromoteSystem(ctx, fx.rel, release.RootSigner(fx.priv), "router", "stable", holdTestRelease("v0.44.0"), release.SystemPromoteOptions{}); err != nil { |
| + t.Fatal(err) |
| + } |
| + fx.srv.cfg.Releases = &checkFailsAfterWriteStore{Store: fx.srv.cfg.Releases} |
| + st, out := postJSON(t, fx.ts.URL+"/api/cli/system/hold", map[string]any{"channel": "stable", "boxes": []string{"pi/a"}, "allow_below_hold_edit_floor": true}, owner) |
| + if st == http.StatusOK || !strings.Contains(fmt.Sprint(out["error"]), "failed, so every hold was kept") { |
| + t.Fatalf("hold = %d %v, want the kept-holds answer", st, out) |
| + } |
| + p, _, err := release.GetSystemPointer(ctx, fx.rel, fx.pub, "router", "stable") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, ok := p.HoldFor("pi", "a"); !ok { |
| + t.Fatalf("holds = %+v, want pi/a kept", p.Holds) |
| + } |
| + rows := holdAudits(t, fx, "system-hold") |
| + if len(rows) != 2 { |
| + t.Fatalf("audit = %+v, want the write and the check's outcome", rows) |
| + } |
| + // Newest first: the check's failure, then the write and its override. |
| + if !strings.Contains(rows[1].Detail, "held pi/a") || !strings.Contains(rows[1].Detail, "override") || !strings.Contains(rows[1].Detail, "plat runs v0.43.11") || rows[1].Address != "paul@keymail.dev" { |
| + t.Errorf("write row = %+v, want the hold and the override by paul", rows[1]) |
| + } |
| + if !strings.Contains(rows[0].Detail, errHoldCheckUnreadable) || rows[0].Address != "paul@keymail.dev" { |
| + t.Errorf("check row = %+v, want the failed check by paul", rows[0]) |
| + } |
| +} |
diff --git a/internal/console/apisystemupdate.go b/internal/console/apisystemupdate.go| index 0f0a147bc..2cff9e1a5 100644 |
| --- a/internal/console/apisystemupdate.go |
| +++ b/internal/console/apisystemupdate.go |
| @@ -280,14 +280,26 @@ func (s *Server) systemBoxesFiltered(ctx context.Context, strict, skipRetiredGro |
| // ("" for a platform box), index for index: what the update holds name a |
| // box by (release.SystemHold). |
| func (s *Server) systemBoxesTagged(ctx context.Context, strict, skipRetiredGroups bool) ([]status.Box, []string, bool, error) { |
| + boxes, tags, partial, _, err := s.systemBoxesInventory(ctx, strict, skipRetiredGroups) |
| + return boxes, tags, partial, err |
| +} |
| + |
| +// systemBoxesInventory is systemBoxesTagged that also says whether every |
| +// heartbeat listed was read (status.LoadBoxesComplete): complete is false |
| +// when any report, the platform's or a fleet's, failed to read, was |
| +// corrupt or oversize, or the listing was capped. A reader that must |
| +// account for every box (the hold-edit floor) refuses on it; the others |
| +// keep the logged skip. |
| +func (s *Server) systemBoxesInventory(ctx context.Context, strict, skipRetiredGroups bool) ([]status.Box, []string, bool, bool, error) { |
| reg, fleets, fleetsErr := s.systemFleets() |
| // The platform's heartbeats and each fleet's are read at once, then |
| // taken in the order they were always taken: the platform's, then the |
| // fleets in registry order. Each fleet's reports drop the boxes its |
| // registry rows hold detached (withoutDetached). |
| type read struct { |
| - boxes []status.Box |
| - err error |
| + boxes []status.Box |
| + complete bool |
| + err error |
| } |
| prefixes := []string{""} |
| if fleetsErr == nil { |
| @@ -297,7 +309,7 @@ func (s *Server) systemBoxesTagged(ctx context.Context, strict, skipRetiredGroup |
| } |
| reads := make([]read, len(prefixes)) |
| forEachLimit(len(prefixes), readConcurrency, func(i int) { |
| - b, _, err := s.loadBoxes(ctx, s.cfg.Releases, prefixes[i]) |
| + b, complete, err := s.loadBoxes(ctx, s.cfg.Releases, prefixes[i]) |
| if err == nil && i > 0 { |
| fleet := fleets[i-1].Name |
| detached, derr := detachedFleetBoxes(ctx, reg, fleet) |
| @@ -306,11 +318,11 @@ func (s *Server) systemBoxesTagged(ctx context.Context, strict, skipRetiredGroup |
| } |
| b = withoutDetached(b, detached) |
| } |
| - reads[i] = read{b, err} |
| + reads[i] = read{b, complete, err} |
| }) |
| - boxes, err := reads[0].boxes, reads[0].err |
| + boxes, complete, err := reads[0].boxes, reads[0].complete, reads[0].err |
| if err != nil { |
| - return nil, nil, false, err |
| + return nil, nil, false, false, err |
| } |
| if skipRetiredGroups { |
| boxes = s.activeStatusRows(ctx, boxes) |
| @@ -319,27 +331,28 @@ func (s *Server) systemBoxesTagged(ctx context.Context, strict, skipRetiredGroup |
| if fleetsErr != nil { |
| b, partial, err := s.systemFleetsUnreadable(boxes, strict, fleetsErr) |
| if err != nil { |
| - return nil, nil, false, err |
| + return nil, nil, false, false, err |
| } |
| - return b, tags, partial, nil |
| + return b, tags, partial, complete && !partial, nil |
| } |
| partial := false |
| for i, f := range fleets { |
| fb, err := reads[i+1].boxes, reads[i+1].err |
| if err != nil { |
| if strict { |
| - return nil, nil, false, fmt.Errorf("fleet %s: cannot read its box heartbeats, refusing to guess which platforms to mirror: %w", f.Name, err) |
| + return nil, nil, false, false, fmt.Errorf("fleet %s: cannot read its box heartbeats, refusing to guess which platforms to mirror: %w", f.Name, err) |
| } |
| log.Printf("console: api system: fleet %s boxes: %v", f.Name, err) |
| partial = true |
| continue |
| } |
| + complete = complete && reads[i+1].complete |
| boxes = append(boxes, fb...) |
| for range fb { |
| tags = append(tags, f.Name) |
| } |
| } |
| - return boxes, tags, partial, nil |
| + return boxes, tags, partial, complete && !partial, nil |
| } |
| // systemFleets is systemBoxes' fleet rule, shared with the size check |