grouproll: a failed drain's return ends without an alert after done
finishReturn writes done, closes the transaction, then refuses drain_failed. The return loop treated that refusal as an operation error, so stopDecision journaled an alert row after done and printed the AWS alert line. A refusal after the done row now leaves the loop as it is.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 files changed,
+27
−3
internal/grouproll/depart_test.go+17 −0internal/grouproll/roll.go+10 −3
Intent
diff --git a/internal/grouproll/depart_test.go b/internal/grouproll/depart_test.go| index 32f38a617..b1dca97ab 100644 |
| --- a/internal/grouproll/depart_test.go |
| +++ b/internal/grouproll/depart_test.go |
| @@ -1697,3 +1697,20 @@ func TestDepartAnsweredRestoreReducedFails(t *testing.T) { |
| }) |
| } |
| } |
| + |
| +// Fable P3-1: a failed drain's return closes the transaction and refuses |
| +// drain_failed straight out of the return loop. No alert row follows the |
| +// done row, and no AWS alert line is printed. |
| +func TestDepartFailedDrainReturnNoAlertAfterDone(t *testing.T) { |
| + h := newHeldHarness(t, 2, nil) |
| + h.f.held.drainMode = "drop-done" |
| + refusedWith(t, h.depart("replace", heldTx), "drain_failed") |
| + rows := h.txJournal(heldTx).Rows() |
| + if last := rows[len(rows)-1]; last["kind"] != "done" || last["outcome"] != "drain-failed" { |
| + t.Fatalf("last row %v, want done drain-failed", last) |
| + } |
| + if alert := Text("line", "phase", "ALERT", "detail", Text("api")); strings.Contains(h.out.String(), alert) { |
| + t.Fatalf("an AWS alert after done:\n%s", h.out.String()) |
| + } |
| + h.mustReturned(heldTx) |
| +} |
diff --git a/internal/grouproll/roll.go b/internal/grouproll/roll.go| index b8344dff1..dda02c58c 100644 |
| --- a/internal/grouproll/roll.go |
| +++ b/internal/grouproll/roll.go |
| @@ -1312,6 +1312,12 @@ func (e *Engine) returnMember(ctx context.Context) error { |
| finish = func(_ context.Context, r *readiness) error { return e.probeFinish(r) } |
| } |
| if err := finish(ctx, ready); err != nil { |
| + // After the done row (a failed drain's drain_failed |
| + // refusal) the transaction is closed: the refusal is |
| + // the outcome, not an operation error to alert on. |
| + if e.has("done", nil) { |
| + return errFinished{err: err} |
| + } |
| return err |
| } |
| return errFinished{} |
| @@ -1324,7 +1330,7 @@ func (e *Engine) returnMember(ctx context.Context) error { |
| switch { |
| case err == nil: |
| case errors.As(err, &done): |
| - return nil |
| + return done.err |
| case isStop(err, "drain-moving"): |
| return err |
| case refusalOrUncertain(err): |
| @@ -1340,8 +1346,9 @@ func (e *Engine) returnMember(ctx context.Context) error { |
| } |
| } |
| -// errFinished ends the return loop after a finished return. |
| -type errFinished struct{} |
| +// errFinished ends the return loop after a finished return; err is the |
| +// closed transaction's own refusal (drain_failed), returned as it is. |
| +type errFinished struct{ err error } |
| func (errFinished) Error() string { return "finished" } |