replicas: a config-waiting join stays open, then kept (#511)
Drill 1 review round 2: Fable (a), Astra M8, and the SetReplicaDeploy ordering. A joining permit holder whose wakes wait for its configuration reached replicaRestartBound (about 32 s) with no generation and answered switched-failed, landing in Completed. The resident state now records since when its wakes have waited for its configuration (configSince). While that wait is younger than releaseConfigBound (3 min) the step stays open and answers nothing. Past it, the step answers kept with the configuration's reason (SR-4-C92), as in the secrets case: a permit-owned fence held until the ACK, never switched-failed, and the box is not added to Completed. Kept fences are owned by reason (replicaKeptOwner(why, id, permit)). SetReplicaDeploy now rejects an older revision of the attempt it holds before it schedules any fence lift, so a late observation from before the permit cannot lift a kept fence. Witnesses: TestJoinConfigWaitKeepsStepOpen (config at 60 s: open past replicaRestartBound, then launched and proven switched; config never: kept with the configuration's reason after the bound, the join halted with b out of Completed) and TestReplicaKeptFenceHeldUntilAck (an older revision leaves the fence held).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
internal/activator/replica_drill1_test.go+100 −0internal/activator/replicadeploy.go+72 −26internal/activator/rootfs_service.go+12 −0
Intent
<task-notification> <task-id>a3447eef93b8e73dc</task-id> <tool-use-id>toolu_016vzNT9yzx5poMhTthdGeq6</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/72128d15-58b8-452f-9f7e-8e864e8854d2/tasks/a3447eef93b8e73dc.output</output-file> <status>completed</status> <summary>Agent "Fix drill-1 findings on Plan 4" 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. Everything in round 1 is fixed and witnessed except R21c's late-created-file case, which needs a new ruling. The code doesn't match the ruling's premise: the platform never writes the instance.key or report.token files. **R21c, what the code shows:** `ensureInstanceKeyFor` (prepare.go:99) mints `CARLOS_INSTANCE_KEY` into the instance's `<host>.env`, not into an instance.key file (instancekey.go:295). That env is escrowed as env.sealed, or comes from the configuration, so every copy uses the same key source. Nothing in the tree writes either file; only tests do, standing in for an app. report.token has no platform source at all. That is the ruling's exception, so I kept the absence markers and recorded the case in a comment in escrow.go. I didn't mint the files because rastrillo's instance.key format and report.token's contents aren't in this repo. **Late-created file (Astra A3):** a running copy can't be stopped from writing its own file. Options: 1. Refuse copies above 1 for an app that writes these files. 2. Treat "recorded absent" as write-once: a file that later appears raises an alert and its copy is stopped. 3. Have the platform mint both files before the app's first start, which needs the rastrillo file contract. **Commits** (on f32f4704, not pushed; tip a97e3e0c): - 7e27ab0b A1: a "kept" answer's fence now stays held until its ACK commits or the permit changes - fe646a2f I1: a stateless launch waits for its config, not just the release. The config-wait bound is now 3 min: config sync's boot pass plus two fast passes (`configSyncBootPass + 2*fastConvergeSpacing`). A store read error keeps waiting, and the stale wait clock is fixed. - 7d903720 records which R21c case applies - 5201624f A2: raising copies keeps the serving box; the door refuses if the serving box has no room (new SR-4-C91) - 9458535a logs the swallowed `reg.Get` error and inventories Reconcile's new digest for `TestGroupNameClassCensus`, which now passes - 256754f9 docs and copy rows, including additions after a finished deploy starting without ordering - a97e3e0c census re-proposed under the same name; `make census-card` is clean **Tests:** new witnesses `TestReplicaKeptFenceHeldUntilAck` (the escrow is repaired while the ACK is paused and the cold wake is refused), `TestJoinFirstWakeWaitsForConfig` on the real Service, `TestReplicaRaiseKeepsServingBox` (small a, large b and c) and three subtests of `TestReleaseConfigWaitHeldAsFailed`. Each fails with its fix disabled. Without the A1 fix the target starts, which is Astra's counterexample. The targeted suites, `TestGroupNameClassCensus`, the HA guards and the three cross-compiles pass. **Other concerns:** - A3's late-created-file divergence is still possible until one of the options above is chosen. - Fable M5, M6 and M8 were outside this round's rulings and are untouched. With the launch now waiting for config, a slow config delivery on a joining box can halt the join (M8). - Placement now blocks, rather than moves, a fresh box that has become ineligible at the same count. Report (Review round 1 section appended): /home/paulca/amadan.net/carlos/platform/.claude/worktrees/stateless-replicas-4/.superpowers/sdd/2026-11-01-stateless-replicas-4-deploy-and-drill/task-drill1-report.md</result> <usage><subagent_tokens>767653</subagent_tokens><tool_uses>40</tool_uses><duration_ms>1846188</duration_ms></usage> </task-notification>
<task-notification> <task-id>bc8zsgdxn</task-id> <tool-use-id>toolu_015WDyXWLQy1dWJjuZJtAguf</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/72128d15-58b8-452f-9f7e-8e864e8854d2/tasks/bc8zsgdxn.output</output-file> <status>completed</status> <summary>Background command "Fable re-review of drill-1 round 1" completed (exit code 0)</summary> </task-notification>
<task-notification> <task-id>bo08qtw7p</task-id> <tool-use-id>toolu_0131b6xiWQU9f3Y4BhpzdPsY</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/72128d15-58b8-452f-9f7e-8e864e8854d2/tasks/bo08qtw7p.output</output-file> <status>completed</status> <summary>Background command "Astra re-review of drill-1 round 1" completed (exit code 0)</summary> </task-notification>
<task-notification> <task-id>breau3ksa</task-id> <tool-use-id>toolu_019t253TkddB6acTy4tqqQjH</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/72128d15-58b8-452f-9f7e-8e864e8854d2/tasks/breau3ksa.output</output-file> <status>completed</status> <summary>Background command "Wait for CI on a97e3e0c" completed (exit code 0)</summary> </task-notification>
diff --git a/internal/activator/replica_drill1_test.go b/internal/activator/replica_drill1_test.go| index 4ebda96b5..eadee464c 100644 |
| --- a/internal/activator/replica_drill1_test.go |
| +++ b/internal/activator/replica_drill1_test.go |
| @@ -552,6 +552,17 @@ func TestReplicaKeptFenceHeldUntilAck(t *testing.T) { |
| if res := step(); !res.Proven || res.WebFailed || res.Reason != replicaSecretsRefusal { |
| t.Fatalf("not answered kept: %+v", res) |
| } |
| + // An older revision of the attempt observed late (before the permit) |
| + // is ignored before it can lift the fence (round 2). |
| + older := *r.store.snapshot() |
| + older.Revision, older.Swap = older.Revision-1, replicas.Swap{Order: []string{"a", "b"}, Completed: []string{"a"}} |
| + r.a.SetReplicaDeploy(r.rt.Host, older, "b") |
| + r.a.mu.Lock() |
| + held := r.a.fences[r.rt.Host] |
| + r.a.mu.Unlock() |
| + if held == 0 { |
| + t.Fatal("an older revision lifted the kept fence") |
| + } |
| // The ACK is delayed. The escrow is repaired meanwhile. |
| r.a.backend = r.b |
| if err := wake(); !errors.Is(err, ErrFenced) { |
| @@ -579,3 +590,92 @@ func TestReplicaKeptFenceHeldUntilAck(t *testing.T) { |
| t.Fatalf("after the ACK b is not refused the target by the record: %v", err) |
| } |
| } |
| + |
| +// TestJoinConfigWaitKeepsStepOpen (#511 drill 1 round 2; Fable (a), Astra |
| +// M8): a joining permit holder whose wakes wait for its configuration |
| +// keeps its step open past replicaRestartBound, up to releaseConfigBound, |
| +// and is never answered switched-failed. |
| +// - config at 60 s: the step stays open through the wait, the copy |
| +// launches once the config is written, and the step proves the switch. |
| +// - config never: past releaseConfigBound the step answers kept with |
| +// the configuration's reason (SR-4-C92); the ACK halts the join and |
| +// the box is not in Completed. |
| +func TestJoinConfigWaitKeepsStepOpen(t *testing.T) { |
| + prev := swapSettle |
| + swapSettle = 20 * time.Millisecond |
| + t.Cleanup(func() { swapSettle = prev }) |
| + join := func(inc string) *replicas.Deploy { |
| + return &replicas.Deploy{ID: "deploy-v2", Incarnation: inc, Target: replicaTarget, BaselineSet: true, LastGood: replicaTarget, Phase: "released", Term: "term", Revision: 5, |
| + Swap: replicas.Swap{Order: []string{"a", "b"}, Completed: []string{"a"}, ActiveBox: "b", Permit: 5}} |
| + } |
| + setup := func(t *testing.T) (*replicaSetRig, *configWaitBackend, func() error, func(bool) SwapResult) { |
| + r := newReplicaSetRig(t, "b", join) |
| + r.rt.Hibernate = false |
| + r.routes.set(r.rt) |
| + cw := &configWaitBackend{wakeRelBackend: r.b} |
| + r.a.backend = cw |
| + wake := func() error { |
| + r.setPlan(WakePlan{Boot: r.next, Mode: ModeOverlap, Token: 2}) |
| + return waitErr(t, r.wake(r.a)) |
| + } |
| + step := func(awake bool) SwapResult { |
| + at := Attempt{Host: r.rt.Host, Cause: CauseRelease, Build: "v2", StagedPath: r.next.StagedPath, Mode: ModeOverlap, SchedRev: 1, ProofOnly: true} |
| + if awake { |
| + at = r.attempt(CauseRelease, ModeOverlap) |
| + } |
| + return r.a.ReplicaSwap(context.Background(), at, *r.store.snapshot(), "b", newestOne) |
| + } |
| + return r, cw, wake, step |
| + } |
| + open := func(t *testing.T, res SwapResult, when string) { |
| + t.Helper() |
| + if res.Proven || res.WebFailed { |
| + t.Fatalf("%s: the waiting copy's step answered: %+v", when, res) |
| + } |
| + } |
| + t.Run("config at 60s", func(t *testing.T) { |
| + r, cw, wake, step := setup(t) |
| + var wait *releaseConfigWait |
| + if err := wake(); !errors.As(err, &wait) { |
| + t.Fatalf("first wake: %v", err) |
| + } |
| + open(t, step(false), "at once") |
| + r.clk.advance(60 * time.Second) |
| + if err := wake(); !errors.As(err, &wait) { |
| + t.Fatalf("wake at 60s: %v", err) |
| + } |
| + open(t, step(false), "past replicaRestartBound") |
| + cw.written.Store(true) |
| + if err := wake(); err != nil { |
| + t.Fatalf("wake with the config: %v", err) |
| + } |
| + res := step(true) |
| + if res.Outcome != SwapDone || !res.Proven || res.WebFailed { |
| + t.Fatalf("the joined copy's switch was not proven: %+v", res) |
| + } |
| + }) |
| + t.Run("config never", func(t *testing.T) { |
| + r, _, wake, step := setup(t) |
| + _ = wake() |
| + open(t, step(false), "at once") |
| + for gone := time.Duration(0); gone <= releaseConfigBound; gone += 50 * time.Second { |
| + r.clk.advance(50 * time.Second) |
| + var wait *releaseConfigWait |
| + if err := wake(); !errors.As(err, &wait) { |
| + t.Fatalf("wake after %s: %v", gone, err) |
| + } |
| + if gone+50*time.Second < releaseConfigBound { |
| + open(t, step(false), "within the bound") |
| + } |
| + } |
| + res := step(false) |
| + if !res.Proven || res.WebFailed || res.Outcome == SwapDone || res.Reason != replicaConfigRefusal { |
| + t.Fatalf("past the bound, not answered kept for the configuration: %+v", res) |
| + } |
| + cur := *r.store.snapshot() |
| + next, err := replicas.NextDeploy(cur, replicas.DeployChange{Op: "ack", ID: cur.ID, Box: "b", Revision: cur.Revision, Target: cur.Target, Permit: cur.Swap.Permit}, replicas.Coordinator{}, time.Now()) |
| + if err != nil || next.PermitOutstanding() || !next.Swap.Halted || slices.Contains(next.Swap.Completed, "b") { |
| + t.Fatalf("the join did not halt with b out of Completed: %v %+v", err, next.Swap) |
| + } |
| + }) |
| +} |
diff --git a/internal/activator/replicadeploy.go b/internal/activator/replicadeploy.go| index 3ef26c6f8..548559f7e 100644 |
| --- a/internal/activator/replicadeploy.go |
| +++ b/internal/activator/replicadeploy.go |
| @@ -78,12 +78,18 @@ type replicaPolicy struct { |
| // the host. An older revision of the same attempt never replaces a newer. |
| func (a *Service) SetReplicaDeploy(host string, deploy replicas.Deploy, box string) { |
| a.mu.Lock() |
| + // An older revision of the attempt held is ignored first: it neither |
| + // replaces the newer nor lifts a fence (round 2). |
| + if cur, ok := a.replicaPolicies[host]; ok && deploy.ID != "" && box != "" && cur.deploy.ID == deploy.ID && cur.deploy.Incarnation == deploy.Incarnation && cur.deploy.Revision > deploy.Revision { |
| + a.mu.Unlock() |
| + return |
| + } |
| // A kept answer's fence stays until its ACK commits or its permit |
| // changes (#511 drill 1 round 1, Astra A1): lifted once the record no |
| // longer holds that permit open for this box. |
| var keptGen uint64 |
| keptOwner := a.fenceOwners[host] |
| - if strings.HasPrefix(keptOwner, replicaKeptFencePrefix) && (deploy.Swap.ActiveBox != box || keptOwner != replicaKeptOwner(deploy.ID, deploy.Swap.Permit)) { |
| + if strings.HasPrefix(keptOwner, replicaKeptFencePrefix) && (deploy.Swap.ActiveBox != box || !replicaKeptFor(keptOwner, deploy.ID, deploy.Swap.Permit)) { |
| keptGen = a.fences[host] |
| } |
| defer func() { |
| @@ -96,9 +102,6 @@ func (a *Service) SetReplicaDeploy(host string, deploy replicas.Deploy, box stri |
| delete(a.replicaPolicies, host) |
| return |
| } |
| - if cur, ok := a.replicaPolicies[host]; ok && cur.deploy.ID == deploy.ID && cur.deploy.Incarnation == deploy.Incarnation && cur.deploy.Revision > deploy.Revision { |
| - return |
| - } |
| if a.replicaPolicies == nil { |
| a.replicaPolicies = make(map[string]replicaPolicy) |
| } |
| @@ -464,10 +467,12 @@ func (a *Service) replicaRestartedFailure(ctx context.Context, at Attempt, deplo |
| return SwapResult{}, false |
| } |
| a.mu.Lock() |
| - if a.fences[at.Host] == key.permit && a.fenceOwners[at.Host] == replicaKeptOwner(key.id, key.permit) { |
| - // Already answered kept for this permit, its fence held since. |
| - a.mu.Unlock() |
| - return replicaKeptAnswer(), true |
| + for _, why := range []string{keptSecrets, keptConfig} { |
| + if a.fences[at.Host] == key.permit && a.fenceOwners[at.Host] == replicaKeptOwner(why, key.id, key.permit) { |
| + // Already answered kept for this permit, its fence held since. |
| + a.mu.Unlock() |
| + return replicaKeptAnswer(why), true |
| + } |
| } |
| if a.entries[at.Host] != nil { |
| a.mu.Unlock() |
| @@ -482,6 +487,20 @@ func (a *Service) replicaRestartedFailure(ctx context.Context, at Attempt, deplo |
| a.replicaNoGen[at.Host] = since |
| } |
| past := !a.now().Before(since.at.Add(replicaRestartBound)) |
| + // A copy waiting for its configuration (round 2, Fable (a) and Astra |
| + // M8) keeps its step open up to releaseConfigBound from its first |
| + // such refusal, never switched-failed; past it, it answers kept |
| + // (below) with the configuration's reason. |
| + var configSince time.Time |
| + if st := a.residents[at.Host]; st != nil { |
| + configSince = st.configSince |
| + } |
| + if !configSince.IsZero() && a.now().Before(configSince.Add(releaseConfigBound)) { |
| + a.mu.Unlock() |
| + res := abandon(errSwapNotAwake) |
| + res.Reason = "this copy holds the permit and waits for its configuration; the step stays open" |
| + return res, true |
| + } |
| a.mu.Unlock() |
| if !past { |
| res := abandon(errSwapNotAwake) |
| @@ -499,11 +518,17 @@ func (a *Service) replicaRestartedFailure(ctx context.Context, at Attempt, deplo |
| // and the ACK (#511 drill 1 round 1, Astra A1). |
| a.mu.Lock() |
| st := a.residents[at.Host] |
| - secrets := st != nil && !st.secretsSince.IsZero() |
| + why := "" |
| + switch { |
| + case st != nil && !st.secretsSince.IsZero(): |
| + why = keptSecrets |
| + case st != nil && !st.configSince.IsZero(): |
| + why = keptConfig |
| + } |
| a.mu.Unlock() |
| owner := fmt.Sprintf("replica-restart:%s:%d", key.id, key.permit) |
| - if secrets { |
| - owner = replicaKeptOwner(key.id, key.permit) |
| + if why != "" { |
| + owner = replicaKeptOwner(why, key.id, key.permit) |
| } |
| sctx, cancel := context.WithTimeout(ctx, replicaWebFailBound) |
| _, err = a.FenceAndStopAs(sctx, at.Host, key.permit, owner) |
| @@ -512,7 +537,7 @@ func (a *Service) replicaRestartedFailure(ctx context.Context, at Attempt, deplo |
| releasing := a.releaseOps[at.Host] != nil |
| a.mu.Unlock() |
| proven := err == nil || errors.Is(err, ErrStopUnproven) && !releasing && !a.StopUncertain(at.Host) |
| - if !proven || !secrets { |
| + if !proven || why == "" { |
| a.LiftFenceAs(at.Host, key.permit, owner) |
| } |
| if !proven { |
| @@ -520,13 +545,14 @@ func (a *Service) replicaRestartedFailure(ctx context.Context, at Attempt, deplo |
| res.Reason = "this copy holds the permit with nothing running; its stop is not proven yet, so the step stays open" |
| return res, true |
| } |
| - if secrets { |
| + if why != "" { |
| // Its wakes were refused for the instance's shared secrets (a |
| - // joining copy whose escrow is not complete; #511 drill 1, R21): |
| - // the target never started here. The answer is kept, not |
| - // switched, so the ACK resolves the permit and halts the deploy, |
| - // and this copy stops asking for a build it cannot start. |
| - return replicaKeptAnswer(), true |
| + // joining copy whose escrow is not complete; #511 drill 1, R21), |
| + // or for its configuration past releaseConfigBound (round 2): the |
| + // target never started here. The answer is kept, not switched, so |
| + // the ACK resolves the permit and halts the deploy, and this copy |
| + // is not left allowed a build it cannot start. |
| + return replicaKeptAnswer(why), true |
| } |
| return SwapResult{Outcome: SwapAbandoned, Proven: true, WebFailed: true, Reason: "the new build failed on this copy after it switched and did not come back; nothing of it runs"}, true |
| } |
| @@ -534,18 +560,38 @@ func (a *Service) replicaRestartedFailure(ctx context.Context, at Attempt, deplo |
| // replicaKeptFencePrefix owns the fence of a kept answer (replicaKeptOwner). |
| const replicaKeptFencePrefix = "replica-kept:" |
| -// replicaKeptOwner is the owner of the kept answer's fence for permit of |
| -// attempt id. |
| -func replicaKeptOwner(id string, permit uint64) string { |
| - return fmt.Sprintf("%s%s:%d", replicaKeptFencePrefix, id, permit) |
| +// Why a permitted step answered kept: the shared secrets, or the |
| +// configuration (round 2). |
| +const ( |
| + keptSecrets = "secrets" |
| + keptConfig = "config" |
| +) |
| + |
| +// replicaKeptOwner is the owner of the kept answer's fence, for why, for |
| +// permit of attempt id. |
| +func replicaKeptOwner(why, id string, permit uint64) string { |
| + return fmt.Sprintf("%s%s:%s:%d", replicaKeptFencePrefix, why, id, permit) |
| } |
| -// replicaKeptAnswer is a permitted step's proven kept answer for want of |
| -// the shared secrets. |
| -func replicaKeptAnswer() SwapResult { |
| - return SwapResult{Outcome: SwapAbandoned, Proven: true, Reason: replicaSecretsRefusal} |
| +// replicaKeptFor reports whether owner is a kept fence of permit of id. |
| +func replicaKeptFor(owner, id string, permit uint64) bool { |
| + return owner == replicaKeptOwner(keptSecrets, id, permit) || owner == replicaKeptOwner(keptConfig, id, permit) |
| } |
| +// replicaKeptAnswer is a permitted step's proven kept answer, for why. |
| +func replicaKeptAnswer(why string) SwapResult { |
| + reason := replicaSecretsRefusal |
| + if why == keptConfig { |
| + reason = replicaConfigRefusal |
| + } |
| + return SwapResult{Outcome: SwapAbandoned, Proven: true, Reason: reason} |
| +} |
| + |
| +// replicaConfigRefusal is the kept answer of a copy that never started |
| +// because its configuration was not written on its box within |
| +// releaseConfigBound (round 2). copy SR-4-C92 |
| +const replicaConfigRefusal = "the new copy's configuration was not written on its box in time, so it did not start. existing copies keep serving" |
| + |
| // replicaSecretsRefusal is the answer of a copy that never started for |
| // want of the instance's shared secrets: its permitted step's, which halts |
| // the deploy, and, past replicaRestartBound, its wakes' (secretsRefusal). |
diff --git a/internal/activator/rootfs_service.go b/internal/activator/rootfs_service.go| index 3c5f81206..a27220cc6 100644 |
| --- a/internal/activator/rootfs_service.go |
| +++ b/internal/activator/rootfs_service.go |
| @@ -430,6 +430,11 @@ type residentState struct { |
| // (replicaRestartedFailure), and past replicaRestartBound a wake says |
| // so plainly (secretsRefusal; #511 drill 1, R21 and R21b). |
| secretsSince time.Time |
| + // configSince: since when its wakes, the last one included, have been |
| + // waiting for its configuration (releaseConfigWait); zero otherwise. A |
| + // copy's permitted step keeps its step open for releaseConfigBound |
| + // from it (replicaRestartedFailure; round 2). |
| + configSince time.Time |
| } |
| // errResidentBackoff is begin's answer for a resident inside its backoff: |
| @@ -1093,6 +1098,13 @@ func (a *Service) noteResidentWakeLocked(e *actEntry, err error) { |
| case st.secretsSince.IsZero(): |
| st.secretsSince = a.now() |
| } |
| + var config *releaseConfigWait |
| + switch { |
| + case !errors.As(err, &config): |
| + st.configSince = time.Time{} |
| + case st.configSince.IsZero(): |
| + st.configSince = a.now() |
| + } |
| } |
| if err == nil || !e.route.Resident() { |
| return |