carlos / platform Public

Merge remote-tracking branch 'origin/main' into rootfs-apps-3-release

claude agent, operated by paul@keymail.dev 03c67c8bb7ba64bc78c00466e4aae0255e15d3c5 parent 3c1e8c1parent ee06618
10 files changed, +341 −15
  • README.md +2 −2
  • docs/superpowers/notes/census-proposal-retire-join-units-on-adopt.md +24 −0
  • docs/superpowers/notes/census-retire-join-units-on-adopt-claims.md +3 −0
  • docs/superpowers/reviews/ASTRA-FINDINGS-retire-join-units-on-adopt-R1.md +26 −0
  • docs/superpowers/reviews/CODEX-REVIEW-BRIEF-retire-join-units-on-adopt.md +101 −0
  • internal/host/retiredunits.go +29 −13
  • internal/host/systemunits.go +14 −0
  • internal/host/systemunits_test.go +132 −0
  • internal/provision/testdata/plan14-root-reads-chain.tsv +1 −0
  • internal/provision/testdata/plan14-root-reads-retire-join-units-on-adopt.tsv +9 −0
diff --git a/README.md b/README.md
index d5e31e74b..48d50a9f5 100644
--- a/README.md
+++ b/README.md
@@ -364,8 +364,8 @@ while it is stopped.
2. Run `console hosts-used roster -o roster.json`. It lists every box and
bucket the regions and fleets use.
3. Scan every target on the roster with `scripts/hosts-used-scan-aws.sh`.
- Pass it a `--targets` coords file naming each box's instance and region
- and each bucket's prefix. The script's header shows the format.
+ Pass a `--targets` file that lists each box's instance ID and region,
+ and each bucket's prefix. See the script header for the file format.
4. Run `console hosts-used activate -roster roster.json -listings
scan.jsonl`. A fleet that cannot be scanned can be closed instead, with
`-close-fleet <fleet>`. A closed fleet takes no new instances. Regions
diff --git a/docs/superpowers/notes/census-proposal-retire-join-units-on-adopt.md b/docs/superpowers/notes/census-proposal-retire-join-units-on-adopt.md
new file mode 100644
index 000000000..beb98d091
--- /dev/null
+++ b/docs/superpowers/notes/census-proposal-retire-join-units-on-adopt.md
@@ -0,0 +1,24 @@
+# Census approval: retire-join-units-on-adopt
+
+Ruling `census-ruling-retire-join-units-on-adopt`. The independent reviewer approves or rejects every change below, 2 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26).
+
+| unit | change | read sites | what changed |
+|---|---|---|---|
+| `internal/host/systemunits.go` `ensureSystemUnits` | body | unchanged (5) | root (the hourly carlos adopt pass, carlos-adopt.timer, and the -config-only/-stage-only passes; never -restart-only): after the apply lock is taken and systemctl has answered, and before the already-armed early return, calls retireUnitsIn(<etc>/systemd/system, retiredUnits, its own systemctl seam) to disable --now, then remove, the units an earlier build installed and this one no longer ships (the compiled-in exact names carlos-system-join.path and carlos-system-join.service); an error is logged and never stops the arming; under a running apply (lock held) or a silent systemctl nothing is retired; no read added in this body (the reads are in retireUnitsIn) (#454) |
+
+Envelopes re-pinned: `internal/host`.
+
+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.
+
+Recorded dispositions, which each change must still satisfy:
+
+- `internal/host/systemunits.go` `ensureSystemUnits`: authority, task F,J4. Basis: rev3=PROPOSED-activation-tools;run=27;basis=automated offline transaction removed; retains preceding integrated classification: root-input;kept=F;scope=protected-decision-only;rev3=census-ruling-db-region-forward-1;identity=root (the adopt pass);basis=installs carlos-dbread.socket and carlos-dbread@.service with the other system units, asks one more is-active and arms the socket, never the service template; read sites unchanged, offsets moved; main's F authority retained; round 1: arms carlos-dbread.socket only when the installed host.env arms db reads (dbReadsSocketWanted reads its six db-reads keys through readClaimUnitFile, which the scanner does not name), and stops and disables it elsewhere
+
+New dispositions, which census-propose wrote and the reviewer checks against the unit's reads and the diff:
+
+- new `internal/host/retiredunits.go:retireUnitsIn`: reads +file:Glob ×2, +file:Lstat; written legacy, accepted-legacy, frozen
+- quiet `internal/host/retiredunits.go:retireUnits`: reads nothing now; retired while it reads nothing (or its row keeps no sites)
+
+Seal: `4337475617b84cadf26e62a31387b7de1b6e9174bf5e6fa4d191f2d2a024e930` → `9e0c4a0c3c5299f68a046e989f49f35cfd2af82dbc76f2e5f00d15512f101a9d`.
+
+Overlay: `internal/provision/testdata/plan14-root-reads-retire-join-units-on-adopt.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`.
diff --git a/docs/superpowers/notes/census-retire-join-units-on-adopt-claims.md b/docs/superpowers/notes/census-retire-join-units-on-adopt-claims.md
new file mode 100644
index 000000000..4d30374f6
--- /dev/null
+++ b/docs/superpowers/notes/census-retire-join-units-on-adopt-claims.md
@@ -0,0 +1,3 @@
+internal/host/systemunits.go:ensureSystemUnits root (the hourly carlos adopt pass, carlos-adopt.timer, and the -config-only/-stage-only passes; never -restart-only): after the apply lock is taken and systemctl has answered, and before the already-armed early return, calls retireUnitsIn(<etc>/systemd/system, retiredUnits, its own systemctl seam) to disable --now, then remove, the units an earlier build installed and this one no longer ships (the compiled-in exact names carlos-system-join.path and carlos-system-join.service); an error is logged and never stops the arming; under a running apply (lock held) or a silent systemctl nothing is retired; no read added in this body (the reads are in retireUnitsIn) (#454)
+internal/host/retiredunits.go:retireUnitsIn new: the body of main's retireUnits, unchanged in its reads, over one unit directory with a systemctl seam instead of the live-root test: for each name in the compiled-in list given (a name with a slash, "." or ".." is refused) Lstats <unitDir>/<unit>; with a seam and an installed unit runs systemctl disable --now <unit> (a failure leaves that unit on disk); Globs <unitDir>/*.wants/<unit> and *.requires/<unit> and removes those links and the unit file (os.Remove, so a link is removed, never followed); daemon-reload through the seam if anything went; reports whether anything was removed. Callers: retireUnits (bootstrap: <root>/etc/systemd/system, live seam only when root is "/") and ensureSystemUnits (the adopt pass: /etc/systemd/system). reads +file:Lstat and +file:Glob x2, all under root's own unit directory with names from the compiled-in retiredUnits list; no tenant, app or agent input names or writes them
+internal/host/retiredunits.go:retireUnits quiet: now a wrapper that picks the live systemctl when root is "/" (as before) and calls retireUnitsIn(<root>/etc/systemd/system, units, ...); its reads moved into retireUnitsIn unchanged
diff --git a/docs/superpowers/reviews/ASTRA-FINDINGS-retire-join-units-on-adopt-R1.md b/docs/superpowers/reviews/ASTRA-FINDINGS-retire-join-units-on-adopt-R1.md
new file mode 100644
index 000000000..f6a31fc96
--- /dev/null
+++ b/docs/superpowers/reviews/ASTRA-FINDINGS-retire-join-units-on-adopt-R1.md
@@ -0,0 +1,26 @@
+| Part A: unit / envelope | Change | Decision | Lines read and basis |
+|---|---|---|---|
+| `ensureSystemUnits` | Body | **APPROVE** | [systemunits.go:53–195](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/retire-join-units-on-adopt/internal/host/systemunits.go:53): retirement follows lock acquisition and responsive probes, precedes the armed return, and logs errors without stopping arming. |
+| `retireUnitsIn` | New; accepted legacy | **APPROVE** | [retiredunits.go:17–83](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/retire-join-units-on-adopt/internal/host/retiredunits.go:17): existing reads moved intact; production callers supply compiled-in exact names under `/etc/systemd/system`. Removal unlinks leaf symlinks. No new tenant-controlled input. |
+| `retireUnits` | Quiet | **APPROVE** | [retiredunits.go:32–38](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/retire-join-units-on-adopt/internal/host/retiredunits.go:32): wrapper contains no direct reads; moved reads are recorded under `retireUnitsIn`. Live-root selection is unchanged. |
+| `internal/host` | Re-pinned envelope | **APPROVE** | Above changes and [systemunits_test.go:215–333](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/retire-join-units-on-adopt/internal/host/systemunits_test.go:215), checked against bootstrap, adopt and apply callers. No additional authority expansion found. |
+
+P1: none.
+
+**P2 — Part B §6: the disable-failure test does not establish that disabling was attempted.**
+
+At [systemunits_test.go:279–303](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/retire-join-units-on-adopt/internal/host/systemunits_test.go:279), the mock records calls and injects a disable error, but assertions only check that the old files remain and arming continues. Those assertions also pass when retirement is skipped entirely.
+
+A regression that skips retirement on an unarmed box would therefore pass this test; the successful-retirement test exercises an already-armed box. This conclusion follows from source inspection; execution was blocked.
+
+Fix: assert that the exact `disable --now carlos-system-join.path` call occurred before checking preservation and continued arming.
+
+Fault family: **retirement failure handling must be exercised before its recovery behavior is asserted.**
+
+P3: none.
+
+Reviewed `origin/main...e240a15df521fd96d85d17dd1e73f7b9cdae5862`, merge base `6c4dccc3`. Exact-name scope, apply-lock exclusion, bootstrap staging behavior and portable API usage check out by inspection. The successful-retirement test would fail without the change; the lock-exclusion test appropriately checks a negative case.
+
+`git diff --check` passed. Targeted Go tests could not start because the read-only sandbox denied creation of `/var/tmp/go-build…`; census tests and cross-compilation remain unverified. No files were edited and no full suites were run.
+
+**READY AFTER FIXES**
\ No newline at end of file
diff --git a/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-retire-join-units-on-adopt.md b/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-retire-join-units-on-adopt.md
new file mode 100644
index 000000000..5e1d6a5b1
--- /dev/null
+++ b/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-retire-join-units-on-adopt.md
@@ -0,0 +1,101 @@
+# Review brief: branch retire-join-units-on-adopt (census + whole branch), round 1 of 3
+
+Repo carlos/platform, branch `retire-join-units-on-adopt`, commit named in
+the prompt that hands you this brief.
+Under review: the diff `origin/main...HEAD` (merge base 6c4dccc3).
+Authorities, all MERGED on main: AGENTS.md ("Stopping rules", "The census:
+the reviewer decides"); `internal/host/retiredunits.go` and its bootstrap
+call (region HA P1a, fd93024a); `internal/host/systemunits.go`
+(`ensureSystemUnits`, spec §7 "second belt"); `internal/host/systemapply.go`
+`installUnits` (the apply's own retirement of units the replaced build
+shipped). Do not review against unmerged branches; if this work needs one,
+say so as a P1 and stop.
+
+You are an independent reviewer. Read the diff, then the code it names,
+and check every claim against that code.
+
+## What the change is
+
+Region HA 2b installed `carlos-system-join.path` (watching
+`/data/system-join-requested`) and `carlos-system-join.service` (root
+oneshot `carlos system join`). P1a deleted both and the verb, and added
+`retireUnits`, which only bootstrap runs. `system apply` retires units only
+when the build it replaces (`carlos.prev`) shipped them. A box that left
+the join-era build by another road (a hand roll with
+update-platform-binary.sh, which only installs units, or a self-hosted
+box) keeps the units until a re-bootstrap. The branch makes the hourly
+root adopt pass (`ensureSystemUnits`) retire the same exact-named list,
+under the apply lock, before its already-armed early return. `retireUnits`
+is split into a wrapper and `retireUnitsIn(unitDir, units, systemctl)` so
+the adopt pass can pass its own systemctl seam. Discussion #454.
+
+## Part A: the census card
+
+Card: `docs/superpowers/notes/census-proposal-retire-join-units-on-adopt.md`;
+claims: `docs/superpowers/notes/census-retire-join-units-on-adopt-claims.md`;
+overlay: `internal/provision/testdata/plan14-root-reads-retire-join-units-on-adopt.tsv`.
+Give APPROVE or REJECT for every unit and every re-pinned envelope on the
+card (`ensureSystemUnits` body, `retireUnitsIn` new, `retireUnits` quiet,
+envelope `internal/host`), citing the lines you read. Reject, as a finding,
+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 root relies on; if a new disposition is wrong for the unit's
+reads; if the quiet unit's reads moved somewhere the card does not show;
+or if the diff cannot settle any of these.
+
+## Part B: what to check in the branch
+
+1. Exactness: only names in the compiled-in `retiredUnits` list are ever
+ disabled or removed. No pattern can match a unit this build ships or a
+ tenant's unit (`carlos-instance*@`, app units). The Globs only find
+ links named exactly after a retired unit. Removal never follows a link.
+2. The adopt pass on a real (fully armed) box actually reaches the retire
+ call; an armed box with nothing to retire makes no extra systemctl call.
+3. Concurrency with `carlos system apply`: retirement only happens under
+ the apply's lock; a held lock retires nothing.
+4. Failure: a failed `disable --now` leaves the unit on disk for the next
+ pass and does not stop the arming; nothing here can make the adopt pass
+ fatal or stop it converging releases.
+5. Bootstrap behaviour is unchanged: `retireUnits` still uses the live
+ systemctl only for root "/", and staging-tree bootstraps (system
+ apply's stagePlan) still only remove files.
+6. Tests (`internal/host/systemunits_test.go`, the three new
+ `TestEnsureSystemUnits*Retire*` / `*Retired*` tests): do they fail
+ without the change and pin the behaviour above?
+7. Cross-compile: `internal/host` links into the CLI on darwin and
+ windows; nothing new is Linux-only.
+
+## Severity
+
+- **P1**: unsafe, would not compile, a test fails, or it would not work.
+ Blocks merge.
+- **P2**: wrong or missing. Fixed without reopening this review. (The
+ census, and review of any newly changed security, root, termination
+ or production-storage behaviour, still check the fix; see AGENTS.md,
+ "Stopping rules".)
+- **P3**: clarity or polish. Goes on a follow-up list; never a reason for
+ another round.
+
+A P1 states its failure scenario and the evidence (file:line). Do not
+raise a P2 to P1 to keep the review open.
+
+## Output
+
+First the census verdict table (Part A): unit, change, APPROVE or REJECT,
+lines read. Then findings ranked P1, P2, P3. Each gives the section or
+task, the problem, the evidence (file:line, verified), the failure
+scenario, a concrete fix and the invariant or trust boundary it breaks
+(that is its fault family). End with exactly one verdict:
+
+- **READY**: no P1 and no P2.
+- **READY AFTER FIXES**: no P1. The listed P2s are fixed without another
+ round.
+- **NOT READY**: one or more P1s, listed.
+
+In round 3, a NOT READY also says whether the P1s share one cause, and
+whether refusing the case up front or cutting the feature would remove
+them.
+
+Do not edit files. Do not spawn Anthropic-model reviewers or subagents of
+your own. Do not run the full test suites.
diff --git a/internal/host/retiredunits.go b/internal/host/retiredunits.go
index 59af9bd67..099a11529 100644
--- a/internal/host/retiredunits.go
+++ b/internal/host/retiredunits.go
@@ -10,7 +10,10 @@ import (
// retiredUnits are units an earlier build installed and this one no longer
// ships: region HA's joining relay, removed with joining mode (region HA
// P1a). Bootstrap retires them so a box bootstrapped by that build does
-// not keep them installed and enabled.
+// not keep them installed and enabled, and so does the hourly root adopt
+// pass (ensureSystemUnits), for a box that left that build by a road that
+// retired nothing (#454). Exact names only, never a pattern: a name here
+// is disabled, stopped and deleted on every box.
var retiredUnits = []string{"carlos-system-join.path", "carlos-system-join.service"}
// retiredUnitLinks are the links `systemctl enable` made for a retired unit,
@@ -27,42 +30,55 @@ var retiredUnitLinks = map[string][]string{
// first; on any root its file and every *.wants/ or *.requires/ link to it
// are removed, which is what disable does to a staging tree.
func retireUnits(root string, units []string) error {
- live := filepath.Clean(root) == "/"
- unitDir := filepath.Join(root, "etc", "systemd", "system")
+ var live func(args ...string) error
+ if filepath.Clean(root) == "/" {
+ live = systemctl
+ }
+ _, err := retireUnitsIn(filepath.Join(root, "etc", "systemd", "system"), units, live)
+ return err
+}
+
+// retireUnitsIn is retireUnits over one unit directory. A non-nil
+// systemctl means the directory is the live one: an installed unit is
+// disabled and stopped through it before its file goes, a failure leaves
+// that unit (and every unit after it) on disk, and a daemon-reload follows
+// when anything went. A nil systemctl is a staging tree: files and links
+// only. It reports whether anything was removed.
+func retireUnitsIn(unitDir string, units []string, systemctl func(args ...string) error) (bool, error) {
removed := false
for _, u := range units {
if filepath.Base(u) != u || u == "." || u == ".." {
- return fmt.Errorf("retire %q: not a unit name", u)
+ return removed, fmt.Errorf("retire %q: not a unit name", u)
}
path := filepath.Join(unitDir, u)
_, err := os.Lstat(path)
installed := err == nil
if err != nil && !errors.Is(err, os.ErrNotExist) {
- return fmt.Errorf("retire %s: %w", u, err)
+ return removed, fmt.Errorf("retire %s: %w", u, err)
}
- if live && installed {
+ if systemctl != nil && installed {
if err := systemctl("disable", "--now", u); err != nil {
- return fmt.Errorf("retire %s: %w", u, err)
+ return removed, fmt.Errorf("retire %s: %w", u, err)
}
}
links, err := filepath.Glob(filepath.Join(unitDir, "*.wants", u))
if err != nil {
- return err
+ return removed, err
}
more, err := filepath.Glob(filepath.Join(unitDir, "*.requires", u))
if err != nil {
- return err
+ return removed, err
}
for _, p := range append(append(links, more...), path) {
if err := os.Remove(p); err == nil {
removed = true
} else if !errors.Is(err, os.ErrNotExist) {
- return fmt.Errorf("retire %s: %w", u, err)
+ return removed, fmt.Errorf("retire %s: %w", u, err)
}
}
}
- if live && removed {
- return systemctl("daemon-reload")
+ if systemctl != nil && removed {
+ return removed, systemctl("daemon-reload")
}
- return nil
+ return removed, nil
}
diff --git a/internal/host/systemunits.go b/internal/host/systemunits.go
index 0d7972188..d1150ee72 100644
--- a/internal/host/systemunits.go
+++ b/internal/host/systemunits.go
@@ -109,6 +109,20 @@ func ensureSystemUnits(etcDir, lockPath string, systemctl, probe func(args ...st
logf("adopt: system units: systemctl said nothing; not touching the self-update units: %v / %v / %v", activeErr, ctlActiveErr, dbrActiveErr)
return
}
+ // Units an earlier build installed and this one no longer ships
+ // (retiredUnits, exact names): disabled, stopped and removed here, under
+ // the apply's lock, before the already-armed early return below, which
+ // is where every real box leaves this pass. A failure is logged and
+ // leaves the unit for the next pass; it never stops the arming.
+ retired, err := retireUnitsIn(unitDir, retiredUnits, func(args ...string) error {
+ _, err := systemctl(args...)
+ return err
+ })
+ if err != nil {
+ logf("adopt: retired units: %v", err)
+ } else if retired {
+ logf("adopt: retired units this build no longer ships: %s", strings.Join(retiredUnits, ", "))
+ }
isEnabled := parseIsEnabled(enabled)
missing := false
for _, u := range systemUnitFiles {
diff --git a/internal/host/systemunits_test.go b/internal/host/systemunits_test.go
index 08b60928c..fe5fc01f3 100644
--- a/internal/host/systemunits_test.go
+++ b/internal/host/systemunits_test.go
@@ -5,6 +5,7 @@ import (
"fmt"
"os"
"path/filepath"
+ "slices"
"strings"
"testing"
)
@@ -205,3 +206,134 @@ func TestParseIsEnabled(t *testing.T) {
}
}
}
+
+// The hourly root adopt pass retires what an earlier build installed and
+// this one no longer ships (retiredUnits), on a box that is otherwise fully
+// armed: that is every real box, so the already-armed early return must not
+// skip it. `system apply` retires only what the build it replaces shipped,
+// and bootstrap only runs when someone runs it; a box that left the
+// join-era build by a hand roll keeps the units until this pass (#454).
+func TestEnsureSystemUnitsRetiresUnitsNoLongerShipped(t *testing.T) {
+ root := t.TempDir()
+ etc := filepath.Join(root, "etc")
+ unitDir := filepath.Join(etc, "systemd", "system")
+ lockPath := filepath.Join(t.TempDir(), "lock")
+ dbReadsHostEnv(t, etc)
+ var calls []string
+ systemctl := func(args ...string) (string, error) {
+ calls = append(calls, strings.Join(args, " "))
+ return "", nil
+ }
+ armed := func(args ...string) (string, error) {
+ calls = append(calls, strings.Join(args, " "))
+ switch args[0] {
+ case "is-active":
+ return "active\n", nil
+ case "is-enabled":
+ return "enabled\n", nil
+ }
+ return "", nil
+ }
+ // A first pass installs this build's units, so the next one is armed.
+ ensureSystemUnits(etc, lockPath, systemctl, armed, t.Logf)
+ writeUnit(t, root, "carlos-system-join.path")
+ if err := os.WriteFile(filepath.Join(unitDir, "carlos-system-join.service"), []byte("[Unit]\n"), 0o644); err != nil {
+ t.Fatal(err)
+ }
+
+ calls = nil
+ ensureSystemUnits(etc, lockPath, systemctl, armed, t.Logf)
+ joined := strings.Join(calls, "\n")
+ for _, want := range []string{"disable --now carlos-system-join.path", "disable --now carlos-system-join.service", "daemon-reload"} {
+ if !strings.Contains(joined, want) {
+ t.Errorf("calls lack %q:\n%s", want, joined)
+ }
+ }
+ for _, p := range []string{"carlos-system-join.path", "carlos-system-join.service", filepath.Join("multi-user.target.wants", "carlos-system-join.path")} {
+ if _, err := os.Lstat(filepath.Join(unitDir, p)); !os.IsNotExist(err) {
+ t.Errorf("%s still installed (%v)", p, err)
+ }
+ }
+ for _, u := range systemUnitFiles {
+ if _, err := os.Stat(filepath.Join(unitDir, u)); err != nil {
+ t.Errorf("retiring touched this build's %s: %v", u, err)
+ }
+ }
+
+ // Nothing left to retire: the armed pass is back to its five questions.
+ calls = nil
+ ensureSystemUnits(etc, lockPath, systemctl, armed, t.Logf)
+ if len(calls) != 5 {
+ t.Fatalf("an armed box with nothing to retire got %v", calls)
+ }
+}
+
+// A unit systemd will not disable stays on disk for the next pass, and the
+// rest of the pass still runs.
+func TestEnsureSystemUnitsKeepsARetiredUnitItCannotDisable(t *testing.T) {
+ root := t.TempDir()
+ etc := filepath.Join(root, "etc")
+ unitDir := filepath.Join(etc, "systemd", "system")
+ lockPath := filepath.Join(t.TempDir(), "lock")
+ writeUnit(t, root, "carlos-system-join.path")
+ var calls []string
+ systemctl := func(args ...string) (string, error) {
+ calls = append(calls, strings.Join(args, " "))
+ if args[0] == "disable" && strings.HasPrefix(args[len(args)-1], "carlos-system-join") {
+ return "", errors.New("Failed to disable unit")
+ }
+ return "", nil
+ }
+ probe := func(args ...string) (string, error) {
+ switch args[0] {
+ case "is-active":
+ return "inactive\n", systemctlExit(3)
+ case "is-enabled":
+ return "disabled\n", systemctlExit(1)
+ }
+ return "", nil
+ }
+ ensureSystemUnits(etc, lockPath, systemctl, probe, t.Logf)
+ // The retire was attempted, on an unarmed box too; only then does the
+ // unit still being there mean the failure kept it.
+ if !slices.Contains(calls, "disable --now carlos-system-join.path") {
+ t.Fatalf("retirement never tried to disable the join unit: %v", calls)
+ }
+ for _, p := range []string{"carlos-system-join.path", filepath.Join("multi-user.target.wants", "carlos-system-join.path")} {
+ if _, err := os.Lstat(filepath.Join(unitDir, p)); err != nil {
+ t.Errorf("%s removed although disable failed (%v)", p, err)
+ }
+ }
+ if !strings.Contains(strings.Join(calls, "\n"), "start carlos-system-update.path") {
+ t.Errorf("a failed retire stopped the arming: %v", calls)
+ }
+}
+
+// An apply in flight owns the unit directory: a locked-out pass retires
+// nothing either.
+func TestEnsureSystemUnitsRetiresNothingUnderARunningApply(t *testing.T) {
+ root := t.TempDir()
+ etc := filepath.Join(root, "etc")
+ lockPath := filepath.Join(t.TempDir(), "lock")
+ writeUnit(t, root, "carlos-system-join.path")
+ held, err := os.OpenFile(lockPath, os.O_CREATE|os.O_RDWR, 0o600)
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer held.Close()
+ if err := flockExclusiveNonblock(held); err != nil {
+ t.Skipf("flock unsupported on this platform: %v", err)
+ }
+ var calls []string
+ record := func(args ...string) (string, error) {
+ calls = append(calls, strings.Join(args, " "))
+ return "", nil
+ }
+ ensureSystemUnits(etc, lockPath, record, record, t.Logf)
+ if len(calls) != 0 {
+ t.Fatalf("a locked-out pass called systemctl: %v", calls)
+ }
+ if _, err := os.Lstat(filepath.Join(etc, "systemd", "system", "carlos-system-join.path")); err != nil {
+ t.Fatalf("a locked-out pass retired a unit: %v", err)
+ }
+}
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv
index 96a507acc..92fe53086 100644
--- a/internal/provision/testdata/plan14-root-reads-chain.tsv
+++ b/internal/provision/testdata/plan14-root-reads-chain.tsv
@@ -18,3 +18,4 @@ plan14-root-reads-plans-6b-checkout-flow.tsv f5afdacd495705841fcc8441eaefe0efb9d
plan14-root-reads-nearest-region-followups.tsv f5afdacd495705841fcc8441eaefe0efb9db7056de281bb06d1714960a5575b7
plan14-root-reads-region-ha-p1b1.tsv 185170fe393cb565d18a3359dee5ace12676b3e1adecb8b638199d25ceeb779f
plan14-root-reads-rootfs-apps-3.tsv 4337475617b84cadf26e62a31387b7de1b6e9174bf5e6fa4d191f2d2a024e930
+plan14-root-reads-retire-join-units-on-adopt.tsv 9e0c4a0c3c5299f68a046e989f49f35cfd2af82dbc76f2e5f00d15512f101a9d
diff --git a/internal/provision/testdata/plan14-root-reads-retire-join-units-on-adopt.tsv b/internal/provision/testdata/plan14-root-reads-retire-join-units-on-adopt.tsv
new file mode 100644
index 000000000..8e8822a84
--- /dev/null
+++ b/internal/provision/testdata/plan14-root-reads-retire-join-units-on-adopt.tsv
@@ -0,0 +1,9 @@
+# Census overlay retire-join-units-on-adopt, written by census-propose (#369). census-ruling-retire-join-units-on-adopt, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-retire-join-units-on-adopt.md.
+# 1 body, 0 sites, 1 envelope: each changed unit re-frozen at its existing disposition with its claim appended.
+# 2 new dispositions: 0 reads re-frozen at their disposition with the claim, 1 new units frozen accepted-legacy, 1 quiet units retired while they read nothing, 0 other.
+@legacy e3027dd15dbb86cb4b453a29e9facd9c6350ac1e88a01612ca05a755b5694e16 internal/host/retiredunits.go retireUnitsIn legacy accepted-legacy accepted-legacy;rev3=census-ruling-retire-join-units-on-adopt;basis=new: the body of main's retireUnits, unchanged in its reads, over one unit directory with a systemctl seam instead of the live-root test: for each name in the compiled-in list given (a name with a slash, "." or ".." is refused) Lstats <unitDir>/<unit>; with a seam and an installed unit runs systemctl disable --now <unit> (a failure leaves that unit on disk); Globs <unitDir>/*.wants/<unit> and *.requires/<unit> and removes those links and the unit file (os.Remove, so a link is removed, never followed); daemon-reload through the seam if anything went; reports whether anything was removed. Callers: retireUnits (bootstrap: <root>/etc/systemd/system, live seam only when root is "/") and ensureSystemUnits (the adopt pass: /etc/systemd/system). reads +file:Lstat and +file:Glob x2, all under root's own unit directory with names from the compiled-in retiredUnits list; no tenant, app or agent input names or writes them file:Glob@650,file:Glob@762,file:Lstat@319 f9c5bc0f1106e3b145e821acb64902e36e893c4ed81914dec8c03fd85731ad09
+internal/host/systemunits.go ensureSystemUnits authority F,J4 rev3=PROPOSED-activation-tools;run=27;basis=automated offline transaction removed; retains preceding integrated classification: root-input;kept=F;scope=protected-decision-only;rev3=census-ruling-db-region-forward-1;identity=root (the adopt pass);basis=installs carlos-dbread.socket and carlos-dbread@.service with the other system units, asks one more is-active and arms the socket, never the service template; read sites unchanged, offsets moved; main's F authority retained; round 1: arms carlos-dbread.socket only when the installed host.env arms db reads (dbReadsSocketWanted reads its six db-reads keys through readClaimUnitFile, which the scanner does not name), and stops and disables it elsewhere;rev3=census-ruling-retire-join-units-on-adopt;basis=root (the hourly carlos adopt pass, carlos-adopt.timer, and the -config-only/-stage-only passes; never -restart-only): after the apply lock is taken and systemctl has answered, and before the already-armed early return, calls retireUnitsIn(<etc>/systemd/system, retiredUnits, its own systemctl seam) to disable --now, then remove, the units an earlier build installed and this one no longer ships (the compiled-in exact names carlos-system-join.path and carlos-system-join.service); an error is logged and never stops the arming; under a running apply (lock held) or a silent systemctl nothing is retired; no read added in this body (the reads are in retireUnitsIn) (#454) file:OpenFile@265,file:ReadFile@4054,file:ReadFile@4187,file:ReadFile@5346,file:Stat@3963 7d3eac3bab7bddb99dc0556440d1f8522157a8de9120870611cf2bc7c11e3ac8
+internal/host/retiredunits.go retireUnitsIn legacy accepted-legacy accepted-legacy;rev3=census-ruling-retire-join-units-on-adopt;basis=new: the body of main's retireUnits, unchanged in its reads, over one unit directory with a systemctl seam instead of the live-root test: for each name in the compiled-in list given (a name with a slash, "." or ".." is refused) Lstats <unitDir>/<unit>; with a seam and an installed unit runs systemctl disable --now <unit> (a failure leaves that unit on disk); Globs <unitDir>/*.wants/<unit> and *.requires/<unit> and removes those links and the unit file (os.Remove, so a link is removed, never followed); daemon-reload through the seam if anything went; reports whether anything was removed. Callers: retireUnits (bootstrap: <root>/etc/systemd/system, live seam only when root is "/") and ensureSystemUnits (the adopt pass: /etc/systemd/system). reads +file:Lstat and +file:Glob x2, all under root's own unit directory with names from the compiled-in retiredUnits list; no tenant, app or agent input names or writes them file:Glob@650,file:Glob@762,file:Lstat@319 f9c5bc0f1106e3b145e821acb64902e36e893c4ed81914dec8c03fd85731ad09
+@remove internal/host/retiredunits.go retireUnits
+@removed internal/host/retiredunits.go retireUnits H3 census-ruling-retire-join-units-on-adopt;basis=quiet: now a wrapper that picks the live systemctl when root is "/" (as before) and calls retireUnitsIn(<root>/etc/systemd/system, units, ...); its reads moved into retireUnitsIn unchanged
+@coverage internal/host 8da342152b7e3c424da56b452c1e92454a081fd4b2fec6a4f40cd421c5f18754