carlos / platform Public

restart: baseline apps a box gains after arming, not at the first request

A fresh box arms its agent before reconcile mints routes, so the boot
seed saw no apps; the restart leg runs only on a serial move, so on a
quiet fleet the first `carlos restart` became the baseline and the box
cycled nothing (G2 drill on dev, 2026-11-05, holder i-00fcda37).

fastTick now runs restartGainSeed each tick: an app with no entry in
the agent restart memory is baselined as its route appears, via the
boot seed body (restartBaseline). Known entries are never overwritten,
retry grants are handled once, read errors back off a minute, and an
idle box reads nothing. Astra review READY; census approved.

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

Squashed from restart-new-box-gap into main.
claude agent, operated by paul@keymail.dev 94b50891009563e6167132057da0adb959e026e9 parent 40e1990
7 files changed, +575 −15
  • docs/superpowers/notes/census-proposal-restart-new-box-gap.md +29 −0
  • internal/host/agent.go +24 −12
  • internal/host/restart.go +163 −2
  • internal/host/restartgain_test.go +338 −0
  • internal/host/restartscope.go +6 −1
  • internal/provision/testdata/plan14-root-reads-chain.tsv +1 −0
  • internal/provision/testdata/plan14-root-reads-restart-new-box-gap.tsv +14 −0

CI passed — run details

diff --git a/docs/superpowers/notes/census-proposal-restart-new-box-gap.md b/docs/superpowers/notes/census-proposal-restart-new-box-gap.md
new file mode 100644
index 000000000..9361a7ee9
--- /dev/null
+++ b/docs/superpowers/notes/census-proposal-restart-new-box-gap.md
@@ -0,0 +1,29 @@
+# Census approval: restart-new-box-gap
+
+Ruling `census-ruling-restart-new-box-gap`. 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` `fastTick` | body | unchanged (1) | 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 |
+| `internal/host/agent.go` `fastConvergeLoop` | sites | -whole:Route | restart leg closure moved into armRestartLegs (same reg.List + restartRequestLeg); also wires restartGain; read moved, not added |
+| `internal/host/restart.go` `restartSeed` | sites | -whole:Route ×4 | body split: list routes then restartBaseline (the former body, unchanged); the route reads move with it |
+
+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` `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.
+- `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.
+- `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.
+
+New dispositions, which census-propose wrote and the reviewer checks against the unit's reads and the diff:
+
+- new `internal/host/restart.go:armRestartLegs`: reads +whole:Route ×2; written legacy, accepted-legacy, frozen
+- new `internal/host/restart.go:restartBaseline`: reads +whole:Route ×5; written legacy, accepted-legacy, frozen
+- new `internal/host/restart.go:restartGainSeed`: reads +registry:App, +whole:Route ×7; written legacy, accepted-legacy, frozen
+
+Seal: `c55b4a022b3d42f40a05b727f93e57dc9f76b6dc2251f7d3b777c34d7ffdee09` → `18e4df5f599a48a881526fc2f85a9b591e3ea8677bb297d5944c9d935771f5e6`.
+
+Overlay: `internal/provision/testdata/plan14-root-reads-restart-new-box-gap.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`.
diff --git a/internal/host/agent.go b/internal/host/agent.go
index c19058384..580fe602f 100644
--- a/internal/host/agent.go
+++ b/internal/host/agent.go
@@ -2652,6 +2652,11 @@ type fastDeps struct {
// read returned (canaryHeads). nil: every pointer is read, as before.
canaryGate *release.ReadGate
canaryHeads map[[3]string]canaryRead // (account, app, channel) -> its group's last good read
+
+ // restartGain baselines, on every tick, the apps this box gained since
+ // the agent armed (restartGainSeed), so the first restart request after
+ // a fresh box comes up is acted on. nil = not armed.
+ restartGain func(ctx context.Context, now time.Time)
}
// canaryRead is one canary group's last good pointer read: the head it
@@ -3104,6 +3109,14 @@ func fastTick(ctx context.Context, d *fastDeps, now time.Time) {
// at least what was observed and indexActed can take it afterwards.
obs, indexOK := d.observeIndex(ctx)
armedBoxRoleReader.Load().pass(ctx, now)
+ // Before the serial read, on every tick: an app this box gained since the
+ // agent armed gets its restart baseline now, while nobody has asked for
+ // anything, rather than on the serial move that carries the first request
+ // (restartGainSeed). It reads the store only for an app it has no entry
+ // for.
+ if d.restartGain != nil {
+ d.restartGain(ctx, now)
+ }
fullRan := false
doc, _, err := release.ReadSerial(ctx, d.store)
switch {
@@ -3433,8 +3446,8 @@ func fastConvergeLoop(reg *registry.Registry, svc *activator.Service, sd *schedu
// The restart check's memory (issue #113, narrowed requests added by
// discussion #16), seeded ONCE here — two reads per app at arming (the
// app-wide generation and the narrowed request log) and never again except
- // on a serial move, which is what keeps an idle box at exactly one serial
- // GET per tick. See restartSeed for why the baseline cannot wait for the
+ // 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
// first request to establish itself.
restartMem := newRestartMemory()
// `carlos instances retry` (zero-downtime spec §8.4) reaches the rollout
@@ -3456,8 +3469,13 @@ func fastConvergeLoop(reg *registry.Registry, svc *activator.Service, sd *schedu
})
}
restartSeed(ctx, reg, store, dd, restartMem)
- restartBounce := bounceFn(svc)
- restartWake := wakeFn(svc)
+ // 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.
+ restartGain, restartLeg := armRestartLegs(reg, store, dd, restartMem, bounceFn(svc), wakeFn(svc))
// 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
@@ -3520,14 +3538,8 @@ func fastConvergeLoop(reg *registry.Registry, svc *activator.Service, sd *schedu
// 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 = func(ctx context.Context) {
- routes, err := reg.List()
- if err != nil {
- log.Printf("agent: restart check: list routes: %v", err)
- return
- }
- restartRequestLeg(ctx, routes, store, dd, restartBounce, restartWake, restartMem)
- }
+ 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
diff --git a/internal/host/restart.go b/internal/host/restart.go
index aa068d862..6d042b7d4 100644
--- a/internal/host/restart.go
+++ b/internal/host/restart.go
@@ -50,6 +50,7 @@ import (
"errors"
"fmt"
"log"
+ "maps"
"os"
"path/filepath"
"time"
@@ -939,11 +940,29 @@ func restartSeed(ctx context.Context, reg *registry.Registry, store release.Stor
log.Printf("agent: restart baseline: list routes: %v (the first request may need a second try)", err)
return
}
+ restartBaseline(ctx, routes, store, dd, mem)
+}
+
+// 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
+// its baseline (or ask it to complete one). restartGainSeed runs it again,
+// later, over just the apps a box gained after arming.
+func restartBaseline(ctx context.Context, routes []registry.Route, store release.Store, dd string, mem *restartMemory) {
_, readErrs := restartGenPass(ctx, routes, store, mem.gen)
// A first sight cycles nothing, but it hands over the retry grants in
// both logs: they are not seed-skipped (Astra plan 9), so a grant
// written before this agent started, and not yet applied, is applied
// now. A grant spent or made stale since clears nothing.
+ //
+ // Which apps this pass is FIRST to see is taken before it runs: a
+ // position the memory already held is not a first sight, even when the
+ // pass reports its retries as history because that position fell out of
+ // the log. That case is the restart leg's (Astra fix check, 2026-11-06).
+ known := make(map[[2]string]bool, len(mem.scope))
+ for k := range mem.scope {
+ known[k] = true
+ }
scoped, scopeErrs := restartScopePass(ctx, routes, store, mem.scope)
readErrs = append(readErrs, scopeErrs...)
grants, grantErrs := hostRetryPass(ctx, routes, store, mem)
@@ -957,7 +976,20 @@ func restartSeed(ctx context.Context, reg *registry.Registry, store release.Stor
// A box with nothing that could clear a hold reads every legacy
// retry at its start as history, silently, as it always has: its
// line would only say, at every start, that nothing is held.
- applyRetries(routes, scoped, mem)
+ //
+ // First sights only: a baseline hands over what an app it has
+ // never seen holds. At arming every app is a first sight;
+ // restartGainSeed's scratch memory carries the positions the
+ // agent already holds, and anything past one of those (movement,
+ // or a position lost from the log) is the restart leg's to
+ // handle, once, on its serial move.
+ var history []scopedRestart
+ for _, w := range scoped {
+ if w.history && !known[w.app] {
+ history = append(history, w)
+ }
+ }
+ applyRetries(routes, history, mem)
}
if len(readErrs) > 0 {
log.Printf("agent: restart baseline: %d apps unreadable: %v", len(readErrs), readErrs[0])
@@ -978,5 +1010,134 @@ func restartSeed(ctx context.Context, reg *registry.Registry, store release.Stor
return
}
log.Printf("agent: restart baseline: the root pass has no narrowed-restart mark for at least one app on this box " +
- "(a marks file written before narrowed restarts existed) — asked for one root pass to record it")
+ "(a marks file written before narrowed restarts existed, or an app the root pass has not seen yet) — asked for one root pass to record it")
+}
+
+// restartGainRetry is how long restartGainSeed leaves an app alone after one
+// of its objects could not be read: long enough that a bucket refusing every
+// read costs a few GETs a minute per app rather than a few every tick, short
+// enough that a blip is over before anybody types `carlos restart`.
+const restartGainRetry = time.Minute
+
+// restartGainSeed baselines every app this box serves that the agent's memory
+// has no entry for yet: the apps whose first route landed AFTER restartSeed
+// ran. fastTick runs it on every tick, and on almost every tick it reads
+// nothing, because the memory already holds every app in the route set.
+//
+// The case it exists for is a fresh box. Its agent arms before reconcile has
+// minted a single route (the G2 replacement box on dev, 2026-11-05, logged
+// "reloaded (0 route(s))" at arming and minted its instance two seconds
+// later), so restartSeed sees no apps and records nothing. The restart leg
+// runs only on a serial MOVE, so on a quiet fleet the first time that box
+// ever reads the app's objects is the move a `carlos restart` makes, and a
+// first sight is a seed. The console answered "restart requested", every
+// other box cycled, and the new box took the request as its baseline and did
+// nothing. Any other serial bump in between closes the gap by luck; a quiet
+// fleet leaves it open for as long as it stays quiet.
+//
+// Seeding when the route appears applies the seed-don't-replay rule at the
+// right moment rather than changing it: whatever the objects say when a box
+// gains an app is history its freshly started process does not owe anybody,
+// and anything recorded after that is movement. A request that lands inside
+// the one tick between a route's mint and this sweep is still taken as the
+// baseline: the same window restartSeed leaves at boot, now a couple of
+// seconds wide instead of open-ended.
+//
+// The sweep is restartBaseline over the gained apps' routes, into a scratch
+// memory, merged back only where the memory has no entry. An entry the
+// memory already holds is never overwritten, because a later value there is
+// exactly the movement the leg exists to see. An app with an object that did
+// not read keeps what did read and is tried again after restartGainRetry.
+func restartGainSeed(ctx context.Context, routes []registry.Route, store release.Store, dd string, mem *restartMemory, now time.Time) (seeded int) {
+ gained := map[[2]string]bool{}
+ for _, k := range restartApps(routes) {
+ _, haveGen := mem.gen[k]
+ _, haveScope := mem.scope[k]
+ if (haveGen && haveScope) || now.Before(mem.notBefore[k]) {
+ continue
+ }
+ gained[k] = true
+ }
+ if len(gained) == 0 {
+ return 0
+ }
+ var sub []registry.Route
+ for _, rt := range routes {
+ if gained[[2]string{release.RouteAccount(rt), rt.App}] {
+ sub = append(sub, rt)
+ }
+ }
+ // The scratch memory starts from what the agent already holds for these
+ // apps, so a retry with one half unreadable handles nothing twice: a
+ // known narrowed position is not a first sight (its legacy retries are
+ // not handed over again), and host-retry ids already handled stay
+ // handled. Only an app's missing halves are first sights.
+ scratch := newRestartMemory()
+ scratch.retryHost, scratch.pub = mem.retryHost, mem.pub
+ for k := range gained {
+ if v, ok := mem.gen[k]; ok {
+ scratch.gen[k] = v
+ }
+ if v, ok := mem.scope[k]; ok {
+ scratch.scope[k] = v
+ }
+ if ids, ok := mem.retries[k]; ok {
+ scratch.retries[k] = maps.Clone(ids)
+ }
+ }
+ restartBaseline(ctx, sub, store, dd, scratch)
+ for k := range gained {
+ gen, genRead := scratch.gen[k]
+ if _, have := mem.gen[k]; !have && genRead {
+ mem.gen[k] = gen
+ }
+ id, scopeRead := scratch.scope[k]
+ if _, have := mem.scope[k]; !have && scopeRead {
+ mem.scope[k] = id
+ }
+ if ids, ok := scratch.retries[k]; ok {
+ if mem.retries[k] == nil {
+ mem.retries[k] = map[string]bool{}
+ }
+ for id := range ids {
+ mem.retries[k][id] = true
+ }
+ }
+ if !genRead || !scopeRead {
+ mem.notBefore[k] = now.Add(restartGainRetry)
+ continue
+ }
+ delete(mem.notBefore, k)
+ seeded++
+ }
+ return seeded
+}
+
+// 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.
+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) {
+ routes, err := reg.List()
+ if err != nil {
+ return // the leg reports a registry it cannot list; once is enough
+ }
+ if n := restartGainSeed(ctx, routes, store, dd, mem, now); n > 0 {
+ log.Printf("agent: restart baseline: recorded %d app(s) this box gained since arming", n)
+ }
+ }
+ leg = func(ctx context.Context) {
+ routes, err := reg.List()
+ if err != nil {
+ log.Printf("agent: restart check: list routes: %v", err)
+ return
+ }
+ restartRequestLeg(ctx, routes, store, dd, bounce, wake, mem)
+ }
+ return gain, leg
}
diff --git a/internal/host/restartgain_test.go b/internal/host/restartgain_test.go
new file mode 100644
index 000000000..be43321a1
--- /dev/null
+++ b/internal/host/restartgain_test.go
@@ -0,0 +1,338 @@
+package host
+
+import (
+ "context"
+ "errors"
+ "fmt"
+ "os"
+ "path/filepath"
+ "slices"
+ "testing"
+ "time"
+
+ "github.com/carlosframework/platform/internal/registry"
+ "github.com/carlosframework/platform/internal/release"
+)
+
+// TestFastTickActsOnTheFirstRestartAfterAFreshBoxGainsItsRoute is the G2
+// replacement box on dev (2026-11-05), through the production wiring:
+// restartSeed and armRestartLegs exactly as fastConvergeLoop calls them,
+// fastTick, a real registry and a real store.
+//
+// The agent arms with an empty registry, reconcile mints the instance a
+// moment later, and the fleet stays quiet: no serial bump until somebody
+// types `carlos restart --host`. That bump is the first serial move this box
+// has seen, so before the gain seed the restart leg met the app for the first
+// time on the very move that carried the request, took the request as its
+// baseline, and bounced nothing, while every other box cycled.
+func TestFastTickActsOnTheFirstRestartAfterAFreshBoxGainsItsRoute(t *testing.T) {
+ ctx := context.Background()
+ f := newFastFixture(t)
+ dd := f.dataDir
+
+ mem := newRestartMemory()
+ restartSeed(ctx, f.reg, f.store, dd, mem) // arming: the registry is still empty
+ var bounced []string
+ bounce := func(h string) bool { bounced = append(bounced, h); return true }
+ gain, leg := armRestartLegs(f.reg, f.store, dd, mem, bounce, nil)
+ d := f.deps(func() {})
+ d.restartLeg, d.restartGain = leg, gain
+
+ now := time.Unix(1762382167, 0)
+ fastTick(ctx, d, now) // seeds the serial
+
+ // Reconcile mints the instance off the serial path, two seconds after arming.
+ host := "one.example.com"
+ if err := f.reg.Upsert(execRoute(host, "bab", "shop")); err != nil {
+ t.Fatalf("upsert: %v", err)
+ }
+ for i := 1; i <= 3; i++ { // quiet fleet: ticks, no serial move
+ fastTick(ctx, d, now.Add(time.Duration(i)*2*time.Second))
+ }
+
+ askScoped(t, ctx, f.store, "bab", "shop", release.RestartScopeHost, host)
+ 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{host}) {
+ t.Fatalf("bounced %v after the first narrowed restart, want [%s]: the request was taken as the baseline", bounced, host)
+ }
+ if _, err := os.Stat(filepath.Join(dd, restartRequestMarker)); err != nil {
+ t.Fatalf("no root-pass marker after the request: %v", err)
+ }
+}
+
+// TestFastTickActsOnTheFirstAppWideRestartAfterAFreshBoxGainsItsRoute is the
+// same gap through the app-wide signal: `carlos restart --app` on a quiet
+// fleet, with a box that gained the app after arming.
+func TestFastTickActsOnTheFirstAppWideRestartAfterAFreshBoxGainsItsRoute(t *testing.T) {
+ ctx := context.Background()
+ f := newFastFixture(t)
+ mem := newRestartMemory()
+ restartSeed(ctx, f.reg, f.store, f.dataDir, mem)
+ var bounced []string
+ gain, leg := armRestartLegs(f.reg, f.store, f.dataDir, mem, func(h string) bool { bounced = append(bounced, h); return true }, nil)
+ d := f.deps(func() {})
+ d.restartLeg, d.restartGain = leg, gain
+
+ now := time.Unix(1762382167, 0)
+ fastTick(ctx, d, now)
+ if err := f.reg.Upsert(execRoute("one.example.com", "bab", "shop")); err != nil {
+ t.Fatalf("upsert: %v", err)
+ }
+ fastTick(ctx, d, now.Add(2*time.Second))
+
+ if err := release.TouchRestartGen(ctx, f.store, "bab", "shop"); err != nil {
+ t.Fatalf("touch restart gen: %v", err)
+ }
+ 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{"one.example.com"}) {
+ t.Fatalf("bounced %v, want the gained app's instance", bounced)
+ }
+}
+
+// TestRestartGainSeedNeverOverwritesAnEntry: an app the memory already holds
+// keeps its entry even when its object has moved since, because that later
+// value is the movement the leg exists to see. Only the app with no entry is
+// read and recorded.
+func TestRestartGainSeedNeverOverwritesAnEntry(t *testing.T) {
+ ctx, s := genKit(t)
+ dd := t.TempDir()
+ known := []registry.Route{execRoute("a.example.com", "bab", "shop")}
+ mem := newRestartMemory()
+ restartBaseline(ctx, known, s, dd, mem)
+ before := mem.gen[[2]string{"bab", "shop"}]
+
+ if err := release.TouchRestartGen(ctx, s, "bab", "shop"); err != nil {
+ t.Fatalf("touch: %v", err)
+ }
+ both := append(known, execRoute("b.example.com", "bab", "cafe"))
+ if n := restartGainSeed(ctx, both, s, dd, mem, time.Now()); n != 1 {
+ t.Fatalf("seeded %d apps, want 1 (only the gained one)", n)
+ }
+ if got := mem.gen[[2]string{"bab", "shop"}]; got != before {
+ t.Fatalf("the gain seed overwrote a known app's mark: %q -> %q", before, got)
+ }
+ if _, ok := mem.scope[[2]string{"bab", "cafe"}]; !ok {
+ t.Fatal("the gained app has no narrowed mark")
+ }
+ var bounced []string
+ if !restartRequestLeg(ctx, both, s, dd, func(h string) bool { bounced = append(bounced, h); return true }, nil, mem) {
+ t.Fatal("the known app's restart was lost")
+ }
+ if !slices.Equal(bounced, []string{"a.example.com"}) {
+ t.Fatalf("bounced %v, want only the app that was asked", bounced)
+ }
+}
+
+// TestRestartGainSeedReadsNothingAtRest: with every app in memory a tick
+// costs no store read, which is what keeps an idle box at one serial GET per
+// tick.
+func TestRestartGainSeedReadsNothingAtRest(t *testing.T) {
+ ctx, base := genKit(t)
+ dd := t.TempDir()
+ routes := []registry.Route{execRoute("a.example.com", "bab", "shop")}
+ mem := newRestartMemory()
+ restartBaseline(ctx, routes, base, dd, mem)
+ cs := &countingStore{Store: base}
+ if n := restartGainSeed(ctx, routes, cs, dd, mem, time.Now()); n != 0 {
+ t.Fatalf("seeded %d apps at rest", n)
+ }
+ if len(cs.gets) != 0 {
+ t.Fatalf("store reads at rest: %v", cs.gets)
+ }
+}
+
+// TestRestartGainSeedBacksOffAnUnreadableApp: an object that will not read is
+// tried again after restartGainRetry, not on every tick, and the half that
+// did read is kept.
+func TestRestartGainSeedBacksOffAnUnreadableApp(t *testing.T) {
+ ctx, base := genKit(t)
+ dd := t.TempDir()
+ routes := []registry.Route{execRoute("a.example.com", "bab", "shop")}
+ fs := &failingKeyStore{Store: base, failKey: release.RestartScopeKey("bab", "shop"), err: errors.New("503 slow down")}
+ cs := &countingStore{Store: fs}
+ mem := newRestartMemory()
+ now := time.Now()
+ k := [2]string{"bab", "shop"}
+
+ if n := restartGainSeed(ctx, routes, cs, dd, mem, now); n != 0 {
+ t.Fatalf("seeded %d apps with the log unreadable", n)
+ }
+ if _, ok := mem.gen[k]; !ok {
+ t.Fatal("the generation that did read was dropped")
+ }
+ if _, ok := mem.scope[k]; ok {
+ t.Fatal("an unreadable log was recorded")
+ }
+ reads := cs.gets[release.RestartScopeKey("bab", "shop")]
+ restartGainSeed(ctx, routes, cs, dd, mem, now.Add(2*time.Second))
+ if got := cs.gets[release.RestartScopeKey("bab", "shop")]; got != reads {
+ t.Fatalf("retried inside the back-off: %d reads, want %d", got, reads)
+ }
+
+ fs.failKey = ""
+ if n := restartGainSeed(ctx, routes, cs, dd, mem, now.Add(restartGainRetry)); n != 1 {
+ t.Fatalf("seeded %d apps after the back-off, want 1", n)
+ }
+ if mem.scope[k] != release.RestartScopeNone {
+ t.Fatalf("narrowed mark %q, want none", mem.scope[k])
+ }
+}
+
+// TestRestartGainSeedKeepsTheHalfItAlreadyHas: an app whose generation was
+// recorded and whose request log was not is read again for the log alone. A
+// generation that moved in between is a request, and must reach the leg as
+// one rather than being re-read into the baseline.
+func TestRestartGainSeedKeepsTheHalfItAlreadyHas(t *testing.T) {
+ ctx, base := genKit(t)
+ dd := t.TempDir()
+ routes := []registry.Route{execRoute("a.example.com", "bab", "shop")}
+ fs := &failingKeyStore{Store: base, failKey: release.RestartScopeKey("bab", "shop"), err: errors.New("503 slow down")}
+ mem := newRestartMemory()
+ now := time.Now()
+ restartGainSeed(ctx, routes, fs, dd, mem, now) // generation recorded, log not
+ k := [2]string{"bab", "shop"}
+ before, ok := mem.gen[k]
+ if !ok {
+ t.Fatal("no generation mark after the first try")
+ }
+
+ if err := release.TouchRestartGen(ctx, base, "bab", "shop"); err != nil {
+ t.Fatalf("touch: %v", err)
+ }
+ fs.failKey = ""
+ if n := restartGainSeed(ctx, routes, fs, dd, mem, now.Add(restartGainRetry)); n != 1 {
+ t.Fatalf("seeded %d apps, want 1", n)
+ }
+ if mem.gen[k] != before {
+ t.Fatalf("the retry re-read the generation into the baseline: %q -> %q", before, mem.gen[k])
+ }
+ var bounced []string
+ if !restartRequestLeg(ctx, routes, fs, dd, func(h string) bool { bounced = append(bounced, h); return true }, nil, mem) {
+ t.Fatal("the app-wide request made between the two tries was lost")
+ }
+ if !slices.Equal(bounced, []string{"a.example.com"}) {
+ t.Fatalf("bounced %v", bounced)
+ }
+}
+
+// TestRestartGainSeedHandlesEachRetryGrantOnce is Astra round 1's P2, both
+// rows: an app whose baseline keeps failing on ONE object is retried every
+// restartGainRetry, and each retry must not hand over again the grants an
+// earlier attempt already handled, from either log. A grant and a restart
+// that land between attempts are still new work: the grant is handled once,
+// and the restart reaches the leg.
+func TestRestartGainSeedHandlesEachRetryGrantOnce(t *testing.T) {
+ for _, tc := range []struct {
+ name string
+ failKey string
+ }{
+ {"host-retry log, narrowed log unreadable", release.RestartScopeKey("bab", "shop")},
+ {"legacy narrowed log, generation unreadable", release.RestartGenKey("bab", "shop")},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ ctx, base := genKit(t)
+ dd := t.TempDir()
+ routes := []registry.Route{execRoute("a.example.com", "bab", "shop")}
+ mem, priv := retryMemory(t)
+ var retried []string
+ mem.retryHost = func(h, b, bk string, e uint64) bool {
+ retried = append(retried, fmt.Sprintf("%s %s %d", h, b, e))
+ return false
+ }
+ legacy := tc.failKey == release.RestartGenKey("bab", "shop")
+ if legacy {
+ legacySignedRetry(t, ctx, base, priv, "bab", "shop", "a.example.com", "v2", "bk", 5)
+ } else {
+ askRetry(t, ctx, base, priv, "bab", "shop", "a.example.com", "v2", "bk", 5)
+ }
+ fs := &failingKeyStore{Store: base, failKey: tc.failKey, err: errors.New("503 slow down")}
+ now := time.Now()
+ restartBaseline(ctx, routes, fs, dd, mem) // arming: one half unreadable
+ restartGainSeed(ctx, routes, fs, dd, mem, now)
+ restartGainSeed(ctx, routes, fs, dd, mem, now.Add(restartGainRetry))
+ if want := []string{"a.example.com v2 5"}; !slices.Equal(retried, want) {
+ t.Fatalf("handled %v across three attempts, want %v once", retried, want)
+ }
+
+ // New work between attempts: a second grant (host-retry log) and
+ // an app-wide restart.
+ if !legacy {
+ askRetry(t, ctx, base, priv, "bab", "shop", "a.example.com", "v3", "bk", 6)
+ }
+ if err := release.TouchRestartGen(ctx, base, "bab", "shop"); err != nil {
+ t.Fatalf("touch: %v", err)
+ }
+ fs.failKey = ""
+ if n := restartGainSeed(ctx, routes, fs, dd, mem, now.Add(2*restartGainRetry)); n != 1 {
+ t.Fatalf("seeded %d apps once the object read, want 1", n)
+ }
+ var bounced []string
+ restartRequestLeg(ctx, routes, fs, dd, func(h string) bool { bounced = append(bounced, h); return true }, nil, mem)
+ want := []string{"a.example.com v2 5"}
+ if !legacy {
+ want = append(want, "a.example.com v3 6")
+ }
+ if !slices.Equal(retried, want) {
+ t.Fatalf("handled %v, want %v (each grant once, the new one included)", retried, want)
+ }
+ if legacy {
+ // The generation was unreadable at the baseline, so its first
+ // readable value is the baseline: the touch above is history.
+ return
+ }
+ if !slices.Equal(bounced, []string{"a.example.com"}) {
+ t.Fatalf("bounced %v: the app-wide restart made between attempts was lost", bounced)
+ }
+ })
+ }
+}
+
+// TestRestartGainSeedLeavesALostPositionToTheLeg is the Astra fix check's
+// residual case: the agent holds a narrowed position, the generation will
+// not read, and the log grows past its bound so that position falls out of
+// it, with a signed legacy retry among the new entries. The scope pass
+// reports that log as history, but it is not a first sight for this memory:
+// the gain retries must hand nothing over, and the restart leg handles the
+// grant exactly once.
+func TestRestartGainSeedLeavesALostPositionToTheLeg(t *testing.T) {
+ ctx, base := genKit(t)
+ dd := t.TempDir()
+ host := "a.example.com"
+ routes := []registry.Route{execRoute(host, "bab", "shop")}
+ mem, priv := retryMemory(t)
+ calls := 0
+ mem.retryHost = func(string, string, string, uint64) bool { calls++; return false }
+
+ askScoped(t, ctx, base, "bab", "shop", release.RestartScopeHost, host)
+ fs := &failingKeyStore{Store: base, failKey: release.RestartGenKey("bab", "shop"), err: errors.New("503 slow down")}
+ restartBaseline(ctx, routes, fs, dd, mem) // position recorded, generation not
+ if _, ok := mem.scope[[2]string{"bab", "shop"}]; !ok {
+ t.Fatal("no narrowed position after the baseline")
+ }
+
+ for i := 0; i < 31; i++ {
+ askScoped(t, ctx, base, "bab", "shop", release.RestartScopeHost, "other.example.com")
+ }
+ legacySignedRetry(t, ctx, base, priv, "bab", "shop", host, "v2", "bk", 5)
+ askScoped(t, ctx, base, "bab", "shop", release.RestartScopeHost, "other.example.com")
+
+ now := time.Now()
+ restartGainSeed(ctx, routes, fs, dd, mem, now)
+ restartGainSeed(ctx, routes, fs, dd, mem, now.Add(restartGainRetry))
+ if calls != 0 {
+ t.Fatalf("the gain seed handled %d grants past a position it already held, want 0 (the leg's)", calls)
+ }
+ bounce := func(string) bool { return true }
+ restartRequestLeg(ctx, routes, fs, dd, bounce, nil, mem)
+ restartRequestLeg(ctx, routes, fs, dd, bounce, nil, mem)
+ if calls != 1 {
+ t.Fatalf("handled the grant %d times in all, want once", calls)
+ }
+}
diff --git a/internal/host/restartscope.go b/internal/host/restartscope.go
index 0256d01bb..11bd319d2 100644
--- a/internal/host/restartscope.go
+++ b/internal/host/restartscope.go
@@ -70,10 +70,15 @@ type restartMemory struct {
// every retry's grant is verified against (spec §11). Nil drops every
// retry: a box that cannot tell a grant from a forgery clears nothing.
pub ed25519.PublicKey
+ // notBefore throttles restartGainSeed's retries after a read error, per
+ // app, so an object that will not read is not asked for on every tick.
+ // Nothing else reads it.
+ notBefore map[[2]string]time.Time
}
func newRestartMemory() *restartMemory {
- return &restartMemory{gen: map[[2]string]string{}, scope: map[[2]string]string{}, retries: map[[2]string]map[string]bool{}}
+ return &restartMemory{gen: map[[2]string]string{}, scope: map[[2]string]string{}, retries: map[[2]string]map[string]bool{},
+ notBefore: map[[2]string]time.Time{}}
}
// scopedRestart is one app's outstanding narrowed work: the requests this box
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv
index 578b1aef3..1768ce744 100644
--- a/internal/provision/testdata/plan14-root-reads-chain.tsv
+++ b/internal/provision/testdata/plan14-root-reads-chain.tsv
@@ -103,3 +103,4 @@ plan14-root-reads-agent-start-demo-analytics-fix.tsv 89841c50d08090185e24cb03c6b
plan14-root-reads-agent-start-demo-log-skip.tsv ed24b69243622fc702159e0b22c732f4f8297438b87f10c499887cd1a13f6fce
plan14-root-reads-demo-api-site-route.tsv 9bfd77d30d8e3deb5f3863cb6c272c2cb46ce32aa1370acbaa6e9181b71101b4
plan14-root-reads-region-ha-p3b2-rolls.tsv c55b4a022b3d42f40a05b727f93e57dc9f76b6dc2251f7d3b777c34d7ffdee09
+plan14-root-reads-restart-new-box-gap.tsv 18e4df5f599a48a881526fc2f85a9b591e3ea8677bb297d5944c9d935771f5e6
diff --git a/internal/provision/testdata/plan14-root-reads-restart-new-box-gap.tsv b/internal/provision/testdata/plan14-root-reads-restart-new-box-gap.tsv
new file mode 100644
index 000000000..866426594
--- /dev/null
+++ b/internal/provision/testdata/plan14-root-reads-restart-new-box-gap.tsv
@@ -0,0 +1,14 @@
+# Census overlay restart-new-box-gap, written by census-propose (#369). census-ruling-restart-new-box-gap, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-restart-new-box-gap.md.
+# 1 body, 2 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 f9901119aae0b7e5bc177c1075a6561e3fc15c272ce24c1156eda08bc471c8fd 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 registry:Host@5265 139e8bee2561c0c4f5c5ff41594c87337f06904c9dc061ed647ffe506ae7f744
+@legacy 88f3281650a151b50649d98a03ff403d00e6b85168782683b8f5974b730988d8 internal/host/restart.go armRestartLegs legacy accepted-legacy accepted-legacy;rev3=census-ruling-restart-new-box-gap;basis=agent-side closures over reg.List for the gain seed and the existing restart leg; same reads the old fastConvergeLoop closure made whole:Route@448,whole:Route@766 1a6e4782f8769840153ed55f2851bde005cdcdaa17a4666b57e82269a29d12a9
+@legacy ff9138a274d754572f76d22dccff3e11c0c10e6a9392e58353e168bc788de69d internal/host/restart.go restartBaseline legacy accepted-legacy accepted-legacy;rev3=census-ruling-restart-new-box-gap;basis=the former restartSeed body over a given route set (both logs, retry grants, seedRestartMarks/marker); legacy retries applied only for apps with no narrowed position before the pass (Astra r1 P2 + fix check), which at arming is every app whole:Route@1293,whole:Route@157,whole:Route@2055,whole:Route@889,whole:Route@999 642ef0cc4d27f87b59a3e52f9952dba1db6c7bd53533020331ff14777aae5584
+@legacy 62b0eec4d5dd673a8ad1debb4e0c39270aeaa2707fe1d28d5898adfce1c94033 internal/host/restart.go restartGainSeed legacy accepted-legacy accepted-legacy;rev3=census-ruling-restart-new-box-gap;basis=baselines apps gained since arming via restartBaseline over those apps routes, into a scratch memory prefilled with the positions and handled retry ids already held (Astra r1 P2); merges only missing entries; throttles read errors; agent process, no root read registry:App@520,whole:Route@1246,whole:Route@212,whole:Route@463,whole:Route@515,whole:Route@534,whole:Route@547,whole:Route@552 be303c5bf5551ebcc9c45b5078d1b8e7b436c9008c07717bf0af3645575308cc
+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 registry:Host@5265 139e8bee2561c0c4f5c5ff41594c87337f06904c9dc061ed647ffe506ae7f744
+internal/host/restart.go armRestartLegs legacy accepted-legacy accepted-legacy;rev3=census-ruling-restart-new-box-gap;basis=agent-side closures over reg.List for the gain seed and the existing restart leg; same reads the old fastConvergeLoop closure made whole:Route@448,whole:Route@766 1a6e4782f8769840153ed55f2851bde005cdcdaa17a4666b57e82269a29d12a9
+internal/host/restart.go restartBaseline legacy accepted-legacy accepted-legacy;rev3=census-ruling-restart-new-box-gap;basis=the former restartSeed body over a given route set (both logs, retry grants, seedRestartMarks/marker); legacy retries applied only for apps with no narrowed position before the pass (Astra r1 P2 + fix check), which at arming is every app whole:Route@1293,whole:Route@157,whole:Route@2055,whole:Route@889,whole:Route@999 642ef0cc4d27f87b59a3e52f9952dba1db6c7bd53533020331ff14777aae5584
+internal/host/restart.go restartGainSeed legacy accepted-legacy accepted-legacy;rev3=census-ruling-restart-new-box-gap;basis=baselines apps gained since arming via restartBaseline over those apps routes, into a scratch memory prefilled with the positions and handled retry ids already held (Astra r1 P2); merges only missing entries; throttles read errors; agent process, no root read registry:App@520,whole:Route@1246,whole:Route@212,whole:Route@463,whole:Route@515,whole:Route@534,whole:Route@547,whole:Route@552 be303c5bf5551ebcc9c45b5078d1b8e7b436c9008c07717bf0af3645575308cc
+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 whole:Route@8609 d10becd47ccedd2d01c6fdb3933882872932e6592410d7c318dbc1390685eb4c
+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 whole:Route@298 b89f5767a539a57160f27d58f80ae2904c5993eeb1177563ed80aec63da632e1
+@coverage internal/host 53016f44b4a5f467b1c5a1c362dabbca557c3c4036cde8140ea7aaf3552b0af3