Plans 4d-1 plan: lapse, disable and choose what stays
When a paid account's limits fall, running things beyond the cap, workers beyond the per-app cap and custom domains get 7 days' grace with notice, then are turned off through a host list in the limits record (edge page, activator refuses wakes) and come back at once when the plan covers them. Owners choose what stays. Outlines for 4d-2 (deletion via the Trash) and 4d-3 (schedules, always-on leftovers, fleets). Calls for Paul included.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+645
−0
docs/superpowers/plans/2026-10-25-plans-4d-lapse.md+645 −0
CI failed — run details
diff --git a/docs/superpowers/plans/2026-10-25-plans-4d-lapse.md b/docs/superpowers/plans/2026-10-25-plans-4d-lapse.md| new file mode 100644 |
| index 000000000..c60e8c7d3 |
| --- /dev/null |
| +++ b/docs/superpowers/plans/2026-10-25-plans-4d-lapse.md |
| @@ -0,0 +1,645 @@ |
| +# Plans 4d-1: Lapse, Disable and Choose What Stays Implementation Plan |
| + |
| +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. |
| + |
| +**Goal:** When a paid account's limits fall (a lapse, a downgrade, a pack reduction), what it no longer pays for gets 7 days' grace, and is then turned off: |
| +- running things beyond the cap, newest first unless an owner chose which stay; |
| +- workers beyond the per-app cap; |
| +- custom domains on a plan without them. |
| + |
| +A turned-off thing stops serving and shows a plain page. Its settings and data are kept, and it comes back as soon as the plan covers it again. Sponsored accounts never take this path. Deletion after 90 days is Plan 4d-2 (outline at the end). |
| + |
| +**Architecture:** |
| +- **Trigger:** "effective limits fell". `applyAccountPlan`, the one console path that changes a plan, marks `account_plans.lapse_since` when the old assignment was paid and the new limits are lower in a field this lifecycle governs. Operators use it today; Checkout (Plan 6) calls the same function. No Stripe event is involved. |
| +- **Grace and notice:** Plan 4a's engine. `running_things` already has a grace row. Two new lapse-only caps, `sidecars` and `custom_domains`, get rows the same way. `afterGraceDue` is the gate. |
| +- **Disable:** the hourly grace pass works out the set of things to turn off and stores it in two places: |
| + - `plan_lapse_items` (console bookkeeping: what is off since when, and owners' keep choices); |
| + - `account_plans.disabled`, a host list that the existing publish pass carries to boxes in the limits record as `plans.Record.Disabled`, the way Plan 4c carried `Throttle`. |
| +- **On the box:** `plansPass` keeps the list in its snapshot. The edge answers a disabled host with a page before the meter, the gate or any wake, and the activator refuses to wake or keep running a disabled route. |
| +- **Choose what stays:** an owner-only console page, `/a/{sqid}/plan/keep`. |
| + |
| +**Why the limits record and not a per-route state:** spec §7 names "suspended routes" as one of the things boxes read from the record. It rides a read every box already makes every five minutes, so it costs no new box requests. It has one writer (the console), and turning things back on is one record write, not one per instance. A registry column fed from instance records would need a record writer per kind (instances, sidecars, domain claims), a record-write census entry for each, and an edge reload per change. The record also fails open the way spec §7 wants: a box that never read it, or runs `CARLOS_PLAN_LIMITS=off`, serves everything. |
| + |
| +**Tech Stack:** Go; `internal/plans`, `internal/console`, `internal/host`, `internal/edge`, `internal/activator`. |
| + |
| +**Spec:** `docs/superpowers/specs/2026-10-20-plans-caps-packs-design.md`: |
| +- §9.2 (lapse and downgrade: grace 7 days, disabled, deleted 90 days later through the Trash; the account's choice, otherwise newest first; sponsored accounts never on this path); |
| +- §5.1 "Over the cap" (newest beyond the cap disabled, "stop serving, show a clear page"); |
| +- §6 (stages; the notice rule: grace ended and notice at least 72 h old); |
| +- §7 (boxes read "suspended routes" from the record; fail open); |
| +- §8.4 (custom domains paid-only); |
| +- §3 (Paul's rulings, not to be reopened). |
| + |
| +The plan builds on Plans 1, 2, 3a, 3b, 4a, 4b and 4c, all merged (main at `e16095cc`). |
| + |
| +## Scope split (Plan 4d) |
| + |
| +- **4d-1 (this plan):** |
| + - the trigger; |
| + - grace for the three leftovers; |
| + - the disable mechanism end to end; |
| + - choosing what stays; |
| + - turning things back on at once. |
| +- **4d-2 (outline below):** deletion 90 days after a thing was turned off, reminders 30, 7 and 1 days before, through the Trash. |
| +- **4d-3 (outline below):** the leftovers that are not turned off: |
| + - schedules faster than the minimum run at the minimum after grace; |
| + - always-on work on a fleet the app has left; |
| + - fleets themselves. |
| + |
| +## Global Constraints |
| + |
| +- **No catalog, no change.** |
| + - `applyAccountPlan` writes exactly what `SetAccountPlan` wrote before. |
| + - With no catalog: no `lapse_since`, no `disabled`, no `plan_lapse_items` row, no `Record.Disabled`, no keep page (404). |
| + - Edge and activator hooks are unset, or answer false. |
| +- **Box side:** a box with `CARLOS_PLAN_LIMITS=off`, without the marker, or that has never read the account's record disables nothing (fail open, spec §7). |
| +- **Sponsored accounts are never on this path** (§9.2, settled policy). `lapseEligible` is false when `row.Sponsored != nil || row.Source == PlanSourceSponsored`. An account that becomes sponsored has everything turned back on in the next pass. |
| +- **The trigger is "effective limits fell from a paid assignment".** |
| + - The old assignment was paid: its plan has `Paid` set, or it held any pack. |
| + - `plans.LimitsFell(old, new)` holds. It governs only `RunningThings`, `SidecarsPerApp`, `CustomDomains`, `Fleets` and `MinScheduleSeconds`. |
| + - Other caps have their own stages (4b, 4c), and those never delete. |
| + - A catalog edit is not a fall, because it does not pass through `applyAccountPlan` (Call 3). |
| +- **Eligible** = plans on, `lapse_since` set, and not sponsored. Only eligible accounts: |
| + - get `sidecars` and `custom_domains` rows; |
| + - have anything turned off. |
| + |
| + A non-eligible account over `running_things` keeps Plan 4a's behaviour: warnings, creation refused, nothing turned off. |
| +- **Turned off only after grace and notice:** per cap, `afterGraceDue(row, now)`. |
| + - During grace nothing new goes off. |
| + - Something already off stays off only while it is still beyond the current limits. |
| + - So a raise turns things back on at once, and a further fall waits for its own grace. |
| +- **Each fall restarts grace:** `applyAccountPlan` deletes the three lapse caps' rows, and the clocks start afresh. |
| +- **Newest first** across apps and instances by creation time (`apps.created_at`, `provision.Record.CreatedAt`). |
| + - Keeping an instance keeps its app, and the app counts. |
| + - Turning an app off turns off all its instances and sidecars. |
| + - Sidecars beyond the per-app cap go newest first within their app. |
| +- **Turned-off things still count** toward `running_things`, so creation stays refused until the account deletes something or the plan grows (§5.1 "if still over, deleted"). |
| +- **Unknown is not over:** an inventory that can't be read leaves the turned-off set exactly as it is, and the leftover rows unchanged. |
| +- **The public page** is a 503 with `no-store` and `noindex`. It never echoes the request and never mentions plans or payment (Call 1). |
| +- **Request budget** (memory `s3-requests-cost-money`): |
| + - **Boxes:** zero new requests. The host list rides the limits record read `plansPass` already makes. |
| + - **Console:** only eligible accounts, once per hourly pass, pay one LIST plus one GET per record for each live app's instances and sidecars. One shared, cached claims listing per pass covers domains. |
| + - **Writes:** one limits-record PUT per change to the turned-off set. |
| +- **Copy:** |
| + - console strings go in `internal/console/plancaps_copy.go` (`planNoticeCopy`, and a new `planKeepCopy`); |
| + - edge page words go in one const block in `internal/edge/plandisabled.go` (the `pending.go` pattern); |
| + - all of it goes through a Luna pass (gpt-5.6-luna via codex) against Paul's house rules: no em dashes, CLI strings lower case, human text only. |
| +- **No product or tenant names** in code, tests or copy. Use neutral examples (`shop`, `example.com`). |
| +- **Census:** |
| + - `plan_lapse_items` goes in `claimSQLTables` as app-scoped `{Account: "account_id", App: "app"}`, written only through `withAutoAppSQL` wrappers (the `doorkeys_store.go` pattern); |
| + - the two new routes go in `testdata/claim-routes.txt`; |
| + - no new worker; |
| + - the root-read census is re-pinned through `make census-card` and `make census-propose NAME=plans-4d-lapse CLAIMS=<file>`. New units are decisions with hand-written overlay rows. Astra approves, and decisions and escalations go to Paul; |
| + - no helper name contains "Record" except the existing `plans.PutLimits` path. |
| +- **Tests:** |
| + - TDD per task; touched packages only, with `-run`; CI runs the full suite; |
| + - inject `now` (`planNow`); |
| + - new `internal/host` and `internal/activator` tests call `t.Parallel()` unless they touch package vars or env. `planLimits` is a package var, so host tests that set it stay serial; |
| + - `GOFLAGS=-buildvcs=false` for anything that builds binaries. |
| + |
| +## Review Focus |
| + |
| +1. **Paying again turns things back on at once,** without waiting for the hourly pass. The plan change itself re-converges and publishes. Pinned in Task 5 (`TestApplyAccountPlanTurnsThingsBackOnAtOnce`). |
| +2. **An inventory read failure changes nothing:** a listing error or an unreadable record neither turns anything off nor back on. Pinned in Task 5 (`TestLapseUnchangedWhenInventoryUnreadable`). |
| +3. **No fall, no lapse; sponsored, never.** A free account that never paid, or a sponsored account, over its running-things cap past grace and notice has nothing turned off. Pinned in Task 5 (`TestNoLapseWithoutAFall`, `TestSponsoredAccountsNeverTurnedOff`). |
| +4. **A custom domain alias is turned off alone:** the instance's platform host keeps serving while its custom alias gets the page. Pinned in Task 7 (`TestDisabledAliasOnly`). |
| +5. **A turned-off route is never woken:** not by a schedule tick, a due wake or the always-on loop, and a running one stops. A move's probe wake still works. Pinned in Task 8 (`TestDisabledForSkipsDueAndAlwaysOn`, `TestServeScheduledRefusesDisabled`, `TestDisabledForStopsALiveEntry`, `TestDisabledForLeavesProbeWakes`). |
| + |
| +--- |
| + |
| +### Task 1: The limits record carries turned-off hosts; what counts as a fall |
| + |
| +**Files:** |
| +- Modify: `internal/plans/record.go` (`Record` gains `Disabled`). |
| +- Create: `internal/plans/lapse.go`. |
| +- Test: `internal/plans/record_test.go`, `internal/plans/lapse_test.go`. |
| + |
| +**Interfaces:** |
| +- Produces: |
| + ```go |
| + // Record gains: |
| + // Disabled lists hosts turned off after a lapse (plans 4d): instance and |
| + // sidecar hosts, custom domains, and "*.<parent>" for a catch-all. Sorted, |
| + // lower case. Boxes answer them with the disabled page and never wake them. |
| + Disabled []string `json:"disabled,omitempty"` |
| + |
| + // LimitsFell reports whether next is lower than old in a limit the lapse |
| + // lifecycle governs. |
| + func LimitsFell(old, next Limits) bool |
| + ``` |
| + `LimitsFell` rules, where 0 means "not set", which is unlimited for counts: |
| + - `RunningThings` and `SidecarsPerApp`: `next > 0 && (old == 0 || next < old)`; |
| + - `CustomDomains` and `Fleets`: `old && !next`; |
| + - `MinScheduleSeconds`: `next > old`. |
| + |
| + Every other field is ignored. |
| + |
| +- [ ] **Step 1: Write the failing tests** |
| + ```go |
| + func TestLimitsFell(t *testing.T) // table: running 25->3 true; 3->25 false; 0->3 true; 3->0 false; sidecars 5->1 true; domains true->false true; fleets true->false true; min schedule 60->900 true; 900->60 false; storage 25GB->1GB alone false; identical false |
| + func TestRecordRoundTripsDisabled(t *testing.T) // PutLimits/GetLimits keep Disabled; a record without it parses with nil |
| + ``` |
| +- [ ] **Step 2: Run** `go test ./internal/plans/ -run 'LimitsFell|RoundTripsDisabled'`. Expected: FAIL (undefined). |
| +- [ ] **Step 3: Implement.** |
| +- [ ] **Step 4: Run** again. Expected: PASS. |
| +- [ ] **Step 5: Commit** `plans: turned-off hosts in the limits record, and what counts as a fall (plans 4d)`. |
| + |
| +### Task 2: The plan row: lapse start and the turned-off host list |
| + |
| +**Files:** |
| +- Modify: `internal/console/store.go`: two additive ALTERs beside the throttle one at ~:426: |
| + - `account_plans ADD COLUMN lapse_since INTEGER NOT NULL DEFAULT 0`; |
| + - `account_plans ADD COLUMN disabled TEXT NOT NULL DEFAULT ''`. |
| +- Modify: `internal/console/accountplans.go`: |
| + - `AccountPlanRow.LapseSince time.Time` and `Disabled []string`; |
| + - `accountPlanColumns` and `scanAccountPlan`; |
| + - new store methods. `SetAccountPlan` leaves both columns alone. |
| +- Modify: `internal/console/planlimits.go:78` (`publishAccountLimits` sets `rec.Disabled = row.Disabled`). |
| +- Create: `internal/console/planlapse.go` (`applyAccountPlan`, `lapseStarted`, `lapseEligible`). |
| +- Modify: `internal/console/apiaccountplan.go:122`: the door calls `applyAccountPlan` instead of `SetAccountPlan` plus its own best-effort publish. |
| +- Test: `internal/console/accountplans_test.go`, `planlimits_test.go`, `planlapse_test.go`. |
| + |
| +**Interfaces:** |
| +- Produces: |
| + ```go |
| + func (s *Store) MarkLapse(accountID int64, now time.Time) error // lapse_since = now (each fall moves it) |
| + func (s *Store) ClearLapse(accountID int64) error |
| + func (s *Store) SetAccountDisabled(accountID int64, hosts []string, now time.Time) (changed bool, err error) // sorted, deduped JSON; "" for none; bumps revision only when the stored value differs; no row: (false, nil) |
| + func lapseEligible(row *AccountPlanRow) bool // row != nil, LapseSince set, not sponsored |
| + func (s *Server) lapseStarted(old *AccountPlanRow, plan string, packs map[string]int, sponsored *plans.Limits) bool |
| + func (s *Server) applyAccountPlan(ctx context.Context, acct *Account, plan string, packs map[string]int, source string, |
| + sponsored *plans.Limits, reason, by string, now time.Time) error |
| + ``` |
| +- `lapseStarted` is true when all of these hold: |
| + - a catalog is configured; |
| + - `sponsored == nil`; |
| + - the old assignment was paid: `old` nil means the default plan, and paid means `cat.Plans[old.Plan].Paid`, or any `old.Packs` quantity above 0; |
| + - `plans.LimitsFell(cat.Effective(old…), cat.Effective(new…))`. |
| + |
| + If the old assignment can't be priced (a plan the catalog no longer has), it is false. |
| +- `applyAccountPlan`: |
| + 1. reads the old row; |
| + 2. calls `SetAccountPlan`, returning its error, including `ErrAccountGone`; |
| + 3. calls `MarkLapse` when `lapseStarted`; |
| + 4. publishes best-effort (today's door behaviour). |
| + |
| + Task 5 adds the immediate re-converge. **It is the only production caller of `Store.SetAccountPlan`.** Plan 6 (Checkout) must call it too, and the census test below enforces that. |
| + |
| +- [ ] **Step 1: Write the failing tests** |
| + ```go |
| + func TestSetAccountDisabledBumpsRevisionOnChange(t *testing.T) // set [b,a]: changed, stored "a","b", revision+1; same set again: unchanged; nil: changed, "" stored |
| + func TestPublishCarriesDisabled(t *testing.T) // after SetAccountDisabled, planLimitsPass writes Record.Disabled |
| + func TestApplyAccountPlanMarksALapse(t *testing.T) // personal -> free: lapse_since = planNow; free -> personal: unchanged |
| + func TestApplyAccountPlanPackReductionIsALapse(t *testing.T) // personal + 2 app packs -> personal + 0: marked |
| + func TestApplyAccountPlanNeverPaidIsNoLapse(t *testing.T) // free -> free with a lower sponsored figure, and free (no packs) -> another free plan: not marked |
| + func TestApplyAccountPlanSponsoredIsNoLapse(t *testing.T) // personal -> free with sponsored limits: not marked |
| + func TestLapseEligible(t *testing.T) // nil row, unset lapse, sponsored source, sponsored limits: false; marked operator row: true |
| + func TestOnlyApplyAccountPlanSetsAccountPlans(t *testing.T) // source census: in non-test .go files of internal/console, ".SetAccountPlan(" appears only in planlapse.go |
| + func TestAccountPlanDoorUnchangedWithoutACatalog(t *testing.T) // existing 409 path still answers; nothing written |
| + ``` |
| +- [ ] **Step 2: Run** `go test ./internal/console/ -run 'SetAccountDisabled|PublishCarriesDisabled|ApplyAccountPlan|LapseEligible|OnlyApplyAccountPlan|AccountPlanDoor|AccountPlan'`. Expected: FAIL. |
| +- [ ] **Step 3: Implement.** |
| +- [ ] **Step 4: Run** again, plus `go test ./internal/console/ -run 'PlanLimits|Throttle'`. Expected: PASS. |
| +- [ ] **Step 5: Commit** `console: a paid account's falling limits start a lapse (plans 4d)`. |
| + |
| +### Task 3: Lapse items: keep choices and what is off since when |
| + |
| +**Files:** |
| +- Create: `internal/console/planlapse_store.go`: the migration `migratePlanLapse()`, chained after `migratePlanGrace()` at the end of the migrate list (`store.go:~554`), plus the methods below. |
| +- Modify: `internal/console/store_gate.go:183`: `"plan_lapse_items": {Account: "account_id", App: "app"}`. |
| +- Modify: `internal/console/store.go` (add `LiveAppsCreated` beside `AppsIn`, ~:1626). |
| +- Test: `internal/console/planlapse_store_test.go`. |
| + |
| +**Interfaces:** |
| +- Produces: |
| + ```go |
| + // table plan_lapse_items(account_id INTEGER NOT NULL, app TEXT NOT NULL, kind TEXT NOT NULL, |
| + // ref TEXT NOT NULL, thing_created INTEGER NOT NULL, keep INTEGER NOT NULL DEFAULT 0, |
| + // disabled_at INTEGER NOT NULL DEFAULT 0, updated_at INTEGER NOT NULL, |
| + // PRIMARY KEY (account_id, kind, ref)) |
| + type lapseItem struct { |
| + AccountID int64 |
| + App string // the owning app (a domain's claim app) |
| + Kind string // lapseApp | lapseInstance | lapseSidecar | lapseDomain (Task 4) |
| + Ref string // the app name, or the host |
| + ThingCreated time.Time // the thing's own creation time: a recreated thing is a new thing |
| + Keep bool |
| + DisabledAt time.Time // zero = on |
| + UpdatedAt time.Time |
| + } |
| + func (s *Store) LapseItems(accountID int64) ([]lapseItem, error) |
| + func (s *Store) PutLapseItem(ctx context.Context, it lapseItem) error // upsert on (account_id, kind, ref) via withAutoAppSQL(ctx, it.AccountID, it.App, "sql.PutLapseItem", …) |
| + func (s *Store) DeleteLapseItem(ctx context.Context, accountID int64, app, kind, ref string) error // "sql.DeleteLapseItem" |
| + func (s *Store) LiveAppsCreated(accountID int64) (map[string]time.Time, error) // apps with deleted_at = 0 OR restoring = 1 (runningThings' live set), by created_at |
| + ``` |
| + Each write method is a public wrapper around a `claimRaw…` body, exactly as `DoorKeyInsert` is (`doorkeys_store.go:249`). |
| + |
| +- [ ] **Step 1: Write the failing tests** |
| + ```go |
| + func TestLapseItemRoundTrip(t *testing.T) // put, list, update keep and disabled_at, delete; times at second precision |
| + func TestLiveAppsCreated(t *testing.T) // live and restoring apps present with created_at; trashed absent |
| + func TestPutLapseItemGoesThroughTheAppGate(t *testing.T) // with the gate armed (the plan9_fix1_sql_test.go fixture), a raw write without admission is refused; PutLapseItem is admitted |
| + func TestClaimSQLCensusAcceptsPlanLapseItems(t *testing.T) // the census runs clean with the new table classified |
| + ``` |
| +- [ ] **Step 2: Run** `go test ./internal/console/ -run 'LapseItem|LiveAppsCreated|ClaimSQLCensus|StoreGate'`. Expected: FAIL. |
| +- [ ] **Step 3: Implement.** |
| +- [ ] **Step 4: Run** again. Expected: PASS. |
| +- [ ] **Step 5: Commit** `console: plan lapse items for keep choices and what is turned off (plans 4d)`. |
| + |
| +### Task 4: Leftover caps, the inventory and who goes first |
| + |
| +**Files:** |
| +- Modify: `internal/console/plangrace.go`: |
| + - `capSidecars` and `capCustomDomains`, appended to `capOrder`; |
| + - `leftoverCap`; |
| + - `levelOf` handles leftover caps. |
| +- Create: `internal/console/planlapse_inventory.go`. |
| +- Test: `internal/console/plangrace_test.go`, `internal/console/planlapse_inventory_test.go`. |
| + |
| +**Interfaces:** |
| +- Consumes: `LiveAppsCreated`, `LapseItems` (Task 3); `provision.ListRecordsStrict`, `provision.ListSidecarRecordsStrict`; `s.claims.List(ctx, s.cfg.Releases)`; `s.customDomain(host, sqid)` (`plancaps.go:220`). |
| +- Produces: |
| + ```go |
| + const ( |
| + capSidecars capID = "sidecars" // workers beyond the per-app cap, summed; lapse only |
| + capCustomDomains capID = "custom_domains" // custom domains on a plan without them; lapse only |
| + ) |
| + func leftoverCap(c capID) bool // levels ok (used 0) or over (used > 0) only; grace 7 days; period "" |
| + |
| + const (lapseApp = "app"; lapseInstance = "instance"; lapseSidecar = "sidecar"; lapseDomain = "domain") |
| + type lapseThing struct { |
| + Kind, App, Ref string |
| + CreatedAt time.Time |
| + Catchall bool // a domain claimed with its catch-all alias |
| + Keep bool |
| + } |
| + type lapseInventory struct{ Things, Sidecars, Domains []lapseThing } // Things: apps and instances |
| + func (s *Server) lapseInventory(ctx context.Context, acct *Account) (*lapseInventory, error) |
| + func measureLeftovers(inv *lapseInventory, l *plans.Limits) map[capID]capMeasure |
| + func chooseOff(things []lapseThing, limit int) []lapseThing |
| + func sidecarsOff(sidecars []lapseThing, perApp int) []lapseThing |
| + func lapseHosts(off []lapseThing, inv *lapseInventory) []string |
| + ``` |
| +- `lapseInventory`, with any error failing the whole call (unknown is not over): |
| + - one `lapseApp` thing per live app; |
| + - one `lapseInstance` per instance record (`ListRecordsStrict` with max `lapseRecordsMax = 1000`; an unreadable host is an error); |
| + - one `lapseSidecar` per sidecar record; |
| + - one `lapseDomain` per claim whose `Account` is the account and whose host `customDomain` reports custom. |
| + |
| + `Keep` comes from `LapseItems` rows matching kind, ref and `ThingCreated`. |
| +- `measureLeftovers`: |
| + - `sidecars` when `SidecarsPerApp > 0`: Used = Σ over apps of max(0, n − cap), and Limit = the cap; |
| + - `custom_domains` when `!CustomDomains`: Used = the number of domains, and Limit 0; |
| + - a cap the plan does not limit is absent. |
| +- `chooseOff`: limit ≤ 0 or `len(things) <= limit` gives nil. Otherwise: |
| + 1. Walk the candidates in order: kept things oldest first, then unkept oldest first. Ties go by kind (app first), then ref. |
| + 2. A candidate costs 1, plus 1 if it is an instance whose app is not yet staying. Keeping an instance keeps its app. |
| + 3. It stays when the staying count plus its cost fits the limit. |
| + 4. Everything not staying is off, and an off app takes its instances with it. |
| +- `sidecarsOff` applies the same rule per app with `perApp`. |
| +- `lapseHosts` gives: |
| + - instance and sidecar refs; |
| + - for an off app, every instance and sidecar host of that app; |
| + - for a domain, its host, plus `"*."+host` when `Catchall`. |
| + |
| + The result is lower case, sorted and deduped. |
| + |
| +- [ ] **Step 1: Write the failing tests** |
| + ```go |
| + func TestLeftoverLevels(t *testing.T) // sidecars used 0 ok, 1 over, never warn or ceiling; custom_domains limit 0 used 2 over; grace planNow+7d |
| + func TestChooseOffNewestFirst(t *testing.T) // cap 3: app a(t1) a1(t2) app b(t3) b1(t4) a2(t5) -> off b1, a2 |
| + func TestChooseOffKeepWins(t *testing.T) // same, keep b1 -> stays b, b1, a; off a1, a2 |
| + func TestChooseOffKeepImpliesTheApp(t *testing.T) // cap 2, keep a2 only -> stays a, a2 |
| + func TestChooseOffUnderTheCapIsNothing(t *testing.T) |
| + func TestSidecarsOffPerApp(t *testing.T) // app with 3 workers, cap 1 -> two newest off; keep the newest -> two oldest off |
| + func TestLapseHostsExpandsAppsAndCatchalls(t *testing.T) |
| + func TestLapseInventoryReadsTheAccount(t *testing.T) // two apps with instance records, a worker, a custom domain, a platform hostname, a trashed app: only live things, the platform hostname not a domain |
| + func TestLapseInventoryUnreadableRecordIsAnError(t *testing.T) |
| + func TestMeasureLeftovers(t *testing.T) |
| + ``` |
| +- [ ] **Step 2: Run** `go test ./internal/console/ -run 'LeftoverLevels|ChooseOff|SidecarsOff|LapseHosts|LapseInventory|MeasureLeftovers|CapLevels|EvaluateCap'`. Expected: FAIL. |
| +- [ ] **Step 3: Implement.** |
| +- [ ] **Step 4: Run** again. Expected: PASS. |
| +- [ ] **Step 5: Commit** `console: lapse inventory, leftover caps and newest-first selection (plans 4d)`. |
| + |
| +### Task 5: Turning things off and back on |
| + |
| +**Files:** |
| +- Modify: `internal/console/planlapse.go` (`convergeLapse`, `clearLapseOff`; `applyAccountPlan` re-converges). |
| +- Modify: `internal/console/plangracepass.go`, in `planGraceAccount`: |
| + - read the plan row once; |
| + - for an eligible account, build the inventory and merge `measureLeftovers` into the measures. An inventory error goes in `errs` for both leftover caps, so their rows are kept; |
| + - after the cap loop, call `convergeLapse`, or `clearLapseOff` when not eligible. |
| +- Test: `internal/console/planlapse_test.go`. |
| + |
| +**Interfaces:** |
| +- Consumes: Tasks 2 to 4; `afterGraceDue`; `s.audit`. |
| +- Produces: |
| + ```go |
| + func (s *Server) convergeLapse(ctx context.Context, acct *Account, row *AccountPlanRow, l *plans.Limits, |
| + states map[capID]capState, inv *lapseInventory, now time.Time) error |
| + func (s *Server) clearLapseOff(ctx context.Context, acct *Account, now time.Time) error // everything back on; no inventory needed |
| + ``` |
| +- `convergeLapse` decides each kind separately: |
| + - **running things:** `selected = chooseOff(inv.Things, l.RunningThings)`, due = `afterGraceDue(states[capRunningThings])`; |
| + - **sidecars:** `sidecarsOff(inv.Sidecars, l.SidecarsPerApp)`, due on `capSidecars`; |
| + - **domains:** all of `inv.Domains` when `!l.CustomDomains`, due on `capCustomDomains`. |
| + |
| + For each kind, `next = selected` when due, otherwise `selected ∩ currently off`. Then: |
| + - items newly off get `PutLapseItem` with `DisabledAt = now`; items already off keep their `DisabledAt`; |
| + - items back on get `DisabledAt` zeroed, and are deleted if not kept; |
| + - item rows for things not in the inventory are deleted; |
| + - `SetAccountDisabled(lapseHosts(allOff, inv))`; |
| + - `plan.turned_off` and `plan.turned_on` are audited once per item, on its app, with the reason; |
| + - `ClearLapse` runs when nothing is off and none of the three lapse caps is over. |
| +- `clearLapseOff` turns every item back on and clears `disabled`. The pass calls it for a non-eligible account that has any item off, which covers sponsorship, a removed catalog row or lapse cleared. |
| +- `applyAccountPlan` (Task 2) gains, after `SetAccountPlan`: |
| + - on a fall, `DeleteCapState` for `running_things`, `sidecars` and `custom_domains` (each fall gets its own grace); |
| + - then `s.planGraceAccount(ctx, acct, now)`, with errors logged; |
| + - then the publish. |
| + |
| + Both happen on every call, so a raise turns things back on at once. |
| + |
| +- [ ] **Step 1: Write the failing tests** (fixture: `newConsoleFixture`, `examplePlanCatalog`, personal → free through `applyAccountPlan`, instance records written with `CreatedAt`, `planNow`) |
| + ```go |
| + func TestLapseGraceTurnsNothingOff(t *testing.T) // 5 things, free cap 3, in grace: disabled empty, no items off |
| + func TestLapseAfterGraceTurnsTheNewestOff(t *testing.T) // grace ended, notice 72h old: the two newest off; Record.Disabled = their hosts; audit plan.turned_off |
| + func TestLapseWaitsForNotice(t *testing.T) // grace ended, notice 71h old: nothing off |
| + func TestApplyAccountPlanTurnsThingsBackOnAtOnce(t *testing.T) // after the above, free -> personal: disabled empty and the record republished in the same call |
| + func TestFurtherFallWaitsForItsOwnGrace(t *testing.T) // two off; pack reduced again: the same two stay off, nothing new until the new grace ends |
| + func TestDeletingAThingBringsAnotherBack(t *testing.T) // owner deletes one live instance; next pass: one off thing back on |
| + func TestLapseUnchangedWhenInventoryUnreadable(t *testing.T) // things off; a record made unreadable: same set, rows kept |
| + func TestNoLapseWithoutAFall(t *testing.T) // free account never paid, over the cap, grace + notice: nothing off |
| + func TestSponsoredAccountsNeverTurnedOff(t *testing.T) // things off, then the operator makes it sponsored: all back on next pass |
| + func TestCustomDomainsTurnedOffAfterGrace(t *testing.T) // personal -> free with a custom alias and a catch-all: both hosts in disabled after grace; platform host absent |
| + func TestLapseClearsWhenNothingIsLeft(t *testing.T) // lapsed account within its limits: lapse_since cleared |
| + func TestLapseWithoutACatalogUnchanged(t *testing.T) |
| + ``` |
| +- [ ] **Step 2: Run** `go test ./internal/console/ -run 'Lapse|ApplyAccountPlan|FurtherFall|DeletingAThing|NoLapseWithout|SponsoredAccountsNever|CustomDomainsTurnedOff'`. Expected: FAIL. |
| +- [ ] **Step 3: Implement.** |
| +- [ ] **Step 4: Run** again, plus `go test ./internal/console/ -run 'GracePass|Throttle|StorageDeny'`. Expected: PASS. |
| +- [ ] **Step 5: Commit** `console: turn off what a lapsed account no longer pays for, and back on when it does (plans 4d)`. |
| + |
| +### Task 6: Banner, CLI line and email say what is off |
| + |
| +**Files:** |
| +- Modify: `internal/console/plangracepass.go`: |
| + - `planStage` names `lapse_grace` and `lapse_off`; |
| + - `planNoticeText` formats `lapse_grace` with the date; |
| + - `noticeDue` takes the stage; |
| + - `notifyPlanOwners` and `planNoticeEmail` pass the stage. |
| +- Modify: `internal/console/plancaps_copy.go` (keys below). |
| +- Test: `internal/console/plangrace_view_test.go`, `plangrace_cli_test.go`, `plangracepass_test.go`. |
| + |
| +**Interfaces:** |
| +- Produces: |
| + - `planStage` for an eligible account, on `running_things`, `sidecars` or `custom_domains`: |
| + - `"lapse_off"` when an item of the matching kind is off (`app`/`instance`, `sidecar`, `domain`); |
| + - else `"lapse_grace"` when the row is over. |
| + |
| + It reads `AccountPlan` and `LapseItems` once per call. The existing stages are unchanged. |
| + - `planNoticeText(n, surface)`: |
| + - for `lapse_grace`: `Sprintf(copy[surface+".lapse_grace"], use, graceEndDate)`; |
| + - for `lapse_off`: `Sprintf(copy[surface+".lapse_off"], use)`. |
| + - `func noticeDue(st capState, now time.Time, stage string, lastOff time.Time) bool`. For `lapse_off` it is due when `RemindedAt` is zero, or before `lastOff` (the newest `DisabledAt` of that kind), or at least 7 days old. Every other case is unchanged. |
| + - `planNoticeEmail` appends `email.lapse_off_list` naming the off things (app names and hosts), plus the keep page URL. |
| +- Draft copy, final after the Luna pass: |
| + - `usage.sidecars`: "%d workers over the %d per app this plan allows" |
| + - `usage.custom_domains`: "%d custom domains, which this plan does not include" |
| + - `banner.lapse_grace`: "This account's plan no longer covers %s. On %s the newest are turned off. Their settings and data are kept, and they come back when the plan covers them again. You can choose which stay." |
| + - `cli.lapse_grace`: "this account's plan no longer covers %s. on %s the newest are turned off. settings and data are kept. choose which stay in the console" |
| + - `email.lapse_grace`: "- %s. On %s the newest are turned off unless the plan covers them again." |
| + - `banner.lapse_off`: "Turned off because this account's plan no longer covers them: %s. Their settings and data are kept, and they come back when the plan covers them again." |
| + - `cli.lapse_off`: "turned off because this account's plan no longer covers them: %s. settings and data are kept" |
| + - `email.lapse_off`: "- Turned off: %s." |
| + - `email.lapse_off_list`: "Turned off: %s.\n\nChoose which stay:\n%s" |
| + |
| +- [ ] **Step 1: Write the failing tests** |
| + ```go |
| + func TestBannerSaysLapseGrace(t *testing.T) // eligible, over in grace: banner has the lapse_grace text with the date |
| + func TestBannerSaysLapseOff(t *testing.T) // after turning off: lapse_off text |
| + func TestNonEligibleBannerUnchanged(t *testing.T) // never paid, over: Plan 4a's banner.over text |
| + func TestCLIWarningSaysLapseOff(t *testing.T) |
| + func TestLapseOffRemindsWeekly(t *testing.T) // email on turning off; +1 day: none; +7 days: one; another thing off: one at once |
| + func TestLapseEmailNamesWhatIsOff(t *testing.T) |
| + ``` |
| +- [ ] **Step 2: Run** `go test ./internal/console/ -run 'BannerSaysLapse|NonEligibleBanner|CLIWarningSaysLapse|LapseOffReminds|LapseEmail'`. Expected: FAIL. |
| +- [ ] **Step 3: Implement.** |
| +- [ ] **Step 4: Run** again, plus `go test ./internal/console/ -run 'Banner|CLIWarning|GracePass'`. Expected: PASS. |
| +- [ ] **Step 5: Commit** `console: banner, CLI and email say what a lapse turned off (plans 4d)`. |
| + |
| +### Task 7: The box keeps the list; the edge answers with the page |
| + |
| +**Files:** |
| +- Modify: `internal/host/plans_pass.go`: |
| + - the snapshot gains `disabled map[string]map[string]bool`, filled from `rec.Disabled` and kept with the last good copy on a read error, as `throttle` is; |
| + - add `planDisabledFor`. |
| +- Create: `internal/edge/plandisabled.go` (hook, page, admit). |
| +- Modify: `internal/edge/edge.go`: |
| + - field `planDisabled atomic.Pointer[func(registry.Route, string) bool]` beside `planThrottle` (:330); |
| + - call `planDisabledAdmit` right after `importGateAdmit` (~:1701). |
| +- Modify: `internal/host/agent.go:951` (`e.SetPlanDisabledFor(planDisabledFor)`). |
| +- Test: `internal/host/plans_disabled_test.go`, `internal/edge/plandisabled_test.go`. |
| + |
| +**Interfaces:** |
| +- Produces: |
| + ```go |
| + // host |
| + func planDisabledFor(rt registry.Route, host string) bool // plans on, the route's account has a record, and rt.Host or host (lower case) is listed, exactly or by "*."+parent(host) |
| + // edge |
| + func (e *Edge) SetPlanDisabledFor(f func(rt registry.Route, host string) bool) |
| + func (e *Edge) planDisabledAdmit(w http.ResponseWriter, r *http.Request, host string, rt registry.Route) bool // false = answered with the page |
| + const disabledTitle, disabledHeading, disabledBody = "Not available", "This site is not available right now", "If it is yours, sign in to your console to see why." // drafts until Luna |
| + ``` |
| +- The page: |
| + - is rendered once at start like `renderPendingPage` (`pending.go:137`); |
| + - is a 503 with `Content-Type: text/html; charset=utf-8`, `Cache-Control: no-store`, a `noindex` meta and no `Retry-After`; |
| + - has no body for HEAD; |
| + - echoes nothing from the request. |
| +- Every route kind except `status` is checked, and door callers too. A turned-off app serves no one. |
| +- Requests backhauled to the home box are judged there. |
| +- Each refusal is logged through `e.logThrottled`, keyed `"plan-disabled "+host`. |
| + |
| +- [ ] **Step 1: Write the failing tests** |
| + ```go |
| + // host (serial: planLimits is a package var) |
| + func TestPlansPassKeepsDisabled(t *testing.T) // record lists x.example.com: planDisabledFor(route x) true; another account's route false |
| + func TestPlanDisabledForMatchesAliasAndCatchall(t *testing.T) // route primary, request host shop.example.com listed: true; "*.example.com" listed, request a.example.com: true; b.a.example.com: false |
| + func TestDisabledKeptOnReadError(t *testing.T) |
| + func TestDisabledOffWithPlanLimitsOff(t *testing.T) |
| + // edge (t.Parallel) |
| + func TestDisabledHostGetsThePage(t *testing.T) // 503, no-store, body has disabledHeading, upstream and activator never called |
| + func TestDisabledAliasOnly(t *testing.T) // alias shop.example.com listed: page; the route's own platform host: proxied |
| + func TestDisabledPageEchoesNothing(t *testing.T) // a request with a hostile path and header: body byte-identical to the rendered page |
| + func TestNoDisabledHookUnchanged(t *testing.T) |
| + ``` |
| +- [ ] **Step 2: Run** `go test ./internal/host/ -run 'PlansPassKeepsDisabled|PlanDisabledFor|DisabledKept|DisabledOff'` and `go test ./internal/edge/ -run 'Disabled'`. Expected: FAIL. |
| +- [ ] **Step 3: Implement.** |
| +- [ ] **Step 4: Run** again, plus `go test ./internal/host/ -run 'PlansPass|Throttle'` and `go test ./internal/edge/ -run 'ImportGate|Throttle|Gate|Pending'`. Expected: PASS. |
| +- [ ] **Step 5: Commit** `host, edge: a turned-off host gets a plain page (plans 4d)`. |
| + |
| +### Task 8: The activator never wakes a turned-off route |
| + |
| +**Files:** |
| +- Modify: `internal/activator/activator.go`: |
| + - field `disabledFor` beside `maxRunFor` (~:1149), and `SetDisabledFor` beside `SetMaxRunFor` (~:5512); |
| + - `wake` (~:1775): cancel like a fence when the hook says disabled and `e.probe == nil`; |
| + - due loop (~:4989): skip; |
| + - always-on loop (~:5047): skip; |
| + - `sweepOnce` beside the max-run branch (~:4734): stop a live entry with `beginStopLocked(e, StopIdle)` when disabled and `e.cmd == nil`; |
| + - `ServeScheduled` (~:5365): `maintenanceResponse` when disabled. |
| +- Modify: `internal/host/agent.go:503` (`svc.SetDisabledFor(func(rt registry.Route) bool { return planDisabledFor(rt, rt.Host) })`). |
| +- Test: `internal/activator/activator_disabledfor_test.go`. |
| + |
| +**Interfaces:** |
| +- Produces: `func (a *Service) SetDisabledFor(f func(registry.Route) bool)`. nil, or a false answer, changes nothing. |
| + |
| +- [ ] **Step 1: Write the failing tests** (`testActivator`, `fakeClock`, as in `activator_maxrunfor_test.go`; `t.Parallel()`) |
| + ```go |
| + func TestDisabledForRefusesAWake(t *testing.T) // a request to a disabled hibernating route: no spawn |
| + func TestDisabledForSkipsDueAndAlwaysOn(t *testing.T) // a due worker and an always-on worker, both disabled: neither started across sweeps |
| + func TestServeScheduledRefusesDisabled(t *testing.T) // maintenance response, no spawn |
| + func TestDisabledForStopsALiveEntry(t *testing.T) // awake instance becomes disabled: stopped at the next sweep (StopIdle); a mid-command entry waits for its command |
| + func TestDisabledForLeavesProbeWakes(t *testing.T) // ProbeWake on a disabled route still wakes (moves keep working) |
| + func TestDisabledForNilUnchanged(t *testing.T) |
| + ``` |
| +- [ ] **Step 2: Run** `go test ./internal/activator/ -run 'DisabledFor|ServeScheduledRefusesDisabled'`. Expected: FAIL. |
| +- [ ] **Step 3: Implement.** |
| +- [ ] **Step 4: Run** again, plus `go test ./internal/activator/ -run 'MaxRunFor|IdleFor|Sweep|Due|AlwaysOn|ProbeWake'`. Expected: PASS. |
| +- [ ] **Step 5: Commit** `activator: never wake or keep running a turned-off route (plans 4d)`. |
| + |
| +### Task 9: Owners choose what stays |
| + |
| +**Files:** |
| +- Create: `internal/console/planlapse_keep.go` (`handlePlanKeep`, `handlePlanKeepSave`). |
| +- Create: `internal/console/templates/plan_keep.html`. |
| +- Modify: `internal/console/server.go`: |
| + - register `GET /a/{sqid}/plan/keep` and `POST /a/{sqid}/plan/keep` beside `/a/{sqid}/settings` (:1516); |
| + - the `page` struct gains `PlanKeepURL string`, set in `accountPage` (~:3369) when the account is eligible and `running_things` or `sidecars` is over. |
| +- Modify: `internal/console/templates/layout.html:594` (a link after the banner when `PlanKeepURL` is set). |
| +- Modify: `internal/console/plancaps_copy.go` (`planKeepCopy`). |
| +- Modify: `internal/console/testdata/claim-routes.txt` (two `route` lines). Add a claim fixture beside `/a/{sqid}/settings`'s if `TestClaimInvariant*` names the routes. |
| +- Test: `internal/console/planlapse_keep_test.go`. |
| + |
| +**Interfaces:** |
| +- Consumes: `lapseInventory`, `chooseOff`, `sidecarsOff`, `PutLapseItem`, `DeleteLapseItem`, `planGraceAccount`, `publishAccountLimits`. |
| +- Produces: |
| + - **GET** (owners only; anyone else gets the not-found answer owner-only pages give, as `ownerFleet` does) lists every app, instance and worker with: |
| + - its creation date; |
| + - whether it is on or off; |
| + - a checkbox, ticked for kept things. |
| + |
| + It shows the plan's numbers. With plans off it answers 404. A non-eligible account sees `keep.nothing`. |
| + - **POST** takes repeated `keep` values `app:<name>`, `instance:<host>` and `sidecar:<host>`. It refuses with `keep.too_many` and changes nothing when: |
| + - a value names nothing in the inventory; |
| + - the kept running things, counting implied apps, exceed `RunningThings`; |
| + - any app's kept workers exceed `SidecarsPerApp`. |
| + |
| + Otherwise it writes `Keep` on every listed item and clears it on the rest. It then runs `planGraceAccount` and publishes, so a swap takes effect at once, and redirects with `keep.saved`. The form uses the console's standard POST and CSRF handling, as `POST /a/{sqid}/analytics/setting` does. |
| +- Draft `planKeepCopy`, final after Luna: |
| + - `keep.title`: "Choose what stays" |
| + - `keep.intro`: "This account's plan covers %d apps and instances and %d workers per app. Tick the ones to keep. The rest are turned off, newest first. Settings and data are kept either way." |
| + - `keep.save`: "Save" |
| + - `keep.too_many`: "You ticked %d, and the plan covers %d. Untick some and save again." |
| + - `keep.saved`: "Saved. The change reaches your apps within a few minutes." |
| + - `keep.nothing`: "Nothing to choose: this account's plan covers everything it runs." |
| + - `keep.link`: "Choose what stays" |
| + |
| +- [ ] **Step 1: Write the failing tests** |
| + ```go |
| + func TestKeepPageListsRunningThings(t *testing.T) |
| + func TestKeepPageOwnersOnly(t *testing.T) // member and outsider: not found |
| + func TestKeepSaveRefusesMoreThanTheCap(t *testing.T) // free cap 3, four ticked: refused, nothing written |
| + func TestKeepSaveImpliesTheApp(t *testing.T) // ticking an instance of an unticked app counts the app |
| + func TestKeepSaveSwapsWhatIsOffAtOnce(t *testing.T) // after turning off: keep an off instance -> it is on and the newest unkept is off; account_plans.disabled changed in the same request |
| + func TestKeepPageWithoutACatalog(t *testing.T) // 404 |
| + func TestBannerLinksToKeepPage(t *testing.T) |
| + func TestClaimConsoleRouteCensus(t *testing.T) // existing test, passing with the two new lines |
| + ``` |
| +- [ ] **Step 2: Run** `go test ./internal/console/ -run 'KeepPage|KeepSave|BannerLinksToKeep|ClaimConsoleRouteCensus'`. Expected: FAIL. |
| +- [ ] **Step 3: Implement.** |
| +- [ ] **Step 4: Run** again. Expected: PASS. |
| +- [ ] **Step 5: Commit** `console: owners choose which running things stay (plans 4d)`. |
| + |
| +### Task 10: Docs, Luna, census and gates |
| + |
| +- [ ] **Luna copy pass** on every new string: `planNoticeCopy` additions, `planKeepCopy` and the edge page. Commit a brief with the house rules and example renderings. Apply Luna's changes, and show Paul only what it flags. |
| +- [ ] **Docs:** add a "When a plan lapses" section to `docs/site/plans.md`, covering: |
| + - who it applies to (paid accounts whose limits fall; never sponsored ones); |
| + - 7 days' grace with notice, then turned off; |
| + - what turned off looks like to visitors; |
| + - that data stays. Check whether `carlos db pull` wakes the instance, which a turned-off route refuses, and document what actually works; |
| + - the keep page; |
| + - that paying again turns everything back on within minutes; |
| + - that `CARLOS_PLAN_LIMITS=off` on a box turns it off there. |
| +- [ ] **Census:** |
| + - run `make census-card`; |
| + - write CLAIMS for `body`/`sites`/`envelope` rows; |
| + - write hand decision rows for new units (`planDisabledFor`, the activator's disabled branches, `planDisabledAdmit`); |
| + - run `make census-propose NAME=plans-4d-lapse CLAIMS=<file>`; |
| + - check `TestPlan9B8RecordWriteCensus` (no new record writer is intended); |
| + - Astra approves the card and records the verdict on #280. Decisions and escalations go to Paul. |
| +- [ ] **Gates:** merge main, push, wait for green CI, then Astra's whole-branch review. |
| + |
| +## Done when |
| + |
| +Every task's tests pass and Review Focus 1–5 are pinned. The census card is approved, CI is green after merging current main, and Astra's whole-branch review has no open Critical or Important finding. |
| + |
| +## Calls for Paul |
| + |
| +Each is a proposal; the plan is written to the recommendation. |
| + |
| +1. **What a turned-off app shows, and to whom.** Recommended: |
| + - visitors get a neutral 503 page: "This site is not available right now. If it is yours, sign in to your console to see why"; |
| + - no mention of plans or payment, so an owner's billing is not published; |
| + - `noindex`, no `Retry-After`; |
| + - the details are for the account only, in the console banner, the keep page, the CLI line and email. |
| +2. **Who chooses what stays, and when.** Recommended: |
| + - owners only, on a console page; |
| + - available from the moment grace starts, and changeable after things are off. A change swaps what is on at once; |
| + - workers can be chosen per app on the same page; |
| + - a CLI command is left for later, if asked for. |
| +3. **What starts a lapse.** Recommended: a plan change through `applyAccountPlan` where the old assignment was paid (a paid plan or any pack) and a governed limit fell. Three consequences: |
| + - an account that never paid is never turned off or deleted, even when over (it gets Plan 4a's warnings and creation refusals); |
| + - a catalog edit that shrinks a plan does not start lapses: the operator decides per account; |
| + - an account that loses its sponsorship is not on this path either, because it never paid. |
| +4. **Turned-off things still count toward the cap.** Recommended yes. Creation stays refused until the account deletes something or the plan grows, which is what makes "if still over, deleted" (§5.1) meaningful. |
| +5. **Reminder cadence once things are off.** Recommended: |
| + - one email when something is turned off, then weekly instead of Plan 4a's daily; |
| + - 4d-2 replaces the weekly email with the 30, 7 and 1 days before deletion. |
| +6. **Custom domains while turned off.** Recommended: |
| + - the domain stays attached, so nobody else can claim it, and its certificate keeps renewing; |
| + - visitors get the same page; |
| + - the platform address of the same instance keeps serving if the instance itself is within the cap; |
| + - it is detached at deletion (4d-2). |
| +7. **Each further fall gets its own 7 days.** Recommended yes. What was already off stays off, and nothing new goes off until the new grace and notice have run. |
| +8. **Re-enable latency.** Paying again re-converges and republishes in the same request. Boxes see it on their next plans pass, within about five minutes. Recommended as "at once" for v1, with no push to boxes. |
| + |
| +## Plan 4d-2 outline: deletion through the Trash |
| + |
| +- **Clock:** a thing off for 90 days (`plan_lapse_items.disabled_at` + 90 days) is deleted. If it was turned back on and off again, the clock restarts. |
| +- **Reminders:** at 30, 7 and 1 days before deletion, sent to owners. The banner and keep page show each thing's deletion date. These replace 4d-1's weekly reminder. A `reminded` stage column on `plan_lapse_items` makes each one go out once. |
| +- **Notice:** deletion waits until the 7-day reminder was accepted for delivery, or an owner saw the banner within the last 30 days. Otherwise it waits and keeps reminding. That is the spirit of §6's notice rule applied to the one irreversible step. |
| +- **Apps wholly off:** `release.TrashApp` with actor `"plan"`, using the expiry pass's sequence (`expirypass.go:140`: lock, settle, TrashApp, re-read, row update, audit, bump). `TrashCooloff` gives 30 more days to restore. Restoring needs room under the cap (`checkRestore`). |
| +- **Production-flagged apps** refuse the Trash. They stay off, and the operator is told. |
| +- **Instances of kept apps:** there is no instance Trash today. Call for Paul, recommended: retire the record (`retireInstanceRecord`). The database and blobs stay parked in the bucket as with any instance delete, so an operator can still recover within the same 30 days. Purge of parked data stays as it is today. |
| +- **Workers:** `retireHostRecord`. |
| +- **Custom domains:** `detachDomain`, which releases the claim. |
| +- **Claims mode:** the claim-retire and claim-trash paths, the same as the member doors. |
| +- **Bookkeeping:** item rows are deleted once the thing is gone, and `lapse_since` clears in the existing pass. |
| + |
| +## Plan 4d-3 outline: leftovers that are not turned off |
| + |
| +- **Schedules faster than the minimum:** |
| + - after grace they run at the plan's minimum; the declaration is untouched (§9.2); |
| + - the record gains a `ScheduleFloor` flag, set by the pass under the same eligibility and `afterGraceDue`; |
| + - on the box, `schedule.Spec.Next` (`spec.go:119`) clamps `every`; |
| + - cron needs the last firing time, which `Runner.record` (`runner.go:600`) has, so the clamp goes there; |
| + - the leftover cap `schedules` counts the declarations below the minimum. |
| +- **Always-on on a fleet the app has left:** |
| + - moving an always-on app (a daemon release or `hibernate:false` workers) from its fleet to shared boxes is refused under a plan, as a creation-style refusal with no grace; |
| + - leftovers that predate the refusal, or that a fleet's deletion strands, get grace and then hibernate with the plan's idle window, through a record flag that `planIdleFor` honours for always-on routes. |
| +- **Fleets** (Call for Paul). Recommended: |
| + - while turned off, a fleet takes no new placements or box attaches (`placeAppTarget`, box attach); |
| + - apps already on it keep serving while within the running-things cap; |
| + - at deletion every box is detached (`SetFleetBoxStatus`), and fleet-placed apps go back to shared placement, subject to the always-on rule above. The registry has no fleet delete, so 4d-3 adds one. |