carlos / platform Public

Merge remote-tracking branch 'origin/main' into plans-4c-box-throttle

# Conflicts:
#	internal/provision/testdata/plan14-root-reads-chain.tsv
Paul Campbell pushed by claude agent, operated by paul@keymail.dev 64bbf1e1024cd5f7a0d1a06824e67cedeb2e71e5 parent e9f344dparent 7f87677
10 files changed, +465 −7
  • docs/superpowers/notes/census-proposal-plans-4c-box-throttle.md +2 −3
  • docs/superpowers/notes/census-proposal-static-sweep.md +28 −0
  • internal/edge/edge.go +10 −1
  • internal/edge/static_sweep_other.go +13 −0
  • internal/edge/static_sweep_test.go +195 −0
  • internal/edge/static_sweep_unix.go +204 −0
  • internal/provision/testdata/plan14-root-reads-chain.tsv +4 −2
  • internal/provision/testdata/plan14-root-reads-plans-4c-box-throttle.tsv +1 −1
  • internal/provision/testdata/plan14-root-reads-static-sweep-new.tsv +5 −0
  • internal/provision/testdata/plan14-root-reads-static-sweep.tsv +3 −0
diff --git a/docs/superpowers/notes/census-proposal-plans-4c-box-throttle.md b/docs/superpowers/notes/census-proposal-plans-4c-box-throttle.md
index aab2351f0..c716dfcf5 100644
--- a/docs/superpowers/notes/census-proposal-plans-4c-box-throttle.md
+++ b/docs/superpowers/notes/census-proposal-plans-4c-box-throttle.md
@@ -24,13 +24,12 @@ Recorded dispositions, which each change must still satisfy:
- `internal/host/plans_pass.go` `plansPass`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=PROPOSED-plans-2-box-limits;basis=root-route; the agent's plans pass, serialised by its own mutex, reads its own routes' accounts and two bucket objects (the plans marker, each account's limits record) into a cache; planIdleFor only narrows the activator's idle window. No root decision.
- `internal/activator/activator.go` `Service.sweepOnce`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=PROPOSED-seed;basis=census-ruling-FS-R6; registry remains legacy; PROPOSED-plans-2-box-limits: the sweep also narrows an entry's idle window to its account's plan idle through the SetIdleFor hook (never lengthens it; always-on workers and held probe entries are untouched; the hibernate, inflight and held-for-tick guards are unchanged).
-Seal: `e451c4d675d99778e80da0b4e175d568e72276d11041f84fcfd53d3bf25ebaaa` → `fa9363ccd028415b3286ac5367fc50594c218b9c0cb3cef9dd10fd49d1059717`.
+Seal: `35f31d046603874ae62b32a60a4f4bf265a9e7fc0edd2fa48a2f9bcec3e3a615` → `eb7ea2158bceb592e91ef9a8ddd549cf1db56f7e508861aea12d5455e99494c8`.
Overlay: `internal/provision/testdata/plan14-root-reads-plans-4c-box-throttle.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`.
-
## Decision (hand-written, census-ruling-plans-4c-units)
-The plan throttle adds seven new units. Each is a new unit, so each is a decision. They have their own overlay, `internal/provision/testdata/plan14-root-reads-plans-4c-units.tsv`, chained just before this one (seal → `e451c4d6…`). Each is classed `legacy`/`accepted-legacy`, the same way as its sibling:
+The plan throttle adds seven new units. Each is a new unit, so each is a decision. They have their own overlay, `internal/provision/testdata/plan14-root-reads-plans-4c-units.tsv`, chained just before this one (seal → `35f31d04…`). Each is classed `legacy`/`accepted-legacy`, the same way as its sibling:
| unit | sibling | what it does |
|---|---|---|
diff --git a/docs/superpowers/notes/census-proposal-static-sweep.md b/docs/superpowers/notes/census-proposal-static-sweep.md
new file mode 100644
index 000000000..f38b932c7
--- /dev/null
+++ b/docs/superpowers/notes/census-proposal-static-sweep.md
@@ -0,0 +1,28 @@
+# Census approval: static-sweep
+
+Ruling `census-ruling-static-sweep`. Every change below keeps the disposition it already has, so it needs an approval, not a decision.
+
+Envelopes re-pinned: `internal/edge`.
+
+Review: a model from the other family than the author reads the branch's diff against main on the amadan.net remote (`origin` or `amadan`, whichever points at amadan.net) and gives a verdict for every unit and every re-pinned envelope above. For a unit, compare the change with its recorded disposition and basis below; for an envelope, read every changed function in the package and what it reaches. Escalate if the change lets root open, run, query or follow anything it did not before from a path or input a tenant, an app or a box agent can create, write or name; if it weakens a check, refusal, validation, argument or environment the basis relies on; or if the diff cannot settle either. Otherwise approve. Record each verdict on #280 with the tip. An escalation goes to the census owner as a decision.
+
+Seal: `5f9f8435788e8bdaa965e1dc68cfccd5264b2b2121366ec73004b9ca3cb48ecb` → `5f9f8435788e8bdaa965e1dc68cfccd5264b2b2121366ec73004b9ca3cb48ecb`.
+
+Overlay: `internal/provision/testdata/plan14-root-reads-static-sweep.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`.
+
+## The decision: two new units, written by hand
+
+`internal/edge/static_sweep_unix.go` adds two units that read the disk. Their rows are in `internal/provision/testdata/plan14-root-reads-static-sweep-new.tsv`, chained before the overlay above. They are `@legacy` rows, so the seal moves to `5f9f8435…8ecb`.
+
+| unit | reads | proposed disposition |
+|---|---|---|
+| `sweepStaticCache` | `OpenFile` of `<cacheDir>/.edge.lock` (created if absent), then `flock` on it | `legacy`/`accepted-legacy`, J4 footing (`root-input`), as the edge's other static units are |
+| `setAside` | `ReadDir` of the cache, each valid account and each valid app; `Readlink` of each app's `current`; `Lstat` of each entry | the same |
+
+Both run in the agent (`carlos-edge.service`, user carlos), not root. They run once, at startup, from `EnableStatic`, before any static handler exists. A start sweeps only when it takes the cache's lock exclusively, and a start that creates the lock file sweeps nothing.
+
+The sweep touches only release trees (`<version>@<64-hex digest>`) and the edge's own debris (`.extract-<n>`, `.sweep-<name>-<n>`), and only under valid account and app names. It never touches bare names, files, links, or anything it doesn't recognise. Each app keeps its `current` tree. Every other release tree is renamed before the sweep returns, then removed in the background. `ensureExtracted` verifies the signed release again before extracting a fresh copy.
+
+Paul's rulings, 2026-10-25, on Astra's round 3 escalations:
+- **The guarantee against an old edge:** systemd stops an edge before it starts the next. The edge only runs as `carlos-edge.service`.
+- **A lock this edge cannot hold:** it serves anyway and raises an ALERT, so a lock-file fault doesn't take static sites down.
diff --git a/internal/edge/edge.go b/internal/edge/edge.go
index 061bb5f20..5ae2fa590 100644
--- a/internal/edge/edge.go
+++ b/internal/edge/edge.go
@@ -157,7 +157,10 @@ type Edge struct {
staticStore release.Store
staticPub ed25519.PublicKey
staticCacheDir string
- staticRecheck time.Duration
+ // staticLock is this process's shared hold on the static cache
+ // (sweepStaticCache): a starting edge sweeps only when it is alone.
+ staticLock *os.File
+ staticRecheck time.Duration
// staticRatchet is #253's ratchet for static pointer reads: marks under
// <dataDir>/pointer-digests, root's under /opt read too.
staticRatchet *release.DigestRatchet
@@ -461,6 +464,12 @@ func (e *Edge) EnableStatic(store release.Store, pub ed25519.PublicKey, cacheDir
e.staticPub = pub
e.staticCacheDir = cacheDir
e.staticRecheck = staticRecheck
+ // Before any static handler exists: old extracted trees go if this is
+ // the only edge using the cache (static_sweep_unix.go). The lock is
+ // held, shared, for the process's life.
+ if cacheDir != "" && e.staticLock == nil {
+ e.staticLock, _ = sweepStaticCache(cacheDir)
+ }
e.armStoreDoor()
}
diff --git a/internal/edge/static_sweep_other.go b/internal/edge/static_sweep_other.go
new file mode 100644
index 000000000..2be635b30
--- /dev/null
+++ b/internal/edge/static_sweep_other.go
@@ -0,0 +1,13 @@
+//go:build !unix
+
+package edge
+
+import "os"
+
+// sweepStaticCache needs flock to know no other edge serves the cache; with
+// none here, nothing is swept (static_sweep_unix.go).
+func sweepStaticCache(string) (*os.File, <-chan struct{}) {
+ done := make(chan struct{})
+ close(done)
+ return nil, done
+}
diff --git a/internal/edge/static_sweep_test.go b/internal/edge/static_sweep_test.go
new file mode 100644
index 000000000..df7b1c712
--- /dev/null
+++ b/internal/edge/static_sweep_test.go
@@ -0,0 +1,195 @@
+//go:build unix
+
+package edge
+
+import (
+ "os"
+ "path/filepath"
+ "sort"
+ "strings"
+ "syscall"
+ "testing"
+)
+
+// tree is a cache entry name as ensureExtracted makes it.
+func tree(version string) string { return version + "@" + strings.Repeat("ab", 32) }
+
+// cacheTree makes <cache>/<acct>/<app>/<name>/index.html.
+func cacheTree(t *testing.T, cache, acct, app, name string) {
+ t.Helper()
+ dir := filepath.Join(cache, acct, app, name)
+ if err := os.MkdirAll(dir, 0o755); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.WriteFile(filepath.Join(dir, "index.html"), []byte(name), 0o644); err != nil {
+ t.Fatal(err)
+ }
+}
+
+func pointAt(t *testing.T, cache, acct, app, name string) {
+ t.Helper()
+ if err := os.Symlink(name, filepath.Join(cache, acct, app, "current")); err != nil {
+ t.Fatal(err)
+ }
+}
+
+// seenLock marks the cache as used by a lock-aware edge before, so this
+// start may sweep (first start: sweepStaticCache).
+func seenLock(t *testing.T, cache string) {
+ t.Helper()
+ if err := os.WriteFile(filepath.Join(cache, staticLockName), nil, 0o600); err != nil {
+ t.Fatal(err)
+ }
+}
+
+func entries(t *testing.T, dir string) []string {
+ t.Helper()
+ es, err := os.ReadDir(dir)
+ if err != nil {
+ t.Fatal(err)
+ }
+ var names []string
+ for _, e := range es {
+ names = append(names, e.Name())
+ }
+ sort.Strings(names)
+ return names
+}
+
+func sweep(t *testing.T, cache string) {
+ t.Helper()
+ lock, done := sweepStaticCache(cache)
+ if lock == nil {
+ t.Fatal("no serving lock")
+ }
+ t.Cleanup(func() { lock.Close() })
+ <-done
+}
+
+// With no other edge holding the cache, every release tree but each app's
+// current one goes, and so does the edge's own debris (a temp extraction,
+// an earlier sweep's leftovers) and pre-#253 bare-version trees. Anything
+// the sweep does not recognise as its own (an operator's directory, a
+// file, a link) is left alone.
+func TestStaticStartupSweepKeepsOnlyEachAppsCurrentTree(t *testing.T) {
+ cache := t.TempDir()
+ seenLock(t, cache)
+ for _, v := range []string{"v1", "v2", "v3"} {
+ cacheTree(t, cache, "bab", "apt", tree(v))
+ }
+ pointAt(t, cache, "bab", "apt", tree("v3"))
+ cacheTree(t, cache, "bab", "apt", ".extract-123")
+ cacheTree(t, cache, "bab", "apt", ".sweep-"+tree("v0")+"-17")
+ cacheTree(t, cache, "bab", "apt", "v0.5.0-1") // a bare version: left, as an operator's "backup" would be
+ cacheTree(t, cache, "bab", "apt", "backup 2026")
+ cacheTree(t, cache, "Not An Account", "apt", tree("v1")) // not a valid account: never entered
+ if err := os.WriteFile(filepath.Join(cache, "bab", "apt", "note.txt"), []byte("x"), 0o644); err != nil {
+ t.Fatal(err)
+ }
+ cacheTree(t, cache, "bac", "docs", tree("v7"))
+ pointAt(t, cache, "bac", "docs", tree("v7"))
+ cacheTree(t, cache, "bac", "nolink", tree("v1")) // no current link: no tree is kept
+
+ sweep(t, cache)
+
+ if got, want := entries(t, filepath.Join(cache, "bab", "apt")), []string{"backup 2026", "current", "note.txt", "v0.5.0-1", tree("v3")}; strings.Join(got, "|") != strings.Join(want, "|") {
+ t.Errorf("bab/apt = %v, want %v", got, want)
+ }
+ if got, want := entries(t, filepath.Join(cache, "bac", "docs")), []string{"current", tree("v7")}; strings.Join(got, "|") != strings.Join(want, "|") {
+ t.Errorf("bac/docs = %v, want %v", got, want)
+ }
+ if got := entries(t, filepath.Join(cache, "bac", "nolink")); len(got) != 0 {
+ t.Errorf("bac/nolink = %v, want empty", got)
+ }
+ if got := entries(t, filepath.Join(cache, "Not An Account", "apt")); len(got) != 1 {
+ t.Errorf("an invalid account's directory was entered: %v", got)
+ }
+}
+
+// A release may be named like the edge's debris (.extract-x, .sweep-x-1
+// are valid version names). Its tree is a release tree, recognised by its
+// @digest, and is never taken for debris: kept when current, renamed out
+// of reach before it is removed otherwise.
+func TestStaticStartupSweepNeverTakesAReleaseForDebris(t *testing.T) {
+ cache := t.TempDir()
+ seenLock(t, cache)
+ cacheTree(t, cache, "bab", "a", tree(".sweep-x-1"))
+ pointAt(t, cache, "bab", "a", tree(".sweep-x-1"))
+ cacheTree(t, cache, "bab", "b", tree(".extract-9"))
+ cacheTree(t, cache, "bab", "b", tree("v2"))
+ pointAt(t, cache, "bab", "b", tree("v2"))
+
+ lock, done := sweepStaticCache(cache)
+ defer lock.Close()
+ // Before the background removal ends, the non-current release is
+ // already gone from its own name: nothing can select it.
+ if _, err := os.Stat(filepath.Join(cache, "bab", "b", tree(".extract-9"))); !os.IsNotExist(err) {
+ t.Errorf("a non-current release tree was still at its own name after the sweep returned: %v", err)
+ }
+ <-done
+ if got := entries(t, filepath.Join(cache, "bab", "a")); strings.Join(got, "|") != tree(".sweep-x-1")+"|current" {
+ t.Errorf("bab/a = %v, want the current release kept", got)
+ }
+ if got := entries(t, filepath.Join(cache, "bab", "b")); strings.Join(got, "|") != "current|"+tree("v2") {
+ t.Errorf("bab/b = %v", got)
+ }
+}
+
+// The first lock-aware edge on a cache creates the lock file and sweeps
+// nothing: an edge from before this change may still be serving from it
+// without taking the lock. From the next start on, every edge using the
+// cache is known to take it.
+func TestStaticStartupSweepFirstStartOnlyCreatesTheLock(t *testing.T) {
+ cache := t.TempDir()
+ cacheTree(t, cache, "bab", "apt", tree("v1"))
+ cacheTree(t, cache, "bab", "apt", tree("v2"))
+ pointAt(t, cache, "bab", "apt", tree("v2"))
+ sweep(t, cache)
+ if got := entries(t, filepath.Join(cache, "bab", "apt")); len(got) != 3 {
+ t.Errorf("bab/apt = %v, want nothing swept on the first lock-aware start", got)
+ }
+ if _, err := os.Stat(filepath.Join(cache, staticLockName)); err != nil {
+ t.Fatalf("no lock file: %v", err)
+ }
+}
+
+// Another edge process serving from the same cache holds its lock: the
+// sweep does nothing, and still returns a shared lock for this process.
+func TestStaticStartupSweepSkipsWhileAnotherEdgeServes(t *testing.T) {
+ cache := t.TempDir()
+ cacheTree(t, cache, "bab", "apt", tree("v1"))
+ cacheTree(t, cache, "bab", "apt", tree("v2"))
+ pointAt(t, cache, "bab", "apt", tree("v2"))
+ seenLock(t, cache)
+ other, err := os.OpenFile(filepath.Join(cache, staticLockName), os.O_RDWR, 0o600)
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer other.Close()
+ if err := syscall.Flock(int(other.Fd()), syscall.LOCK_SH); err != nil {
+ t.Fatal(err)
+ }
+ sweep(t, cache)
+ if got := entries(t, filepath.Join(cache, "bab", "apt")); len(got) != 3 {
+ t.Errorf("bab/apt = %v, want everything kept while another edge serves", got)
+ }
+}
+
+// This process's lock is shared once the sweep is done: a second edge
+// starting beside it cannot sweep either.
+func TestStaticStartupSweepLeavesASharedLock(t *testing.T) {
+ cache := t.TempDir()
+ seenLock(t, cache)
+ sweep(t, cache)
+ probe, err := os.OpenFile(filepath.Join(cache, staticLockName), os.O_RDWR, 0o600)
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer probe.Close()
+ if err := syscall.Flock(int(probe.Fd()), syscall.LOCK_EX|syscall.LOCK_NB); err == nil {
+ t.Fatal("an exclusive lock was granted while this edge serves")
+ }
+ if err := syscall.Flock(int(probe.Fd()), syscall.LOCK_SH|syscall.LOCK_NB); err != nil {
+ t.Fatalf("a second edge could not share the lock: %v", err)
+ }
+}
diff --git a/internal/edge/static_sweep_unix.go b/internal/edge/static_sweep_unix.go
new file mode 100644
index 000000000..fbf15e743
--- /dev/null
+++ b/internal/edge/static_sweep_unix.go
@@ -0,0 +1,204 @@
+//go:build unix
+
+package edge
+
+import (
+ "errors"
+ "fmt"
+ "log"
+ "os"
+ "path/filepath"
+ "regexp"
+ "syscall"
+ "time"
+
+ "github.com/carlosframework/platform/internal/release"
+)
+
+// Every version of a static site a box served stayed extracted under
+// <cacheDir>/<acct>/<app>/ forever: annie-welding held 51 copies of the apt
+// site, 20 GB of 59 (2026-10-25). Sweeping on the serving path races the
+// handlers that pick trees (Astra review of static-sweep), so the sweep
+// runs once, at startup, before any handler exists, and only when no other
+// edge process can be serving from this cache:
+// - Every running edge holds a shared flock on staticLockName for its
+// life. A starting edge sweeps only if it can take it exclusively.
+// - An edge from before this change takes no lock, so the first edge to
+// create the lock file sweeps nothing: from its next start on, every
+// edge using the cache is known to take the lock. That rests on the
+// edge only running as carlos-edge.service, which systemd stops before
+// it starts the next (Paul's ruling, 2026-10-25, on Astra round 3).
+// - An edge that cannot hold the lock serves anyway and raises an ALERT
+// (Paul's ruling, same day): a lock-file fault must not take static
+// sites down, and the exposure needs a second edge starting beside it.
+//
+// Only entries the edge itself made are touched, recognised by name:
+// release trees (<version>@<digest>, siteDirName), temp extractions
+// (.extract-<n>, os.MkdirTemp's) and an earlier sweep's leftovers
+// (.sweep-<name>-<n>), under account and app directories whose names are
+// valid ones. Each app keeps the tree
+// its current link names. Every other release tree is renamed to a .sweep-
+// name before the sweep returns, so no handler built after it can select
+// it (ensureExtracted then extracts a fresh, verified copy if a pointer
+// names that version), and is removed in the background with the debris.
+const staticLockName = ".edge.lock"
+
+var (
+ siteTreeName = regexp.MustCompile(`^(.+)@[0-9a-f]{64}$`)
+ extractTmpName = regexp.MustCompile(`^\.extract-[0-9]+$`)
+ sweptName = regexp.MustCompile(`^\.sweep-.+-[0-9]+$`)
+)
+
+// staticEntry is how the sweep reads one name in an app directory.
+type staticEntry int
+
+const (
+ entryUnknown staticEntry = iota // not the edge's: never touched
+ entryTree // a release tree, set aside unless current
+ entryDebris // the edge's own leftovers: removed
+)
+
+func classifyStaticEntry(name string) staticEntry {
+ if m := siteTreeName.FindStringSubmatch(name); m != nil && release.ValidVersion(m[1]) {
+ return entryTree
+ }
+ if extractTmpName.MatchString(name) || sweptName.MatchString(name) {
+ return entryDebris
+ }
+ // A pre-#253 tree keyed by a bare version is not swept: a bare name
+ // cannot be told from an operator's directory (Astra round 3).
+ return entryUnknown
+}
+
+// sweepStaticCache sweeps cacheDir if no other edge can be using it, and
+// returns this process's lock on it, held shared until the process exits
+// (nil when no lock could be held), and a channel closed once the
+// background removal is done. A lock it cannot hold is an ALERT, not a
+// refusal to serve: static sites stay up, and the only exposure is a second
+// edge starting beside this one while it serves.
+func sweepStaticCache(cacheDir string) (*os.File, <-chan struct{}) {
+ done := make(chan struct{})
+ fail := func(f *os.File, err error) (*os.File, <-chan struct{}) {
+ log.Printf("ALERT: edge: static cache %s: no lock held (%v): not swept, and a second edge starting beside this one could sweep trees it serves", cacheDir, err)
+ if f != nil {
+ f.Close()
+ }
+ close(done)
+ return nil, done
+ }
+ if err := os.MkdirAll(cacheDir, 0o755); err != nil {
+ return fail(nil, err)
+ }
+ path := filepath.Join(cacheDir, staticLockName)
+ first := false
+ lock, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0o600)
+ if err == nil {
+ first = true
+ } else if errors.Is(err, os.ErrExist) {
+ lock, err = os.OpenFile(path, os.O_RDWR, 0o600)
+ }
+ if err != nil {
+ return fail(nil, err)
+ }
+ fd := int(lock.Fd())
+ shared := func() error {
+ var err error
+ for range 5 {
+ if err = syscall.Flock(fd, syscall.LOCK_SH); err == nil {
+ return nil
+ }
+ time.Sleep(200 * time.Millisecond)
+ }
+ return err
+ }
+ if first {
+ log.Printf("edge: static cache %s: first start with the lock; sweeping from the next start", cacheDir)
+ if err := shared(); err != nil {
+ return fail(lock, err)
+ }
+ close(done)
+ return lock, done
+ }
+ if err := syscall.Flock(fd, syscall.LOCK_EX|syscall.LOCK_NB); err != nil {
+ log.Printf("edge: static cache %s: another edge process serves from it; not swept this start", cacheDir)
+ if err := shared(); err != nil {
+ return fail(lock, err)
+ }
+ close(done)
+ return lock, done
+ }
+ doomed := setAside(cacheDir)
+ if err := shared(); err != nil {
+ return fail(lock, err)
+ }
+ go func() {
+ defer close(done)
+ removed := 0
+ for _, p := range doomed {
+ if err := os.RemoveAll(p); err != nil {
+ log.Printf("edge: static cache: remove %s: %v", p, err)
+ continue
+ }
+ removed++
+ }
+ if removed > 0 {
+ log.Printf("edge: static cache %s: swept %d entr(ies) no app's current link names", cacheDir, removed)
+ }
+ }()
+ return lock, done
+}
+
+// setAside renames, in every <acct>/<app> directory, each release tree the
+// current link does not name to a .sweep- name, and returns those paths and
+// the edge's debris for removal. It touches nothing it does not recognise.
+func setAside(cacheDir string) []string {
+ var doomed []string
+ accts, err := os.ReadDir(cacheDir)
+ if err != nil {
+ return nil
+ }
+ stamp := time.Now().UnixNano()
+ for _, a := range accts {
+ if !a.IsDir() || !release.ValidAccount(a.Name()) {
+ continue
+ }
+ apps, err := os.ReadDir(filepath.Join(cacheDir, a.Name()))
+ if err != nil {
+ continue
+ }
+ for _, ap := range apps {
+ if !ap.IsDir() || !release.ValidApp(ap.Name()) {
+ continue
+ }
+ appDir := filepath.Join(cacheDir, a.Name(), ap.Name())
+ cur, _ := os.Readlink(filepath.Join(appDir, "current"))
+ names, err := os.ReadDir(appDir)
+ if err != nil {
+ continue
+ }
+ for _, n := range names {
+ name := n.Name()
+ path := filepath.Join(appDir, name)
+ if name == cur {
+ continue
+ }
+ fi, err := os.Lstat(path)
+ if err != nil || !fi.IsDir() {
+ continue
+ }
+ switch classifyStaticEntry(name) {
+ case entryDebris:
+ doomed = append(doomed, path)
+ case entryTree:
+ to := filepath.Join(appDir, fmt.Sprintf(".sweep-%s-%d", name, stamp))
+ if err := os.Rename(path, to); err != nil {
+ log.Printf("edge: static cache: set aside %s: %v", path, err)
+ continue
+ }
+ doomed = append(doomed, to)
+ }
+ }
+ }
+ }
+ return doomed
+}
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv
index 169b87182..b66720d56 100644
--- a/internal/provision/testdata/plan14-root-reads-chain.tsv
+++ b/internal/provision/testdata/plan14-root-reads-chain.tsv
@@ -25,5 +25,7 @@ plan14-root-reads-design-edge-rate-limit-358-decisions.tsv a067dcd9e32e6be2b7dd9
plan14-root-reads-design-edge-rate-limit-358.tsv 0c4eabfe38e12b098285bdeb5ceb0b16e5333928f5b02e160a6b16b5fd9ce1e0
plan14-root-reads-plans-4b-after-grace.tsv 0c4eabfe38e12b098285bdeb5ceb0b16e5333928f5b02e160a6b16b5fd9ce1e0
plan14-root-reads-certwarm-wake.tsv 91204fcbc484343c03bd5ae69e3084055bc519a5b317e2ae3dc49880080764e2
-plan14-root-reads-plans-4c-units.tsv e451c4d675d99778e80da0b4e175d568e72276d11041f84fcfd53d3bf25ebaaa
-plan14-root-reads-plans-4c-box-throttle.tsv fa9363ccd028415b3286ac5367fc50594c218b9c0cb3cef9dd10fd49d1059717
+plan14-root-reads-static-sweep-new.tsv 5f9f8435788e8bdaa965e1dc68cfccd5264b2b2121366ec73004b9ca3cb48ecb
+plan14-root-reads-static-sweep.tsv 5f9f8435788e8bdaa965e1dc68cfccd5264b2b2121366ec73004b9ca3cb48ecb
+plan14-root-reads-plans-4c-units.tsv 35f31d046603874ae62b32a60a4f4bf265a9e7fc0edd2fa48a2f9bcec3e3a615
+plan14-root-reads-plans-4c-box-throttle.tsv eb7ea2158bceb592e91ef9a8ddd549cf1db56f7e508861aea12d5455e99494c8
diff --git a/internal/provision/testdata/plan14-root-reads-plans-4c-box-throttle.tsv b/internal/provision/testdata/plan14-root-reads-plans-4c-box-throttle.tsv
index ba61b0bcd..f76ad6f4a 100644
--- a/internal/provision/testdata/plan14-root-reads-plans-4c-box-throttle.tsv
+++ b/internal/provision/testdata/plan14-root-reads-plans-4c-box-throttle.tsv
@@ -12,6 +12,6 @@ internal/host/plans_pass.go plansPass legacy accepted-legacy accepted-legacy;rev
internal/activator/activator.go Service.sweepOnce legacy accepted-legacy accepted-legacy;rev3=PROPOSED-seed;basis=census-ruling-FS-R6; registry remains legacy; PROPOSED-plans-2-box-limits: the sweep also narrows an entry's idle window to its account's plan idle through the SetIdleFor hook (never lengthens it; always-on workers and held probe entries are untouched; the hibernate, inflight and held-for-tick guards are unchanged).;rev3=census-ruling-plans-4c-box-throttle;basis=after the worker max_run branch, stops a non-worker entry past the plans continuous-awake ceiling (maxRunFor, passed the row), busy or not, never mid-command (plans 4c). One more whole-row read: the row handed to the hook, as idleFor already is. registry:Hibernate@12971,registry:Hibernate@22142,registry:Hibernate@5124,registry:Hibernate@6794,registry:Hibernate@9319,registry:Host@22211,registry:Host@22269,registry:Host@22641,registry:Host@22734,registry:Host@23469,registry:Host@23551,registry:Host@24616,registry:Host@24795,registry:Host@24844,registry:NextDue@23424,registry:Status@22158,whole:Route@10074,whole:Route@12973,whole:Route@14906,whole:Route@16616,whole:Route@16806,whole:Route@17099,whole:Route@17271,whole:Route@17418,whole:Route@21629,whole:Route@23138,whole:Route@23478,whole:Route@23485,whole:Route@24431,whole:Route@24828,whole:Route@5126,whole:Route@6796,whole:Route@7230,whole:Route@9321 3180204acfaf05f0798b0e22bc2eda7e64b0375a4b1c1b62a09cd5c64fa7dab8
@coverage internal/activator 16c5cfa55eaf72198f6185406e0ab6fa95d7a9d9006cd89c87e28650b1992a6b
@coverage internal/console 939232f35c7eb28793b6fbcc1a4c1c117f402f677960221e9af22df6e520465f
-@coverage internal/edge 102520ba4fa6783f2a0e2d9c9f86eadf28af677e630b8fd87a3bd4f461f71848
+@coverage internal/edge 1c2f46148f9ade37a00bbe2f18cae89ce9d72a4ce6d0152a6806037171dae6b4
@coverage internal/host 9abbe344d6e32a02113775d7b9d9b69f354e76c26f689b52fdf7e599711cafbb
@coverage internal/plans 69df5bdee2fff4d10a8ff01ba7d102f54ae1f9693fec3ac40506b80fb9805768
diff --git a/internal/provision/testdata/plan14-root-reads-static-sweep-new.tsv b/internal/provision/testdata/plan14-root-reads-static-sweep-new.tsv
new file mode 100644
index 000000000..acc8062d7
--- /dev/null
+++ b/internal/provision/testdata/plan14-root-reads-static-sweep-new.tsv
@@ -0,0 +1,5 @@
+# Census overlay static-sweep-new, hand-written: the two new units census-propose leaves to a decision (the static cache startup sweep). census-ruling-static-sweep, asked of the census owner with the approval card (docs/superpowers/notes/census-proposal-static-sweep.md).
+@legacy 01d453647fbf9841171111b2f665e8ec465f013d3d30ee89943d640e44d7e859 internal/edge/static_sweep_unix.go setAside legacy accepted-legacy accepted-legacy;rev3=census-ruling-static-sweep;identity=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos);basis=root-input; once at startup, before any static handler exists, only under an exclusive flock (sweepStaticCache), reads its own static cache (<cacheDir>/<acct>/<app> with valid account and app names: entries, each current link, each entry lstat) and renames each release tree (<version>@<64-hex digest>) the current link does not name to a .sweep- name for removal, with its own debris (.extract-<n>, .sweep-<name>-<n>); never touches files, links, bare names, or names it does not recognise; every tree is a cache of a signed release that ensureExtracted re-verifies before extracting it again; no root decision file:Lstat@789,file:ReadDir@275,file:ReadDir@587,file:ReadDir@78,file:Readlink@524 2606d2b61669d213755ecdc97f69c4ba14a476e3a63f06abff243a0a80204653
+@legacy f4b3cea3571093ff6035600d23a48a030829f97635ba72ce9fae343d3d3b54a9 internal/edge/static_sweep_unix.go sweepStaticCache legacy accepted-legacy accepted-legacy;rev3=census-ruling-static-sweep;identity=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos);basis=root-input; opens or creates <cacheDir>/.edge.lock and flocks it: a start that creates it sweeps nothing (an older edge may not lock; systemd stops an edge before it starts the next, Paul 2026-10-25), otherwise exclusive non-blocking to sweep, then shared for the process life; a lock it cannot hold is an ALERT and the edge still serves (Paul 2026-10-25); the lock decides only whether this start sweeps; no root decision file:OpenFile@556,file:OpenFile@701 0c2857704f81442d833c121e5f7f9b726324c52557d66a50a87d3b4c7c632fdf
+internal/edge/static_sweep_unix.go setAside legacy accepted-legacy accepted-legacy;rev3=census-ruling-static-sweep;identity=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos);basis=root-input; once at startup, before any static handler exists, only under an exclusive flock (sweepStaticCache), reads its own static cache (<cacheDir>/<acct>/<app> with valid account and app names: entries, each current link, each entry lstat) and renames each release tree (<version>@<64-hex digest>) the current link does not name to a .sweep- name for removal, with its own debris (.extract-<n>, .sweep-<name>-<n>); never touches files, links, bare names, or names it does not recognise; every tree is a cache of a signed release that ensureExtracted re-verifies before extracting it again; no root decision file:Lstat@789,file:ReadDir@275,file:ReadDir@587,file:ReadDir@78,file:Readlink@524 2606d2b61669d213755ecdc97f69c4ba14a476e3a63f06abff243a0a80204653
+internal/edge/static_sweep_unix.go sweepStaticCache legacy accepted-legacy accepted-legacy;rev3=census-ruling-static-sweep;identity=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos);basis=root-input; opens or creates <cacheDir>/.edge.lock and flocks it: a start that creates it sweeps nothing (an older edge may not lock; systemd stops an edge before it starts the next, Paul 2026-10-25), otherwise exclusive non-blocking to sweep, then shared for the process life; a lock it cannot hold is an ALERT and the edge still serves (Paul 2026-10-25); the lock decides only whether this start sweeps; no root decision file:OpenFile@556,file:OpenFile@701 0c2857704f81442d833c121e5f7f9b726324c52557d66a50a87d3b4c7c632fdf
diff --git a/internal/provision/testdata/plan14-root-reads-static-sweep.tsv b/internal/provision/testdata/plan14-root-reads-static-sweep.tsv
new file mode 100644
index 000000000..b2ad5efaa
--- /dev/null
+++ b/internal/provision/testdata/plan14-root-reads-static-sweep.tsv
@@ -0,0 +1,3 @@
+# Census overlay static-sweep, written by census-propose (#369). census-ruling-static-sweep, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-static-sweep.md.
+# 0 body, 0 sites, 1 envelope: each changed unit re-frozen at its existing disposition with its claim appended.
+@coverage internal/edge c3f646eaa73b9f08211a678d6874c66c39e22473b3ad5442d7dfcc00ff5066be