restart gain seed: handle each retry grant once (Astra r1 P2)
A gained app with one object unreadable is retried every minute, and each retry ran restartBaseline over an empty scratch memory: the same host-retry and legacy grants were handed over again on every attempt. The scratch memory now starts from the positions and handled retry ids the agent already holds, and restartBaseline applies legacy retries from first-sight history only (every entry at arming, as before). New grants and restarts landing between attempts are still handled once.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5 files changed,
+110
−8
docs/superpowers/notes/census-proposal-restart-new-box-gap.md+1 −1internal/host/restart.go+30 −1internal/host/restartgain_test.go+73 −0internal/provision/testdata/plan14-root-reads-chain.tsv+1 −1internal/provision/testdata/plan14-root-reads-restart-new-box-gap.tsv+5 −5
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| index a326fbe49..d45e79503 100644 |
| --- a/docs/superpowers/notes/census-proposal-restart-new-box-gap.md |
| +++ b/docs/superpowers/notes/census-proposal-restart-new-box-gap.md |
| @@ -24,6 +24,6 @@ New dispositions, which census-propose wrote and the reviewer checks against the |
| - 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` → `f7a78f567175fe0b6eed79095d3709c1c8ba0e85d66581af59c5ef2d755e7eac`. |
| +Seal: `c55b4a022b3d42f40a05b727f93e57dc9f76b6dc2251f7d3b777c34d7ffdee09` → `b9e3f3200199930d966a2453fe7f151926446850c35cf9f5626b682558fc17ec`. |
| 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/restart.go b/internal/host/restart.go| index 5e9bf0a0b..d7a997355 100644 |
| --- a/internal/host/restart.go |
| +++ b/internal/host/restart.go |
| @@ -50,6 +50,7 @@ import ( |
| "errors" |
| "fmt" |
| "log" |
| + "maps" |
| "os" |
| "path/filepath" |
| "time" |
| @@ -966,7 +967,19 @@ func restartBaseline(ctx context.Context, routes []registry.Route, store release |
| // 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) |
| + // |
| + // History only: a baseline hands over what a FIRST sight finds. |
| + // At arming every entry is a first sight; restartGainSeed's |
| + // scratch memory carries the positions the agent already holds, |
| + // and movement past one of those is the restart leg's to handle, |
| + // once, on its serial move. |
| + var history []scopedRestart |
| + for _, w := range scoped { |
| + if w.history { |
| + 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]) |
| @@ -1044,8 +1057,24 @@ func restartGainSeed(ctx context.Context, routes []registry.Route, store release |
| 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] |
diff --git a/internal/host/restartgain_test.go b/internal/host/restartgain_test.go| index 6be5a3da9..5d4c1143a 100644 |
| --- a/internal/host/restartgain_test.go |
| +++ b/internal/host/restartgain_test.go |
| @@ -3,6 +3,7 @@ package host |
| import ( |
| "context" |
| "errors" |
| + "fmt" |
| "os" |
| "path/filepath" |
| "slices" |
| @@ -220,3 +221,75 @@ func TestRestartGainSeedKeepsTheHalfItAlreadyHas(t *testing.T) { |
| 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) |
| + } |
| + }) |
| + } |
| +} |
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv| index 45811b84c..8d0c25e6e 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-chain.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-chain.tsv |
| @@ -103,4 +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 f7a78f567175fe0b6eed79095d3709c1c8ba0e85d66581af59c5ef2d755e7eac |
| +plan14-root-reads-restart-new-box-gap.tsv b9e3f3200199930d966a2453fe7f151926446850c35cf9f5626b682558fc17ec |
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| index 433604c92..4b1ef15ca 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-restart-new-box-gap.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-restart-new-box-gap.tsv |
| @@ -3,12 +3,12 @@ |
| # 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 01318bb14200b8e137212e4aaf567e5be7bfaa694975d81ba53ea339098d31f1 internal/host/restart.go restartBaseline legacy accepted-legacy accepted-legacy;rev3=census-ruling-restart-new-box-gap;basis=the former restartSeed body verbatim over a given route set (both logs, retry grants, seedRestartMarks/marker) whole:Route@1161,whole:Route@157,whole:Route@495,whole:Route@605,whole:Route@899 029f056bd1429151fdebee4b5ed677f1f7e0172b9494769c51308cda24e615ba |
| -@legacy a5645f257a6888daf73bf4d512dd3d89f23345176765c1bc2c064c8be9388160 internal/host/restart.go restartGainSeed legacy accepted-legacy accepted-legacy;rev3=census-ruling-restart-new-box-gap;basis=baselines apps gained since arming into a scratch memory via restartBaseline over those apps routes; merges only missing entries; throttles read errors; agent process, no root read registry:App@520,whole:Route@212,whole:Route@463,whole:Route@515,whole:Route@534,whole:Route@547,whole:Route@552,whole:Route@673 fed1606b4f6b75a38bd681699da616d3bf119aa3ed7a9f70f30e2a47bc560130 |
| +@legacy 5c8a6c951d0ebba1d9e0149eaf5c2fb7259b5f7059c8cdf20ffa0fefd6844874 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 from first-sight history only (Astra r1 P2), which at arming is every entry whole:Route@157,whole:Route@1581,whole:Route@495,whole:Route@605,whole:Route@899 e268bdcbb18133d2db0c0c3a1efe0c685134ddf9f9db1f1d4095373cdf889bee |
| +@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 verbatim over a given route set (both logs, retry grants, seedRestartMarks/marker) whole:Route@1161,whole:Route@157,whole:Route@495,whole:Route@605,whole:Route@899 029f056bd1429151fdebee4b5ed677f1f7e0172b9494769c51308cda24e615ba |
| -internal/host/restart.go restartGainSeed legacy accepted-legacy accepted-legacy;rev3=census-ruling-restart-new-box-gap;basis=baselines apps gained since arming into a scratch memory via restartBaseline over those apps routes; merges only missing entries; throttles read errors; agent process, no root read registry:App@520,whole:Route@212,whole:Route@463,whole:Route@515,whole:Route@534,whole:Route@547,whole:Route@552,whole:Route@673 fed1606b4f6b75a38bd681699da616d3bf119aa3ed7a9f70f30e2a47bc560130 |
| +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 from first-sight history only (Astra r1 P2), which at arming is every entry whole:Route@157,whole:Route@1581,whole:Route@495,whole:Route@605,whole:Route@899 e268bdcbb18133d2db0c0c3a1efe0c685134ddf9f9db1f1d4095373cdf889bee |
| +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 bbfbbcc906ff3ac7a6d418f5f2c49272c3f385a162f9dbbb61bb270ffe5d57ba |
| +@coverage internal/host 447407effe468a4cc81726199ad9bccde4f5c24f1db20ede48fb1a36e1cc9f5a |