carlos / platform Public

stateless: a launch waits for config; size its bound (#511)

Drill 1 review round 1: Fable I1 and the config-wait minors.

A joining copy adopts the passed attempt and returned from
prepareStatelessRelease before the release's config gate, so on a box
where its instance directory was never made it launched with an absent
config file read as empty. doStatelessWake now asks releaseConfigWait
for every stateless rootfs launch, after preparation and before
anything starts; the wait makes the directory, so config sync writes
the file, and an always-on copy asks again after releaseConfigPace.
SR-4-C84 now says "this copy waits", for a launch or a release.

releaseConfigBound is sized against config delivery: the config sync
boot pass (a minute after start) plus two fast-converge passes (at least
a minute apart): three minutes (configSyncBootPass, fastConvergeSpacing).
A bucket read error keeps waiting past the bound; only a configuration
known to render is held as failed. The wait's clock records when it was
last seen and starts again after releaseConfigStale (a minute), so a
clock left by a wait that ended another way is not carried over (Fable
M1).

Witnesses: TestJoinFirstWakeWaitsForConfig (real Service, a join's first
wake: no launch before config, then a launch with it, no release) and
TestReleaseConfigWaitHeldAsFailed (held past the bound; an unreadable
configuration keeps waiting; a stale clock starts again).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev fe646a2f6dc9af4df5e6ef60a8f16a1bda949bc7 parent 7e27ab0
5 files changed, +147 −52
  • internal/activator/activator.go +3 −3
  • internal/activator/backend_rootfs.go +3 −3
  • internal/activator/replica_drill1_test.go +86 −30
  • internal/activator/stateless.go +10 −0
  • internal/activator/statelessrelease.go +45 −16
diff --git a/internal/activator/activator.go b/internal/activator/activator.go
index 214148f23..07f0b571b 100644
--- a/internal/activator/activator.go
+++ b/internal/activator/activator.go
@@ -1325,10 +1325,10 @@ type Service struct {
// with no generation at all and no switch evidence, and since when
// (replicaRestartedFailure): only the bound's clock, never evidence.
replicaNoGen map[string]replicaSwitch
- // releaseConfigSince is, per host, when a stateless release first
- // waited for its instance's config file (releaseConfigWait), for
+ // releaseConfigWaits is, per host, the clock of a stateless release's
+ // wait for its instance's config file (releaseConfigWait), for
// releaseConfigBound (#511 drill 1, R20). Under mu.
- releaseConfigSince map[string]time.Time
+ releaseConfigWaits map[string]releaseConfigClock
// Startup gates admission while the agent recovers installations. Set before publication.
Startup <-chan struct{}
diff --git a/internal/activator/backend_rootfs.go b/internal/activator/backend_rootfs.go
index 3c0a700ed..518470bd4 100644
--- a/internal/activator/backend_rootfs.go
+++ b/internal/activator/backend_rootfs.go
@@ -177,8 +177,8 @@ type releaseConfigGate interface {
releaseConfigWait(ctx context.Context, rt registry.Route) error
}
-// errReleaseConfigWait is a stateless release that waits for its
-// instance's config file (#511 drill 1, R20): the configuration renders an
+// errReleaseConfigWait is a stateless release, or launch (round 1, Fable
+// I1), that waits for its instance's config file (#511 drill 1, R20): the configuration renders an
// environment and this box has not written it yet, so a release now would
// run without it. Nothing ran and no attempt began. It is a refusal
// (ErrFenced to every classifier), never the build's failure; an always-on
@@ -187,7 +187,7 @@ type releaseConfigWait struct{ err error }
// copy SR-4-C84
func (e *releaseConfigWait) Error() string {
- text := "the release waits until this instance's configuration is written on this box. nothing ran yet"
+ text := "this copy waits until the instance's configuration is written on this box. nothing ran yet"
if e.err != nil {
text += ": " + e.err.Error()
}
diff --git a/internal/activator/replica_drill1_test.go b/internal/activator/replica_drill1_test.go
index 8550a434a..4ebda96b5 100644
--- a/internal/activator/replica_drill1_test.go
+++ b/internal/activator/replica_drill1_test.go
@@ -194,13 +194,15 @@ func TestReleaseWaitsForConfigFile(t *testing.T) {
type configWaitBackend struct {
*wakeRelBackend
written atomic.Bool
+ // readErr: the bucket cannot say whether a configuration is expected.
+ readErr error
}
func (b *configWaitBackend) releaseConfigWait(context.Context, registry.Route) error {
if b.written.Load() {
return nil
}
- return &releaseConfigWait{}
+ return &releaseConfigWait{err: b.readErr}
}
// TestFirstWakeReleaseWaitsForConfig (#511 drill 1, F1/R20): a first wake
@@ -384,37 +386,62 @@ func TestStatelessEscrowRecordsAbsence(t *testing.T) {
})
}
-// TestReleaseConfigWaitHeldAsFailed (#511 drill 1, R20 bound): a release
-// whose configuration is never written waits releaseConfigBound and no
-// longer. Within it, nothing begins. Past it, the attempt begins and is
-// held as failed with nothing run, its reason named (SR-4-C90); the copy
-// then meets the failed attempt, as any failed release, until a retry.
+// TestReleaseConfigWaitHeldAsFailed (#511 drill 1, R20 bound; round 1
+// minors): a release whose configuration is never written waits
+// releaseConfigBound and no longer. Within it, nothing begins. Past it,
+// the attempt begins and is held as failed with nothing run, its reason
+// named (SR-4-C90); the copy then meets the failed attempt, as any failed
+// release, until a retry. A configuration the bucket cannot be read for
+// keeps waiting past the bound, and a wait seen again only after
+// releaseConfigStale starts its clock again (Fable M1).
func TestReleaseConfigWaitHeldAsFailed(t *testing.T) {
- r := newWakeRelRig(t)
- store := wireStatelessRig(r)
- r.a.backend = &configWaitBackend{wakeRelBackend: r.b}
- r.rt.Hibernate, r.rt.Stateless = false, true
- r.routes.set(r.rt)
- r.setPlan(WakePlan{Boot: r.next, Mode: ModeOverlap, Token: 1})
- var wait *releaseConfigWait
- if err := waitErr(t, r.wake(r.a)); !errors.As(err, &wait) || store.snapshot() != nil {
- t.Fatalf("within the bound: %v, record %+v", err, store.snapshot())
- }
- r.clk.advance(releaseConfigBound / 2)
- if err := waitErr(t, r.wake(r.a)); !errors.As(err, &wait) || store.snapshot() != nil {
- t.Fatalf("still within the bound: %v, record %+v", err, store.snapshot())
- }
- r.clk.advance(releaseConfigBound)
- err := waitErr(t, r.wake(r.a))
- if !errors.Is(err, errReleaseConfigHeld) || !errors.Is(err, errReplicaReleaseFailed) {
- t.Fatalf("past the bound: %v", err)
- }
- if d := store.snapshot(); d == nil || d.Phase != "failed" || len(r.b.releaseStarts()) != 0 || r.a.hasEntry(r.rt.Host) {
- t.Fatalf("not held as failed with nothing run: %+v, releases %d", d, len(r.b.releaseStarts()))
- }
- if err := waitErr(t, r.wake(r.a)); !errors.Is(err, errReplicaReleaseFailed) || len(r.b.releaseStarts()) != 0 {
- t.Fatalf("the held attempt did not stay failed: %v", err)
+ rig := func(t *testing.T) (*wakeRelRig, *replicaReleaseStore, *configWaitBackend) {
+ r := newWakeRelRig(t)
+ store := wireStatelessRig(r)
+ cw := &configWaitBackend{wakeRelBackend: r.b}
+ r.a.backend = cw
+ r.rt.Hibernate, r.rt.Stateless = false, true
+ r.routes.set(r.rt)
+ r.setPlan(WakePlan{Boot: r.next, Mode: ModeOverlap, Token: 1})
+ return r, store, cw
+ }
+ // waitFor wakes every step until elapsed has passed, each refused as
+ // a wait with nothing begun.
+ waitThrough := func(t *testing.T, r *wakeRelRig, store *replicaReleaseStore, elapsed, step time.Duration) {
+ t.Helper()
+ for gone := time.Duration(0); gone < elapsed; gone += step {
+ var wait *releaseConfigWait
+ if err := waitErr(t, r.wake(r.a)); !errors.As(err, &wait) || store.snapshot() != nil {
+ t.Fatalf("after %s: %v, record %+v", gone, err, store.snapshot())
+ }
+ r.clk.advance(step)
+ }
}
+ t.Run("held", func(t *testing.T) {
+ r, store, _ := rig(t)
+ waitThrough(t, r, store, releaseConfigBound, 50*time.Second)
+ err := waitErr(t, r.wake(r.a))
+ if !errors.Is(err, errReleaseConfigHeld) || !errors.Is(err, errReplicaReleaseFailed) {
+ t.Fatalf("past the bound: %v", err)
+ }
+ if d := store.snapshot(); d == nil || d.Phase != "failed" || len(r.b.releaseStarts()) != 0 || r.a.hasEntry(r.rt.Host) {
+ t.Fatalf("not held as failed with nothing run: %+v, releases %d", d, len(r.b.releaseStarts()))
+ }
+ if err := waitErr(t, r.wake(r.a)); !errors.Is(err, errReplicaReleaseFailed) || len(r.b.releaseStarts()) != 0 {
+ t.Fatalf("the held attempt did not stay failed: %v", err)
+ }
+ })
+ t.Run("unreadable keeps waiting", func(t *testing.T) {
+ r, store, cw := rig(t)
+ cw.readErr = errors.New("bucket unreachable")
+ waitThrough(t, r, store, 2*releaseConfigBound, 50*time.Second)
+ })
+ t.Run("stale clock", func(t *testing.T) {
+ r, store, _ := rig(t)
+ waitThrough(t, r, store, releaseConfigBound-time.Minute, 50*time.Second)
+ r.clk.advance(releaseConfigStale + time.Second)
+ waitThrough(t, r, store, releaseConfigBound-time.Minute, 50*time.Second)
+ })
}
// TestDoneCopyRefusesWithoutSecrets (#511 drill 1, R21b bound): after a
@@ -455,6 +482,35 @@ func TestDoneCopyRefusesWithoutSecrets(t *testing.T) {
}
}
+// TestJoinFirstWakeWaitsForConfig (#511 drill 1 round 1, Fable I1): on the
+// real Service, box b holds a join's permit and has never run the
+// instance. Its first wake adopts the passed attempt and then waits for
+// the instance's config file: nothing launches. Once config sync has
+// written it, the next wake launches the target.
+func TestJoinFirstWakeWaitsForConfig(t *testing.T) {
+ join := func(inc string) *replicas.Deploy {
+ return &replicas.Deploy{ID: "deploy-v2", Incarnation: inc, Target: replicaTarget, BaselineSet: true, LastGood: replicaTarget, Phase: "released", Term: "term", Revision: 5,
+ Swap: replicas.Swap{Order: []string{"a", "b"}, Completed: []string{"a"}, ActiveBox: "b", Permit: 5}}
+ }
+ r := newReplicaSetRig(t, "b", join)
+ r.rt.Hibernate = false
+ r.routes.set(r.rt)
+ cw := &configWaitBackend{wakeRelBackend: r.b}
+ r.a.backend = cw
+ r.setPlan(WakePlan{Boot: r.next, Mode: ModeOverlap, Token: 2})
+ var wait *releaseConfigWait
+ if err := waitErr(t, r.wake(r.a)); !errors.As(err, &wait) || r.started("v2") || r.a.hasEntry(r.rt.Host) {
+ t.Fatalf("the joining copy launched before its config: %v", err)
+ }
+ cw.written.Store(true)
+ if err := waitErr(t, r.wake(r.a)); err != nil {
+ t.Fatalf("the joining copy did not launch with its config: %v", err)
+ }
+ if g, ok := r.a.Current(r.rt.Host); !ok || g.Build != "v2" || len(r.b.releaseStarts()) != 0 {
+ t.Fatalf("serving %+v, releases %d", g, len(r.b.releaseStarts()))
+ }
+}
+
// TestReplicaKeptFenceHeldUntilAck (#511 drill 1 round 1, Astra A1): the
// fence of a kept answer is owned by its permit and held until the ACK
// commits. Between the answer and the ACK the escrow is repaired and a
diff --git a/internal/activator/stateless.go b/internal/activator/stateless.go
index 51f3f781a..a8e85673e 100644
--- a/internal/activator/stateless.go
+++ b/internal/activator/stateless.go
@@ -179,6 +179,16 @@ func (a *Service) doStatelessWake(ctx context.Context, e *actEntry, id release.S
}
return w, a.secretsRefusal(rt.Host, err)
}
+ // A stateless rootfs launch waits for its instance's config file, as
+ // its release does (#511 drill 1 round 1, Fable I1): a copy that joins
+ // on a box where its instance directory was never made would
+ // otherwise start with no configuration. Nothing has started; an
+ // always-on copy asks again after releaseConfigPace.
+ if g, ok := a.backend.(releaseConfigGate); ok && rt.Rootfs() {
+ if err := g.releaseConfigWait(ctx, rt); err != nil {
+ return w, err
+ }
+ }
ctx = prepared
gate := func() error {
if ctx.Err() != nil || !a.wakeGoesOn(e) {
diff --git a/internal/activator/statelessrelease.go b/internal/activator/statelessrelease.go
index bafa28163..a02d3c812 100644
--- a/internal/activator/statelessrelease.go
+++ b/internal/activator/statelessrelease.go
@@ -192,7 +192,12 @@ func (a *Service) prepareStatelessRelease(ctx context.Context, rt registry.Route
switch {
case err == nil:
a.releaseConfigDone(rt.Host)
- case !errors.As(err, &wait) || !a.releaseConfigExpired(rt.Host):
+ case !errors.As(err, &wait):
+ return "", err
+ case !a.releaseConfigExpired(rt.Host, wait.err == nil):
+ // A configuration the bucket could not be read for keeps
+ // waiting, past the bound too: it is no evidence the
+ // configuration is missing (round 1 minor).
return "", err
default:
configHeld = true
@@ -463,10 +468,30 @@ func (a *Service) ReplicaRelease(ctx context.Context, at Attempt) error {
// releaseConfigBound is how long a stateless release waits for its
// instance's config file before its attempt is held as failed (#511 drill
-// 1, R20): the bound a permitted step gives a copy that cannot start
-// (residentPoll + workerStartBound, as replicaRestartBound), about 32 s,
-// some ten config sync ticks.
-var releaseConfigBound = residentPoll + workerStartBound
+// 1, R20), sized against config delivery (round 1 minor): the config sync
+// loop's boot pass runs a minute after the agent starts
+// (configSyncBootPass; internal/host/agent.go, runConfigSync), and the
+// fast-converge passes that also run config sync are at least a minute
+// apart (fastConvergeSpacing; internal/host/changeindex.go). The bound is
+// the boot pass plus two fast passes: three minutes. The config
+// generation tick (3 s) usually writes the file within seconds.
+var releaseConfigBound = configSyncBootPass + 2*fastConvergeSpacing
+
+const (
+ // configSyncBootPass is the delay of the agent's first config sync pass.
+ configSyncBootPass = time.Minute
+ // fastConvergeSpacing is the least spacing of two fast-converge passes.
+ fastConvergeSpacing = time.Minute
+ // releaseConfigStale: a wait seen again only after this long is a new
+ // wait, so a clock left by a wait that ended some other way (a row
+ // change, an adopted attempt) is not carried over (Fable M1). An
+ // always-on copy asks every releaseConfigPace.
+ releaseConfigStale = time.Minute
+)
+
+// releaseConfigClock is one host's config wait: its start and when it was
+// last seen.
+type releaseConfigClock struct{ since, last time.Time }
// errReleaseConfigHeld is the answer of the attempt held as failed past
// releaseConfigBound: the release command never ran. It is the attempt's
@@ -481,25 +506,29 @@ func (releaseConfigHeld) Error() string {
}
func (releaseConfigHeld) Unwrap() error { return errReplicaReleaseFailed }
-// releaseConfigExpired notes host's config wait, from its first, and
-// reports whether it has lasted releaseConfigBound.
-func (a *Service) releaseConfigExpired(host string) bool {
+// releaseConfigExpired notes host's config wait and reports whether it
+// has lasted releaseConfigBound and may be held (holdable: the
+// configuration is known to render an environment). A wait not seen for
+// releaseConfigStale starts again.
+func (a *Service) releaseConfigExpired(host string, holdable bool) bool {
a.mu.Lock()
defer a.mu.Unlock()
now := a.now()
- since, ok := a.releaseConfigSince[host]
- if !ok {
- if a.releaseConfigSince == nil {
- a.releaseConfigSince = make(map[string]time.Time)
- }
- a.releaseConfigSince[host], since = now, now
+ c, ok := a.releaseConfigWaits[host]
+ if !ok || now.Sub(c.last) > releaseConfigStale {
+ c = releaseConfigClock{since: now}
+ }
+ c.last = now
+ if a.releaseConfigWaits == nil {
+ a.releaseConfigWaits = make(map[string]releaseConfigClock)
}
- return !now.Before(since.Add(releaseConfigBound))
+ a.releaseConfigWaits[host] = c
+ return holdable && !now.Before(c.since.Add(releaseConfigBound))
}
// releaseConfigDone ends host's config wait.
func (a *Service) releaseConfigDone(host string) {
a.mu.Lock()
- delete(a.releaseConfigSince, host)
+ delete(a.releaseConfigWaits, host)
a.mu.Unlock()
}