carlos / platform Public

agent: an instance's config is in place before its first process starts

A new instance's first generation started without its app config and was
swapped for a configured one about twelve seconds later (config change).
A nested row's <host>.config.env lives in its instance directory, which
only the first wake made, so the config pass before the wake had nowhere
to write.

The activator now asks the agent before it plans a wake
(Service.ConfigBeforeWake, step 0.69). A route whose file exists, or that
a pass settled with no file, costs a stat and a map read. Any other gets
one config pass narrowed to that host, which makes the instance directory
as prepare would (appconfig.MakeInstanceDir) and writes the bundle. The
plan then carries the delivered revision and the spawn reads the file, so
the first generation is the configured one and nothing restarts.

Best effort: the hook refuses nothing, and a pass that fails or cannot
get the config lock inside 5s leaves the wake as it was.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 8447b1fcc474c559cc8375d79d23435bfa315fa9 parent 55f34c3
13 files changed, +796 −31
  • .amadan/code-health.tsv +3 −3
  • docs/superpowers/notes/census-proposal-instance-ready-before-wake.md +32 −0
  • internal/activator/activator.go +21 −0
  • internal/activator/configbeforewake.go +24 −0
  • internal/activator/configbeforewake_test.go +74 −0
  • internal/appconfig/syncexec.go +38 −1
  • internal/appconfig/syncexec_makedir_test.go +90 −0
  • internal/host/agent.go +6 −27
  • internal/host/configbeforewake.go +220 −0
  • internal/host/configbeforewake_test.go +234 −0
  • internal/provision/testdata/plan14-root-reads-chain.tsv +1 −0
  • internal/provision/testdata/plan14-root-reads-instance-ready-before-wake.tsv +20 −0
  • internal/rollout/wakeplan_test.go +33 −0
diff --git a/.amadan/code-health.tsv b/.amadan/code-health.tsv
index 123cdc67d..439157151 100644
--- a/.amadan/code-health.tsv
+++ b/.amadan/code-health.tsv
@@ -2177,7 +2177,7 @@ func-lines . TestFleetAppServesThroughTheHub - 408
func-lines . runDeploy - 329
func-lines . runRoute - 519
func-lines cmd/console serve - 367
-func-lines internal/activator (*Service).doWakeOnce - 570 # raised: #1290 step 2c, the one call that protects the database before the seed, release commands and the process start (body in replicatebeforestart.go)
+func-lines internal/activator (*Service).doWakeOnce - 571 # raised: step 0.69, the one call that delivers an instance's config before its wake is planned (body in configbeforewake.go); before it, #1290 step 2c
func-lines internal/analytics Prune - 343
func-lines internal/appconfig SyncExecWithCallbacks - 320
func-lines internal/console (*Server).handleAPIInstanceCreate - 769
@@ -2205,7 +2205,7 @@ func-lines internal/host plan14RequiredArtifactsRootRunner - 374
func-lines internal/host plan14TimerIntention - 315
func-lines internal/host plan14TimerIntention.func1 - 311
func-lines internal/host rootFilesSeedIsolatedWitness - 308
-func-lines internal/host runAgent - 688 # raised: #1290 sets the agent continuity directory beside the HA obligation store, where every exec-backend store is configured
+func-lines internal/host runAgent - 689 # raised: sets the activator's ConfigBeforeWake beside BeforeExec, where every wake hook is set before Start (body in configbeforewake.go); before it, #1290's continuity directory
func-lines internal/host runFilesSeedPreparationWithLive - 390
func-lines internal/host runServingParkPeerNamespace - 538
func-lines internal/host testRootMigrationBootstrap - 364
@@ -2220,7 +2220,7 @@ func-lines internal/release adoptHost - 494
func-lines internal/team TestFixture - 421
file-lines . apimode.go - 4184
file-lines . apimode_test.go - 3530 # raised: fdc912b (batch 2, #1123) landed before the ratchet; tests for the system update refusals
-file-lines internal/activator activator.go - 3783 # raised: #1290 step 2c, the call to protectBeforeStart (its body and interface live in replicatebeforestart.go)
+file-lines internal/activator activator.go - 3785 # raised: the Service.ConfigBeforeWake field and doWakeOnce's one call to it (the body lives in configbeforewake.go); before it, #1290 step 2c
file-lines internal/activator activator_test.go - 5471
file-lines internal/console server.go - 4223 # raised: domain transfers Task 6, Config.LookupNS, LookupDS and DNSServer (the brief puts them on Config) and the transfer engine clock seam on Server
file-lines internal/host agent.go - 3214
diff --git a/docs/superpowers/notes/census-proposal-instance-ready-before-wake.md b/docs/superpowers/notes/census-proposal-instance-ready-before-wake.md
new file mode 100644
index 000000000..05a147bcc
--- /dev/null
+++ b/docs/superpowers/notes/census-proposal-instance-ready-before-wake.md
@@ -0,0 +1,32 @@
+# Census approval: instance-ready-before-wake
+
+Ruling `census-ruling-instance-ready-before-wake`. The independent reviewer approves or rejects every change below, 4 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26).
+
+| unit | change | read sites | what changed |
+|---|---|---|---|
+| `internal/activator/activator.go` `type Service` | body | unchanged (0) | the agent as carlos: gains the ConfigBeforeWake hook field beside Planner, a func the agent sets before Start. No read added. |
+| `internal/appconfig/syncexec.go` `SyncExecWithCallbacks` | body | unchanged (62) | the agent as carlos, through syncExecLocked: the per-host call is now syncExecHostMaking with the pass MakeInstanceDir option (false under host writes). With the option off, which every config loop pass and the root pass leave it, the body is as before. No new read site. |
+| `internal/host/agent.go` `runAgent` | body | unchanged (8) | the agent as carlos: sets svc.ConfigBeforeWake = configBeforeWake(reg, dd, claims.Writes) beside BeforeExec, before Start. Read sites unchanged, offsets moved. |
+| `internal/activator/activator.go` `Service.doWakeOnce` | sites | +whole:Route | the agent as carlos: one call, step 0.69, a.configBeforeWake(ctx, e, rt), after the held wake check and before the planner. It hands the hook the route this wake already holds (the added whole Route site). It returns nothing, so no refusal, lease, restore or spawn ordering changes. |
+
+Envelopes re-pinned: `internal/activator`, `internal/appconfig`, `internal/host`.
+
+Review: a model from the other family than the author reads the branch's diff against main on the amadan.net remote (`origin` or `amadan`, whichever points at amadan.net) and gives a verdict for every unit and every re-pinned envelope above. For a unit, compare the change with its recorded disposition and basis below; for an envelope, read every changed function in the package and what it reaches. Reject if the change lets root open, run, query or follow anything it did not before from a path or input a tenant, an app or a box agent can create, write or name; if it weakens a check, refusal, validation, argument or environment the basis relies on; or if the diff cannot settle either. Otherwise approve. Record each verdict on #280 with the tip. A rejected unit goes back to the author to correct; nothing escalates to the census owner.
+
+Recorded dispositions, which each change must still satisfy:
+
+- `internal/activator/activator.go` `type Service`: authority, task B,C,D,F,J4. Basis: rev3=PROPOSED-seed; existing activator lifecycle and due-wake state plus owned seed exclusion and incarnation-keyed diagnostics; normal refusal and preparation ordering remain authoritative; PROPOSED-plans-2-box-limits adds the idleFor hook field, which only narrows idle windows;rev3=census-ruling-plans-4c-box-throttle;basis=gains the maxRunFor hook field beside idleFor (plans 4c). No read added.;rev3=census-ruling-plans-4d-lapse;basis=gains the disabledFor hook field beside maxRunFor (plans 4d). No read added.;rev3=census-ruling-remote-instance-metrics;basis=gains tenancySeq, hostTenants and hostMixed, in-memory fields for Tenancies; no read added;rev3=census-ruling-region-ha-p1a;basis=the agent as carlos: one more field, markers (markerRetry: an atomic running flag and the last log time) for retryOwedMarkers; no read added; merge of origin/main d7ae1d76: main's fields are kept as main has them (census-ruling-remote-instance-metrics: tenancySeq, hostTenants, hostMixed); this branch's change is the same as above;rev3=census-ruling-rootfs-apps-3;basis=rootfs Plan 3 Tasks 7 and 8: new fields for rootfs admission (rootfsArmed, rootfsSwept), the per-host gate ask and refusal memo, and residency state (lister, backoff, start ceiling, cursor, test seam); no read;rev3=census-ruling-rootfs-apps-3-release;basis=rootfs Plan 3 Group R: one new field, releaseOps (host to the in-memory release record, under a.mu); no read;rev3=census-ruling-rootfs-apps-3-workers;basis=rootfs Plan 3 Group W: one new field, leaseNow (a clock seam for a worker start's headroom against the lease deadline, nil is the real clock); no read;rev3=census-ruling-region-ha-p1b2;basis=region HA P1b-2: gains the holder cache and its single-flight state; no read;rev3=census-ruling-managed-fleets-1b;basis=managed fleets 1b (controller ruling after branch review R1, and Paul's R2 ruling): one field, Fleet (activator.FleetWake: the box's fleet state, not on a fleet by default, on a fleet with a known label and a record reader, or on a fleet with an invalid identity), set by the agent before Start and read only by routeCurrentUnderLease. No read in the declaration. Agent, not root.;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a fix round 1: one field, drainBudget (time.Duration), which New copies from residentDrainBudget and a rootfs entry's lease watch reads in its place, so a test's change of the package var never races a watch goroutine; declaration only, reads nothing; merge of origin/main 6f1f6ca6: main's one field, Fleet (activator.FleetWake), is kept as main has it (census-ruling-managed-fleets-1b); this branch's change is the same as above;rev3=census-ruling-region-ha-p1b3a;basis=Add bounded placement peer and diagnostic state and the over-capacity callback; no read in this declaration and no new root authority.;rev3=census-ruling-stateless-replicas-1;basis=Add coordinator, existing-record observation callback and per-host preparation locks; no read in the declaration. Task 3a: Add optional canonical storage-selection and durable deploy-ID callbacks; declaration only, no read or authority in these fields.;rev3=census-ruling-edge-held-streams;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): adds the heldLegs map to actEntry (legs by id, under a.mu) and heldWakeHook (atomic pointer to a callback) and heldLegSeq (atomic counter) to Service. State only, in memory; no read of tenant, app or box-agent-writable input.;rev3=census-ruling-wake-storm-cap;basis=the agent as carlos: one field, wakeSlots (chan struct{}, the wake semaphore made by New from Config.WakeSlots, default 4); declaration only, no read.;rev3=census-ruling-region-ha-p1b3b-t;basis=Add the B2 DutyStore interface field and process-local duty view, suppression and invalidation state. No read added. B2 adds the verified-successor identity callback; no read in the declaration. B3b adds a nonblocking departure-suspicion callback, invoked only after an accepted holder-forward failure and after cache locks release; it cannot authorize a take.;rev3=census-ruling-region-ha-p3a;basis=P3a Task 3: immutable callbacks installed before Start for tenant admission, local start permission, fixed route exemptions and shutdown closure; nil callbacks preserve switch-off behavior; no new reads. Fix R1: add an immutable startup-phase callback for response copy, set before service startup. No new read or execution authority.;rev3=census-ruling-region-ha-g2-fixes;basis=Add in-memory HA loss state and pool withdrawal jobs; no new read.;rev3=census-ruling-region-ha-held-build;basis=region HA held-requests Task 1: one new field, drain (drainSources: two atomic func pointers for this box's and peers' drain state); no read added. region HA held-requests Task 2: one new field, moves (moveTable: per-host move state, hold counts and admission tickets in memory, under mu); no read added;rev3=census-ruling-held-move-speed;basis=the agent as carlos: one new field, moveStreams (per-host in-memory set of edge.StreamEnd for requests in flight, own mutex), for the move's early stream cut; actEntry gains drainRelease (bool, under a.mu), set by DrainStop; declarations only, no read added;rev3=census-ruling-fix-silent-start-kill-861;basis=#861: two fields, wakeFailMu and wakeFailLogged (per-host in-memory note of the last journalled wake failure); declaration only, no read;rev3=census-ruling-w6-ingress-drain;basis=new field TenantStartsClosed func() bool; when it answers true tenantStartRefusal refuses every start, exempt routes included. Wired only by fixedAdmission.bind to the ingress drain's closed flag. Struct field only; no read added.;rev3=census-ruling-stateless-replicas-4-task2;basis=Task 2: one field, replicaPolicies (host to the newest observed replica deploy and this box label, under mu), set only by SetReplicaDeploy; declaration only, no read.;rev3=census-ruling-stateless-replicas-4-task2-fix1;basis=Task 2 fix round 1: one more in-memory field, replicaFailed (host to the permit whose successor failed here, under mu), so that step only proves what it kept; declaration only, no read.;rev3=census-ruling-stateless-replicas-4-task3f;basis=Task 3F fix round 3 (#511 F11): two hook fields, MarkReplicaRelease and ReplicaReleaseMark (the failure book's per-host release mark on this box's disk). No read site.;rev3=census-ruling-stateless-replicas-4-task5;basis=Task 5 first commit (#511 F11): one in-memory field, heldSeen (host to the last held release attempt, error class and when it was met), under the existing wakeFailMu. Declaration only, no read.;rev3=census-ruling-stateless-replicas-4-merge-main;basis=Merge of main 5fac2ff1: both sides changed it. Main (27d3f501) adds the background atomic.Int64 field that tests wait on; this branch keeps its replica fields. Both kept as-is; no read added.;rev3=census-ruling-stateless-replicas-4-final;basis=#511 final wave item 3: adds replicaSwitched, an in-memory map of the permit each set row switched under (host -> permit key, time, resident flag); no read added; #511 micro-fix P1b: adds replicaNoGen, an in-memory map (host -> permit key and when first seen) that is only the bound's clock for a restarted permit holder with no generation; no read added;rev3=census-ruling-stateless-replicas-4-drill1;basis=#511 drill 1 R20 bound (round 1: clock with start and last seen): one in-memory field, releaseConfigWaits (per host, a stateless release's config wait), under mu; no read;rev3=census-ruling-stateless-replicas-4-r28;basis=R28 review round 2 (#511): one field, retiringCopy, an atomic pointer to the edge's in-memory retired-copy check, handed over by edge.New (SetRetiringCopy); no read, no root decision;rev3=census-ruling-g6-fence;basis=G6 F-C Task 3, the agent as carlos: four fields, fenceWatchers (sync.WaitGroup of running write-fence watchers) and three test seams nil in production (fenceWatchStarted, retainDB, wakeReturned). Declaration only, no read.;rev3=census-ruling-fleet-record-labels-m1;basis=fleet record labels R1/R2: actEntry gains checkpoint state (busy while CloseProven runs, unproven, named-once flag for C45), in-memory under a.mu; the worker gains fence pacing apart from crash backoff; Service gains test seams nil in production; declarations only, no read;rev3=census-ruling-race-activator-1249;basis=adds two test-only fields: leaseWork (a WaitGroup counting lease watches and the one-shot stops a short lease starts) and leaseWatchStop (a channel, nil in production, that a test closes to end every lease watch); no read added and production never waits on or closes either;rev3=census-ruling-fleet-restart-wake;basis=Fleet restart wake Task 1: the per-host journal note maps (wakeFailLogged, heldSeen) move into the embedded wakeNotes struct in wakefaillog.go, which adds fenceSeen. In-memory only; no read added.;rev3=census-ruling-stateless-scale-2-fleet-sizes;basis=the agent (carlos-edge.service, user carlos), not root: one embedded field (#892 S2), fleetSizeService (fleetreserve.go), which holds BoxLabel (string, the rollout's own box label, set by armRollout) and fleetReserve (fleetReservations, ready as its zero value; it reads /proc/meminfo through memAvailable only when a fleet-size overlap reserves), the box's in-memory overlap reservation for fleet sizes. Declaration only; no read added
+- `internal/appconfig/syncexec.go` `SyncExecWithCallbacks`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-moves-offline-fixes;basis=route-and-input (J1,J4, main's disposition); the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos), through syncExecSerialized: main's body, with a nested row whose write found no instance directory named and skipped (errInstanceDirAbsent, WhenInstanceDirAbsent) instead of failing the pass, and each in-scope host reported done or not done (WithHostOutcome) once the pass has gone through every route; no new read site;rev3=PROPOSED-s3-change-index;identity=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos);basis=the scoped pass's route filter (WithRouteFilter, syncOptions.kept) is checked in its three route loops, so a route the filter leaves out is out of scope before anything is read for it; three whole-Route sites added, each passing rt to kept; no bucket or file read added;rev3=census-ruling-team-scoped-credentials;basis=team-scoped credentials (#449 §3): checkOptedIn's default-bundle thunk answers no default bundle for an OWNED environment bundle, so its exec_delivery is its own and never inherited; the same bundle reads as before, no read site added;rev3=census-ruling-named-unit-delivery-114;basis=the stale-file notice loop gains the stamped case: os.Stat of ConfigEnvPath(dataDir, rt), the path the exec-addr case already stats, and a notice line; no write, no new path;rev3=census-ruling-design-console-secrets;basis=the <host>.config collision set is built by routeHostSet (shared with the classifier) instead of inline; same rows read, same skip; no read site 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.;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.;rev3=census-ruling-stateless-replicas-4-merge-main;basis=Merge of main 5fac2ff1: both sides changed it. Main (01d6ca78, linked-deployments-slice1) starts linkLoop beside tunnelLoop; this branch keeps its replica coordinator wiring. Both kept as-is; no read added.;rev3=census-ruling-stateless-replicas-4-final;basis=#511 final wave item 2: wires the swap worker's drive (armedReplicaDrive, the armed rollout manager's DriveReplicaRelease); no read added;rev3=census-ruling-stateless-replicas-4-merge-main2;basis=Merge of main af871da0 (v0.34.49): both sides changed it. Main (178dcfe5, member-backups-2a) moves the inline duty-view closure into armDutyView/dutyView and starts verifyAssignLoop; its sites drop by registry:Host and whole:Route x2 as main recorded them. This branch keeps its replica coordinator, swap worker and drive wiring. Both kept as-is; no read added.;rev3=census-ruling-stateless-replicas-4-drill3;basis=drill 3 R24: makes one in-memory channel, closes it (once) inside the edge's existing shutdown-started callback after ingress.shutdownStarted, and passes it to tunnelLoop, which drains only a fleet channel name; no read added, same six sites; touches no admission, lease, ingress drain, listener or file; the agent process, no root decision;rev3=census-ruling-edge-ppv2;basis=Agent (uid carlos), not root. memwatchLoop now gets edgeProxyCounters(&demoEdge) (in-process counters, no read). The drain socket's driver is newAgentDrainSocket(ingress, e, os.Getenv), which attaches the edge trust handler only when CARLOS_INGRESS_PROXY_SOURCES in the agent's environment (from the root-owned host.env) parses to a non-empty list; the socket is served when drainSocketServed: a group member or a configured ingress drain (both as before), or a box armed for PROXY protocol (new). The socket's path and agent-user-only permissions are unchanged. Read sites unchanged (6).;rev3=census-ruling-same-box-edge-fence;basis=Agent (uid carlos), not root. One added line: armEdgeFenceStatus(ctl.EdgeFence), beside the existing armExecSandboxStatus, so the layout report can ask root's /ready for the edge fence state over the control socket client the agent already holds. No read added.;rev3=census-ruling-platform-mail-submission;basis=Task 4: sets eb.Mail = mailsubmit.SocketForwarder{} on every box, and eb.MailSwitch to a mailSwitchCache's On that opens the deploy store itself through openDeployStore, retried at most once a minute with an error line until it opens (review round 1, Task 4 P3), armed for the serial-move refresh (armedMailSwitch). Task 6: also sets the ExecBackend's ManifestOf, the same staged-manifest read as TierOf (rt.App and RouteAccount(rt), hence +registry:App and +whole:Route), for the spawn-time check of decision 10, which logs and emits an event and never refuses. Agent, not root. Fable final P2-2: eb.MailSwitch is the cache's State (three-valued: on, off, unknown) in place of On; an unreadable switch is unknown, never off. No read added.;rev3=census-ruling-fleet-drain-followups;basis=P3 (#1008 T9): one call after armChangeIndex, requestBootFullPass(v, &backstopFullDue), which stores true in the existing in-memory backstopFullDue flag only when no record view is armed, so the fast loop runs its existing full pass on its first tick instead of instancesLoop a minute later; armed boxes unchanged. No read added; read sites unchanged (8); agent, not root.;rev3=census-ruling-fleet-first-reconcile-speed;basis=Startup timing log lines only: runDuties builds a step logger (newStartupLog, which reads the in-memory agent start time) and logs one line after the wait on the activator startup latch and after each existing duty before go fastConvergeLoop. One newStartupLog().at line in the edge ready hook before go tunnelLoop. No read added; read sites unchanged (8). Agent, not root.;rev3=census-ruling-ha-1192;basis=sets the group drain driver's departed hook to armedPeerDeparted (the armed departure controller's PeerDeparted: local registry identity + departure journal); no new read;rev3=census-ruling-replica-wake-gap-r3;basis=Calls lease.SetContinuityDir(<data dir>/.continuity) beside the existing obligation store: the agent's own 0700 directory for clean records, outside every instance tree (#1290 round 3). No new read; failure is logged and every start then takes a full image.;rev3=census-ruling-fleet-restart-wake;basis=Fleet restart wake Task 2: cfg.ReplicaRecord = replicaRecordFacts(boxLifetimes, cfg.Record): hands the existing judged record read (haRecordFacts over openDeployStore and boxJudge) as the live read on a lifetime index miss. No read site added here; agent, not root.;rev3=census-ruling-alias-publish-precert-1293;basis=starts edgesFileLoop with one more argument, edgeAcmeDir(os.Getenv, peekAcmeCache(args)): the agent's own -acme-cache flag (already parsed for domainsLoop) or $CARLOS_DATA_DIR/acme; a string computed from the operator's command line and environment, no read. Same 8 read sites.
+- `internal/activator/activator.go` `Service.doWakeOnce`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-stateless-replicas-1;basis=Task 3a: The former doWake body, not deleted logic: refresh/admit/fence/layout checks remain. Select and verify the actual staged identity before serving Acquire; use canonical mode to call doStatelessWake. Keep SQLite acquire/restore/seed/marker/replicate only in the stateful arm, with the post-acquisition selection recheck and existing cleanup proofs. Fix 3a round 1 I1/I3a: admit config directly only for stateless and mark runtime ownership refusals. Stateful Acquire/Restore precede selection and pending publication; canonical mode inspection is separate, replan precedes settlement. Fix round 2 N2/N3: retain the original route/pin projection for post-lease declaration checks; reuse the unplanned capture so a live-link repoint cannot change the selected build. Stateful capture and changed-copy errors remain start failures after Acquire/Restore. A failed preliminary verification supplies no cached mode observation. No new file path or database authority. Final review C1/R26: unprojected stateful wakes capture and materialize the live link only after Acquire and Restore. Retain original route/generation/pin stateless evidence on the context across fallback, so missing stateless evidence cannot take stateful recovery inference. Known good stateful identity skips canonical declaration lookup. Existing pre-exec verification remains. R28 final fix 2: carry whether this wake has a plan in attempt-local context; no new read here; route, generation and pin stateless projection remains intact.;rev3=census-ruling-agent-start-demo-1;basis=Reads IsDemo and demo admission/capability state; chooses local lease retention, skips seed upload and sidecar selection. Existing stop and under-lease ordering retained.;rev3=census-ruling-region-ha-p3a;basis=P3a Task 3: refuse tenant starts under the existing service lock before main's demoWakeRefusal, and recheck before backend Acquire. Retain main's demo refusal and all lease, restore and serialization checks. Two added whole Route uses feed the in-memory admission predicate; no new filesystem or store read.;rev3=census-ruling-stateless-replicas-2;basis=P14: after verified storage-mode selection, before clearing the projected hint or acquiring a database lease, a set row still on the stateful branch returns ErrFenced. Reads the existing route FleetBoxes field only. Verified stateless wakes take their existing branch; legacy rows remain unchanged. No new file, registry query or bucket read. merge of origin/main 9b8b2c50: retain wake-slot and HA duty logic alongside the replica stateful-start refusal; no gate removed. merge of origin/main 6be08467: Keep main demo lease, local database and KeepLocal path; never equate replication-disabled demos with stateless generations. Merge-only body/read-site change. merge of origin/main 7920cccf: Retain main tenant admission and startOwnedLocked gates alongside the replica stateful-start refusal; whole Route passed to main admission checks, no new path or store read.;rev3=census-ruling-agent-start-demo-3;basis=Route claim seeds through seed restore/admission; do not fall back to empty boot or ordinary import behavior. Census read-site delta: +registry:SeedSource, +whole:Route.;rev3=census-ruling-region-ha-g2-fixes;basis=Bound recovery Acquire by its attempt deadline; existing acquire/restore/start ordering remains; no new read.;rev3=census-ruling-g6-fence;basis=G6 F-C Task 3, the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): right after retainDatabase returns, attaches the write-fence watcher under a.mu (watchWriteFenceLocked, in memory). retainDatabase is called through a retainDB test seam that is nil in production. No read added; no root call; existing acquire, restore, publisher and cleanup order unchanged.;rev3=census-ruling-sr-followups;basis=#1061 Task 1, the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): a refused plan now returns planRefusal(host, plan) instead of the inline fmt.Errorf, the text is unchanged, and when the planner marked the plan Installing the error also matches errBuildNotInstalled (installRefusal, in memory). Same refusal at the same point before the lease, read sites unchanged, no read, file, store, bucket or root call added;rev3=census-ruling-replica-wake-gap;basis=Step 2c: before the seed and the spawn, asks the lease to ProtectStart(rt.DBPath), the route's own database path already used by Restore and retainDatabase; a refusal gives the lease back and starts nothing. Agent code (user carlos); no root call, no new store or file read here.;rev3=census-ruling-replica-wake-gap-ch;basis=Step 2c's body moved unchanged into protectBeforeStart (replicatebeforestart.go); doWakeOnce passes the whole Route it already holds and returns the error. No read added; the DBPath read moved with the body.
+
+New dispositions, which census-propose wrote and the reviewer checks against the unit's reads and the diff:
+
+- new `internal/activator/configbeforewake.go:Service.configBeforeWake`: reads +whole:Route; written legacy, accepted-legacy, frozen
+- new `internal/appconfig/syncexec.go:syncExecHostMaking`: reads +registry:Host, +whole:Route ×3; written legacy, accepted-legacy, frozen
+- new `internal/host/configbeforewake.go:configBeforeWake`: reads +whole:Route; written legacy, accepted-legacy, frozen
+- new `internal/host/configbeforewake.go:deliverConfigBeforeWake`: reads +file:Lstat, +registry:Host ×4, +whole:Route ×2; written legacy, accepted-legacy, frozen
+
+Seal: `c25a6eac6ece70098b052b6451deff684c29ff8cfcd24ba37625f01028dedf88` → `e06c8d16caf860ee2044fd8856fb27c2a824e9546b765d938173cd319a7ede50`.
+
+Overlay: `internal/provision/testdata/plan14-root-reads-instance-ready-before-wake.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`.
diff --git a/internal/activator/activator.go b/internal/activator/activator.go
index c2b64e829..88b91b633 100644
--- a/internal/activator/activator.go
+++ b/internal/activator/activator.go
@@ -1618,6 +1618,22 @@ type Service struct {
// and fail OPEN, since a read error must not stop legitimate bindings.
OnWake func(rt registry.Route)
+ // ConfigBeforeWake, when set, is given each wake's route before the
+ // wake is planned, so the agent can put the instance's config file in
+ // place while nothing of the wake has read it: the planner snapshots
+ // the delivered revision (WakePlan.ConfigRev) and the spawn reads the
+ // file, both after this. Without it a new instance's first process
+ // started before config sync had written its file, ran without its
+ // config, and was restarted onto it seconds later. It answers nothing:
+ // a delivery that fails leaves the wake as it was before the hook
+ // existed, and config sync delivers and restarts as it always has. A
+ // hold swap's pinned wake and a fallback's second pass are not asked:
+ // the instance's file was settled before either. It is called without
+ // a.mu held and must not call back into Service. Set before Start, like
+ // OnWake; nil (every unit test, a box with no config to deliver) asks
+ // nothing.
+ ConfigBeforeWake func(ctx context.Context, rt registry.Route)
+
// Planner, when set, says which build each wake boots (zero-downtime
// spec §8.2). The rollout manager sets it with CARLOS_SWAP=overlap; nil
// keeps today's wake from the live link. It is called without a.mu held.
@@ -2846,6 +2862,11 @@ func (a *Service) doWakeOnce(ctx context.Context, e *actEntry) (*wokenInstance,
}
}
+ // 0.69. The instance's config is delivered before anything of this wake
+ // reads it (ConfigBeforeWake): before the planner, whose plan carries
+ // the delivered revision, and so before the lease and the spawn.
+ a.configBeforeWake(ctx, e, rt)
+
// 0.7. Which build this wake boots (zero-downtime spec §8.2). A hold
// swap's pinned wake (e.pin) already knows; everything else asks the
// planner, off a.mu, before the lease: a refused plan takes no lease.
diff --git a/internal/activator/configbeforewake.go b/internal/activator/configbeforewake.go
new file mode 100644
index 000000000..6ada25605
--- /dev/null
+++ b/internal/activator/configbeforewake.go
@@ -0,0 +1,24 @@
+package activator
+
+import (
+ "context"
+
+ "github.com/carlosframework/platform/internal/registry"
+)
+
+// configBeforeWake is doWakeOnce's step 0.69: the agent's ConfigBeforeWake,
+// asked for every wake that reads the instance's config file afresh. A hold
+// swap's pinned wake (e.pin) and a fallback's second pass through doWakeOnce
+// (wakeFallbackKey) are not asked: the first replaces a generation that was
+// already running on a settled file, and the second follows a pass that
+// asked moments ago. Called without a.mu held; e.pin is set at the entry's
+// construction and never written after (holdWakeLocked).
+func (a *Service) configBeforeWake(ctx context.Context, e *actEntry, rt registry.Route) {
+ if a.ConfigBeforeWake == nil || e.pin != nil {
+ return
+ }
+ if _, fallback := ctx.Value(wakeFallbackKey{}).(WakePlan); fallback {
+ return
+ }
+ a.ConfigBeforeWake(ctx, rt)
+}
diff --git a/internal/activator/configbeforewake_test.go b/internal/activator/configbeforewake_test.go
new file mode 100644
index 000000000..2291aeb78
--- /dev/null
+++ b/internal/activator/configbeforewake_test.go
@@ -0,0 +1,74 @@
+package activator
+
+import (
+ "context"
+ "slices"
+ "sync"
+ "testing"
+
+ "github.com/carlosframework/platform/internal/registry"
+)
+
+// Production, 2026-11-24: a new instance's first generation started before
+// its config file was written, ran without its config, and was swapped for
+// a configured one seconds later. The agent is now asked before the wake is
+// planned (step 0.69), so the plan's delivered revision and the spawn's
+// read both come after the file is in place.
+func TestConfigIsAskedForBeforeAWakeIsPlannedOrStarted(t *testing.T) {
+ dir := t.TempDir()
+ good, next := stagedID(t, dir, "v1"), stagedID(t, dir, "v2")
+ a, b, evs := planActivator(t, WakePlan{})
+ var mu sync.Mutex
+ var order []string
+ note := func(s string) {
+ mu.Lock()
+ defer mu.Unlock()
+ order = append(order, s)
+ }
+ a.ConfigBeforeWake = func(_ context.Context, rt registry.Route) {
+ if len(b.started()) != 0 {
+ note("config after a start")
+ return
+ }
+ note("config " + rt.Host)
+ }
+ a.Planner = func(context.Context, registry.Route) WakePlan {
+ note("plan")
+ return WakePlan{Boot: next, Mode: ModeOverlap, FirstWake: true, Fallback: &good}
+ }
+ done, err := a.beginRequest(context.Background(), testRoute("one.example.com"))
+ if err != nil {
+ t.Fatalf("the wake failed: %v", err)
+ }
+ done()
+ evs.wait(t, GenHealthy)
+ mu.Lock()
+ got := slices.Clone(order)
+ mu.Unlock()
+ if want := []string{"config one.example.com", "plan"}; !slices.Equal(got, want) {
+ t.Fatalf("order = %v, want %v: the config is delivered before the plan snapshots its revision", got, want)
+ }
+ if gens := b.started(); len(gens) != 1 || gens[0].Build != "v2" {
+ t.Fatalf("spawned %+v, want v2 alone", gens)
+ }
+}
+
+// A hold swap's pinned wake and a fallback's second pass are not asked:
+// the file was settled before either, and neither is the first read of it.
+func TestConfigIsNotAskedForOnAPinnedOrFallbackWake(t *testing.T) {
+ a, _, _ := planActivator(t, WakePlan{})
+ asked := 0
+ a.ConfigBeforeWake = func(context.Context, registry.Route) { asked++ }
+ rt := testRoute("one.example.com")
+ a.configBeforeWake(context.Background(), &actEntry{pin: &Gen{Build: "v1"}}, rt)
+ a.configBeforeWake(context.WithValue(context.Background(), wakeFallbackKey{}, WakePlan{}), &actEntry{}, rt)
+ if asked != 0 {
+ t.Fatalf("asked %d times for a pinned wake and a fallback pass", asked)
+ }
+ a.configBeforeWake(context.Background(), &actEntry{}, rt)
+ if asked != 1 {
+ t.Fatalf("asked %d times for an ordinary wake, want 1", asked)
+ }
+ a.ConfigBeforeWake = nil
+ a.configBeforeWake(context.Background(), &actEntry{}, rt) // no hook: nothing to call
+}
diff --git a/internal/appconfig/syncexec.go b/internal/appconfig/syncexec.go
index 3098af7e4..21ed2ce1a 100644
--- a/internal/appconfig/syncexec.go
+++ b/internal/appconfig/syncexec.go
@@ -650,7 +650,7 @@ func SyncExecWithCallbacks(ctx context.Context, reg *registry.Registry, s releas
hostCallbacks.Delivered = nil
}
}
- err := syncExecHostClaimed(ctx, selected[rt.Host], rt, m, Key(k.acct, k.app), priv, dataDir, hostBounce, header, instETag, ack, hostCallbacks)
+ err := syncExecHostMaking(ctx, o.makeDir && !hostWrites.Enabled, selected[rt.Host], rt, m, Key(k.acct, k.app), priv, dataDir, hostBounce, header, instETag, ack, hostCallbacks)
// A nested row's bundle lives in its instance directory, which the
// activator makes at the first wake. Before then the write cannot
// land, so the row is named and the pass goes on to the other
@@ -786,6 +786,7 @@ type syncOptions struct {
fenced func(host string) bool
keep func(rt registry.Route) bool
dirAbsent func(host, dir string)
+ makeDir bool
outcome func(host string, done bool)
hostWrites hostwrite.Config
hostWriteCount int
@@ -816,6 +817,20 @@ func WhenInstanceDirAbsent(dirAbsent func(host, dir string)) SyncOption {
return func(o *syncOptions) { o.dirAbsent = dirAbsent }
}
+// MakeInstanceDir makes SyncExec create a nested row's instance directory
+// when the row has a bundle to write and the directory is not there, in
+// place of naming the row and leaving it (WhenInstanceDirAbsent). It is for
+// the pass a wake runs before it plans (the agent's configBeforeWake): that
+// wake's prepare would make the same directory, with the same mode, a
+// moment later, and by then its first process has started without the
+// bundle. The directory is made only when there are bytes to put in it: a
+// row whose bundle renders nothing leaves no directory behind. Every other
+// pass leaves the directory to the activator, as before. Not under host
+// writes: there the row is named and left, as before.
+func MakeInstanceDir() SyncOption {
+ return func(o *syncOptions) { o.makeDir = true }
+}
+
func WithHostWrite(cfg hostwrite.Config) SyncOption {
return func(o *syncOptions) {
o.hostWrites = cfg
@@ -1384,6 +1399,28 @@ func syncExecHostClaimed(ctx context.Context, work hostwrite.Work, rt registry.R
return nil
}
+// syncExecHostMaking is syncExecHostClaimed for a pass that may make a
+// nested row's instance directory (MakeInstanceDir; makeDir false is
+// syncExecHostClaimed alone). The wake that runs such a pass is about to
+// make this directory itself, so it is made here, as the activator's
+// prepare makes it (os.MkdirAll, 0700), and the write is tried once more.
+// The absent answer comes back only from the write, before anything is
+// delivered, restarted or acknowledged, so nothing runs twice. A directory
+// that cannot be made leaves the absent answer standing, and the pass names
+// the row and goes on as it does without the option.
+func syncExecHostMaking(ctx context.Context, makeDir bool, work hostwrite.Work, rt registry.Route, m *Manifest, key string, priv *ecdh.PrivateKey, dataDir string, bounce func(host string) error, header, instETag string, ack func(ConfigAck), callbacks Callbacks) error {
+ err := syncExecHostClaimed(ctx, work, rt, m, key, priv, dataDir, bounce, header, instETag, ack, callbacks)
+ if !makeDir || !errors.Is(err, errInstanceDirAbsent) {
+ return err
+ }
+ dir := filepath.Dir(ConfigEnvPath(dataDir, rt))
+ if mkErr := os.MkdirAll(dir, 0o700); mkErr != nil {
+ fmt.Printf(" %s: make instance directory %s: %v\n", rt.Host, dir, mkErr)
+ return err
+ }
+ return syncExecHostClaimed(ctx, work, rt, m, key, priv, dataDir, bounce, header, instETag, ack, callbacks)
+}
+
// errInstanceDirAbsent is a nested row's write that found no instance
// directory: the activator has not woken the instance here yet.
var errInstanceDirAbsent = errors.New("the instance directory is not made yet")
diff --git a/internal/appconfig/syncexec_makedir_test.go b/internal/appconfig/syncexec_makedir_test.go
new file mode 100644
index 000000000..337f3319b
--- /dev/null
+++ b/internal/appconfig/syncexec_makedir_test.go
@@ -0,0 +1,90 @@
+package appconfig
+
+import (
+ "os"
+ "path/filepath"
+ "testing"
+
+ "github.com/carlosframework/platform/internal/provision"
+ "github.com/carlosframework/platform/internal/registry"
+)
+
+// MakeInstanceDir is the option of the pass a wake runs before it plans: a
+// nested row with a bundle to write and no instance directory gets the
+// directory, with the mode the activator's prepare gives it, and its file.
+// The same pass without the option names the row and leaves the directory
+// to the activator, as every other pass does. Nothing is restarted or
+// acknowledged twice for the write that needed a second try.
+func TestSyncExecMakeInstanceDirWritesANestedRowWithNoDirectory(t *testing.T) {
+ ctx, s, reg, dd, priv, _ := execKit(t)
+ pk, err := ParsePrivateKey(priv, "test")
+ if err != nil {
+ t.Fatalf("ParsePrivateKey: %v", err)
+ }
+ if err := SetEnv(ctx, s, "bab", "eleven", map[string]string{"LOG_LEVEL": "debug"}); err != nil {
+ t.Fatalf("SetEnv: %v", err)
+ }
+ host := "inst.example.com"
+ if err := reg.Upsert(registry.Route{
+ Host: host, Kind: "instance", App: "eleven", Account: "bab",
+ Status: "ready", DBPath: provision.NestedDBPath(dd, host), Socket: provision.NestedSocket(host),
+ }); err != nil {
+ t.Fatalf("Upsert: %v", err)
+ }
+ dir := provision.InstanceDir(dd, host)
+ var bounced, absent, acks int
+ bounce := func(string) error { bounced++; return nil }
+ ack := func(ConfigAck) { acks++ }
+ waits := WhenInstanceDirAbsent(func(string, string) { absent++ })
+
+ if err := SyncExec(ctx, reg, s, pk, dd, bounce, "", ack, waits); err != nil {
+ t.Fatalf("SyncExec: %v", err)
+ }
+ if _, err := os.Lstat(dir); !os.IsNotExist(err) {
+ t.Fatalf("a pass without the option made the instance directory (err %v)", err)
+ }
+ if absent != 1 || bounced != 0 || acks != 0 {
+ t.Fatalf("without the option: absent %d, bounced %d, acks %d; want the row named once and nothing else", absent, bounced, acks)
+ }
+
+ absent = 0
+ done := map[string]bool{}
+ if err := SyncExec(ctx, reg, s, pk, dd, bounce, "", ack, waits, MakeInstanceDir(),
+ WithHostOutcome(func(h string, ok bool) { done[h] = ok })); err != nil {
+ t.Fatalf("SyncExec: %v", err)
+ }
+ got, err := os.ReadFile(filepath.Join(dir, host+".config.env"))
+ if err != nil || string(got) != "LOG_LEVEL=debug\n" {
+ t.Fatalf("config env = %q, %v, want LOG_LEVEL=debug", got, err)
+ }
+ if fi, err := os.Stat(dir); err != nil || fi.Mode().Perm() != 0o700 {
+ t.Fatalf("instance directory = %v, %v, want 0700", fi, err)
+ }
+ if absent != 0 || bounced != 1 || acks != 1 || !done[host] {
+ t.Fatalf("with the option: absent %d, bounced %d, acks %d, done %v; want one delivery, reported done", absent, bounced, acks, done[host])
+ }
+}
+
+// A bundle that renders nothing has nothing to put in a directory, so the
+// option makes none: an instance of an app with no settings leaves no
+// directory behind for a wake that may yet be refused.
+func TestSyncExecMakeInstanceDirMakesNothingForAnEmptyBundle(t *testing.T) {
+ ctx, s, reg, dd, priv, _ := execKit(t)
+ pk, err := ParsePrivateKey(priv, "test")
+ if err != nil {
+ t.Fatalf("ParsePrivateKey: %v", err)
+ }
+ host := "inst.example.com"
+ if err := reg.Upsert(registry.Route{
+ Host: host, Kind: "instance", App: "eleven", Account: "bab",
+ Status: "ready", DBPath: provision.NestedDBPath(dd, host), Socket: provision.NestedSocket(host),
+ }); err != nil {
+ t.Fatalf("Upsert: %v", err)
+ }
+ if err := SyncExec(ctx, reg, s, pk, dd, nil, "", nil, MakeInstanceDir()); err != nil {
+ t.Fatalf("SyncExec: %v", err)
+ }
+ if _, err := os.Lstat(provision.InstanceDir(dd, host)); !os.IsNotExist(err) {
+ t.Fatalf("a directory was made with no bundle to put in it (err %v)", err)
+ }
+}
diff --git a/internal/host/agent.go b/internal/host/agent.go
index b453edb7d..b63270e8d 100644
--- a/internal/host/agent.go
+++ b/internal/host/agent.go
@@ -771,6 +771,10 @@ func runAgent(args []string, buildClaims ClaimFactory) {
// store that failed to start refuses every spawn (never "run
// unrecorded"). Set before Start, like Routes.
svc.BeforeExec = sandboxExecGate(sandboxEffective, sandboxErr, reg.Get, eb.ConfigGate, demoPolicyHook(os.Getenv, reg, eb.Control, buildStateHook(bs, bsErr)))
+ // An instance's config file is in place before its wake is planned
+ // (configbeforewake.go), so a new instance's first process is the
+ // configured one. Set before Start, like Routes.
+ svc.ConfigBeforeWake = configBeforeWake(reg, dd, claims.Writes)
// The held wake check (settings spec §4.3 rule 3): a held instance
// never wakes on an installed build other than its target. The copy
// is refreshed before every wake that could be held (wakeTarget), and
@@ -2002,7 +2006,7 @@ func configSyncLoop(reg *registry.Registry, svc *activator.Service, dd string, w
// next hourly pass. Serializing in-process closes that outright; the root
// adopt path is a different process writing a different namespace
// (/etc/carlos/apps) and is not this mutex's problem.
-var configSyncMu sync.Mutex
+var configSyncMu = make(passLock, 1)
// syncExecSerialized is the one way either config loop runs SyncExec — the
// mutex lives in a shared wrapper, not at the call sites, so a future third
@@ -2018,32 +2022,7 @@ func syncExecSerialized(ctx context.Context, reg *registry.Registry, store relea
func syncExecSerializedFiltered(ctx context.Context, keep func(registry.Route) bool, reg *registry.Registry, store release.Store, priv *ecdh.PrivateKey, dd string, svc *activator.Service, writes ...hostwrite.Config) error {
configSyncMu.Lock()
defer configSyncMu.Unlock()
- pending := map[string]string{}
- outcomes := map[string]bool{}
- opts := []appconfig.SyncOption{
- appconfig.SkipFenced(func(host string) bool { return layout.JournalPresent(dd, host) }),
- appconfig.WhenInstanceDirAbsent(func(host, dir string) { pending[host] = dir }),
- appconfig.WithHostOutcome(func(host string, done bool) { outcomes[host] = done }),
- }
- if keep != nil {
- opts = append(opts, appconfig.WithRouteFilter(keep))
- }
- for _, cfg := range writes {
- opts = append(opts, appconfig.WithHostWrite(cfg))
- }
- // CARLOS_SWAP=overlap: the scheduler restarts, paced, and acknowledges a
- // revision once it is active; refusing: no restart. configSyncMu above
- // is what makes ConfigDelivered serial per host.
- var err error
- if cb, ok := rolloutConfigCallbacks(ctx, store, configLegs{awake: managedAwake(svc, reg), restart: bounce(svc)}); ok {
- err = appconfig.SyncExecWithCallbacks(ctx, reg, store, priv, dd, os.Getenv("PLATFORM_APPS_DOMAIN"), cb, opts...)
- } else {
- err = appconfig.SyncExec(ctx, reg, store, priv, dd, bounce(svc), os.Getenv("PLATFORM_APPS_DOMAIN"), configAckFunc(ctx, store, "agent"), opts...)
- }
- // A filtered pass names only the routes it kept, so it is never
- // complete: a host it left out keeps its wait (pendingDirs.record).
- configDirsPending.record(pending, outcomes, err == nil && keep == nil)
- return err
+ return syncExecLocked(ctx, keep, reg, store, priv, dd, configLegs{awake: managedAwake(svc, reg), restart: bounce(svc)}, nil, writes...)
}
// configDirsPending is what the last config pass could not write because a
diff --git a/internal/host/configbeforewake.go b/internal/host/configbeforewake.go
new file mode 100644
index 000000000..c3cfaef1c
--- /dev/null
+++ b/internal/host/configbeforewake.go
@@ -0,0 +1,220 @@
+package host
+
+import (
+ "context"
+ "crypto/ecdh"
+ "log"
+ "os"
+ "sync"
+ "time"
+
+ "github.com/carlosframework/platform/internal/appconfig"
+ "github.com/carlosframework/platform/internal/hostwrite"
+ "github.com/carlosframework/platform/internal/layout"
+ "github.com/carlosframework/platform/internal/registry"
+ "github.com/carlosframework/platform/internal/release"
+)
+
+// Config before the first process (production, 2026-11-24). A new instance's
+// first generation started without its app config and was swapped for a
+// configured one about twelve seconds later ("config change"): requests in
+// between reached a process that had none of its settings.
+//
+// Two things made that window. A nested row's <host>.config.env lives in its
+// instance directory, which the activator makes at the first wake (prepare),
+// so the config pass that ran before the wake had nowhere to write and only
+// came back once the directory was there (configDirsPending), after the
+// spawn had read the file. And a wake that beats the first config pass to a
+// new route, nested or flat, finds no file at all.
+//
+// So the wake asks first. The activator calls configBeforeWake before it
+// plans a wake (activator.Service.ConfigBeforeWake). A route whose file is
+// already there costs one Lstat, and one a config pass has already settled
+// with no file (an app with no settings) one map read more. Any other gets
+// a config pass of its own, narrowed to that host, which makes the instance
+// directory if the bundle needs it (appconfig.MakeInstanceDir). The planner
+// then snapshots the revision that pass delivered and the spawn reads the
+// file, so the first generation is the configured one and its healthy event
+// activates the revision: nothing is left to restart for.
+//
+// This is not the fetch-at-spawn the exec config delivery design turned
+// down (2026-08-02-exec-config-delivery-design.md §6: bucket latency and
+// availability in the wake path, no file on disk to debug). The file on
+// disk stays the one thing a spawn reads; the bucket is read inside a wake
+// only when no pass has yet settled that host's file, which is a new
+// instance's first wake, and a read that fails or runs long costs that wake
+// nothing but the old behaviour.
+//
+// Best effort, on purpose. The hook cannot refuse a wake. A pass that fails,
+// or does not get the config lock inside its budget, leaves the wake exactly
+// as it was before the hook existed, and the config loops deliver and
+// restart as they always have. The gate that does refuse a wake whose
+// config this box cannot provide is the config guard (configguard.go), asked
+// later, at the lease.
+
+// passLock is a mutex a caller can stop waiting for: Lock, Unlock and
+// TryLock as sync.Mutex has them, for the config passes, and lockContext
+// for a wake's own pass, which gives up when its budget ends rather than
+// hold a request behind a long pass.
+type passLock chan struct{}
+
+func (l passLock) Lock() { l <- struct{}{} }
+func (l passLock) Unlock() { <-l }
+
+func (l passLock) TryLock() bool {
+ select {
+ case l <- struct{}{}:
+ return true
+ default:
+ return false
+ }
+}
+
+// lockContext takes the lock, or returns ctx's error once ctx is done.
+func (l passLock) lockContext(ctx context.Context) error {
+ select {
+ case l <- struct{}{}:
+ return nil
+ case <-ctx.Done():
+ return ctx.Err()
+ }
+}
+
+// configBeforeWakeBudget bounds what a wake spends on its config: the wait
+// for the config lock and the narrowed pass together. A narrowed pass is a
+// few bucket reads; the wait is as long as a full pass that happens to be
+// running. Past the budget the wake goes on without waiting.
+const configBeforeWakeBudget = 5 * time.Second
+
+// wakeConfigLegs are the restart legs of a wake's own config pass. The
+// instance is inside the wake that asked, so nothing is restarted and
+// nothing counts as awake: the wake about to spawn is what reads the file,
+// which is exactly "delivered on wake". A managed instance does not come
+// through these: the scheduler hears the delivery (ConfigDelivered) and the
+// wake's own healthy event activates it.
+var wakeConfigLegs = configLegs{
+ awake: func(string) bool { return false },
+ restart: func(string) error { return appconfig.ErrDeliveredOnWake },
+}
+
+// configSettled is the hosts whose config file the last pass to name them
+// left as it resolved it: written, up to date, or rightly absent
+// (appconfig.WithHostOutcome). A wake of one of them has nothing to ask the
+// bucket. A host a pass left undone (its instance directory not made yet,
+// its bundle unread) is not in it, nor is one no pass has named: those are
+// the wakes that run a pass of their own.
+var configSettled settledHosts
+
+type settledHosts struct {
+ mu sync.Mutex
+ hosts map[string]bool
+}
+
+// record keeps one pass's outcomes. A complete pass named every host that
+// takes a config file, so a host it did not name is gone (its row deleted,
+// or no longer a shape that takes one) and is forgotten: a host created
+// again under the same name is asked about afresh. A narrowed or failed
+// pass only updates the hosts it named.
+func (s *settledHosts) record(outcomes map[string]bool, complete bool) {
+ s.mu.Lock()
+ defer s.mu.Unlock()
+ if complete || s.hosts == nil {
+ s.hosts = map[string]bool{}
+ }
+ for host, done := range outcomes {
+ if done {
+ s.hosts[host] = true
+ } else {
+ delete(s.hosts, host)
+ }
+ }
+}
+
+func (s *settledHosts) has(host string) bool {
+ s.mu.Lock()
+ defer s.mu.Unlock()
+ return s.hosts[host]
+}
+
+// syncExecLocked is one SyncExec pass under configSyncMu, which the caller
+// holds. legs are the pass's restart legs: the activator's for the config
+// loops, a wake's own for the pass it runs before it plans
+// (configBeforeWake). more are that caller's further options.
+func syncExecLocked(ctx context.Context, keep func(registry.Route) bool, reg *registry.Registry, store release.Store, priv *ecdh.PrivateKey, dd string, legs configLegs, more []appconfig.SyncOption, writes ...hostwrite.Config) error {
+ pending := map[string]string{}
+ outcomes := map[string]bool{}
+ opts := []appconfig.SyncOption{
+ appconfig.SkipFenced(func(host string) bool { return layout.JournalPresent(dd, host) }),
+ appconfig.WhenInstanceDirAbsent(func(host, dir string) { pending[host] = dir }),
+ appconfig.WithHostOutcome(func(host string, done bool) { outcomes[host] = done }),
+ }
+ if keep != nil {
+ opts = append(opts, appconfig.WithRouteFilter(keep))
+ }
+ opts = append(opts, more...)
+ for _, cfg := range writes {
+ opts = append(opts, appconfig.WithHostWrite(cfg))
+ }
+ // CARLOS_SWAP=overlap: the scheduler restarts, paced, and acknowledges a
+ // revision once it is active; refusing: no restart. configSyncMu, which
+ // the caller holds, is what makes ConfigDelivered serial per host.
+ var err error
+ if cb, ok := rolloutConfigCallbacks(ctx, store, legs); ok {
+ err = appconfig.SyncExecWithCallbacks(ctx, reg, store, priv, dd, os.Getenv("PLATFORM_APPS_DOMAIN"), cb, opts...)
+ } else {
+ err = appconfig.SyncExec(ctx, reg, store, priv, dd, legs.restart, os.Getenv("PLATFORM_APPS_DOMAIN"), configAckFunc(ctx, store, "agent"), opts...)
+ }
+ // A filtered pass names only the routes it kept, so it is never
+ // complete: a host it left out keeps its wait (pendingDirs.record).
+ configDirsPending.record(pending, outcomes, err == nil && keep == nil)
+ configSettled.record(outcomes, err == nil && keep == nil)
+ return err
+}
+
+// configBeforeWake is the agent's activator.Service.ConfigBeforeWake. The
+// key and the store are the armed config guard's: the guard read
+// CARLOS_SECRETS_KEY once and keeps the deploy store it opened, and it is
+// asked about this same wake at the lease. A box with no guard, no usable
+// key or no store has no config to deliver, and the hook does nothing.
+func configBeforeWake(reg *registry.Registry, dd string, writes hostwrite.Config) func(context.Context, registry.Route) {
+ return func(ctx context.Context, rt registry.Route) {
+ g := armedConfigGuard.Load()
+ if g == nil || g.priv == nil {
+ return
+ }
+ deliverConfigBeforeWake(ctx, rt, reg, g.deployStore, g.priv, dd, writes)
+ }
+}
+
+// deliverConfigBeforeWake is configBeforeWake's body, with the store and
+// the key handed in. A route that takes no config file of its own on this
+// box (needsBoxConfig), one whose file is already there, and one a pass has
+// settled with no file (configSettled) are left alone: the config loops own
+// every later change to them. Lstat only: a nested row's file is on ground
+// its tenant can write, and nothing here follows or opens it.
+func deliverConfigBeforeWake(ctx context.Context, rt registry.Route, reg *registry.Registry, openStore func(context.Context) (release.Store, error), priv *ecdh.PrivateKey, dd string, writes hostwrite.Config) {
+ if !needsBoxConfig(rt) {
+ return
+ }
+ if _, err := os.Lstat(appconfig.ConfigEnvPath(dd, rt)); err == nil || configSettled.has(rt.Host) {
+ return
+ }
+ ctx, cancel := context.WithTimeout(ctx, configBeforeWakeBudget)
+ defer cancel()
+ store, err := openStore(ctx)
+ if err != nil {
+ // The config guard refuses this wake at the lease if the store
+ // stays unreadable, and says so; nothing to add here.
+ return
+ }
+ if err := configSyncMu.lockContext(ctx); err != nil {
+ log.Printf("agent: %s: its config was not checked before its wake (a config pass held the lock past the wake's budget of %s); config sync delivers it", rt.Host, configBeforeWakeBudget)
+ return
+ }
+ defer configSyncMu.Unlock()
+ host := rt.Host
+ only := func(r registry.Route) bool { return r.Host == host }
+ if err := syncExecLocked(ctx, only, reg, store, priv, dd, wakeConfigLegs, []appconfig.SyncOption{appconfig.MakeInstanceDir()}, writes); err != nil {
+ log.Printf("agent: %s: config before its wake: %v; config sync delivers it", host, err)
+ }
+}
diff --git a/internal/host/configbeforewake_test.go b/internal/host/configbeforewake_test.go
new file mode 100644
index 000000000..1b45fb9e5
--- /dev/null
+++ b/internal/host/configbeforewake_test.go
@@ -0,0 +1,234 @@
+package host
+
+import (
+ "context"
+ "crypto/ecdh"
+ "os"
+ "path/filepath"
+ "testing"
+
+ "github.com/carlosframework/platform/internal/appconfig"
+ "github.com/carlosframework/platform/internal/hostwrite"
+ "github.com/carlosframework/platform/internal/provision"
+ "github.com/carlosframework/platform/internal/registry"
+ "github.com/carlosframework/platform/internal/release"
+)
+
+// wakeConfigKit is a box with one app that has settings, and a nested
+// hibernating instance of it that has never woken: no instance directory.
+type wakeConfigKit struct {
+ ctx context.Context
+ store release.Store
+ reg *registry.Registry
+ dd string
+ rt registry.Route
+ priv *ecdh.PrivateKey
+ opens int
+ deliver
+}
+
+type deliver func(ctx context.Context, rt registry.Route)
+
+func newWakeConfigKit(t *testing.T, vars map[string]string) *wakeConfigKit {
+ t.Helper()
+ configDirsPending = pendingDirs{}
+ configSettled.record(nil, true)
+ t.Cleanup(func() { configDirsPending = pendingDirs{}; configSettled.record(nil, true) })
+ k := &wakeConfigKit{ctx: context.Background(), store: release.NewDirStore(t.TempDir()), reg: restartTestRegistry(t), dd: t.TempDir()}
+ privText, _, err := appconfig.GenerateKey()
+ if err != nil {
+ t.Fatal(err)
+ }
+ priv, err := appconfig.ParsePrivateKey(privText, "test")
+ if err != nil {
+ t.Fatal(err)
+ }
+ k.priv = priv
+ if vars != nil {
+ if err := appconfig.SetEnv(k.ctx, k.store, "bab", "shop", vars); err != nil {
+ t.Fatal(err)
+ }
+ }
+ host := "shop.example.com"
+ k.rt = registry.Route{Host: host, Kind: "instance", App: "shop", Account: "bab", Hibernate: true,
+ Status: "ready", DBPath: provision.NestedDBPath(k.dd, host), Socket: provision.NestedSocket(host)}
+ if err := k.reg.Upsert(k.rt); err != nil {
+ t.Fatal(err)
+ }
+ open := func(context.Context) (release.Store, error) { k.opens++; return k.store, nil }
+ k.deliver = func(ctx context.Context, rt registry.Route) {
+ deliverConfigBeforeWake(ctx, rt, k.reg, open, priv, k.dd, hostwrite.Config{})
+ }
+ return k
+}
+
+func (k *wakeConfigKit) cfgPath() string {
+ return filepath.Join(provision.InstanceDir(k.dd, k.rt.Host), k.rt.Host+".config.env")
+}
+
+// Production, 2026-11-24: a new instance's first generation ran without its
+// app config and was restarted onto it twelve seconds later. Its config
+// file lives in its instance directory, which only the first wake made, so
+// the config pass before the wake had nowhere to write. Asked before the
+// wake is planned, the agent makes the directory as prepare would and
+// writes the bundle, so the spawn that follows reads it.
+func TestConfigBeforeWakeWritesANewNestedInstancesConfig(t *testing.T) {
+ k := newWakeConfigKit(t, map[string]string{"WOODSTAR_WORLD": "https://woodstar.app"})
+ // The pass every loop runs leaves the directory to the activator and
+ // writes nothing: the state the wake used to start from.
+ if err := syncExecSerialized(k.ctx, k.reg, k.store, k.priv, k.dd, nil, hostwrite.Config{}); err != nil {
+ t.Fatal(err)
+ }
+ if _, err := os.Lstat(provision.InstanceDir(k.dd, k.rt.Host)); !os.IsNotExist(err) {
+ t.Fatalf("an ordinary pass made the instance directory (err %v)", err)
+ }
+
+ k.deliver(k.ctx, k.rt)
+
+ b, err := os.ReadFile(k.cfgPath())
+ if err != nil || string(b) != "WOODSTAR_WORLD=https://woodstar.app\n" {
+ t.Fatalf("before the wake, the bundle = %q, %v: the first process would start without its config", b, err)
+ }
+ if fi, err := os.Stat(provision.InstanceDir(k.dd, k.rt.Host)); err != nil || fi.Mode().Perm() != 0o700 {
+ t.Fatalf("the instance directory = %v, %v, want 0700 as prepare makes it", fi, err)
+ }
+ // Delivered, so the generation loop has nothing left to come back for:
+ // no second pass, and so no restart onto a file the wake already read.
+ if h, ok := configDirsPending.appeared(); ok {
+ t.Fatalf("%s is still waited for after its config was delivered", h)
+ }
+ // The ack says what happened: delivered for the wake, nothing restarted.
+ ack, err := appconfig.LatestConfigAck(k.ctx, k.store, k.rt.Host)
+ if err != nil || ack == nil {
+ t.Fatalf("config ack = %v, %v", ack, err)
+ }
+ if ack.Restarted || !ack.Hibernating || ack.RestartError != "" {
+ t.Fatalf("config ack = %+v, want delivered on wake with no restart", *ack)
+ }
+}
+
+// A file that is already there costs the wake one Lstat: no store, no lock,
+// no pass. The config loops own every later change to it.
+func TestConfigBeforeWakeLeavesAnExistingFileToTheLoops(t *testing.T) {
+ k := newWakeConfigKit(t, map[string]string{"WOODSTAR_WORLD": "https://woodstar.app"})
+ if err := os.MkdirAll(provision.InstanceDir(k.dd, k.rt.Host), 0o700); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.WriteFile(k.cfgPath(), []byte("OLD=1\n"), 0o600); err != nil {
+ t.Fatal(err)
+ }
+ configSyncMu.Lock() // a pass is running: the wake must not wait for it
+ defer configSyncMu.Unlock()
+ k.deliver(k.ctx, k.rt)
+ if k.opens != 0 {
+ t.Fatalf("the store was opened %d times for a file that exists", k.opens)
+ }
+ if b, _ := os.ReadFile(k.cfgPath()); string(b) != "OLD=1\n" {
+ t.Fatalf("the existing file was rewritten: %q", b)
+ }
+}
+
+// An app with no settings has nothing to deliver: no file, and no
+// directory left behind for a wake that may yet be refused. Its file stays
+// absent for good, so the pass that found that out is the last one a wake
+// runs for it: later wakes read nothing from the bucket.
+func TestConfigBeforeWakeAsksOnceForAnAppWithNoConfig(t *testing.T) {
+ k := newWakeConfigKit(t, nil)
+ k.deliver(k.ctx, k.rt)
+ if _, err := os.Lstat(provision.InstanceDir(k.dd, k.rt.Host)); !os.IsNotExist(err) {
+ t.Fatalf("a directory was made for an instance with no config (err %v)", err)
+ }
+ if k.opens != 1 {
+ t.Fatalf("the first wake opened the store %d times, want 1", k.opens)
+ }
+ k.deliver(k.ctx, k.rt)
+ k.deliver(k.ctx, k.rt)
+ if k.opens != 1 {
+ t.Fatalf("later wakes of a settled host opened the store (%d opens in all)", k.opens)
+ }
+}
+
+// What the config loops' own passes find out counts too. A pass that left
+// a host's file rightly absent settles it, so its wake asks nothing; a pass
+// that could not write for want of the instance directory leaves it
+// unsettled, and that wake is the one that asks. Once the app has settings
+// the settled host is unsettled again by the pass that could not write them.
+func TestConfigBeforeWakeFollowsWhatThePassesSettled(t *testing.T) {
+ k := newWakeConfigKit(t, nil)
+ pass := func() {
+ t.Helper()
+ if err := syncExecSerialized(k.ctx, k.reg, k.store, k.priv, k.dd, nil, hostwrite.Config{}); err != nil {
+ t.Fatal(err)
+ }
+ }
+ pass()
+ k.deliver(k.ctx, k.rt)
+ if k.opens != 0 {
+ t.Fatalf("a host the boot pass settled cost its wake %d store opens", k.opens)
+ }
+ if err := appconfig.SetEnv(k.ctx, k.store, "bab", "shop", map[string]string{"WOODSTAR_WORLD": "https://woodstar.app"}); err != nil {
+ t.Fatal(err)
+ }
+ pass() // no instance directory: named, left undone
+ k.deliver(k.ctx, k.rt)
+ if b, err := os.ReadFile(k.cfgPath()); err != nil || string(b) != "WOODSTAR_WORLD=https://woodstar.app\n" {
+ t.Fatalf("the bundle = %q, %v: a host a pass left undone was not asked about at its wake", b, err)
+ }
+}
+
+// A complete pass that no longer names a host forgets it, so an instance
+// deleted and created again under the same name is asked about afresh.
+func TestConfigSettledForgetsAHostACompletePassDoesNotName(t *testing.T) {
+ var s settledHosts
+ s.record(map[string]bool{"a": true, "b": true}, true)
+ s.record(map[string]bool{"c": true, "b": false}, false) // narrowed: only what it named
+ if !s.has("a") || s.has("b") || !s.has("c") {
+ t.Fatalf("after a narrowed pass: a %v, b %v, c %v; want a and c settled, b not", s.has("a"), s.has("b"), s.has("c"))
+ }
+ s.record(map[string]bool{"c": true}, true)
+ if s.has("a") || !s.has("c") {
+ t.Fatalf("after a complete pass without a: a %v, c %v", s.has("a"), s.has("c"))
+ }
+}
+
+// A route that takes no config file of its own on this box is not looked
+// at: a unit-backed route's config is the root pass's.
+func TestConfigBeforeWakeSkipsARouteWithNoBoxConfig(t *testing.T) {
+ k := newWakeConfigKit(t, map[string]string{"WOODSTAR_WORLD": "https://woodstar.app"})
+ rt := k.rt
+ rt.Backing = registry.BackingUnit
+ k.deliver(k.ctx, rt)
+ if k.opens != 0 {
+ t.Fatalf("the store was opened %d times for a unit-backed route", k.opens)
+ }
+}
+
+// The hook never holds a wake behind a config pass past its budget: with
+// the lock held and the wake's context done, it returns having written
+// nothing, and the wake goes on as it did before the hook existed.
+func TestConfigBeforeWakeGivesUpWhenAPassHoldsTheLock(t *testing.T) {
+ k := newWakeConfigKit(t, map[string]string{"WOODSTAR_WORLD": "https://woodstar.app"})
+ configSyncMu.Lock()
+ defer configSyncMu.Unlock()
+ ctx, cancel := context.WithCancel(k.ctx)
+ cancel()
+ k.deliver(ctx, k.rt)
+ if _, err := os.Lstat(provision.InstanceDir(k.dd, k.rt.Host)); !os.IsNotExist(err) {
+ t.Fatalf("the hook wrote without the config lock (err %v)", err)
+ }
+}
+
+// With no armed guard, or a guard with no usable key, the agent's hook does
+// nothing: such a box has no config to deliver.
+func TestConfigBeforeWakeNeedsTheArmedGuardsKey(t *testing.T) {
+ k := newWakeConfigKit(t, map[string]string{"WOODSTAR_WORLD": "https://woodstar.app"})
+ armConfigGuard(nil)
+ t.Cleanup(func() { armConfigGuard(nil) })
+ hook := configBeforeWake(k.reg, k.dd, hostwrite.Config{})
+ hook(k.ctx, k.rt)
+ armConfigGuard(newConfigGuard(func(string) string { return "" }, func(context.Context) (release.Store, error) { return k.store, nil }))
+ hook(k.ctx, k.rt)
+ if _, err := os.Lstat(provision.InstanceDir(k.dd, k.rt.Host)); !os.IsNotExist(err) {
+ t.Fatalf("a keyless box delivered config (err %v)", err)
+ }
+}
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv
index f4add2d9e..e6ab0a884 100644
--- a/internal/provision/testdata/plan14-root-reads-chain.tsv
+++ b/internal/provision/testdata/plan14-root-reads-chain.tsv
@@ -287,3 +287,4 @@ plan14-root-reads-store-versioning.tsv 841361b89e20c3763149e8784cdebb037dcc4b828
plan14-root-reads-parent-delegation-1383.tsv 841361b89e20c3763149e8784cdebb037dcc4b828b24196a01d3e300ff319661
plan14-root-reads-alias-publish-precert-1293.tsv c25a6eac6ece70098b052b6451deff684c29ff8cfcd24ba37625f01028dedf88
plan14-root-reads-domain-transfers.tsv c25a6eac6ece70098b052b6451deff684c29ff8cfcd24ba37625f01028dedf88
+plan14-root-reads-instance-ready-before-wake.tsv e06c8d16caf860ee2044fd8856fb27c2a824e9546b765d938173cd319a7ede50
diff --git a/internal/provision/testdata/plan14-root-reads-instance-ready-before-wake.tsv b/internal/provision/testdata/plan14-root-reads-instance-ready-before-wake.tsv
new file mode 100644
index 000000000..da496315b
--- /dev/null
+++ b/internal/provision/testdata/plan14-root-reads-instance-ready-before-wake.tsv
@@ -0,0 +1,20 @@
+# Census overlay instance-ready-before-wake, written by census-propose (#369). census-ruling-instance-ready-before-wake, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-instance-ready-before-wake.md.
+# 3 body, 1 sites, 3 envelope: each changed unit re-frozen at its existing disposition with its claim appended.
+# 4 new dispositions: 0 reads re-frozen at their disposition with the claim, 4 new units frozen accepted-legacy, 0 quiet units retired while they read nothing, 0 other.
+@legacy 69c82e9c6c26b4c26eb90c0ff6bf71b3adf55952aecfa0dac726f0415e9f73a4 internal/appconfig/syncexec.go SyncExecWithCallbacks legacy accepted-legacy accepted-legacy;rev3=census-ruling-moves-offline-fixes;basis=route-and-input (J1,J4, main's disposition); the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos), through syncExecSerialized: main's body, with a nested row whose write found no instance directory named and skipped (errInstanceDirAbsent, WhenInstanceDirAbsent) instead of failing the pass, and each in-scope host reported done or not done (WithHostOutcome) once the pass has gone through every route; no new read site;rev3=PROPOSED-s3-change-index;identity=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos);basis=the scoped pass's route filter (WithRouteFilter, syncOptions.kept) is checked in its three route loops, so a route the filter leaves out is out of scope before anything is read for it; three whole-Route sites added, each passing rt to kept; no bucket or file read added;rev3=census-ruling-team-scoped-credentials;basis=team-scoped credentials (#449 §3): checkOptedIn's default-bundle thunk answers no default bundle for an OWNED environment bundle, so its exec_delivery is its own and never inherited; the same bundle reads as before, no read site added;rev3=census-ruling-named-unit-delivery-114;basis=the stale-file notice loop gains the stamped case: os.Stat of ConfigEnvPath(dataDir, rt), the path the exec-addr case already stats, and a notice line; no write, no new path;rev3=census-ruling-design-console-secrets;basis=the <host>.config collision set is built by routeHostSet (shared with the classifier) instead of inline; same rows read, same skip; no read site added;rev3=census-ruling-instance-ready-before-wake;basis=the agent as carlos, through syncExecLocked: the per-host call is now syncExecHostMaking with the pass MakeInstanceDir option (false under host writes). With the option off, which every config loop pass and the root pass leave it, the body is as before. No new read site. file:Stat@28864,file:Stat@30093,registry:App@10524,registry:App@10739,registry:App@16285,registry:App@28744,registry:Environment@10532,registry:Environment@10747,registry:Environment@16293,registry:Environment@28752,registry:Host@1031,registry:Host@1066,registry:Host@15793,registry:Host@16120,registry:Host@16218,registry:Host@17050,registry:Host@17401,registry:Host@18336,registry:Host@18877,registry:Host@21804,registry:Host@22021,registry:Host@22599,registry:Host@22779,registry:Host@22788,registry:Host@22807,registry:Host@25741,registry:Host@26358,registry:Host@26410,registry:Host@26566,registry:Host@29261,registry:Host@30411,registry:Host@866,registry:Host@937,whole:Route@10294,whole:Route@10352,whole:Route@10417,whole:Route@10478,whole:Route@10519,whole:Route@10636,whole:Route@10670,whole:Route@10734,whole:Route@1434,whole:Route@15705,whole:Route@15755,whole:Route@16280,whole:Route@25304,whole:Route@25751,whole:Route@26455,whole:Route@28612,whole:Route@28634,whole:Route@28692,whole:Route@28739,whole:Route@28844,whole:Route@29302,whole:Route@30073,whole:Route@30652,whole:Route@30725,whole:Route@693,whole:Route@721,whole:Route@750,whole:Route@776,whole:Route@811 fd973880272eb949a799ff2b447290ba922c3a70f6fc691ae41405232507deb7
+@legacy c678d81e80f6592471c9eb6541dbd0b12df9b0f2f60e6e104641027a54e93bd3 internal/activator/configbeforewake.go Service.configBeforeWake legacy accepted-legacy accepted-legacy;rev3=census-ruling-instance-ready-before-wake;basis=new, the agent as carlos: calls the ConfigBeforeWake hook with the wake route, unless the hook is nil, the wake is a hold swap pinned wake (e.pin) or a fallback second pass (wakeFallbackKey). Reads only in-memory state and the route already in hand. whole:Route@258 6399df728bf3a5703f46d56e0bcda13a3b2490f39b6d9d57637658ef7136e3ec
+@legacy 2c39ad99c9e89191d44291ffbc3f8bdfd0d2849f6aaaea089eb56900f2ade531 internal/appconfig/syncexec.go syncExecHostMaking legacy accepted-legacy accepted-legacy;rev3=census-ruling-instance-ready-before-wake;basis=new, the agent as carlos: syncExecHostClaimed, and when the pass asked for it (MakeInstanceDir, set only by the agent own pass before a wake) and the write found no instance directory, os.MkdirAll of provision.InstanceDir(dataDir, host) at 0700, the same call and mode the activator prepare makes at that wake, then the same write once more. A write under /data by the agent, never root. The registry Host and Route reads are the row the pass already holds. registry:Host@607,whole:Route@309,whole:Route@494,whole:Route@683 7aed70f5c1f2cfbf428e1cea4a0f19bd9f5b315bdfb9b2854741b6b56575d60b
+@legacy 63832e4201c26a585011e3be94e893685adaea7313302f1d66c135f11862fb42 internal/host/configbeforewake.go configBeforeWake legacy accepted-legacy accepted-legacy;rev3=census-ruling-instance-ready-before-wake;basis=new, the agent as carlos: the hook runAgent sets. Takes the key and the deploy store from the armed config guard (the same key the config loops parse from CARLOS_SECRETS_KEY) and calls deliverConfigBeforeWake. Does nothing without a guard or a usable key. whole:Route@286 f8f7bf9e9f39049554cffab1069675efffd18f27968bdfad9d582f5f0753528f
+@legacy b0bc0fb29d4709cd0804bafffd73b24baeb66e4776ccecd7f4b6e1699f4b44d4 internal/host/configbeforewake.go deliverConfigBeforeWake legacy accepted-legacy accepted-legacy;rev3=census-ruling-instance-ready-before-wake;basis=new, the agent as carlos: for a route that takes a config file on this box (needsBoxConfig), one os.Lstat of its own config path under /data (appconfig.ConfigEnvPath, never followed or opened). When the file is absent and no pass has settled the host, one SyncExec pass narrowed to that host under configSyncMu, bounded by a 5s budget, with MakeInstanceDir and no restart leg. The registry Host reads are the route the activator handed in. Not reachable from root: only the agent wake path calls it. file:Lstat@262,registry:Host@337,registry:Host@832,registry:Host@915,registry:Host@969,whole:Route@230,whole:Route@299 95feddde3413f6c15123d4a09a1a9f1794aecd154b6e8384fbe62054719541c2
+@legacy 5b0b3da8648fed2cc1fd2323209a1d2aadad19cc7bb60da32fc83150e86495a8 internal/activator/activator.go Service.doWakeOnce legacy accepted-legacy accepted-legacy;rev3=census-ruling-stateless-replicas-1;basis=Task 3a: The former doWake body, not deleted logic: refresh/admit/fence/layout checks remain. Select and verify the actual staged identity before serving Acquire; use canonical mode to call doStatelessWake. Keep SQLite acquire/restore/seed/marker/replicate only in the stateful arm, with the post-acquisition selection recheck and existing cleanup proofs. Fix 3a round 1 I1/I3a: admit config directly only for stateless and mark runtime ownership refusals. Stateful Acquire/Restore precede selection and pending publication; canonical mode inspection is separate, replan precedes settlement. Fix round 2 N2/N3: retain the original route/pin projection for post-lease declaration checks; reuse the unplanned capture so a live-link repoint cannot change the selected build. Stateful capture and changed-copy errors remain start failures after Acquire/Restore. A failed preliminary verification supplies no cached mode observation. No new file path or database authority. Final review C1/R26: unprojected stateful wakes capture and materialize the live link only after Acquire and Restore. Retain original route/generation/pin stateless evidence on the context across fallback, so missing stateless evidence cannot take stateful recovery inference. Known good stateful identity skips canonical declaration lookup. Existing pre-exec verification remains. R28 final fix 2: carry whether this wake has a plan in attempt-local context; no new read here; route, generation and pin stateless projection remains intact.;rev3=census-ruling-agent-start-demo-1;basis=Reads IsDemo and demo admission/capability state; chooses local lease retention, skips seed upload and sidecar selection. Existing stop and under-lease ordering retained.;rev3=census-ruling-region-ha-p3a;basis=P3a Task 3: refuse tenant starts under the existing service lock before main's demoWakeRefusal, and recheck before backend Acquire. Retain main's demo refusal and all lease, restore and serialization checks. Two added whole Route uses feed the in-memory admission predicate; no new filesystem or store read.;rev3=census-ruling-stateless-replicas-2;basis=P14: after verified storage-mode selection, before clearing the projected hint or acquiring a database lease, a set row still on the stateful branch returns ErrFenced. Reads the existing route FleetBoxes field only. Verified stateless wakes take their existing branch; legacy rows remain unchanged. No new file, registry query or bucket read. merge of origin/main 9b8b2c50: retain wake-slot and HA duty logic alongside the replica stateful-start refusal; no gate removed. merge of origin/main 6be08467: Keep main demo lease, local database and KeepLocal path; never equate replication-disabled demos with stateless generations. Merge-only body/read-site change. merge of origin/main 7920cccf: Retain main tenant admission and startOwnedLocked gates alongside the replica stateful-start refusal; whole Route passed to main admission checks, no new path or store read.;rev3=census-ruling-agent-start-demo-3;basis=Route claim seeds through seed restore/admission; do not fall back to empty boot or ordinary import behavior. Census read-site delta: +registry:SeedSource, +whole:Route.;rev3=census-ruling-region-ha-g2-fixes;basis=Bound recovery Acquire by its attempt deadline; existing acquire/restore/start ordering remains; no new read.;rev3=census-ruling-g6-fence;basis=G6 F-C Task 3, the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): right after retainDatabase returns, attaches the write-fence watcher under a.mu (watchWriteFenceLocked, in memory). retainDatabase is called through a retainDB test seam that is nil in production. No read added; no root call; existing acquire, restore, publisher and cleanup order unchanged.;rev3=census-ruling-sr-followups;basis=#1061 Task 1, the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): a refused plan now returns planRefusal(host, plan) instead of the inline fmt.Errorf, the text is unchanged, and when the planner marked the plan Installing the error also matches errBuildNotInstalled (installRefusal, in memory). Same refusal at the same point before the lease, read sites unchanged, no read, file, store, bucket or root call added;rev3=census-ruling-replica-wake-gap;basis=Step 2c: before the seed and the spawn, asks the lease to ProtectStart(rt.DBPath), the route's own database path already used by Restore and retainDatabase; a refusal gives the lease back and starts nothing. Agent code (user carlos); no root call, no new store or file read here.;rev3=census-ruling-replica-wake-gap-ch;basis=Step 2c's body moved unchanged into protectBeforeStart (replicatebeforestart.go); doWakeOnce passes the whole Route it already holds and returns the error. No read added; the DBPath read moved with the body.;rev3=census-ruling-instance-ready-before-wake;basis=the agent as carlos: one call, step 0.69, a.configBeforeWake(ctx, e, rt), after the held wake check and before the planner. It hands the hook the route this wake already holds (the added whole Route site). It returns nothing, so no refusal, lease, restore or spawn ordering changes. registry:DBPath@2071,registry:DBPath@2087,registry:DBPath@2214,registry:DBPath@2225,registry:FleetBoxes@12276,registry:GoodVersion@18566,registry:Host@1900,registry:Host@1975,registry:Host@2053,registry:Host@2205,registry:Host@2539,registry:Host@4556,registry:Host@6813,registry:Host@949,registry:Replication@17193,registry:Replication@17322,registry:Replication@17341,registry:Replication@17422,registry:Replication@33794,registry:Seed@22478,registry:SeedSource@35254,registry:Socket@2100,registry:Socket@2116,registry:Socket@2239,registry:Socket@2250,registry:Stateless@10336,registry:Stateless@10622,registry:Stateless@11994,registry:Stateless@12324,registry:Stateless@20975,registry:Stateless@9879,registry:Stateless@9970,whole:Route@10408,whole:Route@10567,whole:Route@10946,whole:Route@11044,whole:Route@11135,whole:Route@11267,whole:Route@11390,whole:Route@11444,whole:Route@11716,whole:Route@11892,whole:Route@11896,whole:Route@12683,whole:Route@12958,whole:Route@13276,whole:Route@142,whole:Route@14737,whole:Route@15414,whole:Route@16295,whole:Route@17173,whole:Route@17424,whole:Route@18769,whole:Route@19360,whole:Route@19525,whole:Route@1998,whole:Route@20461,whole:Route@21257,whole:Route@21532,whole:Route@21728,whole:Route@22579,whole:Route@22650,whole:Route@2434,whole:Route@2439,whole:Route@2493,whole:Route@2499,whole:Route@25144,whole:Route@2565,whole:Route@2573,whole:Route@2629,whole:Route@27002,whole:Route@27648,whole:Route@28955,whole:Route@29109,whole:Route@29608,whole:Route@29678,whole:Route@30265,whole:Route@31350,whole:Route@31781,whole:Route@31989,whole:Route@32043,whole:Route@32972,whole:Route@33157,whole:Route@333,whole:Route@33957,whole:Route@34028,whole:Route@34746,whole:Route@34795,whole:Route@35189,whole:Route@35371,whole:Route@3591,whole:Route@36623,whole:Route@36718,whole:Route@3685,whole:Route@3752,whole:Route@37559,whole:Route@4446,whole:Route@6182,whole:Route@6441,whole:Route@6703,whole:Route@6708,whole:Route@6765,whole:Route@6771,whole:Route@6840,whole:Route@6848,whole:Route@7164,whole:Route@7225,whole:Route@729,whole:Route@7323,whole:Route@7633,whole:Route@8534,whole:Route@934,whole:Route@9483,whole:Route@9707,whole:Route@9771,whole:Route@9815 72ca438f2e11c7a6eb14e09c895b481898b0162c786180e1c3fc61272b3392ce
+internal/activator/activator.go type Service authority B,C,D,F,J4 rev3=PROPOSED-seed; existing activator lifecycle and due-wake state plus owned seed exclusion and incarnation-keyed diagnostics; normal refusal and preparation ordering remain authoritative; PROPOSED-plans-2-box-limits adds the idleFor hook field, which only narrows idle windows;rev3=census-ruling-plans-4c-box-throttle;basis=gains the maxRunFor hook field beside idleFor (plans 4c). No read added.;rev3=census-ruling-plans-4d-lapse;basis=gains the disabledFor hook field beside maxRunFor (plans 4d). No read added.;rev3=census-ruling-remote-instance-metrics;basis=gains tenancySeq, hostTenants and hostMixed, in-memory fields for Tenancies; no read added;rev3=census-ruling-region-ha-p1a;basis=the agent as carlos: one more field, markers (markerRetry: an atomic running flag and the last log time) for retryOwedMarkers; no read added; merge of origin/main d7ae1d76: main's fields are kept as main has them (census-ruling-remote-instance-metrics: tenancySeq, hostTenants, hostMixed); this branch's change is the same as above;rev3=census-ruling-rootfs-apps-3;basis=rootfs Plan 3 Tasks 7 and 8: new fields for rootfs admission (rootfsArmed, rootfsSwept), the per-host gate ask and refusal memo, and residency state (lister, backoff, start ceiling, cursor, test seam); no read;rev3=census-ruling-rootfs-apps-3-release;basis=rootfs Plan 3 Group R: one new field, releaseOps (host to the in-memory release record, under a.mu); no read;rev3=census-ruling-rootfs-apps-3-workers;basis=rootfs Plan 3 Group W: one new field, leaseNow (a clock seam for a worker start's headroom against the lease deadline, nil is the real clock); no read;rev3=census-ruling-region-ha-p1b2;basis=region HA P1b-2: gains the holder cache and its single-flight state; no read;rev3=census-ruling-managed-fleets-1b;basis=managed fleets 1b (controller ruling after branch review R1, and Paul's R2 ruling): one field, Fleet (activator.FleetWake: the box's fleet state, not on a fleet by default, on a fleet with a known label and a record reader, or on a fleet with an invalid identity), set by the agent before Start and read only by routeCurrentUnderLease. No read in the declaration. Agent, not root.;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a fix round 1: one field, drainBudget (time.Duration), which New copies from residentDrainBudget and a rootfs entry's lease watch reads in its place, so a test's change of the package var never races a watch goroutine; declaration only, reads nothing; merge of origin/main 6f1f6ca6: main's one field, Fleet (activator.FleetWake), is kept as main has it (census-ruling-managed-fleets-1b); this branch's change is the same as above;rev3=census-ruling-region-ha-p1b3a;basis=Add bounded placement peer and diagnostic state and the over-capacity callback; no read in this declaration and no new root authority.;rev3=census-ruling-stateless-replicas-1;basis=Add coordinator, existing-record observation callback and per-host preparation locks; no read in the declaration. Task 3a: Add optional canonical storage-selection and durable deploy-ID callbacks; declaration only, no read or authority in these fields.;rev3=census-ruling-edge-held-streams;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): adds the heldLegs map to actEntry (legs by id, under a.mu) and heldWakeHook (atomic pointer to a callback) and heldLegSeq (atomic counter) to Service. State only, in memory; no read of tenant, app or box-agent-writable input.;rev3=census-ruling-wake-storm-cap;basis=the agent as carlos: one field, wakeSlots (chan struct{}, the wake semaphore made by New from Config.WakeSlots, default 4); declaration only, no read.;rev3=census-ruling-region-ha-p1b3b-t;basis=Add the B2 DutyStore interface field and process-local duty view, suppression and invalidation state. No read added. B2 adds the verified-successor identity callback; no read in the declaration. B3b adds a nonblocking departure-suspicion callback, invoked only after an accepted holder-forward failure and after cache locks release; it cannot authorize a take.;rev3=census-ruling-region-ha-p3a;basis=P3a Task 3: immutable callbacks installed before Start for tenant admission, local start permission, fixed route exemptions and shutdown closure; nil callbacks preserve switch-off behavior; no new reads. Fix R1: add an immutable startup-phase callback for response copy, set before service startup. No new read or execution authority.;rev3=census-ruling-region-ha-g2-fixes;basis=Add in-memory HA loss state and pool withdrawal jobs; no new read.;rev3=census-ruling-region-ha-held-build;basis=region HA held-requests Task 1: one new field, drain (drainSources: two atomic func pointers for this box's and peers' drain state); no read added. region HA held-requests Task 2: one new field, moves (moveTable: per-host move state, hold counts and admission tickets in memory, under mu); no read added;rev3=census-ruling-held-move-speed;basis=the agent as carlos: one new field, moveStreams (per-host in-memory set of edge.StreamEnd for requests in flight, own mutex), for the move's early stream cut; actEntry gains drainRelease (bool, under a.mu), set by DrainStop; declarations only, no read added;rev3=census-ruling-fix-silent-start-kill-861;basis=#861: two fields, wakeFailMu and wakeFailLogged (per-host in-memory note of the last journalled wake failure); declaration only, no read;rev3=census-ruling-w6-ingress-drain;basis=new field TenantStartsClosed func() bool; when it answers true tenantStartRefusal refuses every start, exempt routes included. Wired only by fixedAdmission.bind to the ingress drain's closed flag. Struct field only; no read added.;rev3=census-ruling-stateless-replicas-4-task2;basis=Task 2: one field, replicaPolicies (host to the newest observed replica deploy and this box label, under mu), set only by SetReplicaDeploy; declaration only, no read.;rev3=census-ruling-stateless-replicas-4-task2-fix1;basis=Task 2 fix round 1: one more in-memory field, replicaFailed (host to the permit whose successor failed here, under mu), so that step only proves what it kept; declaration only, no read.;rev3=census-ruling-stateless-replicas-4-task3f;basis=Task 3F fix round 3 (#511 F11): two hook fields, MarkReplicaRelease and ReplicaReleaseMark (the failure book's per-host release mark on this box's disk). No read site.;rev3=census-ruling-stateless-replicas-4-task5;basis=Task 5 first commit (#511 F11): one in-memory field, heldSeen (host to the last held release attempt, error class and when it was met), under the existing wakeFailMu. Declaration only, no read.;rev3=census-ruling-stateless-replicas-4-merge-main;basis=Merge of main 5fac2ff1: both sides changed it. Main (27d3f501) adds the background atomic.Int64 field that tests wait on; this branch keeps its replica fields. Both kept as-is; no read added.;rev3=census-ruling-stateless-replicas-4-final;basis=#511 final wave item 3: adds replicaSwitched, an in-memory map of the permit each set row switched under (host -> permit key, time, resident flag); no read added; #511 micro-fix P1b: adds replicaNoGen, an in-memory map (host -> permit key and when first seen) that is only the bound's clock for a restarted permit holder with no generation; no read added;rev3=census-ruling-stateless-replicas-4-drill1;basis=#511 drill 1 R20 bound (round 1: clock with start and last seen): one in-memory field, releaseConfigWaits (per host, a stateless release's config wait), under mu; no read;rev3=census-ruling-stateless-replicas-4-r28;basis=R28 review round 2 (#511): one field, retiringCopy, an atomic pointer to the edge's in-memory retired-copy check, handed over by edge.New (SetRetiringCopy); no read, no root decision;rev3=census-ruling-g6-fence;basis=G6 F-C Task 3, the agent as carlos: four fields, fenceWatchers (sync.WaitGroup of running write-fence watchers) and three test seams nil in production (fenceWatchStarted, retainDB, wakeReturned). Declaration only, no read.;rev3=census-ruling-fleet-record-labels-m1;basis=fleet record labels R1/R2: actEntry gains checkpoint state (busy while CloseProven runs, unproven, named-once flag for C45), in-memory under a.mu; the worker gains fence pacing apart from crash backoff; Service gains test seams nil in production; declarations only, no read;rev3=census-ruling-race-activator-1249;basis=adds two test-only fields: leaseWork (a WaitGroup counting lease watches and the one-shot stops a short lease starts) and leaseWatchStop (a channel, nil in production, that a test closes to end every lease watch); no read added and production never waits on or closes either;rev3=census-ruling-fleet-restart-wake;basis=Fleet restart wake Task 1: the per-host journal note maps (wakeFailLogged, heldSeen) move into the embedded wakeNotes struct in wakefaillog.go, which adds fenceSeen. In-memory only; no read added.;rev3=census-ruling-stateless-scale-2-fleet-sizes;basis=the agent (carlos-edge.service, user carlos), not root: one embedded field (#892 S2), fleetSizeService (fleetreserve.go), which holds BoxLabel (string, the rollout's own box label, set by armRollout) and fleetReserve (fleetReservations, ready as its zero value; it reads /proc/meminfo through memAvailable only when a fleet-size overlap reserves), the box's in-memory overlap reservation for fleet sizes. Declaration only; no read added;rev3=census-ruling-instance-ready-before-wake;basis=the agent as carlos: gains the ConfigBeforeWake hook field beside Planner, a func the agent sets before Start. No read added. c6b2d95b304c7c8cfd76186e08bc039983b928196762fbb0ecc3d07f52564e1c
+internal/appconfig/syncexec.go SyncExecWithCallbacks legacy accepted-legacy accepted-legacy;rev3=census-ruling-moves-offline-fixes;basis=route-and-input (J1,J4, main's disposition); the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos), through syncExecSerialized: main's body, with a nested row whose write found no instance directory named and skipped (errInstanceDirAbsent, WhenInstanceDirAbsent) instead of failing the pass, and each in-scope host reported done or not done (WithHostOutcome) once the pass has gone through every route; no new read site;rev3=PROPOSED-s3-change-index;identity=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos);basis=the scoped pass's route filter (WithRouteFilter, syncOptions.kept) is checked in its three route loops, so a route the filter leaves out is out of scope before anything is read for it; three whole-Route sites added, each passing rt to kept; no bucket or file read added;rev3=census-ruling-team-scoped-credentials;basis=team-scoped credentials (#449 §3): checkOptedIn's default-bundle thunk answers no default bundle for an OWNED environment bundle, so its exec_delivery is its own and never inherited; the same bundle reads as before, no read site added;rev3=census-ruling-named-unit-delivery-114;basis=the stale-file notice loop gains the stamped case: os.Stat of ConfigEnvPath(dataDir, rt), the path the exec-addr case already stats, and a notice line; no write, no new path;rev3=census-ruling-design-console-secrets;basis=the <host>.config collision set is built by routeHostSet (shared with the classifier) instead of inline; same rows read, same skip; no read site added;rev3=census-ruling-instance-ready-before-wake;basis=the agent as carlos, through syncExecLocked: the per-host call is now syncExecHostMaking with the pass MakeInstanceDir option (false under host writes). With the option off, which every config loop pass and the root pass leave it, the body is as before. No new read site. file:Stat@28864,file:Stat@30093,registry:App@10524,registry:App@10739,registry:App@16285,registry:App@28744,registry:Environment@10532,registry:Environment@10747,registry:Environment@16293,registry:Environment@28752,registry:Host@1031,registry:Host@1066,registry:Host@15793,registry:Host@16120,registry:Host@16218,registry:Host@17050,registry:Host@17401,registry:Host@18336,registry:Host@18877,registry:Host@21804,registry:Host@22021,registry:Host@22599,registry:Host@22779,registry:Host@22788,registry:Host@22807,registry:Host@25741,registry:Host@26358,registry:Host@26410,registry:Host@26566,registry:Host@29261,registry:Host@30411,registry:Host@866,registry:Host@937,whole:Route@10294,whole:Route@10352,whole:Route@10417,whole:Route@10478,whole:Route@10519,whole:Route@10636,whole:Route@10670,whole:Route@10734,whole:Route@1434,whole:Route@15705,whole:Route@15755,whole:Route@16280,whole:Route@25304,whole:Route@25751,whole:Route@26455,whole:Route@28612,whole:Route@28634,whole:Route@28692,whole:Route@28739,whole:Route@28844,whole:Route@29302,whole:Route@30073,whole:Route@30652,whole:Route@30725,whole:Route@693,whole:Route@721,whole:Route@750,whole:Route@776,whole:Route@811 fd973880272eb949a799ff2b447290ba922c3a70f6fc691ae41405232507deb7
+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.;rev3=census-ruling-stateless-replicas-4-merge-main;basis=Merge of main 5fac2ff1: both sides changed it. Main (01d6ca78, linked-deployments-slice1) starts linkLoop beside tunnelLoop; this branch keeps its replica coordinator wiring. Both kept as-is; no read added.;rev3=census-ruling-stateless-replicas-4-final;basis=#511 final wave item 2: wires the swap worker's drive (armedReplicaDrive, the armed rollout manager's DriveReplicaRelease); no read added;rev3=census-ruling-stateless-replicas-4-merge-main2;basis=Merge of main af871da0 (v0.34.49): both sides changed it. Main (178dcfe5, member-backups-2a) moves the inline duty-view closure into armDutyView/dutyView and starts verifyAssignLoop; its sites drop by registry:Host and whole:Route x2 as main recorded them. This branch keeps its replica coordinator, swap worker and drive wiring. Both kept as-is; no read added.;rev3=census-ruling-stateless-replicas-4-drill3;basis=drill 3 R24: makes one in-memory channel, closes it (once) inside the edge's existing shutdown-started callback after ingress.shutdownStarted, and passes it to tunnelLoop, which drains only a fleet channel name; no read added, same six sites; touches no admission, lease, ingress drain, listener or file; the agent process, no root decision;rev3=census-ruling-edge-ppv2;basis=Agent (uid carlos), not root. memwatchLoop now gets edgeProxyCounters(&demoEdge) (in-process counters, no read). The drain socket's driver is newAgentDrainSocket(ingress, e, os.Getenv), which attaches the edge trust handler only when CARLOS_INGRESS_PROXY_SOURCES in the agent's environment (from the root-owned host.env) parses to a non-empty list; the socket is served when drainSocketServed: a group member or a configured ingress drain (both as before), or a box armed for PROXY protocol (new). The socket's path and agent-user-only permissions are unchanged. Read sites unchanged (6).;rev3=census-ruling-same-box-edge-fence;basis=Agent (uid carlos), not root. One added line: armEdgeFenceStatus(ctl.EdgeFence), beside the existing armExecSandboxStatus, so the layout report can ask root's /ready for the edge fence state over the control socket client the agent already holds. No read added.;rev3=census-ruling-platform-mail-submission;basis=Task 4: sets eb.Mail = mailsubmit.SocketForwarder{} on every box, and eb.MailSwitch to a mailSwitchCache's On that opens the deploy store itself through openDeployStore, retried at most once a minute with an error line until it opens (review round 1, Task 4 P3), armed for the serial-move refresh (armedMailSwitch). Task 6: also sets the ExecBackend's ManifestOf, the same staged-manifest read as TierOf (rt.App and RouteAccount(rt), hence +registry:App and +whole:Route), for the spawn-time check of decision 10, which logs and emits an event and never refuses. Agent, not root. Fable final P2-2: eb.MailSwitch is the cache's State (three-valued: on, off, unknown) in place of On; an unreadable switch is unknown, never off. No read added.;rev3=census-ruling-fleet-drain-followups;basis=P3 (#1008 T9): one call after armChangeIndex, requestBootFullPass(v, &backstopFullDue), which stores true in the existing in-memory backstopFullDue flag only when no record view is armed, so the fast loop runs its existing full pass on its first tick instead of instancesLoop a minute later; armed boxes unchanged. No read added; read sites unchanged (8); agent, not root.;rev3=census-ruling-fleet-first-reconcile-speed;basis=Startup timing log lines only: runDuties builds a step logger (newStartupLog, which reads the in-memory agent start time) and logs one line after the wait on the activator startup latch and after each existing duty before go fastConvergeLoop. One newStartupLog().at line in the edge ready hook before go tunnelLoop. No read added; read sites unchanged (8). Agent, not root.;rev3=census-ruling-ha-1192;basis=sets the group drain driver's departed hook to armedPeerDeparted (the armed departure controller's PeerDeparted: local registry identity + departure journal); no new read;rev3=census-ruling-replica-wake-gap-r3;basis=Calls lease.SetContinuityDir(<data dir>/.continuity) beside the existing obligation store: the agent's own 0700 directory for clean records, outside every instance tree (#1290 round 3). No new read; failure is logged and every start then takes a full image.;rev3=census-ruling-fleet-restart-wake;basis=Fleet restart wake Task 2: cfg.ReplicaRecord = replicaRecordFacts(boxLifetimes, cfg.Record): hands the existing judged record read (haRecordFacts over openDeployStore and boxJudge) as the live read on a lifetime index miss. No read site added here; agent, not root.;rev3=census-ruling-alias-publish-precert-1293;basis=starts edgesFileLoop with one more argument, edgeAcmeDir(os.Getenv, peekAcmeCache(args)): the agent's own -acme-cache flag (already parsed for domainsLoop) or $CARLOS_DATA_DIR/acme; a string computed from the operator's command line and environment, no read. Same 8 read sites.;rev3=census-ruling-instance-ready-before-wake;basis=the agent as carlos: sets svc.ConfigBeforeWake = configBeforeWake(reg, dd, claims.Writes) beside BeforeExec, before Start. Read sites unchanged, offsets moved. file:Exec@22002,file:Open@2191,file:Statfs@58710,registry:App@13299,registry:App@13677,whole:Route@13291,whole:Route@13669,whole:Route@51925 f756b9a4787dec6d9866e6ff0809f3ee92b8536253a5b56c2ccf8f1923564073
+internal/activator/configbeforewake.go Service.configBeforeWake legacy accepted-legacy accepted-legacy;rev3=census-ruling-instance-ready-before-wake;basis=new, the agent as carlos: calls the ConfigBeforeWake hook with the wake route, unless the hook is nil, the wake is a hold swap pinned wake (e.pin) or a fallback second pass (wakeFallbackKey). Reads only in-memory state and the route already in hand. whole:Route@258 6399df728bf3a5703f46d56e0bcda13a3b2490f39b6d9d57637658ef7136e3ec
+internal/appconfig/syncexec.go syncExecHostMaking legacy accepted-legacy accepted-legacy;rev3=census-ruling-instance-ready-before-wake;basis=new, the agent as carlos: syncExecHostClaimed, and when the pass asked for it (MakeInstanceDir, set only by the agent own pass before a wake) and the write found no instance directory, os.MkdirAll of provision.InstanceDir(dataDir, host) at 0700, the same call and mode the activator prepare makes at that wake, then the same write once more. A write under /data by the agent, never root. The registry Host and Route reads are the row the pass already holds. registry:Host@607,whole:Route@309,whole:Route@494,whole:Route@683 7aed70f5c1f2cfbf428e1cea4a0f19bd9f5b315bdfb9b2854741b6b56575d60b
+internal/host/configbeforewake.go configBeforeWake legacy accepted-legacy accepted-legacy;rev3=census-ruling-instance-ready-before-wake;basis=new, the agent as carlos: the hook runAgent sets. Takes the key and the deploy store from the armed config guard (the same key the config loops parse from CARLOS_SECRETS_KEY) and calls deliverConfigBeforeWake. Does nothing without a guard or a usable key. whole:Route@286 f8f7bf9e9f39049554cffab1069675efffd18f27968bdfad9d582f5f0753528f
+internal/host/configbeforewake.go deliverConfigBeforeWake legacy accepted-legacy accepted-legacy;rev3=census-ruling-instance-ready-before-wake;basis=new, the agent as carlos: for a route that takes a config file on this box (needsBoxConfig), one os.Lstat of its own config path under /data (appconfig.ConfigEnvPath, never followed or opened). When the file is absent and no pass has settled the host, one SyncExec pass narrowed to that host under configSyncMu, bounded by a 5s budget, with MakeInstanceDir and no restart leg. The registry Host reads are the route the activator handed in. Not reachable from root: only the agent wake path calls it. file:Lstat@262,registry:Host@337,registry:Host@832,registry:Host@915,registry:Host@969,whole:Route@230,whole:Route@299 95feddde3413f6c15123d4a09a1a9f1794aecd154b6e8384fbe62054719541c2
+internal/activator/activator.go Service.doWakeOnce legacy accepted-legacy accepted-legacy;rev3=census-ruling-stateless-replicas-1;basis=Task 3a: The former doWake body, not deleted logic: refresh/admit/fence/layout checks remain. Select and verify the actual staged identity before serving Acquire; use canonical mode to call doStatelessWake. Keep SQLite acquire/restore/seed/marker/replicate only in the stateful arm, with the post-acquisition selection recheck and existing cleanup proofs. Fix 3a round 1 I1/I3a: admit config directly only for stateless and mark runtime ownership refusals. Stateful Acquire/Restore precede selection and pending publication; canonical mode inspection is separate, replan precedes settlement. Fix round 2 N2/N3: retain the original route/pin projection for post-lease declaration checks; reuse the unplanned capture so a live-link repoint cannot change the selected build. Stateful capture and changed-copy errors remain start failures after Acquire/Restore. A failed preliminary verification supplies no cached mode observation. No new file path or database authority. Final review C1/R26: unprojected stateful wakes capture and materialize the live link only after Acquire and Restore. Retain original route/generation/pin stateless evidence on the context across fallback, so missing stateless evidence cannot take stateful recovery inference. Known good stateful identity skips canonical declaration lookup. Existing pre-exec verification remains. R28 final fix 2: carry whether this wake has a plan in attempt-local context; no new read here; route, generation and pin stateless projection remains intact.;rev3=census-ruling-agent-start-demo-1;basis=Reads IsDemo and demo admission/capability state; chooses local lease retention, skips seed upload and sidecar selection. Existing stop and under-lease ordering retained.;rev3=census-ruling-region-ha-p3a;basis=P3a Task 3: refuse tenant starts under the existing service lock before main's demoWakeRefusal, and recheck before backend Acquire. Retain main's demo refusal and all lease, restore and serialization checks. Two added whole Route uses feed the in-memory admission predicate; no new filesystem or store read.;rev3=census-ruling-stateless-replicas-2;basis=P14: after verified storage-mode selection, before clearing the projected hint or acquiring a database lease, a set row still on the stateful branch returns ErrFenced. Reads the existing route FleetBoxes field only. Verified stateless wakes take their existing branch; legacy rows remain unchanged. No new file, registry query or bucket read. merge of origin/main 9b8b2c50: retain wake-slot and HA duty logic alongside the replica stateful-start refusal; no gate removed. merge of origin/main 6be08467: Keep main demo lease, local database and KeepLocal path; never equate replication-disabled demos with stateless generations. Merge-only body/read-site change. merge of origin/main 7920cccf: Retain main tenant admission and startOwnedLocked gates alongside the replica stateful-start refusal; whole Route passed to main admission checks, no new path or store read.;rev3=census-ruling-agent-start-demo-3;basis=Route claim seeds through seed restore/admission; do not fall back to empty boot or ordinary import behavior. Census read-site delta: +registry:SeedSource, +whole:Route.;rev3=census-ruling-region-ha-g2-fixes;basis=Bound recovery Acquire by its attempt deadline; existing acquire/restore/start ordering remains; no new read.;rev3=census-ruling-g6-fence;basis=G6 F-C Task 3, the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): right after retainDatabase returns, attaches the write-fence watcher under a.mu (watchWriteFenceLocked, in memory). retainDatabase is called through a retainDB test seam that is nil in production. No read added; no root call; existing acquire, restore, publisher and cleanup order unchanged.;rev3=census-ruling-sr-followups;basis=#1061 Task 1, the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): a refused plan now returns planRefusal(host, plan) instead of the inline fmt.Errorf, the text is unchanged, and when the planner marked the plan Installing the error also matches errBuildNotInstalled (installRefusal, in memory). Same refusal at the same point before the lease, read sites unchanged, no read, file, store, bucket or root call added;rev3=census-ruling-replica-wake-gap;basis=Step 2c: before the seed and the spawn, asks the lease to ProtectStart(rt.DBPath), the route's own database path already used by Restore and retainDatabase; a refusal gives the lease back and starts nothing. Agent code (user carlos); no root call, no new store or file read here.;rev3=census-ruling-replica-wake-gap-ch;basis=Step 2c's body moved unchanged into protectBeforeStart (replicatebeforestart.go); doWakeOnce passes the whole Route it already holds and returns the error. No read added; the DBPath read moved with the body.;rev3=census-ruling-instance-ready-before-wake;basis=the agent as carlos: one call, step 0.69, a.configBeforeWake(ctx, e, rt), after the held wake check and before the planner. It hands the hook the route this wake already holds (the added whole Route site). It returns nothing, so no refusal, lease, restore or spawn ordering changes. registry:DBPath@2071,registry:DBPath@2087,registry:DBPath@2214,registry:DBPath@2225,registry:FleetBoxes@12276,registry:GoodVersion@18566,registry:Host@1900,registry:Host@1975,registry:Host@2053,registry:Host@2205,registry:Host@2539,registry:Host@4556,registry:Host@6813,registry:Host@949,registry:Replication@17193,registry:Replication@17322,registry:Replication@17341,registry:Replication@17422,registry:Replication@33794,registry:Seed@22478,registry:SeedSource@35254,registry:Socket@2100,registry:Socket@2116,registry:Socket@2239,registry:Socket@2250,registry:Stateless@10336,registry:Stateless@10622,registry:Stateless@11994,registry:Stateless@12324,registry:Stateless@20975,registry:Stateless@9879,registry:Stateless@9970,whole:Route@10408,whole:Route@10567,whole:Route@10946,whole:Route@11044,whole:Route@11135,whole:Route@11267,whole:Route@11390,whole:Route@11444,whole:Route@11716,whole:Route@11892,whole:Route@11896,whole:Route@12683,whole:Route@12958,whole:Route@13276,whole:Route@142,whole:Route@14737,whole:Route@15414,whole:Route@16295,whole:Route@17173,whole:Route@17424,whole:Route@18769,whole:Route@19360,whole:Route@19525,whole:Route@1998,whole:Route@20461,whole:Route@21257,whole:Route@21532,whole:Route@21728,whole:Route@22579,whole:Route@22650,whole:Route@2434,whole:Route@2439,whole:Route@2493,whole:Route@2499,whole:Route@25144,whole:Route@2565,whole:Route@2573,whole:Route@2629,whole:Route@27002,whole:Route@27648,whole:Route@28955,whole:Route@29109,whole:Route@29608,whole:Route@29678,whole:Route@30265,whole:Route@31350,whole:Route@31781,whole:Route@31989,whole:Route@32043,whole:Route@32972,whole:Route@33157,whole:Route@333,whole:Route@33957,whole:Route@34028,whole:Route@34746,whole:Route@34795,whole:Route@35189,whole:Route@35371,whole:Route@3591,whole:Route@36623,whole:Route@36718,whole:Route@3685,whole:Route@3752,whole:Route@37559,whole:Route@4446,whole:Route@6182,whole:Route@6441,whole:Route@6703,whole:Route@6708,whole:Route@6765,whole:Route@6771,whole:Route@6840,whole:Route@6848,whole:Route@7164,whole:Route@7225,whole:Route@729,whole:Route@7323,whole:Route@7633,whole:Route@8534,whole:Route@934,whole:Route@9483,whole:Route@9707,whole:Route@9771,whole:Route@9815 72ca438f2e11c7a6eb14e09c895b481898b0162c786180e1c3fc61272b3392ce
+@coverage internal/activator 4b478ed51242d58ee81586e20d9c7a7d8f9c64423dd8874ea103d70ff9a952a0
+@coverage internal/appconfig dfd8a1080a4b3a60fa27a7ec640f1886796fb672f3367402e5bcba5cbe16d280
+@coverage internal/host 9bde16be4c8abedcb1fdee63e5f6ae9fc3c71fadca443a376297c796b579d452
diff --git a/internal/rollout/wakeplan_test.go b/internal/rollout/wakeplan_test.go
index b1115d6e3..0544c92a8 100644
--- a/internal/rollout/wakeplan_test.go
+++ b/internal/rollout/wakeplan_test.go
@@ -345,6 +345,39 @@ func TestAWakeActivatesTheConfigItStartedWith(t *testing.T) {
}
}
+// Production, 2026-11-24: a new instance's first generation ran without its
+// config and was swapped for a configured one seconds later ("config
+// change"). The agent now delivers the file inside the wake, before the
+// wake is planned (activator.Service.ConfigBeforeWake). The scheduler hears
+// that delivery while the instance is waking, so it queues a config
+// attempt; the plan made right after carries the revision, and the wake's
+// healthy event activates it. Nothing is left pending, so no swap follows.
+func TestAConfigDeliveredBeforeItsWakeIsPlannedLeavesNoAttempt(t *testing.T) {
+ h := newHarness(t, "a")
+ h.pass()
+ h.act.mu.Lock()
+ delete(h.act.gens, "a")
+ h.act.owned["a"] = true // waking: the activator has an entry, nothing serves yet
+ h.act.mu.Unlock()
+ h.m.ConfigDelivered("a", "sha256:c1")
+ if !h.m.Status().Hosts["a"].ConfigPending {
+ t.Fatal("a delivery to a waking instance queued nothing: the test no longer models the wake")
+ }
+ rt := h.rows.get("a")
+ p := h.m.Plan(context.Background(), rt)
+ if p.ConfigRev != "sha256:c1" {
+ t.Fatalf("plan.ConfigRev = %q: the plan made after the delivery does not carry it", p.ConfigRev)
+ }
+ h.m.OnGen(activator.GenEvent{Kind: activator.GenHealthy, Route: rt, Gen: activator.Gen{Build: "v1", Digest: "sha-v1"},
+ Token: p.Token, ConfigRev: p.ConfigRev})
+ if h.m.Status().Hosts["a"].ConfigPending {
+ t.Fatal("the config the wake started with is still pending: a swap would restart the instance onto it")
+ }
+ if calls, _, _ := h.act.snapshot(); len(calls) != 0 {
+ t.Fatalf("attempts %+v: the wake's own config got a restart", calls)
+ }
+}
+
// Spec §8.1: a sleeping instance needs no config attempt. Its next wake
// starts with the delivered file, and config sync's ack goes out at
// delivery, as today, marked Hibernating.