fix: key replica retries to their request and fail closed on reads
Task 1 fix round 2 (re-review 1, #2 and #3). - Retry intent now records the request that wrote it (RetryRequest beside RetryOf), and the writer carries it onto the attempt that consumes the retry. A replay of the same request skips every record it already reached and every record whose attempt is newer than the one it validated, so it finishes only what it missed and never re-arms a new attempt. Keys: the CLI's request_id for promote --retry (sent by the CLI, optional on the wire), the proposal id, the host retry's request id. - Both retry doors read the app strictly. Any record that cannot be read or decoded refuses the whole request before any write (SR-4-C41, pending copy review): the console promote door and proposal path through listRecordsStrict, the direct-bucket CLI refusal through provision.ListRecordsStrict. Record-write census updated; root-read census envelopes re-pinned (stateless-replicas-4-task1-fix2).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
apimode.go+14 −6cli.go+9 −4docs/superpowers/notes/census-proposal-stateless-replicas-4-task1-fix2.md+11 −0docs/superpowers/plans/2026-11-01-stateless-replicas-copy.md+1 −0internal/activator/replicarelease_world_test.go+1 −1internal/console/apicli.go+9 −2internal/console/apiretry.go+1 −1internal/console/pendinghandlers.go+3 −3internal/console/replicadeploy.go+33 −13internal/console/replicadeploy_test.go+63 −1internal/provision/replicadeploy.go+46 −24internal/provision/replicadeploy_test.go+129 −6internal/provision/stateless_replicas_4_task1_census_test.go+15 −4internal/provision/testdata/plan14-root-reads-chain.tsv+1 −0internal/provision/testdata/plan14-root-reads-stateless-replicas-4-task1-fix2.tsv+5 −0internal/replicas/types.go+4 −0replica_promote_retry_test.go+20 −2
CI failed — run details
Intent
<task-notification> <task-id>bgg2hk58d</task-id> <tool-use-id>toolu_01Pr3JZA6ytWhirCYqqUKJQL</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/72128d15-58b8-452f-9f7e-8e864e8854d2/tasks/bgg2hk58d.output</output-file> <status>completed</status> <summary>Background command "Run Astra scoped re-review of fix round 1" completed (exit code 0)</summary> </task-notification>
Attributed to this commit: 16.3 g CO₂e (2,030,055 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on stateless-replicas-4, 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/apimode.go b/apimode.go| index f9b75f71b..9759a2b59 100644 |
| --- a/apimode.go |
| +++ b/apimode.go |
| @@ -18,6 +18,7 @@ package main |
| import ( |
| "bytes" |
| "context" |
| + "crypto/rand" |
| "encoding/json" |
| "errors" |
| "fmt" |
| @@ -993,13 +994,20 @@ func proposedFromBody(body []byte) error { |
| // of anything this call site doesn't already ask for. |
| func (s *apiSession) promote(ctx context.Context, a apiAcct, app, version, channel string, hotfix, retry bool, messages ...string) (apiPromoteResult, error) { |
| message := firstMutationMessage(messages) |
| + // A retry names this invocation, so the console treats a resend of the |
| + // same request as that request (stateless replicas retry intent). |
| + requestID := "" |
| + if retry { |
| + requestID = rand.Text() |
| + } |
| in := struct { |
| - Version string `json:"version"` |
| - Channel string `json:"channel"` |
| - Hotfix bool `json:"hotfix,omitempty"` |
| - Retry bool `json:"retry,omitempty"` |
| - Message string `json:"message,omitempty"` |
| - }{version, channel, hotfix, retry, message} |
| + Version string `json:"version"` |
| + Channel string `json:"channel"` |
| + Hotfix bool `json:"hotfix,omitempty"` |
| + Retry bool `json:"retry,omitempty"` |
| + Message string `json:"message,omitempty"` |
| + RequestID string `json:"request_id,omitempty"` |
| + }{version, channel, hotfix, retry, message, requestID} |
| status, body, err := s.postJSON(ctx, apiPath(a, app, "/promote"), in) |
| if err != nil { |
| return apiPromoteResult{}, err |
diff --git a/cli.go b/cli.go| index 3145ba9ce..f338cfad0 100644 |
| --- a/cli.go |
| +++ b/cli.go |
| @@ -4247,11 +4247,16 @@ var errDirectReplicaRetry = errors.New("this app runs stateless replicas, so ret |
| // that has a copy assignment or a stateless replica deploy. That retry is |
| // durable intent the console writes under its record lock (stateless |
| // replicas R1); a pointer renewal alone would leave the failed attempt in |
| -// place. An unreadable listing refuses too. Nothing is written. |
| +// place. The app's records are read strictly: a listing, a record read or a |
| +// record decode that fails refuses too, since that record could be one. |
| +// Nothing is written. |
| func directRetryRefusal(ctx context.Context, store release.Store, acct, app, channel string) error { |
| - recs, _, err := provision.ListRecords(ctx, store, acct, app, math.MaxInt) |
| - if err != nil { |
| - return err |
| + recs, unreadable, err := provision.ListRecordsStrict(ctx, store, acct, app, math.MaxInt) |
| + if err != nil || len(unreadable) != 0 { |
| + if err != nil { |
| + log.Printf("promote: read instance records: %v", err) |
| + } |
| + return provision.ErrReplicaRetryUnreadable |
| } |
| for _, rec := range recs { |
| if rec.Channel == channel && (rec.ReplicaAssignment != nil || rec.ReplicaDeploy != nil) { |
diff --git a/docs/superpowers/notes/census-proposal-stateless-replicas-4-task1-fix2.md b/docs/superpowers/notes/census-proposal-stateless-replicas-4-task1-fix2.md| new file mode 100644 |
| index 000000000..e11724c3f |
| --- /dev/null |
| +++ b/docs/superpowers/notes/census-proposal-stateless-replicas-4-task1-fix2.md |
| @@ -0,0 +1,11 @@ |
| +# Census approval: stateless-replicas-4-task1-fix2 |
| + |
| +Ruling `census-ruling-stateless-replicas-4-task1-fix2`. The independent reviewer approves or rejects every change below, 0 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26). |
| + |
| +Envelopes re-pinned: `.`, `internal/provision`, `internal/replicas`. |
| + |
| +Review: a model from the other family than the author reads the branch's diff against main on the amadan.net remote (`origin` or `amadan`, whichever points at amadan.net) and gives a verdict for every unit and every re-pinned envelope above. For a unit, compare the change with its recorded disposition and basis below; for an envelope, read every changed function in the package and what it reaches. Reject if the change lets root open, run, query or follow anything it did not before from a path or input a tenant, an app or a box agent can create, write or name; if it weakens a check, refusal, validation, argument or environment the basis relies on; or if the diff cannot settle either. Otherwise approve. Record each verdict on #280 with the tip. A rejected unit goes back to the author to correct; nothing escalates to the census owner. |
| + |
| +Seal: `3f066208f5e5fa2b9854f30118a9a2707f3a5a51bcf55ae6b0949cb0307804f5` → `3f066208f5e5fa2b9854f30118a9a2707f3a5a51bcf55ae6b0949cb0307804f5`. |
| + |
| +Overlay: `internal/provision/testdata/plan14-root-reads-stateless-replicas-4-task1-fix2.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`. |
diff --git a/docs/superpowers/plans/2026-11-01-stateless-replicas-copy.md b/docs/superpowers/plans/2026-11-01-stateless-replicas-copy.md| index 1d01dfd6f..1d5e656ab 100644 |
| --- a/docs/superpowers/plans/2026-11-01-stateless-replicas-copy.md |
| +++ b/docs/superpowers/plans/2026-11-01-stateless-replicas-copy.md |
| @@ -112,3 +112,4 @@ copy too. Internal wire enums are not an excuse to expose unreviewed text. |
| | SR-4-C38 | internal/console/replicadeploy.go | release result unknown | pending | |
| | SR-4-C39 | internal/console/replicadeploy.go | release complete; no copy was running, so the first copy is starting on its own | pending (added by Plan 4 Task 1 for a bootstrap order; awaiting Paul's copy review) | |
| | SR-4-C40 | cli.go | this app runs stateless replicas, so retry it through the console: carlos instances retry <host>, or carlos promote --retry while logged in to the console | pending (added by Plan 4 Task 1 fix round 1 for the direct-bucket retry refusal; awaiting Paul's copy review) | |
| +| SR-4-C41 | internal/provision/replicadeploy.go | an instance record could not be read, so nothing was retried. try again | pending (added by Plan 4 Task 1 fix round 2 for retries that fail closed on unreadable records; awaiting Paul's copy review) | |
diff --git a/internal/activator/replicarelease_world_test.go b/internal/activator/replicarelease_world_test.go| index 2af9938a5..7bea34d60 100644 |
| --- a/internal/activator/replicarelease_world_test.go |
| +++ b/internal/activator/replicarelease_world_test.go |
| @@ -234,7 +234,7 @@ func TestReplicaReleaseCoordinatorDiesBeforeCommit(t *testing.T) { |
| t.Fatalf("successor replaced the attempt: %+v mints=%d", d, b.mints) |
| } |
| // The explicit retry is durable; the coordinator mints once and may repeat. |
| - if _, err := provision.RequestRecordReplicaRetry(context.Background(), w.s, in.id, first.ID); err != nil { |
| + if _, err := provision.RequestRecordReplicaRetry(context.Background(), w.s, in.id, first.ID, "request-1"); err != nil { |
| t.Fatal(err) |
| } |
| b.r.b.unit.done("1", "0", "success") |
diff --git a/internal/console/apicli.go b/internal/console/apicli.go| index 770cbb70e..b17040b2b 100644 |
| --- a/internal/console/apicli.go |
| +++ b/internal/console/apicli.go |
| @@ -922,6 +922,9 @@ func (s *Server) handleAPIPromote(w http.ResponseWriter, r *http.Request) { |
| // fresh PromotedAt. It goes through the same rules, scope and |
| // Authorize checks as any promote. |
| Retry bool `json:"retry"` |
| + // RequestID names one CLI invocation of a retry, so its resend |
| + // finishes the same request (promoteRetryRequest). Optional. |
| + RequestID string `json:"request_id,omitempty"` |
| } |
| if !readJSON(w, r, &req) { |
| return |
| @@ -1136,11 +1139,15 @@ func (s *Server) handleAPIPromote(w http.ResponseWriter, r *http.Request) { |
| // A replicated release retry (R1) is judged before the pointer is |
| // touched, so a refusal writes nothing. |
| var retryTargets []provision.Record |
| + retryRequest := promoteRetryRequest(channel, version, req.RequestID) |
| if req.Retry { |
| - targets, err := s.channelReplicaRetryTargets(ctx, acct.Sqid, app, channel, version) |
| + targets, err := s.channelReplicaRetryTargets(ctx, acct.Sqid, app, channel, version, retryRequest) |
| if errors.Is(err, provision.ErrReplicaSwitchOpen) { |
| jsonError(w, http.StatusConflict, err.Error()) |
| return |
| + } else if errors.Is(err, provision.ErrReplicaRetryUnreadable) { |
| + jsonError(w, http.StatusBadGateway, err.Error()) |
| + return |
| } else if err != nil { |
| log.Printf("console: api promote %s %s -> %s: replica retry: %v", app, version, channel, err) |
| jsonError(w, http.StatusBadGateway, apiRetryStore) |
| @@ -1153,7 +1160,7 @@ func (s *Server) handleAPIPromote(w http.ResponseWriter, r *http.Request) { |
| if err == nil && len(retryTargets) != 0 { |
| // The renewal passed its own checks; the intent lands before the |
| // serial announces it. The same request again finishes a partial one. |
| - if aerr := s.armReplicaRetriesLocked(ctx, retryTargets); aerr != nil { |
| + if aerr := s.armReplicaRetriesLocked(ctx, retryTargets, retryRequest); aerr != nil { |
| log.Printf("console: api promote %s %s -> %s: replica retry: %v", app, version, channel, aerr) |
| jsonError(w, http.StatusBadGateway, apiRetryStore) |
| return |
diff --git a/internal/console/apiretry.go b/internal/console/apiretry.go| index bdf922b0b..9dcd7386f 100644 |
| --- a/internal/console/apiretry.go |
| +++ b/internal/console/apiretry.go |
| @@ -132,7 +132,7 @@ func (s *Server) requestHostRetry(ctx context.Context, acct, app, host string, h |
| return release.RestartRequest{}, err |
| } |
| if len(targets) != 0 { |
| - if err := s.withRecordLock(acct, app, func() error { return s.armReplicaRetriesLocked(ctx, targets) }); err != nil { |
| + if err := s.withRecordLock(acct, app, func() error { return s.armReplicaRetriesLocked(ctx, targets, "retry:"+req.ID) }); err != nil { |
| return release.RestartRequest{}, err |
| } |
| } |
diff --git a/internal/console/pendinghandlers.go b/internal/console/pendinghandlers.go| index d38c1f6b2..4d68088b7 100644 |
| --- a/internal/console/pendinghandlers.go |
| +++ b/internal/console/pendinghandlers.go |
| @@ -575,8 +575,8 @@ func (s *Server) executePendingPromote(ctx context.Context, acct *Account, app, |
| // touched, so a refusal writes nothing. |
| var retryTargets []provision.Record |
| if p.Retry { |
| - targets, err := s.channelReplicaRetryTargets(ctx, acct.Sqid, app, p.Channel, p.Version) |
| - if errors.Is(err, provision.ErrReplicaSwitchOpen) { |
| + targets, err := s.channelReplicaRetryTargets(ctx, acct.Sqid, app, p.Channel, p.Version, "proposal:"+pc.ID) |
| + if errors.Is(err, provision.ErrReplicaSwitchOpen) || errors.Is(err, provision.ErrReplicaRetryUnreadable) { |
| return "", err |
| } else if err != nil { |
| log.Printf("console: execute promote %s %s -> %s: replica retry: %v", app, p.Version, p.Channel, err) |
| @@ -588,7 +588,7 @@ func (s *Server) executePendingPromote(ctx context.Context, acct *Account, app, |
| release.PromoteOptions{Actor: actor, Hotfix: p.Hotfix, Retry: p.Retry}) |
| if err == nil && len(retryTargets) != 0 { |
| // The intent lands before the serial announces the renewal. |
| - if aerr := s.armReplicaRetriesLocked(ctx, retryTargets); aerr != nil { |
| + if aerr := s.armReplicaRetriesLocked(ctx, retryTargets, "proposal:"+pc.ID); aerr != nil { |
| log.Printf("console: execute promote %s %s -> %s: replica retry: %v", app, p.Version, p.Channel, aerr) |
| return "", errors.New(apiRetryStore) |
| } |
diff --git a/internal/console/replicadeploy.go b/internal/console/replicadeploy.go| index 29742ae85..cd4f9629c 100644 |
| --- a/internal/console/replicadeploy.go |
| +++ b/internal/console/replicadeploy.go |
| @@ -2,6 +2,9 @@ package console |
| import ( |
| "context" |
| + "crypto/rand" |
| + "crypto/sha256" |
| + "encoding/hex" |
| "errors" |
| "fmt" |
| "math" |
| @@ -190,30 +193,47 @@ func (s *Server) replicaDeployOrder(ctx context.Context, rec provision.Record, c |
| // hostReplicaRetryTargets is the read-only half of `carlos instances |
| // retry` and the instance page's Retry for a replicated release (R1): it |
| -// refuses an open switch before anything is written or signed. |
| +// refuses an open switch, or a record it cannot read, before anything is |
| +// written or signed. |
| func (s *Server) hostReplicaRetryTargets(ctx context.Context, acct, app, host, build string) ([]provision.Record, error) { |
| rec, _, err := s.readRecord(ctx, acct, app, host) |
| if err != nil { |
| return nil, err |
| } |
| - return provision.ReplicaRetryTargets([]provision.Record{*rec}, "", build) |
| + return provision.ReplicaRetryTargets([]provision.Record{*rec}, nil, "", build, "") |
| } |
| // channelReplicaRetryTargets is the read-only half of `carlos promote |
| // --retry`: every instance on channel whose replicated attempt for build |
| -// would be retried. The caller holds the app lock. |
| -func (s *Server) channelReplicaRetryTargets(ctx context.Context, acct, app, channel, build string) ([]provision.Record, error) { |
| - recs, _, err := s.listRecords(ctx, acct, app, math.MaxInt) |
| +// this request would retry. It reads the whole app strictly: a record that |
| +// cannot be read or decoded refuses the request. The caller holds the app |
| +// lock. |
| +func (s *Server) channelReplicaRetryTargets(ctx context.Context, acct, app, channel, build, request string) ([]provision.Record, error) { |
| + recs, unreadable, err := s.listRecordsStrict(ctx, acct, app, math.MaxInt) |
| if err != nil { |
| - return nil, err |
| + return nil, provision.ErrReplicaRetryUnreadable |
| } |
| - return provision.ReplicaRetryTargets(recs, channel, build) |
| + return provision.ReplicaRetryTargets(recs, unreadable, channel, build, request) |
| } |
| -// armReplicaRetriesLocked writes the retry intent once the door's own |
| -// preconditions passed and before any box is told. Running the same |
| -// request again finishes a partly written one. The caller holds the app |
| -// lock. |
| -func (s *Server) armReplicaRetriesLocked(ctx context.Context, targets []provision.Record) error { |
| - return provision.RequestReplicaRetries(ctx, s.cfg.Releases, targets) |
| +// armReplicaRetriesLocked writes the retry intent of request once the |
| +// door's own preconditions passed and before any box is told. Running the |
| +// same request again finishes a partly written one. The caller holds the |
| +// app lock. |
| +func (s *Server) armReplicaRetriesLocked(ctx context.Context, targets []provision.Record, request string) error { |
| + return provision.RequestReplicaRetries(ctx, s.cfg.Releases, targets, request) |
| +} |
| + |
| +// promoteRetryRequest is the key of one `carlos promote --retry` request: |
| +// the CLI's request_id for this channel and version, so the CLI's resend of |
| +// the same request finishes it rather than starting another; without one, |
| +// a fresh key. |
| +func promoteRetryRequest(channel, version, requestID string) string { |
| + if requestID == "" { |
| + var b [16]byte |
| + _, _ = rand.Read(b[:]) |
| + return "promote:" + hex.EncodeToString(b[:]) |
| + } |
| + sum := sha256.Sum256([]byte(channel + "\x00" + version + "\x00" + requestID)) |
| + return "promote:" + hex.EncodeToString(sum[:16]) |
| } |
diff --git a/internal/console/replicadeploy_test.go b/internal/console/replicadeploy_test.go| index 96cb7af38..385a82de8 100644 |
| --- a/internal/console/replicadeploy_test.go |
| +++ b/internal/console/replicadeploy_test.go |
| @@ -274,7 +274,7 @@ func TestReplicaRetryRefusedWhileSwitchOpen(t *testing.T) { |
| t.Fatalf("host retry: %v", err) |
| } |
| unlock := fx.srv.lockApp(fx.acct, "shop") |
| - _, err = fx.srv.channelReplicaRetryTargets(context.Background(), fx.acct, "shop", before.Channel, "v1") |
| + _, err = fx.srv.channelReplicaRetryTargets(context.Background(), fx.acct, "shop", before.Channel, "v1", "request-1") |
| unlock() |
| if !errors.Is(err, provision.ErrReplicaSwitchOpen) { |
| t.Fatalf("promote retry: %v", err) |
| @@ -415,3 +415,65 @@ func TestReplicaPromoteRetryRefusalWritesNothing(t *testing.T) { |
| t.Fatalf("another build was armed: %+v %v", b, err) |
| } |
| } |
| + |
| +// TestReplicaPromoteRetryUnreadableWritesNothing: a record of the app that |
| +// cannot be decoded could hold an open switch, so `promote --retry` refuses |
| +// with SR-4-C41 and the bucket is left exactly as it was. |
| +func TestReplicaPromoteRetryUnreadableWritesNothing(t *testing.T) { |
| + fx, token, url, put := promoteRetryWorld(t) |
| + put("a.titogo.example.com", replicas.Deploy{ID: "deploy-a", Target: replicas.Build{Version: "abc1234", Digest: "d"}, Phase: "failed", Term: "t", Revision: 3}) |
| + if _, err := fx.rel.Put(context.Background(), provision.RecordKey(release.OpsAccount, "titogo", "c.titogo.example.com"), []byte("{not a record"), ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + before := bucketSnapshot(t, fx.rel) |
| + status, out := postJSON(t, url, map[string]any{"version": "abc1234", "channel": "canary/x", "retry": true}, token) |
| + if status != http.StatusBadGateway || !strings.Contains(str(t, out, "error"), "could not be read, so nothing was retried") { |
| + t.Fatalf("unreadable: %d %v", status, out) |
| + } |
| + if !reflect.DeepEqual(bucketSnapshot(t, fx.rel), before) { |
| + t.Fatal("a refused retry wrote") |
| + } |
| +} |
| + |
| +// TestReplicaPromoteRetryReplayIsKeyed: the CLI's request_id keys the |
| +// retry. Replaying the same request after its write to B failed and A's |
| +// retried release failed finishes only B; a new request retries A again. |
| +func TestReplicaPromoteRetryReplayIsKeyed(t *testing.T) { |
| + fx, token, url, put := promoteRetryWorld(t) |
| + build := replicas.Build{Version: "abc1234", Digest: "d"} |
| + put("a.titogo.example.com", replicas.Deploy{ID: "a1", Target: build, Phase: "failed", Term: "t", Revision: 3}) |
| + put("b.titogo.example.com", replicas.Deploy{ID: "b1", Target: build, Phase: "failed", Term: "t", Revision: 3}) |
| + retry := func(id string) { |
| + t.Helper() |
| + if status, out := postJSON(t, url, map[string]any{"version": "abc1234", "channel": "canary/x", "retry": true, "request_id": id}, token); status != http.StatusOK { |
| + t.Fatalf("retry %s: %d %v", id, status, out) |
| + } |
| + } |
| + get := func(host string) *replicas.Deploy { |
| + t.Helper() |
| + rec, err := provision.GetRecord(context.Background(), fx.rel, release.OpsAccount, "titogo", host) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + return rec.ReplicaDeploy |
| + } |
| + retry("r1") |
| + key := get("a.titogo.example.com").RetryRequest |
| + if key == "" || get("b.titogo.example.com").RetryRequest != key { |
| + t.Fatal("request not recorded on its intent") |
| + } |
| + // B's write is as if it failed; A's retry ran and failed. |
| + put("b.titogo.example.com", replicas.Deploy{ID: "b1", Target: build, Phase: "failed", Term: "t", Revision: 3}) |
| + put("a.titogo.example.com", replicas.Deploy{ID: "a2", Target: build, Phase: "failed", Term: "t2", RetryOf: "a1", RetryRequest: key, Revision: 6}) |
| + retry("r1") |
| + if a := get("a.titogo.example.com"); replicas.RetryRequested(a) { |
| + t.Fatalf("replay re-armed A's newer attempt: %+v", a) |
| + } |
| + if b := get("b.titogo.example.com"); !replicas.RetryRequested(b) || b.RetryRequest != key { |
| + t.Fatalf("replay did not finish B: %+v", b) |
| + } |
| + retry("r2") |
| + if a := get("a.titogo.example.com"); !replicas.RetryRequested(a) || a.ID != "a2" || a.RetryRequest == key { |
| + t.Fatalf("a new request did not retry A: %+v", a) |
| + } |
| +} |
diff --git a/internal/provision/replicadeploy.go b/internal/provision/replicadeploy.go| index aad05e6e3..04bd35d55 100644 |
| --- a/internal/provision/replicadeploy.go |
| +++ b/internal/provision/replicadeploy.go |
| @@ -26,7 +26,7 @@ func SetRecordReplicaRelease(ctx context.Context, s release.Store, id replicas.I |
| } |
| // The writer owns the swap, LastGood and a consumed retry; a |
| // release change carries none of them except a begin's RetryOf. |
| - if next.Incarnation != id.Incarnation || next.ID == "" || next.Term == "" || next.Target.Version == "" || next.Target.Digest == "" || !swapEmpty(next.Swap) || next.LastGood != (replicas.Build{}) || (next.RetryOf != "" && next.Phase != "pending") { |
| + if next.Incarnation != id.Incarnation || next.ID == "" || next.Term == "" || next.Target.Version == "" || next.Target.Digest == "" || !swapEmpty(next.Swap) || next.LastGood != (replicas.Build{}) || next.RetryRequest != "" || (next.RetryOf != "" && next.Phase != "pending") { |
| return replicas.ErrInvalid |
| } |
| if len(proof) != 0 && (len(proof) != 1 || rec.Coordinator == nil || !proof[0].matches(rec, rec.Coordinator.Box)) { |
| @@ -64,6 +64,10 @@ func SetRecordReplicaRelease(ctx context.Context, s release.Store, id replicas.I |
| return err |
| } |
| next.LastGood = replicas.CarryLastGood(old, id.Incarnation) |
| + if next.RetryOf != "" { |
| + // The consuming attempt keeps the request that asked for it. |
| + next.RetryRequest = old.RetryRequest |
| + } |
| } else { |
| if old.Incarnation != next.Incarnation || old.Target != next.Target || old.Previous != next.Previous { |
| return replicas.ErrFenced |
| @@ -71,7 +75,7 @@ func SetRecordReplicaRelease(ctx context.Context, s release.Store, id replicas.I |
| if next.RetryOf != "" && next.RetryOf != old.RetryOf { |
| return replicas.ErrInvalid |
| } |
| - next.RetryOf = old.RetryOf |
| + next.RetryOf, next.RetryRequest = old.RetryOf, old.RetryRequest |
| next.LastGood = old.LastGood |
| if next.Phase == "released" { |
| next.LastGood = next.Target |
| @@ -157,11 +161,18 @@ func SetRecordReplicaDeploy(ctx context.Context, s release.Store, id replicas.Id |
| return result, err |
| } |
| -// RequestRecordReplicaRetry durably asks for one explicit retry of the |
| -// record's failed, unknown or halted attempt named deployID. The coordinator |
| -// consumes it once by writing a new pending attempt that carries RetryOf. |
| -// A request that is already pending is an unchanged replay. |
| -func RequestRecordReplicaRetry(ctx context.Context, s release.Store, id replicas.Identity, deployID string) (*Record, error) { |
| +// RequestRecordReplicaRetry durably asks, for the explicit retry request |
| +// named request, for one retry of the record's failed, unknown or halted |
| +// attempt deployID, the attempt the request validated. The coordinator |
| +// consumes it once by writing a new pending attempt that carries RetryOf |
| +// and the request. A record this request already reached (asked or |
| +// consumed), or whose current attempt is newer than deployID, is left |
| +// unchanged: a replay of the request finishes only what it has not reached |
| +// and never arms an attempt that began after it. |
| +func RequestRecordReplicaRetry(ctx context.Context, s release.Store, id replicas.Identity, deployID, request string) (*Record, error) { |
| + if deployID == "" || request == "" { |
| + return nil, replicas.ErrInvalid |
| + } |
| var result *Record |
| err := release.WithAppMutation(ctx, s, id.Account, id.App, "provision.RequestRecordReplicaRetry", func(ctx context.Context) error { |
| ctx = context.WithValue(ctx, replicaWriteKey{}, "replica_deploy") |
| @@ -171,10 +182,10 @@ func RequestRecordReplicaRetry(ctx context.Context, s release.Store, id replicas |
| return err |
| } |
| d := rec.ReplicaDeploy |
| - if d == nil || d.Incarnation != id.Incarnation || d.ID != deployID || deployID == "" { |
| + if d == nil || d.Incarnation != id.Incarnation { |
| return replicas.ErrFenced |
| } |
| - if replicas.RetryRequested(d) { |
| + if d.RetryRequest == request || d.ID != deployID || replicas.RetryRequested(d) { |
| return errRecordUnchanged |
| } |
| if d.PermitOutstanding() { |
| @@ -184,7 +195,7 @@ func RequestRecordReplicaRetry(ctx context.Context, s release.Store, id replicas |
| return replicas.ErrInvalid |
| } |
| next := d.Clone() |
| - next.RetryOf = d.ID |
| + next.RetryOf, next.RetryRequest = d.ID, request |
| next.Revision++ |
| rec.ReplicaDeploy = &next |
| return nil |
| @@ -199,17 +210,28 @@ func RequestRecordReplicaRetry(ctx context.Context, s release.Store, id replicas |
| // copy SR-4-C31 (provisional) |
| var ErrReplicaSwitchOpen = errors.New("another deploy is still finishing a copy's switch. wait for it to finish before deploying again") |
| -// ReplicaRetryTargets is the read-only half of an explicit retry of build: |
| -// the records among recs (on channel and unpinned, unless channel is "") |
| -// whose replicated attempt for build can be retried and is not yet asked |
| -// for. It refuses with ErrReplicaSwitchOpen, having written nothing, when |
| -// any record it would retry has an unresolved permit, so a refused retry |
| -// never leaves part of its intent behind. |
| -func ReplicaRetryTargets(recs []Record, channel, build string) ([]Record, error) { |
| +// ErrReplicaRetryUnreadable refuses an explicit retry when an instance |
| +// record of the app could not be read or decoded: it could hold an open |
| +// switch, so nothing is retried. |
| +// copy SR-4-C41 (provisional) |
| +var ErrReplicaRetryUnreadable = errors.New("an instance record could not be read, so nothing was retried. try again") |
| + |
| +// ReplicaRetryTargets is the read-only half of the explicit retry request |
| +// named request, over build: the records among recs (on channel and |
| +// unpinned, unless channel is "") whose replicated attempt for build can be |
| +// retried and that this request has not reached yet. recs must be the whole |
| +// app, read strictly; unreadable names records that were not, and any |
| +// refuses. It refuses with ErrReplicaSwitchOpen, having written nothing, |
| +// when any record it would retry has an unresolved permit, so a refused |
| +// retry never leaves part of its intent behind. |
| +func ReplicaRetryTargets(recs []Record, unreadable map[string]bool, channel, build, request string) ([]Record, error) { |
| + if len(unreadable) != 0 { |
| + return nil, ErrReplicaRetryUnreadable |
| + } |
| var out []Record |
| for _, rec := range recs { |
| d := rec.ReplicaDeploy |
| - if d == nil || d.Target.Version != build || (channel != "" && (rec.Channel != channel || rec.Pin != "")) { |
| + if d == nil || d.Target.Version != build || (channel != "" && (rec.Channel != channel || rec.Pin != "")) || (request != "" && d.RetryRequest == request) { |
| continue |
| } |
| if d.PermitOutstanding() { |
| @@ -222,18 +244,18 @@ func ReplicaRetryTargets(recs []Record, channel, build string) ([]Record, error) |
| return out, nil |
| } |
| -// RequestReplicaRetries arms the retries ReplicaRetryTargets chose, after |
| -// the caller's own preconditions passed. Each write is an idempotent replay |
| -// of the same request, so a caller that fails part way through runs the |
| -// same request again to finish it. |
| -func RequestReplicaRetries(ctx context.Context, s release.Store, targets []Record) error { |
| +// RequestReplicaRetries arms, for request, the retries ReplicaRetryTargets |
| +// chose, each against the attempt it validated, after the caller's own |
| +// preconditions passed. Running the same request again, with the same |
| +// key, finishes a partly written one and never re-arms a record it reached. |
| +func RequestReplicaRetries(ctx context.Context, s release.Store, targets []Record, request string) error { |
| for _, rec := range targets { |
| inc, err := Incarnation(rec.Account, rec.App, rec.Host, rec.CreatedAt) |
| if err != nil { |
| return err |
| } |
| id := replicas.Identity{Account: rec.Account, App: rec.App, Host: rec.Host, Incarnation: inc} |
| - if _, err := RequestRecordReplicaRetry(ctx, s, id, rec.ReplicaDeploy.ID); err != nil { |
| + if _, err := RequestRecordReplicaRetry(ctx, s, id, rec.ReplicaDeploy.ID, request); err != nil { |
| return err |
| } |
| } |
diff --git a/internal/provision/replicadeploy_test.go b/internal/provision/replicadeploy_test.go| index f15cdef15..1a86a5a5d 100644 |
| --- a/internal/provision/replicadeploy_test.go |
| +++ b/internal/provision/replicadeploy_test.go |
| @@ -200,7 +200,7 @@ func TestReplicaReleaseUnknownStopsDeployProvision(t *testing.T) { |
| if _, err := SetRecordReplicaRelease(ctx, s, id, r.ReplicaDeploy.Revision, d); err == nil { |
| t.Fatal("fresh ID without a retry request") |
| } |
| - if r, err = RequestRecordReplicaRetry(ctx, s, id, "deploy"); err != nil { |
| + if r, err = RequestRecordReplicaRetry(ctx, s, id, "deploy", "request-1"); err != nil { |
| t.Fatal(err) |
| } |
| d.RetryOf = "deploy" |
| @@ -261,7 +261,7 @@ func TestReplicaReleaseLegalTransitions(t *testing.T) { |
| if terminal == "released" { |
| attempt.Target = replicas.Build{Version: "v2", Digest: "digest-2"} |
| } else { |
| - if r, err = RequestRecordReplicaRetry(ctx, s, id, "deploy"); err != nil { |
| + if r, err = RequestRecordReplicaRetry(ctx, s, id, "deploy", "request-1"); err != nil { |
| t.Fatal(err) |
| } |
| attempt.RetryOf = "deploy" |
| @@ -558,7 +558,7 @@ func TestReplicaReleaseDurableAttemptWins(t *testing.T) { |
| if _, err := SetRecordReplicaRelease(w.ctx, w.s, w.id, w.revision(), forged); err == nil { |
| t.Fatal("RetryOf without a durable request") |
| } |
| - _, err := RequestRecordReplicaRetry(w.ctx, w.s, w.id, "deploy-2") |
| + _, err := RequestRecordReplicaRetry(w.ctx, w.s, w.id, "deploy-2", "request-1") |
| if end == "released" || end == "done" { |
| if err == nil { |
| t.Fatal("retry requested for a passed release") |
| @@ -575,7 +575,7 @@ func TestReplicaReleaseDurableAttemptWins(t *testing.T) { |
| } |
| w.rec, _ = GetRecord(w.ctx, w.s, w.id.Account, w.id.App, w.id.Host) |
| // A lost reply to the retry request: asking again changes nothing. |
| - again, err := RequestRecordReplicaRetry(w.ctx, w.s, w.id, "deploy-2") |
| + again, err := RequestRecordReplicaRetry(w.ctx, w.s, w.id, "deploy-2", "request-1") |
| if err != nil || again.RecordSeq != w.rec.RecordSeq { |
| t.Fatalf("retry replay: %v", err) |
| } |
| @@ -583,7 +583,7 @@ func TestReplicaReleaseDurableAttemptWins(t *testing.T) { |
| t.Fatal("plain begin consumed the retry") |
| } |
| w.release(t, "retry-1", swapTarget, "deploy-2", "pending") |
| - if w.rec.ReplicaDeploy.RetryOf != "deploy-2" || replicas.RetryRequested(w.rec.ReplicaDeploy) { |
| + if w.rec.ReplicaDeploy.RetryOf != "deploy-2" || w.rec.ReplicaDeploy.RetryRequest != "request-1" || replicas.RetryRequested(w.rec.ReplicaDeploy) { |
| t.Fatalf("retry not consumed: %+v", w.rec.ReplicaDeploy) |
| } |
| second := forged |
| @@ -633,7 +633,7 @@ func TestReplicaDeployPermitBlocksNewAttempt(t *testing.T) { |
| if _, err := SetRecordReplicaRelease(w.ctx, w.s, w.id, w.revision(), next); !errors.Is(err, replicas.ErrFenced) { |
| t.Fatalf("new attempt over a halted permit: %v", err) |
| } |
| - if _, err := RequestRecordReplicaRetry(w.ctx, w.s, w.id, "deploy-2"); err == nil { |
| + if _, err := RequestRecordReplicaRetry(w.ctx, w.s, w.id, "deploy-2", "request-1"); err == nil { |
| t.Fatal("retry over a halted permit") |
| } |
| // The old box returns and answers its permit: resolved, not completed. |
| @@ -718,3 +718,126 @@ func TestReplicaDeployLastGoodSurvivesFailures(t *testing.T) { |
| t.Fatal("a box wrote LastGood") |
| } |
| } |
| + |
| +// failingPutStore fails the next Put of key once. |
| +type failingPutStore struct { |
| + release.Store |
| + key string |
| + fail bool |
| +} |
| + |
| +func (s *failingPutStore) Put(ctx context.Context, key string, body []byte, etag string) (string, error) { |
| + if s.fail && key == s.key { |
| + s.fail = false |
| + return "", errors.New("store unavailable") |
| + } |
| + return s.Store.Put(ctx, key, body, etag) |
| +} |
| + |
| +// TestReplicaRetryReplayFinishesOnlyUnreached (R1, fix round 2): one retry |
| +// request arms A, fails on B, and A's retried release then fails. Replaying |
| +// the same request, with its original targets or after a fresh strict |
| +// read, finishes only B and never arms A's newer attempt; a new request |
| +// does. An unreadable record refuses the whole request. |
| +func TestReplicaRetryReplayFinishesOnlyUnreached(t *testing.T) { |
| + ctx := WithRecordSequence(context.Background()) |
| + base := release.NewDirStore(t.TempDir()) |
| + target := replicas.Build{Version: "v1", Digest: "canonical"} |
| + put := func(host string, d replicas.Deploy) { |
| + t.Helper() |
| + key := RecordKey("acme", "shop", host) |
| + raw, etag, err := base.Get(ctx, key) |
| + if err != nil { |
| + rec := Record{Schema: 1, Account: "acme", App: "shop", Host: host, Slug: host[:1], Channel: "edge", CreatedAt: time.Date(2026, 11, 1, 0, 0, 0, 0, time.UTC)} |
| + if err := CreateRecord(ctx, base, rec); err != nil { |
| + t.Fatal(err) |
| + } |
| + if raw, etag, err = base.Get(ctx, key); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + rec, err := DecodeRecord(raw) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + d.Incarnation, _ = Incarnation(rec.Account, rec.App, rec.Host, rec.CreatedAt) |
| + rec.ReplicaDeploy = &d |
| + raw, _ = json.Marshal(rec) |
| + if _, err := base.Put(ctx, key, raw, etag); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + get := func(host string) *replicas.Deploy { |
| + t.Helper() |
| + rec, err := GetRecord(ctx, base, "acme", "shop", host) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + return rec.ReplicaDeploy |
| + } |
| + list := func() ([]Record, map[string]bool) { |
| + t.Helper() |
| + recs, unreadable, err := ListRecordsStrict(ctx, base, "acme", "shop", 100) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + return recs, unreadable |
| + } |
| + put("a.example.com", replicas.Deploy{ID: "a1", Target: target, Phase: "failed", Term: "t", Revision: 3}) |
| + put("b.example.com", replicas.Deploy{ID: "b1", Target: target, Phase: "unknown", Term: "t", Revision: 3}) |
| + |
| + recs, unreadable := list() |
| + targets, err := ReplicaRetryTargets(recs, unreadable, "edge", "v1", "req-1") |
| + if err != nil || len(targets) != 2 { |
| + t.Fatalf("targets: %d %v", len(targets), err) |
| + } |
| + failing := &failingPutStore{Store: base, key: RecordKey("acme", "shop", "b.example.com"), fail: true} |
| + if err := RequestReplicaRetries(ctx, failing, targets, "req-1"); err == nil { |
| + t.Fatal("B's failed write was not reported") |
| + } |
| + if a := get("a.example.com"); !replicas.RetryRequested(a) || a.RetryRequest != "req-1" { |
| + t.Fatalf("A not armed: %+v", a) |
| + } |
| + // A's coordinator consumes the retry, and the new attempt fails too. |
| + put("a.example.com", replicas.Deploy{ID: "a2", Target: target, Phase: "failed", Term: "t2", RetryOf: "a1", RetryRequest: "req-1", Revision: 6}) |
| + before := get("a.example.com") |
| + |
| + // Replay with the request's original targets: A is newer, B finishes. |
| + if err := RequestReplicaRetries(ctx, base, targets, "req-1"); err != nil { |
| + t.Fatal(err) |
| + } |
| + if a := get("a.example.com"); replicas.RetryRequested(a) || a.Revision != before.Revision { |
| + t.Fatalf("replay re-armed A's newer attempt: %+v", a) |
| + } |
| + if b := get("b.example.com"); !replicas.RetryRequested(b) || b.RetryRequest != "req-1" { |
| + t.Fatalf("replay did not finish B: %+v", b) |
| + } |
| + |
| + // Replay after a fresh strict read selects nothing this request reached. |
| + put("b.example.com", replicas.Deploy{ID: "b1", Target: target, Phase: "unknown", Term: "t", Revision: 3}) |
| + recs, unreadable = list() |
| + targets, err = ReplicaRetryTargets(recs, unreadable, "edge", "v1", "req-1") |
| + if err != nil || len(targets) != 1 || targets[0].Host != "b.example.com" { |
| + t.Fatalf("fresh replay targets: %+v %v", targets, err) |
| + } |
| + // A new request is a new retry of A's newer failed attempt. |
| + targets, err = ReplicaRetryTargets(recs, unreadable, "edge", "v1", "req-2") |
| + if err != nil || len(targets) != 2 { |
| + t.Fatalf("new request targets: %d %v", len(targets), err) |
| + } |
| + if err := RequestReplicaRetries(ctx, base, targets, "req-2"); err != nil { |
| + t.Fatal(err) |
| + } |
| + if a := get("a.example.com"); !replicas.RetryRequested(a) || a.ID != "a2" || a.RetryRequest != "req-2" { |
| + t.Fatalf("new request did not arm A: %+v", a) |
| + } |
| + |
| + // Any record that cannot be read refuses the request. |
| + if _, err := base.Put(ctx, RecordKey("acme", "shop", "c.example.com"), []byte("not a record"), ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + recs, unreadable = list() |
| + if _, err := ReplicaRetryTargets(recs, unreadable, "edge", "v1", "req-3"); !errors.Is(err, ErrReplicaRetryUnreadable) { |
| + t.Fatalf("unreadable record: %v", err) |
| + } |
| +} |
diff --git a/internal/provision/stateless_replicas_4_task1_census_test.go b/internal/provision/stateless_replicas_4_task1_census_test.go| index 7f1260cd9..5deab6d4c 100644 |
| --- a/internal/provision/stateless_replicas_4_task1_census_test.go |
| +++ b/internal/provision/stateless_replicas_4_task1_census_test.go |
| @@ -48,6 +48,17 @@ package provision |
| // handleReplicaDeploy: the order |
| // now reads the fleet's heartbeats (fleetBoxView.Fresh) under the same |
| // lock before the same typed write. |
| +// |
| +// Fix round 2 (re-review 1, #2 and #3), self-review: |
| +// - RequestRecordReplicaRetry takes the request's key and the attempt it |
| +// validated: a record this request already reached, or whose current |
| +// attempt is newer, is unchanged, so a replay never re-arms; it writes |
| +// RetryRequest beside RetryOf. Same CAS, field key and lock. |
| +// - RequestReplicaRetries and armReplicaRetriesLocked pass the key. The |
| +// console judges the app through listRecordsStrict and refuses any |
| +// unreadable record before any write; the direct CLI writes no record. |
| +// - SetRecordReplicaRelease carries RetryRequest onto the consuming |
| +// attempt and through its own transitions, and refuses it from a box. |
| func statelessReplicas4Task1WriteCensusInventory() []censusEntry { |
| entries := append([]censusEntry(nil), billingOverviewSpeedWriteCensusInventory()...) |
| for _, r := range []censusEntry{ |
| @@ -62,11 +73,11 @@ func statelessReplicas4Task1WriteCensusInventory() []censusEntry { |
| {"internal/provision/replicaassignment.go", "HaltRecordReplicaDeploy", "record-writer", "key:HaltRecordReplicaDeploy,key:updateRecord", "f8044b6f03638c0098266b603a49203537980572438a9d657a1474998d2ab6b8"}, |
| {"internal/provision/replicaassignment.go", "RecordReplicaRetired", "record-writer", "key:RecordReplicaRetired,key:updateRecord", "c5ee5437291b4f39966cb6bd7e155ae98a9eaa041125be0b6195a488bd6da9e9"}, |
| {"internal/provision/replicaassignment.go", "SetRecordReplicaAssignment", "record-writer", "key:SetRecordReplicaAssignment,key:updateRecord", "504fc1b4e3e2af75fe2088d033370e881d7e8be7ecc291b4a60c81eb16283754"}, |
| - {"internal/provision/replicadeploy.go", "RequestRecordReplicaRetry", "record-writer", "key:RequestRecordReplicaRetry,key:updateRecord", "accd7b18ab0edd0c9ac67992b1594a4c59ae89866e6472465e650fa2811cf333"}, |
| + {"internal/provision/replicadeploy.go", "RequestRecordReplicaRetry", "record-writer", "key:RequestRecordReplicaRetry,key:updateRecord", "ea328eb39d8a097b232d394db18c66d4044c4ec428bab12ddee0c51c5967a893"}, |
| {"internal/provision/replicadeploy.go", "SetRecordReplicaDeploy", "record-writer", "key:SetRecordReplicaDeploy,key:updateRecord", "483c43a7982c699d0939910786ca9d01f41760a5724965d0ef4a6106a08844c1"}, |
| - {"internal/provision/replicadeploy.go", "SetRecordReplicaRelease", "record-writer", "key:SetRecordReplicaRelease,key:updateRecord", "a43483f00d489665844cd469b937c30d9a2aae5f0eaddb5b6b42dd917e5b6ad9"}, |
| - {"internal/console/replicadeploy.go", "Server.armReplicaRetriesLocked", "record-writer", "key:RequestReplicaRetries", "b4f544ab698e115ed1ae2069e842c96401d20044145588995a4062a306fbfc9f"}, |
| - {"internal/provision/replicadeploy.go", "RequestReplicaRetries", "record-writer", "key:RequestRecordReplicaRetry,key:RequestReplicaRetries", "6befe09ed6ba676c633da20db9917497ec8c0dca8372e0fc503786c1012aa684"}, |
| + {"internal/provision/replicadeploy.go", "SetRecordReplicaRelease", "record-writer", "key:SetRecordReplicaRelease,key:updateRecord", "79d300ee48a49ca76a43f876a17d3d48e541bc7e22deb64a638e1d09d3ee3689"}, |
| + {"internal/console/replicadeploy.go", "Server.armReplicaRetriesLocked", "record-writer", "key:RequestReplicaRetries", "c00b09cd8cd01006ded2f3e0ede4a0ebb56ca90d0a54e2f8df06745258935b9e"}, |
| + {"internal/provision/replicadeploy.go", "RequestReplicaRetries", "record-writer", "key:RequestRecordReplicaRetry,key:RequestReplicaRetries", "5359b151b81566b13793595e1876645155d3c06d489d4c1c1d95fcd8711f2341"}, |
| } { |
| replaced := false |
| for i, e := range entries { |
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv| index 2816becb9..49c2611a3 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-chain.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-chain.tsv |
| @@ -170,3 +170,4 @@ plan14-root-reads-group-verb-followups.tsv 9c74b9876a13a3a3802860fe44406898c8bcb |
| plan14-root-reads-group-read-transport-retry.tsv 9c74b9876a13a3a3802860fe44406898c8bcbfd3bd22e8172a59a02674c3b4af |
| plan14-root-reads-stateless-replicas-4-task1.tsv 3f066208f5e5fa2b9854f30118a9a2707f3a5a51bcf55ae6b0949cb0307804f5 |
| plan14-root-reads-stateless-replicas-4-task1-fix1.tsv 3f066208f5e5fa2b9854f30118a9a2707f3a5a51bcf55ae6b0949cb0307804f5 |
| +plan14-root-reads-stateless-replicas-4-task1-fix2.tsv 3f066208f5e5fa2b9854f30118a9a2707f3a5a51bcf55ae6b0949cb0307804f5 |
diff --git a/internal/provision/testdata/plan14-root-reads-stateless-replicas-4-task1-fix2.tsv b/internal/provision/testdata/plan14-root-reads-stateless-replicas-4-task1-fix2.tsv| new file mode 100644 |
| index 000000000..e276e1c37 |
| --- /dev/null |
| +++ b/internal/provision/testdata/plan14-root-reads-stateless-replicas-4-task1-fix2.tsv |
| @@ -0,0 +1,5 @@ |
| +# Census overlay stateless-replicas-4-task1-fix2, written by census-propose (#369). census-ruling-stateless-replicas-4-task1-fix2, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-stateless-replicas-4-task1-fix2.md. |
| +# 0 body, 0 sites, 3 envelope: each changed unit re-frozen at its existing disposition with its claim appended. |
| +@coverage . 19d028cb6afb9afa3ddba6b392486fa6e8e0f3b09ded227c293ec54781a0d7e0 |
| +@coverage internal/provision fd602187e257baf84b7ab58423036d038ede62e38438fb2f675dd69351a39cfc |
| +@coverage internal/replicas 43ed230cc181c643665813602af2fe46b2e62a2096b34f61bbd46fe6c1b4641b |
diff --git a/internal/replicas/types.go b/internal/replicas/types.go| index f9abb0e89..b197cd1f2 100644 |
| --- a/internal/replicas/types.go |
| +++ b/internal/replicas/types.go |
| @@ -72,6 +72,10 @@ type Deploy struct { |
| // unknown attempt. On a different ID it names the attempt whose retry |
| // this attempt consumed. |
| RetryOf string `json:"retry_of,omitempty"` |
| + // RetryRequest names the explicit retry request that wrote RetryOf. It |
| + // rides onto the attempt that consumes the retry, so a replay of the |
| + // same request finishes only the records it has not reached. |
| + RetryRequest string `json:"retry_request,omitempty"` |
| // Swap is the box-by-box switch after a passed release. |
| Swap Swap `json:"swap,omitzero"` |
| Revision uint64 `json:"revision,omitempty"` |
diff --git a/replica_promote_retry_test.go b/replica_promote_retry_test.go| index d725f2606..09e1d446c 100644 |
| --- a/replica_promote_retry_test.go |
| +++ b/replica_promote_retry_test.go |
| @@ -32,8 +32,9 @@ func dirSnapshot(t *testing.T, s release.Store) map[string]string { |
| // TestReplicaDirectPromoteRetry: direct-bucket `carlos promote --retry` |
| // refuses, writing nothing, when the channel has an instance with a copy |
| -// assignment or a stateless replica deploy, and points at the console. The |
| -// same command still renews the pointer for a channel without one. |
| +// assignment or a stateless replica deploy, and points at the console; it |
| +// also refuses when any record of the app cannot be read. The same command |
| +// still renews the pointer for a channel without one. |
| func TestReplicaDirectPromoteRetry(t *testing.T) { |
| run, bucket := versioningCLI(t) |
| if out, err := run("version", "target", "-app", "kass", "0.5.0"); err != nil { |
| @@ -88,6 +89,23 @@ func TestReplicaDirectPromoteRetry(t *testing.T) { |
| t.Fatal(err) |
| } |
| } |
| + // A record that cannot be read could be a replicated one: refused, on |
| + // any channel, with nothing written. |
| + corrupt := provision.RecordKey(release.OpsAccount, "kass", "c.kass.example.com") |
| + if _, err := store.Put(ctx, corrupt, []byte("{not a record"), ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + before := dirSnapshot(t, store) |
| + out, err := run("promote", "-app", "kass", "-retry", "0.5.0-1", "beta") |
| + if err == nil || !strings.Contains(out, "an instance record could not be read, so nothing was retried") { |
| + t.Fatalf("unreadable record: %v\n%s", err, out) |
| + } |
| + if !reflect.DeepEqual(dirSnapshot(t, store), before) { |
| + t.Fatal("a refused retry wrote") |
| + } |
| + if err := store.Delete(ctx, corrupt); err != nil { |
| + t.Fatal(err) |
| + } |
| // beta has no replicated instance: the direct retry renews as before. |
| if out, err := run("promote", "-app", "kass", "-retry", "0.5.0-1", "beta"); err != nil { |
| t.Fatalf("plain retry: %v\n%s", err, out) |