carlos / platform Public

host: run a fleet box's first full pass on arming, seeds beside it

A fleet box's first reconcile came about 17 s after the agent started
(#964, #1008). The boot full pass now runs as soon as the fast converge
loop has built the moves hold view and the offline keep view, with no
tick sleep. The restart and sidecar wake baselines start first, on
their own goroutine; the runs boot pass, the schedule converge and the
system pointer observe run beside the first tick. The first serial
read waits for the request baselines, so no request is half-taken, and
the legs that read the seeds are wired only once they finish.

Also an env-gated measurement test (CARLOS_MEASURE_STARTUP=1) of the
startup reads over a slow fake door. A door-shaped record walk was
built and reverted (d941a849): it pays only if dev's whole-tree listing
proves slow. The activator startup latch is unchanged.

Astra reviewed each task and the branch (two rounds), Fable the branch;
census approved on #280.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Squashed from fleet-first-reconcile-fix into main.
claude agent, operated by paul@keymail.dev 35b7c2553c6c154ed9ccb920ae19f0110855623d parent ffa47d4
10 files changed, +1,435 −84
  • docs/superpowers/notes/census-proposal-fleet-first-reconcile-speed-4.md +31 −0
  • docs/superpowers/plans/2026-11-15-fleet-first-reconcile.md +98 −0
  • internal/host/agent.go +98 −77
  • internal/host/fastboot.go +209 −0
  • internal/host/fastboot_test.go +532 −0
  • internal/host/restart.go +17 −6
  • internal/host/sidecarwake.go +18 −1
  • internal/host/startupmeasure_e2e_test.go +415 −0
  • internal/provision/testdata/plan14-root-reads-chain.tsv +1 −0
  • internal/provision/testdata/plan14-root-reads-fleet-first-reconcile-speed-4.tsv +16 −0

CI passed — run details

diff --git a/docs/superpowers/notes/census-proposal-fleet-first-reconcile-speed-4.md b/docs/superpowers/notes/census-proposal-fleet-first-reconcile-speed-4.md
new file mode 100644
index 000000000..9cbac367b
--- /dev/null
+++ b/docs/superpowers/notes/census-proposal-fleet-first-reconcile-speed-4.md
@@ -0,0 +1,31 @@
+# Census approval: fleet-first-reconcile-speed-4
+
+Ruling `census-ruling-fleet-first-reconcile-speed-4`. The independent reviewer approves or rejects every change below, 3 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26).
+
+| unit | change | read sites | what changed |
+|---|---|---|---|
+| `internal/host/agent.go` `fastConvergeLoop` | body | unchanged (1) | Arming order only (fleet first reconcile Task 4). The moves hold view, the offline view, the restart seed, the sidecar wake seed, the runs boot pass, the arming schedule converge and the arming systemLeg.observe are no longer called here: fastBoot.start runs them (views on this goroutine, then the first tick at once with the seeds beside it). The restart legs, the sidecar wake leg closure (same reg.List + sidecarWakeLeg) and newSystemLeg are built here as before and handed to fastBoot, which gives them to fastDeps once the seeds return, before the second tick. The first tick no longer waits for a tick's sleep. Same calls with the same arguments and keys; no read added; read sites unchanged (1). Agent, not root. |
+| `internal/host/agent.go` `fastTick` | body | unchanged (1) | Startup serial hold (whole-branch review P1). While fastDeps.serialAfter is open (fastBoot closes it when the restart and sidecar wake baselines have read) the tick skips its one ReadSerial of control/serial, so it neither seeds nor acts on a move; the rest of the tick (backstop full pass, index, sweep) is unchanged. A full pass run while held sets fullBeforeSeed, and the seed then sets fullDue once so the backstop branch runs one more full pass under the clamp. Same read, read sites unchanged (1); no read added. Agent, not root. |
+| `internal/host/restart.go` `restartSeed` | body | unchanged (1) | List-error log line moved into logRestartListError (same text); body otherwise unchanged (reg.List then restartBaseline). Doc comment notes fastBoot calls it on the seeds' goroutine, ahead of the serial seed. No read added; agent, not root. |
+| `internal/host/sidecarwake.go` `sidecarWakeSeed` | body | unchanged (1) | Body split: reg.List, then sidecarWakeBaseline (the former rest of the body, unchanged); list-error log line moved into logSidecarWakeListError (same text). No read added; agent, not root. |
+
+Envelopes re-pinned: `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/host/agent.go` `fastConvergeLoop`: authority, task B3. Basis: rev3=census-ruling-self-serve-moves-1;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): every pass context carries the box's lifetime judge (provision.WithLifetimes) and the reconcile config is boxProvisionConfig's; read sites unchanged, offsets moved; B3 authority retained;rev3=census-ruling-fleet-public-routes;basis=fleet public routes (spec 2026-10-29 rev 4, §4.2 writer rule): Task 12: its pass config is now BoxProvisionConfig(reg, os.Getenv, judge, configure) (BoxProvisionConfig replaces boxProvisionConfig: the hub predicate hubArmed and, on the hub, ReconcileConfig.FleetOwners from hubFleetOwners); a call, no read site; read sites unchanged (2); B3 authority retained.;rev3=census-ruling-stateless-replicas-1;basis=Final review I3: wire the coordinator's nonblocking SignalTick to the existing fast tick. No new timer, polling read or authority.;rev3=census-ruling-region-ha-p3b;basis=Bind systemLeg to the existing cached reader fold and handle a nil leg on groups; names-2 rollback gate runs before artifact/request/marker work. Agent-memory evidence only, no new direct or cloud read and no autonomous group update.;rev3=census-ruling-restart-new-box-gap;basis=restart leg closure moved into armRestartLegs (same reg.List + restartRequestLeg); also wires restartGain; read moved, not added;rev3=census-ruling-agent-start-demo-3;basis=Attach the moved reader to the existing shared change watch and advertise that reader as armed. Census read-site delta: unchanged (2).;rev3=census-ruling-fleet-first-reconcile-speed;basis=Startup timing log lines only (fleet first reconcile Task 1). Logs its entry offset and one line per arming step, then times the first tick. restartSeed, sidecarWakeSeed, refreshMovesHolds, refreshOfflineView and the one arming systemLeg.observe now read through countStore(store), a pass-through wrapper that counts and times each call and forwards it unchanged with the same key; for that observe, systemLeg.store is swapped to the wrapper and restored. For the first tick only, d.store is a fresh countStore(store) wrapper and d.startup a step logger; both are reset to the plain store and nil after the tick. passLegs gets startup. Same calls in the same order, no read added; read sites unchanged (1). Agent, not root.
+- `internal/host/agent.go` `fastTick`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=J1;basis=root-route;rev3=PROPOSED-s3-change-index;identity=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos);basis=observes the change index before any pass (observeIndex), runs the backstop's requested full pass and a scoped pass for moved app scopes (indexTick), and arms the canary pointer gate on the sweep (canaryPointerGate) only on a tick whose own index observation succeeded; read site unchanged, offset moved;rev3=census-ruling-stateless-replicas-1;basis=Call coordinator Tick on the existing tick before convergence; client renews held terms only at the pinned interval. Existing registry read unchanged. Final review I3: signal the owned renewal worker instead of waiting for its sequential console HTTP calls. Existing convergence and record read unchanged.;rev3=census-ruling-region-ha-p3a;basis=Run the optional desired-role reader on the existing tick after observing the armed change index; no new root path or timer, nil reader is unchanged.;rev3=census-ruling-stateless-replicas-2;basis=Slice 3b: signals the owned replica worker on the existing tick; coalesced asynchronous execution, no timer or bucket scan added. merge of origin/main 7920cccf: Retain main box-role reader pass on the existing tick alongside the replica worker signal; merge-only body change, unchanged read sites.;rev3=census-ruling-restart-new-box-gap;basis=calls the optional restartGain hook (restartGainSeed) once per existing tick before the serial read; no new root path, timer or read kind; nil hook is unchanged;rev3=census-ruling-agent-start-demo-3;basis=Refresh moved notices through the shared watch before normal convergence; no new per-box poll. Census read-site delta: unchanged (1).;rev3=census-ruling-stateless-replicas-4-task1;basis=Signals the owned replica swap worker (armedReplicaDeploy.tick) beside the placement worker on the existing tick; coalesced background pass, no timer, no bucket read. Its transitions go through the console's authenticated /deploy.;rev3=census-ruling-platform-mail-submission;basis=Task 4: on a serial move, after the schedule leg, starts the armed mail switch cache's Refresh on its own goroutine (each read bounded at 2 s, overlapping refreshes skipped). It re-reads the app sender records already cached, through the agent's deploy store. Agent, not root; the tick waits on nothing new. Fable final P2-1: on a serial move, before the pass set and the restart leg, calls the armed cache's MarkStale (a counter bump under the cache's mutex; no I/O), so a spawn the move causes reads the switch again, bounded, instead of using an answer from before the move. No read added.;rev3=census-ruling-fleet-first-reconcile-speed;basis=Startup timing log lines only: d.startup.done(<part>) calls between the existing parts and a deferred one after the sweep. d.startup is nil on every tick but the first after agent start, and its methods are then no-ops. No read added, no order change; read site unchanged (1). Agent, not root.
+- `internal/host/restart.go` `restartSeed`: authority, task E1,E3,J1,J4. Basis: fix1-merge-review;basis=Baselines both request logs without applying historical ordinary restarts; signed retry grants remain independently verified.;rev3=census-ruling-restart-new-box-gap;basis=body split: list routes then restartBaseline (the former body, unchanged); the route reads move with it
+- `internal/host/sidecarwake.go` `sidecarWakeSeed`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=J1;basis=root-route
+
+New dispositions, which census-propose wrote and the reviewer checks against the unit's reads and the diff:
+
+- new `internal/host/fastboot.go:fastBoot.seed`: reads +whole:Route; written legacy, accepted-legacy, frozen
+- new `internal/host/fastboot.go:fastBoot.start`: reads +whole:Route; written legacy, accepted-legacy, frozen
+- new `internal/host/sidecarwake.go:sidecarWakeBaseline`: reads +whole:Route; written legacy, accepted-legacy, frozen
+
+Seal: `9206205b2a3bf27b8b85310f4a44f94ef0c5886d85d6e55dbf2f22e073a8af11` → `4eda67fee53800e2cfa4177b954c7f0fce6bdfcfbfe1aa2547ddcec3027b668b`.
+
+Overlay: `internal/provision/testdata/plan14-root-reads-fleet-first-reconcile-speed-4.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`.
diff --git a/docs/superpowers/plans/2026-11-15-fleet-first-reconcile.md b/docs/superpowers/plans/2026-11-15-fleet-first-reconcile.md
index 890eccf66..281471be1 100644
--- a/docs/superpowers/plans/2026-11-15-fleet-first-reconcile.md
+++ b/docs/superpowers/plans/2026-11-15-fleet-first-reconcile.md
@@ -106,3 +106,101 @@ door reads inside reconcile and the moves pass, with S3 cost flat; mint
already-owned records before the moves stage. Deterministic witnesses:
barrier or fake-clock tests showing the first reconcile is not gated by the
seeds or the moves pass.
+
+## Phase 2 tasks (from Task 2's report, task-2-report.md in the SDD workspace)
+
+Local numbers (60 ms/op fake door): ~2 s of reads before the first mint, so
+the dev 17 s is mostly costs a fixed-latency door cannot show. The prime
+suspects: (a) on the door, `provision.listAppSubtree` cannot use ListDirs
+(`release.HasBucketListDirs` is false for the fleetapi store) and falls back
+to `List("apps/")`, which the door maps to the account's whole `apps/<sqid>/`
+subtree (every artifact and log chunk, paged from S3 at the hub; #231
+measured 60 pages for apps/ on the flagship), and `List("accounts/")`, which
+the door pages across every account and filters. Each runs about 4 times
+before the first pass ends (offline view at arming, reconcile, moves, ...).
+(b) the activator startup latch (sweep + Recover) before the duties start
+(cannot be measured locally; dev numbers after the next release).
+
+### Task 3: door-shaped record walk
+
+Goal: on a fleet box, every record walk lists only what it needs over the
+door: the account's app directories, then each app's `instances/` (or the
+`sub` the caller asks for), never the whole `apps/<sqid>/` subtree, and never
+an unscoped `accounts/` listing that the door pages across the platform.
+
+1. Read `provision.listAppSubtree`, `readAllRecordsJudged` and every caller of
+ `List("apps/")` / `List("accounts/")` on the paths a fleet box runs in its
+ first pass and at arming (offline view, reconcile record scan, moves pass,
+ snapshot build in recordview_store.go). Read the door's `serveListing`,
+ `aclListScope` and `aclDir` (internal/edge/storedoor.go) to learn exactly
+ what `/store/dirs` answers for `apps/`, `apps/<acct>/`,
+ `apps/<acct>/<app>/` and `accounts/` from a fleet box.
+2. Make the walk use the door's delimiter listing in the shape the door
+ really answers. Preferred: a capability the fleetapi store declares (an
+ optional interface in `release`, like `BucketListDirs`) that says "ListDirs
+ works per known account", and a walk branch that lists
+ `apps/<acct>/` for each known account, then `<app>/<sub>` per app, with
+ the existing bounded concurrency (`forEach`). Same for the `accounts/`
+ listing if it is on the path: list only the known accounts' prefixes.
+ Keep the fallback for stores that declare nothing. Do not change the
+ door server unless step 1 shows it cannot answer a needed shape; if it
+ must change, it must stay compatible with old boxes, and a NEW box must
+ work against an OLD hub (the walk runs before any hub upgrade in a roll):
+ prove the old hub already answers what the new box asks.
+3. Results must be identical: the same set of keys/records as the full
+ listing, for records, partial-walk reporting and errors (a failed listing
+ still marks the pass partial, never "no records"). Test with the real
+ fleetapi client against the real door handler (there are door tests in
+ internal/edge and internal/host fleetbind_door_test.go to copy setup
+ from), over a fixture with artifacts and log chunks under the app: assert
+ the key set equals the full listing's and that no listing is made of a
+ whole app subtree (count requests by path and prefix at the handler).
+4. S3 cost: count the hub's S3 listings before and after for the same
+ fixture; the new walk must not cost more S3 list calls than the old one
+ for an account with at least one artifact (report the numbers).
+5. The census (root-read and record-write) will fail for changed units:
+ run `make census-card`, write a CLAIMS file, `make census-propose
+ NAME=fleet-first-reconcile-speed-2 CLAIMS=<file>`; the controller gets
+ it approved.
+
+### Task 4: the first pass runs when the loop arms, seeds off its path
+
+Goal: the first full pass starts as soon as `fastConvergeLoop` has built
+what that pass needs, not after every seed and a tick's sleep.
+
+1. Keep before the first pass, in order: `refreshMovesHolds` (moves spec
+ §9.4: an unbuilt view freezes every host) and `refreshOfflineView`
+ (movesoffline.go: keep answers false only once read), and whatever else
+ the pass's legs read (d.restart, d.passOpts, legs). Every other pre-arm
+ step (`restartSeed`, `armRestartLegs`, `sidecarWakeSeed`,
+ `runRunsBootPass`, `sd.converge`, `systemLeg.observe`, heldHolds'
+ pointer loop) moves after the first pass or runs concurrently, ONLY if
+ its own doc comment's guarantee still holds. In particular restartSeed
+ and sidecarWakeSeed must establish their baseline before the first serial
+ MOVE is acted on (the serial is seeded by the first tick, and the restart
+ and wake legs ride only a serial move), and restartGain must not treat a
+ route minted by the first pass as a request. Read each seed's doc comment
+ and say in the report, per seed, why its guarantee holds in the new order.
+2. Run the boot full pass immediately on arming (the requested boot pass,
+ `requestBootFullPass`, today waits for the first tick's sleep), then
+ enter the tick loop. The pass runs on the loop goroutine as today; no new
+ goroutine may run a pass concurrently with the tick.
+3. Witness tests (deterministic, barriers or a fake clock, no sleeps): (a)
+ the first reconcile starts before restartSeed, sidecarWakeSeed,
+ sd.converge and systemLeg.observe finish (block each on a barrier; the
+ reconcile must still run); (b) the first reconcile does not start before
+ refreshMovesHolds and refreshOfflineView have returned; (c) a restart
+ request already in the store at boot is still not replayed, and one
+ written after the seed is acted on at the next serial move. Use test
+ seams that already exist where possible; a new seam is a package-level
+ func var defaulting to production.
+4. Census as Task 3 (NAME=fleet-first-reconcile-speed-4).
+
+### Parked
+
+- Offline view built from reconcile's own scan (saves one walk, ~0.8 s at
+ 39 records locally): revisit after Task 3, whose fix makes each walk cheap.
+- The activator startup latch: needs the dev numbers from the next release
+ (Task 1's "duties: wait for the activator startup" line). The latch is a
+ safety order (sweep before wakes and before reconcile acts on seeded
+ records); any change gets its own task and review.
diff --git a/internal/host/agent.go b/internal/host/agent.go
index c1e2d5ae6..838c77eab 100644
--- a/internal/host/agent.go
+++ b/internal/host/agent.go
@@ -2925,6 +2925,31 @@ type fastDeps struct {
// (startuptiming.go); nil on every other tick, where its calls do
// nothing.
startup *startupSteps
+
+ // serialAfter holds the serial unread, and so unseeded, until it is
+ // closed: fastBoot closes it when the request baselines have read, so a
+ // request they take as history has its serial bump taken as history too
+ // (fastBoot's comment). nil: no hold.
+ serialAfter <-chan struct{}
+ // fullBeforeSeed is set when a full pass ran on a tick whose serial was
+ // held: the seed asks for one more full pass, for whatever the bumps it
+ // absorbed carried while that pass was running.
+ fullBeforeSeed bool
+}
+
+// serialHeld reports whether this tick must leave the serial unread
+// (serialAfter still open), and drops the hold once it has opened.
+func (d *fastDeps) serialHeld() bool {
+ if d.serialAfter == nil {
+ return false
+ }
+ select {
+ case <-d.serialAfter:
+ d.serialAfter = nil
+ return false
+ default:
+ return true
+ }
}
// canaryRead is one canary group's last good pointer read: the head it
@@ -3346,6 +3371,10 @@ func logSlow(what string, start time.Time, detail string) {
// is deferred by NOT recording the acted serial, so the next tick past
// the window re-fires. Read errors are tolerated silently (one log
// line per state change, never per tick).
+// At startup the read waits for fastBoot's request baselines
+// (serialAfter): until they have read, a tick reads no serial, so it
+// neither seeds nor moves, and a full pass it runs meanwhile is run once
+// more after the seed.
// The restart leg (issue #113) rides that same move, AFTER the pass set:
// a bump can carry a promote and a restart request at once, and cycling
// processes before their new version and config land would cycle them onto
@@ -3397,9 +3426,17 @@ func fastTick(ctx context.Context, d *fastDeps, now time.Time) {
}
d.startup.done("restart gain")
fullRan := false
- doc, _, err := release.ReadSerial(ctx, d.store)
- d.startup.done("serial read")
+ held := d.serialHeld()
+ var doc release.SerialDoc
+ var err error
+ if !held {
+ doc, _, err = release.ReadSerial(ctx, d.store)
+ d.startup.done("serial read")
+ }
switch {
+ case held:
+ // fastBoot's request baselines have not read yet: no seed, no move.
+ d.startup.done("serial held for the request baselines")
case err != nil:
if !d.serialBroken {
log.Printf("agent: fast converge serial read: %v", err)
@@ -3416,6 +3453,13 @@ func fastTick(ctx context.Context, d *fastDeps, now time.Time) {
// must not act on (adoptLoop's 1-minute first pass covers boot).
d.lastSerial, d.seeded = doc.Serial, true
d.serialBroken = false
+ // A full pass that ran while the serial was held may have missed
+ // what the bumps behind this seed carried: one more, under the
+ // clamp, as the backstop's request runs.
+ if d.fullBeforeSeed && d.fullDue != nil {
+ d.fullDue.Store(true)
+ }
+ d.fullBeforeSeed = false
default:
d.serialBroken = false
if doc.Serial != d.lastSerial && now.Sub(d.lastFull) >= fastFullClamp {
@@ -3491,6 +3535,7 @@ func fastTick(ctx context.Context, d *fastDeps, now time.Time) {
d.runFull(ctx)
fullRan = true
d.lastFull = now
+ d.fullBeforeSeed = d.fullBeforeSeed || held
d.startup.done("full pass")
}
// An index-only change runs the scoped pass (spec §4.5).
@@ -3701,12 +3746,14 @@ func (d *fastDeps) indexTick(ctx context.Context, now time.Time, obs map[string]
// its new binary, not wait for hibernation. Nil is fine.
//
// Thin and untested by convention, like adoptLoop/statusLoop — the tick's
-// whole decision lives in fastTick/fastMembers, which are tested.
+// whole decision lives in fastTick/fastMembers, and the order it arms in
+// lives in fastBoot, which are tested.
func fastConvergeLoop(reg *registry.Registry, svc *activator.Service, sd *scheduleDeps, writes hostwrite.Config, serialNotify chan<- struct{}, bs *buildStates, judge *provision.LifetimeJudge, configure ...func(*provision.ReconcileConfig)) {
// Startup timing (startuptiming.go): every step before the loop arms,
- // the first tick and the first full pass each get a line. The seeds
- // read through a counting wrapper (seedStore); what is kept for the
- // loop's life holds the plain store.
+ // the first tick, the seeds beside it and the first full pass each get
+ // a line. The arming views read through a counting wrapper (viewStore),
+ // the seeds through one of their own; what is kept for the loop's life
+ // holds the plain store.
startup := newStartupLog()
startup.at("fast converge loop entered")
arming := startup.steps("arming: ", nil)
@@ -3717,9 +3764,9 @@ func fastConvergeLoop(reg *registry.Registry, svc *activator.Service, sd *schedu
declinedHoldsStay("no deploy store")
return // adoptLoop already logged this
}
- seedStore, seedOps := countStore(store)
+ viewStore, viewOps := countStore(store)
arming.done("deploy store")
- arming.count(seedOps)
+ arming.count(viewOps)
pub, err := release.ParsePublicKey(os.Getenv("CARLOS_RELEASE_PUBKEY"), "CARLOS_RELEASE_PUBKEY")
if err != nil {
declinedHoldsStay("no release key")
@@ -3757,7 +3804,7 @@ func fastConvergeLoop(reg *registry.Registry, svc *activator.Service, sd *schedu
d.mintLeg = (&mintAsker{reg: reg, store: store, sys: systemdUnits{}, optDir: optDir,
policyPath: release.ProofPolicyPath, request: mintRequester(dd), now: time.Now}).tick
// The restart check's memory (issue #113, narrowed requests added by
- // discussion #16), seeded ONCE here — two reads per app at arming (the
+ // discussion #16), seeded ONCE at arming (fastBoot) — two reads per app (the
// app-wide generation and the narrowed request log) and never again except
// on a serial move or for an app the box gains later (restartGainSeed),
// which is what keeps an idle box at exactly one serial GET per tick. See restartSeed for why the baseline cannot wait for the
@@ -3783,49 +3830,20 @@ func fastConvergeLoop(reg *registry.Registry, svc *activator.Service, sd *schedu
})
}
arming.done("held holds")
- restartSeed(ctx, reg, seedStore, dd, restartMem)
- arming.done("restart seed")
// The seed alone is not enough on a fresh box: its agent arms before
// reconcile has minted a route, so the seed sees no apps, and the leg
// runs only on a serial move. The gain hook baselines each app as its
// first route appears (restartGainSeed), so the first `carlos restart`
// after a replacement box comes up is acted on, not taken as the
- // baseline.
+ // baseline. Built here, handed to the loop by fastBoot once the seed
+ // has run.
restartGain, restartLeg := armRestartLegs(reg, store, dd, restartMem, bounceFn(svc), wakeFn(svc))
- arming.done("restart legs")
// The sidecar wake leg's own memory, seeded the same way and for the
// same reason: one silent read per served sidecar at arming so the
// FIRST wake request after a boot is acted on rather than swallowed as
// the baseline (sidecarWakeSeed's own doc comment).
sidecarWakeMem := newSidecarWakeMemory(writes.Enabled)
- sidecarWakeSeed(ctx, reg, seedStore, sidecarWakeMem)
sidecarWake := wakeFn(svc)
- arming.done("sidecar wake seed")
- // The moves hold view, built before the converge below: that converge
- // runs before the first moves pass, and an unbuilt view freezes every
- // host (moves spec §9.4). Nothing with the Phase 1 switch off.
- refreshMovesHolds(ctx, seedStore)
- arming.done("moves holds")
- // The offline keep view, likewise before any reconcile pass: once it is
- // read, keep answers false for every host with no offline move, so the
- // first pass removes what it always has (movesoffline.go).
- refreshOfflineView(ctx, seedStore, armedOfflineView())
- arming.done("offline view")
- // carlos run's boot pass (run spec §5.2, index item 2): reconcile's
- // first pass is a minute away and the CLI expires a run at 60 s.
- runRunsBootPass(ctx)
- arming.done("runs boot pass")
- // The schedule converge's own seed, on restartSeed's precedent and for the
- // same shape of reason: the leg below runs only on a serial MOVE, so
- // without one pass here a box that booted after the bump would carry no
- // timer rows (and report no status) until the hourly floor in adoptLoop —
- // up to an hour of a schedule silently not running. It also seeds the
- // converger's etag memory, which is what makes a run signal older than this
- // process read as history rather than as a fresh request to run.
- if err := sd.converge(ctx); err != nil {
- log.Printf("agent: schedule converge (start): %v", err)
- }
- arming.done("schedule converge")
d.restart = restart
d.passOpts = opts
// The scheduler's pass with CARLOS_SWAP=overlap armed, nothing while
@@ -3859,17 +3877,13 @@ func fastConvergeLoop(reg *registry.Registry, svc *activator.Service, sd *schedu
// (spec §5). Built here, after RunAgent armed the index.
d.canaryGate = newChangeGate()
}
- // The restart leg: this process's own children bounced here, everything
- // unit-shaped relayed to a root pass. Deliberately NOT inside fullPass
- // above — see fastTick's comment for both reasons.
- d.restartLeg = restartLeg
- d.restartGain = restartGain
// The sidecar wake leg: apps/<acct>/<app>/sidecar-wake/<name>.json
- // (release.SidecarWakeKey) compared and dispatched here, riding the
- // same serial move as the restart leg immediately above it — see
- // fastTick's comment for why both must run after fullPass and on a
- // box with no CARLOS_SECRETS_KEY.
- d.wakeLeg = func(ctx context.Context) {
+ // (release.SidecarWakeKey) compared and dispatched on a serial move,
+ // riding the same move as the restart leg — see fastTick's comment for
+ // why both must run after fullPass and on a box with no
+ // CARLOS_SECRETS_KEY. The restart leg is deliberately NOT inside
+ // fullPass either (fastTick's comment). fastBoot hands both to the loop.
+ wakeLeg := func(ctx context.Context) {
routes, err := reg.List()
if err != nil {
log.Printf("agent: sidecar wake check: list routes: %v", err)
@@ -3879,7 +3893,8 @@ func fastConvergeLoop(reg *registry.Registry, svc *activator.Service, sd *schedu
}
// The schedule leg: converge this box's timer rows from the apps'
// declarations. Nil when the box has no scheduled work armed, which
- // fastTick tolerates.
+ // fastTick tolerates. It rides a serial move only, so the first tick
+ // never runs it; the converger's own seed is fastBoot's.
d.scheduleLeg = scheduleLegFor(sd)
// The layout leg: this box's label is the one its status publishes
// under, which is the label an operator scopes a layout request to.
@@ -3890,39 +3905,45 @@ func fastConvergeLoop(reg *registry.Registry, svc *activator.Service, sd *schedu
// ever fetches into /data and writes a request. It lives here rather than
// in a loop of its own because the spread deadline needs a seconds
// cadence to run down on, and this is the loop that already has one.
+ // One observe at arming (fastBoot's seeds), on restartSeed's precedent:
+ // the leg only re-observes on a serial move or at its hourly floor, so a
+ // box that (re)starts under an already-promoted pointer would otherwise
+ // sit on the old build for up to an hour with nobody to bump the serial.
+ // observe handles "no pointer" itself, which is every deployment before
+ // its first `carlos system update`.
+ system := newSystemLeg(store, pub, os.Getenv, dd, optDir)
+ if system != nil {
+ system.readers = cachedGroupReaders
+ }
arming.done("loop wiring")
- d.systemLeg = newSystemLeg(store, pub, os.Getenv, dd, optDir)
- if d.systemLeg != nil {
- d.systemLeg.readers = cachedGroupReaders
- // One observe at arming, on restartSeed's precedent: the leg below only
- // re-observes on a serial move or at its hourly floor, so a box that
- // (re)starts under an already-promoted pointer would otherwise sit on the
- // old build for up to an hour with nobody to bump the serial. observe
- // handles "no pointer" itself, which is every deployment before its first
- // `carlos system update`. Read through the counting wrapper for
- // this one observe only.
- d.systemLeg.store = seedStore
- d.systemLeg.observe(ctx)
- d.systemLeg.store = store
- }
- arming.done("system pointer")
- arming.total("total")
- log.Printf("agent: fast converge loop armed (2s + jitter: serial poll + canary/* + unstaged routes + system pointer)")
- first := true
- for {
- time.Sleep(fastTickEvery + rand.N(time.Second))
- if !first {
- fastTick(ctx, d, time.Now())
- continue
- }
+ // The views, then the first tick at once with the seeds beside it
+ // (fastBoot, which says why each seed's promise holds in that order).
+ // The first tick runs the boot full pass requestBootFullPass asked for,
+ // so on a fleet box the routes a stopped box missed are minted without
+ // waiting for every seed and a tick's sleep. The seeds read through
+ // their own counting store, so their lines and the views' stay apart.
+ seedsStore, seedsOps := countStore(store)
+ boot := &fastBoot{reg: reg, viewStore: viewStore, seedStore: seedsStore, dd: dd, sd: sd,
+ restartMem: restartMem, wakeMem: sidecarWakeMem, system: system,
+ restartGain: restartGain, restartLeg: restartLeg, wakeLeg: wakeLeg,
+ arming: arming, log: startup, seedOps: seedsOps}
+ ready := boot.start(ctx, d, func() {
+ arming.total("total")
+ log.Printf("agent: fast converge loop armed (2s + jitter: serial poll + canary/* + unstaged routes + system pointer)")
// The first tick, timed part by part, its own reads counted.
- first = false
- arming.done("first tick wait")
tickStore, tickOps := countStore(store)
d.store, d.startup = tickStore, startup.steps("first tick: ", tickOps)
fastTick(ctx, d, time.Now())
d.startup.total("total")
d.store, d.startup = store, nil
+ })
+ for {
+ time.Sleep(fastTickEvery + rand.N(time.Second))
+ if ready != nil {
+ ready() // the seeds' legs, before any tick that could act on a serial move
+ ready = nil
+ }
+ fastTick(ctx, d, time.Now())
}
}
diff --git a/internal/host/fastboot.go b/internal/host/fastboot.go
new file mode 100644
index 000000000..ec4ccffe8
--- /dev/null
+++ b/internal/host/fastboot.go
@@ -0,0 +1,209 @@
+package host
+
+import (
+ "context"
+ "log"
+ "sync"
+ "time"
+
+ "github.com/carlosframework/platform/internal/registry"
+ "github.com/carlosframework/platform/internal/release"
+)
+
+// fastBoot is the start of fastConvergeLoop, in the order the first full
+// pass needs (fleet first reconcile, Task 4). The loop's first tick runs the
+// boot full pass (requestBootFullPass), and on a fleet box that pass mints
+// the routes a stopped box missed, so it runs as soon as what it reads is
+// built:
+//
+// 1. The request baselines (restart, then sidecar wake) start first, on a
+// goroutine of their own, over the routes the box serves at arming. They
+// read neither view, so they start before the view walks, where they
+// always ran.
+// 2. The views, on the loop's goroutine: the moves hold view, then the
+// offline keep view. An unbuilt hold view freezes every host (moves spec
+// §9.4), and keep answers false only once the offline view has read a
+// listing (movesoffline.go), so no pass starts before both have returned.
+// The rest of the seeds (the runs boot pass, the schedule converge, the
+// system pointer) follow on the seeds' goroutine once the views are
+// built: the converger reads the hold view (Converger.Frozen).
+// 3. The first tick, at once rather than after a tick's sleep, on the loop's
+// goroutine like every tick. It reads the serial only if the request
+// baselines have finished (fastDeps.serialAfter); otherwise it leaves
+// the serial unseeded and still runs the boot full pass, which needs no
+// serial.
+// 4. ready, which the loop calls before its second tick, on the loop's
+// goroutine: it waits for the seeds, runs one runs pass for what the
+// first tick noted, and only then hands the loop the legs that read the
+// seeds' memories.
+//
+// Why each seed's promise still holds:
+//
+// - The serial is never seeded before the request baselines have read.
+// A request that lands before a baseline reads it is history, and so is
+// its serial bump, which the seed then absorbs: the old order's rule,
+// where both baselines finished before the first tick. Were the serial
+// seeded first, that bump would come back as a move the legs answer
+// from a baseline that already holds the request, and the request would
+// be lost (whole-branch review, Astra P1).
+// - The restart, sidecar wake and schedule legs act only on a serial MOVE,
+// and no tick before ready can see one: the first good serial read only
+// seeds lastSerial (fastTick). ready runs before the second tick, so
+// every baseline exists before the first move is acted on. The two legs
+// that run on every tick and read seeded memory, restartGain and the
+// system leg's tick, are left off the first tick for the same reason.
+// - The sidecar baseline is taken over the route list read before the
+// first pass, never over what that pass leaves. A sidecar the pass mints
+// with a wake already standing at it is the create-then-wake flow, and is
+// woken on the next move (sidecarWakeChanges), not recorded as history.
+// The restart seed lists the routes itself; an app the first pass mints
+// is a baseline whichever of the seed or the second tick's restartGain
+// (restartGainSeed) reads it first, never a request.
+// - A boot full pass that ran while the serial was unseeded is requested
+// once more when the serial is seeded (fastTick), so a change whose bump
+// the seed absorbed while that pass was running is still converged.
+// - The schedule converger and the runs worker already take calls from
+// more than one goroutine and order them themselves: Converger.Pass holds
+// its mutex for the whole pass, and a runs pass that starts before the
+// runs boot pass has finished acts on nothing and keeps reconcile's notes
+// (runsWorker.booted), which ready then takes.
+type fastBoot struct {
+ reg *registry.Registry
+ viewStore release.Store // the views' reads
+ seedStore release.Store // the seeds' reads
+ dd string
+ sd *scheduleDeps
+ restartMem *restartMemory
+ wakeMem *sidecarWakeMemory
+ system *systemLeg // nil: not armed
+
+ // The legs ready hands the loop once the seeds have returned.
+ restartGain func(ctx context.Context, now time.Time)
+ restartLeg func(ctx context.Context)
+ wakeLeg func(ctx context.Context)
+
+ arming *startupSteps // the loop goroutine's arming lines; nil in tests
+ log *startupLog // nil in tests
+ seedOps *storeCounter // seedStore's counter, or nil
+}
+
+// The boot steps, production by default. Tests replace them to hold one
+// step on a barrier or to record the order the steps ran in. The request
+// baselines are called directly (restartSeed is a census authority unit
+// whose production caller must stay visible); bootBeforeBaseline is the
+// tests' hold in front of each, nil in production.
+var (
+ bootBeforeBaseline func(step string)
+ bootMovesHolds = refreshMovesHolds
+ bootOfflineView = func(ctx context.Context, s release.Store) { refreshOfflineView(ctx, s, armedOfflineView()) }
+ bootRunsPass = runRunsBootPass
+ bootRunsNotes = runRunsPass
+ bootSchedule = func(ctx context.Context, sd *scheduleDeps) error { return sd.converge(ctx) }
+ bootSystem = func(ctx context.Context, l *systemLeg) { l.observe(ctx) }
+)
+
+// start runs fastBoot's order: the request baselines started, the views
+// built, then first (the loop's first tick), and returns ready. The loop
+// calls ready before its second tick, and before any other tick: it is what
+// hands the loop the seeded legs.
+func (b *fastBoot) start(ctx context.Context, d *fastDeps, first func()) (ready func()) {
+ // The routes the box serves now, before the first pass mints anything:
+ // the sidecar baseline is taken over this list (fastBoot's comment).
+ routes, listErr := b.reg.List()
+ baselined, viewsBuilt, done := make(chan struct{}), make(chan struct{}), make(chan struct{})
+ go func() {
+ defer close(done)
+ b.seed(ctx, routes, listErr, baselined, viewsBuilt)
+ }()
+ bootMovesHolds(ctx, b.viewStore)
+ b.arming.done("moves holds")
+ bootOfflineView(ctx, b.viewStore)
+ b.arming.done("offline view")
+ close(viewsBuilt)
+ d.serialAfter = baselined
+ first()
+ var once sync.Once
+ return func() {
+ once.Do(func() {
+ wait := b.log.steps("seeds: ", nil)
+ waitSeeds(done)
+ wait.done("second tick wait")
+ // The first tick's runs pass may have run before the runs boot
+ // pass had finished, and then acted on nothing: a run queued after
+ // the boot pass read the records waits in the notes. This pass
+ // acts on them now, rather than at the next full pass.
+ bootRunsNotes(ctx)
+ wait.done("runs notes")
+ d.serialAfter = nil
+ d.restartGain, d.restartLeg, d.wakeLeg, d.systemLeg = b.restartGain, b.restartLeg, b.wakeLeg, b.system
+ })
+ }
+}
+
+// waitSeeds waits for done, saying once in the journal when that has taken
+// longer than slowLegAfter: the loop stands still meanwhile, after "armed".
+func waitSeeds(done <-chan struct{}) {
+ slow := time.NewTimer(slowLegAfter)
+ defer slow.Stop()
+ select {
+ case <-done:
+ return
+ case <-slow.C:
+ log.Printf("agent: fast converge: the second tick is still waiting for the startup seeds after %s", slowLegAfter)
+ }
+ <-done
+}
+
+// seed runs the seeds, in order: the request baselines, then (closing
+// baselined) the rest once viewsBuilt is closed. routes is the list read at
+// arming, nil with listErr when it could not be read. Its own goroutine: it
+// touches nothing the loop reads until the loop has seen baselined (the
+// serial) or ready has waited for it (everything else).
+func (b *fastBoot) seed(ctx context.Context, routes []registry.Route, listErr error, baselined chan<- struct{}, viewsBuilt <-chan struct{}) {
+ steps := b.log.steps("seeds: ", b.seedOps)
+ if bootBeforeBaseline != nil {
+ bootBeforeBaseline("restart seed")
+ }
+ restartSeed(ctx, b.reg, b.seedStore, b.dd, b.restartMem)
+ steps.done("restart seed")
+ if bootBeforeBaseline != nil {
+ bootBeforeBaseline("sidecar wake seed")
+ }
+ // An unread list leaves the wake memory unseeded on purpose
+ // (sidecarWakeSeed): the first leg pass is then the baseline.
+ if listErr != nil {
+ logSidecarWakeListError(listErr)
+ } else {
+ sidecarWakeBaseline(ctx, routes, b.seedStore, b.wakeMem)
+ }
+ steps.done("sidecar wake seed")
+ close(baselined)
+ <-viewsBuilt
+ steps.done("views wait")
+ // carlos run's boot pass (run spec §5.2, index item 2): it must not wait
+ // for a reconcile pass on a box whose first one is a minute away, since
+ // the CLI expires a run at 60 s. A runs pass that starts before it has
+ // finished does nothing and keeps reconcile's notes (runsWorker.booted);
+ // ready runs one more pass for the notes the first tick left.
+ bootRunsPass(ctx)
+ steps.done("runs boot pass")
+ // The schedule converge's own seed, on restartSeed's precedent: the leg
+ // runs only on a serial MOVE, so without one pass here a box that booted
+ // after the bump would carry no timer rows (and report no status) until
+ // the hourly floor in adoptLoop. It also seeds the converger's etag
+ // memory, which is what makes a run signal older than this process read
+ // as history rather than as a fresh request to run.
+ if err := bootSchedule(ctx, b.sd); err != nil {
+ log.Printf("agent: schedule converge (start): %v", err)
+ }
+ steps.done("schedule converge")
+ if b.system != nil {
+ // Read through the seeds' counting store for this one observe only.
+ plain := b.system.store
+ b.system.store = b.seedStore
+ bootSystem(ctx, b.system)
+ b.system.store = plain
+ }
+ steps.done("system pointer")
+ steps.total("total")
+}
diff --git a/internal/host/fastboot_test.go b/internal/host/fastboot_test.go
new file mode 100644
index 000000000..fdd21da43
--- /dev/null
+++ b/internal/host/fastboot_test.go
@@ -0,0 +1,532 @@
+package host
+
+import (
+ "context"
+ "go/ast"
+ "go/parser"
+ "go/token"
+ "slices"
+ "sync"
+ "sync/atomic"
+ "testing"
+ "time"
+
+ "github.com/carlosframework/platform/internal/provision"
+ "github.com/carlosframework/platform/internal/registry"
+ "github.com/carlosframework/platform/internal/release"
+)
+
+// bootFailAfter bounds a wait that only a regression would make long. It
+// never paces a passing run.
+const bootFailAfter = 10 * time.Second
+
+// swapBootSteps replaces every boot step that has a seam with a no-op for
+// the test's life, so a test arms only the steps it names. The request
+// baselines always run (production calls them directly); bootBeforeBaseline
+// is how a test holds one.
+func swapBootSteps(t *testing.T) {
+ t.Helper()
+ holds, offline, before, runs, notes, sched, system := bootMovesHolds, bootOfflineView, bootBeforeBaseline, bootRunsPass, bootRunsNotes, bootSchedule, bootSystem
+ t.Cleanup(func() {
+ bootMovesHolds, bootOfflineView, bootBeforeBaseline, bootRunsPass, bootRunsNotes, bootSchedule, bootSystem = holds, offline, before, runs, notes, sched, system
+ })
+ bootMovesHolds = func(context.Context, release.Store) {}
+ bootOfflineView = func(context.Context, release.Store) {}
+ bootRunsPass = func(context.Context) {}
+ bootRunsNotes = func(context.Context) {}
+ bootSchedule = func(context.Context, *scheduleDeps) error { return nil }
+ bootSystem = func(context.Context, *systemLeg) {}
+}
+
+// bootFixture is a fastBoot over the fast fixture, with the boot full pass
+// requested as requestBootFullPass requests it on a fleet box.
+func bootFixture(t *testing.T, f *fastFixture, fullPass func()) (*fastDeps, *fastBoot) {
+ t.Helper()
+ d := f.deps(fullPass)
+ due := &atomic.Bool{}
+ requestBootFullPass(nil, due)
+ d.fullDue = due
+ mem := newRestartMemory()
+ gain, leg := armRestartLegs(f.reg, f.store, f.dataDir, mem, nil, nil)
+ b := &fastBoot{
+ reg: f.reg, viewStore: f.store, seedStore: f.store, dd: f.dataDir,
+ restartMem: mem, wakeMem: newSidecarWakeMemory(false),
+ restartGain: gain, restartLeg: leg, wakeLeg: func(context.Context) {},
+ }
+ return d, b
+}
+
+// TestFastBootFirstPassDoesNotWaitForTheSeeds is witness (a): with any one
+// seed held on a barrier, the first tick still runs the boot full pass, and
+// the legs that read the seeds' memories reach the loop only once the seeds
+// have returned.
+func TestFastBootFirstPassDoesNotWaitForTheSeeds(t *testing.T) {
+ for _, seed := range []string{"restart seed", "sidecar wake seed", "runs boot pass", "schedule converge", "system pointer"} {
+ t.Run(seed, func(t *testing.T) {
+ swapBootSteps(t)
+ barrier := make(chan struct{})
+ var once sync.Once
+ unblock := func() { once.Do(func() { close(barrier) }) }
+ hold := func() { <-barrier }
+ switch seed {
+ case "restart seed", "sidecar wake seed":
+ bootBeforeBaseline = func(step string) {
+ if step == seed {
+ hold()
+ }
+ }
+ case "runs boot pass":
+ bootRunsPass = func(context.Context) { hold() }
+ case "schedule converge":
+ bootSchedule = func(context.Context, *scheduleDeps) error { hold(); return nil }
+ case "system pointer":
+ bootSystem = func(context.Context, *systemLeg) { hold() }
+ }
+
+ ctx := context.Background()
+ f := newFastFixture(t)
+ reconciled := make(chan struct{}, 4)
+ d, b := bootFixture(t, f, func() { reconciled <- struct{}{} })
+ b.system = &systemLeg{} // armed; its observe is the swapped step
+ readyc := make(chan func(), 1)
+ go func() { readyc <- b.start(ctx, d, func() { fastTick(ctx, d, time.Unix(1762382167, 0)) }) }()
+ var ready func()
+ // Before the fixture's own cleanups: a failing run leaves start
+ // or the seeds blocked; free them and wait them out first.
+ t.Cleanup(func() {
+ unblock()
+ if ready == nil {
+ ready = <-readyc
+ }
+ ready()
+ })
+
+ select {
+ case <-reconciled:
+ case <-time.After(bootFailAfter):
+ t.Fatalf("the first full pass waited for the %s", seed)
+ }
+ ready = <-readyc
+ if d.restartGain != nil || d.restartLeg != nil || d.wakeLeg != nil || d.systemLeg != nil {
+ t.Fatalf("a leg reading a seed's memory reached the loop while the %s was still running", seed)
+ }
+
+ unblock()
+ ready()
+ if d.restartGain == nil || d.restartLeg == nil || d.wakeLeg == nil || d.systemLeg == nil {
+ t.Fatal("ready returned without handing the loop the seeded legs")
+ }
+ })
+ }
+}
+
+// TestFastBootFirstPassWaitsForTheViews is witness (b): the first full pass
+// starts only after the moves hold view and then the offline keep view have
+// returned, and the schedule converge, which reads the hold view, also
+// starts after them.
+func TestFastBootFirstPassWaitsForTheViews(t *testing.T) {
+ swapBootSteps(t)
+ var mu sync.Mutex
+ var order []string
+ note := func(s string) {
+ mu.Lock()
+ order = append(order, s)
+ mu.Unlock()
+ }
+ bootMovesHolds = func(context.Context, release.Store) { note("holds") }
+ bootOfflineView = func(context.Context, release.Store) { note("offline") }
+ bootSchedule = func(context.Context, *scheduleDeps) error { note("schedule"); return nil }
+
+ ctx := context.Background()
+ f := newFastFixture(t)
+ passes := 0
+ d, b := bootFixture(t, f, func() { passes++; note("reconcile") })
+ ready := b.start(ctx, d, func() { fastTick(ctx, d, time.Unix(1762382167, 0)) })
+ ready()
+
+ at := func(s string) int { return slices.Index(order, s) }
+ if at("holds") < 0 || at("offline") < 0 || at("reconcile") < 0 || at("schedule") < 0 {
+ t.Fatalf("order %v: a step did not run", order)
+ }
+ if !(at("holds") < at("offline") && at("offline") < at("reconcile")) {
+ t.Fatalf("order %v: the first pass started before the views had returned", order)
+ }
+ if at("offline") > at("schedule") {
+ t.Fatalf("order %v: the schedule converge started before the views", order)
+ }
+ if passes != 1 {
+ t.Fatalf("the boot full pass ran %d times at arming, want once", passes)
+ }
+}
+
+// TestFastBootRestartBaselineNeitherReplaysNorSwallows is witness (c),
+// through the production restart seed and legs: a restart request already
+// in the store at boot is not replayed, an app the first pass mints is a
+// baseline rather than a request, and a request written after the seed is
+// acted on at the next serial move. The boot pass runs once, at arming.
+func TestFastBootRestartBaselineNeitherReplaysNorSwallows(t *testing.T) {
+ swapBootSteps(t)
+
+ ctx := context.Background()
+ f := newFastFixture(t)
+ served := execRoute("one.example.com", "bab", "shop")
+ minted := execRoute("two.example.com", "bab", "cafe")
+ if err := f.reg.Upsert(served); err != nil {
+ t.Fatalf("upsert: %v", err)
+ }
+ now := time.Unix(1762382167, 0)
+ // History: a request for the app the box serves, one for the app its
+ // first pass will mint, and the serial bumps behind them.
+ for _, app := range []string{"shop", "cafe"} {
+ if err := release.TouchRestartGen(ctx, f.store, "bab", app); err != nil {
+ t.Fatalf("touch restart gen: %v", err)
+ }
+ }
+ if err := release.BumpSerial(ctx, f.store, now.Add(-time.Minute)); err != nil {
+ t.Fatalf("bump serial: %v", err)
+ }
+
+ passes := 0
+ d, b := bootFixture(t, f, func() {
+ passes++
+ if err := f.reg.Upsert(minted); err != nil {
+ t.Errorf("mint: %v", err)
+ }
+ })
+ var bounced []string
+ b.restartGain, b.restartLeg = armRestartLegs(f.reg, f.store, f.dataDir, b.restartMem,
+ func(h string) bool { bounced = append(bounced, h); return true }, nil)
+
+ ready := b.start(ctx, d, func() { fastTick(ctx, d, now) })
+ ready()
+ fastTick(ctx, d, now.Add(2*time.Second)) // inside the clamp; gains the minted app
+ if passes != 1 {
+ t.Fatalf("the boot full pass ran %d times by the second tick, want once", passes)
+ }
+
+ move := func(at time.Time) {
+ t.Helper()
+ if err := release.BumpSerial(ctx, f.store, at); err != nil {
+ t.Fatalf("bump serial: %v", err)
+ }
+ fastTick(ctx, d, at)
+ }
+ move(now.Add(time.Hour)) // an unrelated move
+ if len(bounced) != 0 {
+ t.Fatalf("bounced %v on the first move: history replayed, or a minted route taken as a request", bounced)
+ }
+
+ if err := release.TouchRestartGen(ctx, f.store, "bab", "shop"); err != nil {
+ t.Fatalf("touch restart gen: %v", err)
+ }
+ move(now.Add(2 * time.Hour))
+ if !slices.Equal(bounced, []string{served.Host}) {
+ t.Fatalf("bounced %v after a request written after the seed, want [%s]", bounced, served.Host)
+ }
+
+ if err := release.TouchRestartGen(ctx, f.store, "bab", "cafe"); err != nil {
+ t.Fatalf("touch restart gen: %v", err)
+ }
+ move(now.Add(3 * time.Hour))
+ if !slices.Equal(bounced, []string{served.Host, minted.Host}) {
+ t.Fatalf("bounced %v after a request for the minted app, want it added", bounced)
+ }
+}
+
+// TestFastBootRequestDuringTheSeedsIsNeverHalfTaken is the overlap the
+// whole-branch review found (Astra P1). The request baselines are held
+// before they read anything; the first tick finishes; a restart request
+// and a sidecar wake land, with their serial bump; then the baselines read.
+// Those reads take both requests as history, so their serial bump must be
+// history too: the first tick may not seed the serial while the baselines
+// are unread. Otherwise the second tick processes the bump as a move and the
+// legs, comparing against a baseline that already holds the request, drop
+// it. A request written once the baselines have read is acted on at the next
+// move. A boot full pass that ran before the serial was seeded is run once
+// more after it is, for whatever the bump behind the seed carried.
+func TestFastBootRequestDuringTheSeedsIsNeverHalfTaken(t *testing.T) {
+ swapBootSteps(t)
+ barrier := make(chan struct{})
+ bootBeforeBaseline = func(step string) {
+ if step == "restart seed" { // before either baseline reads
+ <-barrier
+ }
+ }
+
+ ctx := context.Background()
+ f := newFastFixture(t)
+ served := execRoute("one.example.com", "bab", "shop")
+ sidecar := wakeSidecarRoute("old.shop.sidecar.internal", "bab", "shop", "old")
+ for _, rt := range []registry.Route{served, sidecar} {
+ if err := f.reg.Upsert(rt); err != nil {
+ t.Fatalf("upsert: %v", err)
+ }
+ }
+ now := time.Unix(1762382167, 0)
+ if err := release.BumpSerial(ctx, f.store, now.Add(-time.Minute)); err != nil {
+ t.Fatalf("bump serial: %v", err)
+ }
+
+ passes := 0
+ d, b := bootFixture(t, f, func() { passes++ })
+ var bounced []string
+ restartLegs := 0
+ gain, leg := armRestartLegs(f.reg, f.store, f.dataDir, b.restartMem,
+ func(h string) bool { bounced = append(bounced, h); return true }, nil)
+ b.restartGain = gain
+ b.restartLeg = func(ctx context.Context) { restartLegs++; leg(ctx) }
+ var woken []registry.Route
+ wakeLegs := 0
+ b.wakeLeg = func(ctx context.Context) {
+ wakeLegs++
+ routes, err := f.reg.List()
+ if err != nil {
+ t.Errorf("list: %v", err)
+ return
+ }
+ m, _ := sidecarWakeLeg(ctx, routes, f.store, b.wakeMem, nil)
+ woken = append(woken, m...)
+ }
+
+ ready := b.start(ctx, d, func() { fastTick(ctx, d, now) })
+ if passes != 1 {
+ t.Fatalf("the first tick ran %d full passes, want the boot pass", passes)
+ }
+ if d.seeded {
+ t.Fatal("the first tick seeded the serial while the request baselines were unread")
+ }
+ // Both requests land with their bump, then the baselines read.
+ if err := release.TouchRestartGen(ctx, f.store, "bab", "shop"); err != nil {
+ t.Fatalf("touch restart gen: %v", err)
+ }
+ touchSidecarWake(t, ctx, f.store, "bab", "shop", "old")
+ if err := release.BumpSerial(ctx, f.store, now.Add(time.Second)); err != nil {
+ t.Fatalf("bump serial: %v", err)
+ }
+ close(barrier)
+ ready()
+ fastTick(ctx, d, now.Add(2*time.Second)) // the second tick
+ fastTick(ctx, d, now.Add(6*time.Second)) // past the clamp
+ if restartLegs > 0 && len(bounced) == 0 {
+ t.Fatal("the restart request's serial move was processed, but its baseline had already taken it as history: lost")
+ }
+ if wakeLegs > 0 && len(woken) == 0 {
+ t.Fatal("the wake's serial move was processed, but its baseline had already taken it as history: lost")
+ }
+ if passes != 2 {
+ t.Fatalf("%d full passes by the clamp, want 2: the boot pass ran before the serial was seeded and is not run again", passes)
+ }
+
+ // After the baselines: acted on at the next move.
+ bounced, woken = nil, nil
+ if err := release.TouchRestartGen(ctx, f.store, "bab", "shop"); err != nil {
+ t.Fatalf("touch restart gen: %v", err)
+ }
+ touchSidecarWake(t, ctx, f.store, "bab", "shop", "old")
+ if err := release.BumpSerial(ctx, f.store, now.Add(time.Hour)); err != nil {
+ t.Fatalf("bump serial: %v", err)
+ }
+ fastTick(ctx, d, now.Add(time.Hour))
+ if !slices.Equal(bounced, []string{served.Host}) {
+ t.Fatalf("bounced %v at the next move, want [%s]", bounced, served.Host)
+ }
+ if len(woken) != 1 || woken[0].Host != sidecar.Host {
+ t.Fatalf("woke %v at the next move, want [%s]", woken, sidecar.Host)
+ }
+}
+
+// TestFastBootWakesASidecarTheFirstPassMints: the sidecar wake baseline is
+// taken over the routes the box served when it armed. A sidecar the first
+// pass mints with a wake already standing at it is the create-then-wake flow
+// and is woken on the next move; a sidecar served at arming keeps its wake
+// as history.
+func TestFastBootWakesASidecarTheFirstPassMints(t *testing.T) {
+ swapBootSteps(t)
+
+ ctx := context.Background()
+ f := newFastFixture(t)
+ old := wakeSidecarRoute("old.shop.sidecar.internal", "bdm", "shop", "old")
+ bot := wakeSidecarRoute("bot.shop.sidecar.internal", "bdm", "shop", "bot")
+ if err := f.reg.Upsert(old); err != nil {
+ t.Fatalf("upsert: %v", err)
+ }
+ touchSidecarWake(t, ctx, f.store, "bdm", "shop", "old") // history
+ touchSidecarWake(t, ctx, f.store, "bdm", "shop", "bot") // create-then-wake, before the mint
+ now := time.Unix(1762382167, 0)
+ if err := release.BumpSerial(ctx, f.store, now.Add(-time.Minute)); err != nil {
+ t.Fatalf("bump serial: %v", err)
+ }
+
+ d, b := bootFixture(t, f, func() {
+ if err := f.reg.Upsert(bot); err != nil {
+ t.Errorf("mint: %v", err)
+ }
+ })
+ var moved []registry.Route
+ b.wakeLeg = func(ctx context.Context) {
+ routes, err := f.reg.List()
+ if err != nil {
+ t.Errorf("list: %v", err)
+ return
+ }
+ m, _ := sidecarWakeLeg(ctx, routes, f.store, b.wakeMem, nil)
+ moved = append(moved, m...)
+ }
+
+ ready := b.start(ctx, d, func() { fastTick(ctx, d, now) })
+ ready()
+ fastTick(ctx, d, now.Add(2*time.Second)) // the second tick: the serial is seeded by now
+ if err := release.BumpSerial(ctx, f.store, now.Add(time.Hour)); err != nil {
+ t.Fatalf("bump serial: %v", err)
+ }
+ fastTick(ctx, d, now.Add(time.Hour))
+
+ if len(moved) != 1 || moved[0].Host != bot.Host {
+ t.Fatalf("woke %v on the first move, want only the sidecar the first pass minted", moved)
+ }
+}
+
+// TestFastBootActsOnTheRunsTheFirstTickNoted: a run queued after the runs
+// boot pass has read the records, and noted by the first tick's reconcile
+// while that boot pass is still running, is picked neither by the first
+// tick's runs pass (runsWorker.booted) nor by the boot pass (its listing is
+// older). ready's runs pass picks it, rather than the next full pass.
+func TestFastBootActsOnTheRunsTheFirstTickNoted(t *testing.T) {
+ swapBootSteps(t)
+ ctx := context.Background()
+ f := newFastFixture(t)
+ // A run already queued at boot, on a row this box does not serve. The
+ // boot pass reads it with every other record, then asks whether it owns
+ // the row: the test holds it there, after its listing, before it is done.
+ const other = "other.example.com"
+ earlier := runRecord()
+ earlier.Host = other
+ if err := provision.CreateRecord(ctx, f.store, earlier); err != nil {
+ t.Fatal(err)
+ }
+ if _, err := provision.SetRecordRun(ctx, f.store, earlier.Account, earlier.App, other,
+ provision.RunAdmit(provision.RunAdmission{ID: "run_zyxwvutsrqponmlkjihgfedcba", By: "op@example.com", Deadline: time.Now().Add(time.Minute)})); err != nil {
+ t.Fatal(err)
+ }
+ listed, release := make(chan struct{}), make(chan struct{})
+ var once sync.Once
+ owned := runOwnedRoute(runHost)
+ routes := func(h string) (*registry.Route, error) {
+ if h == other {
+ once.Do(func() { close(listed); <-release })
+ return nil, nil
+ }
+ return owned(h)
+ }
+ var launched execLog
+ w := testWorker(f.store, routes, "box-1", "boot-1", &launched)
+ w.dataDir = t.TempDir()
+ w.booted.Store(false) // a fresh agent: the boot pass has not run
+ prev := armedRuns.Load()
+ armedRuns.Store(w)
+ t.Cleanup(func() { armedRuns.Store(prev) })
+ bootRunsPass = runRunsBootPass
+ bootRunsNotes = runRunsPass
+
+ var id string
+ d, b := bootFixture(t, f, func() {
+ select { // the boot pass has read the records, and is held
+ case <-listed:
+ case <-time.After(bootFailAfter):
+ t.Error("the runs boot pass never reached its owned-route check beside the first tick")
+ return
+ }
+ var rec provision.Record
+ rec, id = queueRun(t, f.store, time.Now().Add(time.Minute))
+ w.note(rec) // reconcile's note
+ runRunsPass(ctx) // the full pass's runs leg
+ })
+ ready := b.start(ctx, d, func() { fastTick(ctx, d, time.Unix(1762382167, 0)) })
+ if n := launched.count(); n != 0 {
+ t.Fatalf("%d runs launched by the first tick, want 0: a runs pass acted before the boot pass finished", n)
+ }
+ close(release)
+ ready()
+ if n := launched.count(); n != 1 {
+ t.Fatalf("%d runs launched after ready, want 1: the queued run the first tick noted waits for the next full pass", n)
+ }
+ got, err := provision.GetRecord(ctx, f.store, "bab", "shop", runHost)
+ if err != nil || got.ActiveRun == nil || got.ActiveRun.ID != id || got.ActiveRun.State != provision.RunPicked || got.ActiveRun.Box != "box-1" {
+ t.Fatalf("record after ready: %+v, %v; want run %s picked by box-1", got.ActiveRun, err, id)
+ }
+}
+
+// TestFastConvergeLoopArmsThroughFastBoot pins the wiring the witnesses
+// above rely on: fastConvergeLoop reaches the views and the seeds only
+// through fastBoot, so their order is the one fastBoot.start keeps.
+func TestFastConvergeLoopArmsThroughFastBoot(t *testing.T) {
+ file, err := parser.ParseFile(token.NewFileSet(), "agent.go", nil, 0)
+ if err != nil {
+ t.Fatal(err)
+ }
+ banned := map[string]bool{
+ "refreshMovesHolds": true, "refreshOfflineView": true, "restartSeed": true, "restartBaseline": true,
+ "sidecarWakeSeed": true, "sidecarWakeBaseline": true, "runRunsBootPass": true,
+ }
+ found, starts, loops := false, 0, 0
+ for _, decl := range file.Decls {
+ fn, ok := decl.(*ast.FuncDecl)
+ if !ok || fn.Name.Name != "fastConvergeLoop" {
+ continue
+ }
+ found = true
+ for _, stmt := range fn.Body.List {
+ loop, ok := stmt.(*ast.ForStmt)
+ if !ok {
+ continue
+ }
+ readyAt, tickAt := token.NoPos, token.NoPos
+ ast.Inspect(loop.Body, func(n ast.Node) bool {
+ if call, ok := n.(*ast.CallExpr); ok {
+ if id, ok := call.Fun.(*ast.Ident); ok {
+ switch {
+ case id.Name == "ready" && readyAt == token.NoPos:
+ readyAt = call.Pos()
+ case id.Name == "fastTick" && tickAt == token.NoPos:
+ tickAt = call.Pos()
+ }
+ }
+ }
+ return true
+ })
+ if readyAt == token.NoPos || tickAt == token.NoPos || readyAt > tickAt {
+ t.Error("fastConvergeLoop's tick loop does not call ready() before fastTick: the seeded legs never reach the loop, or reach it after a tick that can act on a move")
+ }
+ loops++
+ }
+ ast.Inspect(fn.Body, func(n ast.Node) bool {
+ call, ok := n.(*ast.CallExpr)
+ if !ok {
+ return true
+ }
+ switch fun := call.Fun.(type) {
+ case *ast.Ident:
+ if banned[fun.Name] {
+ t.Errorf("fastConvergeLoop calls %s itself; it belongs to fastBoot", fun.Name)
+ }
+ case *ast.SelectorExpr:
+ switch fun.Sel.Name {
+ case "start":
+ starts++
+ case "converge", "observe":
+ t.Errorf("fastConvergeLoop calls .%s itself; the arming one belongs to fastBoot", fun.Sel.Name)
+ }
+ }
+ return true
+ })
+ }
+ if !found {
+ t.Fatal("no fastConvergeLoop in agent.go")
+ }
+ if loops != 1 {
+ t.Fatalf("fastConvergeLoop has %d for loops at its top level, want the tick loop alone", loops)
+ }
+ if starts != 1 {
+ t.Fatalf("fastConvergeLoop calls .start %d times, want once (fastBoot.start)", starts)
+ }
+}
diff --git a/internal/host/restart.go b/internal/host/restart.go
index 6d042b7d4..c1be4967d 100644
--- a/internal/host/restart.go
+++ b/internal/host/restart.go
@@ -934,15 +934,26 @@ func restartRequestLeg(ctx context.Context, routes []registry.Route, store relea
// narrowed log, is verified and applied here (applyRetries), so one written
// before this agent started is not lost to the baseline. One spent or made
// stale since clears nothing.
+//
+// fastConvergeLoop runs it through fastBoot, first on the seeds' goroutine,
+// beside the view walks and the first tick. The loop reads no serial until
+// it has returned, and gets the restart legs only once it has: the baseline
+// exists before the serial is seeded, as it did when the seed ran before
+// arming.
func restartSeed(ctx context.Context, reg *registry.Registry, store release.Store, dd string, mem *restartMemory) {
routes, err := reg.List()
if err != nil {
- log.Printf("agent: restart baseline: list routes: %v (the first request may need a second try)", err)
+ logRestartListError(err)
return
}
restartBaseline(ctx, routes, store, dd, mem)
}
+// logRestartListError is the seed's line for a route list it could not read.
+func logRestartListError(err error) {
+ log.Printf("agent: restart baseline: list routes: %v (the first request may need a second try)", err)
+}
+
// restartBaseline is restartSeed's sweep over a given route set, and every
// rule in restartSeed's comment is this function's: record what every app's
// two objects say, cycle nothing, apply retry grants, and give the root pass
@@ -1115,11 +1126,11 @@ func restartGainSeed(ctx context.Context, routes []registry.Route, store release
// armRestartLegs builds the agent's two restart hooks over ONE memory: gain,
// which fastTick runs on every tick (restartGainSeed), and leg, which it runs
-// on a serial move (restartRequestLeg). The memory is passed in already
-// seeded (restartSeed), because fastConvergeLoop arms more than this file
-// knows about on it first. fastConvergeLoop takes both hooks from here, and
-// so do the tests, so the wiring a test exercises is the wiring production
-// runs.
+// on a serial move (restartRequestLeg). Building them reads nothing; the
+// memory is seeded by restartSeed, which fastConvergeLoop runs through
+// fastBoot, and fastBoot hands both hooks to the loop only once that seed has
+// returned. fastConvergeLoop takes both hooks from here, and so do the
+// tests, so the wiring a test exercises is the wiring production runs.
func armRestartLegs(reg *registry.Registry, store release.Store, dd string, mem *restartMemory,
bounce func(host string) bool, wake func(rt registry.Route) error) (gain func(ctx context.Context, now time.Time), leg func(ctx context.Context)) {
gain = func(ctx context.Context, now time.Time) {
diff --git a/internal/host/sidecarwake.go b/internal/host/sidecarwake.go
index 5893a6953..b024d4dc6 100644
--- a/internal/host/sidecarwake.go
+++ b/internal/host/sidecarwake.go
@@ -265,12 +265,29 @@ func sidecarWakeLeg(ctx context.Context, routes []registry.Route, store release.
// "every sidecar on this box is brand new" and waking the lot. A per-sidecar
// read error is narrower — that one sidecar is left out of the cache and may
// be woken once on its next sighting.
+//
+// fastConvergeLoop takes the route list itself, before its first full pass,
+// and runs sidecarWakeBaseline over it beside that pass (fastBoot): a list
+// taken after the pass would record a sidecar the pass just minted as
+// history, and drop the wake standing at it.
func sidecarWakeSeed(ctx context.Context, reg *registry.Registry, store release.Store, mem *sidecarWakeMemory) {
routes, err := reg.List()
if err != nil {
- log.Printf("agent: sidecar wake baseline: list routes: %v (the first request may need a second try)", err)
+ logSidecarWakeListError(err)
return
}
+ sidecarWakeBaseline(ctx, routes, store, mem)
+}
+
+// logSidecarWakeListError is the seed's line for a route list it could not
+// read, which leaves the memory unseeded.
+func logSidecarWakeListError(err error) {
+ log.Printf("agent: sidecar wake baseline: list routes: %v (the first request may need a second try)", err)
+}
+
+// sidecarWakeBaseline is sidecarWakeSeed's silent pass over a given route
+// list, the one the agent served when it armed.
+func sidecarWakeBaseline(ctx context.Context, routes []registry.Route, store release.Store, mem *sidecarWakeMemory) {
_, readErrs := sidecarWakeChanges(ctx, routes, store, mem)
if len(readErrs) > 0 {
log.Printf("agent: sidecar wake baseline: %d sidecars unreadable: %v", len(readErrs), readErrs[0])
diff --git a/internal/host/startupmeasure_e2e_test.go b/internal/host/startupmeasure_e2e_test.go
new file mode 100644
index 000000000..69cb65316
--- /dev/null
+++ b/internal/host/startupmeasure_e2e_test.go
@@ -0,0 +1,415 @@
+//go:build linux
+
+package host
+
+import (
+ "context"
+ "crypto/ed25519"
+ "encoding/base64"
+ "fmt"
+ "io"
+ "os"
+ "regexp"
+ "slices"
+ "sort"
+ "strconv"
+ "strings"
+ "sync"
+ "sync/atomic"
+ "testing"
+ "time"
+
+ "github.com/carlosframework/platform/internal/appconfig"
+ "github.com/carlosframework/platform/internal/apppolicy"
+ "github.com/carlosframework/platform/internal/hostwrite"
+ "github.com/carlosframework/platform/internal/provision"
+ "github.com/carlosframework/platform/internal/release"
+)
+
+// The startup measurement (fleet first reconcile, Task 2): a fleet box's
+// startup store reads over a slow fake store door, step by step, without a
+// dev box. Not a witness: it asserts nothing about timing. It prints, per
+// step, the ops by kind, the wall time, the summed op time and the peak
+// number of ops in flight, then every key each step read, grouped.
+//
+// Skipped unless CARLOS_MEASURE_STARTUP=1. Knobs:
+//
+// CARLOS_MEASURE_STARTUP_LATENCY each op's latency (default 60ms)
+// CARLOS_MEASURE_STARTUP_SIZES instances on the box, comma-separated (default 5,20)
+// CARLOS_MEASURE_STARTUP_OUT a file the tables are also written to
+//
+// The world is the two-box harness's (newFleetWorld): fleet pi, boxes pi-1
+// and pi-2, app shop placed on it, with a signed app policy. For n
+// instances on pi-1, 2(n-1) are created through the console's door (they
+// alternate boxes), pi-1 runs one reconcile (its previous life), then one
+// more is created while it is "stopped" (it lands on pi-1, the witness
+// method). The box then starts: the seeds, then the first tick's reads and
+// the first full pass, one after another, through the production helpers,
+// every store op over the door. That is the order before Task 4 (the
+// pre-change sequential baseline): fastConvergeLoop now arms through
+// fastBoot, which runs the seeds beside the first tick. Read these numbers
+// as the cost of each step, not as the new startup path.
+//
+// Not measured here: the activator startup (systemd sweep and Recover),
+// the runDuties steps, the runs boot pass and the schedule converge (each
+// opens its own store), the moves holds with the Phase 1 switch on (off is
+// the fleet default, and the step is then a no-op), and the first tick's
+// sleep.
+func TestStartupMeasure(t *testing.T) {
+ if os.Getenv("CARLOS_MEASURE_STARTUP") != "1" {
+ t.Skip("a measurement, not a test: set CARLOS_MEASURE_STARTUP=1 to run it")
+ }
+ lat := 60 * time.Millisecond
+ if v := os.Getenv("CARLOS_MEASURE_STARTUP_LATENCY"); v != "" {
+ d, err := time.ParseDuration(v)
+ if err != nil {
+ t.Fatalf("CARLOS_MEASURE_STARTUP_LATENCY=%q: %v", v, err)
+ }
+ lat = d
+ }
+ sizes := []int{5, 20}
+ if v := os.Getenv("CARLOS_MEASURE_STARTUP_SIZES"); v != "" {
+ sizes = nil
+ for _, f := range strings.Split(v, ",") {
+ n, err := strconv.Atoi(strings.TrimSpace(f))
+ if err != nil || n < 1 {
+ t.Fatalf("CARLOS_MEASURE_STARTUP_SIZES=%q: want whole numbers of 1 or more", v)
+ }
+ sizes = append(sizes, n)
+ }
+ }
+ var out strings.Builder
+ for _, n := range sizes {
+ t.Run(fmt.Sprintf("instances=%d", n), func(t *testing.T) {
+ out.WriteString(measureStartup(t, n, lat))
+ })
+ }
+ t.Log("\n" + out.String())
+ if path := os.Getenv("CARLOS_MEASURE_STARTUP_OUT"); path != "" {
+ if err := os.WriteFile(path, []byte(out.String()), 0o644); err != nil {
+ t.Fatal(err)
+ }
+ }
+}
+
+// slowDoor is the fleet store door's shape (Store, Opener, ETagLister) over
+// a fast store: every op waits lat first, then is noted with its key and
+// how many ops were in flight when it began.
+type slowDoor struct {
+ inner release.Store // a DirStore: Opener and ETagLister both
+ lat time.Duration
+ inflight atomic.Int32
+
+ mu sync.Mutex
+ ops []doorOp
+}
+
+type doorOp struct {
+ op storeOp
+ key string
+ inflight int32 // ops in flight when this one began, itself included
+}
+
+func (d *slowDoor) begin(op storeOp, key string) func() {
+ n := d.inflight.Add(1)
+ time.Sleep(d.lat)
+ d.mu.Lock()
+ d.ops = append(d.ops, doorOp{op: op, key: key, inflight: n})
+ d.mu.Unlock()
+ return func() { d.inflight.Add(-1) }
+}
+
+func (d *slowDoor) mark() int {
+ d.mu.Lock()
+ defer d.mu.Unlock()
+ return len(d.ops)
+}
+
+func (d *slowDoor) between(from, to int) []doorOp {
+ d.mu.Lock()
+ defer d.mu.Unlock()
+ return append([]doorOp(nil), d.ops[from:to]...)
+}
+
+func (d *slowDoor) Get(ctx context.Context, key string) ([]byte, string, error) {
+ defer d.begin(opGet, key)()
+ return d.inner.Get(ctx, key)
+}
+
+func (d *slowDoor) Put(ctx context.Context, key string, body []byte, ifMatch string) (string, error) {
+ defer d.begin(opPut, key)()
+ return d.inner.Put(ctx, key, body, ifMatch)
+}
+
+func (d *slowDoor) List(ctx context.Context, prefix string) ([]string, error) {
+ defer d.begin(opList, prefix)()
+ return d.inner.List(ctx, prefix)
+}
+
+func (d *slowDoor) ListDirs(ctx context.Context, prefix string) ([]string, error) {
+ defer d.begin(opDirs, prefix)()
+ return d.inner.ListDirs(ctx, prefix)
+}
+
+func (d *slowDoor) Delete(ctx context.Context, key string) error {
+ defer d.begin(opDelete, key)()
+ return d.inner.Delete(ctx, key)
+}
+
+func (d *slowDoor) Open(ctx context.Context, key string) (io.ReadCloser, string, error) {
+ defer d.begin(opGet, key)()
+ return d.inner.(release.Opener).Open(ctx, key)
+}
+
+func (d *slowDoor) ListETags(ctx context.Context, prefix string) ([]release.KeyETag, error) {
+ defer d.begin(opList, prefix)()
+ return d.inner.(release.ETagLister).ListETags(ctx, prefix)
+}
+
+// measuredLine is one startup timing line and the door ops made since the
+// line before it.
+type measuredLine struct {
+ text string
+ ops []doorOp
+}
+
+// measureStartup builds the world for n instances on pi-1, runs the box's
+// startup reads over a door of latency lat, and returns the report's
+// markdown for this size.
+func measureStartup(t *testing.T, n int, lat time.Duration) string {
+ ctx := context.Background()
+ w := newFleetWorld(t, fleetOpts{})
+ b := w.pi1
+
+ // The release key: the box verifies app policies with it.
+ relPub, relPriv, err := ed25519.GenerateKey(nil)
+ if err != nil {
+ t.Fatal(err)
+ }
+ cfgKey, _, err := appconfig.GenerateKey()
+ if err != nil {
+ t.Fatal(err)
+ }
+ env := map[string]string{
+ "CARLOS_RELEASE_PUBKEY": base64.StdEncoding.EncodeToString(relPub),
+ "CARLOS_SECRETS_KEY": cfgKey,
+ }
+ getenv := func(k string) string {
+ if v, ok := env[k]; ok {
+ return v
+ }
+ return b.getenv(k)
+ }
+ if err := apppolicy.PutIfMatch(ctx, w.store, relPriv, apppolicy.Policy{V: 1, Account: w.acct, App: "shop", Revision: 1,
+ SignedAt: time.Now().UTC()}, ""); err != nil {
+ t.Fatal(err)
+ }
+
+ // n-1 instances on each box, pi-1's previous life, then one more.
+ host := func(i int) string { return fmt.Sprintf("m%02d.example.com", i) }
+ for i := 0; i < 2*(n-1); i++ {
+ w.create(host(i))
+ }
+ b.mustReconcile()
+ last := host(2 * (n - 1))
+ w.create(last)
+ if rec := w.record(last); rec.FleetBox != b.label {
+ t.Fatalf("fixture: %s landed on %q, want %s", last, rec.FleetBox, b.label)
+ }
+
+ // The box starts. Every read from here on is over the door.
+ judge := newBoxJudge(getenv)
+ if judge == nil {
+ t.Fatal("fixture: no lifetime judge, as a claims-off fleet box has")
+ }
+ armMeasuredBox(t, b, getenv, judge)
+ ctx = provision.WithLifetimes(ctx, judge)
+ door := &slowDoor{inner: w.store, lat: lat}
+ if storeExts(door) != doorShape {
+ t.Fatal("fixture: the fake door is not the fleet door's shape")
+ }
+ store, counter := countStore(door)
+
+ var mu sync.Mutex
+ var lines []measuredLine
+ from := 0
+ slog := &startupLog{start: time.Now(), now: time.Now, logf: func(format string, args ...any) {
+ mu.Lock()
+ defer mu.Unlock()
+ to := door.mark()
+ lines = append(lines, measuredLine{text: fmt.Sprintf(format, args...), ops: door.between(from, to)})
+ from = to
+ }}
+ pub, err := release.ParsePublicKey(getenv("CARLOS_RELEASE_PUBKEY"), "CARLOS_RELEASE_PUBKEY")
+ if err != nil {
+ t.Fatal(err)
+ }
+ priv, err := appconfig.ParsePrivateKey(getenv("CARLOS_SECRETS_KEY"), "CARLOS_SECRETS_KEY")
+ if err != nil {
+ t.Fatal(err)
+ }
+ optDir := t.TempDir()
+
+ // The seeds in the pre-change sequential order (before Task 4's
+ // fastBoot; the runs boot pass and the schedule converge open their own
+ // stores: left out).
+ arming := slog.steps("arming: ", counter)
+ mem := newRestartMemory()
+ mem.pub = pub
+ restartSeed(ctx, b.reg, store, b.dd, mem)
+ arming.done("restart seed")
+ gain, _ := armRestartLegs(b.reg, store, b.dd, mem, nil, nil)
+ arming.done("restart legs")
+ sidecarWakeSeed(ctx, b.reg, store, newSidecarWakeMemory(false))
+ arming.done("sidecar wake seed")
+ refreshMovesHolds(ctx, store)
+ arming.done("moves holds")
+ refreshOfflineView(ctx, store, armedOfflineView())
+ arming.done("offline view")
+ if leg := newSystemLeg(store, pub, getenv, b.dd, optDir); leg != nil {
+ leg.readers = cachedGroupReaders
+ leg.observe(ctx)
+ }
+ arming.done("system pointer")
+ arming.total("total")
+
+ // The first tick's reads, then the first full pass, which counts
+ // through its own wrapper and logs its own stages.
+ tick := slog.steps("first tick: ", counter)
+ gain(ctx, time.Now())
+ tick.done("restart gain")
+ if _, _, err := release.ReadSerial(ctx, store); err != nil {
+ t.Logf("serial read: %v", err)
+ }
+ tick.done("serial read")
+ legs := &passLegs{store: door, reg: b.reg, pub: pub, optDir: optDir, priv: priv, dd: b.dd, startup: slog,
+ cfg: func() provision.ReconcileConfig {
+ c := BoxProvisionConfig(b.reg, getenv, judge, nil)
+ c.Lifetimes = &provision.LifetimeIndex{}
+ c.Layout = flatLayout
+ return c
+ }}
+ legs.full(ctx)
+ tick.done("full pass")
+ tick.total("total")
+ if rt := b.row(last); rt == nil {
+ t.Fatalf("the first pass did not mint %s", last)
+ }
+
+ mu.Lock()
+ defer mu.Unlock()
+ return startupReport(n, lat, lines, func(key string) string {
+ key = strings.ReplaceAll(key, w.acct, "<acct>")
+ for i := 0; i <= 2*(n-1); i++ {
+ key = strings.ReplaceAll(key, host(i), "<host>")
+ }
+ return key
+ })
+}
+
+// startupReport is one size's markdown: the step table, then each step's
+// reads grouped by key shape.
+func startupReport(n int, lat time.Duration, lines []measuredLine, shape func(string) string) string {
+ // Reconcile's own stage lines come from its trace hook, when it has
+ // one; without them the reconcile line carries its reads itself.
+ staged := slices.ContainsFunc(lines, func(l measuredLine) bool {
+ return strings.HasPrefix(l.text, "agent: startup: first pass: reconcile: ")
+ })
+ aggregate := func(name string) bool {
+ return strings.HasSuffix(name, "total") || name == "first tick: full pass" || (staged && name == "first pass: reconcile")
+ }
+ var b strings.Builder
+ fmt.Fprintf(&b, "### %d instances on the box, %s per op (pre-change sequential order, not fastBoot's)\n\n", n, lat)
+ b.WriteString("| step | wall | store ops (count/summed time) | ops x latency | peak in flight | began alone |\n")
+ b.WriteString("|---|---|---|---|---|---|\n")
+ for _, l := range lines {
+ m := startupLineRE.FindStringSubmatch(l.text)
+ if m == nil {
+ continue
+ }
+ name, took, ops := m[1], m[2], m[3]
+ total := 0
+ for _, part := range strings.Split(ops, ", ") {
+ if _, rest, ok := strings.Cut(part, " "); ok {
+ c, _, _ := strings.Cut(rest, "/")
+ k, _ := strconv.Atoi(c)
+ total += k
+ }
+ }
+ serialEq := ""
+ if total > 0 {
+ serialEq = (time.Duration(total) * lat).String()
+ }
+ peak, alone := "", ""
+ if aggregate(name) {
+ peak, alone = "(sum of the above)", ""
+ } else if len(l.ops) > 0 {
+ var p int32
+ a := 0
+ for _, o := range l.ops {
+ p = max(p, o.inflight)
+ if o.inflight == 1 {
+ a++
+ }
+ }
+ peak, alone = strconv.Itoa(int(p)), strconv.Itoa(a)
+ }
+ fmt.Fprintf(&b, "| %s | %s | %s | %s | %s | %s |\n", name, took, ops, serialEq, peak, alone)
+ }
+ b.WriteString("\nReads by step (key shape, op, count; listings show their prefix):\n\n")
+ for _, l := range lines {
+ m := startupLineRE.FindStringSubmatch(l.text)
+ if m == nil || len(l.ops) == 0 || aggregate(m[1]) {
+ continue
+ }
+ counts := map[string]int{}
+ for _, o := range l.ops {
+ counts[storeOpNames[o.op]+" "+shape(o.key)]++
+ }
+ keys := make([]string, 0, len(counts))
+ for k := range counts {
+ keys = append(keys, k)
+ }
+ sort.Slice(keys, func(i, j int) bool {
+ if counts[keys[i]] != counts[keys[j]] {
+ return counts[keys[i]] > counts[keys[j]]
+ }
+ return keys[i] < keys[j]
+ })
+ fmt.Fprintf(&b, "- **%s** (%d ops)\n", m[1], len(l.ops))
+ for _, k := range keys {
+ fmt.Fprintf(&b, " - %s x%d\n", k, counts[k])
+ }
+ }
+ b.WriteString("\n")
+ return b.String()
+}
+
+var startupLineRE = regexp.MustCompile(`^agent: startup: (.+?) took (\S+) at \+\S+(?: \(store: (.*)\))?$`)
+
+// armMeasuredBox arms the globals the startup reads through as the agent
+// arms them on a fleet box (claims off, moves switch unset, hibernation
+// configured), and puts them back afterwards.
+func armMeasuredBox(t *testing.T, b *fleetBox, getenv func(string) string, judge *provision.LifetimeJudge) {
+ t.Helper()
+ prevWorker, prevPolicies := armedMovesWorker.Load(), armedPolicyCache.Load()
+ t.Cleanup(func() {
+ armedMovesWorker.Store(prevWorker)
+ armedPolicyCache.Store(prevPolicies)
+ aliasClaimCache.Reset()
+ })
+ aliasClaimCache.Reset()
+ armedPolicyCache.Store(provision.NewPolicyCache(nil))
+ cfg := moveCfg{Judge: judge, Region: getenv("CARLOS_REGION"), OwnBucket: fleetBucket, OwnBucketRegion: fleetRegion,
+ OwnPrefix: fleetPrefix, DataDir: b.dd, Now: time.Now, Box: b.label, OptDir: t.TempDir(),
+ OwnsRoute: func(host string) bool {
+ rt, err := b.reg.Get(host)
+ return err == nil && rt != nil && rt.Provisioned
+ },
+ Route: b.reg.Get, SetStatus: b.reg.SetStatus}
+ armOffline(&cfg, b.dd, b.reg, nil, nil, hostwrite.Config{}, getenv)
+ if !cfg.OfflineCapable {
+ t.Fatal("fixture: the box is not offline capable, as a fleet box with hibernation is")
+ }
+ armedMovesWorker.Store(newMovesWorker(cfg))
+}
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv
index b80565a5e..60fa52cca 100644
--- a/internal/provision/testdata/plan14-root-reads-chain.tsv
+++ b/internal/provision/testdata/plan14-root-reads-chain.tsv
@@ -231,3 +231,4 @@ plan14-root-reads-fleet-unrouted-503-fix1.tsv e8043922abe9911a69ed6f5a9f8ec1d8f1
plan14-root-reads-omr-run.tsv f82b5e513d7434e1440c13aa4aa8bc06348745749a21593cf453f761ded0781b
plan14-root-reads-fleet-first-reconcile-speed.tsv 9206205b2a3bf27b8b85310f4a44f94ef0c5886d85d6e55dbf2f22e073a8af11
plan14-root-reads-free-storage-250.tsv 9206205b2a3bf27b8b85310f4a44f94ef0c5886d85d6e55dbf2f22e073a8af11
+plan14-root-reads-fleet-first-reconcile-speed-4.tsv 4eda67fee53800e2cfa4177b954c7f0fce6bdfcfbfe1aa2547ddcec3027b668b
diff --git a/internal/provision/testdata/plan14-root-reads-fleet-first-reconcile-speed-4.tsv b/internal/provision/testdata/plan14-root-reads-fleet-first-reconcile-speed-4.tsv
new file mode 100644
index 000000000..c9523d968
--- /dev/null
+++ b/internal/provision/testdata/plan14-root-reads-fleet-first-reconcile-speed-4.tsv
@@ -0,0 +1,16 @@
+# Census overlay fleet-first-reconcile-speed-4, written by census-propose (#369). census-ruling-fleet-first-reconcile-speed-4, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-fleet-first-reconcile-speed-4.md.
+# 4 body, 0 sites, 1 envelope: each changed unit re-frozen at its existing disposition with its claim appended.
+# 3 new dispositions: 0 reads re-frozen at their disposition with the claim, 3 new units frozen accepted-legacy, 0 quiet units retired while they read nothing, 0 other.
+@legacy 56c59582ac0dfa8b8ef952f9b0422e7f36711764abb4225536123575f5099871 internal/host/agent.go fastTick legacy accepted-legacy accepted-legacy;rev3=J1;basis=root-route;rev3=PROPOSED-s3-change-index;identity=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos);basis=observes the change index before any pass (observeIndex), runs the backstop's requested full pass and a scoped pass for moved app scopes (indexTick), and arms the canary pointer gate on the sweep (canaryPointerGate) only on a tick whose own index observation succeeded; read site unchanged, offset moved;rev3=census-ruling-stateless-replicas-1;basis=Call coordinator Tick on the existing tick before convergence; client renews held terms only at the pinned interval. Existing registry read unchanged. Final review I3: signal the owned renewal worker instead of waiting for its sequential console HTTP calls. Existing convergence and record read unchanged.;rev3=census-ruling-region-ha-p3a;basis=Run the optional desired-role reader on the existing tick after observing the armed change index; no new root path or timer, nil reader is unchanged.;rev3=census-ruling-stateless-replicas-2;basis=Slice 3b: signals the owned replica worker on the existing tick; coalesced asynchronous execution, no timer or bucket scan added. merge of origin/main 7920cccf: Retain main box-role reader pass on the existing tick alongside the replica worker signal; merge-only body change, unchanged read sites.;rev3=census-ruling-restart-new-box-gap;basis=calls the optional restartGain hook (restartGainSeed) once per existing tick before the serial read; no new root path, timer or read kind; nil hook is unchanged;rev3=census-ruling-agent-start-demo-3;basis=Refresh moved notices through the shared watch before normal convergence; no new per-box poll. Census read-site delta: unchanged (1).;rev3=census-ruling-stateless-replicas-4-task1;basis=Signals the owned replica swap worker (armedReplicaDeploy.tick) beside the placement worker on the existing tick; coalesced background pass, no timer, no bucket read. Its transitions go through the console's authenticated /deploy.;rev3=census-ruling-platform-mail-submission;basis=Task 4: on a serial move, after the schedule leg, starts the armed mail switch cache's Refresh on its own goroutine (each read bounded at 2 s, overlapping refreshes skipped). It re-reads the app sender records already cached, through the agent's deploy store. Agent, not root; the tick waits on nothing new. Fable final P2-1: on a serial move, before the pass set and the restart leg, calls the armed cache's MarkStale (a counter bump under the cache's mutex; no I/O), so a spawn the move causes reads the switch again, bounded, instead of using an answer from before the move. No read added.;rev3=census-ruling-fleet-first-reconcile-speed;basis=Startup timing log lines only: d.startup.done(<part>) calls between the existing parts and a deferred one after the sweep. d.startup is nil on every tick but the first after agent start, and its methods are then no-ops. No read added, no order change; read site unchanged (1). Agent, not root.;rev3=census-ruling-fleet-first-reconcile-speed-4;basis=Startup serial hold (whole-branch review P1). While fastDeps.serialAfter is open (fastBoot closes it when the restart and sidecar wake baselines have read) the tick skips its one ReadSerial of control/serial, so it neither seeds nor acts on a move; the rest of the tick (backstop full pass, index, sweep) is unchanged. A full pass run while held sets fullBeforeSeed, and the seed then sets fullDue once so the backstop branch runs one more full pass under the clamp. Same read, read sites unchanged (1); no read added. Agent, not root. registry:Host@7321 5e7b593089330e12933dac81b1ffab26a34edc0d65e355b530faed17c28f2e47
+@legacy b0d342fd85526d360ba5d6b2b31d603800c7b1b6192985679b3e1e64f3cdfd5e internal/host/sidecarwake.go sidecarWakeSeed legacy accepted-legacy accepted-legacy;rev3=J1;basis=root-route;rev3=census-ruling-fleet-first-reconcile-speed-4;basis=Body split: reg.List, then sidecarWakeBaseline (the former rest of the body, unchanged); list-error log line moved into logSidecarWakeListError (same text). No read added; agent, not root. whole:Route@226 2ab3e681cf37e2020c89971b0a9ce4da882053b37931308710dfcf2bee81cebc
+@legacy 5de5403ccc8acfdec62ec3ac54188491766596cafc180a8a8f03b440d4184b77 internal/host/fastboot.go fastBoot.seed legacy accepted-legacy accepted-legacy;rev3=census-ruling-fleet-first-reconcile-speed-4;basis=New (Task 4): the seeds moved out of fastConvergeLoop, same order. restartSeed is called directly (its own reg.List, then restartBaseline, as fastConvergeLoop called it before), sidecarWakeBaseline over the arming route snapshot (or the existing list-error line), then it closes the serial hold, waits for the views, and runs runRunsBootPass, sd.converge and systemLeg.observe (systemLeg.store swapped to the counting wrapper and restored), the last three through package func vars defaulting to them. A nil test hook (bootBeforeBaseline) precedes each baseline. Same calls and keys as before; no read added. Agent, not root. whole:Route@640 3ff89b37f97698583a97e56b72b7a2f36b6bc837991525dddd41f3eb7c8ee9eb
+@legacy 77c697a23c8948b9b466ab3fdb41f043e1ff5980c402274cb59e231ef8c24c83 internal/host/fastboot.go fastBoot.start legacy accepted-legacy accepted-legacy;rev3=census-ruling-fleet-first-reconcile-speed-4;basis=New (Task 4): the arming order moved out of fastConvergeLoop. One reg.List of this box's registry (the route snapshot for the sidecar baseline), starts the seeds goroutine first, then refreshMovesHolds and refreshOfflineView (through package func vars defaulting to them), sets fastDeps.serialAfter, runs the first tick, and returns ready, which waits for the seeds (one log line if over slowLegAfter), runs runRunsPass once (through bootRunsNotes; the same runs pass every full pass runs, for notes the first tick kept while the runs boot pass was unfinished), clears the serial hold and assigns the seeded legs to fastDeps. No read beyond those the moved calls and that existing runs pass already make. Agent, not root. whole:Route@408 37ce68db08a2099bf75e3082ac811a286d7ab3fed78f67baedf7819919a63d95
+@legacy e7e1964bcc5167146f6b0438f36132659cacd1cdd6b23923e6061e172135b9f6 internal/host/sidecarwake.go sidecarWakeBaseline legacy accepted-legacy accepted-legacy;rev3=census-ruling-fleet-first-reconcile-speed-4;basis=New: the former second half of sidecarWakeSeed over a given route list (sidecarWakeChanges on the box's own routes, read errors logged). The route values come from the caller's reg.List of this box's registry; no new read site. Agent, not root. whole:Route@158 44f8d730300282571787e2d2e7d59c8f8bb0f768045c44864a7860233370636e
+internal/host/agent.go fastConvergeLoop authority B3 rev3=census-ruling-self-serve-moves-1;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): every pass context carries the box's lifetime judge (provision.WithLifetimes) and the reconcile config is boxProvisionConfig's; read sites unchanged, offsets moved; B3 authority retained;rev3=census-ruling-fleet-public-routes;basis=fleet public routes (spec 2026-10-29 rev 4, §4.2 writer rule): Task 12: its pass config is now BoxProvisionConfig(reg, os.Getenv, judge, configure) (BoxProvisionConfig replaces boxProvisionConfig: the hub predicate hubArmed and, on the hub, ReconcileConfig.FleetOwners from hubFleetOwners); a call, no read site; read sites unchanged (2); B3 authority retained.;rev3=census-ruling-stateless-replicas-1;basis=Final review I3: wire the coordinator's nonblocking SignalTick to the existing fast tick. No new timer, polling read or authority.;rev3=census-ruling-region-ha-p3b;basis=Bind systemLeg to the existing cached reader fold and handle a nil leg on groups; names-2 rollback gate runs before artifact/request/marker work. Agent-memory evidence only, no new direct or cloud read and no autonomous group update.;rev3=census-ruling-restart-new-box-gap;basis=restart leg closure moved into armRestartLegs (same reg.List + restartRequestLeg); also wires restartGain; read moved, not added;rev3=census-ruling-agent-start-demo-3;basis=Attach the moved reader to the existing shared change watch and advertise that reader as armed. Census read-site delta: unchanged (2).;rev3=census-ruling-fleet-first-reconcile-speed;basis=Startup timing log lines only (fleet first reconcile Task 1). Logs its entry offset and one line per arming step, then times the first tick. restartSeed, sidecarWakeSeed, refreshMovesHolds, refreshOfflineView and the one arming systemLeg.observe now read through countStore(store), a pass-through wrapper that counts and times each call and forwards it unchanged with the same key; for that observe, systemLeg.store is swapped to the wrapper and restored. For the first tick only, d.store is a fresh countStore(store) wrapper and d.startup a step logger; both are reset to the plain store and nil after the tick. passLegs gets startup. Same calls in the same order, no read added; read sites unchanged (1). Agent, not root.;rev3=census-ruling-fleet-first-reconcile-speed-4;basis=Arming order only (fleet first reconcile Task 4). The moves hold view, the offline view, the restart seed, the sidecar wake seed, the runs boot pass, the arming schedule converge and the arming systemLeg.observe are no longer called here: fastBoot.start runs them (views on this goroutine, then the first tick at once with the seeds beside it). The restart legs, the sidecar wake leg closure (same reg.List + sidecarWakeLeg) and newSystemLeg are built here as before and handed to fastBoot, which gives them to fastDeps once the seeds return, before the second tick. The first tick no longer waits for a tick's sleep. Same calls with the same arguments and keys; no read added; read sites unchanged (1). Agent, not root. whole:Route@7828 305f82326c431fb0fcb7dc4d66a94dee5bb46107ec935dafbc456407fcd53627
+internal/host/agent.go fastTick legacy accepted-legacy accepted-legacy;rev3=J1;basis=root-route;rev3=PROPOSED-s3-change-index;identity=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos);basis=observes the change index before any pass (observeIndex), runs the backstop's requested full pass and a scoped pass for moved app scopes (indexTick), and arms the canary pointer gate on the sweep (canaryPointerGate) only on a tick whose own index observation succeeded; read site unchanged, offset moved;rev3=census-ruling-stateless-replicas-1;basis=Call coordinator Tick on the existing tick before convergence; client renews held terms only at the pinned interval. Existing registry read unchanged. Final review I3: signal the owned renewal worker instead of waiting for its sequential console HTTP calls. Existing convergence and record read unchanged.;rev3=census-ruling-region-ha-p3a;basis=Run the optional desired-role reader on the existing tick after observing the armed change index; no new root path or timer, nil reader is unchanged.;rev3=census-ruling-stateless-replicas-2;basis=Slice 3b: signals the owned replica worker on the existing tick; coalesced asynchronous execution, no timer or bucket scan added. merge of origin/main 7920cccf: Retain main box-role reader pass on the existing tick alongside the replica worker signal; merge-only body change, unchanged read sites.;rev3=census-ruling-restart-new-box-gap;basis=calls the optional restartGain hook (restartGainSeed) once per existing tick before the serial read; no new root path, timer or read kind; nil hook is unchanged;rev3=census-ruling-agent-start-demo-3;basis=Refresh moved notices through the shared watch before normal convergence; no new per-box poll. Census read-site delta: unchanged (1).;rev3=census-ruling-stateless-replicas-4-task1;basis=Signals the owned replica swap worker (armedReplicaDeploy.tick) beside the placement worker on the existing tick; coalesced background pass, no timer, no bucket read. Its transitions go through the console's authenticated /deploy.;rev3=census-ruling-platform-mail-submission;basis=Task 4: on a serial move, after the schedule leg, starts the armed mail switch cache's Refresh on its own goroutine (each read bounded at 2 s, overlapping refreshes skipped). It re-reads the app sender records already cached, through the agent's deploy store. Agent, not root; the tick waits on nothing new. Fable final P2-1: on a serial move, before the pass set and the restart leg, calls the armed cache's MarkStale (a counter bump under the cache's mutex; no I/O), so a spawn the move causes reads the switch again, bounded, instead of using an answer from before the move. No read added.;rev3=census-ruling-fleet-first-reconcile-speed;basis=Startup timing log lines only: d.startup.done(<part>) calls between the existing parts and a deferred one after the sweep. d.startup is nil on every tick but the first after agent start, and its methods are then no-ops. No read added, no order change; read site unchanged (1). Agent, not root.;rev3=census-ruling-fleet-first-reconcile-speed-4;basis=Startup serial hold (whole-branch review P1). While fastDeps.serialAfter is open (fastBoot closes it when the restart and sidecar wake baselines have read) the tick skips its one ReadSerial of control/serial, so it neither seeds nor acts on a move; the rest of the tick (backstop full pass, index, sweep) is unchanged. A full pass run while held sets fullBeforeSeed, and the seed then sets fullDue once so the backstop branch runs one more full pass under the clamp. Same read, read sites unchanged (1); no read added. Agent, not root. registry:Host@7321 5e7b593089330e12933dac81b1ffab26a34edc0d65e355b530faed17c28f2e47
+internal/host/restart.go restartSeed authority E1,E3,J1,J4 fix1-merge-review;basis=Baselines both request logs without applying historical ordinary restarts; signed retry grants remain independently verified.;rev3=census-ruling-restart-new-box-gap;basis=body split: list routes then restartBaseline (the former body, unchanged); the route reads move with it;rev3=census-ruling-fleet-first-reconcile-speed-4;basis=List-error log line moved into logRestartListError (same text); body otherwise unchanged (reg.List then restartBaseline). Doc comment notes fastBoot calls it on the seeds' goroutine, ahead of the serial seed. No read added; agent, not root. whole:Route@221 5ee75ad73f3e2ed1d0ef3f3cd4c87c5b055cd9488e0e5a891f865079ebc97a40
+internal/host/sidecarwake.go sidecarWakeSeed legacy accepted-legacy accepted-legacy;rev3=J1;basis=root-route;rev3=census-ruling-fleet-first-reconcile-speed-4;basis=Body split: reg.List, then sidecarWakeBaseline (the former rest of the body, unchanged); list-error log line moved into logSidecarWakeListError (same text). No read added; agent, not root. whole:Route@226 2ab3e681cf37e2020c89971b0a9ce4da882053b37931308710dfcf2bee81cebc
+internal/host/fastboot.go fastBoot.seed legacy accepted-legacy accepted-legacy;rev3=census-ruling-fleet-first-reconcile-speed-4;basis=New (Task 4): the seeds moved out of fastConvergeLoop, same order. restartSeed is called directly (its own reg.List, then restartBaseline, as fastConvergeLoop called it before), sidecarWakeBaseline over the arming route snapshot (or the existing list-error line), then it closes the serial hold, waits for the views, and runs runRunsBootPass, sd.converge and systemLeg.observe (systemLeg.store swapped to the counting wrapper and restored), the last three through package func vars defaulting to them. A nil test hook (bootBeforeBaseline) precedes each baseline. Same calls and keys as before; no read added. Agent, not root. whole:Route@640 3ff89b37f97698583a97e56b72b7a2f36b6bc837991525dddd41f3eb7c8ee9eb
+internal/host/fastboot.go fastBoot.start legacy accepted-legacy accepted-legacy;rev3=census-ruling-fleet-first-reconcile-speed-4;basis=New (Task 4): the arming order moved out of fastConvergeLoop. One reg.List of this box's registry (the route snapshot for the sidecar baseline), starts the seeds goroutine first, then refreshMovesHolds and refreshOfflineView (through package func vars defaulting to them), sets fastDeps.serialAfter, runs the first tick, and returns ready, which waits for the seeds (one log line if over slowLegAfter), runs runRunsPass once (through bootRunsNotes; the same runs pass every full pass runs, for notes the first tick kept while the runs boot pass was unfinished), clears the serial hold and assigns the seeded legs to fastDeps. No read beyond those the moved calls and that existing runs pass already make. Agent, not root. whole:Route@408 37ce68db08a2099bf75e3082ac811a286d7ab3fed78f67baedf7819919a63d95
+internal/host/sidecarwake.go sidecarWakeBaseline legacy accepted-legacy accepted-legacy;rev3=census-ruling-fleet-first-reconcile-speed-4;basis=New: the former second half of sidecarWakeSeed over a given route list (sidecarWakeChanges on the box's own routes, read errors logged). The route values come from the caller's reg.List of this box's registry; no new read site. Agent, not root. whole:Route@158 44f8d730300282571787e2d2e7d59c8f8bb0f768045c44864a7860233370636e
+@coverage internal/host acb11853f3c614e9ac9d4758a1621d1d6c8a852803b8ada2a1c6e565ec34ed7e