carlos / platform Public

release: one trash rule, TrashRetired, for fleet drains and HA

release.TrashRetired (marker positively present, production flag
positively clear via ProductionClear) is the one rule for "a trashed
app's records never hold HA or fleet work". The console's fleet drain
(#1008 T9) and the reconcile's productionClear now use it; the HA
departure scan uses it next (#1192).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev f80fb8a226376b128586dc519d2642e01424b48d parent 03ff5d1
4 files changed, +110 −23
  • internal/console/fleetrelabel.go +5 −18
  • internal/provision/reconcile.go +2 −5
  • internal/release/trash.go +32 −0
  • internal/release/trashretired_test.go +71 −0

Intent

Human

<paseo-system version="1" kind="agent-message" source-agent-id="8a3d302a-eac7-407c-b61c-f5ccc66b5544" message-id="18849fb0-bb08-4375-a9e2-eb3928ab8300"> Agent manager 8a3d302: agreed on all four, including the close-lost deviation (report and name the still-published record, no delete; the departure owns retirement). Note it&apos;s the same family as #1008 T9&apos;s &quot;trashed app record blocks a drain&quot;: check that both trash checks now share one rule for &quot;a trashed app&apos;s records never hold HA or fleet work&quot;. Carry on. </paseo-system>

diff --git a/internal/console/fleetrelabel.go b/internal/console/fleetrelabel.go
index 9abb17189..b5176106b 100644
--- a/internal/console/fleetrelabel.go
+++ b/internal/console/fleetrelabel.go
@@ -650,25 +650,12 @@ func (s *Server) drainBox(ctx context.Context, fleet, label string) (stuck []str
}
// trashRetired reports whether the boxes have retired app's routes because
-// it is in the Trash: its marker positively read (release.ReadAppTombstone)
-// and its production flag positively clear (release.GetProduction with
-// s.cfg.ReleasePub: absent, or present and not production). This is
-// reconcile's removable test (internal/provision/reconcile.go:1766-1775,
-// productionClear) asked of the same bucket. An unreadable marker or flag
-// is an error, which the caller treats as "still served".
+// it is in the Trash: release.TrashRetired, the one rule the departure scan
+// shares (#1192), asked of the same bucket with s.cfg.ReleasePub. An
+// unreadable marker or flag is an error, which the caller treats as "still
+// served".
func (s *Server) trashRetired(ctx context.Context, sqid, app string) (bool, error) {
- tomb, err := release.ReadAppTombstone(ctx, s.cfg.Releases, sqid, app)
- if err != nil {
- return false, err
- }
- if tomb == nil {
- return false, nil
- }
- flag, err := release.GetProduction(ctx, s.cfg.Releases, s.cfg.ReleasePub, sqid, app)
- if err != nil {
- return false, err
- }
- return flag == nil || !flag.Production, nil
+ return release.TrashRetired(ctx, s.cfg.Releases, s.cfg.ReleasePub, sqid, app)
}
// The values of `carlos fleets ls`'s labels_paused: absent when the fleet
diff --git a/internal/provision/reconcile.go b/internal/provision/reconcile.go
index 780da7732..2c153a565 100644
--- a/internal/provision/reconcile.go
+++ b/internal/provision/reconcile.go
@@ -325,15 +325,12 @@ type trashState struct {
// marker on purpose has to be told why nothing happened, or they will assume
// deletion is broken.
func productionClear(ctx context.Context, s release.Store, pub ed25519.PublicKey, acct, app string) bool {
- if pub == nil {
- return true
- }
- flag, err := release.GetProduction(ctx, s, pub, acct, app)
+ ok, err := release.ProductionClear(ctx, s, pub, acct, app)
switch {
case err != nil:
log.Printf("provision: cannot read the production flag for %s/%s — refusing to act on the trash marker: %v", acct, app, err)
return false
- case flag != nil && flag.Production:
+ case !ok:
log.Printf("provision: trash marker on production app %s/%s — refusing to act on it; turn production off first", acct, app)
return false
}
diff --git a/internal/release/trash.go b/internal/release/trash.go
index 33ae4f0c9..aaaccf214 100644
--- a/internal/release/trash.go
+++ b/internal/release/trash.go
@@ -94,6 +94,38 @@ func ReadAppTombstone(ctx context.Context, s Store, acct, app string) (*AppTombs
return &t, nil
}
+// ProductionClear is the production half of the trash rule: whether app's
+// production flag is positively clear (absent, or present and not
+// production). A nil pub is a box with no release key, which retires
+// trashed apps without reading the flag (internal/host agent.go), so it
+// answers clear. An unreadable flag is an error, never "clear".
+func ProductionClear(ctx context.Context, s Store, pub ed25519.PublicKey, acct, app string) (bool, error) {
+ if pub == nil {
+ return true, nil
+ }
+ flag, err := GetProduction(ctx, s, pub, acct, app)
+ if err != nil {
+ return false, err
+ }
+ return flag == nil || !flag.Production, nil
+}
+
+// TrashRetired is the one rule for "a trashed app's records never hold HA
+// or fleet work" (#1192, #1008 T9): true only when app's trash marker is
+// positively read and present AND its production flag is positively clear
+// (ProductionClear). That is exactly when the boxes retire the app's routes
+// (provision reconcile's removable), so no box will ever wake, adopt or
+// serve its hosts until a restore deletes the marker. Any read failure is
+// an error, which every caller treats as "still served": a fleet drain
+// keeps waiting and a departure keeps its host.
+func TrashRetired(ctx context.Context, s Store, pub ed25519.PublicKey, acct, app string) (bool, error) {
+ tomb, err := ReadAppTombstone(ctx, s, acct, app)
+ if err != nil || tomb == nil {
+ return false, err
+ }
+ return ProductionClear(ctx, s, pub, acct, app)
+}
+
// RestoreApp deletes the marker. Store.Delete is idempotent by contract, so
// restoring an app that is not in the trash is a no-op, not an error.
func RestoreApp(ctx context.Context, s Store, acct, app string) error {
diff --git a/internal/release/trashretired_test.go b/internal/release/trashretired_test.go
new file mode 100644
index 000000000..ee350d2ed
--- /dev/null
+++ b/internal/release/trashretired_test.go
@@ -0,0 +1,71 @@
+package release
+
+// TrashRetired is the one rule the fleet drain (#1008 T9) and the region
+// HA departure scan (#1192) share: an app's records stop holding work only
+// when its trash marker is positively present and its production flag is
+// positively clear. Every other answer, including a read failure, keeps
+// the work.
+
+import (
+ "context"
+ "testing"
+ "time"
+)
+
+func TestTrashRetired(t *testing.T) {
+ ctx := context.Background()
+ priv, pub := testKeys(t)
+
+ t.Run("live app", func(t *testing.T) {
+ s := NewDirStore(t.TempDir())
+ if got, err := TrashRetired(ctx, s, pub, "bab", "g6x"); got || err != nil {
+ t.Fatalf("TrashRetired(live) = %v, %v; want false, nil", got, err)
+ }
+ })
+ t.Run("trashed app", func(t *testing.T) {
+ s := NewDirStore(t.TempDir())
+ if err := TrashApp(ctx, s, "bab", "g6x", "paul@keymail.dev", time.Now()); err != nil {
+ t.Fatal(err)
+ }
+ if got, err := TrashRetired(ctx, s, pub, "bab", "g6x"); !got || err != nil {
+ t.Fatalf("TrashRetired(trashed) = %v, %v; want true, nil", got, err)
+ }
+ // A keyless box retires trashed apps without reading the flag.
+ if got, err := TrashRetired(ctx, s, nil, "bab", "g6x"); !got || err != nil {
+ t.Fatalf("TrashRetired(trashed, no key) = %v, %v; want true, nil", got, err)
+ }
+ })
+ t.Run("trashed production app keeps its work", func(t *testing.T) {
+ s := NewDirStore(t.TempDir())
+ if err := SetProduction(ctx, s, priv, "bab", "g6x", true, "paul@keymail.dev"); err != nil {
+ t.Fatal(err)
+ }
+ if err := TrashApp(ctx, s, "bab", "g6x", "paul@keymail.dev", time.Now()); err != nil {
+ t.Fatal(err)
+ }
+ if got, err := TrashRetired(ctx, s, pub, "bab", "g6x"); got || err != nil {
+ t.Fatalf("TrashRetired(trashed production) = %v, %v; want false, nil", got, err)
+ }
+ })
+ t.Run("unreadable marker is an error", func(t *testing.T) {
+ s := NewDirStore(t.TempDir())
+ if _, err := s.Put(ctx, AppTombstoneKey("bab", "g6x"), []byte(`{"schema":2}`), ""); err != nil {
+ t.Fatal(err)
+ }
+ if got, err := TrashRetired(ctx, s, pub, "bab", "g6x"); got || err == nil {
+ t.Fatalf("TrashRetired(bad marker) = %v, %v; want false and an error", got, err)
+ }
+ })
+ t.Run("unreadable flag is an error", func(t *testing.T) {
+ s := NewDirStore(t.TempDir())
+ if err := TrashApp(ctx, s, "bab", "g6x", "paul@keymail.dev", time.Now()); err != nil {
+ t.Fatal(err)
+ }
+ if _, err := s.Put(ctx, ProductionKey("bab", "g6x"), []byte(`not json`), ""); err != nil {
+ t.Fatal(err)
+ }
+ if got, err := TrashRetired(ctx, s, pub, "bab", "g6x"); got || err == nil {
+ t.Fatalf("TrashRetired(bad flag) = %v, %v; want false and an error", got, err)
+ }
+ })
+}