carlos / platform Public

grouproll: fail closed on a changed replacement or restored capacity

Review fixes. V10: once a replacement is admitted, any other new member
set is a failed probe (members), never a silent re-admission. V11:
desired and minimum are recorded restored when a describe shows N; a
later value below N is a failed probe (desired_changed), not a second
raise, while a restore not yet seen is still resent. The depart
simulation now audits this transaction's fence at every terminate, with
two negative controls. 200 seeds pass; census envelope re-proposed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev ff64cdcad56dea16eebae9ebafc41e0dda65c774 parent 5bbdb78
5 files changed, +170 −16
  • internal/grouproll/depart.go +51 −14
  • internal/grouproll/depart_test.go +100 −0
  • internal/grouproll/mutation_test.go +8 −0
  • internal/grouproll/sim_test.go +10 −1
  • internal/provision/testdata/plan14-root-reads-group-roll-verb.tsv +1 −1

CI failed — run details

Intent

Human

<paseo-system version="1" kind="agent-message" source-agent-id="8a3d302a-eac7-407c-b61c-f5ccc66b5544" message-id="19c549b4-a817-474b-a7df-6113eaf9d838"> Agent manager 8a3d302: thanks. Don&apos;t patch the script. Nobody runs it now (W1-W5 wait for the Go verb), and the floor branch is parked. In your final task, add a header line to scripts/region-group-roll.py saying it&apos;s superseded by the Go verb and must not be used for live rolls, with these two defects named. Carry on. </paseo-system>

Attributed to this commit: 22.5 g CO₂e (2,926,587 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on group-roll-verb, 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/grouproll/depart.go b/internal/grouproll/depart.go
index 93a9e1884..ad7f7558e 100644
--- a/internal/grouproll/depart.go
+++ b/internal/grouproll/depart.go
@@ -963,23 +963,20 @@ func (e *Engine) departWatch(ctx context.Context) error {
return err
}
}
- if kind == "replace" && g.View.Desired < n {
- if _, err := e.event("phase", map[string]any{"phase": "restore-desired"}); err != nil {
- return err
- }
- if err := e.raiseDesired(ctx, n); err != nil {
- return err
- }
- continue
- }
- if kind == "replace" && g.View.Minimum < n {
- if _, err := e.event("phase", map[string]any{"phase": "restore-minimum"}); err != nil {
+ if kind == "replace" {
+ // V11 (fail closed, a deviation from the script's
+ // depart_watch): each restore is recorded once a describe
+ // shows it reached N. A restore not yet seen there (unsent,
+ // unanswered or lost) is sent again; a value below N after
+ // it was seen restored is a change outside this transaction,
+ // never raised again.
+ restored, err := e.restoreCapacity(ctx, g.View, n)
+ if err != nil {
return err
}
- if err := e.setMinimum(ctx, n); err != nil {
- return err
+ if !restored {
+ continue
}
- continue
}
if !departed {
keys, err := e.edgesList(ctx)
@@ -1011,6 +1008,14 @@ func (e *Engine) departWatch(ctx context.Context) error {
fresh = append(fresh, member)
}
}
+ // V10 (fail closed, a deviation from the script): once a replacement was admitted, the new
+ // member must stay exactly that one; any other set fails,
+ // and is never admitted again silently.
+ if admitted, ok := e.last("replacement-admitted", nil); ok {
+ if len(fresh) != 1 || fresh[0] != admitted["iid"] {
+ return e.alert("members", true)
+ }
+ }
if len(fresh) > 1 || g.View.Desired != n || g.View.Minimum != n {
return refuse("members")
}
@@ -1037,6 +1042,38 @@ func (e *Engine) departWatch(ctx context.Context) error {
}
}
+// restoreCapacity is the replace's restore of desired, then minimum, to
+// n (V11). It reports whether both are restored; when not, it has sent
+// the next restore and the watch reads the group again.
+func (e *Engine) restoreCapacity(ctx context.Context, g GroupView, n int) (bool, error) {
+ steps := []struct {
+ value int
+ row, phase, op string
+ send func() error
+ }{
+ {g.Desired, "desired-restored", "restore-desired", "desired", func() error { return e.raiseDesired(ctx, n) }},
+ {g.Minimum, "minimum-restored", "restore-minimum", "minimum", func() error { return e.setMinimum(ctx, n) }},
+ }
+ for _, st := range steps {
+ if e.has(st.row, nil) {
+ if st.value < n {
+ return false, e.alert("desired_changed", true)
+ }
+ continue
+ }
+ if st.value < n {
+ if _, err := e.event("phase", map[string]any{"phase": st.phase}); err != nil {
+ return false, err
+ }
+ return false, st.send()
+ }
+ if _, err := e.event(st.row, map[string]any{"value": st.value}); err != nil {
+ return false, err
+ }
+ }
+ return true, nil
+}
+
// admitReplacement: the replacement is online, ready, and at the floor
// too (§25.9: it publishes ha_take 1).
func (e *Engine) admitReplacement(ctx context.Context, iid string, start int64) error {
diff --git a/internal/grouproll/depart_test.go b/internal/grouproll/depart_test.go
index 00913ac0b..baa9a5c3b 100644
--- a/internal/grouproll/depart_test.go
+++ b/internal/grouproll/depart_test.go
@@ -1475,3 +1475,103 @@ func TestDrainSummaryLine(t *testing.T) {
t.Fatal("encoded an infinite number")
}
}
+
+// V10 (review fix, fail closed): replacement A is admitted while the
+// departure is still pending; A goes and B comes up healthy. The watch
+// fails the probe instead of finishing on A's admission.
+func TestDepartChangedReplacementAfterAdmissionFails(t *testing.T) {
+ h := newHeldHarness(t, 2, nil)
+ h.f.held.departureDelay = 600 * time.Second
+ const other = "i-0cccccccccccccccc"
+ swapped := false
+ h.afterEvent = func(kind string, _ Row) {
+ if kind == "replacement-admitted" && !swapped {
+ swapped = true
+ f := h.f
+ f.states[replacementIID] = "Terminated"
+ delete(f.tg, replacementIID)
+ f.addMember(other, "InService")
+ }
+ }
+ err := h.depart("replace", heldTx)
+ if !isStop(err, "failed-probe") || refusalKey(err) != "members" {
+ t.Fatalf("depart = %v", err)
+ }
+ j := h.txJournal(heldTx)
+ if _, ok := j.Last("done", nil); ok {
+ t.Fatal("a done row")
+ }
+ if !blockedFlag(h) || h.activeTx() != heldTx {
+ t.Fatalf("blocked %v active %q", blockedFlag(h), h.activeTx())
+ }
+ if n := len(rowsOf(j, "replacement-admitted")); n != 1 {
+ t.Fatalf("%d admissions", n)
+ }
+}
+
+// V11 (review fix, fail closed): desired and minimum were seen restored;
+// an outside reduction afterwards fails the probe and is never raised
+// again.
+func TestDepartCapacityReducedAfterRestoreFails(t *testing.T) {
+ h := newHeldHarness(t, 2, nil)
+ h.afterEvent = func(kind string, _ Row) {
+ if kind == "minimum-restored" {
+ h.f.minimum, h.f.desired = 1, 1
+ }
+ }
+ err := h.depart("replace", heldTx)
+ if !isStop(err, "failed-probe") || refusalKey(err) != "desired_changed" {
+ t.Fatalf("depart = %v", err)
+ }
+ if countOf(h.verbs(), "desired") != 1 || countOf(h.verbs(), "minimum") != 2 {
+ t.Fatalf("verbs %v", h.verbs())
+ }
+ if _, ok := h.txJournal(heldTx).Last("done", nil); ok || !blockedFlag(h) {
+ t.Fatalf("done or no flag (blocked %v)", blockedFlag(h))
+ }
+}
+
+// V11: a restore whose answer was lost is settled by the next describe
+// (recorded restored, not sent again); one that never reached the
+// provider is sent again.
+func TestDepartUnansweredRestoreRecovers(t *testing.T) {
+ cases := []struct {
+ name string
+ boundary int
+ before bool
+ fault string
+ desiredSent int
+ }{
+ {"desired answer lost", 6, false, "loss", 1},
+ {"minimum answer lost", 7, false, "loss", 1},
+ {"desired never sent", 6, true, "death", 2},
+ {"minimum never sent", 7, true, "death", 1},
+ }
+ for _, c := range cases {
+ t.Run(c.name, func(t *testing.T) {
+ h := newHeldHarness(t, 2, nil)
+ h.f.fault, h.f.faultAt, h.f.failBefore = c.fault, c.boundary, c.before
+ var err error
+ died := expectDeath(t, func() { err = h.depart("replace", heldTx) })
+ if !died && !isUncertain(err) {
+ t.Fatalf("depart = %v", err)
+ }
+ if err := h.resume(); err != nil {
+ t.Fatalf("resume: %v\n%s", err, h.out.String())
+ }
+ f := h.f
+ if f.minimum != 2 || f.desired != 2 || h.activeTx() != "" || blockedFlag(h) {
+ t.Fatalf("shape %d %d active %q", f.minimum, f.desired, h.activeTx())
+ }
+ if n := countOf(h.verbs(), "desired"); n != c.desiredSent {
+ t.Fatalf("desired sent %d times: %v", n, h.verbs())
+ }
+ j := h.txJournal(heldTx)
+ for _, k := range []string{"desired-restored", "minimum-restored"} {
+ if len(rowsOf(j, k)) != 1 {
+ t.Fatalf("%s rows %d", k, len(rowsOf(j, k)))
+ }
+ }
+ })
+ }
+}
diff --git a/internal/grouproll/mutation_test.go b/internal/grouproll/mutation_test.go
index 7827aef0d..43db8ef1d 100644
--- a/internal/grouproll/mutation_test.go
+++ b/internal/grouproll/mutation_test.go
@@ -129,6 +129,14 @@ func TestDepartMutations(t *testing.T) {
}, "terminate with decrement|desired lowered other than by Park|H4 violated"},
{"provider lowers desired on terminate (audit control)", func(s *departSim) { s.lowersOnTerminate = true },
"desired lowered other than by Park"},
+ {"fence removed before terminate (audit control)", func(s *departSim) {
+ none := ""
+ s.fenceBeforeTerminate = &none
+ }, "terminate without this transaction's fence"},
+ {"fence swapped before terminate (audit control)", func(s *departSim) {
+ other := "other-tx"
+ s.fenceBeforeTerminate = &other
+ }, "terminate without this transaction's fence"},
{"terminate before edge stop", func(s *departSim) { s.h.seams.terminateFirst = true },
"terminate before edge stop"},
{"skip the second sweep", func(s *departSim) { s.h.seams.skipSecondSweep = true },
diff --git a/internal/grouproll/sim_test.go b/internal/grouproll/sim_test.go
index 4c3c911a5..c7e3e55d9 100644
--- a/internal/grouproll/sim_test.go
+++ b/internal/grouproll/sim_test.go
@@ -593,7 +593,10 @@ type departSim struct {
// lowersOnTerminate is the audit control: a provider whose terminate
// lowers desired though the call said no decrement.
lowersOnTerminate bool
- lastAlert string
+ // fenceBeforeTerminate is the fence audit's negative control: the
+ // member's fence changes to this value just before the terminate.
+ fenceBeforeTerminate *string
+ lastAlert string
}
func unknownDrain(map[string]any) map[string]any {
@@ -827,6 +830,9 @@ func (s *departSim) request(op string, args map[string]any, write bool, perform
case "complete":
s.fail("lifecycle completion attempted")
case "terminate":
+ if s.fenceBeforeTerminate != nil {
+ f.held.fence = *s.fenceBeforeTerminate
+ }
s.auditTerminate(args)
if len(f.held.outcomes) > 0 {
o := f.held.outcomes[0]
@@ -992,6 +998,9 @@ func (s *departSim) auditTerminate(args map[string]any) {
systemd, _ := stopped["systemd"].(map[string]any)
pid := pyNumber(systemd["main_pid"])
s.check(stopped != nil && pid != nil && *pid == 0, "terminate before edge stop")
+ fence, _ := stopped["fence"].(map[string]any)
+ s.check(fence["state"] == "present" && fence["transaction"] == s.tx, "terminate without this transaction's fence")
+ s.check(s.f.held.fence == s.tx, "terminate without this transaction's fence")
s.check(s.emptySweepAfter(at, report), "terminate without an empty second sweep")
s.check(s.f.edge(fakeIID)["pid"] == nil, "terminate while the edge runs")
}
diff --git a/internal/provision/testdata/plan14-root-reads-group-roll-verb.tsv b/internal/provision/testdata/plan14-root-reads-group-roll-verb.tsv
index 4fd93a99d..52f5da82a 100644
--- a/internal/provision/testdata/plan14-root-reads-group-roll-verb.tsv
+++ b/internal/provision/testdata/plan14-root-reads-group-roll-verb.tsv
@@ -48,6 +48,6 @@ internal/grouprollaws/transport.go boundBody.HandleDeserialize legacy accepted-l
internal/grouprollaws/transport.go boundedBody.Read legacy accepted-legacy accepted-legacy;rev3=census-ruling-group-roll-verb;basis=reads an AWS API answer body under the 4 MiB cap and the read timeout file:Read@22,file:Read@448 7ff90cef635efcf75d046d9113cb6a0dcddd8dfb3570c73984bc5565b637e872
system_group.go runSystemGroup legacy accepted-legacy accepted-legacy;rev3=census-ruling-group-roll-verb;basis=lstats /etc/carlos/host.env to refuse running on a carlos box (euid 0 is refused first); routes the roll, replace, remove and cancel-drain verbs to the engine after refusing missing arguments file:Lstat@245 4582ac431a27dcd463bb78496dad6311dd9c487b75dfc759d067c286bb10d79c
@coverage . 324f3e9b1718abb0fe1f07c31f977e27ae50dc32a8c43e8977e636ba1793992a
-@coverage internal/grouproll 57beceed675c5d836f5e6115a8fa2e109fddf51ce2d9fcaf441d4e2eb9973ffb
+@coverage internal/grouproll 373305527c55ad2e12afe5435b6dc91030d4cb2449013c76b4c5e3e45399a8c3
@coverage internal/grouprollaws d9bc632b24975cd6e6434b0c23439871a68e4b4659041e6e110ba8b8b5e96ffc
@coverage internal/release e8d4983a8b37969c7d4ad9b99facf8332113f12f69c640b0b9624901184c9e54