carlos / platform Public

host, status: demo backlog counts every output above the bound

Final fixes for demo disk slice 1. The backlog is one accounting
invariant (demoBacklog): per app, the larger of the outputs it keeps
above 8 plus its reserved ones, however pinned or held, and what
retention should have removed and kept. Held apps reach box status
(DemoBuilds.Held), the CLI shows them even at zero backlog and stops
promising the next pass for them, and the invalid-settings refusal names
CARLOS_DEMO_BOX. Pins and the staging refusal are unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 19a48183e966c358582a28dd799ff78bc091f122 parent 719fc3f
7 files changed, +271 −64
  • cli.go +10 −1
  • internal/host/demodisk_status.go +1 −1
  • internal/host/demodisk_status_test.go +2 −1
  • internal/host/demoretention.go +133 −58
  • internal/host/demoretention_test.go +106 −1
  • internal/status/demodisk.go +7 −2
  • statuslive_demodisk_test.go +12 −0
diff --git a/cli.go b/cli.go
index 8194b6303..84ae6d068 100644
--- a/cli.go
+++ b/cli.go
@@ -4244,11 +4244,20 @@ func printDemoDisk(w io.Writer, d *status.DemoDisk, now time.Time) {
held := b.OutputBytes
fmt.Fprintf(w, " demo builds kept: %d (%s) as of %s\n", b.Outputs, humanBytes(&held), b.At.UTC().Format(time.RFC3339))
if b.Backlog > 0 {
- fmt.Fprintf(w, " demo builds over the limit: %d since %s; the next adopt pass tries again\n", b.Backlog, b.BacklogSince.UTC().Format(time.RFC3339))
+ // A held app's builds stay until an operator clears the hold, so the
+ // next pass is only promised when nothing is held.
+ next := "; the next adopt pass tries again"
+ if len(b.Held) > 0 {
+ next = ""
+ }
+ fmt.Fprintf(w, " demo builds over the limit: %d since %s%s\n", b.Backlog, b.BacklogSince.UTC().Format(time.RFC3339), next)
if !b.BacklogSince.IsZero() && now.Sub(b.BacklogSince) > status.DemoBacklogStale {
fmt.Fprintln(w, " demo build cleanup has been behind for over 24 hours: check the adopt pass log on this box")
}
}
+ for _, h := range b.Held {
+ fmt.Fprintf(w, " demo updates refused for %s; its builds stay until that is fixed\n", h)
+ }
}
// alertsWord renders a box's alert-sink answer for the live listing. "not
diff --git a/internal/host/demodisk_status.go b/internal/host/demodisk_status.go
index a63ac7bdf..a27652e34 100644
--- a/internal/host/demodisk_status.go
+++ b/internal/host/demodisk_status.go
@@ -65,7 +65,7 @@ func readDemoBuilds(open func() (rootstate.Store, error)) (*status.DemoBuilds, e
if rec.Schema != 1 {
return nil, os.ErrInvalid
}
- return &status.DemoBuilds{Outputs: rec.Outputs, OutputBytes: rec.OutputBytes, At: rec.At, Backlog: rec.Backlog, BacklogSince: rec.BacklogSince}, nil
+ return &status.DemoBuilds{Outputs: rec.Outputs, OutputBytes: rec.OutputBytes, At: rec.At, Backlog: rec.Backlog, BacklogSince: rec.BacklogSince, Held: rec.Held}, nil
}
// diskReading is one filesystem's use and what was measured, which the
diff --git a/internal/host/demodisk_status_test.go b/internal/host/demodisk_status_test.go
index 383e116cb..77a3ac3ed 100644
--- a/internal/host/demodisk_status_test.go
+++ b/internal/host/demodisk_status_test.go
@@ -7,6 +7,7 @@ import (
"math"
"os"
"path/filepath"
+ "reflect"
"strings"
"testing"
"time"
@@ -69,7 +70,7 @@ func TestDemoBuildsReadsRootsRecord(t *testing.T) {
t.Fatal(err)
}
want := status.DemoBuilds{Outputs: 3, OutputBytes: 96, At: since, Backlog: 2, BacklogSince: since}
- if *got != want {
+ if !reflect.DeepEqual(*got, want) {
t.Fatalf("read %+v, want %+v", *got, want)
}
if _, err := readDemoBuilds(func() (rootstate.Store, error) { return &rollbackDisk{dir: t.TempDir()}, nil }); err == nil {
diff --git a/internal/host/demoretention.go b/internal/host/demoretention.go
index 11b1ce0f2..e33b540cf 100644
--- a/internal/host/demoretention.go
+++ b/internal/host/demoretention.go
@@ -58,9 +58,15 @@
// a pass that holds the lock on a correctly configured demo box
// (admitRoute, release.WithRouteAdmission, before the pass touches it). An
// app held by a registry row that is not a valid demo binding, or by
-// unread settings references, keeps every build, counts what it keeps
-// beyond the bound as backlog, is named with the reason in the record, and
-// stages nothing new until the hold clears.
+// unread settings references, keeps every build, is named with the reason
+// in the record and in box status, and stages nothing new until the hold
+// clears.
+//
+// The backlog is an accounting invariant (demoBacklog), not a by-product of
+// what retention may delete: for each app, the larger of the outputs it
+// keeps above its bound (8 plus those a generation reserves), however they
+// are pinned or held, and the outputs retention should have removed and
+// did not.
//
// The bound per demo app is (8 + G + R) x 32 MiB: six registry and
// settings pins (Version, PrevVersion, GoodVersion, the settings pin,
@@ -127,6 +133,9 @@ type demoRetentionStatus struct {
Backlog int `json:"backlog"`
BacklogSince time.Time `json:"backlog_since,omitzero"`
Reason string `json:"reason,omitempty"`
+ // Held is every held app as "<app>: <why>": it keeps every build and
+ // its updates are refused until the hold is cleared.
+ Held []string `json:"held,omitempty"`
}
type demoRetention struct {
@@ -183,8 +192,16 @@ type demoOutput struct {
held string
// inFlight: staged after every version its app's live links name.
inFlight bool
+ // reserved: a generations-file or root generation pin covers it, so it
+ // counts toward its app's G + R rather than against the bound.
+ reserved bool
}
+// demoOutputBound is the outputs a demo app may keep besides those a
+// generation reserves: six registry and settings pins, the previous link
+// and one pending output (the 8 of 8 + G + R).
+const demoOutputBound = 8
+
func (o demoOutput) path(optDir string) string {
return release.VersionPath(optDir, o.acct, o.version, o.app)
}
@@ -283,8 +300,7 @@ func inFlight(v string, adopted []string) bool {
// pins are complete for every app it does not cover and which is returned
// for the caller to hold those apps. Otherwise (the backlog estimate) a
// failed source adds nothing.
-func (r *demoRetention) pinSet(ctx context.Context, routes []registry.Route, strict bool) ([]string, *release.IncompleteRefsError, error) {
- var out []string
+func (r *demoRetention) pinSet(ctx context.Context, routes []registry.Route, strict bool) (out, reserved []string, _ *release.IncompleteRefsError, _ error) {
add := func(name string, paths release.StagedPaths, err error) error {
if err != nil {
if strict {
@@ -297,6 +313,15 @@ func (r *demoRetention) pinSet(ctx context.Context, routes []registry.Route, str
}
return nil
}
+ // The generation sources' pins are also kept apart: they are G and R.
+ addReserved := func(name string, paths release.StagedPaths, err error) error {
+ if err == nil {
+ for p := range paths {
+ reserved = append(reserved, filepath.Clean(p))
+ }
+ }
+ return add(name, paths, err)
+ }
box, err := release.BoxPins(r.optDir, routes)
var inc *release.IncompleteRefsError
if errors.As(err, &inc) && box != nil {
@@ -305,7 +330,7 @@ func (r *demoRetention) pinSet(ctx context.Context, routes []registry.Route, str
inc = nil
}
if err := add("live links and registry rows", box, err); err != nil {
- return nil, nil, err
+ return nil, nil, nil, err
}
if !strict {
// BoxPins answers nothing when one live link does not read; the
@@ -321,21 +346,21 @@ func (r *demoRetention) pinSet(ctx context.Context, routes []registry.Route, str
}
prev, err := linkTargets(filepath.Join(r.optDir, "previous"))
if err := add("previous links", prev, err); err != nil {
- return nil, nil, err
+ return nil, nil, nil, err
}
gen, err := release.GenerationPins(r.genPath, func() ([]registry.Route, error) { return routes, nil }).StagedPins(ctx, r.optDir)
- if err := add("generations file", gen, err); err != nil {
- return nil, nil, err
+ if err := addReserved("generations file", gen, err); err != nil {
+ return nil, nil, nil, err
}
var root release.StagedPaths
err = os.ErrPermission
if r.rootPins != nil {
root, err = r.rootPins.StagedPins(ctx, r.optDir)
}
- if err := add("root generation pins", root, err); err != nil {
- return nil, nil, err
+ if err := addReserved("root generation pins", root, err); err != nil {
+ return nil, nil, nil, err
}
- return out, inc, nil
+ return out, reserved, inc, nil
}
// linkTargets is every link's target in dir (<opt>/previous or <opt>/live,
@@ -455,33 +480,43 @@ const (
heldByRefs = "its settings references did not read in full"
)
+// demoSelection is one look at the store for the demo account's apps.
+type demoSelection struct {
+ // outs is every output present, marked.
+ outs []demoOutput
+ // hold says why an app is held, "" when it is not, for any app,
+ // whether or not it has outputs.
+ hold func(app string) string
+ // held is every held app of the demo account, outputs or not, as
+ // "<app>: <why>".
+ held []string
+}
+
// selection is one look at the store for the demo account's apps (only,
-// when set): every output present, marked. except is the version about to
-// be staged, which is kept. hold says why an app is held, "" when it is
-// not, for any app, whether or not it has outputs.
-func (r *demoRetention) selection(ctx context.Context, only, except string, strict bool) (outs []demoOutput, hold func(app string) string, err error) {
+// when set). except is the version about to be staged, which is kept.
+func (r *demoRetention) selection(ctx context.Context, only, except string, strict bool) (sel demoSelection, err error) {
if r.onPins != nil {
r.onPins()
}
acct, err := r.demoAccount()
if err != nil {
- return nil, nil, err
+ return sel, err
}
if r.reg == nil {
- return nil, nil, os.ErrPermission
+ return sel, os.ErrPermission
}
routes, err := r.reg.List()
if err != nil {
- return nil, nil, fmt.Errorf("list routes: %w", err)
+ return sel, fmt.Errorf("list routes: %w", err)
}
- pins, inc, err := r.pinSet(ctx, routes, strict)
+ pins, reserved, inc, err := r.pinSet(ctx, routes, strict)
if err != nil {
- return nil, nil, err
+ return sel, err
}
live, liveErr := linkTargets(filepath.Join(r.optDir, "live"))
if liveErr != nil {
if strict {
- return nil, nil, fmt.Errorf("live links: %w", liveErr)
+ return sel, fmt.Errorf("live links: %w", liveErr)
}
live = release.StagedPaths{}
}
@@ -491,7 +526,7 @@ func (r *demoRetention) selection(ctx context.Context, only, except string, stri
guarded[rt.App] = true
}
}
- hold = func(app string) string {
+ hold := func(app string) string {
switch {
case guarded[app]:
return heldByRow
@@ -500,9 +535,9 @@ func (r *demoRetention) selection(ctx context.Context, only, except string, stri
}
return ""
}
- outs, err = r.listOutputs(acct, only)
+ outs, err := r.listOutputs(acct, only)
if err != nil {
- return nil, nil, err
+ return sel, err
}
adopted := map[string][]string{}
for _, o := range outs {
@@ -527,16 +562,33 @@ func (r *demoRetention) selection(ctx context.Context, only, except string, stri
o.pinned = o.version == except || pinned(pins, r.optDir, *o)
o.held = hold(o.app)
o.inFlight = inFlight(o.version, adopted[o.app])
+ o.reserved = pinned(reserved, r.optDir, *o)
}
- return outs, hold, nil
+ var held []string
+ note := func(app string) {
+ if why := hold(app); why != "" && !slices.Contains(held, app+": "+why) {
+ held = append(held, app+": "+why)
+ }
+ }
+ for _, rt := range routes {
+ if release.RouteAccount(rt) == acct && validDemoName(rt.App) && (only == "" || rt.App == only) {
+ note(rt.App)
+ }
+ }
+ for _, o := range outs {
+ note(o.app)
+ }
+ sort.Strings(held)
+ return demoSelection{outs: outs, hold: hold, held: held}, nil
}
// planRemovals is what retention removes from outs: every output nothing
// pins that is not its app's newest pending output, and nothing of a held
-// app. backlog counts what it keeps beyond the bound: a held app's
-// outputs it would otherwise remove, and pending outputs beyond one where
-// the names cannot be ordered.
-func planRemovals(outs []demoOutput) (remove []int, backlog int) {
+// app. unremoved counts, per app, what it should remove and keeps: a held
+// app's outputs it would otherwise remove, and pending outputs beyond one
+// where the names cannot be ordered.
+func planRemovals(outs []demoOutput) (remove []int, unremoved map[string]int) {
+ unremoved = map[string]int{}
pending := map[string][]int{}
var apps []string
for i, o := range outs {
@@ -548,7 +600,7 @@ func planRemovals(outs []demoOutput) (remove []int, backlog int) {
}
pending[o.app] = append(pending[o.app], i)
case o.held != "":
- backlog++
+ unremoved[o.app]++
default:
remove = append(remove, i)
}
@@ -568,32 +620,46 @@ func planRemovals(outs []demoOutput) (remove []int, backlog int) {
}
}
if !ordered {
- backlog += len(idx) - 1
+ unremoved[app] += len(idx) - 1
continue
}
for _, i := range idx {
switch {
case i == newest:
case outs[i].held != "":
- backlog++
+ unremoved[app]++
default:
remove = append(remove, i)
}
}
}
sort.Ints(remove)
- return remove, backlog
+ return remove, unremoved
}
-// heldApps says, for each app of outs that is held, which and why.
-func heldApps(outs []demoOutput) []string {
- var apps []string
- for _, o := range outs {
- if why := o.app + ": " + o.held; o.held != "" && !slices.Contains(apps, why) {
- apps = append(apps, why)
+// demoBacklog is the accounting invariant behind the backlog: for each app,
+// the larger of the outputs it keeps above its bound (demoOutputBound plus
+// those a generation reserves), however they are pinned or held, and the
+// outputs retention should have removed and did not. So an app above its
+// bound always shows, whatever kept its outputs.
+func demoBacklog(kept []demoOutput, unremoved map[string]int) int {
+ count, reserved := map[string]int{}, map[string]int{}
+ for _, o := range kept {
+ count[o.app]++
+ if o.reserved {
+ reserved[o.app]++
+ }
+ }
+ for app := range unremoved {
+ if _, ok := count[app]; !ok {
+ count[app] = 0
}
}
- return apps
+ total := 0
+ for app, n := range count {
+ total += max(n-demoOutputBound-reserved[app], unremoved[app], 0)
+ }
+ return total
}
// removeOutput deletes one output beneath its version directory, the
@@ -617,56 +683,64 @@ type demoRetentionResult struct {
outputs int
outputBytes int64
backlog int
- err error
+ // held is every held app, as "<app>: <why>" (demoSelection.held).
+ held []string
+ err error
}
// retain is one retention run, deleting only under the lock and on a
// complete pin set.
func (r *demoRetention) retain(ctx context.Context) demoRetentionResult {
var res demoRetentionResult
- var outs []demoOutput
+ var sel demoSelection
if !r.locked {
res.err = errors.New("the adopt pass lock is not held")
} else {
- outs, _, res.err = r.selection(ctx, "", "", true)
+ sel, res.err = r.selection(ctx, "", "", true)
}
if res.err != nil {
// Deletes nothing. The backlog is estimated on what does read.
- est, _, err := r.selection(ctx, "", "", false)
+ est, err := r.selection(ctx, "", "", false)
if err != nil {
res.backlog = -1
return res
}
- remove, backlog := planRemovals(est)
- res.backlog = len(remove) + backlog
- for _, o := range est {
+ remove, unremoved := planRemovals(est.outs)
+ for _, i := range remove {
+ unremoved[est.outs[i].app]++
+ }
+ res.backlog, res.held = demoBacklog(est.outs, unremoved), est.held
+ for _, o := range est.outs {
res.outputs++
res.outputBytes += o.bytes
}
return res
}
- remove, backlog := planRemovals(outs)
- res.backlog = backlog
+ outs := sel.outs
+ remove, unremoved := planRemovals(outs)
gone := map[int]bool{}
var failed []error
for _, i := range remove {
o := outs[i]
if err := r.removeOutput(o); err != nil {
failed = append(failed, fmt.Errorf("%s: %w", o.path(r.optDir), err))
- res.backlog++
+ unremoved[o.app]++
continue
}
gone[i] = true
res.removed = append(res.removed, o.app+"@"+o.version)
}
+ var kept []demoOutput
for i, o := range outs {
if !gone[i] {
+ kept = append(kept, o)
res.outputs++
res.outputBytes += o.bytes
}
}
- if held := heldApps(outs); len(held) > 0 {
- failed = append(failed, fmt.Errorf("kept every build of %s", strings.Join(held, "; ")))
+ res.backlog, res.held = demoBacklog(kept, unremoved), sel.held
+ if len(sel.held) > 0 {
+ failed = append(failed, fmt.Errorf("kept every build of %s", strings.Join(sel.held, "; ")))
}
if len(failed) > 0 {
res.err = errors.Join(failed...)
@@ -707,10 +781,10 @@ func (r *demoRetention) saveStatus(res demoRetentionResult) {
if raw, err := s.Read(demoRetentionRecord); err == nil {
_ = json.Unmarshal(raw, &prev)
}
- next := demoRetentionStatus{Schema: 1, At: now, Outputs: res.outputs, OutputBytes: res.outputBytes, Backlog: res.backlog}
+ next := demoRetentionStatus{Schema: 1, At: now, Outputs: res.outputs, OutputBytes: res.outputBytes, Backlog: res.backlog, Held: res.held}
if res.backlog < 0 {
// Nothing read at all: keep the last known numbers.
- next.Outputs, next.OutputBytes, next.Backlog = prev.Outputs, prev.OutputBytes, max(prev.Backlog, 1)
+ next.Outputs, next.OutputBytes, next.Backlog, next.Held = prev.Outputs, prev.OutputBytes, max(prev.Backlog, 1), prev.Held
}
if res.err != nil {
next.Reason = res.err.Error()
@@ -758,11 +832,12 @@ func (r *demoRetention) beforeStage(ctx context.Context, path string) error {
if !r.locked {
return errors.New("demo build cleanup: the adopt pass lock is not held")
}
- outs, hold, err := r.selection(ctx, k.app, ver, true)
+ sel, err := r.selection(ctx, k.app, ver, true)
if err != nil {
return fmt.Errorf("demo build cleanup: %w", err)
}
- if why := hold(k.app); why != "" {
+ outs := sel.outs
+ if why := sel.hold(k.app); why != "" {
return fmt.Errorf("demo build cleanup: %s: %s, so its build is not staged", k.app, why)
}
for _, o := range outs {
@@ -790,7 +865,7 @@ func (r *demoRetention) admitRoute(rt registry.Route) error {
return nil
}
if r.boxErr != nil {
- return fmt.Errorf("this box's demo settings in host.env are invalid (%v), so no demo build is adopted", r.boxErr)
+ return fmt.Errorf("host.env sets CARLOS_DEMO_BOX, but the demo settings (CARLOS_DEMO_BOX, CARLOS_DEMO_ACCOUNT, CARLOS_DEMO_FLEET, CARLOS_DEMO_DOMAIN) are invalid (%v), so no demo build is adopted", r.boxErr)
}
if !r.box.BoxMode() || release.RouteAccount(rt) != r.box.Account {
return nil
diff --git a/internal/host/demoretention_test.go b/internal/host/demoretention_test.go
index 05ef13297..0ff2a8697 100644
--- a/internal/host/demoretention_test.go
+++ b/internal/host/demoretention_test.go
@@ -8,6 +8,7 @@ import (
"encoding/json"
"errors"
"fmt"
+ "math/rand/v2"
"os"
"path/filepath"
"runtime"
@@ -549,7 +550,7 @@ func TestDemoRetentionFailedOutputsDoNotAccumulate(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- pins, _, err := b.retention(true).pinSet(context.Background(), routes, true)
+ pins, _, _, err := b.retention(true).pinSet(context.Background(), routes, true)
if err != nil {
t.Fatal(err)
}
@@ -980,3 +981,107 @@ func TestAdoptPassAroundRefusesDemoBuildsOnAMisconfiguredDemoBox(t *testing.T) {
t.Fatalf("a misconfigured demo box adopted a demo build: %q", v)
}
}
+
+// Backlog is an accounting invariant, not a by-product of deletion: every
+// output an app keeps above its bound (8 plus what generations reserve)
+// counts, however it is pinned. Twelve outputs, the real row pinning the
+// newest, three conflicting non-demo rows pinning the nine oldest through
+// their Version, PrevVersion and GoodVersion: all twelve stay, the app is
+// held and its stage refused, and the backlog is the four above the bound.
+func TestDemoRetentionBacklogCountsAHeldAppsPinnedExcess(t *testing.T) {
+ b := newRetentionBox(t, "")
+ app := demoAppName("red")
+ b.addDemo("red", true)
+ b.adoptedAt("red", 12, 11, 12)
+ var rows []registry.Route
+ for i, host := range []string{"a.example.org", "b.example.org", "c.example.org"} {
+ rt := b.demoRow("red", true)
+ rt.Host, rt.Socket = host, provision.NestedSocket(host)
+ rt.DemoID, rt.DemoHost, rt.DemoLifetime, rt.DemoExpiresAt = "", "", "", 0
+ rt.Version, rt.PrevVersion, rt.GoodVersion = demoVer(3*i+1), demoVer(3*i+2), demoVer(3*i+3)
+ rows = append(rows, rt)
+ }
+ b.lister = forgedLister{reg: b.reg, rows: rows}
+ r := b.retention(true)
+ r.run(context.Background())
+ if got := b.outputs("shop", app); len(got) != 12 {
+ t.Fatalf("store %v, want all twelve kept", got)
+ }
+ if s := b.status(); s.Backlog != 4 || s.BacklogSince.IsZero() || !strings.Contains(s.Reason, app) {
+ t.Fatalf("record %+v, want backlog 4 (twelve kept, bound eight) and the hold named", s)
+ }
+ if err := r.beforeStage(context.Background(), release.VersionPath(b.opt, "shop", demoVer(13), app)); err == nil {
+ t.Fatal("the held app's next stage was not refused")
+ }
+ published, err := readDemoBuilds(func() (rootstate.Store, error) { return b.record, nil })
+ if want := []string{app + ": " + heldByRow}; err != nil || published.Backlog != 4 || !slices.Equal(published.Held, want) {
+ t.Fatalf("published %+v (%v), want backlog 4 and held %v", published, err, want)
+ }
+}
+
+// The accounting invariant, as a guard: whatever pins, holds, pending
+// state and reservations the outputs carry, and whichever removals fail,
+// the backlog is at least every app's kept outputs above its bound
+// (demoOutputBound plus its reserved ones), and at least what retention
+// should have removed and kept.
+func TestDemoBacklogCoversEveryOutputAboveTheBound(t *testing.T) {
+ rng := rand.New(rand.NewPCG(1, 2))
+ sawOver := 0
+ for trial := 0; trial < 2000; trial++ {
+ var outs []demoOutput
+ for app := 0; app < 3; app++ {
+ n := rng.IntN(24)
+ for v := 1; v <= n; v++ {
+ o := demoOutput{demoAppKey: demoAppKey{"shop", fmt.Sprintf("app%d", app)}, version: demoVer(v)}
+ o.pinned, o.inFlight, o.reserved = rng.IntN(2) == 0, rng.IntN(3) == 0, rng.IntN(5) == 0
+ if rng.IntN(4) == 0 {
+ o.held = heldByRow
+ }
+ outs = append(outs, o)
+ }
+ }
+ remove, unremoved := planRemovals(outs)
+ gone := map[int]bool{}
+ for _, i := range remove {
+ if rng.IntN(4) == 0 {
+ unremoved[outs[i].app]++ // a removal that failed
+ continue
+ }
+ gone[i] = true
+ }
+ var kept []demoOutput
+ count, reserved := map[string]int{}, map[string]int{}
+ for i, o := range outs {
+ if gone[i] {
+ continue
+ }
+ kept = append(kept, o)
+ count[o.app]++
+ if o.reserved {
+ reserved[o.app]++
+ }
+ }
+ backlog := demoBacklog(kept, unremoved)
+ over, owed := 0, 0
+ for app, n := range count {
+ over += max(n-demoOutputBound-reserved[app], 0)
+ }
+ for _, n := range unremoved {
+ owed += n
+ }
+ if over > 0 {
+ sawOver++
+ }
+ if backlog < over || backlog < owed {
+ t.Fatalf("trial %d: backlog %d, but %d outputs are above the bound and %d were not removed", trial, backlog, over, owed)
+ }
+ for i := range outs {
+ if gone[i] && (outs[i].pinned || outs[i].held != "") {
+ t.Fatalf("trial %d: removed a pinned or held output %+v", trial, outs[i])
+ }
+ }
+ }
+ if sawOver < 100 {
+ t.Fatalf("only %d trials kept an app above its bound; the guard needs many", sawOver)
+ }
+}
diff --git a/internal/status/demodisk.go b/internal/status/demodisk.go
index 3bd36749f..dd3c711b1 100644
--- a/internal/status/demodisk.go
+++ b/internal/status/demodisk.go
@@ -29,12 +29,17 @@ type FilesystemRoom struct {
const DemoBacklogStale = 24 * time.Hour
// DemoBuilds is the staged demo build outputs root's last retention run
-// left, and its backlog: outputs held beyond the bound because a run could
-// not delete them, with when that began (zero when there is none).
+// left, and its backlog: for each demo app, the larger of the outputs it
+// keeps above its bound and those the run could not delete, with when that
+// began (zero when there is none).
type DemoBuilds struct {
Outputs int `json:"outputs"`
OutputBytes int64 `json:"output_bytes"`
At time.Time `json:"at"`
Backlog int `json:"backlog"`
BacklogSince time.Time `json:"backlog_since,omitzero"`
+ // Held is every demo app whose builds are all kept and whose updates
+ // are refused until an operator clears the cause, as "<app>: <why>".
+ // Shown even with no backlog.
+ Held []string `json:"held,omitempty"`
}
diff --git a/statuslive_demodisk_test.go b/statuslive_demodisk_test.go
index 1bd101742..f190f4e1e 100644
--- a/statuslive_demodisk_test.go
+++ b/statuslive_demodisk_test.go
@@ -54,6 +54,18 @@ func TestPrintLiveBoxesShowsADemoBoxsDisk(t *testing.T) {
if want := " demo build cleanup has been behind for over 24 hours: check the adopt pass log on this box\n"; !strings.Contains(box(d), want) {
t.Fatalf("missing %q in:\n%s", want, box(d))
}
+ // A held app is shown even with no backlog, and a backlog beside a
+ // hold does not promise the next pass clears it.
+ d.Builds.Backlog, d.Builds.BacklogSince = 0, time.Time{}
+ d.Builds.Held = []string{"tmp-demo-amber-acorn-01: a registry row runs it as something other than a valid demo"}
+ if want := " demo updates refused for tmp-demo-amber-acorn-01: a registry row runs it as something other than a valid demo; its builds stay until that is fixed\n"; !strings.Contains(box(d), want) {
+ t.Fatalf("missing %q in:\n%s", want, box(d))
+ }
+ d.Builds.Backlog, d.Builds.BacklogSince = 4, now.Add(-2*time.Hour)
+ if got := box(d); !strings.Contains(got, " demo builds over the limit: 4 since 2026-11-30T10:00:00Z\n") || strings.Contains(got, "tries again") {
+ t.Fatalf("a held app's backlog:\n%s", got)
+ }
+ d.Builds.Held = nil
// Only what was read.
if got := box(&status.DemoDisk{Run: d.Run}); !strings.Contains(got, " free: /run 180.0MB and 230000 inodes\n") || strings.Contains(got, "demo builds") {
t.Fatalf("partial reading:\n%s", got)