carlos / platform Public

fix: resolve replica permits on worker failure; baseline per box

Stateless replicas Plan 4 Task 2, fix round 2 (#511), as the controller
ruled on the re-reviews:

- Worker failure: after the settle window, a switch whose new workers
  crashed, restarted or did not all start answers switched with
  WorkersFailed. The ack resolves the permit, the deploy halts with the
  box named (SR-4-C46, provisional), and a retry, fix build or rollback
  can begin. No permit stays open for a worker failure, and no worker is
  restarted to try for a clean proof.
- Baseline per box, from the record: the target for a box in Completed
  or for every box once done, otherwise Previous. A start of this box's
  baseline takes the no-release path whatever the pointer says, so a
  lagging pointer no longer blocks a waiting copy during an open permit
  or a running release. Only a build that is neither this box's baseline
  nor its permitted target, and that the pointer names, begins a new
  attempt (rollback).
- Census overlay task2-fix2 and the record-write census re-digest.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 6bae56b5dcbaff778c1fa363abfe221b4edc93af parent e19f02d
20 files changed, +344 −93
  • docs/superpowers/notes/census-proposal-stateless-replicas-4-task2-fix2.md +25 −0
  • docs/superpowers/plans/2026-11-01-stateless-replicas-copy.md +1 −0
  • internal/activator/replicadeploy.go +41 −16
  • internal/activator/replicadeploy_test.go +50 −12
  • internal/activator/stateless.go +18 −19
  • internal/activator/swap.go +5 −0
  • internal/console/replicadeploy.go +4 −0
  • internal/console/replicadeploy_test.go +15 −0
  • internal/host/agent.go +1 −1
  • internal/host/replica_deploy_e2e_test.go +34 −0
  • internal/host/replicadeploy.go +17 −7
  • internal/host/replicadeploy_test.go +3 −2
  • internal/provision/stateless_replicas_4_task2_census_test.go +11 −1
  • internal/provision/testdata/plan14-root-reads-chain.tsv +1 −0
  • internal/provision/testdata/plan14-root-reads-stateless-replicas-4-task2-fix2.tsv +13 −0
  • internal/replicas/deploy.go +28 −14
  • internal/replicas/deploy_test.go +30 −2
  • internal/replicas/types.go +3 −0
  • internal/rollout/replicas.go +20 −13
  • internal/rollout/replicas_test.go +24 −6

CI failed — run details

Intent

Human

<task-notification> <task-id>a4621592a91bafe83</task-id> <tool-use-id>toolu_0154JdhnZEBR8KEiqXZdjVbS</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 - **Commits:** e19f02d9 fix: prove replica answers and route rollbacks through a release, on top of c98180b1. Local only; the tree is clean. - **Tests:** RED against c98180b1's code shows each fix failing (the R8 test passes there, since it pins the existing drain behaviour). GREEN on the Task 2 and fix-round tests in all five packages, plus the targeted activator, rollout and host runs, census, HA guards, copy checks, the darwin, windows and linux/arm64 builds, vet and gofmt. All 5 fix-round mutations were killed. - **All seven items fixed:** - a rollback after done, or on a box that completed before a halt, now begins a new attempt; - "kept" waits for the failed successor's stop proof; - the committed target starts even when the box's installed Version is stale; - a halted permit gets a step that only proves (switched or kept) and skips the start gate; - the R8 test now pauses a request on the old generation while successor requests keep being served; - the switch is proven only once the new workers are running; - the scheduler uses the same fleet label as the gates. - **Not reaching `releaseInWake` / `releaseBeforeSwap`:** confirmed with line citations (activator.go:2848-2857 before :3250; swap.go:378-391 before :410, :434 and :443). I also added a refusal so a mode change can never turn a copy's swap into a hold. - **Concerns:** - Task 2 now has 14 mutations, over the plan's 10. - A halted permit on a box that lost the target's staged build waits for root to restage it. - A worker that crashes once keeps that box's step from ever being proven, so the deploy stays open until an operator acts. - A rollback reruns the old release command, which D3 accepts. - **Census:** proposal stateless-replicas-4-task2-fix1 is written (seal 1a0605f7…). Nothing is posted to #280. - **Report:** /home/paulca/amadan.net/carlos/platform/.claude/worktrees/stateless-replicas-4/.superpowers/sdd/2026-11-01-stateless-replicas-4-deploy-and-drill/task-2-report.md (the "Fix round 1" section)</result> <usage><subagent_tokens>647307</subagent_tokens><tool_uses>47</tool_uses><duration_ms>1610640</duration_ms></usage> </task-notification>

Human

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

Human

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

Attributed to this commit: 35.7 g CO₂e (4,434,587 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-fix2.md b/docs/superpowers/notes/census-proposal-stateless-replicas-4-task2-fix2.md
new file mode 100644
index 000000000..049333b6a
--- /dev/null
+++ b/docs/superpowers/notes/census-proposal-stateless-replicas-4-task2-fix2.md
@@ -0,0 +1,25 @@
+# Census approval: stateless-replicas-4-task2-fix2
+
+Ruling `census-ruling-stateless-replicas-4-task2-fix2`. The independent reviewer approves or rejects every change below, 0 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26).
+
+| unit | change | read sites | what changed |
+|---|---|---|---|
+| `internal/activator/replicadeploy.go` `Service.ReplicaSwap` | body | unchanged (4) | Task 2 fix round 2: the switch proof is replicaSwitchProof, which also reports WorkersFailed (switched, the new workers crashed or did not start within the settle window) so the step answers instead of staying open. Reads only the in-memory entry; no store, file or root call. |
+| `internal/activator/replicadeploy.go` `Service.replicaSettle` | body | unchanged (2) | Task 2 fix round 2: after the settle window the proof judges the new workers (replicaSwitchProof, settled); a failure answers switched with WorkersFailed. Same in-memory reads. |
+| `internal/activator/stateless.go` `Service.prepareStateless` | body | unchanged (32) | Task 2 fix round 2: for a set row the no-release start is decided per box from the record (this box baseline, or its permitted target adopted through the durable path), whatever the pointer says; only a build that is neither and that the pointer names begins a new attempt. Same reads (the handed route and its copy); no store read or write added. |
+| `internal/host/agent.go` `runAgent` | body | unchanged (9) | Task 2 fix round 2: the swap worker step is armedReplicaStep, the same lazy scheduler lookup as before as a named function; no read site 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/replicadeploy.go` `Service.ReplicaSwap`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-stateless-replicas-4-task2;basis=Task 2: new. Checks the permit (box label, phase released, not halted, ActiveBox, build), refuses a hold, asks tenantStartRefusal on the in-memory entry route, then either re-proves an existing switch (replicaSettle) or runs the existing Swap as a canary and checks replicaStepProven. Reads the in-memory entry route only; no store, file or root call of its own.;rev3=census-ruling-stateless-replicas-4-task2-fix1;basis=Task 2 fix round 1: proof-only steps (an already switched copy, a halted permit, a permit whose successor failed here) skip the start gates because nothing starts; a failed successor answers kept only after replicaKeptProven (its stop proven, an empty operation set). Reads only the in-memory entry route; no store, file or root call.
+- `internal/activator/replicadeploy.go` `Service.replicaSettle`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-stateless-replicas-4-task2;basis=Task 2: new. GET / health (genHealthy) and the settle window on the current in-memory generation, then replicaStepProven; reads the in-memory entry route only.
+- `internal/activator/stateless.go` `Service.prepareStateless`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-stateless-replicas-1;basis=Task 3a: Capture RecordFacts from the existing record source, obtain the durable FailureBook deploy ID, and call Task 2 PrepareStatelessRelease with the canonical verdict/digest carrier. Carry a successful attempt through its hold only after another current-record check; no serving lease or polling loop. Fix 3a round 1 I2: preparation uses reconcile observations and records the successful deploy ID. Carry prepared evidence through hold; fresh backend read must confirm that same released deploy before web runs.;rev3=census-ruling-stateless-failed-release-held;basis=For recovery onto a different installed version's exact committed good version and artifact digest, retain recovery evidence without selecting or writing another deploy. Adds the existing committedGood registry read, with its route and incarnation check. Canonical storage declaration and observed lifetime gates remain.;rev3=census-ruling-stateless-replicas-4-task1;basis=R1: no longer calls ReplicaDeployID before preparation; hands the same a.ReplicaDeployID selector to prepareStatelessRelease, which calls it only after coordinator term acquisition. The ObservedReplicaRelease call stays as a validity check. Same read sites; no new read, write or authority.;rev3=census-ruling-stateless-replicas-4-task2;basis=Task 2 (D4): for a set row, prepares the record baseline with no release, and refuses a build the row Version does not name before any release; reads the route it is handed (FleetBoxes, Version). No store read or write added.;rev3=census-ruling-stateless-replicas-4-task2-fix1;basis=Task 2 fix round 1: for a set row, a build its pointer does not name starts only as the record baseline or the committed permitted target, the latter adopted through prepareStatelessRelease durable path (never a new attempt); a named build, a rollback included, takes the release path. The added reads are the handed route (FleetBoxes, Version) and a copy of it with Stateless set for the adoption, as the release path already builds. No store read or write added.
+- `internal/host/agent.go` `runAgent`: authority, task B,C,D,F. Basis: rev3=census-ruling-self-serve-moves-1;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): builds the box's lifetime judge once (newBoxJudge, nil with host claims on) and hands it to the seed placement, the moves and runs workers and every loop it starts; read sites unchanged, offsets moved; B,C,D,F authority retained; self-serve moves 1 Task 8: derives the box's lifetimes switch from the judge once (lifetimes := boxJudge != nil) and hands it to the edges file loop; read sites unchanged, offsets moved;rev3=census-ruling-plans-4d-lapse;basis=arms two more plans hooks from the same snapshot: e.SetPlanDisabledFor(planDisabledFor) beside SetPlanGovernedFor, and svc.SetDisabledFor(planDisabledRoute) beside SetMaxRunFor (plans 4d); the reads live in those units (plans-4d-units decision); read sites unchanged, offsets moved;rev3=census-ruling-rootfs-apps-2;basis=main's body as of the merge of origin/main 9b81d97b (with main's plan rate ceiling, edge request records, regional box names, self-serve moves plan 1, plans 4d-1 lapse and its other later changes under main's own census rulings) plus the rootfs placement wiring in the activator start: an agentRootfs built from eb.NestedOK, CARLOS_DEPLOYMENT_SINGLE_TENANT, CARLOS_POOLS, the claim flag, swapArming's answer, the control client's /ready/rootfs and, on a fleet box whose identity resolved, fleetOwnerCheck over the deploy store main already opens for the fleet label (fleetStore), then arm and armedRootfs.Store; this body reads nothing new itself; the closures it wires read later, at a rootfs wake and each status tick: GET /ready/rootfs over the control socket, NestedOK's checks, and release.FleetOwnerKey for the judged row's own account and this box's fleet from the deploy store;rev3=census-ruling-instance-egress-sizes-328-329;basis=#328 plan 2 Tasks 7 and 11, #329 plan 3 Task 7 and plan 1 Task 7's policy cache: the control client is built once and handed to eb.Control, to the status tick (egressStatus) and to a new egressNudgeLoop goroutine; armSizeSource(svc, "/sys/fs/cgroup") after the activator Service; armPolicyCache() after armChangeIndex; statusLoop takes egressStatus. The reads are those units' own (decision rows); this body reads nothing new: the same five sites, offsets moved, in the agent; B,C,D,F authority retained.;rev3=census-ruling-remote-instance-metrics;basis=builds the metrics loop's owners closure (metricsOwners over the agent's registry, the activator and cgm.Leftover) when an activator exists and hands it to metricsLoop; reads nothing new itself;rev3=census-ruling-edge-asset-cache-3;basis=adds file:Statfs. runAgent keeps its authority (B,C,D,F). The new site is assetcache.Statfs, an exported assetcache.FS interface value (var Statfs FS = statfsFS{}), not a function value and not a call in runAgent: the ready hook passes it to armEdgeAssetCache as the store's filesystem, and armEdgeAssetCache calls its Space method on the configured data directory (dataDir(): $CARLOS_DATA_DIR, else /data), which calls unix.Statfs there (statfsFS.Space, accepted legacy at census-ruling-edge-asset-cache-2). No request-supplied pathname reaches it.;rev3=census-ruling-remote-metrics-nested;basis=main's body (merged origin/main acfa4f80, under main's own census rulings) plus: snapshots the nested layout (snapshotNestedUnits over /sys/fs/cgroup/carlos.slice/carlos-instances.slice) once at start, before the activator, and hands the metrics loop a unitSources struct (stamped units, routeHostNames, that root and the snapshot); reads nothing new itself;rev3=census-ruling-region-ha-p1a;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): wires region HA P1a into the activator: cfg.Record = haRecordFacts(openDeployStore, boxJudge) (the box's lifetime judge this body already builds with newBoxJudge, nil with host claims on; CI fix) and cfg.Self = lease.CurrentSelf; eb.Lifetimes (the process's lifetime index), eb.Registry, eb.StartupSwept (seedSweptAtStart.Load), eb.FilesStore from newProductionFilesStore (now lease.NewFilesStore, rootaws-loaded, a log line on failure) and lease.SetObligationDir(<data>/.ha-owed) (logged on failure; HA acquires then refuse); this body reads nothing new itself, the same five sites; the reads are those units' own (haRecordFacts and lease's SetObligationDir are new rows on this card); merge of origin/main d7ae1d76: main's own later changes to this body are kept as main has them, under main's rulings (census-ruling-remote-instance-metrics: the metricsOwners closure for metricsLoop; census-ruling-edge-asset-cache-3: the +file:Statfs site, assetcache.Statfs handed to the asset ready hook); this branch's change is the same as above;rev3=census-ruling-region-ha-p1b1;basis=region HA P1b-1: builds one termfence.Confirmer (Self from lease.CurrentSelf at each call, EC2 DescribeInstances method only, client from rootaws.LoadDefaultConfig with retries off, built lazily on first use) and sets eb.OwnerTerminated; this body reads nothing new itself, the same six sites;rev3=census-ruling-rootfs-apps-3;basis=rootfs Plan 3 Task 7: the startup Sweep literal hands its answer to startupSwept, which logs as before and, only on a clean sweep, marks rootfs admission swept (MarkRootfsSwept); same Sweep call, no read added;rev3=census-ruling-managed-fleets-1b;basis=managed fleets 1b (controller ruling after branch review R1, and Paul's R2 ruling): sets svc.Fleet = fleetWakeFor(os.Getenv, identity, identErr, fleetStore) from the identity it already resolves once and the deployment store the fleet loops already opened, and logs an ERROR naming the identity error when the box is on a fleet with an invalid identity. fleetWakeFor reads CARLOS_REGION and CARLOS_FLEET from the same environment. Read sites unchanged (6). Agent, not root; a platform box is unchanged.;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 12: one call more beside armRunsPass, armInteractivePass(svc, reg, rolloutSink, boxJudge), in the same activator Configure hook, handing it the same box judge; fix round 1 (Astra P2, shutdown): after svc.Shutdown(ctx), shutdownInteractive(ctx) ends and joins every interactive session under the same shutdown budget; the worker's own reads are its units' (interactive.go); this body reads nothing new, the same six sites; merge of origin/main 6f1f6ca6: main's svc.Fleet = fleetWakeFor(...) and its invalid-identity ERROR line are kept as main has them (census-ruling-managed-fleets-1b); this branch's change is the same as above; read sites unchanged (6);rev3=census-ruling-fix-set-aside-exdev;basis=set-aside EXDEV fix: one field more on the agent ExecBackend literal, RawInstanceDir: layout.RawInstanceDir (a pure path join: <dataDir>/.instances/<InstanceID(host)>), so the start rule set-aside moves a copy out through the raw directory instead of through the nosymfollow bind; this body reads nothing new, the same six sites;rev3=census-ruling-durability-3a-escrow;basis=durability 3a Task 3: one more assignment beside eb.FilesStore: eb.EscrowKey = haEscrowKey(os.Getenv("CARLOS_SECRETS_KEY")), the agent's own environment parsed by appconfig.ParsePrivateKey as the moves pass parses it (unset or unparseable: a log line and nil, and HA publication refuses on the box). No path is opened or read, no read site added; the same six sites, offsets moved; B,C,D,F authority retained. Durability 3a Task 4: one more goroutine beside configSyncLoop: go escrowLoop(agentCtx, reg, svc), the escrow sweep every 30 s over the same registry and Service. This body reads nothing new itself; the same six sites, offsets moved; B,C,D,F authority retained. Durability 3a Task 5: one more call beside eb.EscrowKey: wireRawSecretPages(eb, PageOperator, metricsBoxLabel(os.Getenv, readMachineID())), which sets eb.OnRawSecret to page an operator (alerting.Page through PageOperator, LevelIncident) on its own goroutine with a 20 s timeout; metricsBoxLabel and readMachineID are the reads this body already makes for the moves refusal log; no new read site; the same six sites, offsets moved; B,C,D,F authority retained. Merge of origin/main 90c4d3aa: main's own later changes to this body are kept as main has them, under main's rulings; this branch's change is the same as above. Merge of origin/main 00bf5b8c (fleet set-aside EXDEV fix): main's change to this body is kept as main has it, under its own census ruling; this branch's change is unchanged.;rev3=census-ruling-probe-burst-limit;basis=two more sink wirings beside setAnalyticsSink: setProtectionSink(e.SetProtectionRecordOnly) and setAssetOwnersSource(e.AssetOwners), function values the telemetry pass calls; this body reads nothing new, the same six sites; authority B,C,D,F retained; no new root read or write kind;rev3=census-ruling-region-ha-p1b3a;basis=Arm HA placement exactly once on the existing Service before activatorStart and edges publication, wiring AwakeApps and the PageOperator callback; existing six read sites unchanged, no new root authority.;rev3=census-ruling-stateless-replicas-1;basis=Final review I3: start the concrete coordinator's renewal worker with agent setup; existing closeReplicaCoordinator shutdown cancels and joins it before release. No new read sites or credentials. Merge origin/main c59715e7: retain main's armHAPlacement(svc, PageOperator) wiring beside the existing activator setup; stateless coordinator and shutdown wiring remain. Same read sites; no new root read or credential.;rev3=census-ruling-edge-held-streams;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): in the edge-ready callback, calls act.SetHeldWakeHook(e.HeldWake) when act is non-nil (installing the non-blocking wake callback) and stores e.HeldStreamsForStatus in heldStreamsSource. Wiring of in-memory callbacks only; no read added.;rev3=census-ruling-region-ha-p1b3b-t;basis=Wire Service.SetDutyView to the live edge DutySnapshot in the ready callback. No new read; no new loop or cloud operation. B2 wires the registry as the persistent DutyStore before service startup; no new cloud or filesystem path. B3b: arm one journal-backed termination consumer before service startup using agentCtx and the shared confirmer; expose edge tick and join at edge shutdown. No new direct read sites.;rev3=census-ruling-agent-start-demo-1;basis=Passes the existing registry, data store and hibernation prefix into the demo worker, and the existing instance-control client into the demo before-exec hook. No alternate data store or polling loop. Merge resolution against origin/main 9bd45488 retains main's HA departure controller, lifecycle and duty wiring alongside the demo data store and worker; no read site added by the resolution.;rev3=census-ruling-region-ha-p3a;basis=P3a Task 3: install closed fixed admission before every launch source, bind activator/backend and edge, wire the real termination Started lifecycle and role reader after the change index; close before cancellation/child shutdown. No new external reads or cloud authority. Fix R1: move bind/lifecycle/edge-option wiring into wireAgentAdmission and worker listing into runWorkerBootPassAfterAdmission. Worker boot waits for admission before listing then uses unchanged bounded wakes and per-host serialization; whole Route read moves to the helper. No new storage, cloud, or root execution authority. Preserve merged main's agent wiring and census basis; the branch removes one whole Route use by moving worker iteration to the helper, with no added read kind.;rev3=census-ruling-stateless-replicas-2;basis=Slice 3b: arms a fleet-only worker using the existing registry, activator, backend and authenticated console transport. Owned worker stops and joins at shutdown. No new bucket reader. merge of origin/main 9b8b2c50: retain HA duty/departure lifecycle, wake-slot and existing agent wiring alongside the replica placement worker; no new read introduced by resolution. merge of origin/main 6be08467: Retain main demo configuration, admission, build and expiry wiring alongside the replica worker; merge-only body change, no additional read. merge of origin/main 7920cccf: Retain main box-role/group admission wiring and boot publication beside the owned replica worker and shutdown; main moves the boot registry List into runWorkerBootPassAfterAdmission, removing its inline whole Route site. No new read introduced by conflict resolution.;rev3=census-ruling-stateless-replicas-3;basis=Task 1 fix round 1 M3: retain the private snapshot source and cancel/join ownership, but use the replica-health-specific retry loop. It logs its first failure only and retains the existing exponential backoff capped at 30 seconds; unsupported builds return nil. Existing five direct read sites unchanged; no new credentials, bucket reader or app lifecycle action. Fix round 1 Q20: publish Edge.ReplicaSnapshots as a separate in-memory status source, leaving the tenant-visible Upstreams source unchanged. No new external reader or authority.;rev3=census-ruling-region-ha-p3b;basis=Load root-written group marker/configuration, configure signed boot binding and agent receipt completer, wire cancellable admission into departure work and expose cached GroupReaderSnapshot. New indirect boot reads use protected root files; agent-owned receipt controls duplicate initial completion only, never root restart permission. Same five direct sites. Merge 45cebde4 retains the replica health socket lifecycle and setReplicaSource beside GroupReaderSnapshot; no extra read beyond main.;rev3=census-ruling-agent-start-demo-2;basis=agent.go:309-329 opens demo-traffic.db beside the operator-configured registry when a demo domain exists, closes it at shutdown and wires drain-before-purge; :1010-1019 shares the worker and write gate; :1164-1177 installs the fleet identity and closed-until-worker serving callback. One added whole Route pass; the new indirect filesystem/SQL reads are claimed in openDemoTraffic and worker/store units. No request chooses the database pathname.;rev3=census-ruling-region-ha-p1b3b-s;basis=Wire the service duty view to authoritative cached sidecar manifest placement in LifetimeIndex and the edge sidecar projection; missing policy denies duty. Existing instance duty wiring remains.;rev3=census-ruling-region-ha-g2-t3;basis=T3a: wire eb.Page = PageOperator beside OwnerTerminated before departures arm, so suspect-holder pages work if departure setup fails; no new read; existing nine sites and authority unchanged; pages through the existing sink. T3b: publish the same backend through an atomic pointer for the metrics observer, and clear it on return; no new external read or authority.;rev3=census-ruling-agent-start-demo-3;basis=Wire the claim activator and root snapshot client into the demo worker; pass moved readiness to status reporting. Census read-site delta: unchanged (9).;rev3=census-ruling-region-ha-g2-fixes;basis=Wire local pool evidence, live withdrawal activator, startup ingress scan and alias publication, and edge lookup; no new direct sites; new indirect record/claim reads use existing store/judge paths described in ingress helpers.;rev3=census-ruling-region-ha-g2r-fixes;basis=W3: starts the existing record-view backstop loop with a departure-inventory listener (non-blocking, coalesced signal) even without an armed RecordView; it requests the existing full pass (backstopFullDue) there. Same nine read sites; no new read or authority.;rev3=census-ruling-region-ha-graceful-terminate-t2;basis=Derive one signal-time deadline with a 90-second budget; cap departure stop and startup/seed/service shutdown joins by it. No read added.;rev3=census-ruling-static-sweep-periodic;basis=in the edge-ready callback, publishes e.LargestStaticTree in staticTreeSource for the disk alert line (diskAlertFrac in the metrics loop); in-memory wiring only, no read added; read sites unchanged (9);rev3=census-ruling-edge-page-cache-1;basis=wires the exec backend's CurrentInputs into the edge cache (wireCurrentInputs) and, in the ready hook after armEdgeAssetCache (whose returned store it now keeps), calls armEdgePageCache, which does nothing unless CARLOS_PAGE_CACHE=1; read sites unchanged (9); no read added;rev3=census-ruling-gvisor-demos;basis=Capture sandbox resolution and refusal once; log errors once; gate route admission and BeforeExec before process launch. No new root read. Task 5: pass the once-captured sandbox effective mode/config error into ExecBackend, UnitBackend and the immutable Client expectation. Same startup environment/registry reads; swapArming declines gVisor before placement. Task 8: arm read-only status projection with the existing Client.SandboxStatus callback. Agent status now queries the existing root /ready endpoint; no new root authority or guest-file input. Merge2 e8a1ddde: retain main wireCurrentInputs and armEdgePageCache through the existing asset-store ready hook alongside branch once-captured sandbox mode, wake gates and root status wiring. No new direct read; main page-cache helpers retain their own census overlays.;rev3=census-ruling-region-ha-held-build;basis=wires the drain state: svc.SetDrainingSource(boxDrain.IsDraining), svc.SetPeerDrainView(e.PeerDraining), e.SetPeerDrainedHook(svc.DropHoldersNaming); in-memory only; no read added; region HA held-requests Task 5: on group members, starts the drain driver over the activator, the edge and boxDrain, and serves its root-only drain socket; no read added beyond the socket's own Branch review r1: the drain state follows the root start fence on group members (the fence reader is the existing fenceLocation.read, a root-owned fixed path); e.SetPeerUndrainedHook(svc.AllowHoldersNaming) beside the drained hook (memory only); the drain socket serves only the agent's own user. No read added.;rev3=census-ruling-security-review-mitigations;basis=Wire the cached operator flat-layout choice into the exec backend's new-resident refusal; no read source added, existing authority retained.;rev3=census-ruling-w6-ingress-drain;basis=agent (user carlos), not root. Builds the ingress drain (newIngressDrain) with arming read at ask time from os.Getenv (CARLOS_REGION_HA, CARLOS_INGRESS_TARGET_GROUPS, both from the root-owned host.env), the fixed admission and lease.CurrentSelf (existing IMDS identity); its reader is awstg.Load, the box role's credentials calling ELB DescribeTargetHealth/DescribeTargetGroupAttributes (new AWS reads, by the agent). Wires admission.closeStartsForIngressDrain, the lbhealth drain condition, ingress.setEdge, and ingress.shutdownStarted in WithShutdownStarted. The drain socket (/run/carlos/.ha-drain/drain.sock, agent-user only, existing) is now also served on a fixed box with the drain configured (was group members only), routing /v1/ingress/* to the ingress drain and the group drain verbs to 404 there. armHADepartures now takes fixtureDepartureGetenv() and MakeQueue fixtureDepartureQueue(), which in a production (non-rootrunner) build are os.Getenv and nil, as before. Read sites unchanged (9).;rev3=census-ruling-stateless-replicas-4-task1;basis=Arms the fleet-only replica swap worker next to the placement worker: same console URL and fleet token as the existing replicaCoordinatorAPI, the existing activator Service; stops and joins at shutdown. No new read site, credential or bucket reader.;rev3=census-ruling-stateless-replicas-4-task2;basis=Task 2: sets deployWorker.step to the rollout scheduler answer for the record permit (replicaStepOf over armedRollout), an in-memory callback; no read site, credential or bucket reader added.
+
+Seal: `1a0605f79ac62c776bccc1ae8d166357b05c6acb56aeead59290e43b9cc67788` → `5f83de2e018b47543789a8dbe2cccb86b2d644fbe9ee5771e5d621704ae46e0b`.
+
+Overlay: `internal/provision/testdata/plan14-root-reads-stateless-replicas-4-task2-fix2.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`.
diff --git a/docs/superpowers/plans/2026-11-01-stateless-replicas-copy.md b/docs/superpowers/plans/2026-11-01-stateless-replicas-copy.md
index 20d1c6323..272fac039 100644
--- a/docs/superpowers/plans/2026-11-01-stateless-replicas-copy.md
+++ b/docs/superpowers/plans/2026-11-01-stateless-replicas-copy.md
@@ -117,3 +117,4 @@ copy too. Internal wire enums are not an excuse to expose unreviewed text.
| SR-4-C43 | internal/activator/replicadeploy.go | this copy keeps its current build until its turn to switch | pending (added by Plan 4 Task 2 for a copy refused a build its deploy has not yet permitted on its box; awaiting Paul's copy review) |
| SR-4-C44 | internal/activator/replicadeploy.go | copies above 1 switch builds with an overlap swap, so this release's hold swap was refused. the current build keeps serving | pending (added by Plan 4 Task 2 for a hold demand or hold policy on a replicated instance; awaiting Paul's copy review) |
| SR-4-C45 | internal/rollout/replicas.go | this copy waits for a release to pass before it starts | pending (added by Plan 4 Task 2 for a copy's wake when its record names no build that passed a release; awaiting Paul's copy review) |
+| SR-4-C46 | internal/console/replicadeploy.go | the new build's workers failed on <box>, so the deploy stopped. other copies keep serving | pending (added by Plan 4 Task 2 fix round 2 for a switch whose workers failed, which halts the deploy; awaiting Paul's copy review) |
diff --git a/internal/activator/replicadeploy.go b/internal/activator/replicadeploy.go
index e4159b3b7..419e6006c 100644
--- a/internal/activator/replicadeploy.go
+++ b/internal/activator/replicadeploy.go
@@ -26,7 +26,9 @@
// fence) admit a start: a refused start answers nothing;
// 4. the successor passes GET / and the normal settle window (Canary);
// 5. it is switched in, the workers are handed over and the retiring
-// generation's stop is proven: replicaStepProven.
+// generation's stop is proven: replicaSwitchProof. Workers that
+// failed still answer switched, marked workers failed, which halts
+// the deploy.
//
// A step that ends anywhere short of 5 leaves the permit open. Asking
// again after the box already switched (a lost reply, an agent restart)
@@ -123,7 +125,8 @@ type replicaStepKey struct {
// 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).
+// generation and worker proven stopped (replicaSwitchProof), with
+// WorkersFailed set when its workers failed (the deploy halts).
// - 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).
@@ -179,7 +182,10 @@ func (a *Service) ReplicaSwap(ctx context.Context, at Attempt, deploy replicas.D
res := a.Swap(ctx, at, newest)
switch res.Outcome {
case SwapDone:
- res.Proven = a.replicaStepProven(at.Host, res.Gen)
+ // The workers were only registered at the switch; the next step
+ // judges them after its settle window (replicaSettle), unless one
+ // has already failed.
+ res.Proven, res.WorkersFailed = a.replicaSwitchProof(at.Host, res.Gen, false)
if !res.Proven && res.Reason == "" {
res.Reason = "the switch is not yet proven; the step stays open"
}
@@ -217,35 +223,54 @@ func (a *Service) replicaSettle(ctx context.Context, host string, g Gen) SwapRes
if observeSettle(ctx, proc, swapSettle) != settleOK {
return abandon(errSwapStopped)
}
- res := SwapResult{Outcome: SwapDone, Gen: g, Proven: a.replicaStepProven(host, g)}
+ res := SwapResult{Outcome: SwapDone, Gen: g}
+ res.Proven, res.WorkersFailed = a.replicaSwitchProof(host, g, true)
if !res.Proven {
res.Reason = "the switch is not yet proven; the step stays open"
}
return res
}
-// 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); 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 {
+// replicaSwitchProof is a switch's last proof. proven needs g to be host's
+// current, live, awake generation, no other generation left in the
+// operation set (a retiring one whose stop was not proven stays there until
+// the sweep proves it), and no worker of another generation, stray
+// included. The new generation's workers then decide workersFailed:
+// - every worker started, alive and never restarted: a clean switch;
+// - any worker crashed, restarted, ended in a crash loop or failed to
+// start: switched, workers failed;
+// - any worker not yet started: not proven while settled is false (its
+// tick has not run since the switch registered it), and switched,
+// workers failed once the step's settle window has passed.
+//
+// A worker failure is still an answer: the box switched, the ack resolves
+// the permit and halts the deploy, so no worker failure leaves a permit
+// open. Nothing here restarts a worker to try for a clean proof.
+func (a *Service) replicaSwitchProof(host string, g Gen, settled bool) (proven, workersFailed bool) {
a.mu.Lock()
defer a.mu.Unlock()
e := a.entries[host]
if e == nil || e.state != actAwake || e.gen.N != g.N || e.proc == nil || e.proc.Exited() {
- return false
+ return false, false
}
if len(e.ops.members) != 0 || len(e.strayRootfsWorkers) != 0 {
- return false
+ return false, false
}
+ pending := false
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
+ switch {
+ case wk.gen != g.N:
+ return false, false
+ case wk.restarts != 0 || wk.crashLoop || wk.startFailed || (wk.proc != nil && wk.proc.Exited()):
+ workersFailed = true
+ case wk.starting || wk.proc == nil:
+ pending = true
}
}
- return true
+ if pending && !settled && !workersFailed {
+ return false, false
+ }
+ return true, workersFailed || pending
}
// replicaKeptProven is a "kept" answer's proof: host's current generation
diff --git a/internal/activator/replicadeploy_test.go b/internal/activator/replicadeploy_test.go
index 3efdc333d..a2de204d6 100644
--- a/internal/activator/replicadeploy_test.go
+++ b/internal/activator/replicadeploy_test.go
@@ -543,16 +543,19 @@ func TestReplicaSwapProofOnlySteps(t *testing.T) {
})
}
-// 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.
+// TestReplicaSwapWaitsForWorkers (fix rounds 1 and 2): right after the
+// switch the step is not proven while the new workers have not started.
+// After the settle window it answers: switched and clean when every worker
+// started and is alive; switched with WorkersFailed when a worker crashed
+// or never started, so the permit resolves and the deploy halts instead of
+// staying open. Nothing restarts a worker to try for a clean proof.
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) {
+ for _, tc := range []string{"started", "crashes on start", "never starts"} {
+ t.Run(tc, func(t *testing.T) {
r := newReplicaSetRig(t, "b", replicaAttempt("released", replicas.Swap{Order: []string{"a", "b"}, Completed: []string{"a"}, ActiveBox: "b", Permit: 5}))
workers := &fakeWorkerBackend{killBackend: &killBackend{fakeBackend: r.b.fakeBackend}}
r.a.backend = &statelessWakeBackend{r.b, workers}
@@ -560,17 +563,52 @@ func TestReplicaSwapWaitsForWorkers(t *testing.T) {
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)
+ t.Fatalf("answered 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")
+ if tc != "never starts" {
r.a.rootfsTick()
+ waitFor(t, "the worker", func() bool { return workers.alive() == 1 })
+ }
+ if tc == "crashes on start" {
+ workers.lastWorker(t, "jobs").exit("exited", "1")
}
+ launches := workers.launchCount("jobs")
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)
+ failed := tc != "started"
+ if res.Outcome != SwapDone || !res.Proven || res.WorkersFailed != failed {
+ t.Fatalf("%s: %+v", tc, res)
+ }
+ if workers.launchCount("jobs") != launches {
+ t.Fatal("the proof restarted a worker")
+ }
+ })
+ }
+}
+
+// TestReplicaWakeAndAdoptLaggingPointer (fix round 2): what a copy starts
+// without a release is decided per box from the record, whatever its
+// pointer says. A waiting box whose pointer still names the previous build
+// restarts on it, while another box holds the permit and while another box
+// runs the release: no release, no refusal, the record untouched.
+func TestReplicaWakeAndAdoptLaggingPointer(t *testing.T) {
+ for _, tc := range []struct {
+ name string
+ state func(string) *replicas.Deploy
+ }{
+ {"another box holds the permit", replicaAttempt("released", replicas.Swap{Order: []string{"a", "b"}, ActiveBox: "a", Permit: 4})},
+ {"another box runs the release", replicaAttempt("releasing", replicas.Swap{})},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ r := newReplicaSetRig(t, "b", tc.state)
+ r.rt.Version = "v1" // the pointer has not caught up
+ r.routes.set(r.rt)
+ before := *r.store.snapshot()
+ r.setPlan(WakePlan{Boot: r.good, Mode: ModeOverlap, Token: 1})
+ if err := waitErr(t, r.wake(r.a)); err != nil || !r.started("v1") {
+ t.Fatalf("the waiting copy could not restart on its baseline: %v %v", err, r.b.events())
+ }
+ if after := *r.store.snapshot(); after.ID != before.ID || after.Revision != before.Revision || r.store.acquires != 0 || len(r.b.releaseStarts()) != 0 {
+ t.Fatalf("the restart touched the release: %+v (acquires %d)", after, r.store.acquires)
}
})
}
diff --git a/internal/activator/stateless.go b/internal/activator/stateless.go
index 1e7dd5133..255cacdec 100644
--- a/internal/activator/stateless.go
+++ b/internal/activator/stateless.go
@@ -397,41 +397,40 @@ func (a *Service) prepareStateless(ctx context.Context, rt registry.Route, id re
return ctx, err
}
observation, _ := observed.Value(replicaObservationKey{}).(replicaObservation)
- 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.
+ if rt.FleetBoxes != "" {
+ // A copy of an assigned instance (D4). What it may start without a
+ // release is decided per box from the record, whatever its pointer
+ // says: a lagging pointer and a rollback look the same from here.
+ // - This box's baseline (replicas.Deploy.Baseline): no release.
+ // - This box's permitted target: the passed attempt is adopted,
+ // its escrow initialization included; no new attempt.
+ // - Anything else begins a new attempt, and only for the build the
+ // pointer names (the rollback path, D3). A build the pointer does
+ // not name is never released here; the box's local good build is
+ // never used. 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
- }
+ build := replicas.Build{Version: id.Version, Digest: digest}
prepared := &statelessPreparation{route: rt, id: id, digest: digest, observation: observation}
switch {
- case d.Target == (replicas.Build{Version: id.Version, Digest: digest}) && d.TargetAllowed(box):
+ case d != nil && d.Incarnation == inc && build == d.Target && d.TargetAllowed(box):
if replicas.DurableAttempt(d, inc, d.Target) == nil {
return ctx, errReplicaTurn // a requested retry: only a named build begins one
}
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}):
+ return context.WithValue(observed, statelessPreparedKey{}, prepared), nil
+ case d != nil && d.Incarnation == inc && digest != "" && build == d.Baseline(box):
prepared.baseline = true
- default:
+ return context.WithValue(observed, statelessPreparedKey{}, prepared), nil
+ case id.Version != rt.Version:
return ctx, errReplicaTurn
}
- return context.WithValue(observed, statelessPreparedKey{}, prepared), nil
+ // The pointer names it: the release path below.
} 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.
diff --git a/internal/activator/swap.go b/internal/activator/swap.go
index 72a162715..03a574dfc 100644
--- a/internal/activator/swap.go
+++ b/internal/activator/swap.go
@@ -111,6 +111,11 @@ type SwapResult struct {
// 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
+ // WorkersFailed, with a proven SwapDone, is ReplicaSwap's switched
+ // answer whose new workers crashed, restarted or did not all start
+ // within the settle window: the box acknowledges it as switched with
+ // its workers failed, which halts the deploy (replicaSwitchProof).
+ WorkersFailed bool
}
var (
diff --git a/internal/console/replicadeploy.go b/internal/console/replicadeploy.go
index cd4f9629c..8a6fa59bf 100644
--- a/internal/console/replicadeploy.go
+++ b/internal/console/replicadeploy.go
@@ -38,6 +38,8 @@ const (
replicaDeployHalted = "this copy's switch has not been confirmed. other copies keep serving and the deploy is stopped"
// copy SR-4-C37 (provisional)
replicaDeployDone = "deploy complete"
+ // copy SR-4-C46 (provisional)
+ replicaDeployWorkersFailed = "the new build's workers failed on %s, so the deploy stopped. other copies keep serving"
)
// replicaDeployStatus is the one-line deploy state of a record with a copy
@@ -60,6 +62,8 @@ func replicaDeployStatus(rec provision.Record) string {
return replicaDeployDone
case "released":
switch {
+ case d.Swap.Halted && d.Swap.WorkersFailed != "":
+ return fmt.Sprintf(replicaDeployWorkersFailed, d.Swap.WorkersFailed)
case d.Swap.Halted:
return replicaDeployHalted
case d.Swap.ActiveBox != "":
diff --git a/internal/console/replicadeploy_test.go b/internal/console/replicadeploy_test.go
index e74a61ec8..8c0ad3e17 100644
--- a/internal/console/replicadeploy_test.go
+++ b/internal/console/replicadeploy_test.go
@@ -497,3 +497,18 @@ func TestReplicaPromoteRetryStaleReplayRefused(t *testing.T) {
t.Fatal("a refused replay wrote")
}
}
+
+// TestReplicaSwapWorkersFailedStatus (fix round 2): a deploy halted because
+// a box's new workers failed says so, naming the box (SR-4-C46); any other
+// halt keeps SR-4-C16.
+func TestReplicaSwapWorkersFailedStatus(t *testing.T) {
+ rec := provision.Record{ReplicaAssignment: &replicas.Assignment{Desired: 2, Boxes: []string{"a", "b"}},
+ ReplicaDeploy: &replicas.Deploy{ID: "deploy-2", Phase: "released", Swap: replicas.Swap{Order: []string{"a", "b"}, Completed: []string{"a"}, Halted: true, WorkersFailed: "a"}}}
+ if got, want := replicaDeployStatus(rec), "the new build's workers failed on a, so the deploy stopped. other copies keep serving"; got != want {
+ t.Fatalf("status %q, want %q", got, want)
+ }
+ rec.ReplicaDeploy.Swap.WorkersFailed = ""
+ if got := replicaDeployStatus(rec); got != replicaDeployHalted {
+ t.Fatalf("other halt: %q", got)
+ }
+}
diff --git a/internal/host/agent.go b/internal/host/agent.go
index 061f6d5b3..6c5e61035 100644
--- a/internal/host/agent.go
+++ b/internal/host/agent.go
@@ -782,7 +782,7 @@ func runAgent(args []string, buildClaims ClaimFactory) {
deployWorker := newReplicaDeployWorker(deployAPI, identity.Label, svc)
// The box's permitted step runs on its rollout scheduler; the
// worker acknowledges only that step's proven answer.
- deployWorker.step = func(rec provision.Record) (bool, bool) { return replicaStepOf(armedRollout())(rec) }
+ deployWorker.step = armedReplicaStep
armedReplicaDeploy.Store(deployWorker)
defer func() { armedReplicaDeploy.Store(nil); deployWorker.close() }()
defer armedStatelessBindings.Store(nil)
diff --git a/internal/host/replica_deploy_e2e_test.go b/internal/host/replica_deploy_e2e_test.go
index 941229cb7..24b559326 100644
--- a/internal/host/replica_deploy_e2e_test.go
+++ b/internal/host/replica_deploy_e2e_test.go
@@ -369,3 +369,37 @@ func TestReplicaSwapSchedulerUsesFleetLabel(t *testing.T) {
t.Fatalf("off a fleet: %q", got)
}
}
+
+// TestReplicaSwapWorkersFailedHalts (fix round 2): box a switches but its
+// new workers crash. Its step answers switched with WorkersFailed, so the
+// permit resolves (a completed, no open step), the deploy halts with a
+// named and b never gets a permit, and a new attempt may begin at once: a
+// worker failure never leaves a permit open.
+func TestReplicaSwapWorkersFailedHalts(t *testing.T) {
+ w := newDeployStoreWorld(t)
+ client := &e2eClient{w: w, fresh: []string{"a", "b"}}
+ a, b := newE2EBox(t, w, client, "a", true), newE2EBox(t, w, client, "b", false)
+ a.act.step = func() activator.SwapResult {
+ return activator.SwapResult{Outcome: activator.SwapDone, Proven: true, WorkersFailed: true}
+ }
+ runUntil(t, w, "the worker-failure halt", func(rec provision.Record) bool { return rec.ReplicaDeploy.Swap.Halted }, a, b)
+ for i := 0; i < 20; i++ {
+ round(t, w, a, b)
+ }
+ d := w.record().ReplicaDeploy
+ if d.PermitOutstanding() || !slices.Equal(d.Swap.Completed, []string{"a"}) || d.Swap.WorkersFailed != "a" || !replicas.Retryable(d) {
+ t.Fatalf("worker failure did not resolve and halt: %+v", d.Swap)
+ }
+ if _, steps := b.act.counts(); len(steps) != 0 || b.act.serving() != "v1" {
+ t.Fatalf("b moved after a's workers failed: %d steps, serving %s", len(steps), b.act.serving())
+ }
+ // One permit (a's), its ack, and nothing after: no permit for b.
+ if want := []string{"order:a", "permit:a", "ack:a"}; !slices.Equal(client.ops, want) {
+ t.Fatalf("transitions %v, want %v", client.ops, want)
+ }
+ rec := w.record()
+ next := replicas.Deploy{ID: "deploy-3", Incarnation: w.id.Incarnation, Term: w.term, Target: replicas.Build{Version: "v3", Digest: "canonical-3"}, Phase: "pending"}
+ if _, err := provision.SetRecordReplicaRelease(context.Background(), w.s, w.id, rec.ReplicaDeploy.Revision, next); err != nil {
+ t.Fatalf("a fix build could not begin after the halt: %v", err)
+ }
+}
diff --git a/internal/host/replicadeploy.go b/internal/host/replicadeploy.go
index 59239bce4..12b81a86b 100644
--- a/internal/host/replicadeploy.go
+++ b/internal/host/replicadeploy.go
@@ -63,7 +63,7 @@ type replicaDeployWorker struct {
// scheduler's permitted step (activator.ReplicaSwap) has one, switched
// only after that step proved the switch (replicaStepOf). Nil, or no
// answer yet: the permit stays open and nothing is sent.
- step func(provision.Record) (switched, ok bool)
+ step func(provision.Record) (rollout.ReplicaAnswer, bool)
}
var armedReplicaDeploy atomic.Pointer[replicaDeployWorker]
@@ -160,16 +160,20 @@ func replicaDeployStep(rec provision.Record, box, term string) (replicas.DeployC
// when the successor failed and the incumbent kept serving, which halts the
// deploy. No answer, no ACK: the permit stays open, so no next permit is
// granted. A halted permit is answered the same way, which resolves it.
-func replicaAnswer(rec provision.Record, box string, step func(provision.Record) (bool, bool)) (replicas.DeployChange, bool) {
+//
+// A switch whose new workers failed is acknowledged as switched with
+// WorkersFailed: the permit resolves and the deploy halts, so a worker
+// failure never leaves a permit open.
+func replicaAnswer(rec provision.Record, box string, step func(provision.Record) (rollout.ReplicaAnswer, bool)) (replicas.DeployChange, bool) {
d := rec.ReplicaDeploy
if step == nil || d == nil || d.Swap.ActiveBox != box || d.Phase != "released" {
return replicas.DeployChange{}, false
}
- switched, ok := step(rec)
+ answer, ok := step(rec)
if !ok {
return replicas.DeployChange{}, false
}
- return replicas.DeployChange{Op: "ack", ID: d.ID, Box: box, Revision: d.Revision, Target: d.Target, Permit: d.Swap.Permit, Switched: switched}, true
+ return replicas.DeployChange{Op: "ack", ID: d.ID, Box: box, Revision: d.Revision, Target: d.Target, Permit: d.Swap.Permit, Switched: answer.Switched, WorkersFailed: answer.Switched && answer.WorkersFailed}, true
}
// Pass runs at most one transition per noted host.
@@ -227,16 +231,22 @@ func (w *replicaDeployWorker) Pass(ctx context.Context) {
// is m: the answer m's permitted step left for the record's permit
// (rollout.Manager.ReplicaOutcome). The step runs on the scheduler, so it
// keeps the slot, intent and failure book of any attempt.
-func replicaStepOf(m *rollout.Manager) func(provision.Record) (switched, ok bool) {
- return func(rec provision.Record) (bool, bool) {
+func replicaStepOf(m *rollout.Manager) func(provision.Record) (rollout.ReplicaAnswer, bool) {
+ return func(rec provision.Record) (rollout.ReplicaAnswer, bool) {
if m == nil || rec.ReplicaDeploy == nil {
- return false, false
+ return rollout.ReplicaAnswer{}, false
}
d := rec.ReplicaDeploy
return m.ReplicaOutcome(rec.Host, d.ID, d.Swap.Permit)
}
}
+// armedReplicaStep is replicaStepOf over the scheduler armed now, looked
+// up per call: the scheduler arms after the swap worker is built.
+func armedReplicaStep(rec provision.Record) (rollout.ReplicaAnswer, bool) {
+ return replicaStepOf(armedRollout())(rec)
+}
+
// replicaObserved is the reconcile pass's one record observation fanned out
// (R7): to the placement worker, the swap worker and the rollout scheduler
// (which hands it to the activator as policy). None reads the store itself.
diff --git a/internal/host/replicadeploy_test.go b/internal/host/replicadeploy_test.go
index 70621b58b..65c9d0210 100644
--- a/internal/host/replicadeploy_test.go
+++ b/internal/host/replicadeploy_test.go
@@ -14,6 +14,7 @@ import (
"github.com/carlosframework/platform/internal/registry"
"github.com/carlosframework/platform/internal/release"
"github.com/carlosframework/platform/internal/replicas"
+ "github.com/carlosframework/platform/internal/rollout"
)
// deployStoreWorld is one record assigned to boxes a and b, coordinated by
@@ -228,12 +229,12 @@ func TestReplicaDeployPermitReachesWorkerThroughReconcile(t *testing.T) {
}
permits := make(chan provision.Record, 4)
worker := newReplicaDeployWorker(&deployStoreClient{}, "b", nil)
- worker.step = func(r provision.Record) (bool, bool) {
+ worker.step = func(r provision.Record) (rollout.ReplicaAnswer, bool) {
select {
case permits <- r:
default:
}
- return false, false
+ return rollout.ReplicaAnswer{}, false
}
pctx, pcancel := context.WithCancel(ctx)
placement := &replicaPlacementWorker{box: "b", ctx: pctx, cancel: pcancel, reg: reg}
diff --git a/internal/provision/stateless_replicas_4_task2_census_test.go b/internal/provision/stateless_replicas_4_task2_census_test.go
index 3d02f76de..40b9eebca 100644
--- a/internal/provision/stateless_replicas_4_task2_census_test.go
+++ b/internal/provision/stateless_replicas_4_task2_census_test.go
@@ -24,10 +24,20 @@ package provision
// 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.
+//
+// Fix round 2, self-review:
+// - prepareStateless: the no-release shortcut is decided per box from the
+// record (this box's baseline, or its permitted target adopted through
+// the durable path), whatever the pointer says; only a build that is
+// neither, and that the pointer names, begins a new attempt. Still no
+// record write; the reference is unchanged.
+// - The worker-failure ACK is one more field on Task 1's /deploy ack,
+// through the unchanged SetRecordReplicaDeploy (replicas.NextDeploy
+// halts the deploy); no new writer.
func statelessReplicas4Task2WriteCensusInventory() []censusEntry {
entries := append([]censusEntry(nil), statelessReplicas4Task1WriteCensusInventory()...)
for _, r := range []censusEntry{
- {"internal/activator/stateless.go", "Service.prepareStateless", "reference", "key:statelessRecordKey", "9dea1add8190b42c08ed29690350fde6e2c28644d98a5897ea89b7507125e1e6"},
+ {"internal/activator/stateless.go", "Service.prepareStateless", "reference", "key:statelessRecordKey", "b5408db6444e04239d8735515a860a043c7f2203624a3bb992ecc39acd0bfdfe"},
{"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 0987727e9..363b35af3 100644
--- a/internal/provision/testdata/plan14-root-reads-chain.tsv
+++ b/internal/provision/testdata/plan14-root-reads-chain.tsv
@@ -174,3 +174,4 @@ plan14-root-reads-stateless-replicas-4-task1-fix2.tsv 3f066208f5e5fa2b9854f30118
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
+plan14-root-reads-stateless-replicas-4-task2-fix2.tsv 5f83de2e018b47543789a8dbe2cccb86b2d644fbe9ee5771e5d621704ae46e0b
diff --git a/internal/provision/testdata/plan14-root-reads-stateless-replicas-4-task2-fix2.tsv b/internal/provision/testdata/plan14-root-reads-stateless-replicas-4-task2-fix2.tsv
new file mode 100644
index 000000000..3c95caeaa
--- /dev/null
+++ b/internal/provision/testdata/plan14-root-reads-stateless-replicas-4-task2-fix2.tsv
@@ -0,0 +1,13 @@
+# Census overlay stateless-replicas-4-task2-fix2, written by census-propose (#369). census-ruling-stateless-replicas-4-task2-fix2, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-stateless-replicas-4-task2-fix2.md.
+# 4 body, 0 sites, 4 envelope: each changed unit re-frozen at its existing disposition with its claim appended.
+@legacy 3cb5edc4ea42acd31ebdaac4cfd77217fe10d254ed89ea5368232d48e21824b6 internal/activator/replicadeploy.go Service.ReplicaSwap legacy accepted-legacy accepted-legacy;rev3=census-ruling-stateless-replicas-4-task2;basis=Task 2: new. Checks the permit (box label, phase released, not halted, ActiveBox, build), refuses a hold, asks tenantStartRefusal on the in-memory entry route, then either re-proves an existing switch (replicaSettle) or runs the existing Swap as a canary and checks replicaStepProven. Reads the in-memory entry route only; no store, file or root call of its own.;rev3=census-ruling-stateless-replicas-4-task2-fix1;basis=Task 2 fix round 1: proof-only steps (an already switched copy, a halted permit, a permit whose successor failed here) skip the start gates because nothing starts; a failed successor answers kept only after replicaKeptProven (its stop proven, an empty operation set). Reads only the in-memory entry route; no store, file or root call.;rev3=census-ruling-stateless-replicas-4-task2-fix2;basis=Task 2 fix round 2: the switch proof is replicaSwitchProof, which also reports WorkersFailed (switched, the new workers crashed or did not start within the settle window) so the step answers instead of staying open. Reads only the in-memory entry; no store, file or root call. registry:FleetBoxes@694,whole:Route@1408,whole:Route@557,whole:Route@567 180f56db299f2adaf1e73b8d4f1bebf33b009a0585901579be5027c64596d154
+@legacy d167123fb885e1214882018ba08c18af137ead8e45fa6a8a6ea93fcba92d1c47 internal/activator/replicadeploy.go Service.replicaSettle legacy accepted-legacy accepted-legacy;rev3=census-ruling-stateless-replicas-4-task2;basis=Task 2: new. GET / health (genHealthy) and the settle window on the current in-memory generation, then replicaStepProven; reads the in-memory entry route only.;rev3=census-ruling-stateless-replicas-4-task2-fix2;basis=Task 2 fix round 2: after the settle window the proof judges the new workers (replicaSwitchProof, settled); a failure answers switched with WorkersFailed. Same in-memory reads. whole:Route@262,whole:Route@320 b4a2cbc41632244ebe735949f5bae581b9349af513deb3d76a2520ad4a47cbb5
+@legacy c603f4021940fba385ba6aa86304b7641e7e2571797b5e9966718f4e0e2ac24c internal/activator/stateless.go Service.prepareStateless legacy accepted-legacy accepted-legacy;rev3=census-ruling-stateless-replicas-1;basis=Task 3a: Capture RecordFacts from the existing record source, obtain the durable FailureBook deploy ID, and call Task 2 PrepareStatelessRelease with the canonical verdict/digest carrier. Carry a successful attempt through its hold only after another current-record check; no serving lease or polling loop. Fix 3a round 1 I2: preparation uses reconcile observations and records the successful deploy ID. Carry prepared evidence through hold; fresh backend read must confirm that same released deploy before web runs.;rev3=census-ruling-stateless-failed-release-held;basis=For recovery onto a different installed version's exact committed good version and artifact digest, retain recovery evidence without selecting or writing another deploy. Adds the existing committedGood registry read, with its route and incarnation check. Canonical storage declaration and observed lifetime gates remain.;rev3=census-ruling-stateless-replicas-4-task1;basis=R1: no longer calls ReplicaDeployID before preparation; hands the same a.ReplicaDeployID selector to prepareStatelessRelease, which calls it only after coordinator term acquisition. The ObservedReplicaRelease call stays as a validity check. Same read sites; no new read, write or authority.;rev3=census-ruling-stateless-replicas-4-task2;basis=Task 2 (D4): for a set row, prepares the record baseline with no release, and refuses a build the row Version does not name before any release; reads the route it is handed (FleetBoxes, Version). No store read or write added.;rev3=census-ruling-stateless-replicas-4-task2-fix1;basis=Task 2 fix round 1: for a set row, a build its pointer does not name starts only as the record baseline or the committed permitted target, the latter adopted through prepareStatelessRelease durable path (never a new attempt); a named build, a rollback included, takes the release path. The added reads are the handed route (FleetBoxes, Version) and a copy of it with Stateless set for the adoption, as the release path already builds. No store read or write added.;rev3=census-ruling-stateless-replicas-4-task2-fix2;basis=Task 2 fix round 2: for a set row the no-release start is decided per box from the record (this box baseline, or its permitted target adopted through the durable path), whatever the pointer says; only a build that is neither and that the pointer names begins a new attempt. Same reads (the handed route and its copy); no store read or write added. registry:Account@284,registry:Account@310,registry:App@324,registry:App@346,registry:Digest@3117,registry:FleetBoxes@2760,registry:FleetBoxes@944,registry:Host@250,registry:Host@273,registry:Stateless@2177,registry:Stateless@3415,registry:Version@2652,registry:Version@2797,registry:Version@3087,whole:Route@1855,whole:Route@1862,whole:Route@2171,whole:Route@2257,whole:Route@259,whole:Route@293,whole:Route@3037,whole:Route@3181,whole:Route@3188,whole:Route@333,whole:Route@3411,whole:Route@3565,whole:Route@3669,whole:Route@3676,whole:Route@540,whole:Route@597,whole:Route@714,whole:Route@821 b5408db6444e04239d8735515a860a043c7f2203624a3bb992ecc39acd0bfdfe
+internal/activator/replicadeploy.go Service.ReplicaSwap legacy accepted-legacy accepted-legacy;rev3=census-ruling-stateless-replicas-4-task2;basis=Task 2: new. Checks the permit (box label, phase released, not halted, ActiveBox, build), refuses a hold, asks tenantStartRefusal on the in-memory entry route, then either re-proves an existing switch (replicaSettle) or runs the existing Swap as a canary and checks replicaStepProven. Reads the in-memory entry route only; no store, file or root call of its own.;rev3=census-ruling-stateless-replicas-4-task2-fix1;basis=Task 2 fix round 1: proof-only steps (an already switched copy, a halted permit, a permit whose successor failed here) skip the start gates because nothing starts; a failed successor answers kept only after replicaKeptProven (its stop proven, an empty operation set). Reads only the in-memory entry route; no store, file or root call.;rev3=census-ruling-stateless-replicas-4-task2-fix2;basis=Task 2 fix round 2: the switch proof is replicaSwitchProof, which also reports WorkersFailed (switched, the new workers crashed or did not start within the settle window) so the step answers instead of staying open. Reads only the in-memory entry; no store, file or root call. registry:FleetBoxes@694,whole:Route@1408,whole:Route@557,whole:Route@567 180f56db299f2adaf1e73b8d4f1bebf33b009a0585901579be5027c64596d154
+internal/activator/replicadeploy.go Service.replicaSettle legacy accepted-legacy accepted-legacy;rev3=census-ruling-stateless-replicas-4-task2;basis=Task 2: new. GET / health (genHealthy) and the settle window on the current in-memory generation, then replicaStepProven; reads the in-memory entry route only.;rev3=census-ruling-stateless-replicas-4-task2-fix2;basis=Task 2 fix round 2: after the settle window the proof judges the new workers (replicaSwitchProof, settled); a failure answers switched with WorkersFailed. Same in-memory reads. whole:Route@262,whole:Route@320 b4a2cbc41632244ebe735949f5bae581b9349af513deb3d76a2520ad4a47cbb5
+internal/activator/stateless.go Service.prepareStateless legacy accepted-legacy accepted-legacy;rev3=census-ruling-stateless-replicas-1;basis=Task 3a: Capture RecordFacts from the existing record source, obtain the durable FailureBook deploy ID, and call Task 2 PrepareStatelessRelease with the canonical verdict/digest carrier. Carry a successful attempt through its hold only after another current-record check; no serving lease or polling loop. Fix 3a round 1 I2: preparation uses reconcile observations and records the successful deploy ID. Carry prepared evidence through hold; fresh backend read must confirm that same released deploy before web runs.;rev3=census-ruling-stateless-failed-release-held;basis=For recovery onto a different installed version's exact committed good version and artifact digest, retain recovery evidence without selecting or writing another deploy. Adds the existing committedGood registry read, with its route and incarnation check. Canonical storage declaration and observed lifetime gates remain.;rev3=census-ruling-stateless-replicas-4-task1;basis=R1: no longer calls ReplicaDeployID before preparation; hands the same a.ReplicaDeployID selector to prepareStatelessRelease, which calls it only after coordinator term acquisition. The ObservedReplicaRelease call stays as a validity check. Same read sites; no new read, write or authority.;rev3=census-ruling-stateless-replicas-4-task2;basis=Task 2 (D4): for a set row, prepares the record baseline with no release, and refuses a build the row Version does not name before any release; reads the route it is handed (FleetBoxes, Version). No store read or write added.;rev3=census-ruling-stateless-replicas-4-task2-fix1;basis=Task 2 fix round 1: for a set row, a build its pointer does not name starts only as the record baseline or the committed permitted target, the latter adopted through prepareStatelessRelease durable path (never a new attempt); a named build, a rollback included, takes the release path. The added reads are the handed route (FleetBoxes, Version) and a copy of it with Stateless set for the adoption, as the release path already builds. No store read or write added.;rev3=census-ruling-stateless-replicas-4-task2-fix2;basis=Task 2 fix round 2: for a set row the no-release start is decided per box from the record (this box baseline, or its permitted target adopted through the durable path), whatever the pointer says; only a build that is neither and that the pointer names begins a new attempt. Same reads (the handed route and its copy); no store read or write added. registry:Account@284,registry:Account@310,registry:App@324,registry:App@346,registry:Digest@3117,registry:FleetBoxes@2760,registry:FleetBoxes@944,registry:Host@250,registry:Host@273,registry:Stateless@2177,registry:Stateless@3415,registry:Version@2652,registry:Version@2797,registry:Version@3087,whole:Route@1855,whole:Route@1862,whole:Route@2171,whole:Route@2257,whole:Route@259,whole:Route@293,whole:Route@3037,whole:Route@3181,whole:Route@3188,whole:Route@333,whole:Route@3411,whole:Route@3565,whole:Route@3669,whole:Route@3676,whole:Route@540,whole:Route@597,whole:Route@714,whole:Route@821 b5408db6444e04239d8735515a860a043c7f2203624a3bb992ecc39acd0bfdfe
+internal/host/agent.go runAgent authority B,C,D,F rev3=census-ruling-self-serve-moves-1;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): builds the box's lifetime judge once (newBoxJudge, nil with host claims on) and hands it to the seed placement, the moves and runs workers and every loop it starts; read sites unchanged, offsets moved; B,C,D,F authority retained; self-serve moves 1 Task 8: derives the box's lifetimes switch from the judge once (lifetimes := boxJudge != nil) and hands it to the edges file loop; read sites unchanged, offsets moved;rev3=census-ruling-plans-4d-lapse;basis=arms two more plans hooks from the same snapshot: e.SetPlanDisabledFor(planDisabledFor) beside SetPlanGovernedFor, and svc.SetDisabledFor(planDisabledRoute) beside SetMaxRunFor (plans 4d); the reads live in those units (plans-4d-units decision); read sites unchanged, offsets moved;rev3=census-ruling-rootfs-apps-2;basis=main's body as of the merge of origin/main 9b81d97b (with main's plan rate ceiling, edge request records, regional box names, self-serve moves plan 1, plans 4d-1 lapse and its other later changes under main's own census rulings) plus the rootfs placement wiring in the activator start: an agentRootfs built from eb.NestedOK, CARLOS_DEPLOYMENT_SINGLE_TENANT, CARLOS_POOLS, the claim flag, swapArming's answer, the control client's /ready/rootfs and, on a fleet box whose identity resolved, fleetOwnerCheck over the deploy store main already opens for the fleet label (fleetStore), then arm and armedRootfs.Store; this body reads nothing new itself; the closures it wires read later, at a rootfs wake and each status tick: GET /ready/rootfs over the control socket, NestedOK's checks, and release.FleetOwnerKey for the judged row's own account and this box's fleet from the deploy store;rev3=census-ruling-instance-egress-sizes-328-329;basis=#328 plan 2 Tasks 7 and 11, #329 plan 3 Task 7 and plan 1 Task 7's policy cache: the control client is built once and handed to eb.Control, to the status tick (egressStatus) and to a new egressNudgeLoop goroutine; armSizeSource(svc, "/sys/fs/cgroup") after the activator Service; armPolicyCache() after armChangeIndex; statusLoop takes egressStatus. The reads are those units' own (decision rows); this body reads nothing new: the same five sites, offsets moved, in the agent; B,C,D,F authority retained.;rev3=census-ruling-remote-instance-metrics;basis=builds the metrics loop's owners closure (metricsOwners over the agent's registry, the activator and cgm.Leftover) when an activator exists and hands it to metricsLoop; reads nothing new itself;rev3=census-ruling-edge-asset-cache-3;basis=adds file:Statfs. runAgent keeps its authority (B,C,D,F). The new site is assetcache.Statfs, an exported assetcache.FS interface value (var Statfs FS = statfsFS{}), not a function value and not a call in runAgent: the ready hook passes it to armEdgeAssetCache as the store's filesystem, and armEdgeAssetCache calls its Space method on the configured data directory (dataDir(): $CARLOS_DATA_DIR, else /data), which calls unix.Statfs there (statfsFS.Space, accepted legacy at census-ruling-edge-asset-cache-2). No request-supplied pathname reaches it.;rev3=census-ruling-remote-metrics-nested;basis=main's body (merged origin/main acfa4f80, under main's own census rulings) plus: snapshots the nested layout (snapshotNestedUnits over /sys/fs/cgroup/carlos.slice/carlos-instances.slice) once at start, before the activator, and hands the metrics loop a unitSources struct (stamped units, routeHostNames, that root and the snapshot); reads nothing new itself;rev3=census-ruling-region-ha-p1a;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): wires region HA P1a into the activator: cfg.Record = haRecordFacts(openDeployStore, boxJudge) (the box's lifetime judge this body already builds with newBoxJudge, nil with host claims on; CI fix) and cfg.Self = lease.CurrentSelf; eb.Lifetimes (the process's lifetime index), eb.Registry, eb.StartupSwept (seedSweptAtStart.Load), eb.FilesStore from newProductionFilesStore (now lease.NewFilesStore, rootaws-loaded, a log line on failure) and lease.SetObligationDir(<data>/.ha-owed) (logged on failure; HA acquires then refuse); this body reads nothing new itself, the same five sites; the reads are those units' own (haRecordFacts and lease's SetObligationDir are new rows on this card); merge of origin/main d7ae1d76: main's own later changes to this body are kept as main has them, under main's rulings (census-ruling-remote-instance-metrics: the metricsOwners closure for metricsLoop; census-ruling-edge-asset-cache-3: the +file:Statfs site, assetcache.Statfs handed to the asset ready hook); this branch's change is the same as above;rev3=census-ruling-region-ha-p1b1;basis=region HA P1b-1: builds one termfence.Confirmer (Self from lease.CurrentSelf at each call, EC2 DescribeInstances method only, client from rootaws.LoadDefaultConfig with retries off, built lazily on first use) and sets eb.OwnerTerminated; this body reads nothing new itself, the same six sites;rev3=census-ruling-rootfs-apps-3;basis=rootfs Plan 3 Task 7: the startup Sweep literal hands its answer to startupSwept, which logs as before and, only on a clean sweep, marks rootfs admission swept (MarkRootfsSwept); same Sweep call, no read added;rev3=census-ruling-managed-fleets-1b;basis=managed fleets 1b (controller ruling after branch review R1, and Paul's R2 ruling): sets svc.Fleet = fleetWakeFor(os.Getenv, identity, identErr, fleetStore) from the identity it already resolves once and the deployment store the fleet loops already opened, and logs an ERROR naming the identity error when the box is on a fleet with an invalid identity. fleetWakeFor reads CARLOS_REGION and CARLOS_FLEET from the same environment. Read sites unchanged (6). Agent, not root; a platform box is unchanged.;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 12: one call more beside armRunsPass, armInteractivePass(svc, reg, rolloutSink, boxJudge), in the same activator Configure hook, handing it the same box judge; fix round 1 (Astra P2, shutdown): after svc.Shutdown(ctx), shutdownInteractive(ctx) ends and joins every interactive session under the same shutdown budget; the worker's own reads are its units' (interactive.go); this body reads nothing new, the same six sites; merge of origin/main 6f1f6ca6: main's svc.Fleet = fleetWakeFor(...) and its invalid-identity ERROR line are kept as main has them (census-ruling-managed-fleets-1b); this branch's change is the same as above; read sites unchanged (6);rev3=census-ruling-fix-set-aside-exdev;basis=set-aside EXDEV fix: one field more on the agent ExecBackend literal, RawInstanceDir: layout.RawInstanceDir (a pure path join: <dataDir>/.instances/<InstanceID(host)>), so the start rule set-aside moves a copy out through the raw directory instead of through the nosymfollow bind; this body reads nothing new, the same six sites;rev3=census-ruling-durability-3a-escrow;basis=durability 3a Task 3: one more assignment beside eb.FilesStore: eb.EscrowKey = haEscrowKey(os.Getenv("CARLOS_SECRETS_KEY")), the agent's own environment parsed by appconfig.ParsePrivateKey as the moves pass parses it (unset or unparseable: a log line and nil, and HA publication refuses on the box). No path is opened or read, no read site added; the same six sites, offsets moved; B,C,D,F authority retained. Durability 3a Task 4: one more goroutine beside configSyncLoop: go escrowLoop(agentCtx, reg, svc), the escrow sweep every 30 s over the same registry and Service. This body reads nothing new itself; the same six sites, offsets moved; B,C,D,F authority retained. Durability 3a Task 5: one more call beside eb.EscrowKey: wireRawSecretPages(eb, PageOperator, metricsBoxLabel(os.Getenv, readMachineID())), which sets eb.OnRawSecret to page an operator (alerting.Page through PageOperator, LevelIncident) on its own goroutine with a 20 s timeout; metricsBoxLabel and readMachineID are the reads this body already makes for the moves refusal log; no new read site; the same six sites, offsets moved; B,C,D,F authority retained. Merge of origin/main 90c4d3aa: main's own later changes to this body are kept as main has them, under main's rulings; this branch's change is the same as above. Merge of origin/main 00bf5b8c (fleet set-aside EXDEV fix): main's change to this body is kept as main has it, under its own census ruling; this branch's change is unchanged.;rev3=census-ruling-probe-burst-limit;basis=two more sink wirings beside setAnalyticsSink: setProtectionSink(e.SetProtectionRecordOnly) and setAssetOwnersSource(e.AssetOwners), function values the telemetry pass calls; this body reads nothing new, the same six sites; authority B,C,D,F retained; no new root read or write kind;rev3=census-ruling-region-ha-p1b3a;basis=Arm HA placement exactly once on the existing Service before activatorStart and edges publication, wiring AwakeApps and the PageOperator callback; existing six read sites unchanged, no new root authority.;rev3=census-ruling-stateless-replicas-1;basis=Final review I3: start the concrete coordinator's renewal worker with agent setup; existing closeReplicaCoordinator shutdown cancels and joins it before release. No new read sites or credentials. Merge origin/main c59715e7: retain main's armHAPlacement(svc, PageOperator) wiring beside the existing activator setup; stateless coordinator and shutdown wiring remain. Same read sites; no new root read or credential.;rev3=census-ruling-edge-held-streams;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): in the edge-ready callback, calls act.SetHeldWakeHook(e.HeldWake) when act is non-nil (installing the non-blocking wake callback) and stores e.HeldStreamsForStatus in heldStreamsSource. Wiring of in-memory callbacks only; no read added.;rev3=census-ruling-region-ha-p1b3b-t;basis=Wire Service.SetDutyView to the live edge DutySnapshot in the ready callback. No new read; no new loop or cloud operation. B2 wires the registry as the persistent DutyStore before service startup; no new cloud or filesystem path. B3b: arm one journal-backed termination consumer before service startup using agentCtx and the shared confirmer; expose edge tick and join at edge shutdown. No new direct read sites.;rev3=census-ruling-agent-start-demo-1;basis=Passes the existing registry, data store and hibernation prefix into the demo worker, and the existing instance-control client into the demo before-exec hook. No alternate data store or polling loop. Merge resolution against origin/main 9bd45488 retains main's HA departure controller, lifecycle and duty wiring alongside the demo data store and worker; no read site added by the resolution.;rev3=census-ruling-region-ha-p3a;basis=P3a Task 3: install closed fixed admission before every launch source, bind activator/backend and edge, wire the real termination Started lifecycle and role reader after the change index; close before cancellation/child shutdown. No new external reads or cloud authority. Fix R1: move bind/lifecycle/edge-option wiring into wireAgentAdmission and worker listing into runWorkerBootPassAfterAdmission. Worker boot waits for admission before listing then uses unchanged bounded wakes and per-host serialization; whole Route read moves to the helper. No new storage, cloud, or root execution authority. Preserve merged main's agent wiring and census basis; the branch removes one whole Route use by moving worker iteration to the helper, with no added read kind.;rev3=census-ruling-stateless-replicas-2;basis=Slice 3b: arms a fleet-only worker using the existing registry, activator, backend and authenticated console transport. Owned worker stops and joins at shutdown. No new bucket reader. merge of origin/main 9b8b2c50: retain HA duty/departure lifecycle, wake-slot and existing agent wiring alongside the replica placement worker; no new read introduced by resolution. merge of origin/main 6be08467: Retain main demo configuration, admission, build and expiry wiring alongside the replica worker; merge-only body change, no additional read. merge of origin/main 7920cccf: Retain main box-role/group admission wiring and boot publication beside the owned replica worker and shutdown; main moves the boot registry List into runWorkerBootPassAfterAdmission, removing its inline whole Route site. No new read introduced by conflict resolution.;rev3=census-ruling-stateless-replicas-3;basis=Task 1 fix round 1 M3: retain the private snapshot source and cancel/join ownership, but use the replica-health-specific retry loop. It logs its first failure only and retains the existing exponential backoff capped at 30 seconds; unsupported builds return nil. Existing five direct read sites unchanged; no new credentials, bucket reader or app lifecycle action. Fix round 1 Q20: publish Edge.ReplicaSnapshots as a separate in-memory status source, leaving the tenant-visible Upstreams source unchanged. No new external reader or authority.;rev3=census-ruling-region-ha-p3b;basis=Load root-written group marker/configuration, configure signed boot binding and agent receipt completer, wire cancellable admission into departure work and expose cached GroupReaderSnapshot. New indirect boot reads use protected root files; agent-owned receipt controls duplicate initial completion only, never root restart permission. Same five direct sites. Merge 45cebde4 retains the replica health socket lifecycle and setReplicaSource beside GroupReaderSnapshot; no extra read beyond main.;rev3=census-ruling-agent-start-demo-2;basis=agent.go:309-329 opens demo-traffic.db beside the operator-configured registry when a demo domain exists, closes it at shutdown and wires drain-before-purge; :1010-1019 shares the worker and write gate; :1164-1177 installs the fleet identity and closed-until-worker serving callback. One added whole Route pass; the new indirect filesystem/SQL reads are claimed in openDemoTraffic and worker/store units. No request chooses the database pathname.;rev3=census-ruling-region-ha-p1b3b-s;basis=Wire the service duty view to authoritative cached sidecar manifest placement in LifetimeIndex and the edge sidecar projection; missing policy denies duty. Existing instance duty wiring remains.;rev3=census-ruling-region-ha-g2-t3;basis=T3a: wire eb.Page = PageOperator beside OwnerTerminated before departures arm, so suspect-holder pages work if departure setup fails; no new read; existing nine sites and authority unchanged; pages through the existing sink. T3b: publish the same backend through an atomic pointer for the metrics observer, and clear it on return; no new external read or authority.;rev3=census-ruling-agent-start-demo-3;basis=Wire the claim activator and root snapshot client into the demo worker; pass moved readiness to status reporting. Census read-site delta: unchanged (9).;rev3=census-ruling-region-ha-g2-fixes;basis=Wire local pool evidence, live withdrawal activator, startup ingress scan and alias publication, and edge lookup; no new direct sites; new indirect record/claim reads use existing store/judge paths described in ingress helpers.;rev3=census-ruling-region-ha-g2r-fixes;basis=W3: starts the existing record-view backstop loop with a departure-inventory listener (non-blocking, coalesced signal) even without an armed RecordView; it requests the existing full pass (backstopFullDue) there. Same nine read sites; no new read or authority.;rev3=census-ruling-region-ha-graceful-terminate-t2;basis=Derive one signal-time deadline with a 90-second budget; cap departure stop and startup/seed/service shutdown joins by it. No read added.;rev3=census-ruling-static-sweep-periodic;basis=in the edge-ready callback, publishes e.LargestStaticTree in staticTreeSource for the disk alert line (diskAlertFrac in the metrics loop); in-memory wiring only, no read added; read sites unchanged (9);rev3=census-ruling-edge-page-cache-1;basis=wires the exec backend's CurrentInputs into the edge cache (wireCurrentInputs) and, in the ready hook after armEdgeAssetCache (whose returned store it now keeps), calls armEdgePageCache, which does nothing unless CARLOS_PAGE_CACHE=1; read sites unchanged (9); no read added;rev3=census-ruling-gvisor-demos;basis=Capture sandbox resolution and refusal once; log errors once; gate route admission and BeforeExec before process launch. No new root read. Task 5: pass the once-captured sandbox effective mode/config error into ExecBackend, UnitBackend and the immutable Client expectation. Same startup environment/registry reads; swapArming declines gVisor before placement. Task 8: arm read-only status projection with the existing Client.SandboxStatus callback. Agent status now queries the existing root /ready endpoint; no new root authority or guest-file input. Merge2 e8a1ddde: retain main wireCurrentInputs and armEdgePageCache through the existing asset-store ready hook alongside branch once-captured sandbox mode, wake gates and root status wiring. No new direct read; main page-cache helpers retain their own census overlays.;rev3=census-ruling-region-ha-held-build;basis=wires the drain state: svc.SetDrainingSource(boxDrain.IsDraining), svc.SetPeerDrainView(e.PeerDraining), e.SetPeerDrainedHook(svc.DropHoldersNaming); in-memory only; no read added; region HA held-requests Task 5: on group members, starts the drain driver over the activator, the edge and boxDrain, and serves its root-only drain socket; no read added beyond the socket's own Branch review r1: the drain state follows the root start fence on group members (the fence reader is the existing fenceLocation.read, a root-owned fixed path); e.SetPeerUndrainedHook(svc.AllowHoldersNaming) beside the drained hook (memory only); the drain socket serves only the agent's own user. No read added.;rev3=census-ruling-security-review-mitigations;basis=Wire the cached operator flat-layout choice into the exec backend's new-resident refusal; no read source added, existing authority retained.;rev3=census-ruling-w6-ingress-drain;basis=agent (user carlos), not root. Builds the ingress drain (newIngressDrain) with arming read at ask time from os.Getenv (CARLOS_REGION_HA, CARLOS_INGRESS_TARGET_GROUPS, both from the root-owned host.env), the fixed admission and lease.CurrentSelf (existing IMDS identity); its reader is awstg.Load, the box role's credentials calling ELB DescribeTargetHealth/DescribeTargetGroupAttributes (new AWS reads, by the agent). Wires admission.closeStartsForIngressDrain, the lbhealth drain condition, ingress.setEdge, and ingress.shutdownStarted in WithShutdownStarted. The drain socket (/run/carlos/.ha-drain/drain.sock, agent-user only, existing) is now also served on a fixed box with the drain configured (was group members only), routing /v1/ingress/* to the ingress drain and the group drain verbs to 404 there. armHADepartures now takes fixtureDepartureGetenv() and MakeQueue fixtureDepartureQueue(), which in a production (non-rootrunner) build are os.Getenv and nil, as before. Read sites unchanged (9).;rev3=census-ruling-stateless-replicas-4-task1;basis=Arms the fleet-only replica swap worker next to the placement worker: same console URL and fleet token as the existing replicaCoordinatorAPI, the existing activator Service; stops and joins at shutdown. No new read site, credential or bucket reader.;rev3=census-ruling-stateless-replicas-4-task2;basis=Task 2: sets deployWorker.step to the rollout scheduler answer for the record permit (replicaStepOf over armedRollout), an in-memory callback; no read site, credential or bucket reader added.;rev3=census-ruling-stateless-replicas-4-task2-fix2;basis=Task 2 fix round 2: the swap worker step is armedReplicaStep, the same lazy scheduler lookup as before as a named function; no read site added. file:Exec@20408,file:Open@2191,file:Statfs@54834,registry:App@13287,registry:Host@50477,whole:Route@13279,whole:Route@48824,whole:Route@50600,whole:Route@50662 e839b014f4721eefd750c6467aea9a408a9c3020b3af2fc47eb07a2366615e1e
+@coverage internal/activator e786a11e8d6e959ad8efc3125d73134d05e1988f26fe8f20fb3407c5908d928f
+@coverage internal/host 6e0b8760056783f6bedc199c9dd8b22d291d2834e1f0270699ca1e130d55853a
+@coverage internal/replicas 08afa34b7a367c18fdc9f27fc432da60d0ce50e67656877520aa94d3409cf545
+@coverage internal/rollout 838a76580a3fa715c939070cab251740dc1b8054a8c271c9125d52f1e0ab51e9
diff --git a/internal/replicas/deploy.go b/internal/replicas/deploy.go
index 3e310cb7c..a401de492 100644
--- a/internal/replicas/deploy.go
+++ b/internal/replicas/deploy.go
@@ -28,6 +28,10 @@ type DeployChange struct {
// without it reports the box kept its incumbent, which halts the swap.
Permit uint64 `json:"permit,omitempty"`
Switched bool `json:"switched,omitempty"`
+ // WorkersFailed, with Switched, reports that the box switched but the
+ // new build's workers crashed, restarted or did not all start within
+ // the settle window. The ack resolves the permit and halts the deploy.
+ WorkersFailed bool `json:"workers_failed,omitempty"`
}
// ReleasePassed reports a phase whose release command succeeded.
@@ -170,9 +174,16 @@ func NextDeploy(cur Deploy, change DeployChange, coordinator Coordinator, now ti
s.ActiveBox = change.Grant
s.Permit = cur.Revision + 1
case "ack":
- if change.Switched {
+ switch {
+ case change.WorkersFailed && !change.Switched:
+ return Deploy{}, ErrInvalid
+ case change.Switched:
s.Completed = append(s.Completed, s.ActiveBox)
- } else {
+ if change.WorkersFailed {
+ // Switched, but its workers failed: no further permits.
+ s.Halted, s.WorkersFailed = true, s.ActiveBox
+ }
+ default:
s.Halted = true
}
s.ActiveBox = ""
@@ -192,22 +203,25 @@ func NextDeploy(cur Deploy, change DeployChange, coordinator Coordinator, now ti
return next, nil
}
-// 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. 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 {
+// Baseline is the build box runs while this attempt's target is not yet
+// allowed on it, decided from the record alone, whatever box's pointer
+// says. Once the deploy is done, and for a box that completed its switch,
+// it is the target: the previous build is no longer that box's fallback,
+// so returning to it is a new attempt (a rollback takes the same path as a
+// promotion). For any other box it is Previous, the LastGood the attempt
+// began with, which the writer records at begin; before the release passes
+// that equals LastGood, which a legacy record without Previous falls back
+// to. It is empty when no build of this lifetime ever passed a release.
+func (d *Deploy) Baseline(box string) Build {
switch {
case d == nil:
return Build{}
- case d.Phase == "done":
+ case d.Phase == "done", ReleasePassed(d.Phase) && box != "" && slices.Contains(d.Swap.Completed, box):
return d.Target
case ReleasePassed(d.Phase):
return d.Previous
+ case d.Previous != (Build{}):
+ return d.Previous
}
return d.LastGood
}
@@ -234,7 +248,7 @@ func (d *Deploy) Allows(box, incarnation, manifestDigest string) bool {
if manifestDigest == d.Target.Digest && d.TargetAllowed(box) {
return true
}
- return manifestDigest == d.Baseline().Digest
+ return manifestDigest == d.Baseline(box).Digest
}
// Want is the build box should run now: the target once it is allowed
@@ -243,5 +257,5 @@ func (d *Deploy) Want(box string) Build {
if d.TargetAllowed(box) {
return d.Target
}
- return d.Baseline()
+ return d.Baseline(box)
}
diff --git a/internal/replicas/deploy_test.go b/internal/replicas/deploy_test.go
index 893ffb600..1b1c8c4ec 100644
--- a/internal/replicas/deploy_test.go
+++ b/internal/replicas/deploy_test.go
@@ -442,11 +442,13 @@ func TestReplicaSwapAllowsOnlyPermittedTarget(t *testing.T) {
{"failed", attempt("failed", Swap{}), "a", false, good, []Build{good}},
{"unknown", attempt("unknown", Swap{}), "a", false, good, []Build{good}},
{"released, not yet ordered", attempt("released", Swap{}), "a", false, good, []Build{good}},
- {"released, completed", attempt("released", swapping), "a", true, target, []Build{target, good}},
+ // A box that completed its switch has the target as its baseline:
+ // returning it to the previous build is a new attempt (fix round 2).
+ {"released, completed", attempt("released", swapping), "a", true, target, []Build{target}},
{"released, holds the permit", attempt("released", swapping), "b", true, target, []Build{target, good}},
{"released, waiting", attempt("released", swapping), "c", false, good, []Build{good}},
{"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, completed", attempt("released", Swap{Order: []string{"a", "b"}, Completed: []string{"a"}, Halted: true}), "a", true, target, []Build{target}},
{"halted, waiting", attempt("released", Swap{Order: []string{"a", "b"}, Completed: []string{"a"}, Halted: true}), "b", false, good, []Build{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}},
@@ -476,3 +478,29 @@ func TestReplicaSwapAllowsOnlyPermittedTarget(t *testing.T) {
t.Fatal("a waiting box ran something without a baseline")
}
}
+
+// TestReplicaSwapWorkersFailedAckHalts (fix round 2): a box that switched
+// but whose new workers failed acknowledges switched with WorkersFailed.
+// The permit resolves (the box joins Completed, ActiveBox clears), the
+// deploy halts with the box named, and a retry or a new attempt may begin.
+// A worker failure without a switch is not an answer.
+func TestReplicaSwapWorkersFailedAckHalts(t *testing.T) {
+ cur := releasedDeploy()
+ cur.Swap = Swap{Order: []string{"a", "b"}, ActiveBox: "a", Permit: 3}
+ ack := DeployChange{Op: "ack", ID: cur.ID, Box: "a", Revision: cur.Revision, Target: cur.Target, Permit: 3, Switched: true, WorkersFailed: true}
+ next, err := NextDeploy(cur, ack, Coordinator{}, deployNow)
+ if err != nil {
+ t.Fatal(err)
+ }
+ s := next.Swap
+ if s.ActiveBox != "" || !slices.Equal(s.Completed, []string{"a"}) || !s.Halted || s.WorkersFailed != "a" || next.PermitOutstanding() || !Retryable(&next) {
+ t.Fatalf("workers failed: %+v", next)
+ }
+ if err := NewAttemptAllowed(&next, Deploy{ID: "deploy-3", Incarnation: next.Incarnation, Target: Build{Version: "v3", Digest: "canonical-3"}, Phase: "pending", Term: "term-a"}); err != nil {
+ t.Fatalf("a fix build could not begin: %v", err)
+ }
+ ack.Switched = false
+ if _, err := NextDeploy(cur, ack, Coordinator{}, deployNow); !errors.Is(err, ErrInvalid) {
+ t.Fatalf("workers failed without a switch: %v", err)
+ }
+}
diff --git a/internal/replicas/types.go b/internal/replicas/types.go
index b197cd1f2..2224216f0 100644
--- a/internal/replicas/types.go
+++ b/internal/replicas/types.go
@@ -92,6 +92,9 @@ type Swap struct {
// Bootstrap marks an order made when no assigned box was up: its first
// copy started alone, so it was not an availability-preserving rollout.
Bootstrap bool `json:"bootstrap,omitempty"`
+ // WorkersFailed names the box whose switch completed while the new
+ // build's workers failed there; it halted the deploy (DeployChange).
+ WorkersFailed string `json:"workers_failed,omitempty"`
}
type ReleaseChange struct {
diff --git a/internal/rollout/replicas.go b/internal/rollout/replicas.go
index 190e97f2b..edc931a6c 100644
--- a/internal/rollout/replicas.go
+++ b/internal/rollout/replicas.go
@@ -37,12 +37,18 @@ type ReplicaActivator interface {
ReplicaSwap(ctx context.Context, at activator.Attempt, deploy replicas.Deploy, box string, newest func(string) uint64) activator.SwapResult
}
-// replicaOutcome is this box's answer to one permit: switched after its
-// proof, or kept when the successor failed and the incumbent serves.
+// ReplicaAnswer is this box's proven answer to one permit: switched (its
+// new workers possibly failed, which halts the deploy), or kept.
+type ReplicaAnswer struct {
+ Switched bool
+ WorkersFailed bool
+}
+
+// replicaOutcome is this box's answer to one permit.
type replicaOutcome struct {
- id string
- permit uint64
- switched bool
+ id string
+ permit uint64
+ answer ReplicaAnswer
}
// replicaNoBuildRefusal refuses a copy's wake when its record names no
@@ -94,14 +100,14 @@ func (m *Manager) NoteReplicaDeploy(rec provision.Record) {
// ReplicaOutcome is this box's answer to permit of attempt id on host, once
// its step has one: ok false while it has none, and the permit stays open.
-func (m *Manager) ReplicaOutcome(host, id string, permit uint64) (switched, ok bool) {
+func (m *Manager) ReplicaOutcome(host, id string, permit uint64) (ReplicaAnswer, bool) {
m.replicaMu.Lock()
defer m.replicaMu.Unlock()
out, ok := m.replicaOutcomes[host]
if !ok || out.id != id || out.permit != permit {
- return false, false
+ return ReplicaAnswer{}, false
}
- return out.switched, true
+ return out.answer, true
}
// replicaDecision is the queue's question for host (appQueue.replica),
@@ -166,16 +172,17 @@ func (m *Manager) replicaStep(ctx context.Context, a activator.Attempt, newest f
// 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
+ // SwapDone with proof: switched, its workers possibly failed. SwapFailed
+ // with proof (the failed successor proven stopped) or a proof-only step
+ // (SwapAbandoned, ran nothing): kept.
+ answer := ReplicaAnswer{Switched: res.Outcome == activator.SwapDone}
+ answer.WorkersFailed = answer.Switched && res.WorkersFailed
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 {
m.replicaOutcomes = map[string]replicaOutcome{}
}
- m.replicaOutcomes[a.Host] = replicaOutcome{id: d.ID, permit: d.Swap.Permit, switched: switched}
+ m.replicaOutcomes[a.Host] = replicaOutcome{id: d.ID, permit: d.Swap.Permit, answer: answer}
}
m.replicaMu.Unlock()
return res
diff --git a/internal/rollout/replicas_test.go b/internal/rollout/replicas_test.go
index 8241bacdb..c057df23d 100644
--- a/internal/rollout/replicas_test.go
+++ b/internal/rollout/replicas_test.go
@@ -162,7 +162,8 @@ func TestReplicaOrderedOverlapWaitsForPermit(t *testing.T) {
t.Fatalf("step: %+v", at)
}
waitFor(t, "its outcome", func() bool {
- switched, ok := h.m.ReplicaOutcome(replicaHost, "deploy-v2", 9)
+ answer, ok := h.m.ReplicaOutcome(replicaHost, "deploy-v2", 9)
+ switched := answer.Switched
return ok && switched
})
if _, ok := h.m.ReplicaOutcome(replicaHost, "deploy-v2", 8); ok {
@@ -283,7 +284,11 @@ func TestReplicaSwapUnknownHaltsWithoutOutcome(t *testing.T) {
t.Fatal("an unproven step answered")
}
settle(h)
- waitFor(t, "the proof", func() bool { switched, ok := h.m.ReplicaOutcome(replicaHost, "deploy-v2", 9); return ok && switched })
+ waitFor(t, "the proof", func() bool {
+ answer, ok := h.m.ReplicaOutcome(replicaHost, "deploy-v2", 9)
+ switched := answer.Switched
+ return ok && switched
+ })
if at := ra.lastStep(); at.Build != "v2" {
t.Fatalf("proof step: %+v", at)
}
@@ -312,7 +317,11 @@ func TestReplicaSwapUnknownHaltsWithoutOutcome(t *testing.T) {
refusing = false
refuse.Unlock()
settle(h)
- waitFor(t, "the retried step", func() bool { switched, ok := h.m.ReplicaOutcome(replicaHost, "deploy-v2", 9); return ok && switched })
+ waitFor(t, "the retried step", func() bool {
+ answer, ok := h.m.ReplicaOutcome(replicaHost, "deploy-v2", 9)
+ switched := answer.Switched
+ return ok && switched
+ })
})
t.Run("failed successor", func(t *testing.T) {
h, ra := newReplicaHarness(t)
@@ -322,7 +331,11 @@ func TestReplicaSwapUnknownHaltsWithoutOutcome(t *testing.T) {
h.install("v2", replicaHost)
noteReplica(h, deployOf("v2", "v1", "released", permit))
h.pass()
- waitFor(t, "the kept answer", func() bool { switched, ok := h.m.ReplicaOutcome(replicaHost, "deploy-v2", 9); return ok && !switched })
+ waitFor(t, "the kept answer", func() bool {
+ answer, ok := h.m.ReplicaOutcome(replicaHost, "deploy-v2", 9)
+ switched := answer.Switched
+ return ok && !switched
+ })
settle(h)
if ra.stepCount() != 1 || plainSwaps(h, "v2") != 0 {
t.Fatalf("the failed step was retried: %d steps, %d plain", ra.stepCount(), plainSwaps(h, "v2"))
@@ -355,7 +368,11 @@ func TestReplicaSwapUnknownHaltsUntilProof(t *testing.T) {
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 })
+ waitFor(t, "the proven kept answer", func() bool {
+ answer, ok := h.m.ReplicaOutcome(replicaHost, "deploy-v2", 9)
+ switched := answer.Switched
+ 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) {
@@ -370,7 +387,8 @@ func TestReplicaSwapUnknownHaltsUntilProof(t *testing.T) {
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)
+ answer, ok := h.m.ReplicaOutcome(replicaHost, "deploy-v2", 9)
+ switched := answer.Switched
return ok && switched == !kept
})
})