carlos / platform Public

console: a replay is refused without its retirement mark whatever the proof's age (plans 6b task 13 review)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev e07ec5a8e84249009a10c4688368c0bf067189dc parent 2575f5f
2 files changed, +48 −0
  • internal/console/billingretire.go +14 −0
  • internal/console/billingretire_test.go +34 −0
diff --git a/internal/console/billingretire.go b/internal/console/billingretire.go
index c44529228..0ccaa2e7c 100644
--- a/internal/console/billingretire.go
+++ b/internal/console/billingretire.go
@@ -185,6 +185,20 @@ func (s *Server) retireForDeletion(w http.ResponseWriter, r *http.Request, addr,
fresh := s.store.FreshStepUp(raw, addr, time.Now(), StepUpWindow)
now := time.Now()
h, release := s.holdBilling(acct.Sqid)
+ // A replay needs the mark its first run set, whatever its proof's age:
+ // checked under the hold before anything else, so a replay whose proof
+ // expired on the way never marks the account again or asks for another
+ // step-up.
+ if stepUpReplay(r) {
+ if retiring, err := s.store.BillingRetiring(acct.ID, now); err != nil || !retiring {
+ release()
+ if err == nil {
+ err = errDeleteRetry
+ }
+ refuse(err)
+ return nil, false
+ }
+ }
if fresh {
if err := s.retireLocked(h, ctx, acct, addr, stepUpReplay(r), now); err != nil {
release()
diff --git a/internal/console/billingretire_test.go b/internal/console/billingretire_test.go
index da9d24e70..e9c1bf81d 100644
--- a/internal/console/billingretire_test.go
+++ b/internal/console/billingretire_test.go
@@ -6,6 +6,7 @@ import (
"fmt"
"html"
"net/http"
+ "net/http/httptest"
"net/url"
"strings"
"testing"
@@ -551,3 +552,36 @@ func TestReplayNeedsRetirementToHold(t *testing.T) {
wantCounts(t, o.counts(), map[string]int{})
o.wantKept(t)
}
+
+// A replay whose proof expired between the callback and the dispatch, with
+// its retirement mark gone, is still a replay: refused before the gate, no
+// new mark and no new step-up, nothing deleted.
+func TestReplayWithExpiredProofNeedsRetirement(t *testing.T) {
+ o := newDeleteFixture(t, nil, false)
+ form := url.Values{"csrf": {o.csrf}, "confirm": {o.acct.Name}}
+ req := httptest.NewRequest(http.MethodPost, o.ts.URL+"/a/"+o.acct.Sqid+"/delete", strings.NewReader(form.Encode()))
+ req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
+ u, _ := url.Parse(o.ts.URL)
+ for _, ck := range o.owner.Jar.Cookies(u) {
+ req.AddCookie(ck)
+ }
+ req = req.WithContext(context.WithValue(req.Context(), stepUpReplayKey{}, true))
+ rr := httptest.NewRecorder()
+ o.srv.ServeHTTP(rr, req)
+ var flash string
+ for _, ck := range rr.Result().Cookies() {
+ if ck.Name == flashCookie {
+ flash, _ = url.QueryUnescape(ck.Value)
+ }
+ }
+ if rr.Code != http.StatusSeeOther || rr.Header().Get("Location") != o.settingsPath() || flash != "err|"+billingCopy["delete.retry"] {
+ t.Fatalf("replay = %d %q flash %q, want delete.retry", rr.Code, rr.Header().Get("Location"), flash)
+ }
+ wantCounts(t, o.counts(), map[string]int{})
+ o.wantKept(t)
+ var stashed int
+ o.st.db.QueryRow(`SELECT COUNT(*) FROM pending_actions`).Scan(&stashed)
+ if stashed != 0 {
+ t.Fatalf("%d pending actions parked by a refused replay", stashed)
+ }
+}