carlos / platform Public

console: instance retry arms the record's retry (#511)

For a replicated host whose deploy attempt can be retried, the record
holds the host, not any one box's report (Fable I3). The instance
retry door, CLI and browser alike, now arms the durable RetryOf on the
record whichever report the console joined, and signs a box grant only
when that report holds the same build. The coordinator consumes the
retry once on its tick.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev d3076e1f2ce419b325d1a70c5ae11edae3763e10 parent 9aebb78
2 files changed, +75 −8
  • internal/console/apiretry.go +39 −8
  • internal/console/replicadeploy_test.go +36 −0
diff --git a/internal/console/apiretry.go b/internal/console/apiretry.go
index 9dcd7386f..50d64edc1 100644
--- a/internal/console/apiretry.go
+++ b/internal/console/apiretry.go
@@ -18,6 +18,8 @@ package console
import (
"context"
+ "crypto/rand"
+ "encoding/hex"
"errors"
"fmt"
"log"
@@ -27,6 +29,7 @@ import (
"github.com/carlosframework/platform/internal/provision"
"github.com/carlosframework/platform/internal/release"
+ "github.com/carlosframework/platform/internal/replicas"
)
const (
@@ -79,8 +82,17 @@ var (
// (errRetryUnsupported); a held host at epoch 0 is a box whose failure
// book owes a save, and no grant clears anything until it lands
// (errRetryUnsaved).
+//
+// A replicated host (a record with a copy assignment) whose deploy attempt
+// can be retried is held by its record, not by any one box's report
+// (#511 final wave, item 8; Fable I3): its retry is the durable RetryOf
+// the coordinator consumes once (requestHostRetry), whichever box's
+// failure book the report joined for the host names. A box grant is
+// still signed when that report holds the same build, and is otherwise
+// left out.
func (s *Server) retryHostBuild(ctx context.Context, acct *Account, app, host string) (heldRestriction, error) {
- if _, _, err := s.readRecord(ctx, acct.Sqid, app, host); err != nil {
+ rec, _, err := s.readRecord(ctx, acct.Sqid, app, host)
+ if err != nil {
if errors.Is(err, os.ErrNotExist) {
return heldRestriction{}, errRetryNoRecord
}
@@ -88,6 +100,13 @@ func (s *Server) retryHostBuild(ctx context.Context, acct *Account, app, host st
}
join, _ := s.loadRolloutJoin(ctx, acct.Sqid, time.Now(), nil)
ro := join.rollout(host, acct.Sqid, app)
+ if d := rec.ReplicaDeploy; rec.ReplicaAssignment != nil && replicas.Retryable(d) {
+ held := heldRestriction{build: d.Target.Version, replicated: true}
+ if ro.retryable() && ro.retryRefusal() == nil && ro.HeldBy == held.build {
+ held.book, held.epoch, held.declined = ro.heldBook, ro.heldEpoch, ro.Unavailable != ""
+ }
+ return held, nil
+ }
if !ro.retryable() {
return heldRestriction{}, errRetryNotHeld
}
@@ -105,6 +124,10 @@ type heldRestriction struct {
build, book string
epoch uint64
declined bool
+ // replicated: the record holds the host (a retryable replicated
+ // attempt); book is empty when no box report holds the same build, and
+ // then no box grant is signed.
+ replicated bool
}
// requestHostRetry signs the retry grant for held (its build, book and
@@ -123,13 +146,21 @@ func (s *Server) requestHostRetry(ctx context.Context, acct, app, host string, h
if err != nil {
return release.RestartRequest{}, err
}
- signed, err := release.SignHostRetry(release.RootSigner(s.cfg.Key), acct, app, host, held.build, held.book, held.epoch, time.Now())
- if err != nil {
- return release.RestartRequest{}, err
- }
- req, err := release.AppendHostRetry(ctx, s.cfg.Releases, acct, app, host, signed)
- if err != nil {
- return release.RestartRequest{}, err
+ var req release.RestartRequest
+ if held.replicated && held.book == "" {
+ // The record alone holds this replicated host: its durable retry
+ // is the request, and no box's book is named.
+ var b [8]byte
+ _, _ = rand.Read(b[:])
+ req.ID = hex.EncodeToString(b[:])
+ } else {
+ signed, err := release.SignHostRetry(release.RootSigner(s.cfg.Key), acct, app, host, held.build, held.book, held.epoch, time.Now())
+ if err != nil {
+ return release.RestartRequest{}, err
+ }
+ if req, err = release.AppendHostRetry(ctx, s.cfg.Releases, acct, app, host, signed); err != nil {
+ return release.RestartRequest{}, err
+ }
}
if len(targets) != 0 {
if err := s.withRecordLock(acct, app, func() error { return s.armReplicaRetriesLocked(ctx, targets, "retry:"+req.ID) }); err != nil {
diff --git a/internal/console/replicadeploy_test.go b/internal/console/replicadeploy_test.go
index ebe9f0f1a..72b2d5708 100644
--- a/internal/console/replicadeploy_test.go
+++ b/internal/console/replicadeploy_test.go
@@ -518,3 +518,39 @@ func TestReplicaSwapWorkersFailedStatus(t *testing.T) {
t.Fatalf("status %q, want %q", got, want)
}
}
+
+// TestReplicaInstanceRetryArmsTheRecord (#511 final wave, item 8; Fable
+// I3): the instance retry door, for a replicated host whose deploy failed,
+// arms the durable RetryOf on the record whichever box's report the
+// console joined for the host, even when no report holds it (no box grant
+// is signed then). The coordinator consumes it once. A second request
+// finds it armed and writes nothing more; a passed attempt is not retried.
+func TestReplicaInstanceRetryArmsTheRecord(t *testing.T) {
+ fx, _, _, _, _ := replicaDeployFixture(t)
+ replaceRecord(t, fx, func(r *provision.Record) { r.ReplicaDeploy.Phase = "failed" })
+ u := fx.ts.URL + "/api/cli/apps/" + fx.acct + "/shop/instances/" + ixHost + "/retry"
+ code, _, body := rawReq(t, http.MethodPost, u, fx.owner, `{}`)
+ if code != http.StatusOK {
+ t.Fatalf("retry of a replicated host no box reports held = %d %s", code, body)
+ }
+ rec, _ := ixRecord(t, fx, ixHost)
+ d := rec.ReplicaDeploy
+ if !replicas.RetryRequested(d) || !strings.HasPrefix(d.RetryRequest, "retry:") {
+ t.Fatalf("the record's retry was not armed: %+v", d)
+ }
+ if code, _, body := rawReq(t, http.MethodPost, u, fx.owner, `{}`); code != http.StatusOK {
+ t.Fatalf("second retry = %d %s", code, body)
+ }
+ if again, _ := ixRecord(t, fx, ixHost); again.RecordSeq != rec.RecordSeq {
+ t.Fatal("a second request rewrote the armed record")
+ }
+ // A passed attempt is no replicated retry: the box report decides, as
+ // for any host, and with none it is not held.
+ replaceRecord(t, fx, func(r *provision.Record) {
+ r.ReplicaDeploy.Phase = "done"
+ r.ReplicaDeploy.RetryOf, r.ReplicaDeploy.RetryRequest = "", ""
+ })
+ if code, _, body := rawReq(t, http.MethodPost, u, fx.owner, `{}`); code != http.StatusConflict {
+ t.Fatalf("retry of a done deploy = %d %s", code, body)
+ }
+}