Merge remote-tracking branch 'origin/main' into held-floor-capability
# Conflicts: # internal/provision/testdata/plan14-root-reads-chain.tsv
15 files changed,
+682
−31
docs/superpowers/notes/census-proposal-group-roll-dr4-lock-refusal.md+11 −0docs/superpowers/specs/2026-11-09-group-roll-verb-design.md+4 −2internal/grouproll/dr4.go+148 −0internal/grouproll/dr4_test.go+327 −0internal/grouproll/engine.go+4 −0internal/grouproll/fake_test.go+31 −8internal/grouproll/mutation_test.go+20 −0internal/grouproll/roll.go+39 −11internal/grouproll/roll_test.go+13 −3internal/grouproll/sim_test.go+76 −3internal/grouproll/testdata/parity-ledger.tsv+3 −3internal/provision/testdata/plan14-root-reads-chain.tsv+1 −0internal/provision/testdata/plan14-root-reads-group-roll-dr4-lock-refusal.tsv+3 −0internal/provision/testdata/plan14-root-reads-held-floor-capability.tsv+1 −1region_ha_boundary_test.go+1 −0
CI passed — run details
Intent
Attributed to this commit: 74.5 g CO₂e (8,951,767 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on held-floor-capability, 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/docs/superpowers/notes/census-proposal-group-roll-dr4-lock-refusal.md b/docs/superpowers/notes/census-proposal-group-roll-dr4-lock-refusal.md| new file mode 100644 |
| index 000000000..50b2137b6 |
| --- /dev/null |
| +++ b/docs/superpowers/notes/census-proposal-group-roll-dr4-lock-refusal.md |
| @@ -0,0 +1,11 @@ |
| +# Census approval: group-roll-dr4-lock-refusal |
| + |
| +Ruling `census-ruling-group-roll-dr4-lock-refusal`. The independent reviewer approves or rejects every change below, 0 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26). |
| + |
| +Envelopes re-pinned: `internal/grouproll`. |
| + |
| +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. Reject 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. A rejected unit goes back to the author to correct; nothing escalates to the census owner. |
| + |
| +Seal: `6d3ea7fccce1a7f4bc507b6eb8d368ed0b62f83022504aa04c7684c72c93aa9a` → `6d3ea7fccce1a7f4bc507b6eb8d368ed0b62f83022504aa04c7684c72c93aa9a`. |
| + |
| +Overlay: `internal/provision/testdata/plan14-root-reads-group-roll-dr4-lock-refusal.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`. |
diff --git a/docs/superpowers/specs/2026-11-09-group-roll-verb-design.md b/docs/superpowers/specs/2026-11-09-group-roll-verb-design.md| index 9f0de2041..2520d4409 100644 |
| --- a/docs/superpowers/specs/2026-11-09-group-roll-verb-design.md |
| +++ b/docs/superpowers/specs/2026-11-09-group-roll-verb-design.md |
| @@ -313,8 +313,9 @@ The Go verb does what the script does, decision for decision. In particular: |
| `carlos-edge.service`, prove `MainPID=0`, sweep the locks again, and terminate |
| (`stop_and_terminate`, `:2169-2182`). |
| - **The floor and DR-4.** `roll` drains only when the floor holds and says which |
| - rule applied; `replace` and `remove` refuse below the floor; a floor that cannot |
| - be read refuses and never falls back to DR-4 (§9). |
| + rule applied; under DR-4 it rolls only a member no lock names (V13); `replace` |
| + and `remove` refuse below the floor; a floor that cannot be read refuses and |
| + never falls back to DR-4 (§9). |
| - **The same bounds:** `WAIT` 900 s, `DRAIN_TRIES` 3, `DRAIN_BOUND` 3600 s, edge stop |
| 120 s, cancel 300 s, `TERMINATE_RETRIES` 2, settle 120 s, pending 600 s, the 5 s |
| freshness window on `ExitStandby`, the 60 s readiness age, the 2 s publication |
| @@ -372,6 +373,7 @@ build to it. |
| | V10 | The depart watch keeps the first replacement it admitted; a different replacement later passes without its own readiness check (`depart_watch`, `:2264-2278`) | The admitted replacement's iid is journaled; any later change to the set of new members is a failed probe (`members`) | Found in the build's Task 9 review (Astra, 2026-11-10); completion must describe the replacement actually admitted | |
| | V11 | After the terminate check, any `desired` or `minimum` below N is raised again (`:2248-2255`), so an outside reduction after the restore launches capacity | Once a fresh read shows a restore reached N, a later value below N is a failed probe (`desired_changed`); only an unanswered restore is retried | Same review; H4 forbids the tool from raising capacity it already restored | |
| | V12 | `refuse_while_moving` is skipped once any `exit-intent` exists (`:1828`), though that row is written before dispatch and dispatch can be refused or cut | Before every ExitStandby of a failed drain's member the drain check runs on the status the request acts on, whatever earlier intents exist | Branch review round 1 (Astra P1, 2026-11-10): the r2 cut must hold on resume | |
| +| V13 | Under DR-4, `roll` prints the rule ("Replace only lock-free members") and goes on: Standby, then apply, which restarts the edge with no drain | Under DR-4, `roll` refuses up front when a lock names the member: it runs the lock sweep (`locks_naming_member`) immediately before the first group write and closes `floor-refused` with no group write (`floor_refused`, then `lock_held`; `floor_config` without `data_bucket` or `data_prefix`; a sweep that cannot read refuses too). A resumed process sweeps again before the next write that leads to Standby, whatever intents the journal holds (an intent is written before dispatch); a finding then restores a lowered minimum and closes `lock-refused`. It re-checks immediately before the mutation, after Standby and the permit: a lock or a failed sweep returns the member unchanged, revokes the permit and closes `lock-refused` | Dev W2 2026-11-10 restarted a lease-holding member without a drain (8a3d302 P1) | |
| Not deviations, recorded so nobody "fixes" them in the port: the drain-rerun |
| backoff and the TakeHost `wake_timeout` follow-ups from the held build stay |
diff --git a/internal/grouproll/dr4.go b/internal/grouproll/dr4.go| new file mode 100644 |
| index 000000000..a41314791 |
| --- /dev/null |
| +++ b/internal/grouproll/dr4.go |
| @@ -0,0 +1,148 @@ |
| +package grouproll |
| + |
| +import ( |
| + "context" |
| + "strings" |
| +) |
| + |
| +// The DR-4 lock rule for a roll (group roll verb spec V13). Under DR-4 a |
| +// roll restarts the member's edge with no drain, so only a member no lock |
| +// names may roll ("Replace only lock-free members"). The script printed |
| +// the rule and went on; the Go verb runs the departures' lock sweep |
| +// (locksNamingMember) twice: |
| +// |
| +// - up front, immediately before the first group write: a lock naming |
| +// the member, a config without data_bucket or data_prefix, or a sweep |
| +// that cannot read closes the transaction floor-refused with no group |
| +// write, as a preflight refusal closes. A resumed process sweeps again |
| +// before the next write that leads to Standby (lower-minimum or |
| +// enter), whatever intents the journal holds: an intent is written |
| +// before dispatch. A finding then sends no further write except the |
| +// restore of a minimum the group shows lowered, and closes |
| +// lock-refused; |
| +// - again immediately before the action, with the member in Standby and |
| +// the permit granted (the member may have taken a lease in between): |
| +// the same findings journal lock-refused and stop the mutation, and |
| +// the member returns unchanged through the failed drain's return (the |
| +// roll's return executor, chosen by Classify), which revokes the |
| +// permit, restores the shape and closes the transaction lock-refused. |
| +// |
| +// The drain rule is unchanged: H5 (preAction) covers it. |
| + |
| +// dr4Applies: this transaction is a roll under DR-4 (the probe and the |
| +// departures never reach here with a DR-4 rule to act on). |
| +func (e *Engine) dr4Applies() bool { |
| + return !e.probe && e.kind() == "roll" && e.rule() == "dr4" && !e.seams.skipDR4Locks |
| +} |
| + |
| +// dr4Sweep is locksNamingMember, refusing floor_config when the config |
| +// cannot name the data bucket and prefix to sweep: never roll blind. |
| +func (e *Engine) dr4Sweep(ctx context.Context) ([]string, error) { |
| + if e.c.DataBucket == nil || e.c.DataPrefix == nil { |
| + return nil, refuse("floor_config") |
| + } |
| + return e.locksNamingMember(ctx) |
| +} |
| + |
| +// lockHeld is the lock_held refusal for the hosts (the first 20, as the |
| +// H5 check names them). |
| +func lockHeld(held []string) error { |
| + if len(held) > 20 { |
| + held = held[:20] |
| + } |
| + return refuse("lock_held", "hosts", strings.Join(held, ", ")) |
| +} |
| + |
| +// dr4BeforeStandby is the sweep before a write that leads to Standby; g |
| +// is the group read Classify chose the write from (the member serving, |
| +// desired N). It returns nil when the member is lock free, and this |
| +// process does not sweep again before Standby. Otherwise it closes the |
| +// transaction, says the floor refusal and returns the finding (lock_held, |
| +// floor_config, or the sweep's own refusal): |
| +// |
| +// - floor-refused when the journal holds no group write intent; |
| +// - lock-refused when it does (a write that may have been sent). If g |
| +// shows the minimum lowered, the roll's own minimum call restores it |
| +// first; when that call fails the transaction stays open, and resume |
| +// sweeps and restores again. |
| +// |
| +// A journal failure or an interrupt is returned as itself and leaves the |
| +// transaction open. |
| +func (e *Engine) dr4BeforeStandby(ctx context.Context, g snapshotView) error { |
| + held, err := e.dr4Sweep(ctx) |
| + if err != nil && !refusalOrUncertain(err) { |
| + return err |
| + } |
| + if err == nil { |
| + if len(held) == 0 { |
| + e.dr4Clear = true |
| + return nil |
| + } |
| + err = lockHeld(held) |
| + } |
| + outcome := "floor-refused" |
| + if e.has("intent", map[string]any{"op": "minimum"}) || e.has("intent", map[string]any{"op": "enter"}) { |
| + outcome = "lock-refused" |
| + if n := e.hInt("n"); g.View.Minimum != n { |
| + if _, perr := e.event("phase", map[string]any{"phase": "restore-minimum"}); perr != nil { |
| + return perr |
| + } |
| + if serr := e.setMinimum(ctx, n); serr != nil { |
| + return serr |
| + } |
| + } |
| + } |
| + if _, jerr := e.event("done", map[string]any{"outcome": outcome, "reason": reasonOf(err)}); jerr != nil { |
| + return jerr |
| + } |
| + if ferr := e.s.Finish(); ferr != nil { |
| + return ferr |
| + } |
| + e.say("floor", Text("floor_refused")) |
| + return err |
| +} |
| + |
| +// dr4PreAction is the second sweep, immediately before the action. A |
| +// finding journals lock-refused (its reason, and the hosts when locks |
| +// named the member), says it, and stops lock-refused; the caller returns |
| +// the member unchanged. |
| +func (e *Engine) dr4PreAction(ctx context.Context) error { |
| + held, err := e.dr4Sweep(ctx) |
| + if err != nil && !refusalOrUncertain(err) { |
| + return err |
| + } |
| + if err == nil && len(held) == 0 { |
| + return nil |
| + } |
| + row := map[string]any{"hosts": nil} |
| + if err == nil { |
| + err = lockHeld(held) |
| + hosts := make([]any, len(held)) |
| + for i, h := range held { |
| + hosts[i] = h |
| + } |
| + row["hosts"] = hosts |
| + } |
| + row["reason"] = reasonOf(err) |
| + if _, jerr := e.event("lock-refused", row); jerr != nil { |
| + return jerr |
| + } |
| + e.say("ALERT", reasonOf(err)) |
| + return stopped("lock-refused", "floor_refused") |
| +} |
| + |
| +// lockRefusal is the refusal a lock-refused transaction closes with: |
| +// lock_held naming the hosts, or floor_refused when the sweep could not |
| +// read (its reason was said when it was journaled). |
| +func (e *Engine) lockRefusal() error { |
| + row, _ := e.last("lock-refused", nil) |
| + raw, _ := row["hosts"].([]any) |
| + if len(raw) == 0 { |
| + return refuse("floor_refused") |
| + } |
| + held := make([]string, len(raw)) |
| + for i, h := range raw { |
| + held[i] = pyStrOf(h) |
| + } |
| + return lockHeld(held) |
| +} |
diff --git a/internal/grouproll/dr4_test.go b/internal/grouproll/dr4_test.go| new file mode 100644 |
| index 000000000..8acf76714 |
| --- /dev/null |
| +++ b/internal/grouproll/dr4_test.go |
| @@ -0,0 +1,327 @@ |
| +//go:build linux || darwin |
| + |
| +package grouproll |
| + |
| +import ( |
| + "reflect" |
| + "strings" |
| + "testing" |
| +) |
| + |
| +// A roll under DR-4 (spec V13; dev W2 2026-11-10, agent manager 8a3d302 |
| +// P1): the member's edge restarts with no drain, so the roll must refuse |
| +// a member a lock names. The sweep runs up front, before any group write, |
| +// and again immediately before the permit's action. |
| + |
| +// mustClosedWithoutGroupWrite: the only write was prepare, the |
| +// transaction is closed with outcome, and the output said floor_refused. |
| +func (h *harness) mustClosedWithoutGroupWrite(outcome string) { |
| + h.t.Helper() |
| + f := h.f |
| + if !reflect.DeepEqual(f.writes, []string{"prepare"}) { |
| + h.t.Fatalf("writes %v, want only prepare", f.writes) |
| + } |
| + if f.minimum != 2 || f.desired != 2 || f.maximum != 2 || f.states[fakeIID] != "InService" { |
| + h.t.Fatalf("group %d %d %d, member %s", f.minimum, f.desired, f.maximum, f.states[fakeIID]) |
| + } |
| + if f.boxes[fakeIID]["binary_sha256"] != oldSHA { |
| + h.t.Fatalf("binary %v", f.boxes[fakeIID]["binary_sha256"]) |
| + } |
| + if h.activeTx() != "" { |
| + h.t.Fatalf("transaction %s still open", h.activeTx()) |
| + } |
| + if done, _ := h.txJournal(h.onlyTx()).Last("done", nil); done["outcome"] != outcome { |
| + h.t.Fatalf("done %v, want outcome %s", done, outcome) |
| + } |
| + if !strings.Contains(h.out.String(), Text("floor_refused")) { |
| + h.t.Fatalf("output lacks the floor refusal: %s", h.out.String()) |
| + } |
| + mustRetain(h.t, h) |
| +} |
| + |
| +func TestRollDR4RefusesLeaseHolder(t *testing.T) { |
| + for name, owner := range map[string]map[string]any{ |
| + "ref and iid": heldLock(ref(fakeIID), fakeIID), |
| + "another form": {"generation": int64(2), "expires_at": "2030-01-01T00:00:00Z", |
| + "owner": "legacy:" + fakeIID}, |
| + } { |
| + t.Run(name, func(t *testing.T) { |
| + h := newHarness(t, 2) |
| + h.f.locks["shop"] = owner |
| + h.f.locks["idle"] = nil |
| + err := h.runRoll() |
| + refusedWith(t, err, "lock_held") |
| + if !strings.Contains(err.Error(), "shop") || strings.Contains(err.Error(), "blog") { |
| + t.Fatalf("refusal %q, want the member's host only", err) |
| + } |
| + h.mustClosedWithoutGroupWrite("floor-refused") |
| + if floor, _ := h.txJournal(h.onlyTx()).Last("floor", nil); floor["rule"] != "dr4" { |
| + t.Fatalf("floor %v", floor) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +func TestRollDR4LockFreeProceeds(t *testing.T) { |
| + h := newHarness(t, 2) |
| + // A release marker naming the member and another box's lock both pass. |
| + h.f.locks["shop"] = heldMarker(ref(fakeIID)) |
| + if err := scenarioStandbyRollOrder(h); err != nil { |
| + t.Fatal(err) |
| + } |
| + if countOf(h.f.ops(), "lock_hosts") != 2 { |
| + t.Fatalf("lock sweeps %d, want 2 (up front and before apply): %v", countOf(h.f.ops(), "lock_hosts"), h.f.ops()) |
| + } |
| + for _, v := range []string{"drain", "edge-stop", "fence-clear"} { |
| + if countOf(h.f.writes, v) != 0 { |
| + t.Fatalf("%s under DR-4: %v", v, h.f.writes) |
| + } |
| + } |
| + j := h.txJournal(h.onlyTx()) |
| + if floor, _ := j.Last("floor", nil); floor["rule"] != "dr4" { |
| + t.Fatalf("floor %v", floor) |
| + } |
| + if done, _ := j.Last("done", nil); done["outcome"] != "returned" { |
| + t.Fatalf("done %v", done) |
| + } |
| +} |
| + |
| +func TestRollDR4MissingDataConfigRefuses(t *testing.T) { |
| + for _, key := range []string{"data_bucket", "data_prefix"} { |
| + t.Run(key, func(t *testing.T) { |
| + h := newHarnessWith(t, stateRoot(t), 2, func(c *Config) { |
| + if key == "data_bucket" { |
| + c.DataBucket = nil |
| + } else { |
| + c.DataPrefix = nil |
| + } |
| + }) |
| + refusedWith(t, h.runRoll(), "floor_config") |
| + if countOf(h.f.ops(), "lock_hosts") != 0 { |
| + t.Fatalf("swept without the config: %v", h.f.ops()) |
| + } |
| + h.mustClosedWithoutGroupWrite("floor-refused") |
| + }) |
| + } |
| +} |
| + |
| +func TestRollDR4SweepErrorRefuses(t *testing.T) { |
| + cases := map[string]struct { |
| + op string |
| + fail error |
| + }{ |
| + "listing uncertain": {"lock_hosts", Uncertain{Key: "api"}}, |
| + "lock read refused": {"lock_get", Refusal{Key: "api"}}, |
| + } |
| + for name, c := range cases { |
| + t.Run(name, func(t *testing.T) { |
| + h := newHarness(t, 2) |
| + h.f.before = func(op string, _ map[string]any) error { |
| + if op == c.op { |
| + return c.fail |
| + } |
| + return nil |
| + } |
| + err := h.runRoll() |
| + if !refusalOrUncertain(err) { |
| + t.Fatalf("err = %v, want the sweep's refusal", err) |
| + } |
| + h.mustClosedWithoutGroupWrite("floor-refused") |
| + }) |
| + } |
| + t.Run("member names another data bucket", func(t *testing.T) { |
| + h := newHarness(t, 2) |
| + other := "other-bucket" |
| + h.c.DataBucket = &other |
| + h.f.c.DataBucket = &other |
| + refusedWith(t, h.runRoll(), "data_bucket_mismatch") |
| + h.mustClosedWithoutGroupWrite("floor-refused") |
| + }) |
| +} |
| + |
| +// A lease taken between the up-front sweep and the action: the second |
| +// sweep, after Standby and the permit, finds it. The member returns |
| +// unchanged (no apply), the permit is revoked, the shape is restored and |
| +// the transaction closes refusing with lock_held. |
| +func TestRollDR4LeaseAppearsBeforeApply(t *testing.T) { |
| + h := newHarness(t, 2) |
| + f := h.f |
| + f.after = func(name string) { |
| + if name == "enter" { |
| + f.locks["shop"] = heldLock(ref(fakeIID), fakeIID) |
| + } |
| + } |
| + err := h.runRoll() |
| + refusedWith(t, err, "lock_held") |
| + if !strings.Contains(err.Error(), "shop") { |
| + t.Fatalf("refusal %q lacks the host", err) |
| + } |
| + want := []string{"prepare", "minimum", "enter", "permit", "exit", "minimum", "revoke"} |
| + if !reflect.DeepEqual(f.writes, want) { |
| + t.Fatalf("writes %v, want %v", f.writes, want) |
| + } |
| + if f.boxes[fakeIID]["binary_sha256"] != oldSHA || f.states[fakeIID] != "InService" { |
| + t.Fatalf("member %v %s", f.boxes[fakeIID]["binary_sha256"], f.states[fakeIID]) |
| + } |
| + if f.minimum != 2 || f.desired != 2 || f.maximum != 2 { |
| + t.Fatalf("shape %d %d %d", f.minimum, f.desired, f.maximum) |
| + } |
| + if f.permit(fakeIID)["state"] != "absent" { |
| + t.Fatalf("permit %v", f.permit(fakeIID)) |
| + } |
| + if h.activeTx() != "" { |
| + t.Fatalf("transaction %s still open", h.activeTx()) |
| + } |
| + j := h.txJournal(h.onlyTx()) |
| + if done, _ := j.Last("done", nil); done["outcome"] != "lock-refused" { |
| + t.Fatalf("done %v", done) |
| + } |
| + if _, ok := j.Last("lock-refused", nil); !ok { |
| + t.Fatal("no lock-refused row") |
| + } |
| + if strings.Contains(h.out.String(), "cancel-drain") { |
| + t.Fatalf("a DR-4 refusal printed the drain's instruction: %s", h.out.String()) |
| + } |
| + mustRetain(t, h) |
| + if _, ok := j.Last("drain-failed", nil); ok { |
| + t.Fatal("a DR-4 lock refusal journaled a failed drain") |
| + } |
| +} |
| + |
| +// A sweep that fails at the second check fails closed: no apply, the |
| +// member returns unchanged. |
| +func TestRollDR4SecondSweepErrorReturnsUnchanged(t *testing.T) { |
| + h := newHarness(t, 2) |
| + f := h.f |
| + entered := false |
| + f.after = func(name string) { entered = entered || name == "enter" } |
| + f.before = func(op string, _ map[string]any) error { |
| + if entered && op == "lock_hosts" { |
| + return Uncertain{Key: "api"} |
| + } |
| + return nil |
| + } |
| + refusedWith(t, h.runRoll(), "floor_refused") |
| + want := []string{"prepare", "minimum", "enter", "permit", "exit", "minimum", "revoke"} |
| + if !reflect.DeepEqual(f.writes, want) { |
| + t.Fatalf("writes %v, want %v", f.writes, want) |
| + } |
| + if f.boxes[fakeIID]["binary_sha256"] != oldSHA || h.activeTx() != "" { |
| + t.Fatalf("binary %v, active %q", f.boxes[fakeIID]["binary_sha256"], h.activeTx()) |
| + } |
| + if done, _ := h.txJournal(h.onlyTx()).Last("done", nil); done["outcome"] != "lock-refused" { |
| + t.Fatalf("done %v", done) |
| + } |
| + mustRetain(t, h) |
| +} |
| + |
| +// A cut after the floor row and before the first group write: resume |
| +// sweeps before it lowers the minimum. |
| +func TestRollDR4ResumeSweepsBeforeFirstGroupWrite(t *testing.T) { |
| + h := newHarness(t, 2) |
| + f := h.f |
| + f.before = func(op string, _ map[string]any) error { |
| + if op == "lock_hosts" { |
| + panic(fakeDeath{op}) |
| + } |
| + return nil |
| + } |
| + if !expectDeath(t, func() { h.runRoll() }) { |
| + t.Fatal("roll did not die at the sweep") |
| + } |
| + f.before = nil |
| + f.locks["shop"] = heldLock(ref(fakeIID), fakeIID) |
| + refusedWith(t, h.resume(), "lock_held") |
| + h.mustClosedWithoutGroupWrite("floor-refused") |
| +} |
| + |
| +// A cut after the permit: resume sweeps again before the action. |
| +func TestRollDR4ResumeAfterPermitSweepsAgain(t *testing.T) { |
| + h := newHarness(t, 2) |
| + f := h.f |
| + f.after = func(name string) { |
| + if name == "enter" { |
| + f.locks["shop"] = heldLock(ref(fakeIID), fakeIID) |
| + } |
| + if name == "permit" { |
| + panic(fakeDeath{name}) |
| + } |
| + } |
| + if !expectDeath(t, func() { h.runRoll() }) { |
| + t.Fatal("roll did not die at the permit") |
| + } |
| + f.after = nil |
| + refusedWith(t, h.resume(), "lock_held") |
| + if countOf(f.writes, "apply") != 0 { |
| + t.Fatalf("applied: %v", f.writes) |
| + } |
| +} |
| + |
| +// Astra R1 P2: a minimum intent is journaled before dispatch, so it alone |
| +// must not exempt the up-front sweep. Die after the intent row and before |
| +// the write is sent, let the member take a lease, resume: no group write |
| +// is sent and the roll refuses lock_held. |
| +func TestRollDR4ResumeAfterUnsentMinimumIntentSweeps(t *testing.T) { |
| + h := newHarness(t, 2) |
| + f := h.f |
| + f.before = func(op string, _ map[string]any) error { |
| + if op == "minimum" { |
| + panic(fakeDeath{op}) |
| + } |
| + return nil |
| + } |
| + if !expectDeath(t, func() { h.runRoll() }) { |
| + t.Fatal("roll did not die before the minimum write") |
| + } |
| + tx := h.activeTx() |
| + if _, ok := h.txJournal(tx).Last("intent", map[string]any{"op": "minimum"}); !ok { |
| + t.Fatal("no minimum intent row") |
| + } |
| + f.before = nil |
| + f.locks["shop"] = heldLock(ref(fakeIID), fakeIID) |
| + err := h.resume() |
| + refusedWith(t, err, "lock_held") |
| + if !reflect.DeepEqual(f.writes, []string{"prepare"}) { |
| + t.Fatalf("writes %v, want only prepare", f.writes) |
| + } |
| + if f.minimum != 2 || f.desired != 2 || f.states[fakeIID] != "InService" || h.activeTx() != "" { |
| + t.Fatalf("group %d %d %s, active %q", f.minimum, f.desired, f.states[fakeIID], h.activeTx()) |
| + } |
| + if done, _ := h.txJournal(tx).Last("done", nil); done["outcome"] != "lock-refused" { |
| + t.Fatalf("done %v", done) |
| + } |
| + mustRetain(t, h) |
| +} |
| + |
| +// The minimum write landed before the death: resume sweeps before |
| +// EnterStandby, refuses, and restores the minimum it lowered (the one |
| +// write it sends). |
| +func TestRollDR4ResumeAfterLoweredMinimumRestores(t *testing.T) { |
| + h := newHarness(t, 2) |
| + f := h.f |
| + f.after = func(name string) { |
| + if name == "minimum" { |
| + panic(fakeDeath{name}) |
| + } |
| + } |
| + if !expectDeath(t, func() { h.runRoll() }) { |
| + t.Fatal("roll did not die after the minimum write") |
| + } |
| + f.after = nil |
| + f.locks["shop"] = heldLock(ref(fakeIID), fakeIID) |
| + tx := h.activeTx() |
| + refusedWith(t, h.resume(), "lock_held") |
| + if want := []string{"prepare", "minimum", "minimum"}; !reflect.DeepEqual(f.writes, want) { |
| + t.Fatalf("writes %v, want %v", f.writes, want) |
| + } |
| + if f.minimum != 2 || f.desired != 2 || f.maximum != 2 || f.states[fakeIID] != "InService" { |
| + t.Fatalf("group %d %d %d %s", f.minimum, f.desired, f.maximum, f.states[fakeIID]) |
| + } |
| + if h.activeTx() != "" { |
| + t.Fatalf("transaction %s still open", h.activeTx()) |
| + } |
| + if done, _ := h.txJournal(tx).Last("done", nil); done["outcome"] != "lock-refused" { |
| + t.Fatalf("done %v", done) |
| + } |
| + mustRetain(t, h) |
| +} |
diff --git a/internal/grouproll/engine.go b/internal/grouproll/engine.go| index 614c938e6..a6c795c19 100644 |
| --- a/internal/grouproll/engine.go |
| +++ b/internal/grouproll/engine.go |
| @@ -67,6 +67,10 @@ type Engine struct { |
| // reconciled with the member's own membership row, the probe's |
| // identity checks, and only probe journals. |
| probe bool |
| + |
| + // dr4Clear: this process's DR-4 sweep before Standby found the member |
| + // lock free (dr4.go). In memory only, so every resume sweeps again. |
| + dr4Clear bool |
| } |
| // Caller is the provider's "who am I": the user id the provider's own |
diff --git a/internal/grouproll/fake_test.go b/internal/grouproll/fake_test.go| index 5382e95d8..b465620cb 100644 |
| --- a/internal/grouproll/fake_test.go |
| +++ b/internal/grouproll/fake_test.go |
| @@ -137,6 +137,13 @@ type fake struct { |
| // held is the planned handovers' provider and agent (the held |
| // branch's HeldFake); nil keeps the roll fake as it was. |
| held *heldFake |
| + |
| + // dataBucket and locks are the region's data bucket and its host |
| + // locks (host: its lock.json body; nil is no lock), which a DR-4 |
| + // roll's lock sweep reads (spec V13). The held fake's own pair |
| + // replaces them when it is set. |
| + dataBucket string |
| + locks map[string]any |
| } |
| // fixedEdges is a box outside the group: its ha_take and ha_handover |
| @@ -161,7 +168,9 @@ func newFake(t *testing.T, n int) *fake { |
| used: map[[2]string]bool{}, permitBodies: map[string]map[string]any{}, |
| publicationLag: 2 * time.Second, published: map[string]time.Time{}, |
| version: "v0.34.0", targetWarmup: 30 * time.Second, templateRelease: "v0.34.0", |
| - userID: "AIDAEXAMPLEOPERATOR", |
| + userID: "AIDAEXAMPLEOPERATOR", |
| + dataBucket: "example-bucket", |
| + locks: map[string]any{"blog": heldLock(ref(fakePeer), fakePeer)}, |
| } |
| f.order = []string{fakeIID, fakePeer} |
| for i := 2; i < n; i++ { |
| @@ -779,6 +788,14 @@ func (f *fake) session(iid, verb string, a BoxArgs) (any, error) { |
| func (f *fake) Bucket(name string) release.Store { return fakeStore{f: f, bucket: name} } |
| +// lockStore is the data bucket and its locks: the held fake's when set. |
| +func (f *fake) lockStore() (string, map[string]any) { |
| + if f.held != nil { |
| + return f.held.dataBucket, f.held.locks |
| + } |
| + return f.dataBucket, f.locks |
| +} |
| + |
| type fakeStore struct { |
| release.Store // nil: only Get is modelled |
| f *fake |
| @@ -790,7 +807,7 @@ type fakeStore struct { |
| // floor must skip. |
| func (s fakeStore) List(ctx context.Context, prefix string) ([]string, error) { |
| f := s.f |
| - if f.held != nil && s.bucket == f.held.dataBucket { |
| + if bucket, _ := f.lockStore(); s.bucket == bucket { |
| return s.lockList(prefix) |
| } |
| r, err := f.request("edges_list", map[string]any{"prefix": prefix}, func() (any, error) { |
| @@ -818,7 +835,7 @@ func (s fakeStore) List(ctx context.Context, prefix string) ([]string, error) { |
| func (s fakeStore) Get(ctx context.Context, key string) ([]byte, string, error) { |
| f := s.f |
| - if f.held != nil && s.bucket == f.held.dataBucket { |
| + if bucket, _ := f.lockStore(); s.bucket == bucket { |
| return s.lockGet(key) |
| } |
| if channel, ok := strings.CutPrefix(key, "control/system/router/"); ok { |
| @@ -986,6 +1003,10 @@ func newHarnessAt(t *testing.T, root string, n int) *harness { |
| func newHarnessWith(t *testing.T, root string, n int, configure func(c *Config)) *harness { |
| t.Helper() |
| f := newFake(t, n) |
| + // A deployment's data bucket and prefix, so a DR-4 roll can sweep the |
| + // locks (V13); configure may take them away again. |
| + prefix, bucket := "instances", f.dataBucket |
| + f.c.DataPrefix, f.c.DataBucket = &prefix, &bucket |
| if configure != nil { |
| configure(&f.c) |
| } |
| @@ -1428,12 +1449,13 @@ func (f *fake) heldSession(iid, verb string, a BoxArgs) (r any, err error, ok bo |
| func (s fakeStore) ListDirs(ctx context.Context, prefix string) ([]string, error) { |
| f := s.f |
| r, err := f.request("lock_hosts", map[string]any{"bucket": s.bucket, "prefix": prefix}, func() (any, error) { |
| - if f.held == nil || s.bucket != f.held.dataBucket || prefix != "instances/" { |
| + bucket, locks := f.lockStore() |
| + if s.bucket != bucket || prefix != "instances/" { |
| f.violate("lock listing of %s/%s", s.bucket, prefix) |
| return nil, Uncertain{Key: "api"} |
| } |
| var out []string |
| - for _, host := range sortedKeys(f.held.locks) { |
| + for _, host := range sortedKeys(locks) { |
| out = append(out, "instances/"+host+"/") |
| } |
| return out, nil |
| @@ -1460,7 +1482,7 @@ func (s fakeStore) lockList(prefix string) ([]string, error) { |
| f.violate("lock key listing of %s", prefix) |
| return nil, Uncertain{Key: "api"} |
| } |
| - if f.held.locks[host] == nil { |
| + if _, locks := f.lockStore(); locks[host] == nil { |
| return []string{}, nil |
| } |
| return []string{prefix}, nil |
| @@ -1474,11 +1496,12 @@ func (s fakeStore) lockList(prefix string) ([]string, error) { |
| func (s fakeStore) lockGet(key string) ([]byte, string, error) { |
| f := s.f |
| r, err := f.request("lock_get", map[string]any{"key": key}, func() (any, error) { |
| + _, locks := f.lockStore() |
| host, ok := lockHost(key) |
| - if !ok || f.held.locks[host] == nil { |
| + if !ok || locks[host] == nil { |
| return nil, os.ErrNotExist |
| } |
| - return json.Marshal(f.held.locks[host]) |
| + return json.Marshal(locks[host]) |
| }) |
| if err != nil { |
| return nil, "", err |
diff --git a/internal/grouproll/mutation_test.go b/internal/grouproll/mutation_test.go| index 96cba8e7c..c0b466547 100644 |
| --- a/internal/grouproll/mutation_test.go |
| +++ b/internal/grouproll/mutation_test.go |
| @@ -112,6 +112,26 @@ func TestRequiredMutations(t *testing.T) { |
| } |
| } |
| +// TestDR4LockMutation: a DR-4 roll that never sweeps the locks (the |
| +// script's behaviour, V13) restarts a lease-holding member, and the roll |
| +// simulation's apply audit catches it within 100 seeds. |
| +func TestDR4LockMutation(t *testing.T) { |
| + base := stateRoot(t) |
| + for seed := int64(0); seed < 100; seed++ { |
| + _, err := runSeedWith(t, base, seed, nil, func(h *harness) { h.seams.skipDR4Locks = true }) |
| + if err == nil { |
| + continue |
| + } |
| + first := strings.SplitN(strings.TrimPrefix(err.Error(), fmt.Sprintf("seed=%d: ", seed)), "\n", 2)[0] |
| + if first != "apply while a lock names the member under DR-4" { |
| + t.Fatalf("mutant failed on another audit: %v", err) |
| + } |
| + t.Logf("DR-4 lock mutation caught: seed %d: %s", seed, first) |
| + return |
| + } |
| + t.Fatal("skipping the DR-4 lock sweeps survived the simulation") |
| +} |
| + |
| // TestDepartMutations: the planned handovers' required mutants, each an |
| // executor seam, must fail the depart simulation's audits within 100 |
| // seeds, on the audit that names it. |
diff --git a/internal/grouproll/roll.go b/internal/grouproll/roll.go| index c38e5ab30..edcf5afe0 100644 |
| --- a/internal/grouproll/roll.go |
| +++ b/internal/grouproll/roll.go |
| @@ -30,7 +30,7 @@ var departKinds = map[string]bool{"replace": true, "remove": true} |
| // stop is one of the script's Refusal subclasses: a refusal that also |
| // says how the transaction stopped. The operator sees the refusal's text. |
| type stop struct { |
| - kind string // failed-probe, divergence-held, drain-failed, drain-moving |
| + kind string // failed-probe, divergence-held, drain-failed, drain-moving, lock-refused |
| r Refusal |
| } |
| @@ -65,6 +65,7 @@ type seams struct { |
| unparkUnknownDrain bool // unknown drain status passes the return |
| restoreDesiredEarly bool // desired restored before the terminate check |
| acceptDrainResult bool // a drain whose result is not ok passes |
| + skipDR4Locks bool // a DR-4 roll never sweeps the locks (V13) |
| // The probe's mutants (probe.go). |
| skipFreshness bool // ExitStandby on an observation of any age |
| @@ -389,9 +390,9 @@ func (e *Engine) beforeProcess() any { |
| return e.header["original_process"] |
| } |
| -// unchanged is a failed drain: the member returns as it was, with no |
| -// action run. |
| -func (e *Engine) unchanged() bool { return e.has("drain-failed", nil) } |
| +// unchanged is a failed drain, or a DR-4 roll's lock refusal before the |
| +// action (dr4.go): the member returns as it was, with no action run. |
| +func (e *Engine) unchanged() bool { return e.has("drain-failed", nil) || e.has("lock-refused", nil) } |
| // rule is the floor's rule for this transaction; dr4 until one is read. |
| func (e *Engine) rule() string { |
| @@ -664,7 +665,7 @@ func (e *Engine) decisionFacts(context string, group *snapshotView, timedOut boo |
| ActionVerified: e.has("box-action-verified", map[string]any{"action": e.action()}), |
| AlreadyRestored: e.has("rollback-requested", map[string]any{"already_restored": true}), |
| FloorChecked: e.kind() != "roll" || floorRead, |
| - DrainFailed: e.has("drain-failed", nil), |
| + DrainFailed: e.unchanged(), |
| Observed: group != nil, |
| N: n, |
| TimedOut: timedOut, |
| @@ -726,6 +727,17 @@ func (e *Engine) resume(ctx context.Context) error { |
| return e.s.Finish() |
| case "return": |
| return e.returnMember(ctx) |
| + case "lower-minimum", "enter": |
| + // V13: under DR-4 only a lock-free member rolls. Swept |
| + // immediately before the first group write, and again by a |
| + // resumed process before any write that leads to Standby: |
| + // an intent row is journaled before dispatch, so it proves |
| + // nothing about the member's locks. |
| + if e.dr4Applies() && !e.dr4Clear { |
| + if err := e.dr4BeforeStandby(ctx, *group); err != nil { |
| + return err |
| + } |
| + } |
| } |
| err = func() error { |
| switch d.Action { |
| @@ -839,8 +851,9 @@ func (e *Engine) resume(ctx context.Context) error { |
| }() |
| switch { |
| case err == nil: |
| - case isStop(err, "drain-failed"): |
| - // Recorded as drain-failed; classify now chooses the return. |
| + case isStop(err, "drain-failed"), isStop(err, "lock-refused"): |
| + // Recorded as drain-failed or lock-refused; classify now |
| + // chooses the return of the unchanged member. |
| group = nil |
| case refusalOrUncertain(err): |
| opErr = err |
| @@ -1044,6 +1057,12 @@ func (e *Engine) mutation(ctx context.Context) error { |
| return err |
| } |
| } |
| + if action == "apply" && e.dr4Applies() { |
| + // V13, immediately before the action: no lock names the member. |
| + if err := e.dr4PreAction(ctx); err != nil { |
| + return err |
| + } |
| + } |
| if _, err := e.event("phase", map[string]any{"phase": "mutation", "action": action}); err != nil { |
| return err |
| } |
| @@ -1109,7 +1128,7 @@ func (e *Engine) rollback(ctx context.Context, iid string) error { |
| if err := e.restoreHeader(); err != nil { |
| return err |
| } |
| - if e.kind() != "roll" || iid != e.hStr("iid") || e.has("exit-intent", nil) || e.has("drain-failed", nil) { |
| + if e.kind() != "roll" || iid != e.hStr("iid") || e.has("exit-intent", nil) || e.unchanged() { |
| return refuse("rollback_refused") |
| } |
| end := e.clock().Add(standbyWait) |
| @@ -1399,7 +1418,8 @@ func (e *Engine) refuseWhileMoving(status map[string]any) error { |
| // earlier exit-intent: the gate in front of every ExitStandby (spec r2 |
| // cut; the script skipped it once any exit-intent existed). |
| func (e *Engine) checkDrainBeforeExit(status map[string]any) error { |
| - if !e.unchanged() { |
| + // A DR-4 lock refusal ran no drain, so no move can be running. |
| + if !e.has("drain-failed", nil) { |
| return nil |
| } |
| d, ok := status["drain"].(map[string]any) |
| @@ -1422,7 +1442,8 @@ func (e *Engine) checkDrainBeforeExit(status map[string]any) error { |
| // finishReturn is the script's finish_return: lift the fence, revoke a |
| // remaining permit, record the outcome and close the transaction. A |
| // failed drain closes drain-failed and refuses with the cancel-drain |
| -// instruction. |
| +// instruction; a DR-4 lock refusal closes lock-refused and refuses with |
| +// what the second sweep found (V13). |
| func (e *Engine) finishReturn(ctx context.Context, ready *readiness) error { |
| if ready == nil { |
| return refuse("record") |
| @@ -1449,7 +1470,8 @@ func (e *Engine) finishReturn(ctx context.Context, ready *readiness) error { |
| return refuse("permit") |
| } |
| } |
| - failedDrain := e.unchanged() |
| + failedDrain := e.has("drain-failed", nil) |
| + lockRefused := e.has("lock-refused", nil) |
| if e.has("drained", nil) && !failedDrain { |
| if err := e.drainSummary(nil); err != nil { |
| return err |
| @@ -1459,6 +1481,8 @@ func (e *Engine) finishReturn(ctx context.Context, ready *readiness) error { |
| switch { |
| case failedDrain: |
| outcome = "drain-failed" |
| + case lockRefused: |
| + outcome = "lock-refused" |
| case e.has("failed-probe", nil): |
| outcome = "failed-probe-recovered" |
| } |
| @@ -1476,6 +1500,10 @@ func (e *Engine) finishReturn(ctx context.Context, ready *readiness) error { |
| e.say("ALERT", Text("drain_cancel", "config", e.ConfigPath, "iid", iid, "transaction", tx)) |
| return refuse("drain_failed") |
| } |
| + if lockRefused { |
| + e.say("floor", Text("floor_refused")) |
| + return e.lockRefusal() |
| + } |
| e.say("done", Text("done")) |
| return nil |
| } |
diff --git a/internal/grouproll/roll_test.go b/internal/grouproll/roll_test.go| index 64d4ef9b3..4200caf89 100644 |
| --- a/internal/grouproll/roll_test.go |
| +++ b/internal/grouproll/roll_test.go |
| @@ -267,9 +267,14 @@ func TestRollStandbyResume(t *testing.T) { |
| // finishes once it clears. |
| func scenarioStandbySharedOutage(h *harness) error { |
| f := h.f |
| + // The script started the outage at the permit. Under DR-4 the verb |
| + // reads the member's edges file again right before apply (V13), and an |
| + // unreadable sweep fails closed, so the outage starts at the apply it |
| + // follows: the member drops its admission as the script's did. |
| f.after = func(name string) { |
| - if name == "permit" { |
| - f.outage = true |
| + if name == "apply" { |
| + f.outage, f.admitted = true, false |
| + f.boxes[fakeIID]["health"] = map[string]any{"state": "unhealthy", "code": int64(503)} |
| } |
| } |
| start := f.now |
| @@ -1727,8 +1732,13 @@ func TestRollFsyncPrecedesProviderWrite(t *testing.T) { |
| h := newHarness(t, 2) |
| var trace []string |
| h.state.fsync = func(*os.File) error { trace = append(trace, "sync"); return nil } |
| + previous := "" |
| h.f.before = func(op string, _ map[string]any) error { |
| - if op != "caller" && (len(trace) == 0 || trace[len(trace)-1] != "sync") { |
| + // One journaled lock call is an exact-key listing, then its GET |
| + // (the DR-4 sweep, V13). |
| + within := op == "lock_get" && previous == "lock_list" |
| + previous = op |
| + if op != "caller" && !within && (len(trace) == 0 || trace[len(trace)-1] != "sync") { |
| t.Errorf("%s without a preceding fsync", op) |
| } |
| trace = append(trace, "api") |
diff --git a/internal/grouproll/sim_test.go b/internal/grouproll/sim_test.go| index c0a0f0431..b5a198c24 100644 |
| --- a/internal/grouproll/sim_test.go |
| +++ b/internal/grouproll/sim_test.go |
| @@ -59,6 +59,11 @@ type simulation struct { |
| // last journaled row of each kind, kept as rows become durable. |
| rows map[string]Row |
| forbidden []string // complete, desired or terminate calls seen |
| + // lock is the seed's DR-4 lock (V13): "" none, "before" a lock names |
| + // the member from the start, "minimum" one appears once the minimum |
| + // write is sent (after the first sweep, before Standby), "standby" one |
| + // appears once it enters Standby (between the two sweeps). |
| + lock string |
| } |
| // runSeed runs one seed and returns its coverage, or the first failed |
| @@ -66,6 +71,12 @@ type simulation struct { |
| // (nil is Classify); the audited wrapper always runs around it. Each seed |
| // gets its own state directory under base, removed afterwards. |
| func runSeed(t *testing.T, base string, seed int64, classify func(Facts) Decision) (coverage map[string]int, err error) { |
| + return runSeedWith(t, base, seed, classify, nil) |
| +} |
| + |
| +// runSeedWith is runSeed with mutate applied to the seed's harness before |
| +// it runs (the executor mutants). |
| +func runSeedWith(t *testing.T, base string, seed int64, classify func(Facts) Decision, mutate func(h *harness)) (coverage map[string]int, err error) { |
| if classify == nil { |
| classify = Classify |
| } |
| @@ -86,6 +97,23 @@ func runSeed(t *testing.T, base string, seed int64, classify func(Facts) Decisio |
| s.h.classify = s.decide |
| s.h.beforeEvent = func(kind string, _ map[string]any) { s.journalStep("before", kind, nil) } |
| s.h.afterEvent = func(kind string, row Row) { s.journalStep("after", kind, row) } |
| + // The lock draws from its own source, so each seed's chaos draws are |
| + // not shifted by it. |
| + switch rand.New(rand.NewSource(seed ^ 0x5eedd4)).Intn(8) { |
| + case 0: |
| + s.lock = "before" |
| + s.f.locks["shop"] = heldLock(ref(fakeIID), fakeIID) |
| + case 1: |
| + s.lock = "standby" |
| + case 2: |
| + s.lock = "minimum" |
| + } |
| + if s.lock != "" { |
| + s.coverage["lock:"+s.lock]++ |
| + } |
| + if mutate != nil { |
| + mutate(s.h) |
| + } |
| defer func() { |
| if r := recover(); r != nil { |
| f, ok := r.(simFailure) |
| @@ -134,9 +162,15 @@ func (s *simulation) journalStep(when, kind string, row Row) { |
| s.chaos = true |
| } |
| switch kind { |
| - case "failed-probe", "return-hook", "divergence-held", "done": |
| + case "failed-probe", "return-hook", "divergence-held", "done", "lock-refused": |
| s.trace = append(s.trace, "journal:"+kind) |
| } |
| + switch kind { |
| + case "lock-refused": |
| + s.coverage["lock-refused"]++ |
| + case "done": |
| + s.coverage[fmt.Sprintf("outcome:%v", row["outcome"])]++ |
| + } |
| } |
| s.audit(when + ":journal:" + kind) |
| s.maybeDie(when + ":journal:" + kind) |
| @@ -227,7 +261,10 @@ func (s *simulation) request(op string, args map[string]any, write bool, perform |
| } |
| if v := pyNumber(args["value"]); op == "minimum" && v != nil && *v == 2 { |
| s.check(!s.last("return-hook") && !s.last("divergence-hold"), "minimum restored in hold") |
| - s.check(f.states[fakeIID] == "InService" && f.tg[fakeIID] == "healthy" && f.admitted, |
| + // A DR-4 refusal before Standby restores the minimum of a member |
| + // that never left service (V13): only its state is required. |
| + neverLeft := countOf(f.writes, "enter") == 0 && f.states[fakeIID] == "InService" |
| + s.check(f.states[fakeIID] == "InService" && (neverLeft || f.tg[fakeIID] == "healthy" && f.admitted), |
| "minimum restored before readiness") |
| s.check(f.desired == 2, "minimum raised desired") |
| } |
| @@ -239,11 +276,19 @@ func (s *simulation) request(op string, args map[string]any, write bool, perform |
| s.forbidden = append(s.forbidden, op) |
| s.fail("forbidden provider write") |
| } |
| + if op == "session" && args["verb"] == "apply" { |
| + // V13: DR-4 restarts the edge with no drain. |
| + s.check(f.locks["shop"] == nil, "apply while a lock names the member under DR-4") |
| + } |
| oldDesired := f.desired |
| result, err := perform() |
| if err != nil { |
| return nil, err |
| } |
| + if (op == "enter" && s.lock == "standby") || (op == "minimum" && s.lock == "minimum") { |
| + // The member takes a lease after the first sweep. |
| + f.locks["shop"] = heldLock(ref(fakeIID), fakeIID) |
| + } |
| if op == "minimum" { |
| s.check(f.desired == oldDesired, "minimum raised desired") |
| } |
| @@ -415,6 +460,33 @@ func (s *simulation) run() map[string]int { |
| } |
| s.check(converged, "did not converge after fault injection stopped") |
| s.audit("end") |
| + outcome := s.rows["done"]["outcome"] |
| + if s.lock == "before" { |
| + // Refused up front: no group write, nothing to return. |
| + s.check(!s.active() && outcome == "floor-refused", "lock holder not refused up front") |
| + s.check(countOf(f.writes, "minimum") == 0 && countOf(f.writes, "enter") == 0, |
| + "group write before the DR-4 sweep") |
| + s.check(f.minimum == 2 && f.desired == 2 && f.maximum == 2 && f.states[fakeIID] == "InService", |
| + "DR-4 refusal changed the group") |
| + return s.coverage |
| + } |
| + if s.lock == "standby" || s.lock == "minimum" { |
| + s.check(countOf(f.writes, "apply") == 0 && f.boxes[fakeIID]["binary_sha256"] == oldSHA, |
| + "lease holder not returned unchanged") |
| + // Refused by the sweep before the action (a lock-refused row), or, |
| + // after a death before Standby, by a resumed process's sweep. |
| + s.check(s.last("lock-refused") || outcome == "lock-refused", "lease after the first sweep not refused") |
| + if !f.hook { |
| + s.check(outcome == "lock-refused", "lease after the first sweep not closed lock-refused") |
| + } |
| + if outcome == "lock-refused" && countOf(f.writes, "enter") == 0 { |
| + // Refused before Standby: the member never left, so no |
| + // return (and no hook) follows; the minimum is restored. |
| + s.check(!s.active() && f.minimum == 2 && f.desired == 2 && f.states[fakeIID] == "InService", |
| + "DR-4 refusal before Standby left the group changed") |
| + return s.coverage |
| + } |
| + } |
| if f.hook { |
| if s.providerReturns { |
| s.check(s.last("divergence-held") && f.states[fakeIID] == "Standby", "hook return did not hold") |
| @@ -481,7 +553,8 @@ func TestSeededSimulation(t *testing.T) { |
| if count >= 50 { |
| for _, event := range []string{"describe-error", "diverged", "failed", "provider-return", "death", "resume", |
| "admission-drop", "admission-recovery", "loss:exit", "phase:ReturnHeld", "phase:Returning", |
| - "phase:Serving", "death:before-api", "death:after-api"} { |
| + "phase:Serving", "death:before-api", "death:after-api", "lock:before", "lock:standby", "lock:minimum", |
| + "lock-refused", "outcome:floor-refused", "outcome:lock-refused"} { |
| if coverage[event] == 0 { |
| t.Errorf("coverage %s = 0", event) |
| } |
diff --git a/internal/grouproll/testdata/parity-ledger.tsv b/internal/grouproll/testdata/parity-ledger.tsv| index 89304e31f..b62999077 100644 |
| --- a/internal/grouproll/testdata/parity-ledger.tsv |
| +++ b/internal/grouproll/testdata/parity-ledger.tsv |
| @@ -24,7 +24,7 @@ roll StandbyTests.test_standby_roll_order ported TestRollStandbyOrder |
| roll StandbyTests.test_standby_response_loss ported TestRollStandbyResponseLoss |
| roll StandbyTests.test_standby_resume ported TestRollStandbyResume |
| roll StandbyTests.test_standby_resume_before_every_write ported TestRollStandbyResume the before=true cases |
| -roll StandbyTests.test_standby_shared_outage ported TestRollStandbySharedOutage |
| +roll StandbyTests.test_standby_shared_outage ported TestRollStandbySharedOutage V13: the outage starts at the apply, not the permit: the second DR-4 lock sweep reads the member's edges file before apply and fails closed |
| roll StandbyTests.test_standby_exit_pending_wait ported TestRollHookIsDivergenceWithoutCompletion |
| roll StandbyTests.test_standby_exit_pending_wait_resume_and_loss ported TestRollExitPendingWaitResumeAndLoss |
| roll StandbyTests.test_standby_exit_pending_wait_admission_loss ported TestRollDefaultAbandonAndResumeStayFailed |
| @@ -102,7 +102,7 @@ roll AdapterTests.test_session_pty_captures_noninteractive_output ported groupro |
| roll AdapterTests.test_session_pty_stdin_is_terminal_without_eof ported grouprollaws.TestSessionReadsFrame |
| roll AdapterTests.test_session_pty_plugin_returns_frames_without_stdin_eof ported grouprollaws.TestSessionReadsFrame |
| roll AdapterTests.test_session_pty_timeout ported grouprollaws.TestSessionBoundKillsGroup grouprollaws.TestSessionLeaderExitsBeforeOutputEnds |
| -roll AdapterTests.test_fsync_precedes_provider_write ported TestRollFsyncPrecedesProviderWrite |
| +roll AdapterTests.test_fsync_precedes_provider_write ported TestRollFsyncPrecedesProviderWrite V13: a DR-4 lock read is one journaled call of two requests (the exact-key listing, then its GET) |
| roll RoundThreeTests.test_box_action_time_does_not_consume_readiness_wait ported TestRollBoxActionTimeDoesNotConsumeReadinessWait |
| roll RoundThreeTests.test_rollback_waits_for_cut_apply_lock_before_inspecting_digest ported TestRollRollbackWaitsForStatus |
| roll ClassifyTests.test_table_hook_record_cut ported TestClassifyGolden the recorder ran over this row (testdata/golden/classify.jsonl) |
| @@ -215,7 +215,7 @@ held RemoveMinimumTests.test_remove_needs_two_survivors ported TestDepartRemoveN |
| held DrainedRollTests.test_roll_drains_before_apply_and_lifts_fence_after_exit ported TestDrainedRollDrainsBeforeApplyAndLiftsFenceAfterExit |
| held DrainedRollTests.test_roll_failed_drain_returns_unchanged ported TestDrainedRollFailedDrainReturnsUnchanged |
| held DrainedRollTests.test_roll_lock_after_permit_returns_and_revokes ported TestDrainedRollLockAfterPermitReturnsAndRevokes |
| -held DrainedRollTests.test_roll_below_floor_uses_dr4_and_says_so ported TestDrainedRollBelowFloorUsesDR4AndSaysSo |
| +held DrainedRollTests.test_roll_below_floor_uses_dr4_and_says_so ported TestDrainedRollBelowFloorUsesDR4AndSaysSo TestRollDR4LockFreeProceeds TestRollDR4RefusesLeaseHolder V13: the member is lock free; a lock naming it refuses the roll |
| held DrainedRollTests.test_roll_to_release_below_floor_uses_dr4 ported TestDrainedRollToReleaseBelowFloorUsesDR4 TestFloorRollToReleaseBelowFloorUsesDR4 |
| held DrainedRollTests.test_drained_roll_resumes_after_every_write ported TestDrainedRollResumesAfterEveryWrite |
| held TerminateDecisionTests.test_every_combination ported TestTerminateEveryCombination the 92,169-row grid against the ported oracle (not recorded into golden) |
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv| index d017240d7..32b36c4fa 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-chain.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-chain.tsv |
| @@ -155,4 +155,5 @@ plan14-root-reads-gvisor-probe-diag.tsv a9ae6b238b6b2e177be1f9c7ae06ea0f24477e4e |
| plan14-root-reads-deploy-happy-path.tsv a9ae6b238b6b2e177be1f9c7ae06ea0f24477e4eb0e58abda63f4b7337dbe3ee |
| plan14-root-reads-held-move-speed.tsv 837f27a6b7b6ed272f8c68aca07650fa32cf3ec92ce28bf9d812a4282eeb0b58 |
| plan14-root-reads-litestream-quiet-802.tsv 6d3ea7fccce1a7f4bc507b6eb8d368ed0b62f83022504aa04c7684c72c93aa9a |
| +plan14-root-reads-group-roll-dr4-lock-refusal.tsv 6d3ea7fccce1a7f4bc507b6eb8d368ed0b62f83022504aa04c7684c72c93aa9a |
| plan14-root-reads-held-floor-capability.tsv b60c83f8ba4311222174284420b5327e92002882b4a1c6f291e74e69234c6f59 |
diff --git a/internal/provision/testdata/plan14-root-reads-group-roll-dr4-lock-refusal.tsv b/internal/provision/testdata/plan14-root-reads-group-roll-dr4-lock-refusal.tsv| new file mode 100644 |
| index 000000000..28ae88dd6 |
| --- /dev/null |
| +++ b/internal/provision/testdata/plan14-root-reads-group-roll-dr4-lock-refusal.tsv |
| @@ -0,0 +1,3 @@ |
| +# Census overlay group-roll-dr4-lock-refusal, written by census-propose (#369). census-ruling-group-roll-dr4-lock-refusal, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-group-roll-dr4-lock-refusal.md. |
| +# 0 body, 0 sites, 1 envelope: each changed unit re-frozen at its existing disposition with its claim appended. |
| +@coverage internal/grouproll a71ede194e6d365ef847ff4d8bda80dbb50942d53b921c224fe78ca08c2a8489 |
diff --git a/internal/provision/testdata/plan14-root-reads-held-floor-capability.tsv b/internal/provision/testdata/plan14-root-reads-held-floor-capability.tsv| index 5c4d24f17..1c8e6c033 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-held-floor-capability.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-held-floor-capability.tsv |
| @@ -16,5 +16,5 @@ internal/host/hadrain_socket.go drainDriver.handler legacy accepted-legacy accep |
| internal/edge/hadrain.go Edge.AskDrainSeen legacy accepted-legacy accepted-legacy;rev3=census-ruling-held-floor-capability;basis=held floor capability (region HA §25.4 step 1, agent manager 8a3d302, 2026-11-10): the ask gains a nonce, 16 bytes from crypto/rand in lower-case hex, inside the already signed body; the answer must carry sig, an HMAC-SHA256 under either mirrored mesh key over a distinct domain, the peer, this box, the transaction, the phase, the id, that nonce and the seen value, verified in constant time; an unsigned, wrongly signed or other-ask answer is an error (not acknowledged), never seen. Astra r2 F2.1: when the peer (from the verb's list) has no edges file in this edge's fold, it runs the existing refreshHostsNow once (the receivers' own fold read on an ask: a LIST and GETs of control/edges/ in the deployment bucket, as the agent user, bounded by haDrainRefreshTimeout) and retries controlTarget; still absent, the ask fails naming the peer. No new read kind, path or record; a drain only fails more often, never proceeds on less. file:Read@1398 7f634d395f69292d2fbb6012a65f2cec0e04ae053943052c4ff17e1249f2bd1b |
| @coverage infra/modules/region-group-operator-document bc02dd037f5f04854964d89efcfdb72a5b10221303e346c61e62e7f85a2f0494 |
| @coverage internal/edge 9c3f3a915e490691be4eb79789067ed1e160f5009990f70b94189c6e04ed7fb4 |
| -@coverage internal/grouproll 3c5596626935f53896d8f9a7c6a019a8025165927d6b5b08f19451be8c53acb0 |
| +@coverage internal/grouproll 9a567994d5e6197e84024b628e9556e09a021a04a1644a5d6e1f97912c1f93b4 |
| @coverage internal/host 00baab19b9ed34b246421999024d672cadad9dfbd4a760e7a596b1de6fd00686 |
diff --git a/region_ha_boundary_test.go b/region_ha_boundary_test.go| index 79007ee94..4255ec850 100644 |
| --- a/region_ha_boundary_test.go |
| +++ b/region_ha_boundary_test.go |
| @@ -57,6 +57,7 @@ var regionHACoreFiles = []string{ |
| "internal/grouproll/floor.go", |
| "internal/grouproll/roll.go", |
| "internal/grouproll/depart.go", |
| + "internal/grouproll/dr4.go", |
| "internal/grouproll/probe.go", |
| "internal/grouproll/testdata/remotecommand/main.go", |
| "internal/release/systemlookup.go", |