fix: prove replica answers and route rollbacks through a release
Stateless replicas Plan 4 Task 2, fix round 1 (#511), from the Astra and Fable reviews: - Rollback after done: at done the baseline is the target, and a set row starts a build its pointer names only through the release path, so a rollback to Previous is a new attempt with its own order (D3). - The committed, permitted target starts whatever the box's installed Version says (a stale row, a pointer that moved on during a permit); the version check now only guards beginning a new release. - "Kept" needs the failed successor's stop proof and an empty operation set; until then the permit stays open and the step only re-proves. - A halted permit is stepped proof-only (switched or kept, no swap, no start gate), so a lost answer no longer blocks later deploys. - Proven needs the new generation's workers started, alive and never restarted; a build whose workers crash on start never acknowledges. - R8 as amended: the test pauses a request on the old generation while successor requests are served; the answer follows its drain. - One label: the scheduler takes the fleet identity label the gates use. - A set row whose incumbent is not stateless is refused, so no mode change turns it into a hold. Census overlay task2-fix1.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs/superpowers/notes/census-proposal-stateless-replicas-4-task2-fix1.md+27 −0internal/activator/activator.go+3 −0internal/activator/replicadeploy.go+77 −17internal/activator/replicadeploy_test.go+268 −11internal/activator/stateless.go+33 −10internal/activator/statelessrelease_test.go+11 −0internal/activator/swap.go+13 −5internal/host/replica_deploy_e2e_test.go+13 −0internal/host/rollout.go+13 −1internal/provision/stateless_replicas_4_task2_census_test.go+9 −1internal/provision/testdata/plan14-root-reads-chain.tsv+1 −0internal/provision/testdata/plan14-root-reads-stateless-replicas-4-task2-fix1.tsv+15 −0internal/replicas/deploy.go+9 −4internal/replicas/deploy_test.go+2 −1internal/rollout/replicas.go+12 −11internal/rollout/replicas_test.go+48 −1
CI failed — run details
Intent
<task-notification> <task-id>a4621592a91bafe83</task-id> <tool-use-id>toolu_01HeDSkF2K23yLwhv7jKJH9a</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:** c98180b1 feat: enforce replica rollout permissions at launch (local, not pushed; the tree is clean) - **Tests:** all 13 new tests failed first (RED) and now pass (GREEN), across replicas, provision, rollout, activator and host. 9 of 9 mutations were killed. Targeted runs of activator, rollout, host, console and provision pass, as do the grouproll and region HA guards, the darwin, windows and linux/arm64 builds, vet and gofmt. - **Brief vs code:** the brief says a waiting copy runs LastGood, but LastGood already names the target once the release passes. So the writer now records `Previous` (the LastGood the attempt began with), and a waiting copy runs that. - **Census:** proposal stateless-replicas-4-task2 is written (seal 40c909a8…), plus a record-write census layer. Nothing is posted to #280. - **Concerns:** - The scheduler and the activator get this box's label from two places. They agree on fleet boxes; if they ever disagreed, permitted swaps would be refused, never let through. - While starts are closed for an ingress drain, a copy that already switched cannot send its ACK, so the deploy pauses until starts reopen. - A halted permit with no recorded answer is still resolved only by retiring that box (Task 1 concern 3). - Copy rows SR-4-C43, C44 and C45 are new and provisional, pending Paul's review. - No live dev smoke was run; the report says which one I would run. - **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</result> <usage><subagent_tokens>567325</subagent_tokens><tool_uses>178</tool_uses><duration_ms>4068759</duration_ms></usage> </task-notification>
<task-notification> <task-id>bm1jqc1we</task-id> <tool-use-id>toolu_01Xprbtz2fUKEt3Sy2A2uHwE</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/72128d15-58b8-452f-9f7e-8e864e8854d2/tasks/bm1jqc1we.output</output-file> <status>completed</status> <summary>Background command "Run Astra review of Task 2" completed (exit code 0)</summary> </task-notification>
<task-notification> <task-id>bgt8rnccl</task-id> <tool-use-id>toolu_01RukAPcaLZY79vXvpEc4PGy</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/72128d15-58b8-452f-9f7e-8e864e8854d2/tasks/bgt8rnccl.output</output-file> <status>completed</status> <summary>Background command "Run Fable review of Task 2" completed (exit code 0)</summary> </task-notification>
<cross-session-message from="uds:/run/user/1001/cc-socks/3488194.sock" from-name="amadan-13" from-mode="bypass"> amadan-13: carlos/platform's CI is back on the fleet (lane w5). The hosted measurement run (job 5678) filled the hosted machine's 20 GiB disk, so any failures you saw in that window with `no space left on device` or `database or disk is full` were environmental, not your code. I'll try hosted again once the disk is bigger and give you a heads-up first. </cross-session-message>
<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. Hosted disks are now 100 GiB, so the `no space left on device` failures from earlier shouldn't recur. I'm timing three re-runs of main: 32 vCPU cold, 32 warm, then 16. Your pushes in that window run on hosted too. If a run fails for environmental reasons, tell me. After that it goes back to the fleet (w5) until the numbers are agreed. </cross-session-message>
Attributed to this commit: 31.3 g CO₂e (3,856,187 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-fix1.md b/docs/superpowers/notes/census-proposal-stateless-replicas-4-task2-fix1.md| new file mode 100644 |
| index 000000000..e8b5270ed |
| --- /dev/null |
| +++ b/docs/superpowers/notes/census-proposal-stateless-replicas-4-task2-fix1.md |
| @@ -0,0 +1,27 @@ |
| +# Census approval: stateless-replicas-4-task2-fix1 |
| + |
| +Ruling `census-ruling-stateless-replicas-4-task2-fix1`. 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/activator.go` `type Service` | body | unchanged (0) | Task 2 fix round 1: one more in-memory field, replicaFailed (host to the permit whose successor failed here, under mu), so that step only proves what it kept; declaration only, no read. | |
| +| `internal/activator/replicadeploy.go` `Service.ReplicaSwap` | body | unchanged (4) | 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. | |
| +| `internal/activator/swap.go` `Service.Swap` | body | unchanged (15) | Task 2 fix round 1: a set row whose incumbent is not stateless is refused (errReplicaHold) before preparation, so the mode-change hold conversion below can never run a set row as a hold; with replicaSwapRefusal this keeps every set row off swapHold and releaseBeforeSwap. Refusal only, no read added. | |
| +| `internal/host/rollout.go` `armRollout` | body | unchanged (5) | Task 2 fix round 1: the scheduler box label is rolloutBox(svc): the fleet identity label already on svc.Fleet (set from identity.Label before the scheduler arms), else BoxLabel() as before. No read added. | |
| +| `internal/activator/stateless.go` `Service.prepareStateless` | sites | +registry:FleetBoxes, +registry:Stateless, +whole:Route ×2 | 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. | |
| + |
| +Envelopes re-pinned: `internal/activator`, `internal/host`, `internal/replicas`, `internal/rollout`. |
| + |
| +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/activator.go` `type Service`: authority, task B,C,D,F,J4. Basis: rev3=PROPOSED-seed; existing activator lifecycle and due-wake state plus owned seed exclusion and incarnation-keyed diagnostics; normal refusal and preparation ordering remain authoritative; PROPOSED-plans-2-box-limits adds the idleFor hook field, which only narrows idle windows;rev3=census-ruling-plans-4c-box-throttle;basis=gains the maxRunFor hook field beside idleFor (plans 4c). No read added.;rev3=census-ruling-plans-4d-lapse;basis=gains the disabledFor hook field beside maxRunFor (plans 4d). No read added.;rev3=census-ruling-remote-instance-metrics;basis=gains tenancySeq, hostTenants and hostMixed, in-memory fields for Tenancies; no read added;rev3=census-ruling-region-ha-p1a;basis=the agent as carlos: one more field, markers (markerRetry: an atomic running flag and the last log time) for retryOwedMarkers; no read added; merge of origin/main d7ae1d76: main's fields are kept as main has them (census-ruling-remote-instance-metrics: tenancySeq, hostTenants, hostMixed); this branch's change is the same as above;rev3=census-ruling-rootfs-apps-3;basis=rootfs Plan 3 Tasks 7 and 8: new fields for rootfs admission (rootfsArmed, rootfsSwept), the per-host gate ask and refusal memo, and residency state (lister, backoff, start ceiling, cursor, test seam); no read;rev3=census-ruling-rootfs-apps-3-release;basis=rootfs Plan 3 Group R: one new field, releaseOps (host to the in-memory release record, under a.mu); no read;rev3=census-ruling-rootfs-apps-3-workers;basis=rootfs Plan 3 Group W: one new field, leaseNow (a clock seam for a worker start's headroom against the lease deadline, nil is the real clock); no read;rev3=census-ruling-region-ha-p1b2;basis=region HA P1b-2: gains the holder cache and its single-flight state; no read;rev3=census-ruling-managed-fleets-1b;basis=managed fleets 1b (controller ruling after branch review R1, and Paul's R2 ruling): one field, Fleet (activator.FleetWake: the box's fleet state, not on a fleet by default, on a fleet with a known label and a record reader, or on a fleet with an invalid identity), set by the agent before Start and read only by routeCurrentUnderLease. No read in the declaration. Agent, not root.;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a fix round 1: one field, drainBudget (time.Duration), which New copies from residentDrainBudget and a rootfs entry's lease watch reads in its place, so a test's change of the package var never races a watch goroutine; declaration only, reads nothing; merge of origin/main 6f1f6ca6: main's one field, Fleet (activator.FleetWake), is kept as main has it (census-ruling-managed-fleets-1b); this branch's change is the same as above;rev3=census-ruling-region-ha-p1b3a;basis=Add bounded placement peer and diagnostic state and the over-capacity callback; no read in this declaration and no new root authority.;rev3=census-ruling-stateless-replicas-1;basis=Add coordinator, existing-record observation callback and per-host preparation locks; no read in the declaration. Task 3a: Add optional canonical storage-selection and durable deploy-ID callbacks; declaration only, no read or authority in these fields.;rev3=census-ruling-edge-held-streams;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): adds the heldLegs map to actEntry (legs by id, under a.mu) and heldWakeHook (atomic pointer to a callback) and heldLegSeq (atomic counter) to Service. State only, in memory; no read of tenant, app or box-agent-writable input.;rev3=census-ruling-wake-storm-cap;basis=the agent as carlos: one field, wakeSlots (chan struct{}, the wake semaphore made by New from Config.WakeSlots, default 4); declaration only, no read.;rev3=census-ruling-region-ha-p1b3b-t;basis=Add the B2 DutyStore interface field and process-local duty view, suppression and invalidation state. No read added. B2 adds the verified-successor identity callback; no read in the declaration. B3b adds a nonblocking departure-suspicion callback, invoked only after an accepted holder-forward failure and after cache locks release; it cannot authorize a take.;rev3=census-ruling-region-ha-p3a;basis=P3a Task 3: immutable callbacks installed before Start for tenant admission, local start permission, fixed route exemptions and shutdown closure; nil callbacks preserve switch-off behavior; no new reads. Fix R1: add an immutable startup-phase callback for response copy, set before service startup. No new read or execution authority.;rev3=census-ruling-region-ha-g2-fixes;basis=Add in-memory HA loss state and pool withdrawal jobs; no new read.;rev3=census-ruling-region-ha-held-build;basis=region HA held-requests Task 1: one new field, drain (drainSources: two atomic func pointers for this box's and peers' drain state); no read added. region HA held-requests Task 2: one new field, moves (moveTable: per-host move state, hold counts and admission tickets in memory, under mu); no read added;rev3=census-ruling-held-move-speed;basis=the agent as carlos: one new field, moveStreams (per-host in-memory set of edge.StreamEnd for requests in flight, own mutex), for the move's early stream cut; actEntry gains drainRelease (bool, under a.mu), set by DrainStop; declarations only, no read added;rev3=census-ruling-fix-silent-start-kill-861;basis=#861: two fields, wakeFailMu and wakeFailLogged (per-host in-memory note of the last journalled wake failure); declaration only, no read;rev3=census-ruling-w6-ingress-drain;basis=new field TenantStartsClosed func() bool; when it answers true tenantStartRefusal refuses every start, exempt routes included. Wired only by fixedAdmission.bind to the ingress drain's closed flag. Struct field only; no read added.;rev3=census-ruling-stateless-replicas-4-task2;basis=Task 2: one field, replicaPolicies (host to the newest observed replica deploy and this box label, under mu), set only by SetReplicaDeploy; declaration only, no read. |
| +- `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. |
| +- `internal/activator/swap.go` `Service.Swap`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-stateless-replicas-1;basis=Task 3a: Verify the target canonical mode and prepare its durable stateless release before stopping the incumbent. A mode change forces the existing proven hold path; same-mode stateless overlap uses local lifecycle gates and the final current-record check, without a serving lease. CI fix 1: defer a missing registry row to the existing release checks only for stateful rootfs overlap, preserving disabled/newest checks and committedGood refusal. Stateless modes, transitions, binary/foreign/hold paths still fence before preparation. No new reads. Final review C1/R26: include incumbent Gen.Stateless as declaration evidence, so only matching good stateful recovery/config attempts can skip canonical lookup. Fresh route, release, ownership and stop gates unchanged.;rev3=census-ruling-stateless-failed-release-held;basis=Classify a proven stateless release failure, or the same deploy's durable failed or unknown phase, through the existing SwapFailed hold mechanism. Preparation precedes stopping the incumbent, so report overlap semantics even if the requested swap is hold. Stateful path unchanged; no new root input.;rev3=census-ruling-stateless-replicas-4-task2;basis=Task 2: for a set row (route FleetBoxes), refuses a stateful or non-overlap attempt before preparation, and a build the observed policy does not allow after it; refusals only, the route read is the row Swap already reads. |
| +- `internal/host/rollout.go` `armRollout`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=fix1-merge-review;basis=Comment-only clarification of failure-book saves; existing agent rollout setup remains legacy.;rev3=census-ruling-rootfs-apps-3;basis=rootfs Plan 3 Task 7: after the overlap scheduler arms, calls svc.ArmRootfs() so rootfs rows start only where the scheduler armed this boot; never on the refuseManaged path; no read added;rev3=census-ruling-stateless-replicas-1;basis=Task 3a: Bind Service.ReplicaDeployID to the same FailureBook the scheduler owns and bind RuntimeSelection to one CanonicalStatelessDigest read through the existing store. Fix 3a round 1 R18: canonical selection receives route stateless projection to keep legacy DemandHold fallback only for stateful/unknown builds; staged digest mismatch still refuses. |
| +- `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. |
| + |
| +Seal: `40c909a853a761733e9f837d4c8336bc91e174125cad65ac412f71141978be19` → `1a0605f79ac62c776bccc1ae8d166357b05c6acb56aeead59290e43b9cc67788`. |
| + |
| +Overlay: `internal/provision/testdata/plan14-root-reads-stateless-replicas-4-task2-fix1.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`. |
diff --git a/internal/activator/activator.go b/internal/activator/activator.go| index 31e83c68b..cfa676ae1 100644 |
| --- a/internal/activator/activator.go |
| +++ b/internal/activator/activator.go |
| @@ -1300,6 +1300,9 @@ type Service struct { |
| // replicaPolicies is each set row's newest observed deploy |
| // (SetReplicaDeploy), guarded by mu. It refuses early; it grants nothing. |
| replicaPolicies map[string]replicaPolicy |
| + // replicaFailed is, per set row, the permit whose step's successor |
| + // failed here (ReplicaSwap): that step only proves what it kept. |
| + replicaFailed map[string]replicaStepKey |
| // Startup gates admission while the agent recovers installations. Set before publication. |
| Startup <-chan struct{} |
diff --git a/internal/activator/replicadeploy.go b/internal/activator/replicadeploy.go| index 76d803432..e4159b3b7 100644 |
| --- a/internal/activator/replicadeploy.go |
| +++ b/internal/activator/replicadeploy.go |
| @@ -108,27 +108,44 @@ func (a *Service) replicaSwapRefusal(at Attempt, stateless bool) error { |
| return nil |
| } |
| +// replicaStepKey names one permit: an attempt and the revision that granted |
| +// its permit to this box. |
| +type replicaStepKey struct { |
| + id string |
| + permit uint64 |
| +} |
| + |
| // ReplicaSwap runs this box's permitted step of deploy: the overlap swap of |
| // at onto the deploy's target, under the existing overlap (never stop then |
| // start). Only a result with Proven set may be acknowledged; see the file |
| // comment for what it proves and in which order. box is this box's label. |
| +// |
| +// The answers, each only with Proven: |
| +// - SwapDone: switched. The target is current, healthy through its |
| +// settle window, its workers started and alive, and every older |
| +// generation and worker proven stopped (replicaStepProven). |
| +// - SwapFailed: kept. The successor failed and its stop is proven: the |
| +// incumbent is current and nothing else is left (replicaKeptProven). |
| +// - SwapAbandoned: kept, by a proof-only step that ran nothing (below). |
| +// |
| +// Two kinds of step swap nothing and so skip the start gates, because |
| +// nothing starts: a copy that already switched (a lost reply, an agent |
| +// restart) re-proves the switch; a halted permit, or one whose successor |
| +// already failed here, proves what the copy kept. Neither ever swaps. |
| func (a *Service) ReplicaSwap(ctx context.Context, at Attempt, deploy replicas.Deploy, box string, newest func(string) uint64) SwapResult { |
| a.SetReplicaDeploy(at.Host, deploy, box) |
| - // 1. The permit. |
| - if box == "" || box != a.Fleet.Label || deploy.Phase != "released" || deploy.Swap.Halted || deploy.Swap.ActiveBox != box || at.Build != deploy.Target.Version { |
| + key := replicaStepKey{deploy.ID, deploy.Swap.Permit} |
| + // 1. The permit: this box's, still unresolved, for this build. |
| + if box == "" || box != a.Fleet.Label || deploy.Phase != "released" || deploy.Swap.ActiveBox != box || at.Build != deploy.Target.Version { |
| return abandon(errReplicaTurn) |
| } |
| - // 2. Overlap only. |
| - if at.Mode != ModeOverlap || at.Demand == release.DemandHold || a.foreignRow(at.Host) { |
| - return abandon(errReplicaHold) |
| - } |
| - // 3. The start gates. |
| a.mu.Lock() |
| e := a.entries[at.Host] |
| var route registry.Route |
| if e != nil { |
| route = e.route |
| } |
| + failedHere := a.replicaFailed[at.Host] == key |
| a.mu.Unlock() |
| if e == nil { |
| return abandon(errSwapNotAwake) |
| @@ -136,21 +153,47 @@ func (a *Service) ReplicaSwap(ctx context.Context, at Attempt, deploy replicas.D |
| if route.FleetBoxes == "" { |
| return abandon(ErrFenced) |
| } |
| - if err := a.tenantStartRefusal(route); err != nil { |
| - return abandon(err) |
| - } |
| - // 4 and 5 for a step that already switched: prove it, swap nothing. |
| + // Proof only: the copy already switched. |
| if cur, ok := a.Current(at.Host); ok && cur.Build == at.Build && cur.Digest == at.Digest { |
| return a.replicaSettle(ctx, at.Host, cur) |
| } |
| + // Proof only: the step may not, or need not, swap again. |
| + if deploy.Swap.Halted || failedHere { |
| + res := abandon(errReplicaTurn) |
| + res.Proven = a.replicaKeptProven(at.Host, at.Build) |
| + if res.Proven { |
| + res.Reason = "this copy kept its current build" |
| + } |
| + return res |
| + } |
| + // 2. Overlap only. |
| + if at.Mode != ModeOverlap || at.Demand == release.DemandHold || a.foreignRow(at.Host) { |
| + return abandon(errReplicaHold) |
| + } |
| + // 3. The start gates. |
| + if err := a.tenantStartRefusal(route); err != nil { |
| + return abandon(err) |
| + } |
| // 4 and 5: the overlap, as a canary (the settle window), then the proof. |
| at.Canary = true |
| res := a.Swap(ctx, at, newest) |
| - if res.Outcome == SwapDone { |
| + switch res.Outcome { |
| + case SwapDone: |
| res.Proven = a.replicaStepProven(at.Host, res.Gen) |
| if !res.Proven && res.Reason == "" { |
| res.Reason = "the switch is not yet proven; the step stays open" |
| } |
| + case SwapFailed: |
| + // The successor's own stop must be proven before the copy answers |
| + // kept: an unproven one stays in the operation set, and the sweep |
| + // proves it. The step is not run again for this permit. |
| + a.mu.Lock() |
| + if a.replicaFailed == nil { |
| + a.replicaFailed = make(map[string]replicaStepKey) |
| + } |
| + a.replicaFailed[at.Host] = key |
| + a.mu.Unlock() |
| + res.Proven = a.replicaKeptProven(at.Host, at.Build) |
| } |
| return res |
| } |
| @@ -181,10 +224,12 @@ func (a *Service) replicaSettle(ctx context.Context, host string, g Gen) SwapRes |
| return res |
| } |
| -// replicaStepProven is the step's last proof: g is host's current, live, |
| +// replicaStepProven is a switch's last proof: g is host's current, live, |
| // awake generation; no other generation is 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, is left. |
| +// retiring one whose stop was not proven stays there until the sweep |
| +// proves it); every worker of the entry is g's, started, alive and never |
| +// restarted on it; and no worker of another generation, stray included, |
| +// is left. A build whose workers crash on start is never proven. |
| func (a *Service) replicaStepProven(host string, g Gen) bool { |
| a.mu.Lock() |
| defer a.mu.Unlock() |
| @@ -192,8 +237,23 @@ func (a *Service) replicaStepProven(host string, g Gen) bool { |
| if e == nil || e.state != actAwake || e.gen.N != g.N || e.proc == nil || e.proc.Exited() { |
| return false |
| } |
| - if len(e.ops.members) != 0 { |
| + if len(e.ops.members) != 0 || len(e.strayRootfsWorkers) != 0 { |
| return false |
| } |
| - return len(workerNamesWhereLocked(e, func(gen uint64) bool { return gen != g.N })) == 0 |
| + for _, wk := range e.rootfsWorkers { |
| + if wk.gen != g.N || wk.starting || wk.proc == nil || wk.proc.Exited() || wk.restarts != 0 || wk.crashLoop || wk.startFailed { |
| + return false |
| + } |
| + } |
| + return true |
| +} |
| + |
| +// replicaKeptProven is a "kept" answer's proof: host's current generation |
| +// is awake, live and not of build target, and nothing else is left in the |
| +// operation set, so no process of the target outlives the answer. |
| +func (a *Service) replicaKeptProven(host, target string) bool { |
| + a.mu.Lock() |
| + defer a.mu.Unlock() |
| + e := a.entries[host] |
| + return e != nil && e.state == actAwake && e.proc != nil && !e.proc.Exited() && e.gen.Build != target && len(e.ops.members) == 0 |
| } |
diff --git a/internal/activator/replicadeploy_test.go b/internal/activator/replicadeploy_test.go| index 2fa7a4838..3efdc333d 100644 |
| --- a/internal/activator/replicadeploy_test.go |
| +++ b/internal/activator/replicadeploy_test.go |
| @@ -6,7 +6,6 @@ import ( |
| "testing" |
| "time" |
| - "github.com/carlosframework/platform/internal/edge" |
| "github.com/carlosframework/platform/internal/provision" |
| "github.com/carlosframework/platform/internal/registry" |
| "github.com/carlosframework/platform/internal/release" |
| @@ -32,9 +31,20 @@ var ( |
| ) |
| func newReplicaSetRig(t *testing.T, label string, state func(inc string) *replicas.Deploy) *replicaSetRig { |
| + t.Helper() |
| + return newReplicaSetRigOn(t, label, nil, state) |
| +} |
| + |
| +// newReplicaSetRigOn is newReplicaSetRig whose record and coordinator are |
| +// shared, when shared is set: two boxes of one instance. |
| +func newReplicaSetRigOn(t *testing.T, label string, shared *replicaReleaseStore, state func(inc string) *replicas.Deploy) *replicaSetRig { |
| t.Helper() |
| r := newWakeRelRig(t) |
| store := wireStatelessRig(r) |
| + if shared != nil { |
| + store = shared |
| + r.a.Coordinator = shared |
| + } |
| rec := provision.Record{Schema: 1, Host: r.rt.Host, Account: r.rt.Account, App: r.rt.App, Channel: r.rt.Channel, Environment: r.rt.Environment, Runtime: r.rt.Runtime, Region: "fleet/pi", CreatedAt: time.Unix(1, 0), Hibernate: new(bool), ReplicaAssignment: &replicas.Assignment{Desired: 2, Revision: 1, Boxes: []string{"a", "b"}}} |
| inc, err := provision.Incarnation(rec.Account, rec.App, rec.Host, rec.CreatedAt) |
| if err != nil { |
| @@ -67,6 +77,8 @@ func newReplicaSetRig(t *testing.T, label string, state func(inc string) *replic |
| if d := state(inc); d != nil { |
| store.d = d |
| r.a.SetReplicaDeploy(r.rt.Host, *d, label) |
| + } else if d := store.snapshot(); d != nil { |
| + r.a.SetReplicaDeploy(r.rt.Host, *d, label) |
| } |
| return &replicaSetRig{wakeRelRig: r, store: store, inc: inc, label: label, stale: stale} |
| } |
| @@ -97,7 +109,9 @@ var replicaStates = []struct { |
| {"waiting", replicaAttempt("released", replicas.Swap{Order: []string{"a", "b"}, ActiveBox: "a", Permit: 4}), false, true}, |
| {"halted", replicaAttempt("released", replicas.Swap{Order: []string{"a", "b"}, Completed: []string{"a"}, Halted: true}), false, true}, |
| {"permitted", replicaAttempt("released", replicas.Swap{Order: []string{"a", "b"}, Completed: []string{"a"}, ActiveBox: "b", Permit: 5}), true, true}, |
| - {"done", replicaAttempt("done", replicas.Swap{Order: []string{"a", "b"}, Completed: []string{"a", "b"}}), true, true}, |
| + // Done: every copy runs the target; the previous build is no fallback, |
| + // and returning to it is a new attempt (fix round 1, Fable 1). |
| + {"done", replicaAttempt("done", replicas.Swap{Order: []string{"a", "b"}, Completed: []string{"a", "b"}}), true, false}, |
| } |
| func (r *replicaSetRig) started(build string) bool { |
| @@ -108,12 +122,21 @@ func (r *replicaSetRig) started(build string) bool { |
| // begin from a running copy. |
| func (r *replicaSetRig) awake(t *testing.T) { |
| t.Helper() |
| - r.setPlan(WakePlan{Boot: r.good, Mode: ModeOverlap, Token: 1}) |
| + r.awakeOn(t, r.good) |
| +} |
| + |
| +func (r *replicaSetRig) awakeOn(t *testing.T, id release.StagedIdentity) { |
| + t.Helper() |
| + r.setPlan(WakePlan{Boot: id, Mode: ModeOverlap, Token: 1}) |
| if err := waitErr(t, r.wake(r.a)); err != nil { |
| t.Fatalf("baseline wake: %v", err) |
| } |
| - if g, ok := r.a.Current(r.rt.Host); !ok || g.Build != "v1" { |
| - t.Fatalf("not awake on v1: %+v %v", g, ok) |
| + r.a.mu.Lock() |
| + e := r.a.entries[r.rt.Host] |
| + awake := e != nil && e.state == actAwake && e.gen.Build == id.Version && e.firstWatch == nil |
| + r.a.mu.Unlock() |
| + if !awake { |
| + t.Fatalf("not awake on %s", id.Version) |
| } |
| } |
| @@ -299,9 +322,6 @@ func TestReplicaSwapAcksOnlyAfterProof(t *testing.T) { |
| r := newReplicaSetRig(t, "b", permitted) |
| r.awake(t) |
| old, _ := r.a.Current(r.rt.Host) |
| - // A request admitted before the swap, still open (R8): no ticket is |
| - // awaited by a replica swap. |
| - r.a.MoveState(r.rt, edge.MoveAsk{}) |
| res := r.a.ReplicaSwap(ctx, r.attempt(CauseRelease, ModeOverlap), *r.store.snapshot(), "b", newestOne) |
| if res.Outcome != SwapDone || !res.Proven || res.Gen.Build != "v2" { |
| t.Fatalf("permitted swap: %+v", res) |
| @@ -347,8 +367,8 @@ func TestReplicaSwapAcksOnlyAfterProof(t *testing.T) { |
| return nil |
| } |
| res := r.a.ReplicaSwap(ctx, r.attempt(CauseRelease, ModeOverlap), *r.store.snapshot(), "b", newestOne) |
| - if res.Outcome != SwapFailed || res.Proven { |
| - t.Fatalf("failed successor: %+v", res) |
| + if res.Outcome != SwapFailed || !res.Proven { |
| + t.Fatalf("failed successor, its stop proven, not answered kept: %+v", res) |
| } |
| if g, ok := r.a.Current(r.rt.Host); !ok || g.Build != "v1" { |
| t.Fatal("the incumbent stopped serving") |
| @@ -362,7 +382,6 @@ func TestReplicaSwapAcksOnlyAfterProof(t *testing.T) { |
| {"start gate closed", permitted, func(r *replicaSetRig, _ *Attempt) { r.a.TenantStartsClosed = func() bool { return true } }}, |
| {"hold demand", permitted, func(_ *replicaSetRig, at *Attempt) { at.Mode = ModeHold }}, |
| {"another box's permit", replicaAttempt("released", replicas.Swap{Order: []string{"a", "b"}, ActiveBox: "a", Permit: 4}), func(*replicaSetRig, *Attempt) {}}, |
| - {"halted permit", replicaAttempt("released", replicas.Swap{Order: []string{"a", "b"}, Completed: []string{"a"}, ActiveBox: "b", Permit: 5, Halted: true}), func(*replicaSetRig, *Attempt) {}}, |
| } { |
| t.Run(tc.name, func(t *testing.T) { |
| r := newReplicaSetRig(t, "b", tc.state) |
| @@ -376,3 +395,241 @@ func TestReplicaSwapAcksOnlyAfterProof(t *testing.T) { |
| }) |
| } |
| } |
| + |
| +// TestReplicaWakeAndAdoptRollbackAfterDone (fix round 1, Fable 1): v2's |
| +// deploy is done on boxes a and b, and the pointer is rolled back to v1, |
| +// the attempt's Previous. Neither box starts v1 without an attempt: the |
| +// rollback begins one new attempt, once, and v1 waits for its permits like |
| +// any promotion (D3). A cold wake of the last passed build, v2, still |
| +// starts while the rollback waits, so nothing wedges. |
| +func TestReplicaWakeAndAdoptRollbackAfterDone(t *testing.T) { |
| + store := &replicaReleaseStore{held: newOwnedLease(time.Now().Add(time.Hour), false)} |
| + done := replicaAttempt("done", replicas.Swap{Order: []string{"a", "b"}, Completed: []string{"a", "b"}}) |
| + a := newReplicaSetRigOn(t, "a", store, done) |
| + b := newReplicaSetRigOn(t, "b", store, func(string) *replicas.Deploy { return nil }) |
| + for _, r := range []*replicaSetRig{a, b} { |
| + r.rt.Version = "v1" // the rolled-back pointer |
| + r.routes.set(r.rt) |
| + r.setPlan(WakePlan{Boot: r.good, Mode: ModeOverlap, FirstWake: true, Token: 1}) |
| + waitErr(t, r.wake(r.a)) |
| + if r.started("v1") { |
| + t.Fatalf("box %s rolled back without an attempt: %v", r.label, r.b.events()) |
| + } |
| + } |
| + d := store.snapshot() |
| + if d.ID != "deploy-v1" || d.Target.Version != "v1" || !replicas.ReleasePassed(d.Phase) || d.Previous != replicaTarget || store.acquires != 1 { |
| + t.Fatalf("the rollback is not one new attempt: %+v (acquires %d)", d, store.acquires) |
| + } |
| + // Box b's copy is down; its cold wake boots the last passed build. |
| + b.setPlan(WakePlan{Boot: b.next, Mode: ModeOverlap, FirstWake: true, Token: 2}) |
| + if err := waitErr(t, b.wake(b.a)); err != nil || !b.started("v2") { |
| + t.Fatalf("cold wake of the last passed build wedged: %v %v", err, b.b.events()) |
| + } |
| + |
| + // The same for a box that completed its switch before a halt: v1 is |
| + // still the attempt's baseline, but a pointer naming it is a rollback, |
| + // and a rollback is a new attempt. |
| + halted := newReplicaSetRig(t, "a", replicaAttempt("released", replicas.Swap{Order: []string{"a", "b"}, Completed: []string{"a"}, Halted: true})) |
| + halted.rt.Version = "v1" |
| + halted.routes.set(halted.rt) |
| + halted.setPlan(WakePlan{Boot: halted.good, Mode: ModeOverlap, FirstWake: true, Token: 1}) |
| + waitErr(t, halted.wake(halted.a)) |
| + if halted.started("v1") || halted.store.snapshot().ID != "deploy-v1" { |
| + t.Fatalf("a completed box rolled back without an attempt: %v %+v", halted.b.events(), halted.store.snapshot()) |
| + } |
| +} |
| + |
| +// TestReplicaReturnsAfterDeployWithStaleInstall (fix round 1, Astra 3): the |
| +// committed target controls a copy whatever its installed state says. A box |
| +// whose row still installs v1 boots the done target v2. |
| +func TestReplicaReturnsAfterDeployWithStaleInstall(t *testing.T) { |
| + r := newReplicaSetRig(t, "b", replicaAttempt("done", replicas.Swap{Order: []string{"a"}, Completed: []string{"a"}})) |
| + r.rt.Version = "v1" |
| + r.routes.set(r.rt) |
| + 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") || r.started("v1") { |
| + t.Fatalf("stale install vetoed the committed target: %v %v", err, r.b.events()) |
| + } |
| + if len(r.b.releaseStarts()) != 0 || r.store.snapshot().ID != "deploy-v2" { |
| + t.Fatal("the return began a release") |
| + } |
| +} |
| + |
| +// TestReplicaSwapProofOnlySteps (fix round 1): steps that must not swap |
| +// prove what the copy runs instead, with the start gate closed because |
| +// nothing starts. A halted permit after lost answers: kept on the |
| +// baseline, switched on the target. A successor that failed with an |
| +// unproven stop: no answer until its stop is proven, then kept, never a |
| +// second swap. A permit whose pointer moved on still switches. |
| +func TestReplicaSwapProofOnlySteps(t *testing.T) { |
| + prev := swapSettle |
| + swapSettle = 20 * time.Millisecond |
| + t.Cleanup(func() { swapSettle = prev }) |
| + ctx := context.Background() |
| + permit := replicas.Swap{Order: []string{"a", "b"}, Completed: []string{"a"}, ActiveBox: "b", Permit: 5} |
| + halted := permit |
| + halted.Halted = true |
| + closed := func() bool { return true } |
| + |
| + t.Run("halted, kept", func(t *testing.T) { |
| + r := newReplicaSetRig(t, "b", replicaAttempt("released", halted)) |
| + r.awake(t) |
| + r.a.TenantStartsClosed = closed |
| + res := r.a.ReplicaSwap(ctx, r.attempt(CauseRelease, ModeOverlap), *r.store.snapshot(), "b", newestOne) |
| + if res.Outcome != SwapAbandoned || !res.Proven || r.started("v2") { |
| + t.Fatalf("halted, on the baseline: %+v", res) |
| + } |
| + }) |
| + t.Run("halted, switched", func(t *testing.T) { |
| + r := newReplicaSetRig(t, "b", replicaAttempt("released", permit)) |
| + r.awake(t) |
| + if res := r.a.ReplicaSwap(ctx, r.attempt(CauseRelease, ModeOverlap), *r.store.snapshot(), "b", newestOne); !res.Proven { |
| + t.Fatalf("switch: %+v", res) |
| + } |
| + // The answer was lost (an agent restart) and placement halted. |
| + r.store.d = replicaAttempt("released", halted)(r.inc) |
| + r.a.TenantStartsClosed = closed |
| + starts := len(r.b.started()) |
| + res := r.a.ReplicaSwap(ctx, r.attempt(CauseRelease, ModeOverlap), *r.store.snapshot(), "b", newestOne) |
| + if res.Outcome != SwapDone || !res.Proven || len(r.b.started()) != starts { |
| + t.Fatalf("halted, on the target: %+v", res) |
| + } |
| + }) |
| + t.Run("failed successor, stop unproven", func(t *testing.T) { |
| + r := newReplicaSetRig(t, "b", replicaAttempt("released", permit)) |
| + r.awake(t) |
| + var successor *fakeProc |
| + r.a.genHealth = func(_ context.Context, g Gen) error { |
| + if g.Build != "v2" { |
| + return nil |
| + } |
| + successor = r.b.procOf(g.N) |
| + successor.mu.Lock() |
| + successor.stuck = true |
| + successor.mu.Unlock() |
| + return context.DeadlineExceeded |
| + } |
| + res := r.a.ReplicaSwap(ctx, r.attempt(CauseRelease, ModeOverlap), *r.store.snapshot(), "b", newestOne) |
| + t.Cleanup(successor.exit) |
| + if res.Outcome != SwapFailed || res.Proven { |
| + t.Fatalf("kept before the failed successor's stop was proven: %+v", res) |
| + } |
| + starts := len(r.b.started()) |
| + if again := r.a.ReplicaSwap(ctx, r.attempt(CauseRelease, ModeOverlap), *r.store.snapshot(), "b", newestOne); again.Proven { |
| + t.Fatalf("answered while the successor's stop is unproven: %+v", again) |
| + } |
| + successor.exit() |
| + waitFor(t, "the sweep's proof of the failed successor", func() bool { |
| + r.a.sweepOnce() |
| + res = r.a.ReplicaSwap(ctx, r.attempt(CauseRelease, ModeOverlap), *r.store.snapshot(), "b", newestOne) |
| + return res.Proven |
| + }) |
| + if res.Outcome != SwapAbandoned || len(r.b.started()) != starts { |
| + t.Fatalf("the proof swapped again: %+v", res) |
| + } |
| + if g, ok := r.a.Current(r.rt.Host); !ok || g.Build != "v1" { |
| + t.Fatal("the incumbent stopped serving") |
| + } |
| + }) |
| + t.Run("pointer moved on", func(t *testing.T) { |
| + r := newReplicaSetRig(t, "b", replicaAttempt("released", permit)) |
| + r.awake(t) |
| + r.rt.Version = "v3" |
| + r.routes.set(r.rt) |
| + res := r.a.ReplicaSwap(ctx, r.attempt(CauseRelease, ModeOverlap), *r.store.snapshot(), "b", newestOne) |
| + if res.Outcome != SwapDone || !res.Proven || res.Gen.Build != "v2" { |
| + t.Fatalf("a newer pointer stranded the open permit: %+v", res) |
| + } |
| + }) |
| +} |
| + |
| +// TestReplicaSwapWaitsForWorkers (fix round 1, Fable 5): the switch is not |
| +// proven until the new generation's workers have started and are alive. A |
| +// build whose worker crashes on start is never proven, so never acked. |
| +func TestReplicaSwapWaitsForWorkers(t *testing.T) { |
| + prev := swapSettle |
| + swapSettle = 20 * time.Millisecond |
| + t.Cleanup(func() { swapSettle = prev }) |
| + ctx := context.Background() |
| + for _, crash := range []bool{false, true} { |
| + t.Run(map[bool]string{false: "started", true: "crashes on start"}[crash], 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}} |
| + 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) |
| + res := r.a.ReplicaSwap(ctx, r.attempt(CauseRelease, ModeOverlap), *r.store.snapshot(), "b", newestOne) |
| + if res.Outcome != SwapDone || res.Proven { |
| + t.Fatalf("proven before its workers started: %+v", res) |
| + } |
| + r.a.rootfsTick() |
| + waitFor(t, "the worker", func() bool { return workers.alive() == 1 }) |
| + if crash { |
| + workers.lastWorker(t, "jobs").exit("exited", "1") |
| + r.a.rootfsTick() |
| + } |
| + res = r.a.ReplicaSwap(ctx, r.attempt(CauseRelease, ModeOverlap), *r.store.snapshot(), "b", newestOne) |
| + if res.Proven == crash { |
| + t.Fatalf("crash=%t: %+v", crash, res) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// TestReplicaSwapRetiresAfterRoutedRequests (R8 as amended by the |
| +// controller): replica routes never enter the move gate, so no ticket is |
| +// involved. The old generation stops only after the request already routed |
| +// to it finishes (its drain), while successor requests keep arriving, are |
| +// served and are never awaited; the answer follows the stop proof. |
| +func TestReplicaSwapRetiresAfterRoutedRequests(t *testing.T) { |
| + prev := swapSettle |
| + swapSettle = 20 * time.Millisecond |
| + t.Cleanup(func() { swapSettle = prev }) |
| + r := newReplicaSetRig(t, "b", replicaAttempt("released", replicas.Swap{Order: []string{"a", "b"}, Completed: []string{"a"}, ActiveBox: "b", Permit: 5})) |
| + r.awake(t) |
| + old, _ := r.a.Current(r.rt.Host) |
| + p := r.b.procOf(old.N) |
| + // The request routed to the old generation: its drain holds the stop. |
| + routed := make(chan struct{}) |
| + p.setStopGate(routed) |
| + t.Cleanup(func() { |
| + select { |
| + case <-routed: |
| + default: |
| + close(routed) |
| + } |
| + }) |
| + out := make(chan SwapResult, 1) |
| + go func() { |
| + out <- r.a.ReplicaSwap(context.Background(), r.attempt(CauseRelease, ModeOverlap), *r.store.snapshot(), "b", newestOne) |
| + }() |
| + waitFor(t, "the old generation's drain", func() bool { |
| + p.mu.Lock() |
| + defer p.mu.Unlock() |
| + return p.stopEnters > 0 |
| + }) |
| + for i := 0; i < 5; i++ { |
| + done, err := r.a.beginRequest(context.Background(), r.rt) |
| + if err != nil { |
| + t.Fatalf("successor request %d was held: %v", i, err) |
| + } |
| + done() |
| + if g, ok := r.a.Current(r.rt.Host); !ok || g.Build != "v2" { |
| + t.Fatalf("successor request %d not on the new generation", i) |
| + } |
| + } |
| + select { |
| + case res := <-out: |
| + t.Fatalf("answered before the routed request finished: %+v", res) |
| + case <-time.After(50 * time.Millisecond): |
| + } |
| + close(routed) |
| + select { |
| + case res := <-out: |
| + if res.Outcome != SwapDone || !res.Proven || !p.Exited() { |
| + t.Fatalf("after the drain: %+v", res) |
| + } |
| + case <-time.After(10 * time.Second): |
| + t.Fatal("retirement did not end once the routed request finished") |
| + } |
| +} |
diff --git a/internal/activator/stateless.go b/internal/activator/stateless.go| index ad68ed20b..1e7dd5133 100644 |
| --- a/internal/activator/stateless.go |
| +++ b/internal/activator/stateless.go |
| @@ -397,19 +397,42 @@ func (a *Service) prepareStateless(ctx context.Context, rt registry.Route, id re |
| return ctx, err |
| } |
| observation, _ := observed.Value(replicaObservationKey{}).(replicaObservation) |
| - if rt.FleetBoxes != "" { |
| - // A copy of an assigned instance (D4): its baseline is the record's, |
| - // never the box's local good build, and it runs no release. A build |
| - // the pointer does not name is never released here either. The final |
| - // gate asks the record again (statelessFinalRecord). |
| - if base := observation.record.ReplicaDeploy.Baseline(); base.Digest != "" && base.Digest == digest && base.Version == id.Version && base != observation.record.ReplicaDeploy.Target { |
| - prepared := &statelessPreparation{route: rt, id: id, digest: digest, observation: observation, baseline: true} |
| - return context.WithValue(observed, statelessPreparedKey{}, prepared), nil |
| + if rt.FleetBoxes != "" && id.Version != rt.Version { |
| + // A copy of an assigned instance starting a build its pointer does |
| + // not name (D4). It may start only what the record already allows |
| + // on this box, and never begins a release for it: the attempt's |
| + // baseline, or the committed target whatever this box's installed |
| + // state says (a stale row, or a pointer that moved on during an open |
| + // permit). The box's local good build is never used. A build the |
| + // pointer does name, including a rollback to the previous build, |
| + // takes the release path below: one path for promotion, rollback |
| + // and first deploy (D3). The final gate asks the record again. |
| + d, box, inc := observation.record.ReplicaDeploy, a.Fleet.Label, observation.record.Identity.Incarnation |
| + if !d.Allows(box, inc, digest) { |
| + return ctx, errReplicaTurn |
| } |
| - if id.Version != rt.Version { |
| + prepared := &statelessPreparation{route: rt, id: id, digest: digest, observation: observation} |
| + switch { |
| + case d.Target == (replicas.Build{Version: id.Version, Digest: digest}) && d.TargetAllowed(box): |
| + if replicas.DurableAttempt(d, inc, d.Target) == nil { |
| + return ctx, errReplicaTurn // a requested retry: only a named build begins one |
| + } |
| + launch := rt |
| + launch.Stateless = true |
| + // Adopts the passed attempt (its escrow initialization |
| + // included); with a durable attempt it never coordinates. |
| + deployID, err := a.prepareStatelessRelease(observed, launch, id, a.ReplicaDeployID) |
| + if err != nil { |
| + return ctx, err |
| + } |
| + prepared.deployID = deployID |
| + case d.Baseline() == (replicas.Build{Version: id.Version, Digest: digest}): |
| + prepared.baseline = true |
| + default: |
| return ctx, errReplicaTurn |
| } |
| - } else if id.Version != rt.Version && id.Version != "" && id.Digest != "" { |
| + return context.WithValue(observed, statelessPreparedKey{}, prepared), nil |
| + } else if rt.FleetBoxes == "" && id.Version != rt.Version && id.Version != "" && id.Digest != "" { |
| // Recovery uses the committed good build without replacing the failed |
| // deploy or rerunning its predecessor's release. The final gate checks it again. |
| good, err := a.committedGood(rt) |
diff --git a/internal/activator/statelessrelease_test.go b/internal/activator/statelessrelease_test.go| index 7971c6dd1..ec25f381f 100644 |
| --- a/internal/activator/statelessrelease_test.go |
| +++ b/internal/activator/statelessrelease_test.go |
| @@ -56,6 +56,17 @@ func (s *replicaReleaseStore) ReleaseState(_ context.Context, id replicas.Identi |
| phase = "pending" |
| } |
| d := replicas.Deploy{ID: c.ID, Target: c.Target, Incarnation: id.Incarnation, Term: c.Term, Phase: phase, Revision: rev + 1} |
| + // LastGood and Previous as the real writer keeps them |
| + // (provision.SetRecordReplicaRelease). |
| + if s.d != nil && s.d.ID == c.ID { |
| + d.LastGood, d.Previous = s.d.LastGood, s.d.Previous |
| + } else { |
| + d.LastGood = replicas.CarryLastGood(s.d, id.Incarnation) |
| + d.Previous = d.LastGood |
| + } |
| + if phase == "released" { |
| + d.LastGood = d.Target |
| + } |
| s.d = &d |
| if c.Op == "begin" && s.beginHook != nil { |
| hook := s.beginHook |
diff --git a/internal/activator/swap.go b/internal/activator/swap.go| index c9cb24cb4..72a162715 100644 |
| --- a/internal/activator/swap.go |
| +++ b/internal/activator/swap.go |
| @@ -103,11 +103,13 @@ type SwapResult struct { |
| // triage T9). A replacement still running at the end of the window is |
| // SwapDone with CleanExit false. |
| CleanExit bool |
| - // Proven is ReplicaSwap's proof for a replicated deploy's step: the |
| - // result's generation is current and healthy through its settle |
| - // window, the workers are handed over and every older generation's |
| - // stop is proven. A box acknowledges its permit only for a SwapDone |
| - // with Proven set. Swap itself never sets it. |
| + // Proven is ReplicaSwap's proof for a replicated deploy's step. With |
| + // SwapDone: the new generation is current and healthy through its |
| + // settle window, its workers are started and alive, and every older |
| + // generation's stop is proven (switched). With SwapFailed or |
| + // SwapAbandoned: the incumbent is current and the failed successor's |
| + // stop is proven, or nothing ran (kept). A box acknowledges its permit |
| + // only for a result with Proven set. Swap itself never sets it. |
| Proven bool |
| } |
| @@ -380,6 +382,12 @@ func (a *Service) Swap(ctx context.Context, at Attempt, newest func(host string) |
| if err := a.replicaSwapRefusal(at, mode); err != nil { |
| return abandon(err) |
| } |
| + // Nor may a mode change below turn it into a hold: a copy's |
| + // incumbent is always stateless (the stateful wake path refuses a |
| + // set row), so one that is not is refused here. |
| + if !oldStateless { |
| + return abandon(errReplicaHold) |
| + } |
| } |
| if mode { |
| prepared, err := a.prepareStateless(ctx, route, id, digest) |
diff --git a/internal/host/replica_deploy_e2e_test.go b/internal/host/replica_deploy_e2e_test.go| index 0c4318460..941229cb7 100644 |
| --- a/internal/host/replica_deploy_e2e_test.go |
| +++ b/internal/host/replica_deploy_e2e_test.go |
| @@ -356,3 +356,16 @@ func TestReplicaOneSurvivorDeploy(t *testing.T) { |
| t.Fatalf("the return changed the deploy: %+v", d) |
| } |
| } |
| + |
| +// TestReplicaSwapSchedulerUsesFleetLabel (fix round 1, Fable 6): on a fleet |
| +// box the scheduler's box label is the fleet identity's label, the one the |
| +// activator's replica gates hold, so a permit and the gates name one box. |
| +func TestReplicaSwapSchedulerUsesFleetLabel(t *testing.T) { |
| + svc := &activator.Service{Fleet: activator.FleetWake{Mode: activator.FleetWakeCheck, Fleet: "pi", Label: "b"}} |
| + if got := rolloutBox(svc); got != "b" { |
| + t.Fatalf("scheduler box %q, gates %q", got, svc.Fleet.Label) |
| + } |
| + if got := rolloutBox(&activator.Service{}); got != BoxLabel() { |
| + t.Fatalf("off a fleet: %q", got) |
| + } |
| +} |
diff --git a/internal/host/rollout.go b/internal/host/rollout.go| index b7c1e89b5..b5a8a2d11 100644 |
| --- a/internal/host/rollout.go |
| +++ b/internal/host/rollout.go |
| @@ -387,7 +387,7 @@ func armRollout(ctx context.Context, getenv func(string) string, svc *activator. |
| } |
| svc.ReplicaDeployID = book.ReplicaDeployID |
| m := rollout.NewManager(ctx, rollout.Deps{ |
| - Act: svc, Routes: reg, Book: book, OptDir: release.OptDir(), DataDir: dd, Box: BoxLabel(), |
| + Act: svc, Routes: reg, Book: book, OptDir: release.OptDir(), DataDir: dd, Box: rolloutBox(svc), |
| Demand: func(ctx context.Context, acct, app, ver, path string) (string, string, error) { |
| selection, err := release.CanonicalRuntimeSelection(ctx, store, acct, app, ver, path, false) |
| return selection.Identity.Demand, selection.Identity.Digest, err |
| @@ -423,6 +423,18 @@ func armRollout(ctx context.Context, getenv func(string) string, svc *activator. |
| return m |
| } |
| +// rolloutBox is the scheduler's box label. On a fleet box it is the fleet |
| +// identity's label, the same value the activator's replica gates hold |
| +// (svc.Fleet.Label, set from identity.Label before the scheduler arms), so |
| +// the scheduler's permits and the gates name one box. Elsewhere it is the |
| +// metrics label (BoxLabel), which only names the box in events. |
| +func rolloutBox(svc *activator.Service) string { |
| + if svc.Fleet.Mode == activator.FleetWakeCheck && svc.Fleet.Label != "" { |
| + return svc.Fleet.Label |
| + } |
| + return BoxLabel() |
| +} |
| + |
| // rolloutLegFor is the converge leg with the flag on (spec §10): the agent |
| // pass of spec §6.1, every adoptedConvergeEvery, in place of convergeAdopted. |
| func rolloutLegFor(m *rollout.Manager, reg *registry.Registry) func() { |
diff --git a/internal/provision/stateless_replicas_4_task2_census_test.go b/internal/provision/stateless_replicas_4_task2_census_test.go| index 61360b4f0..3d02f76de 100644 |
| --- a/internal/provision/stateless_replicas_4_task2_census_test.go |
| +++ b/internal/provision/stateless_replicas_4_task2_census_test.go |
| @@ -16,10 +16,18 @@ package provision |
| // is the unchanged statelessRecordKey observation. |
| // - No new record writer. The swap worker's ACK goes through Task 1's |
| // /deploy door and SetRecordReplicaDeploy, unchanged. |
| +// |
| +// Fix round 1, self-review: |
| +// - prepareStateless: a set row's build its pointer does not name starts |
| +// only as the record's baseline or its committed, permitted target |
| +// (adopted through prepareStatelessRelease's durable path, which never |
| +// begins an attempt); a build the pointer names, a rollback included, |
| +// takes the release path. It still writes no record; the reference is |
| +// the unchanged statelessRecordKey observation. |
| func statelessReplicas4Task2WriteCensusInventory() []censusEntry { |
| entries := append([]censusEntry(nil), statelessReplicas4Task1WriteCensusInventory()...) |
| for _, r := range []censusEntry{ |
| - {"internal/activator/stateless.go", "Service.prepareStateless", "reference", "key:statelessRecordKey", "2585582c2a68892b701f4d1fdf9f40bf4cec8a667cb1ff3a10477e354f668304"}, |
| + {"internal/activator/stateless.go", "Service.prepareStateless", "reference", "key:statelessRecordKey", "9dea1add8190b42c08ed29690350fde6e2c28644d98a5897ea89b7507125e1e6"}, |
| {"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 4ab2616ea..0987727e9 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-chain.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-chain.tsv |
| @@ -173,3 +173,4 @@ plan14-root-reads-stateless-replicas-4-task1-fix1.tsv 3f066208f5e5fa2b9854f30118 |
| plan14-root-reads-stateless-replicas-4-task1-fix2.tsv 3f066208f5e5fa2b9854f30118a9a2707f3a5a51bcf55ae6b0949cb0307804f5 |
| plan14-root-reads-stateless-replicas-4-task1-fix3.tsv 3f066208f5e5fa2b9854f30118a9a2707f3a5a51bcf55ae6b0949cb0307804f5 |
| plan14-root-reads-stateless-replicas-4-task2.tsv 40c909a853a761733e9f837d4c8336bc91e174125cad65ac412f71141978be19 |
| +plan14-root-reads-stateless-replicas-4-task2-fix1.tsv 1a0605f79ac62c776bccc1ae8d166357b05c6acb56aeead59290e43b9cc67788 |
diff --git a/internal/provision/testdata/plan14-root-reads-stateless-replicas-4-task2-fix1.tsv b/internal/provision/testdata/plan14-root-reads-stateless-replicas-4-task2-fix1.tsv| new file mode 100644 |
| index 000000000..7bb627777 |
| --- /dev/null |
| +++ b/internal/provision/testdata/plan14-root-reads-stateless-replicas-4-task2-fix1.tsv |
| @@ -0,0 +1,15 @@ |
| +# Census overlay stateless-replicas-4-task2-fix1, written by census-propose (#369). census-ruling-stateless-replicas-4-task2-fix1, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-stateless-replicas-4-task2-fix1.md. |
| +# 4 body, 1 sites, 4 envelope: each changed unit re-frozen at its existing disposition with its claim appended. |
| +@legacy 564ab7cf17dd24e3366e4986f0184081e28561dfc17424f903c97c8e3d2f0818 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. registry:FleetBoxes@694,whole:Route@1408,whole:Route@557,whole:Route@567 8fc0129043a21a728c0f274cdeae478f4733ed45930ea2548fd6e17bf823a0ae |
| +@legacy 7c5b118a140009560120100c2b8b0b546e563769b47f8a2e9f50a1ff0cf5f6da internal/activator/swap.go Service.Swap legacy accepted-legacy accepted-legacy;rev3=census-ruling-stateless-replicas-1;basis=Task 3a: Verify the target canonical mode and prepare its durable stateless release before stopping the incumbent. A mode change forces the existing proven hold path; same-mode stateless overlap uses local lifecycle gates and the final current-record check, without a serving lease. CI fix 1: defer a missing registry row to the existing release checks only for stateful rootfs overlap, preserving disabled/newest checks and committedGood refusal. Stateless modes, transitions, binary/foreign/hold paths still fence before preparation. No new reads. Final review C1/R26: include incumbent Gen.Stateless as declaration evidence, so only matching good stateful recovery/config attempts can skip canonical lookup. Fresh route, release, ownership and stop gates unchanged.;rev3=census-ruling-stateless-failed-release-held;basis=Classify a proven stateless release failure, or the same deploy's durable failed or unknown phase, through the existing SwapFailed hold mechanism. Preparation precedes stopping the incumbent, so report overlap semantics even if the requested swap is hold. Stateful path unchanged; no new root input.;rev3=census-ruling-stateless-replicas-4-task2;basis=Task 2: for a set row (route FleetBoxes), refuses a stateful or non-overlap attempt before preparation, and a build the observed policy does not allow after it; refusals only, the route read is the row Swap already reads.;rev3=census-ruling-stateless-replicas-4-task2-fix1;basis=Task 2 fix round 1: a set row whose incumbent is not stateless is refused (errReplicaHold) before preparation, so the mode-change hold conversion below can never run a set row as a hold; with replicaSwapRefusal this keeps every set row off swapHold and releaseBeforeSwap. Refusal only, no read added. registry:FleetBoxes@1723,registry:Stateless@1340,registry:Stateless@1369,whole:Route@1013,whole:Route@1063,whole:Route@1072,whole:Route@1257,whole:Route@1333,whole:Route@1446,whole:Route@1690,whole:Route@2254,whole:Route@2726,whole:Route@3144,whole:Route@785,whole:Route@801 473eae4437bd3a20ed226d6042ac73b0cc429b4c83f3879643fda62f35ca0517 |
| +@legacy 44e3cf5e22d37d64e82296bc8c12a8ec8f20851af2c8ec072cc55f78899dce13 internal/host/rollout.go armRollout legacy accepted-legacy accepted-legacy;rev3=fix1-merge-review;basis=Comment-only clarification of failure-book saves; existing agent rollout setup remains legacy.;rev3=census-ruling-rootfs-apps-3;basis=rootfs Plan 3 Task 7: after the overlap scheduler arms, calls svc.ArmRootfs() so rootfs rows start only where the scheduler armed this boot; never on the refuseManaged path; no read added;rev3=census-ruling-stateless-replicas-1;basis=Task 3a: Bind Service.ReplicaDeployID to the same FailureBook the scheduler owns and bind RuntimeSelection to one CanonicalStatelessDigest read through the existing store. Fix 3a round 1 R18: canonical selection receives route stateless projection to keep legacy DemandHold fallback only for stateful/unknown builds; staged digest mismatch still refuses.;rev3=census-ruling-stateless-replicas-4-task2-fix1;basis=Task 2 fix round 1: the scheduler box label is rolloutBox(svc): the fleet identity label already on svc.Fleet (set from identity.Label before the scheduler arms), else BoxLabel() as before. No read added. registry:App@2917,registry:Stateless@2936,whole:Route@2912,whole:Route@3604,whole:Route@3688 20af28dfe9a50dde181a36dfe944c087387f8b558bd6418b92f5f5d8c646c902 |
| +@legacy 856e1ddb56ea8fb0ac12672b95080e612fd5d02f476ff1c8da2ccecd5035b1ed 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. registry:Account@284,registry:Account@310,registry:App@324,registry:App@346,registry:Digest@3059,registry:FleetBoxes@2702,registry:FleetBoxes@944,registry:Host@250,registry:Host@273,registry:Stateless@2156,registry:Stateless@3357,registry:Version@2739,registry:Version@3029,registry:Version@981,whole:Route@1822,whole:Route@1829,whole:Route@2150,whole:Route@2357,whole:Route@259,whole:Route@293,whole:Route@2979,whole:Route@3123,whole:Route@3130,whole:Route@333,whole:Route@3353,whole:Route@3507,whole:Route@3611,whole:Route@3618,whole:Route@540,whole:Route@597,whole:Route@714,whole:Route@821 9dea1add8190b42c08ed29690350fde6e2c28644d98a5897ea89b7507125e1e6 |
| +internal/activator/activator.go type Service authority B,C,D,F,J4 rev3=PROPOSED-seed; existing activator lifecycle and due-wake state plus owned seed exclusion and incarnation-keyed diagnostics; normal refusal and preparation ordering remain authoritative; PROPOSED-plans-2-box-limits adds the idleFor hook field, which only narrows idle windows;rev3=census-ruling-plans-4c-box-throttle;basis=gains the maxRunFor hook field beside idleFor (plans 4c). No read added.;rev3=census-ruling-plans-4d-lapse;basis=gains the disabledFor hook field beside maxRunFor (plans 4d). No read added.;rev3=census-ruling-remote-instance-metrics;basis=gains tenancySeq, hostTenants and hostMixed, in-memory fields for Tenancies; no read added;rev3=census-ruling-region-ha-p1a;basis=the agent as carlos: one more field, markers (markerRetry: an atomic running flag and the last log time) for retryOwedMarkers; no read added; merge of origin/main d7ae1d76: main's fields are kept as main has them (census-ruling-remote-instance-metrics: tenancySeq, hostTenants, hostMixed); this branch's change is the same as above;rev3=census-ruling-rootfs-apps-3;basis=rootfs Plan 3 Tasks 7 and 8: new fields for rootfs admission (rootfsArmed, rootfsSwept), the per-host gate ask and refusal memo, and residency state (lister, backoff, start ceiling, cursor, test seam); no read;rev3=census-ruling-rootfs-apps-3-release;basis=rootfs Plan 3 Group R: one new field, releaseOps (host to the in-memory release record, under a.mu); no read;rev3=census-ruling-rootfs-apps-3-workers;basis=rootfs Plan 3 Group W: one new field, leaseNow (a clock seam for a worker start's headroom against the lease deadline, nil is the real clock); no read;rev3=census-ruling-region-ha-p1b2;basis=region HA P1b-2: gains the holder cache and its single-flight state; no read;rev3=census-ruling-managed-fleets-1b;basis=managed fleets 1b (controller ruling after branch review R1, and Paul's R2 ruling): one field, Fleet (activator.FleetWake: the box's fleet state, not on a fleet by default, on a fleet with a known label and a record reader, or on a fleet with an invalid identity), set by the agent before Start and read only by routeCurrentUnderLease. No read in the declaration. Agent, not root.;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a fix round 1: one field, drainBudget (time.Duration), which New copies from residentDrainBudget and a rootfs entry's lease watch reads in its place, so a test's change of the package var never races a watch goroutine; declaration only, reads nothing; merge of origin/main 6f1f6ca6: main's one field, Fleet (activator.FleetWake), is kept as main has it (census-ruling-managed-fleets-1b); this branch's change is the same as above;rev3=census-ruling-region-ha-p1b3a;basis=Add bounded placement peer and diagnostic state and the over-capacity callback; no read in this declaration and no new root authority.;rev3=census-ruling-stateless-replicas-1;basis=Add coordinator, existing-record observation callback and per-host preparation locks; no read in the declaration. Task 3a: Add optional canonical storage-selection and durable deploy-ID callbacks; declaration only, no read or authority in these fields.;rev3=census-ruling-edge-held-streams;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): adds the heldLegs map to actEntry (legs by id, under a.mu) and heldWakeHook (atomic pointer to a callback) and heldLegSeq (atomic counter) to Service. State only, in memory; no read of tenant, app or box-agent-writable input.;rev3=census-ruling-wake-storm-cap;basis=the agent as carlos: one field, wakeSlots (chan struct{}, the wake semaphore made by New from Config.WakeSlots, default 4); declaration only, no read.;rev3=census-ruling-region-ha-p1b3b-t;basis=Add the B2 DutyStore interface field and process-local duty view, suppression and invalidation state. No read added. B2 adds the verified-successor identity callback; no read in the declaration. B3b adds a nonblocking departure-suspicion callback, invoked only after an accepted holder-forward failure and after cache locks release; it cannot authorize a take.;rev3=census-ruling-region-ha-p3a;basis=P3a Task 3: immutable callbacks installed before Start for tenant admission, local start permission, fixed route exemptions and shutdown closure; nil callbacks preserve switch-off behavior; no new reads. Fix R1: add an immutable startup-phase callback for response copy, set before service startup. No new read or execution authority.;rev3=census-ruling-region-ha-g2-fixes;basis=Add in-memory HA loss state and pool withdrawal jobs; no new read.;rev3=census-ruling-region-ha-held-build;basis=region HA held-requests Task 1: one new field, drain (drainSources: two atomic func pointers for this box's and peers' drain state); no read added. region HA held-requests Task 2: one new field, moves (moveTable: per-host move state, hold counts and admission tickets in memory, under mu); no read added;rev3=census-ruling-held-move-speed;basis=the agent as carlos: one new field, moveStreams (per-host in-memory set of edge.StreamEnd for requests in flight, own mutex), for the move's early stream cut; actEntry gains drainRelease (bool, under a.mu), set by DrainStop; declarations only, no read added;rev3=census-ruling-fix-silent-start-kill-861;basis=#861: two fields, wakeFailMu and wakeFailLogged (per-host in-memory note of the last journalled wake failure); declaration only, no read;rev3=census-ruling-w6-ingress-drain;basis=new field TenantStartsClosed func() bool; when it answers true tenantStartRefusal refuses every start, exempt routes included. Wired only by fixedAdmission.bind to the ingress drain's closed flag. Struct field only; no read added.;rev3=census-ruling-stateless-replicas-4-task2;basis=Task 2: one field, replicaPolicies (host to the newest observed replica deploy and this box label, under mu), set only by SetReplicaDeploy; declaration only, no read.;rev3=census-ruling-stateless-replicas-4-task2-fix1;basis=Task 2 fix round 1: one more in-memory field, replicaFailed (host to the permit whose successor failed here, under mu), so that step only proves what it kept; declaration only, no read. 165c9602e6d361d8c8097e1466dc7071bfc98b9a5dce0db2e5041fb1648679fb |
| +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. registry:FleetBoxes@694,whole:Route@1408,whole:Route@557,whole:Route@567 8fc0129043a21a728c0f274cdeae478f4733ed45930ea2548fd6e17bf823a0ae |
| +internal/activator/swap.go Service.Swap legacy accepted-legacy accepted-legacy;rev3=census-ruling-stateless-replicas-1;basis=Task 3a: Verify the target canonical mode and prepare its durable stateless release before stopping the incumbent. A mode change forces the existing proven hold path; same-mode stateless overlap uses local lifecycle gates and the final current-record check, without a serving lease. CI fix 1: defer a missing registry row to the existing release checks only for stateful rootfs overlap, preserving disabled/newest checks and committedGood refusal. Stateless modes, transitions, binary/foreign/hold paths still fence before preparation. No new reads. Final review C1/R26: include incumbent Gen.Stateless as declaration evidence, so only matching good stateful recovery/config attempts can skip canonical lookup. Fresh route, release, ownership and stop gates unchanged.;rev3=census-ruling-stateless-failed-release-held;basis=Classify a proven stateless release failure, or the same deploy's durable failed or unknown phase, through the existing SwapFailed hold mechanism. Preparation precedes stopping the incumbent, so report overlap semantics even if the requested swap is hold. Stateful path unchanged; no new root input.;rev3=census-ruling-stateless-replicas-4-task2;basis=Task 2: for a set row (route FleetBoxes), refuses a stateful or non-overlap attempt before preparation, and a build the observed policy does not allow after it; refusals only, the route read is the row Swap already reads.;rev3=census-ruling-stateless-replicas-4-task2-fix1;basis=Task 2 fix round 1: a set row whose incumbent is not stateless is refused (errReplicaHold) before preparation, so the mode-change hold conversion below can never run a set row as a hold; with replicaSwapRefusal this keeps every set row off swapHold and releaseBeforeSwap. Refusal only, no read added. registry:FleetBoxes@1723,registry:Stateless@1340,registry:Stateless@1369,whole:Route@1013,whole:Route@1063,whole:Route@1072,whole:Route@1257,whole:Route@1333,whole:Route@1446,whole:Route@1690,whole:Route@2254,whole:Route@2726,whole:Route@3144,whole:Route@785,whole:Route@801 473eae4437bd3a20ed226d6042ac73b0cc429b4c83f3879643fda62f35ca0517 |
| +internal/host/rollout.go armRollout legacy accepted-legacy accepted-legacy;rev3=fix1-merge-review;basis=Comment-only clarification of failure-book saves; existing agent rollout setup remains legacy.;rev3=census-ruling-rootfs-apps-3;basis=rootfs Plan 3 Task 7: after the overlap scheduler arms, calls svc.ArmRootfs() so rootfs rows start only where the scheduler armed this boot; never on the refuseManaged path; no read added;rev3=census-ruling-stateless-replicas-1;basis=Task 3a: Bind Service.ReplicaDeployID to the same FailureBook the scheduler owns and bind RuntimeSelection to one CanonicalStatelessDigest read through the existing store. Fix 3a round 1 R18: canonical selection receives route stateless projection to keep legacy DemandHold fallback only for stateful/unknown builds; staged digest mismatch still refuses.;rev3=census-ruling-stateless-replicas-4-task2-fix1;basis=Task 2 fix round 1: the scheduler box label is rolloutBox(svc): the fleet identity label already on svc.Fleet (set from identity.Label before the scheduler arms), else BoxLabel() as before. No read added. registry:App@2917,registry:Stateless@2936,whole:Route@2912,whole:Route@3604,whole:Route@3688 20af28dfe9a50dde181a36dfe944c087387f8b558bd6418b92f5f5d8c646c902 |
| +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. registry:Account@284,registry:Account@310,registry:App@324,registry:App@346,registry:Digest@3059,registry:FleetBoxes@2702,registry:FleetBoxes@944,registry:Host@250,registry:Host@273,registry:Stateless@2156,registry:Stateless@3357,registry:Version@2739,registry:Version@3029,registry:Version@981,whole:Route@1822,whole:Route@1829,whole:Route@2150,whole:Route@2357,whole:Route@259,whole:Route@293,whole:Route@2979,whole:Route@3123,whole:Route@3130,whole:Route@333,whole:Route@3353,whole:Route@3507,whole:Route@3611,whole:Route@3618,whole:Route@540,whole:Route@597,whole:Route@714,whole:Route@821 9dea1add8190b42c08ed29690350fde6e2c28644d98a5897ea89b7507125e1e6 |
| +@coverage internal/activator 41339ac233747c633fd9547955d661779f3a6e0a831d0001162dba3e752440c6 |
| +@coverage internal/host c7a227cf2b638ed21a0b84c67f060aaa83e8f281def6725403f84ba9ed972c4f |
| +@coverage internal/replicas e4eebc10f8ec7e86c25af3bb09c1ddea690b7127f2b2b300b4d74eadceec5373 |
| +@coverage internal/rollout 70f1a24aaf547a378e4c191470257dab1e380b5c04241b804c14d3e3e75a26da |
diff --git a/internal/replicas/deploy.go b/internal/replicas/deploy.go| index 1d554abbf..3e310cb7c 100644 |
| --- a/internal/replicas/deploy.go |
| +++ b/internal/replicas/deploy.go |
| @@ -195,13 +195,18 @@ func NextDeploy(cur Deploy, change DeployChange, coordinator Coordinator, now ti |
| // Baseline is the build a copy runs while this attempt's target is not yet |
| // allowed on it. Until the release passes that is LastGood. Once it passes, |
| // LastGood names the target, so the baseline is Previous: the LastGood this |
| -// attempt began with, which the writer records at begin. It is empty when |
| +// attempt began with, which the writer records at begin. Once the deploy is |
| +// done every copy runs the target, so the baseline is the target: the |
| +// previous build is no longer a fallback, and returning to it is a new |
| +// attempt (a rollback takes the same path as a promotion). It is empty when |
| // no build of this lifetime ever passed a release. |
| func (d *Deploy) Baseline() Build { |
| - if d == nil { |
| + switch { |
| + case d == nil: |
| return Build{} |
| - } |
| - if ReleasePassed(d.Phase) { |
| + case d.Phase == "done": |
| + return d.Target |
| + case ReleasePassed(d.Phase): |
| return d.Previous |
| } |
| return d.LastGood |
diff --git a/internal/replicas/deploy_test.go b/internal/replicas/deploy_test.go| index 663b2291d..893ffb600 100644 |
| --- a/internal/replicas/deploy_test.go |
| +++ b/internal/replicas/deploy_test.go |
| @@ -448,7 +448,8 @@ func TestReplicaSwapAllowsOnlyPermittedTarget(t *testing.T) { |
| {"released, not ordered", attempt("released", swapping), "d", false, good, []Build{good}}, |
| {"halted, completed", attempt("released", Swap{Order: []string{"a", "b"}, Completed: []string{"a"}, Halted: true}), "a", true, target, []Build{target, good}}, |
| {"halted, waiting", attempt("released", Swap{Order: []string{"a", "b"}, Completed: []string{"a"}, Halted: true}), "b", false, good, []Build{good}}, |
| - {"done", attempt("done", Swap{Order: []string{"a"}, Completed: []string{"a"}}), "z", true, target, []Build{target, good}}, |
| + // Done: the previous build is no fallback; a rollback is a new attempt. |
| + {"done", attempt("done", Swap{Order: []string{"a"}, Completed: []string{"a"}}), "z", true, target, []Build{target}}, |
| } { |
| t.Run(tc.name, func(t *testing.T) { |
| if got := tc.d.TargetAllowed(tc.box); got != tc.target { |
diff --git a/internal/rollout/replicas.go b/internal/rollout/replicas.go| index 0f64db362..190e97f2b 100644 |
| --- a/internal/rollout/replicas.go |
| +++ b/internal/rollout/replicas.go |
| @@ -117,10 +117,12 @@ func (m *Manager) replicaDecision(host, serving, want string) (step string, hold |
| } |
| box := m.d.Box |
| if d.Swap.ActiveBox == box { |
| - // This box's step, once per permit. A halted permit is not stepped, |
| - // and an answered one waits for its ACK to land. |
| + // This box's step, once per permit; an answered one waits for its |
| + // ACK to land. A halted permit is stepped too: the activator then |
| + // only proves what the copy runs (switched or kept) and swaps |
| + // nothing, so a permit whose answer was lost still resolves. |
| out, answered := m.replicaOutcomes[host] |
| - if d.Phase != "released" || d.Swap.Halted || (answered && out.id == d.ID && out.permit == d.Swap.Permit) { |
| + if d.Phase != "released" || (answered && out.id == d.ID && out.permit == d.Swap.Permit) { |
| return "", true |
| } |
| return d.Target.Version, false |
| @@ -159,16 +161,15 @@ func (m *Manager) replicaStep(ctx context.Context, a activator.Attempt, newest f |
| return activator.SwapResult{Outcome: activator.SwapAbandoned, Reason: "this box holds no permit for the instance"} |
| } |
| res := ra.ReplicaSwap(ctx, a, d, m.d.Box, newest) |
| - var switched bool |
| - switch { |
| - case res.Outcome == activator.SwapDone && res.Proven: |
| - switched = true |
| - case res.Outcome == activator.SwapFailed: |
| - // The successor failed and the incumbent serves: kept. |
| - default: |
| - // Abandoned, refused, or switched without proof: no answer yet. |
| + if !res.Proven { |
| + // Refused, abandoned, or a switch or a failure whose stop is not |
| + // proven: no answer yet, and the permit stays open. |
| return res |
| } |
| + // SwapDone with proof: switched. SwapFailed with proof (the failed |
| + // successor proven stopped) or a proof-only step (SwapAbandoned, ran |
| + // nothing): kept. |
| + switched := res.Outcome == activator.SwapDone |
| m.replicaMu.Lock() |
| if cur, ok := m.replicaNotes[a.Host]; ok && cur.ID == d.ID && cur.Swap.Permit == d.Swap.Permit { |
| if m.replicaOutcomes == nil { |
diff --git a/internal/rollout/replicas_test.go b/internal/rollout/replicas_test.go| index d5f1f3d95..8241bacdb 100644 |
| --- a/internal/rollout/replicas_test.go |
| +++ b/internal/rollout/replicas_test.go |
| @@ -317,7 +317,7 @@ func TestReplicaSwapUnknownHaltsWithoutOutcome(t *testing.T) { |
| t.Run("failed successor", func(t *testing.T) { |
| h, ra := newReplicaHarness(t) |
| ra.result = func(activator.Attempt) activator.SwapResult { |
| - return activator.SwapResult{Outcome: activator.SwapFailed, Reason: "health check failed", Executed: true} |
| + return activator.SwapResult{Outcome: activator.SwapFailed, Reason: "health check failed", Executed: true, Proven: true} |
| } |
| h.install("v2", replicaHost) |
| noteReplica(h, deployOf("v2", "v1", "released", permit)) |
| @@ -329,3 +329,50 @@ func TestReplicaSwapUnknownHaltsWithoutOutcome(t *testing.T) { |
| } |
| }) |
| } |
| + |
| +// TestReplicaSwapUnknownHaltsUntilProof (fix round 1): a failed successor |
| +// whose stop is not proven leaves no answer; the next step proves the stop |
| +// and only then answers kept. A halted permit whose answer was lost (a new |
| +// manager: an agent restart) is stepped, and its proof-only answer is |
| +// kept, so the permit resolves. |
| +func TestReplicaSwapUnknownHaltsUntilProof(t *testing.T) { |
| + t.Run("failed successor, stop unproven", func(t *testing.T) { |
| + h, ra := newReplicaHarness(t) |
| + calls := 0 |
| + ra.result = func(activator.Attempt) activator.SwapResult { |
| + calls++ |
| + if calls == 1 { |
| + return activator.SwapResult{Outcome: activator.SwapFailed, Reason: "health check failed", Executed: true} |
| + } |
| + return activator.SwapResult{Outcome: activator.SwapAbandoned, Reason: "kept", Proven: true} |
| + } |
| + h.install("v2", replicaHost) |
| + noteReplica(h, deployOf("v2", "v1", "released", replicas.Swap{Order: []string{"box-0", "box-1"}, Completed: []string{"box-0"}, ActiveBox: "box-1", Permit: 9})) |
| + h.pass() |
| + waitFor(t, "the failed step", func() bool { return ra.stepCount() >= 1 }) |
| + time.Sleep(30 * time.Millisecond) |
| + if _, ok := h.m.ReplicaOutcome(replicaHost, "deploy-v2", 9); ok && ra.stepCount() == 1 { |
| + t.Fatal("kept was answered before the failed successor's stop was proven") |
| + } |
| + settle(h) |
| + waitFor(t, "the proven kept answer", func() bool { switched, ok := h.m.ReplicaOutcome(replicaHost, "deploy-v2", 9); return ok && !switched }) |
| + }) |
| + for _, kept := range []bool{true, false} { |
| + t.Run(map[bool]string{true: "halted, kept", false: "halted, switched"}[kept], func(t *testing.T) { |
| + h, ra := newReplicaHarness(t) |
| + ra.result = func(activator.Attempt) activator.SwapResult { |
| + if kept { |
| + return activator.SwapResult{Outcome: activator.SwapAbandoned, Reason: "kept", Proven: true} |
| + } |
| + return activator.SwapResult{Outcome: activator.SwapDone, Proven: true} |
| + } |
| + h.install("v2", replicaHost) |
| + noteReplica(h, deployOf("v2", "v1", "released", replicas.Swap{Order: []string{"box-0", "box-1"}, Completed: []string{"box-0"}, ActiveBox: "box-1", Permit: 9, Halted: true})) |
| + h.pass() |
| + waitFor(t, "the halted permit's answer", func() bool { |
| + switched, ok := h.m.ReplicaOutcome(replicaHost, "deploy-v2", 9) |
| + return ok && switched == !kept |
| + }) |
| + }) |
| + } |
| +} |