carlos / platform Public

region HA: keep the start fence on persistent storage

The start fence moves from /run/carlos-group-fence to
/var/lib/carlos-group-fence, same ownership and modes (root, dir 0755,
file 0644). /run is a tmpfs, so a member that rebooted in the middle of
a transaction came back unfenced (Task 7's reboot gap); now it comes
back fenced until drain --cancel or fence-clear of the transaction.

The simulation's reboot keeps the fence. With that, a reboot alone no
longer makes a stale report unsafe, so action-on-stale-report is now
witnessed by an out-of-band drain --cancel that lifts the fence after
the report; the sweep gains that event at 1 in 8 seeds. 3,000 seeds:
baseline 0, action-on-stale-report caught 45, fence-lift-on-unknown 9.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev cc8c08a10daf2bb33d68d54e973f3e0f1370a878 parent 43d12df
4 files changed, +79 −18
  • internal/host/hadrainfence.go +10 −8
  • internal/host/hadrainfence_linux_test.go +36 −0
  • internal/sim/regionha/handover_test.go +18 −5
  • internal/sim/regionha/handover_witness_test.go +15 −5

Intent

Human

<task-notification> <task-id>af98cd70b0fccc48d</task-id> <tool-use-id>toolu_01Auk9wEUN3nTAGF4fyA4CcH</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/283be278-5c6a-4a71-a8d6-b3d32c668985/tasks/af98cd70b0fccc48d.output</output-file> <status>completed</status> <summary>Agent "Implement Task 7: simulation" 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>Status: DONE (fix round 1, Astra P2-1 fixed) Commit: 43d12df1 `region HA sim: separate admission tickets from app entry (R3.2)` (on top of e1e10cf4, not pushed) Tests: - The unmutated 3,000-seed sweep had 0 failures (20.4 s), serial at nice 19. - The new rule `move-ignores-tickets` is caught by the sweep (297 of 3,000 seeds, all H1) and by its witness. - I re-ran the two H1 rules because the oracle changed. Both are still caught: `movestate-after-gate` in 2,880 seeds and `movestate-skips-marked` in 2,041. - Package tests, gofmt and vet pass. What changed: - **Admission is two steps.** MoveState's "none" now issues a ticket, and the request reaches A's app 0 to 3 s later, so the move can start in between. - **The move waits on outstanding tickets.** It counts requests that are ticketed but not yet in the app, as well as those running in it, for up to 10 s. At that bound it cuts the app and gives the waiting requests today's answer. - **The H1 check matches.** A request needs a ticket to enter A's app. A ticketed request may enter while its host is holding, but never after the app was stopped. - **One knob changed.** Drawing the new delay shifted the random stream, so I turned the third-box local race on in two thirds of seeds instead of one third, to keep that path covered. Concerns: the other 11 rules were not re-run at 3,000 seeds; their witnesses still pass. The file split (P3) stays deferred, as you said. Report (fix section appended): /home/paulca/amadan.net/carlos/platform/.claude/worktrees/region-ha-held-build/.superpowers/sdd/2026-11-08-region-ha-held-requests/task-7-report.md</result> <usage><subagent_tokens>381243</subagent_tokens><tool_uses>9</tool_uses><duration_ms>323058</duration_ms></usage> </task-notification>

diff --git a/internal/host/hadrainfence.go b/internal/host/hadrainfence.go
index 08679f32f..fa3a37e08 100644
--- a/internal/host/hadrainfence.go
+++ b/internal/host/hadrainfence.go
@@ -11,13 +11,15 @@ package host
// /run/carlos-group-maintenance, but that directory is root's alone
// (0700; tmpfiles, openMaintenanceDirectory, consumeGroupAction and
// checkGroupMaintenanceDirectory all insist on it), and the agent runs as
-// carlos, so it could never read a fence there. The fence is therefore
-// its sibling, /run/carlos-group-fence, which the same verbs create and
-// own: root's, 0755, holding fence.json, root's, 0644. The agent can read
-// it and cannot write, rename or remove it (only root writes /run and the
-// directory). /run is a tmpfs, so a reboot clears the fence; that is
-// safe, because a terminated member never boots again and a roll
-// restarts only the edge (the box does not reboot).
+// carlos, so it could never read a fence there. The fence therefore has
+// its own directory, /var/lib/carlos-group-fence, which the same verbs
+// create and own: root's, 0755, holding fence.json, root's, 0644. The
+// agent can read it and cannot write, rename or remove it (only root
+// writes /var/lib and the directory; the agent's unit is
+// ProtectSystem=strict, which leaves /var/lib readable). It is on
+// persistent storage, not /run, so a member that reboots in the middle
+// of a transaction comes back fenced (Task 7's reboot gap): only
+// drain --cancel and fence-clear of the transaction lift it.
//
// Reading fails closed: an absent directory or file is no fence; a fence
// that is present but cannot be read, is not root's, is writable by
@@ -32,7 +34,7 @@ import (
)
const (
- groupFenceDir = "/run/carlos-group-fence"
+ groupFenceDir = "/var/lib/carlos-group-fence"
groupFenceFile = "fence.json"
// groupFenceMax bounds the fence body read.
groupFenceMax = 1024
diff --git a/internal/host/hadrainfence_linux_test.go b/internal/host/hadrainfence_linux_test.go
index 2ac7fdd5f..7790f91a3 100644
--- a/internal/host/hadrainfence_linux_test.go
+++ b/internal/host/hadrainfence_linux_test.go
@@ -27,6 +27,42 @@ func testFence(t *testing.T) fenceLocation {
return fenceLocation{root: root, dir: filepath.Join(root, "carlos-group-fence"), owner: os.Geteuid()}
}
+// The fence is on persistent storage (§25.15 R3.1, Task 7's reboot gap):
+// /var/lib/carlos-group-fence, root's, so a member that reboots in the
+// middle of a transaction comes back fenced. It is never under /run, a
+// tmpfs a reboot empties. The production location is read and written
+// from the real root, through the same protected-ancestor walk the
+// fixtures below exercise; under a root laid out like a box (var/lib,
+// 0755) the verb's install creates the directory 0755 and the file 0644,
+// and a fresh location value (a new process after the reboot) reads it.
+func TestStartFenceIsPersistent(t *testing.T) {
+ want := fenceLocation{root: "/", dir: "/var/lib/carlos-group-fence", owner: 0}
+ if groupStartFence != want || groupFenceDir != want.dir {
+ t.Fatalf("production fence %+v (dir %q), want %+v", groupStartFence, groupFenceDir, want)
+ }
+ if strings.HasPrefix(groupFenceDir, "/run/") || strings.HasPrefix(groupFenceDir, "/tmp/") {
+ t.Fatalf("fence dir %q is on a tmpfs", groupFenceDir)
+ }
+ root := t.TempDir()
+ must(t, os.Chmod(root, 0755))
+ must(t, os.MkdirAll(filepath.Join(root, "var", "lib"), 0755))
+ rel, err := filepath.Rel("/", groupFenceDir)
+ must(t, err)
+ l := fenceLocation{root: root, dir: filepath.Join(root, rel), owner: os.Geteuid()}
+ must(t, l.install("t1", time.Unix(100, 0)))
+ if st, err := os.Stat(l.dir); err != nil || st.Mode().Perm() != 0755 {
+ t.Fatalf("fence dir: %v %v, want 0755", st, err)
+ }
+ if st, err := os.Stat(filepath.Join(l.dir, groupFenceFile)); err != nil || st.Mode().Perm() != 0644 {
+ t.Fatalf("fence file: %v %v, want 0644", st, err)
+ }
+ after := fenceLocation{root: root, dir: filepath.Join(root, rel), owner: os.Geteuid()}
+ if s := after.read(); !s.Present || s.Err != nil || s.Transaction != "t1" {
+ t.Fatalf("after a restart: %+v, want t1's fence", s)
+ }
+ must(t, after.remove("t1"))
+}
+
func TestStartFenceInstallReadRemove(t *testing.T) {
l := testFence(t)
if s := l.read(); s.Present {
diff --git a/internal/sim/regionha/handover_test.go b/internal/sim/regionha/handover_test.go
index 6f6c1990d..f85bbc054 100644
--- a/internal/sim/regionha/handover_test.go
+++ b/internal/sim/regionha/handover_test.go
@@ -190,6 +190,7 @@ type hoKnobs struct {
RestoreFails map[string]bool
ReportDelay int
Reboot int // seconds into the report wait that A reboots; -1 never
+ StrayCancel int // seconds into the report wait that an out-of-band drain --cancel lands; -1 never
Restart int // the second A's agent crashes; -1 never
RestartDown int // seconds it stays down
Stop string // proven, unknown-stopped, unknown-running, running
@@ -1127,9 +1128,10 @@ func (ho *hoWorld) agentDown(reboot bool) {
for _, x := range lost {
ho.finish(x.r.First, x.r, "reset")
}
- if reboot {
- ho.fence = "" // /run is a tmpfs
- }
+ // A reboot keeps the fence: it is on persistent storage
+ // (/var/lib/carlos-group-fence, §25.15), so the new incarnation comes
+ // up behind it whether the agent crashed or the box rebooted.
+ _ = reboot
switch ho.phase {
case "withdraw", "quiesce", "move", "conn":
ho.drainFail("the agent restarted")
@@ -1538,6 +1540,13 @@ func (ho *hoWorld) txnStep() {
ho.agentDown(true)
ho.agentUp()
}
+ // An operator's drain --cancel of this transaction from another
+ // session: it ends the drain and lifts the fence, so A may place
+ // and acquire again before the tool's pre-action check.
+ if k.StrayCancel >= 0 && el == k.StrayCancel && ho.live(A) && ho.fence == ho.txn {
+ ho.event("ho-stray-cancel")
+ ho.cancel()
+ }
if el < k.ReportDelay {
return
}
@@ -1616,7 +1625,7 @@ func (ho *hoWorld) txnStep() {
ho.lockFree(A, "the terminate as it lands")
ho.w.terminate(A)
delete(ho.inService, A)
- ho.fence = "" // moot: it lived in the member's /run
+ ho.fence = "" // moot: the member and its disk are gone
if k.Kind == "replace" {
ho.desired, ho.minimum = ho.n, ho.n
ho.event("ho-replaced")
@@ -1973,7 +1982,7 @@ func randomKnobs(rng *rand.Rand, n int, hosts []string, nodes []string) hoKnobs
Start: rng.Intn(20), AckDelay: map[string]int{}, Ack2Delay: map[string]int{},
Release: map[string]sleepOpts{}, ReleaseLat: map[string]int{}, TakeLat: map[string]int{},
Race: map[string]bool{}, RestoreFails: map[string]bool{},
- PendingFor: 1 + rng.Intn(3), ReportDelay: 1 + rng.Intn(10), Reboot: -1, Restart: -1,
+ PendingFor: 1 + rng.Intn(3), ReportDelay: 1 + rng.Intn(10), Reboot: -1, StrayCancel: -1, Restart: -1,
Land: 2 + rng.Intn(20), EdgeRestart: -1, Poll: "running", Probe: "absent",
}
switch x := rng.Intn(10); {
@@ -2022,6 +2031,10 @@ func randomKnobs(rng *rand.Rand, n int, hosts []string, nodes []string) hoKnobs
k.Reboot = rng.Intn(k.ReportDelay)
k.ReportDelay += 10
}
+ if rng.Intn(8) == 0 {
+ k.StrayCancel = rng.Intn(k.ReportDelay)
+ k.ReportDelay += 10
+ }
switch x := rng.Intn(20); {
case x == 0:
k.Stop = "running"
diff --git a/internal/sim/regionha/handover_witness_test.go b/internal/sim/regionha/handover_witness_test.go
index b667a488e..a8fa99a31 100644
--- a/internal/sim/regionha/handover_witness_test.go
+++ b/internal/sim/regionha/handover_witness_test.go
@@ -30,7 +30,7 @@ func init() {
witness{"report-before-quiescence", "report-before-quiescence", "I11",
"roll: A's acquire of blog is between GET and PUT as the drain starts; a report before it settles lets apply run with it in flight", wHOQuiesce},
witness{"action-on-stale-report", "action-on-stale-report", "I11",
- "roll: A reboots after its report, losing the fence, and acquires blog; acting on the old report applies while a lease names A", wHOStale},
+ "roll: A reboots after its report and keeps the fence; then an out-of-band drain --cancel lifts it and A acquires blog; acting on the old report applies while a lease names A", wHOStale},
witness{"place-before-acks", "place-before-acks", "WD",
"C's acknowledgement is slow; a drain that goes on without it closes A's gate while C still places blog on A (§6.3 rule 1)", wHOAcks},
witness{"move-ignores-tickets", "move-ignores-tickets", "H1",
@@ -52,7 +52,7 @@ func hoWitness(w *world, kind string, extra ...string) *hoWorld {
Kind: kind, AckDelay: map[string]int{}, Ack2Delay: map[string]int{},
Release: map[string]sleepOpts{}, ReleaseLat: map[string]int{}, TakeLat: map[string]int{},
Race: map[string]bool{}, RestoreFails: map[string]bool{},
- PendingFor: 1, ReportDelay: 1, Reboot: -1, Restart: -1, Stop: "proven", Land: 3,
+ PendingFor: 1, ReportDelay: 1, Reboot: -1, StrayCancel: -1, Restart: -1, Stop: "proven", Land: 3,
EdgeRestart: -1, Poll: "running", Probe: "absent",
}
for _, h := range w.hosts {
@@ -228,16 +228,26 @@ func wHOQuiesce(t *testing.T, w *world) {
func wHOStale(t *testing.T, w *world) {
A, _, C := w.abc()
ho := hoWitness(w, "roll", "blog")
- ho.k.ReportDelay = 5
+ ho.k.ReportDelay = 8
w.wake(A, sh, wakeOpts{}, nil)
ho.until(t, "the report", func() bool { return ho.phase == "report" })
+ // A reboot keeps the persistent fence: the new incarnation is fenced
+ // and a request for blog cannot start it on A.
ho.agentDown(true)
ho.agentUp()
+ expect(t, "action-on-stale-report", ho.fence == ho.txn, "the reboot keeps the fence")
ho.second(nil)
r := ho.req("client", ho.nodeOf[C], "blog", "none", 0)
ho.arrive(r)
+ ho.second(nil)
+ expect(t, "action-on-stale-report", A.Entries["blog"] == nil, "the fenced agent starts nothing")
+ // An out-of-band cancel lifts the fence; blog is then placed on A.
+ ho.k.StrayCancel = ho.sec + 1 - ho.phaseAt
+ ho.second(nil)
+ r = ho.req("client", ho.nodeOf[C], "blog", "none", 0)
+ ho.arrive(r)
ho.finishAll()
- expect(t, "action-on-stale-report", w.events["ho-precheck-refused"] == 1 && w.events["ho-roll-applied"] == 0, "the pre-action check refuses after the reboot")
+ expect(t, "action-on-stale-report", w.events["ho-stray-cancel"] == 1 && w.events["ho-precheck-refused"] == 1 && w.events["ho-roll-applied"] == 0, "the pre-action check refuses after the cancel")
}
func wHOAcks(t *testing.T, w *world) {
@@ -326,7 +336,7 @@ func TestHandoverEveryActionFires(t *testing.T) {
"ho-redirect", "ho-redirect-read", "ho-successor-slept", "ho-handover-answer", "ho-handover-followed",
"ho-handover-local", "ho-local-raced", "ho-retry-named",
"ho-reset-after-send", "ho-dial-before-send", "ho-placed-on-A", "ho-start-refused", "ho-start-refused-fenced",
- "ho-drained", "ho-reboot", "ho-agent-restart", "ho-precheck-refused",
+ "ho-drained", "ho-reboot", "ho-stray-cancel", "ho-agent-restart", "ho-precheck-refused",
"ho-roll-applied", "ho-edge-stop-unproven", "ho-terminate-dispatched", "ho-edge-restart",
"ho-replaced", "ho-removed", "ho-replacement-launched", "ho-drain-failed", "ho-cancel",
"ho-answer-app", "ho-answer-today", "ho-answer-fa", "ho-answer-cut", "ho-answer-reset",