carlos / platform Public

fix: bound replica worker proof; baseline before adopt on retry

Stateless replicas Plan 4 Task 2, fix round 3 (#511), as ruled:

- Worker proof timing: a worker start in flight keeps the step open, a
  gate-refused start (startFailed with no restart) is pending, and a
  worker that never started is judged only after residentPoll +
  workerStartBound from its registration (now recorded). A crash or
  restart still answers switched with workers failed at once. The wait
  is bounded, so it cannot wedge the permit.
- A completed box (or any box once done) checks its baseline before the
  adopt path, so it restarts on the target while a retry is requested;
  the passed target still runs the escrow recovery the adopt path ran.
- Census overlay task2-fix3 and the record-write re-digest.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 99b1a539c44e0784f4f026b6fa130209aadad18f parent 6bae56b
8 files changed, +210 −38
  • docs/superpowers/notes/census-proposal-stateless-replicas-4-task2-fix3.md +25 −0
  • internal/activator/replicadeploy.go +29 −23
  • internal/activator/replicadeploy_test.go +112 −9
  • internal/activator/rootfsworkers.go +7 −2
  • internal/activator/stateless.go +17 −3
  • internal/provision/stateless_replicas_4_task2_census_test.go +8 −1
  • internal/provision/testdata/plan14-root-reads-chain.tsv +1 −0
  • internal/provision/testdata/plan14-root-reads-stateless-replicas-4-task2-fix3.tsv +11 −0

CI failed — run details

Intent

Human

<task-notification> <task-id>a4621592a91bafe83</task-id> <tool-use-id>toolu_01HPDKQuo752LFuGckat1qoQ</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/72128d15-58b8-452f-9f7e-8e864e8854d2/tasks/a4621592a91bafe83.output</output-file> <status>completed</status> <summary>Agent "Implement Plan 4 Task 2" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>- **Status:** DONE_WITH_CONCERNS - **Commit:** 6bae56b5 fix: resolve replica permits on worker failure; baseline per box, on top of e19f02d9. Local only; the tree is clean, and the R8 test is unchanged as ruled. - **Tests:** RED against e19f02d9's code shows every new case failing (the rollback and clean-worker cases already passed there, as expected). GREEN on all Task 2 tests across six packages (replicas, provision, rollout, activator, host, console), plus the targeted runs, census, HA guards, copy checks, the darwin, windows and linux/arm64 builds, vet and gofmt. All 4 mutations were killed. - **Worker failure:** a switch whose new workers crash, restart, or have not started by the end of the settle window now answers "switched, workers failed". The ACK resolves the permit and halts the deploy with the box named (new provisional copy row SR-4-C46), and a retry, fix build or rollback can begin. No worker is restarted to try for a clean proof. - **Per-box baseline:** each box's baseline now comes from the record. It is the target for a box that completed its switch, or for every box once the deploy is done; otherwise it is Previous. Starting that baseline needs no release, whatever the pointer says. Only a build that is neither this box's baseline nor its permitted target, and that the pointer names, begins a new attempt. - **Concerns:** - Task 2 now has 18 mutations, against the plan's 10. - A worker that is slower to start than the settle window halts the deploy rather than waiting (an explicit retry clears it). - A completed box can return to Previous only through a new attempt. - **Census:** proposal stateless-replicas-4-task2-fix2 is written (seal 5f83de2e…). Nothing is posted to #280. - **Cleanup:** my scratch and `/tmp/g` leftovers are deleted. - **Report:** /home/paulca/amadan.net/carlos/platform/.claude/worktrees/stateless-replicas-4/.superpowers/sdd/2026-11-01-stateless-replicas-4-deploy-and-drill/task-2-report.md (the "Fix round 2" section)</result> <usage><subagent_tokens>697644</subagent_tokens><tool_uses>25</tool_uses><duration_ms>1109711</duration_ms></usage> </task-notification>

Human

<task-notification> <task-id>b430ztox7</task-id> <tool-use-id>toolu_01EjBfYen8Pz4UAgcyWLo3Au</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/72128d15-58b8-452f-9f7e-8e864e8854d2/tasks/b430ztox7.output</output-file> <status>completed</status> <summary>Background command "Astra re-review of Task 2 round 2" completed (exit code 0)</summary> </task-notification>

Human

<task-notification> <task-id>b4djzomdl</task-id> <tool-use-id>toolu_01TRTrYXoDBdHHEMMbg7Y6Uc</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/72128d15-58b8-452f-9f7e-8e864e8854d2/tasks/b4djzomdl.output</output-file> <status>completed</status> <summary>Background command "Fable re-review of Task 2 round 2" completed (exit code 0)</summary> </task-notification>

Human

<cross-session-message from="uds:/run/user/1001/cc-socks/3488194.sock" from-name="amadan-13" from-mode="bypass"> amadan-13, heads-up: carlos/platform's CI goes back on hosted for about an hour from now. The GOTMPDIR fix is live (2c2fc7d): t.TempDir() is back on /tmp, which should clear the EXDEV, chroot-fixture and disk-full failures. I'm timing three re-runs of main (32 vCPU cold, 32 warm, 16). Your pushes in that window run on hosted too. If anything fails that looks environmental, tell me. </cross-session-message>

Attributed to this commit: 39.5 g CO₂e (4,998,602 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/docs/superpowers/notes/census-proposal-stateless-replicas-4-task2-fix3.md b/docs/superpowers/notes/census-proposal-stateless-replicas-4-task2-fix3.md
new file mode 100644
index 000000000..d74e3046a
--- /dev/null
+++ b/docs/superpowers/notes/census-proposal-stateless-replicas-4-task2-fix3.md
@@ -0,0 +1,25 @@
+# Census approval: stateless-replicas-4-task2-fix3
+
+Ruling `census-ruling-stateless-replicas-4-task2-fix3`. 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).
+
+| unit | change | read sites | what changed |
+|---|---|---|---|
+| `internal/activator/replicadeploy.go` `Service.ReplicaSwap` | body | unchanged (4) | Task 2 fix round 3: replicaSwitchProof keeps the step open while a worker start is in flight or a gate-refused start waits for its retry, and judges a never-started worker only after residentPoll + workerStartBound from registration (Service clock); a crash or restart still answers workers failed. Reads only the in-memory entry; no store, file or root call. |
+| `internal/activator/replicadeploy.go` `Service.replicaSettle` | body | unchanged (2) | Task 2 fix round 3: the same bounded worker judgment (replicaSwitchProof). Same in-memory reads. |
+| `internal/activator/rootfsworkers.go` `Service.registerRootfsWorkers` | body | unchanged (5) | Task 2 fix round 3: each registered worker records its registration time (registered: a.now()), an in-memory field the proof reads; no read added. |
+| `internal/activator/stateless.go` `Service.prepareStateless` | sites | +registry:Stateless, +whole:Route Ɨ2 | Task 2 fix round 3: this box baseline is checked before the adopt path, so a completed box restarts on the target while a retry is requested; for the passed target it calls the existing escrow initializer (prepareStatelessEscrow) that the adopt path ran, with the same route and identity. No new reader; no record write. |
+
+Envelopes re-pinned: `internal/activator`.
+
+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.
+
+Recorded dispositions, which each change must still satisfy:
+
+- `internal/activator/replicadeploy.go` `Service.ReplicaSwap`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-stateless-replicas-4-task2;basis=Task 2: new. Checks the permit (box label, phase released, not halted, ActiveBox, build), refuses a hold, asks tenantStartRefusal on the in-memory entry route, then either re-proves an existing switch (replicaSettle) or runs the existing Swap as a canary and checks replicaStepProven. Reads the in-memory entry route only; no store, file or root call of its own.;rev3=census-ruling-stateless-replicas-4-task2-fix1;basis=Task 2 fix round 1: proof-only steps (an already switched copy, a halted permit, a permit whose successor failed here) skip the start gates because nothing starts; a failed successor answers kept only after replicaKeptProven (its stop proven, an empty operation set). Reads only the in-memory entry route; no store, file or root call.;rev3=census-ruling-stateless-replicas-4-task2-fix2;basis=Task 2 fix round 2: the switch proof is replicaSwitchProof, which also reports WorkersFailed (switched, the new workers crashed or did not start within the settle window) so the step answers instead of staying open. Reads only the in-memory entry; no store, file or root call.
+- `internal/activator/replicadeploy.go` `Service.replicaSettle`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-stateless-replicas-4-task2;basis=Task 2: new. GET / health (genHealthy) and the settle window on the current in-memory generation, then replicaStepProven; reads the in-memory entry route only.;rev3=census-ruling-stateless-replicas-4-task2-fix2;basis=Task 2 fix round 2: after the settle window the proof judges the new workers (replicaSwitchProof, settled); a failure answers switched with WorkersFailed. Same in-memory reads.
+- `internal/activator/rootfsworkers.go` `Service.registerRootfsWorkers`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-rootfs-apps-3-workers;basis=rootfs Plan 3 Group W: the one place a generation's declared workers are registered; reads the workers the generation declares through the existing staged-manifest read of the backend's Processes (the manifest root's staging wrote, checked against the identity's path and digest), registers each as pending on the host's own entry; an unreadable or invalid declaration registers none and web serves; starts nothing
+- `internal/activator/stateless.go` `Service.prepareStateless`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-stateless-replicas-1;basis=Task 3a: Capture RecordFacts from the existing record source, obtain the durable FailureBook deploy ID, and call Task 2 PrepareStatelessRelease with the canonical verdict/digest carrier. Carry a successful attempt through its hold only after another current-record check; no serving lease or polling loop. Fix 3a round 1 I2: preparation uses reconcile observations and records the successful deploy ID. Carry prepared evidence through hold; fresh backend read must confirm that same released deploy before web runs.;rev3=census-ruling-stateless-failed-release-held;basis=For recovery onto a different installed version's exact committed good version and artifact digest, retain recovery evidence without selecting or writing another deploy. Adds the existing committedGood registry read, with its route and incarnation check. Canonical storage declaration and observed lifetime gates remain.;rev3=census-ruling-stateless-replicas-4-task1;basis=R1: no longer calls ReplicaDeployID before preparation; hands the same a.ReplicaDeployID selector to prepareStatelessRelease, which calls it only after coordinator term acquisition. The ObservedReplicaRelease call stays as a validity check. Same read sites; no new read, write or authority.;rev3=census-ruling-stateless-replicas-4-task2;basis=Task 2 (D4): for a set row, prepares the record baseline with no release, and refuses a build the row Version does not name before any release; reads the route it is handed (FleetBoxes, Version). No store read or write added.;rev3=census-ruling-stateless-replicas-4-task2-fix1;basis=Task 2 fix round 1: for a set row, a build its pointer does not name starts only as the record baseline or the committed permitted target, the latter adopted through prepareStatelessRelease durable path (never a new attempt); a named build, a rollback included, takes the release path. The added reads are the handed route (FleetBoxes, Version) and a copy of it with Stateless set for the adoption, as the release path already builds. No store read or write added.;rev3=census-ruling-stateless-replicas-4-task2-fix2;basis=Task 2 fix round 2: for a set row the no-release start is decided per box from the record (this box baseline, or its permitted target adopted through the durable path), whatever the pointer says; only a build that is neither and that the pointer names begins a new attempt. Same reads (the handed route and its copy); no store read or write added.
+
+Seal: `5f83de2e018b47543789a8dbe2cccb86b2d644fbe9ee5771e5d621704ae46e0b` → `bd25367161555e8a9c5b0df079ad2d8eb648ebaeae3f407e6c638f2f7f01605b`.
+
+Overlay: `internal/provision/testdata/plan14-root-reads-stateless-replicas-4-task2-fix3.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`.
diff --git a/internal/activator/replicadeploy.go b/internal/activator/replicadeploy.go
index 419e6006c..c47abffab 100644
--- a/internal/activator/replicadeploy.go
+++ b/internal/activator/replicadeploy.go
@@ -182,10 +182,9 @@ func (a *Service) ReplicaSwap(ctx context.Context, at Attempt, deploy replicas.D
res := a.Swap(ctx, at, newest)
switch res.Outcome {
case SwapDone:
- // The workers were only registered at the switch; the next step
- // judges them after its settle window (replicaSettle), unless one
- // has already failed.
- res.Proven, res.WorkersFailed = a.replicaSwitchProof(at.Host, res.Gen, false)
+ // The workers were only registered at the switch: a later step
+ // judges them (replicaSwitchProof), unless one has already failed.
+ res.Proven, res.WorkersFailed = a.replicaSwitchProof(at.Host, res.Gen)
if !res.Proven && res.Reason == "" {
res.Reason = "the switch is not yet proven; the step stays open"
}
@@ -224,7 +223,7 @@ func (a *Service) replicaSettle(ctx context.Context, host string, g Gen) SwapRes
return abandon(errSwapStopped)
}
res := SwapResult{Outcome: SwapDone, Gen: g}
- res.Proven, res.WorkersFailed = a.replicaSwitchProof(host, g, true)
+ res.Proven, res.WorkersFailed = a.replicaSwitchProof(host, g)
if !res.Proven {
res.Reason = "the switch is not yet proven; the step stays open"
}
@@ -235,18 +234,21 @@ func (a *Service) replicaSettle(ctx context.Context, host string, g Gen) SwapRes
// current, live, awake generation, no other generation left in the
// operation set (a retiring one whose stop was not proven stays there until
// the sweep proves it), and no worker of another generation, stray
-// included. The new generation's workers then decide workersFailed:
-// - every worker started, alive and never restarted: a clean switch;
-// - any worker crashed, restarted, ended in a crash loop or failed to
-// start: switched, workers failed;
-// - any worker not yet started: not proven while settled is false (its
-// tick has not run since the switch registered it), and switched,
-// workers failed once the step's settle window has passed.
+// included. The new generation's workers then decide:
+// - any worker that crashed or restarted (restarts > 0, a crash loop, or
+// an exit after it started): switched, workers failed, at once;
+// - any worker start in flight, or a worker not started yet (a gate's
+// refusal, startFailed with restarts == 0, is not yet a failure):
+// not proven, no answer, until residentPoll + workerStartBound have
+// passed since its registration; then it never started, and the
+// answer is switched, workers failed;
+// - every worker started and alive: switched, clean.
//
-// A worker failure is still an answer: the box switched, the ack resolves
-// the permit and halts the deploy, so no worker failure leaves a permit
-// open. Nothing here restarts a worker to try for a clean proof.
-func (a *Service) replicaSwitchProof(host string, g Gen, settled bool) (proven, workersFailed bool) {
+// The wait is bounded by workerStartBound, so a worker never leaves a
+// permit open for long: a worker failure is still an answer, whose ack
+// resolves the permit and halts the deploy. Nothing here restarts a
+// worker to try for a clean proof.
+func (a *Service) replicaSwitchProof(host string, g Gen) (proven, workersFailed bool) {
a.mu.Lock()
defer a.mu.Unlock()
e := a.entries[host]
@@ -256,21 +258,25 @@ func (a *Service) replicaSwitchProof(host string, g Gen, settled bool) (proven,
if len(e.ops.members) != 0 || len(e.strayRootfsWorkers) != 0 {
return false, false
}
- pending := false
+ now, open := a.now(), false
for _, wk := range e.rootfsWorkers {
switch {
case wk.gen != g.N:
return false, false
- case wk.restarts != 0 || wk.crashLoop || wk.startFailed || (wk.proc != nil && wk.proc.Exited()):
+ case wk.restarts != 0 || wk.crashLoop || (wk.proc != nil && wk.proc.Exited()):
workersFailed = true
- case wk.starting || wk.proc == nil:
- pending = true
+ case wk.starting:
+ open = true
+ case wk.proc == nil && now.Before(wk.registered.Add(residentPoll+workerStartBound)):
+ open = true
+ case wk.proc == nil:
+ workersFailed = true // never started within its bound
}
}
- if pending && !settled && !workersFailed {
- return false, false
+ if workersFailed {
+ return true, true
}
- return true, workersFailed || pending
+ return !open, false
}
// replicaKeptProven is a "kept" answer's proof: host's current generation
diff --git a/internal/activator/replicadeploy_test.go b/internal/activator/replicadeploy_test.go
index a2de204d6..c8bfec08e 100644
--- a/internal/activator/replicadeploy_test.go
+++ b/internal/activator/replicadeploy_test.go
@@ -545,16 +545,18 @@ func TestReplicaSwapProofOnlySteps(t *testing.T) {
// TestReplicaSwapWaitsForWorkers (fix rounds 1 and 2): right after the
// switch the step is not proven while the new workers have not started.
-// After the settle window it answers: switched and clean when every worker
-// started and is alive; switched with WorkersFailed when a worker crashed
-// or never started, so the permit resolves and the deploy halts instead of
-// staying open. Nothing restarts a worker to try for a clean proof.
+// It then answers: switched and clean when every worker started and is
+// alive; switched with WorkersFailed when a worker crashed, so the permit
+// resolves and the deploy halts instead of staying open. Nothing restarts
+// a worker to try for a clean proof.
func TestReplicaSwapWaitsForWorkers(t *testing.T) {
prev := swapSettle
swapSettle = 20 * time.Millisecond
t.Cleanup(func() { swapSettle = prev })
ctx := context.Background()
- for _, tc := range []string{"started", "crashes on start", "never starts"} {
+ // A worker that never starts is judged against its start bound
+ // (TestReplicaSwapWorkerProofTiming, fix round 3).
+ for _, tc := range []string{"started", "crashes on start"} {
t.Run(tc, func(t *testing.T) {
r := newReplicaSetRig(t, "b", replicaAttempt("released", replicas.Swap{Order: []string{"a", "b"}, Completed: []string{"a"}, ActiveBox: "b", Permit: 5}))
workers := &fakeWorkerBackend{killBackend: &killBackend{fakeBackend: r.b.fakeBackend}}
@@ -565,10 +567,8 @@ func TestReplicaSwapWaitsForWorkers(t *testing.T) {
if res.Outcome != SwapDone || res.Proven {
t.Fatalf("answered before its workers started: %+v", res)
}
- if tc != "never starts" {
- r.a.rootfsTick()
- waitFor(t, "the worker", func() bool { return workers.alive() == 1 })
- }
+ r.a.rootfsTick()
+ waitFor(t, "the worker", func() bool { return workers.alive() == 1 })
if tc == "crashes on start" {
workers.lastWorker(t, "jobs").exit("exited", "1")
}
@@ -671,3 +671,106 @@ func TestReplicaSwapRetiresAfterRoutedRequests(t *testing.T) {
t.Fatal("retirement did not end once the routed request finished")
}
}
+
+// TestReplicaSwapWorkerProofTiming (fix round 3): a worker is judged only
+// once its start could have ended. A start in flight keeps the step open
+// (no answer), then proves clean once it has started. A start a gate
+// refused is not a failure: the retry that succeeds proves clean. A worker
+// that never started is answered "workers failed" only after residentPoll
+// + workerStartBound from its registration, which bounds the wait.
+func TestReplicaSwapWorkerProofTiming(t *testing.T) {
+ prev := swapSettle
+ swapSettle = 20 * time.Millisecond
+ t.Cleanup(func() { swapSettle = prev })
+ ctx := context.Background()
+ setup := func(t *testing.T) (*replicaSetRig, *fakeWorkerBackend) {
+ r := newReplicaSetRig(t, "b", replicaAttempt("released", replicas.Swap{Order: []string{"a", "b"}, Completed: []string{"a"}, ActiveBox: "b", Permit: 5}))
+ workers := &fakeWorkerBackend{killBackend: &killBackend{fakeBackend: r.b.fakeBackend}}
+ r.a.backend = &statelessWakeBackend{r.b, workers}
+ r.b.procs["v2"] = map[string]release.Process{release.ProcessWeb: {Command: []string{"serve"}}, "jobs": {Command: []string{"jobs"}}}
+ r.awake(t)
+ if res := r.a.ReplicaSwap(ctx, r.attempt(CauseRelease, ModeOverlap), *r.store.snapshot(), "b", newestOne); res.Outcome != SwapDone || res.Proven {
+ t.Fatalf("switch: %+v", res)
+ }
+ return r, workers
+ }
+ step := func(r *replicaSetRig) SwapResult {
+ return r.a.ReplicaSwap(ctx, r.attempt(CauseRelease, ModeOverlap), *r.store.snapshot(), "b", newestOne)
+ }
+
+ t.Run("start in flight", func(t *testing.T) {
+ r, workers := setup(t)
+ block, entered := make(chan struct{}), make(chan string, 1)
+ workers.wmu.Lock()
+ workers.block, workers.entered = block, entered
+ workers.wmu.Unlock()
+ t.Cleanup(func() {
+ select {
+ case <-block:
+ default:
+ close(block)
+ }
+ })
+ r.a.rootfsTick()
+ <-entered
+ r.clk.advance(residentPoll + workerStartBound + time.Second) // even past the bound
+ if res := step(r); res.Proven {
+ t.Fatalf("answered while a worker start is in flight: %+v", res)
+ }
+ close(block)
+ waitFor(t, "the worker", func() bool { return workers.alive() == 1 })
+ if res := step(r); res.Outcome != SwapDone || !res.Proven || res.WorkersFailed {
+ t.Fatalf("after the start: %+v", res)
+ }
+ })
+ t.Run("gate refused, then started", func(t *testing.T) {
+ r, workers := setup(t)
+ r.a.TenantStartsClosed = func() bool { return true }
+ r.a.rootfsTick()
+ waitFor(t, "the refused start", func() bool {
+ r.a.mu.Lock()
+ defer r.a.mu.Unlock()
+ wk := r.a.entries[r.rt.Host].rootfsWorkers["jobs"]
+ return wk != nil && !wk.starting && wk.startFailed
+ })
+ if res := step(r); res.Proven {
+ t.Fatalf("a refused start was judged: %+v", res)
+ }
+ r.a.TenantStartsClosed = nil
+ r.clk.advance(sidecarRestartBase + time.Second)
+ r.a.rootfsTick()
+ waitFor(t, "the retried worker", func() bool { return workers.alive() == 1 })
+ if res := step(r); res.Outcome != SwapDone || !res.Proven || res.WorkersFailed {
+ t.Fatalf("after the retry: %+v", res)
+ }
+ })
+ t.Run("never started", func(t *testing.T) {
+ r, _ := setup(t)
+ if res := step(r); res.Proven {
+ t.Fatalf("judged before the bound: %+v", res)
+ }
+ r.clk.advance(residentPoll + workerStartBound + time.Second)
+ if res := step(r); res.Outcome != SwapDone || !res.Proven || !res.WorkersFailed {
+ t.Fatalf("after the bound: %+v", res)
+ }
+ })
+}
+
+// TestReplicaReturnsAfterDeployUnderRetry (fix round 3): a box that
+// completed its switch, under a halt with a retry requested, cold-starts
+// its baseline (the target) with no release and no refusal; consuming the
+// retry stays with the coordinator's release path.
+func TestReplicaReturnsAfterDeployUnderRetry(t *testing.T) {
+ r := newReplicaSetRig(t, "a", func(inc string) *replicas.Deploy {
+ d := replicaAttempt("released", replicas.Swap{Order: []string{"a", "b"}, Completed: []string{"a"}, Halted: true})(inc)
+ d.RetryOf = d.ID
+ return d
+ })
+ r.setPlan(WakePlan{Boot: r.next, Mode: ModeOverlap, FirstWake: true, Token: 1})
+ if err := waitErr(t, r.wake(r.a)); err != nil || !r.started("v2") {
+ t.Fatalf("the completed box could not restart under a requested retry: %v %v", err, r.b.events())
+ }
+ if d := r.store.snapshot(); d.ID != "deploy-v2" || d.Revision != 5 || r.store.acquires != 0 || len(r.b.releaseStarts()) != 0 {
+ t.Fatalf("the restart consumed the retry: %+v (acquires %d)", d, r.store.acquires)
+ }
+}
diff --git a/internal/activator/rootfsworkers.go b/internal/activator/rootfsworkers.go
index db62c07a2..6462f55a5 100644
--- a/internal/activator/rootfsworkers.go
+++ b/internal/activator/rootfsworkers.go
@@ -77,6 +77,11 @@ type rootfsWorker struct {
// strayAt is when a stray's stop was last tried: the sweep re-tries it
// at most every actStopTimeout.
strayAt time.Time
+ // registered is when this generation's worker was registered (the
+ // Service clock): a replicated deploy judges a worker that never
+ // started only once residentPoll + workerStartBound have passed since
+ // (replicaSwitchProof).
+ registered time.Time
// pending: declared by the wake and never started on this entry. The
// tick's first pass starts it, with no backoff and no crash counted
// (Paul's ruling, W1 round 2).
@@ -266,7 +271,7 @@ func (a *Service) registerRootfsWorkers(e *actEntry, rt registry.Route, g Gen, s
e.strayRootfsWorkers = append(e.strayRootfsWorkers, old)
}
}
- e.rootfsWorkers[name] = &rootfsWorker{name: name, gen: g.N, build: build, pending: true}
+ e.rootfsWorkers[name] = &rootfsWorker{name: name, gen: g.N, build: build, pending: true, registered: a.now()}
}
}
@@ -536,7 +541,7 @@ func (a *Service) strayWorkerLocked(e *actEntry, wk *rootfsWorker, now time.Time
}
delete(e.rootfsWorkers, wk.name)
if e.state == actAwake {
- e.rootfsWorkers[wk.name] = &rootfsWorker{name: wk.name, gen: wk.gen, build: wk.build,
+ e.rootfsWorkers[wk.name] = &rootfsWorker{name: wk.name, gen: wk.gen, build: wk.build, registered: wk.registered,
retryAt: now.Add(max(wk.backoff, sidecarRestartBase)), backoff: wk.backoff, restarts: wk.restarts,
crashLoop: wk.crashLoop, lastExitEvent: wk.lastExitEvent, startFailed: true}
}
diff --git a/internal/activator/stateless.go b/internal/activator/stateless.go
index 255cacdec..07464b72b 100644
--- a/internal/activator/stateless.go
+++ b/internal/activator/stateless.go
@@ -412,6 +412,23 @@ func (a *Service) prepareStateless(ctx context.Context, rt registry.Route, id re
build := replicas.Build{Version: id.Version, Digest: digest}
prepared := &statelessPreparation{route: rt, id: id, digest: digest, observation: observation}
switch {
+ case d != nil && d.Incarnation == inc && digest != "" && build == d.Baseline(box):
+ // This box's baseline first: a completed box, or any box once
+ // done, restarts on the target even while a retry is requested;
+ // consuming the retry stays with the coordinator's release path.
+ if build == d.Target && replicas.ReleasePassed(d.Phase) {
+ // The passed target: the escrow recovery the adopt path runs
+ // (it never coordinates or reruns a release).
+ if escrow, ok := a.backend.(statelessEscrowInitializer); ok {
+ launch := rt
+ launch.Stateless = true
+ if err := escrow.prepareStatelessEscrow(observed, launch, observation.record.Identity); err != nil {
+ return ctx, err
+ }
+ }
+ }
+ prepared.baseline = true
+ return context.WithValue(observed, statelessPreparedKey{}, prepared), nil
case d != nil && d.Incarnation == inc && build == d.Target && d.TargetAllowed(box):
if replicas.DurableAttempt(d, inc, d.Target) == nil {
return ctx, errReplicaTurn // a requested retry: only a named build begins one
@@ -424,9 +441,6 @@ func (a *Service) prepareStateless(ctx context.Context, rt registry.Route, id re
}
prepared.deployID = deployID
return context.WithValue(observed, statelessPreparedKey{}, prepared), nil
- case d != nil && d.Incarnation == inc && digest != "" && build == d.Baseline(box):
- prepared.baseline = true
- return context.WithValue(observed, statelessPreparedKey{}, prepared), nil
case id.Version != rt.Version:
return ctx, errReplicaTurn
}
diff --git a/internal/provision/stateless_replicas_4_task2_census_test.go b/internal/provision/stateless_replicas_4_task2_census_test.go
index 40b9eebca..c92164aeb 100644
--- a/internal/provision/stateless_replicas_4_task2_census_test.go
+++ b/internal/provision/stateless_replicas_4_task2_census_test.go
@@ -34,10 +34,17 @@ package provision
// - The worker-failure ACK is one more field on Task 1's /deploy ack,
// through the unchanged SetRecordReplicaDeploy (replicas.NextDeploy
// halts the deploy); no new writer.
+//
+// Fix round 3, self-review:
+// - prepareStateless checks this box's baseline before the adopt path,
+// so a completed box restarts on the target while a retry is
+// requested; for the passed target it calls the same escrow recovery
+// the adopt path ran. Still no record write; the reference is
+// unchanged.
func statelessReplicas4Task2WriteCensusInventory() []censusEntry {
entries := append([]censusEntry(nil), statelessReplicas4Task1WriteCensusInventory()...)
for _, r := range []censusEntry{
- {"internal/activator/stateless.go", "Service.prepareStateless", "reference", "key:statelessRecordKey", "b5408db6444e04239d8735515a860a043c7f2203624a3bb992ecc39acd0bfdfe"},
+ {"internal/activator/stateless.go", "Service.prepareStateless", "reference", "key:statelessRecordKey", "3151a8c2583249a51f15e2bf596306a1e94f012ad81864e8feacaaca0628c3a1"},
{"internal/provision/replicadeploy.go", "SetRecordReplicaRelease", "record-writer", "key:SetRecordReplicaRelease,key:updateRecord", "4cf65247d1cb0e75c0bd61aa18eefad95e877c2ab89790a718e075e091e249df"},
} {
replaced := false
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv
index 363b35af3..ad9a7680c 100644
--- a/internal/provision/testdata/plan14-root-reads-chain.tsv
+++ b/internal/provision/testdata/plan14-root-reads-chain.tsv
@@ -175,3 +175,4 @@ plan14-root-reads-stateless-replicas-4-task1-fix3.tsv 3f066208f5e5fa2b9854f30118
plan14-root-reads-stateless-replicas-4-task2.tsv 40c909a853a761733e9f837d4c8336bc91e174125cad65ac412f71141978be19
plan14-root-reads-stateless-replicas-4-task2-fix1.tsv 1a0605f79ac62c776bccc1ae8d166357b05c6acb56aeead59290e43b9cc67788
plan14-root-reads-stateless-replicas-4-task2-fix2.tsv 5f83de2e018b47543789a8dbe2cccb86b2d644fbe9ee5771e5d621704ae46e0b
+plan14-root-reads-stateless-replicas-4-task2-fix3.tsv bd25367161555e8a9c5b0df079ad2d8eb648ebaeae3f407e6c638f2f7f01605b
diff --git a/internal/provision/testdata/plan14-root-reads-stateless-replicas-4-task2-fix3.tsv b/internal/provision/testdata/plan14-root-reads-stateless-replicas-4-task2-fix3.tsv
new file mode 100644
index 000000000..257c5f22f
--- /dev/null
+++ b/internal/provision/testdata/plan14-root-reads-stateless-replicas-4-task2-fix3.tsv
@@ -0,0 +1,11 @@
+# Census overlay stateless-replicas-4-task2-fix3, written by census-propose (#369). census-ruling-stateless-replicas-4-task2-fix3, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-stateless-replicas-4-task2-fix3.md.
+# 3 body, 1 sites, 1 envelope: each changed unit re-frozen at its existing disposition with its claim appended.
+@legacy c781846b8fdfa53a95152020630a11e66c0bce3aac85c0817b867a34d3efb44d internal/activator/replicadeploy.go Service.ReplicaSwap legacy accepted-legacy accepted-legacy;rev3=census-ruling-stateless-replicas-4-task2;basis=Task 2: new. Checks the permit (box label, phase released, not halted, ActiveBox, build), refuses a hold, asks tenantStartRefusal on the in-memory entry route, then either re-proves an existing switch (replicaSettle) or runs the existing Swap as a canary and checks replicaStepProven. Reads the in-memory entry route only; no store, file or root call of its own.;rev3=census-ruling-stateless-replicas-4-task2-fix1;basis=Task 2 fix round 1: proof-only steps (an already switched copy, a halted permit, a permit whose successor failed here) skip the start gates because nothing starts; a failed successor answers kept only after replicaKeptProven (its stop proven, an empty operation set). Reads only the in-memory entry route; no store, file or root call.;rev3=census-ruling-stateless-replicas-4-task2-fix2;basis=Task 2 fix round 2: the switch proof is replicaSwitchProof, which also reports WorkersFailed (switched, the new workers crashed or did not start within the settle window) so the step answers instead of staying open. Reads only the in-memory entry; no store, file or root call.;rev3=census-ruling-stateless-replicas-4-task2-fix3;basis=Task 2 fix round 3: replicaSwitchProof keeps the step open while a worker start is in flight or a gate-refused start waits for its retry, and judges a never-started worker only after residentPoll + workerStartBound from registration (Service clock); a crash or restart still answers workers failed. Reads only the in-memory entry; no store, file or root call. registry:FleetBoxes@694,whole:Route@1408,whole:Route@557,whole:Route@567 65db8dd808e63023928c8f6a09e93f8aca26d66924e11e3fb8289a7e36f3f881
+@legacy 8426728a36035ae749325840cf9b3ae3faf68b123114c20fd594b5203b458247 internal/activator/replicadeploy.go Service.replicaSettle legacy accepted-legacy accepted-legacy;rev3=census-ruling-stateless-replicas-4-task2;basis=Task 2: new. GET / health (genHealthy) and the settle window on the current in-memory generation, then replicaStepProven; reads the in-memory entry route only.;rev3=census-ruling-stateless-replicas-4-task2-fix2;basis=Task 2 fix round 2: after the settle window the proof judges the new workers (replicaSwitchProof, settled); a failure answers switched with WorkersFailed. Same in-memory reads.;rev3=census-ruling-stateless-replicas-4-task2-fix3;basis=Task 2 fix round 3: the same bounded worker judgment (replicaSwitchProof). Same in-memory reads. whole:Route@262,whole:Route@320 db103e5d8547dedaeeca8fd6339fb1427203f348ae0965031092366fca327c99
+@legacy 8783b144f6c2b0216859e997b2daed9bf8f3551409b4250179cffac121160ac3 internal/activator/rootfsworkers.go Service.registerRootfsWorkers legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-3-workers;basis=rootfs Plan 3 Group W: the one place a generation's declared workers are registered; reads the workers the generation declares through the existing staged-manifest read of the backend's Processes (the manifest root's staging wrote, checked against the identity's path and digest), registers each as pending on the host's own entry; an unreadable or invalid declaration registers none and web serves; starts nothing;rev3=census-ruling-stateless-replicas-4-task2-fix3;basis=Task 2 fix round 3: each registered worker records its registration time (registered: a.now()), an in-memory field the proof reads; no read added. registry:Host@313,registry:Host@515,registry:Host@747,registry:Host@922,whole:Route@178 3a937f69e19044f9548e5acb4b7138e0b12ee8ae055215ea0f0479b12826cd89
+@legacy fc092eedda5b86bd6f920e9525651403388e94ef4c26d07f383d8637d15efb7e internal/activator/stateless.go Service.prepareStateless legacy accepted-legacy accepted-legacy;rev3=census-ruling-stateless-replicas-1;basis=Task 3a: Capture RecordFacts from the existing record source, obtain the durable FailureBook deploy ID, and call Task 2 PrepareStatelessRelease with the canonical verdict/digest carrier. Carry a successful attempt through its hold only after another current-record check; no serving lease or polling loop. Fix 3a round 1 I2: preparation uses reconcile observations and records the successful deploy ID. Carry prepared evidence through hold; fresh backend read must confirm that same released deploy before web runs.;rev3=census-ruling-stateless-failed-release-held;basis=For recovery onto a different installed version's exact committed good version and artifact digest, retain recovery evidence without selecting or writing another deploy. Adds the existing committedGood registry read, with its route and incarnation check. Canonical storage declaration and observed lifetime gates remain.;rev3=census-ruling-stateless-replicas-4-task1;basis=R1: no longer calls ReplicaDeployID before preparation; hands the same a.ReplicaDeployID selector to prepareStatelessRelease, which calls it only after coordinator term acquisition. The ObservedReplicaRelease call stays as a validity check. Same read sites; no new read, write or authority.;rev3=census-ruling-stateless-replicas-4-task2;basis=Task 2 (D4): for a set row, prepares the record baseline with no release, and refuses a build the row Version does not name before any release; reads the route it is handed (FleetBoxes, Version). No store read or write added.;rev3=census-ruling-stateless-replicas-4-task2-fix1;basis=Task 2 fix round 1: for a set row, a build its pointer does not name starts only as the record baseline or the committed permitted target, the latter adopted through prepareStatelessRelease durable path (never a new attempt); a named build, a rollback included, takes the release path. The added reads are the handed route (FleetBoxes, Version) and a copy of it with Stateless set for the adoption, as the release path already builds. No store read or write added.;rev3=census-ruling-stateless-replicas-4-task2-fix2;basis=Task 2 fix round 2: for a set row the no-release start is decided per box from the record (this box baseline, or its permitted target adopted through the durable path), whatever the pointer says; only a build that is neither and that the pointer names begins a new attempt. Same reads (the handed route and its copy); no store read or write added.;rev3=census-ruling-stateless-replicas-4-task2-fix3;basis=Task 2 fix round 3: this box baseline is checked before the adopt path, so a completed box restarts on the target while a retry is requested; for the passed target it calls the existing escrow initializer (prepareStatelessEscrow) that the adopt path ran, with the same route and identity. No new reader; no record write. registry:Account@284,registry:Account@310,registry:App@324,registry:App@346,registry:Digest@3757,registry:FleetBoxes@3400,registry:FleetBoxes@944,registry:Host@250,registry:Host@273,registry:Stateless@2482,registry:Stateless@3007,registry:Stateless@4055,registry:Version@3292,registry:Version@3437,registry:Version@3727,whole:Route@1855,whole:Route@1862,whole:Route@2474,whole:Route@2561,whole:Route@259,whole:Route@293,whole:Route@3001,whole:Route@3087,whole:Route@333,whole:Route@3677,whole:Route@3821,whole:Route@3828,whole:Route@4051,whole:Route@4205,whole:Route@4309,whole:Route@4316,whole:Route@540,whole:Route@597,whole:Route@714,whole:Route@821 3151a8c2583249a51f15e2bf596306a1e94f012ad81864e8feacaaca0628c3a1
+internal/activator/replicadeploy.go Service.ReplicaSwap legacy accepted-legacy accepted-legacy;rev3=census-ruling-stateless-replicas-4-task2;basis=Task 2: new. Checks the permit (box label, phase released, not halted, ActiveBox, build), refuses a hold, asks tenantStartRefusal on the in-memory entry route, then either re-proves an existing switch (replicaSettle) or runs the existing Swap as a canary and checks replicaStepProven. Reads the in-memory entry route only; no store, file or root call of its own.;rev3=census-ruling-stateless-replicas-4-task2-fix1;basis=Task 2 fix round 1: proof-only steps (an already switched copy, a halted permit, a permit whose successor failed here) skip the start gates because nothing starts; a failed successor answers kept only after replicaKeptProven (its stop proven, an empty operation set). Reads only the in-memory entry route; no store, file or root call.;rev3=census-ruling-stateless-replicas-4-task2-fix2;basis=Task 2 fix round 2: the switch proof is replicaSwitchProof, which also reports WorkersFailed (switched, the new workers crashed or did not start within the settle window) so the step answers instead of staying open. Reads only the in-memory entry; no store, file or root call.;rev3=census-ruling-stateless-replicas-4-task2-fix3;basis=Task 2 fix round 3: replicaSwitchProof keeps the step open while a worker start is in flight or a gate-refused start waits for its retry, and judges a never-started worker only after residentPoll + workerStartBound from registration (Service clock); a crash or restart still answers workers failed. Reads only the in-memory entry; no store, file or root call. registry:FleetBoxes@694,whole:Route@1408,whole:Route@557,whole:Route@567 65db8dd808e63023928c8f6a09e93f8aca26d66924e11e3fb8289a7e36f3f881
+internal/activator/replicadeploy.go Service.replicaSettle legacy accepted-legacy accepted-legacy;rev3=census-ruling-stateless-replicas-4-task2;basis=Task 2: new. GET / health (genHealthy) and the settle window on the current in-memory generation, then replicaStepProven; reads the in-memory entry route only.;rev3=census-ruling-stateless-replicas-4-task2-fix2;basis=Task 2 fix round 2: after the settle window the proof judges the new workers (replicaSwitchProof, settled); a failure answers switched with WorkersFailed. Same in-memory reads.;rev3=census-ruling-stateless-replicas-4-task2-fix3;basis=Task 2 fix round 3: the same bounded worker judgment (replicaSwitchProof). Same in-memory reads. whole:Route@262,whole:Route@320 db103e5d8547dedaeeca8fd6339fb1427203f348ae0965031092366fca327c99
+internal/activator/rootfsworkers.go Service.registerRootfsWorkers legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-3-workers;basis=rootfs Plan 3 Group W: the one place a generation's declared workers are registered; reads the workers the generation declares through the existing staged-manifest read of the backend's Processes (the manifest root's staging wrote, checked against the identity's path and digest), registers each as pending on the host's own entry; an unreadable or invalid declaration registers none and web serves; starts nothing;rev3=census-ruling-stateless-replicas-4-task2-fix3;basis=Task 2 fix round 3: each registered worker records its registration time (registered: a.now()), an in-memory field the proof reads; no read added. registry:Host@313,registry:Host@515,registry:Host@747,registry:Host@922,whole:Route@178 3a937f69e19044f9548e5acb4b7138e0b12ee8ae055215ea0f0479b12826cd89
+internal/activator/stateless.go Service.prepareStateless legacy accepted-legacy accepted-legacy;rev3=census-ruling-stateless-replicas-1;basis=Task 3a: Capture RecordFacts from the existing record source, obtain the durable FailureBook deploy ID, and call Task 2 PrepareStatelessRelease with the canonical verdict/digest carrier. Carry a successful attempt through its hold only after another current-record check; no serving lease or polling loop. Fix 3a round 1 I2: preparation uses reconcile observations and records the successful deploy ID. Carry prepared evidence through hold; fresh backend read must confirm that same released deploy before web runs.;rev3=census-ruling-stateless-failed-release-held;basis=For recovery onto a different installed version's exact committed good version and artifact digest, retain recovery evidence without selecting or writing another deploy. Adds the existing committedGood registry read, with its route and incarnation check. Canonical storage declaration and observed lifetime gates remain.;rev3=census-ruling-stateless-replicas-4-task1;basis=R1: no longer calls ReplicaDeployID before preparation; hands the same a.ReplicaDeployID selector to prepareStatelessRelease, which calls it only after coordinator term acquisition. The ObservedReplicaRelease call stays as a validity check. Same read sites; no new read, write or authority.;rev3=census-ruling-stateless-replicas-4-task2;basis=Task 2 (D4): for a set row, prepares the record baseline with no release, and refuses a build the row Version does not name before any release; reads the route it is handed (FleetBoxes, Version). No store read or write added.;rev3=census-ruling-stateless-replicas-4-task2-fix1;basis=Task 2 fix round 1: for a set row, a build its pointer does not name starts only as the record baseline or the committed permitted target, the latter adopted through prepareStatelessRelease durable path (never a new attempt); a named build, a rollback included, takes the release path. The added reads are the handed route (FleetBoxes, Version) and a copy of it with Stateless set for the adoption, as the release path already builds. No store read or write added.;rev3=census-ruling-stateless-replicas-4-task2-fix2;basis=Task 2 fix round 2: for a set row the no-release start is decided per box from the record (this box baseline, or its permitted target adopted through the durable path), whatever the pointer says; only a build that is neither and that the pointer names begins a new attempt. Same reads (the handed route and its copy); no store read or write added.;rev3=census-ruling-stateless-replicas-4-task2-fix3;basis=Task 2 fix round 3: this box baseline is checked before the adopt path, so a completed box restarts on the target while a retry is requested; for the passed target it calls the existing escrow initializer (prepareStatelessEscrow) that the adopt path ran, with the same route and identity. No new reader; no record write. registry:Account@284,registry:Account@310,registry:App@324,registry:App@346,registry:Digest@3757,registry:FleetBoxes@3400,registry:FleetBoxes@944,registry:Host@250,registry:Host@273,registry:Stateless@2482,registry:Stateless@3007,registry:Stateless@4055,registry:Version@3292,registry:Version@3437,registry:Version@3727,whole:Route@1855,whole:Route@1862,whole:Route@2474,whole:Route@2561,whole:Route@259,whole:Route@293,whole:Route@3001,whole:Route@3087,whole:Route@333,whole:Route@3677,whole:Route@3821,whole:Route@3828,whole:Route@4051,whole:Route@4205,whole:Route@4309,whole:Route@4316,whole:Route@540,whole:Route@597,whole:Route@714,whole:Route@821 3151a8c2583249a51f15e2bf596306a1e94f012ad81864e8feacaaca0628c3a1
+@coverage internal/activator 114bf7de5fdcab3b2e3f4993bdcd4f807ac9fa165872890de727db4e573840e6