grouproll: a resumed DR-4 roll sweeps before every pre-Standby write
Astra R1 P2: a minimum intent is journaled before dispatch, so it must not exempt the up-front sweep. A resumed process now sweeps before lower-minimum or enter until one sweep in that process finds the member lock free. A finding with a group write intent restores a lowered minimum through the roll's minimum call and closes lock-refused; with none it closes floor-refused as before. Regressions for a death before and after the minimum dispatch; the simulation also adds a lock at the minimum write.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs/superpowers/specs/2026-11-09-group-roll-verb-design.md+1 −1internal/grouproll/dr4.go+36 −8internal/grouproll/dr4_test.go+69 −0internal/grouproll/engine.go+4 −0internal/grouproll/roll.go+7 −5internal/grouproll/sim_test.go+23 −8
Intent
<task-notification> <task-id>a8d6b9fd55a05cb9f</task-id> <tool-use-id>toolu_01LbPZrB7NSm3p48inJ91Ywo</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/669506ff-23ec-45f1-9035-1d29593f2c37/tasks/a8d6b9fd55a05cb9f.output</output-file> <status>completed</status> <summary>Agent "P1 fix: DR-4 roll lock refusal" 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. `roll` under DR-4 now refuses a member that holds a lock. Every gate passes. Four commits on `group-roll-dr4-lock-refusal`, not pushed: 95514fb9 (the fix), e5588c18 (simulation and mutant), 29d23bd5 (spec V13 and ledger notes), 7d837481 (census re-pin). **Behaviour:** Under DR-4, the lock sweep runs just before the first group write. A lock naming the member, a config without `data_bucket` or `data_prefix` (`floor_config`), or a sweep that can't read closes the transaction `floor-refused` with no group write; a lock prints `floor_refused` and refuses with `lock_held`. A second sweep runs after Standby and the permit, just before apply. If it finds a lock or fails, the member goes back unchanged and the transaction closes `lock-refused`. **Tests:** 8 new tests in `internal/grouproll/dr4_test.go`, all red before the change and green after. The simulation now gives a quarter of seeds a lock and audits every apply. The skip-sweep mutant is caught at seed 3. Package tests, vet, gofmt, the darwin and windows builds, the root `TestCLIProjection|TestRegionHA` run and the census all pass. Three existing tests needed small updates, recorded under V13 in the ledger. **Decisions:** - The second check reuses the failed-drain return path but writes its own `lock-refused` row, so the drain-only steps (cancel-drain, the drain check before exit) don't apply. - The up-front sweep sits at `lower-minimum`, so a resume after a crash still sweeps first. - Rollback is not re-swept, matching the drain rule's H5 check, which only covers apply. - No new strings. **Concerns:** - Live group configs need `data_bucket` and `data_prefix`, or every DR-4 roll refuses. Check dev and flagship before W1-W5. - A box below the floor that doesn't publish `data_bucket` in its edges file will be refused. - The census overlay still needs a reviewer's verdict on #280. Whichever of this branch and `held-floor-capability` lands second must re-run `census-propose`. - Every commit printed a `packed-refs.lock` warning. The lock file is an empty one from 11:02 that I didn't create, and the commits landed correctly. Full report: `/home/paulca/.cache/group-roll-go/dr4-fix-report.md`</result> <usage><subagent_tokens>222391</subagent_tokens><tool_uses>67</tool_uses><duration_ms>2152884</duration_ms></usage> </task-notification>
<task-notification> <task-id>bhze24033</task-id> <tool-use-id>toolu_016d2VWZ4AxNfZcnsVANoV5D</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/669506ff-23ec-45f1-9035-1d29593f2c37/tasks/bhze24033.output</output-file> <status>completed</status> <summary>Background command "Wait for the Astra review" completed (exit code 0)</summary> </task-notification>
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 396d5261a..0d0d2c484 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 |
| @@ -368,7 +368,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). 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) | |
| +| 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| index 0e6db4aa1..a41314791 100644 |
| --- a/internal/grouproll/dr4.go |
| +++ b/internal/grouproll/dr4.go |
| @@ -14,7 +14,12 @@ import ( |
| // - 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; |
| +// 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 |
| @@ -48,23 +53,46 @@ func lockHeld(held []string) error { |
| return refuse("lock_held", "hosts", strings.Join(held, ", ")) |
| } |
| -// dr4UpFront is the first sweep. It returns nil when the member is lock |
| -// free; otherwise it closes the transaction floor-refused, says the floor |
| -// refusal and returns the finding (lock_held, floor_config, or the |
| -// sweep's own refusal). A journal failure or an interrupt is returned as |
| -// itself and leaves the transaction open. |
| -func (e *Engine) dr4UpFront(ctx context.Context) error { |
| +// 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) |
| } |
| - if _, jerr := e.event("done", map[string]any{"outcome": "floor-refused", "reason": reasonOf(err)}); jerr != nil { |
| + 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 { |
diff --git a/internal/grouproll/dr4_test.go b/internal/grouproll/dr4_test.go| index 03433ba9f..8acf76714 100644 |
| --- a/internal/grouproll/dr4_test.go |
| +++ b/internal/grouproll/dr4_test.go |
| @@ -256,3 +256,72 @@ func TestRollDR4ResumeAfterPermitSweepsAgain(t *testing.T) { |
| 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 3093c4148..68a4cbef6 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/roll.go b/internal/grouproll/roll.go| index 3d410d9ba..edcf5afe0 100644 |
| --- a/internal/grouproll/roll.go |
| +++ b/internal/grouproll/roll.go |
| @@ -727,12 +727,14 @@ func (e *Engine) resume(ctx context.Context) error { |
| return e.s.Finish() |
| case "return": |
| return e.returnMember(ctx) |
| - case "lower-minimum": |
| + case "lower-minimum", "enter": |
| // V13: under DR-4 only a lock-free member rolls. Swept |
| - // immediately before the first group write, so a refusal |
| - // closes the transaction with none. |
| - if e.dr4Applies() && !facts.MinimumIntent { |
| - if err := e.dr4UpFront(ctx); err != nil { |
| + // 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 |
| } |
| } |
diff --git a/internal/grouproll/sim_test.go b/internal/grouproll/sim_test.go| index 3baa26ca1..b5a198c24 100644 |
| --- a/internal/grouproll/sim_test.go |
| +++ b/internal/grouproll/sim_test.go |
| @@ -60,8 +60,9 @@ type simulation struct { |
| 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, "standby" one appears once it enters |
| - // Standby (between the two sweeps). |
| + // 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 |
| } |
| @@ -104,6 +105,8 @@ func runSeedWith(t *testing.T, base string, seed int64, classify func(Facts) Dec |
| 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]++ |
| @@ -258,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") |
| } |
| @@ -279,7 +285,7 @@ func (s *simulation) request(op string, args map[string]any, write bool, perform |
| if err != nil { |
| return nil, err |
| } |
| - if op == "enter" && s.lock == "standby" { |
| + 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) |
| } |
| @@ -464,12 +470,21 @@ func (s *simulation) run() map[string]int { |
| "DR-4 refusal changed the group") |
| return s.coverage |
| } |
| - if s.lock == "standby" { |
| + 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") |
| - s.check(s.last("lock-refused"), "lease after Standby not refused") |
| + // 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 Standby not closed lock-refused") |
| + 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 { |
| @@ -538,7 +553,7 @@ 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", "lock:before", "lock:standby", |
| + "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) |