carlos / platform Public

plans: ops exemption settlement clears only the limits record and cap rows (round 3 cut, #455)

Round 3 (NOT READY at c7d07387): the storage-deny step could mark
settlement done with a deny left, since convergeStoreDeny answers nil
on a failed grant check or seal-key read. Paul chose the cut
(discussion 455).

settlePlanExempt now clears only what ops can have today: it deletes
the limits record (accounts/<sqid>/limits.json, carrying the limits,
the 4c throttle and the 4d turned-off hosts) and the cap rows
(plan_cap_state). Both steps return their errors, so a failure leaves
settlement not done and the next pass retries
(TestPlanExemptSettleClearsLimitsAndCapRows fails the delete once).

The storage-deny and lapse-item steps are gone, with
convergeStoresOf, which only the storage step used: planstorage.go is
back to main's. No storage deny, mail pause or lapse item can exist on
ops on any deployment: the flagship never had a plan catalog, and dev's
ops was sponsored a minute after plans went on, days before those
stages could act. The exemption stops new ones (EffectiveLimits is nil
for ops). docs/site/plans.md says only what is still true.

Two tests from the main merge use the ops fixture account under a plan
(TestPlacementsPutPlanCapComesFirst, TestPerfWriteRoutesMeetTheBudget):
both now call governOps.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev 0ad4a3da59395626cec41e8a8ca56cbf585e0c2c parent 75fe78e
6 files changed, +63 −97
  • docs/site/plans.md +1 −1
  • internal/console/apiplacements_put_test.go +1 −0
  • internal/console/perfwrites_test.go +1 −0
  • internal/console/planexempt.go +17 −49
  • internal/console/planexempt_test.go +43 −39
  • internal/console/planstorage.go +0 −8

CI passed — run details

diff --git a/docs/site/plans.md b/docs/site/plans.md
index 212271f8d..c91feb5d8 100644
--- a/docs/site/plans.md
+++ b/docs/site/plans.md
@@ -46,7 +46,7 @@ The console writes each account's limits to `accounts/<sqid>/limits.json` in the
## The ops account
-The deployment's built-in ops account (`bab`) is exempt from plans. It has no limits, caps or billing, and owning it doesn't count toward anyone's free account. `carlos accounts plan --account bab` says so and changes nothing. If it was under a plan before, the console removes the limits, storage blocks and warnings that plan left.
+The deployment's built-in ops account (`bab`) is exempt from plans. It has no limits, caps or billing, and owning it doesn't count toward anyone's free account. `carlos accounts plan --account bab` says so and changes nothing. If it was under a plan before, the console removes the limits and warnings that plan left.
## Sponsored accounts
diff --git a/internal/console/apiplacements_put_test.go b/internal/console/apiplacements_put_test.go
index 6510ae245..b2b2fa12b 100644
--- a/internal/console/apiplacements_put_test.go
+++ b/internal/console/apiplacements_put_test.go
@@ -1050,6 +1050,7 @@ func TestPlacementsPutPlanCapComesFirst(t *testing.T) {
attachShopClaim(t, w.fx, w.fx.sqid, "shop", "alias.example.com", rdIE)
attachShopClaim(t, w.fx, "zzz", "blog", "theirs.example.com", "theirs.example.net")
w.fx.srv.cfg.PlanCatalog = examplePlanCatalog(t)
+ governOps(w.fx) // the fixture account is ops
if _, err := w.fx.st.SetAccountPlan(OpsAccountID, "free", nil, 0, PlanSourceOperator, nil, "r", "ops@example.com", time.Now()); err != nil {
t.Fatal(err)
}
diff --git a/internal/console/perfwrites_test.go b/internal/console/perfwrites_test.go
index fc706b6f8..2f188699b 100644
--- a/internal/console/perfwrites_test.go
+++ b/internal/console/perfwrites_test.go
@@ -69,6 +69,7 @@ func newPerfWritesFx(t *testing.T) perfWritesFx {
if err != nil || acct == nil {
t.Fatalf("account %s: %v", fx.sqid, err)
}
+ governOps(fx) // the fixture account is ops, which plans exempt
applyPlan(t, fx, acct, "free", nil, &plans.Limits{RunningThings: 10000, SidecarsPerApp: 10}, now)
codes := []string{"ie", "uk", "us"}
for i := perfFlagshipInstances; i < perfWritesInstances; i++ {
diff --git a/internal/console/planexempt.go b/internal/console/planexempt.go
index 497d10f44..42c2db509 100644
--- a/internal/console/planexempt.go
+++ b/internal/console/planexempt.go
@@ -6,7 +6,6 @@ import (
"fmt"
"log"
"os"
- "slices"
"time"
"github.com/carlosframework/platform/internal/plans"
@@ -41,31 +40,28 @@ var errPlanExempt = errors.New("console: " + planCopyExempt)
// errBillingExempt refuses a billing door for the exempt account.
var errBillingExempt = billingRefusal{Key: "notice.exempt"}
-// settlePlanExempt is the one place that clears what plan stages put on
-// the exempt account before it was exempt. It runs once per console start,
-// from the first limits pass, and is done only when every step succeeded;
-// a failure is retried on the next pass. Each step is conditional, and
+// settlePlanExempt is the one place that clears what a plan left on the
+// exempt account before it was exempt. It runs once per console start,
+// from the first limits pass, and is done only when both steps succeeded;
+// a failure leaves it not done, and the next pass retries. Each step
// changes nothing when its state is absent:
//
// - the limits record (plans 2; accounts/<sqid>/limits.json), which is
// how the plan's limits, the 4c throttle and the 4d turned-off hosts
// reach the boxes: deleted, so boxes read no limits, no throttle and
// nothing turned off;
-// - storage denies (4b) on the stores of every app, live or trashed:
-// lifted, so a restored app takes uploads again;
-// - cap rows (4a), behind warning emails, banners, CLI warning headers
-// and the after-grace stages: deleted;
-// - lapse items (4d), behind the turned-off list, its banners and the keep
-// page: deleted, for every app the account still has a row for.
+// - cap rows (4a, plan_cap_state), behind warning emails, banners and CLI
+// warning headers: deleted.
+//
+// Nothing else is cleared (Paul's cut, discussion 455): no storage deny,
+// plan mail pause or lapse item can exist on ops on any deployment. The
+// flagship never had a plan catalog, and dev's ops was sponsored a minute
+// after plans went on there, days before the storage, email or lapse
+// stages could act. The exemption stops new ones: EffectiveLimits is nil
+// for ops, so no grace pass measures it.
//
// The account's plan row (its throttle, lapse mark and turned-off column)
// is left as it is: nothing reads it for ops, and it is never published.
-//
-// Plan mail pauses (4b, mail.PauseKindPlan) are not cleared here (Paul's
-// cut, discussion 455). None can exist on ops: the flagship has no plan
-// catalog, and dev's ops was sponsored within a minute of plans going on,
-// before any grace period could end. The exemption stops new ones, since
-// enforceAccountMail reads EffectiveLimits, which is nil for ops.
func (s *Server) settlePlanExempt(ctx context.Context, now time.Time) {
if s.planExemptSettled.Load() {
return
@@ -81,7 +77,7 @@ func (s *Server) settlePlanExempt(ctx context.Context, now time.Time) {
return
}
defer s.lapseLock(acct.ID)()
- if err := s.clearPlanState(ctx, acct, now); err != nil {
+ if err := s.clearPlanState(ctx, acct); err != nil {
log.Printf("console: plan limits: exempt account %s: %v", acct.Sqid, err)
jobFailed(ctx, fmt.Errorf("plan limits: exempt account %s: %w", acct.Sqid, err))
return
@@ -89,27 +85,13 @@ func (s *Server) settlePlanExempt(ctx context.Context, now time.Time) {
s.planExemptSettled.Store(true)
}
-// clearPlanState is settlePlanExempt's steps, in its order. Every step runs
-// whatever the others did.
-func (s *Server) clearPlanState(ctx context.Context, acct *Account, now time.Time) error {
+// clearPlanState is settlePlanExempt's two steps. Both run whatever the
+// other did, and every error comes back.
+func (s *Server) clearPlanState(ctx context.Context, acct *Account) error {
var errs []error
if err := s.cfg.Releases.Delete(ctx, plans.LimitsKey(acct.Sqid)); err != nil && !errors.Is(err, os.ErrNotExist) {
errs = append(errs, fmt.Errorf("limits record: %w", err))
}
- apps, err := s.store.AppsIn(acct.ID)
- if err != nil {
- return errors.Join(append(errs, fmt.Errorf("apps: %w", err))...)
- }
- trashed, err := s.store.TrashedAppsIn(acct.ID)
- if err != nil {
- return errors.Join(append(errs, fmt.Errorf("trashed apps: %w", err))...)
- }
- for _, t := range trashed {
- apps = append(apps, t.App)
- }
- if err := s.convergeStoresOf(ctx, acct, apps, false, capState{}, now); err != nil {
- errs = append(errs, fmt.Errorf("storage deny: %w", err))
- }
states, err := s.store.CapStates(acct.ID)
if err != nil {
errs = append(errs, fmt.Errorf("cap rows: %w", err))
@@ -119,19 +101,5 @@ func (s *Server) clearPlanState(ctx context.Context, acct *Account, now time.Tim
errs = append(errs, fmt.Errorf("cap row %s: %w", st.Cap, err))
}
}
- items, err := s.store.LapseItems(acct.ID)
- if err != nil {
- errs = append(errs, fmt.Errorf("lapse items: %w", err))
- }
- for _, it := range items {
- // An item of an app with no row at all cannot be admitted, and
- // with the record gone it turns nothing off.
- if !slices.Contains(apps, it.App) {
- continue
- }
- if err := s.store.DeleteLapseItem(ctx, acct.ID, it.App, it.Kind, it.Ref); err != nil {
- errs = append(errs, fmt.Errorf("lapse item %s %s: %w", it.Kind, it.Ref, err))
- }
- }
return errors.Join(errs...)
}
diff --git a/internal/console/planexempt_test.go b/internal/console/planexempt_test.go
index d72c0570a..3e692fcab 100644
--- a/internal/console/planexempt_test.go
+++ b/internal/console/planexempt_test.go
@@ -3,6 +3,7 @@ package console
import (
"context"
"database/sql"
+ "errors"
"go/ast"
"go/token"
"net/http"
@@ -11,10 +12,12 @@ import (
"sort"
"strconv"
"strings"
+ "sync/atomic"
"testing"
"time"
"github.com/carlosframework/platform/internal/plans"
+ "github.com/carlosframework/platform/internal/release"
)
// The ops account is exempt from plans (Paul, 2026-10-28): no limits
@@ -415,71 +418,72 @@ func (s *Server) EffectiveLimits(acct *Account) {}
}
}
-// ---- round 1: settlement clears every plan-enforced state ---------------------
+// ---- settlement: the limits record and cap rows ---------------------------
-// TestPlanExemptSettleClearsEveryPlanState: everything a plan stage put on
-// ops before the exemption is gone after one limits pass: the limits record
-// (with its throttle and turned-off hosts), a storage deny, even on an app
-// trashed since, cap rows behind warnings and banners, and lapse items.
-// The plan row stays. Plan mail pauses are not cleared (discussion 455).
-func TestPlanExemptSettleClearsEveryPlanState(t *testing.T) {
- fx, fake, ops := deniedStoreFixture(t, "code-plan-exempt-settle") // ops governed
- ctx := context.Background()
- capsApp(t, fx, ops, "blog")
+// failingDelete fails Delete of one key while fail is set.
+type failingDelete struct {
+ release.Store
+ key string
+ fail *atomic.Bool
+}
- // Under a plan: a storage deny on titogo.
- st := storageRow(ops, 3_000_000_000, 1_000_000_000, planNow)
- if err := fx.srv.convergeStorageDeny(ctx, ops, st, true, planNow); err != nil {
- t.Fatal(err)
- }
- if rec := titogoStore(t, fx); rec.WritesDenied == nil || !hasWriteDeny(t, fake.PolicyFor(rec.Provisioned.IAMUser)) {
- t.Fatal("setup: no deny")
+func (f failingDelete) Delete(ctx context.Context, key string) error {
+ if key == f.key && f.fail.Load() {
+ return errors.New("bucket unavailable")
}
+ return f.Store.Delete(ctx, key)
+}
+
+// TestPlanExemptSettleClearsLimitsAndCapRows: what a plan left on ops
+// before the exemption, its limits record (limits, throttle, turned-off
+// hosts) and its cap rows (warnings, banners), is gone after one limits
+// pass. A failed step leaves settlement not done, and the next pass
+// retries. The plan row stays.
+func TestPlanExemptSettleClearsLimitsAndCapRows(t *testing.T) {
+ fail := &atomic.Bool{}
+ fail.Store(true)
+ fx := newConsoleFixtureWith(t, consoleFixtureOptions{WithKey: true, WrapReleases: func(rs release.Store) release.Store {
+ return failingDelete{Store: rs, key: plans.LimitsKey(opsSqid), fail: fail}
+ }})
+ fx.srv.cfg.PlanCatalog = examplePlanCatalog(t)
+ ctx := context.Background()
+ ops := opsPlanAccount(t, fx, "paul@example.com")
+ rowBefore := opsSponsoredRow(t, fx, ops)
if err := fx.st.PutCapState(capState{AccountID: ops.ID, Cap: capEmail, Level: levelOver, Used: 200, Limit: 50,
Period: capPeriod(capEmail, planNow), FirstOver: planNow, GraceEnds: planNow, UpdatedAt: planNow}); err != nil {
t.Fatal(err)
}
- if err := fx.st.PutLapseItem(ctx, lapseItem{AccountID: ops.ID, App: "blog", Kind: lapseApp, Ref: "blog",
- ThingCreated: planNow, DisabledAt: planNow, UpdatedAt: planNow}); err != nil {
- t.Fatal(err)
- }
if _, err := plans.PutLimits(ctx, fx.rel, &plans.Record{Account: ops.Sqid, CatalogID: "old", Plan: "free",
Throttle: &plans.Throttle{Awake: true}, Disabled: []string{"blog.example.com"}}, ""); err != nil {
t.Fatal(err)
}
- rowBefore := opsSponsoredRow(t, fx, ops)
- // titogo is trashed before the exemption ships.
- if err := fx.st.TrashAppRow(ops.ID, "titogo", planNow); err != nil {
- t.Fatal(err)
+
+ // The bucket refuses the delete: not done, the record is still there.
+ fx.srv.planLimitsPass(ctx, planNow)
+ if fx.srv.planExemptSettled.Load() {
+ t.Fatal("settlement finished with the limits record left")
+ }
+ if r, _ := readLimits(t, fx, ops.Sqid); r == nil {
+ t.Fatal("setup: the failing delete removed the record")
}
- // The exemption ships: one limits pass.
- fx.st.planExemptID = OpsAccountID
+ // The next pass retries and finishes.
+ fail.Store(false)
fx.srv.planLimitsPass(ctx, planNow.Add(time.Minute))
if !fx.srv.planExemptSettled.Load() {
- t.Fatal("settlement did not finish")
+ t.Fatal("settlement did not finish on the retry")
}
-
if r, _ := readLimits(t, fx, ops.Sqid); r != nil {
t.Errorf("limits record left: %+v", r)
}
if states, _ := fx.st.CapStates(ops.ID); len(states) != 0 {
t.Errorf("cap rows left: %+v", states)
}
- if items, _ := fx.st.LapseItems(ops.ID); len(items) != 0 {
- t.Errorf("lapse items left: %+v", items)
- }
- if err := fx.st.RestoreAppRow(ops.ID, "titogo"); err != nil {
- t.Fatal(err)
- }
- if rec := titogoStore(t, fx); rec.WritesDenied != nil || hasWriteDeny(t, fake.PolicyFor(rec.Provisioned.IAMUser)) {
- t.Errorf("restored titogo still refuses uploads: %+v", rec.WritesDenied)
- }
if rowAfter, _ := fx.st.AccountPlan(ops.ID); rowAfter == nil || rowAfter.Revision != rowBefore.Revision {
t.Errorf("the ops row changed: %+v, was %+v", rowAfter, rowBefore)
}
- // Safe when nothing is left: a second settlement changes nothing.
+ // Safe when nothing is left: a second settlement finishes.
fx.srv.planExemptSettled.Store(false)
fx.srv.planLimitsPass(ctx, planNow.Add(2*time.Minute))
if !fx.srv.planExemptSettled.Load() {
diff --git a/internal/console/planstorage.go b/internal/console/planstorage.go
index dda46e796..2226f226f 100644
--- a/internal/console/planstorage.go
+++ b/internal/console/planstorage.go
@@ -55,14 +55,6 @@ func (s *Server) convergeStores(ctx context.Context, acct *Account, want bool, s
if err != nil {
return err
}
- return s.convergeStoresOf(ctx, acct, apps, want, st, now)
-}
-
-// convergeStoresOf is convergeStores over the named apps.
-func (s *Server) convergeStoresOf(ctx context.Context, acct *Account, apps []string, want bool, st capState, now time.Time) error {
- if s.cfg.PlanCatalog == nil || s.cfg.StoreProvisioner == nil {
- return nil
- }
var errs []error
for _, app := range apps {
envs, err := objstore.StoreEnvironments(ctx, s.cfg.Releases, acct.Sqid, app)