grouproll: an answered capacity restore is never sent again (V11)
restoreCapacity resent a desired or minimum restore whenever the value read below N and no describe had yet seen it at N. A restore AWS answered and then reduced outside the transaction was raised again. Now a value below N after a response row for the restore fails the probe (desired_changed); only an unsent or unanswered restore is resent.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 files changed,
+80
−4
internal/grouproll/depart.go+35 −4internal/grouproll/depart_test.go+45 −0
Intent
diff --git a/internal/grouproll/depart.go b/internal/grouproll/depart.go| index ad7f7558e..8edbf9a23 100644 |
| --- a/internal/grouproll/depart.go |
| +++ b/internal/grouproll/depart.go |
| @@ -966,10 +966,11 @@ func (e *Engine) departWatch(ctx context.Context) error { |
| 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. |
| + // shows it reached N. Only a restore with no answer (never |
| + // sent, or its answer lost) is sent again. A value below N |
| + // after AWS answered the restore, or after a describe saw |
| + // it at N, is a change outside this transaction: a failed |
| + // probe, never raised again. |
| restored, err := e.restoreCapacity(ctx, g.View, n) |
| if err != nil { |
| return err |
| @@ -1062,6 +1063,9 @@ func (e *Engine) restoreCapacity(ctx context.Context, g GroupView, n int) (bool, |
| continue |
| } |
| if st.value < n { |
| + if e.restoreAnswered(st.op, n) { |
| + return false, e.alert("desired_changed", true) |
| + } |
| if _, err := e.event("phase", map[string]any{"phase": st.phase}); err != nil { |
| return false, err |
| } |
| @@ -1074,6 +1078,33 @@ func (e *Engine) restoreCapacity(ctx context.Context, g GroupView, n int) (bool, |
| return true, nil |
| } |
| +// restoreAnswered reports whether a restore of op to n sent after the |
| +// terminate check has a response row: AWS answered it, so the value |
| +// reached n whatever a later describe shows. |
| +func (e *Engine) restoreAnswered(op string, n int) bool { |
| + if e.j == nil { |
| + return false |
| + } |
| + after := false |
| + var intents []any |
| + for _, r := range e.j.Rows() { |
| + switch { |
| + case r["kind"] == "terminate-checked": |
| + after = true |
| + case !after: |
| + case r["kind"] == "intent" && r["op"] == op && sameValue(r["args"], map[string]any{"value": n}): |
| + intents = append(intents, r["seq"]) |
| + case r["kind"] == "response" && r["op"] == op: |
| + for _, seq := range intents { |
| + if sameValue(r["intent"], seq) { |
| + return true |
| + } |
| + } |
| + } |
| + } |
| + return false |
| +} |
| + |
| // 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 d80cd29a3..32f38a617 100644 |
| --- a/internal/grouproll/depart_test.go |
| +++ b/internal/grouproll/depart_test.go |
| @@ -1652,3 +1652,48 @@ func TestDepartExpiredExitAttemptRechecksDrain(t *testing.T) { |
| t.Fatalf("verbs %v state %s", h.verbs(), h.f.states[fakeIID]) |
| } |
| } |
| + |
| +// Fable P2-1 (V11): a restore AWS answered is not sent again. When the |
| +// value is reduced outside the transaction after the answer but before a |
| +// describe shows it at N, the watch fails the probe (desired_changed) |
| +// instead of raising it again. |
| +func TestDepartAnsweredRestoreReducedFails(t *testing.T) { |
| + for _, op := range []string{"desired", "minimum"} { |
| + t.Run(op, func(t *testing.T) { |
| + h := newHeldHarness(t, 2, nil) |
| + reduced := false |
| + h.afterEvent = func(kind string, r Row) { |
| + if kind != "response" || r["op"] != op || reduced { |
| + return |
| + } |
| + switch { |
| + case op == "desired" && h.f.desired == 2: |
| + h.f.desired, reduced = 1, true |
| + case op == "minimum" && h.f.minimum == 2: |
| + h.f.minimum, reduced = 1, true |
| + } |
| + } |
| + err := h.depart("replace", heldTx) |
| + if !reduced { |
| + t.Fatal("no restore was answered") |
| + } |
| + if !isStop(err, "failed-probe") || refusalKey(err) != "desired_changed" { |
| + t.Fatalf("depart = %v", err) |
| + } |
| + // Each restore is sent once; a desired failure stops before |
| + // the minimum restore. |
| + want := map[string]int{"desired": 1, "minimum": 2} |
| + if op == "desired" { |
| + want["minimum"] = 1 |
| + } |
| + for k, n := range want { |
| + if countOf(h.verbs(), k) != n { |
| + t.Fatalf("%s sent %d times, want %d: %v", k, countOf(h.verbs(), k), n, h.verbs()) |
| + } |
| + } |
| + if !blockedFlag(h) { |
| + t.Fatal("no divergence flag") |
| + } |
| + }) |
| + } |
| +} |