Set aside a fleet copy through /data/.instances (EXDEV fix)
The managed-fleets 1b start rule sets an unmarked or reassigned local copy aside by renaming it from the instance directory into <DataDir>/.superseded. On the nested layout <DataDir>/instances is a nosymfollow bind mount of <DataDir>/.instances, and rename(2) refuses to cross mount points even within one filesystem, so every move failed with EXDEV and every wake was refused. Found on dev fleet box box-1 after v0.33.1: shop and railsdemo answered 503 from their first restart since the drill labelled them (v0.33.0 code). supersede now moves the copy out through <DataDir>/.instances/<id> when that is the same directory as <DataDir>/instances/<id> (same device and inode), which shares .superseded's mount. Anything else moves from the instance directory as before. The set-aside location, the durability order and the no-symlink opens are unchanged. Test: TestSetAsideCrossesTheNestedBindMount re-executes itself in an unprivileged user and mount namespace, binds .instances on instances, checks a plain rename across the bind is EXDEV, then runs the real Restore and checks the copy is set aside whole and a replica restored. It fails without the fix with the box's error, and skips where the kernel allows no unprivileged mount namespace.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
internal/activator/startrule.go+32 −3internal/activator/startrule_bind_linux_test.go+124 −0
CI failed — run details
Intent
<task-notification> <task-id>af4316d8578e8cb5c</task-id> <tool-use-id>toolu_01BufUTU9ik6riWdw5xDku9A</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/3bbea1fd-996b-42f3-b651-0add5a8ac1d5/tasks/af4316d8578e8cb5c.output</output-file> <status>completed</status> <summary>Agent "Cut v0.33.1 and roll dev" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>The dev console is on v0.33.1 and every dev check passed, except shop and railsdemo on box-1, which I've marked KNOWN FAILING as you asked. Detail is in /home/paulca/.cache/release-v0.33.1/roll-log.md. **Console roll** - Shipped and promoted to canary/console at 08:50:48–08:51:01Z, using the console build stamped with 11c8c864. - Console restart: stopped at 08:51:05.93Z and serving again at 08:51:08.54Z, about 2.6 s. It hasn't restarted since. - x-carlos-version is v0.33.1 on platform.dev.carlosframework.com from 08:51:10Z. - Over the 5-minute probe of GET /, all 1186 requests got 200. Requests sent during the restart waited at most 2.55 s. - The rollback target was v0.33.0 (c48f29ff); I didn't need it. **Checks** - **Sophie's console drop-ins:** the 9 drop-ins and 4 files have the same sha8, owner and mode before and after. - **Console journal since start:** no ERROR lines, none mentioning interactive, tty, session or relay, and no panics. - **"launch rule not cleared":** absent. - **"Alert checks":** running. The job writes nothing to the journal and its status page needs an operator sign-in, so my evidence is its beat file, alert-engine.beat. It was rewritten at 08:51:08Z and again by 08:56:08Z, with no beat errors. - **alert-connectors.key:** exists. I checked existence only. - **Edge journals on sophie, leo and dennis:** no ERROR, REFUSING or LEASE HELD lines, no proxy errors, no restarts, and no ERROR lines about interactive, tty, session or relay. Their host.env files haven't changed since this morning's pre-check. - **Everything else from v0.33.0's checklist passed:** - all boxes v0.33.1 current except box-2, which is detached and was already unreachable on v0.33.0; - fleets ls, hosts-used (38 recorded, floor v0.33.0), and the static site's headers are unchanged; - the protection logs path works, the ops-account exemption holds, and the billing webhook returns 400 as before; - wakecheck returned 200 (0.51 s), and analytics exited 0 for all four apps. - **Shop and railsdemo on box-1:** both returned 200 before the roll and 503 after. KNOWN FAILING (the v0.33.0 set-aside cross-device bug); I didn't touch box-1. **Anything odd** - At 08:09:11Z, the second sophie's edge restarted, one sample got 502 from both shop and railsdemo. That is the gap before box-1's tunnel reconnected at 08:09:12Z. - The analytics commands needed `--account bab`. Without it the CLI exits 1 saying I belong to several accounts. - Main moved to 90c4d3aa (#488) after I tagged at MERGE, so that commit is not in v0.33.1. Nothing I started is still running. The Plan 6 dev-box checklist is yours.</result> <usage><subagent_tokens>204151</subagent_tokens><tool_uses>18</tool_uses><duration_ms>389860</duration_ms></usage> </task-notification>
Attributed to this commit: 56.2 g CO₂e (6,153,352 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on fix-set-aside-exdev, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.
diff --git a/internal/activator/startrule.go b/internal/activator/startrule.go| index 3090e793f..09eda92aa 100644 |
| --- a/internal/activator/startrule.go |
| +++ b/internal/activator/startrule.go |
| @@ -15,7 +15,9 @@ package activator |
| // |
| // A local copy under any other assignment, or under none, is SET ASIDE, |
| // NEVER DELETED: moved whole into <DataDir>/.superseded/<host>/<unix |
| -// nanos>/ (built as <unix nanos>.partial and renamed when complete). A |
| +// nanos>/ (built as <unix nanos>.partial and renamed when complete; on the |
| +// nested layout the move goes through <DataDir>/.instances, see |
| +// setAsideSource). A |
| // set-aside copy, complete or partial, stays on disk as the standing |
| // reason to refuse an empty start, so a second wake and an agent restart |
| // refuse again. Nothing in this package deletes from .superseded: that is |
| @@ -217,6 +219,32 @@ func (b *ExecBackend) reconcileAssignment(rt registry.Route, dbPath string) erro |
| return nil |
| } |
| +// setAsideSource is the directory the set-aside moves a local copy out |
| +// of. On the nested layout <DataDir>/instances is a nosymfollow bind |
| +// mount of <DataDir>/.instances, and rename(2) refuses to cross mount |
| +// points even within one filesystem (EXDEV), so a move from |
| +// <DataDir>/instances/<id> into <DataDir>/.superseded can never succeed |
| +// (found on a dev fleet box, v0.33.0: every wake of an unmarked copy was |
| +// refused). When dir is <DataDir>/instances/<id> and |
| +// <DataDir>/.instances/<id> is the same directory, the copy moves out |
| +// through the latter, which shares .superseded's mount. Anything else |
| +// (the flat layout, a test's plain directory) moves from dir as before. |
| +// The renames open both paths with no symlink resolution, as before. |
| +func (b *ExecBackend) setAsideSource(dir string) string { |
| + data := filepath.Clean(b.DataDir) |
| + id, err := filepath.Rel(filepath.Join(data, "instances"), filepath.Clean(dir)) |
| + if err != nil || id == "." || id == ".." || strings.HasPrefix(id, ".."+string(filepath.Separator)) || strings.ContainsRune(id, filepath.Separator) { |
| + return dir |
| + } |
| + raw := filepath.Join(data, ".instances", id) |
| + viaBind, errB := os.Lstat(dir) |
| + viaRaw, errR := os.Lstat(raw) |
| + if errB != nil || errR != nil || !viaBind.IsDir() || !viaRaw.IsDir() || !os.SameFile(viaBind, viaRaw) { |
| + return dir |
| + } |
| + return raw |
| +} |
| + |
| // supersede moves names from dir into a new set-aside entry for host and |
| // returns the entry's final path. On a failure part way, what has moved |
| // stays in the .partial directory, whose path the error names. |
| @@ -239,6 +267,7 @@ func (b *ExecBackend) supersede(host, dir string, names []string) (string, error |
| } |
| root := filepath.Dir(hostDir) |
| dataRoot := filepath.Dir(root) |
| + src := b.setAsideSource(dir) |
| if _, err := instancefs.EnsureDirBeneath(dataRoot, supersededDirName, 0o700); err != nil { |
| return "", err |
| } |
| @@ -271,10 +300,10 @@ func (b *ExecBackend) supersede(host, dir string, names []string) (string, error |
| return partial, fmt.Errorf("sync %s: %w", hostDir, err) |
| } |
| for _, n := range names { |
| - if err := setAsideRename(dir, n, partial, n); err != nil { |
| + if err := setAsideRename(src, n, partial, n); err != nil { |
| return partial, fmt.Errorf("interrupted with part of it at %s: %w", partial, err) |
| } |
| - for _, d := range []string{dir, partial} { |
| + for _, d := range []string{src, partial} { |
| if err := durableSync(d); err != nil { |
| return partial, fmt.Errorf("interrupted with part of it at %s: sync %s: %w", partial, d, err) |
| } |
diff --git a/internal/activator/startrule_bind_linux_test.go b/internal/activator/startrule_bind_linux_test.go| new file mode 100644 |
| index 000000000..998c29544 |
| --- /dev/null |
| +++ b/internal/activator/startrule_bind_linux_test.go |
| @@ -0,0 +1,124 @@ |
| +//go:build linux |
| + |
| +package activator |
| + |
| +import ( |
| + "context" |
| + "errors" |
| + "os" |
| + "os/exec" |
| + "path/filepath" |
| + "strings" |
| + "syscall" |
| + "testing" |
| + |
| + "github.com/carlosframework/platform/internal/provision" |
| + "github.com/carlosframework/platform/internal/registry" |
| +) |
| + |
| +// bindChildEnv marks the re-executed test binary that runs inside its own |
| +// user and mount namespace, where it may bind-mount without privilege. |
| +const bindChildEnv = "CARLOS_TEST_SETASIDE_BIND_CHILD" |
| + |
| +// bindSkipPrefix is what the child prints when this kernel will not let |
| +// it build the bind mount, so the parent skips rather than fails. |
| +const bindSkipPrefix = "SKIP-BIND: " |
| + |
| +// TestSetAsideCrossesTheNestedBindMount sets aside an unmarked copy on the |
| +// nested layout as a box has it: <DataDir>/instances is a bind mount of |
| +// <DataDir>/.instances, so rename(2) from an instance directory into |
| +// <DataDir>/.superseded fails with EXDEV. v0.33.0 moved through the bind |
| +// and refused every wake of shop and railsdemo on a dev fleet box. The |
| +// test runs the real Restore in a user and mount namespace holding that |
| +// bind, checks first that a plain rename across it does fail with EXDEV, |
| +// and then that the copy is set aside whole and a replica restored. |
| +func TestSetAsideCrossesTheNestedBindMount(t *testing.T) { |
| + if os.Getenv(bindChildEnv) == "1" { |
| + setAsideUnderBind(t) |
| + return |
| + } |
| + self, err := os.Executable() |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + cmd := exec.Command(self, "-test.run=^TestSetAsideCrossesTheNestedBindMount$", "-test.count=1", "-test.v") |
| + cmd.Env = append(os.Environ(), bindChildEnv+"=1") |
| + cmd.SysProcAttr = &syscall.SysProcAttr{ |
| + Cloneflags: syscall.CLONE_NEWUSER | syscall.CLONE_NEWNS, |
| + UidMappings: []syscall.SysProcIDMap{{ContainerID: 0, HostID: os.Getuid(), Size: 1}}, |
| + GidMappings: []syscall.SysProcIDMap{{ContainerID: 0, HostID: os.Getgid(), Size: 1}}, |
| + } |
| + out, err := cmd.CombinedOutput() |
| + if i := strings.Index(string(out), bindSkipPrefix); i >= 0 { |
| + t.Skipf("no bind mount in an unprivileged namespace here: %s", strings.TrimSpace(string(out[i+len(bindSkipPrefix):]))) |
| + } |
| + if err != nil { |
| + var ee *exec.ExitError |
| + if !errors.As(err, &ee) { |
| + t.Skipf("no unprivileged user and mount namespace here: %v", err) |
| + } |
| + t.Fatalf("set-aside under the bind failed: %v\n%s", err, out) |
| + } |
| + if !strings.Contains(string(out), "--- PASS: TestSetAsideCrossesTheNestedBindMount") { |
| + t.Fatalf("the child did not run the test:\n%s", out) |
| + } |
| +} |
| + |
| +// setAsideUnderBind is the child's half: it builds the box's bind, then |
| +// drives Restore on a labelled row whose copy has no marker. |
| +func setAsideUnderBind(t *testing.T) { |
| + skip := func(format string, args ...any) { |
| + t.Logf(bindSkipPrefix+format, args...) |
| + t.SkipNow() |
| + } |
| + // A mount made here must not propagate anywhere. |
| + if err := syscall.Mount("", "/", "", syscall.MS_REC|syscall.MS_PRIVATE, ""); err != nil { |
| + skip("make / private: %v", err) |
| + } |
| + b := testExecBackend(t) |
| + raw := filepath.Join(b.DataDir, ".instances") |
| + bind := filepath.Join(b.DataDir, "instances") |
| + for _, d := range []string{raw, bind} { |
| + if err := os.Mkdir(d, 0o700); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + if err := syscall.Mount(raw, bind, "", syscall.MS_BIND, ""); err != nil { |
| + skip("bind %s on %s: %v", raw, bind, err) |
| + } |
| + t.Cleanup(func() { _ = syscall.Unmount(bind, syscall.MNT_DETACH) }) |
| + |
| + instDir := provision.InstanceDir(b.DataDir, ruleHost) |
| + if err := os.Mkdir(instDir, 0o700); err != nil { |
| + t.Fatal(err) |
| + } |
| + // The condition the box had: a rename out through the bind is EXDEV. |
| + probe := filepath.Join(instDir, "probe") |
| + if err := os.WriteFile(probe, nil, 0o600); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := os.Rename(probe, filepath.Join(b.DataDir, "probe")); !errors.Is(err, syscall.EXDEV) { |
| + t.Fatalf("rename across the bind = %v; want EXDEV, or this test reproduces nothing", err) |
| + } |
| + if err := os.Remove(probe); err != nil { |
| + t.Fatal(err) |
| + } |
| + |
| + rt := registry.Route{Host: ruleHost, Kind: "instance", Hibernate: true, |
| + Socket: "/tmp/nope.sock", DBPath: filepath.Join(instDir, ruleHost+".db"), |
| + Assigned: assignA} |
| + want := localCopy(t, rt.DBPath, "") |
| + restores := replicaCalls(t, true) |
| + |
| + fresh, err := b.Restore(context.Background(), rt) |
| + if err != nil || fresh { |
| + t.Fatalf("fresh %v err %v; want the copy set aside and a replica restored", fresh, err) |
| + } |
| + if *restores != 1 { |
| + t.Fatalf("restores = %d; want 1", *restores) |
| + } |
| + assertSetAside(t, b, rt.Host, want) |
| + if got, ok := markerAt(t, rt.DBPath); !ok || got != assignA { |
| + t.Fatalf("marker = %q (present %v); want %q after the restore", got, ok, assignA) |
| + } |
| +} |