activator, console: move growth out of files the ratchet holds
Code motion, no behaviour change: - retryTake moves from activator.go to haretrytake.go, with the take retry call from doWake (doWakeRetryingTake), so activator.go is back at its allowance of 3778 code lines. - testExecBackend moves from activator_test.go to backend_exec_test.go. - TestHAP2ProductionDoors's import-begin rail check becomes importBeginRail, so the test is back under 321 lines.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5 files changed,
+88
−67
internal/activator/activator.go+1 −24internal/activator/activator_test.go+0 −13internal/activator/backend_exec_test.go+13 −0internal/activator/haretrytake.go+39 −0internal/console/hap2_wiring_test.go+35 −30
diff --git a/internal/activator/activator.go b/internal/activator/activator.go| index d60dd356d..8931b9261 100644 |
| --- a/internal/activator/activator.go |
| +++ b/internal/activator/activator.go |
| @@ -2609,10 +2609,7 @@ type wokenInstance struct { |
| // fixed at entry construction, before the wake goroutine starts, so reading |
| // them here without a.mu is safe by construction. |
| func (a *Service) doWake(ctx context.Context, e *actEntry) (*wokenInstance, error) { |
| - w, err := a.doWakeOnce(ctx, e) |
| - if takeRaced(err) { |
| - w, err = a.retryTake(ctx, e, w, err) |
| - } |
| + w, err := a.doWakeRetryingTake(ctx, e) |
| var change *wakeModeChange |
| if !errors.As(err, &change) || w == nil { |
| return w, err |
| @@ -2649,26 +2646,6 @@ func (a *Service) doWake(ctx context.Context, e *actEntry) (*wokenInstance, erro |
| return result, nextErr |
| } |
| -// retryTake is the one retry of a wake whose storage generation take lost |
| -// a conditional write (spec §4 step 5, §7): head.json moved under its |
| -// switch, or the files manifest under its fence. It runs the wake again |
| -// from the acquire, once, only when the failed wake started nothing (its |
| -// restore failed before any spawn) and gave its lease back, as the |
| -// wakeModeChange retry requires; otherwise the failure stands. |
| -func (a *Service) retryTake(ctx context.Context, e *actEntry, w *wokenInstance, err error) (*wokenInstance, error) { |
| - if w == nil || w.proc != nil || w.pend != 0 || w.stopOutcome == nil || !w.stopOutcome.leaseReleased { |
| - return w, err |
| - } |
| - a.mu.Lock() |
| - unproven := a.unprovenWakes[e.host] != nil || len(a.straySidecars[e.host]) > 0 || a.releaseOps[e.host] != nil |
| - a.mu.Unlock() |
| - if unproven { |
| - return w, err |
| - } |
| - log.Printf("activator: %s: %v; the lease is back, retrying the wake once", e.host, err) |
| - return a.doWakeOnce(ctx, e) |
| -} |
| - |
| func (a *Service) doWakeOnce(ctx context.Context, e *actEntry) (*wokenInstance, error) { |
| a.mu.Lock() |
| admissionErr := a.tenantStartRefusal(e.route) |
diff --git a/internal/activator/activator_test.go b/internal/activator/activator_test.go| index 3314cfe6c..e2918a474 100644 |
| --- a/internal/activator/activator_test.go |
| +++ b/internal/activator/activator_test.go |
| @@ -37,7 +37,6 @@ import ( |
| "github.com/carlosframework/platform/internal/cgroup" |
| "github.com/carlosframework/platform/internal/edge" |
| - "github.com/carlosframework/platform/internal/edgesfile" |
| "github.com/carlosframework/platform/internal/lease" |
| "github.com/carlosframework/platform/internal/provision" |
| "github.com/carlosframework/platform/internal/registry" |
| @@ -4668,18 +4667,6 @@ func TestConfigFromEnv(t *testing.T) { |
| // --- ExecBackend ------------------------------------------------------------- |
| -func testExecBackend(t *testing.T) *ExecBackend { |
| - t.Helper() |
| - return &ExecBackend{ |
| - ServedPools: func() edgesfile.PoolEvidence { return edgesfile.PoolEvidence(`[""]`) }, |
| - Cfg: Config{Bucket: "test-bucket", Idle: time.Minute}, |
| - OptDir: t.TempDir(), |
| - DataDir: t.TempDir(), |
| - // The root layout: nil would be lease.HasHead, a real S3 GET. |
| - HasHead: func(context.Context, string, string, string) (bool, error) { return false, nil }, |
| - } |
| -} |
| - |
| // stageLive materializes <OptDir>/live/<host> → <OptDir>/versions/<ver>/app, |
| // the layout the adopt pass maintains in production. |
| func stageLive(t *testing.T, b *ExecBackend, host, ver string) { |
diff --git a/internal/activator/backend_exec_test.go b/internal/activator/backend_exec_test.go| index b57119831..2749c0d61 100644 |
| --- a/internal/activator/backend_exec_test.go |
| +++ b/internal/activator/backend_exec_test.go |
| @@ -20,10 +20,23 @@ import ( |
| "github.com/carlosframework/platform/internal/cgroup" |
| "github.com/carlosframework/platform/internal/edge" |
| + "github.com/carlosframework/platform/internal/edgesfile" |
| "github.com/carlosframework/platform/internal/lease" |
| "github.com/carlosframework/platform/internal/registry" |
| ) |
| +func testExecBackend(t *testing.T) *ExecBackend { |
| + t.Helper() |
| + return &ExecBackend{ |
| + ServedPools: func() edgesfile.PoolEvidence { return edgesfile.PoolEvidence(`[""]`) }, |
| + Cfg: Config{Bucket: "test-bucket", Idle: time.Minute}, |
| + OptDir: t.TempDir(), |
| + DataDir: t.TempDir(), |
| + // The root layout: nil would be lease.HasHead, a real S3 GET. |
| + HasHead: func(context.Context, string, string, string) (bool, error) { return false, nil }, |
| + } |
| +} |
| + |
| // TestExecBackendTierSeam: a nil Tier means the default tier, and a set |
| // Tier is consulted with the route. The cgroup manager is nil here (no |
| // delegation in a test), so this pins the seam's contract, not the write. |
diff --git a/internal/activator/haretrytake.go b/internal/activator/haretrytake.go| new file mode 100644 |
| index 000000000..eeed06e71 |
| --- /dev/null |
| +++ b/internal/activator/haretrytake.go |
| @@ -0,0 +1,39 @@ |
| +package activator |
| + |
| +import ( |
| + "context" |
| + "log" |
| +) |
| + |
| +// A wake whose storage generation take lost a conditional write runs |
| +// again, once (spec 2026-11-12 §4 step 5, §7). |
| + |
| +// doWakeRetryingTake is doWake's first wake: doWakeOnce, and retryTake |
| +// when its generation take raced (takeRaced). |
| +func (a *Service) doWakeRetryingTake(ctx context.Context, e *actEntry) (*wokenInstance, error) { |
| + w, err := a.doWakeOnce(ctx, e) |
| + if takeRaced(err) { |
| + w, err = a.retryTake(ctx, e, w, err) |
| + } |
| + return w, err |
| +} |
| + |
| +// retryTake is the one retry of a wake whose storage generation take lost |
| +// a conditional write (spec §4 step 5, §7): head.json moved under its |
| +// switch, or the files manifest under its fence. It runs the wake again |
| +// from the acquire, once, only when the failed wake started nothing (its |
| +// restore failed before any spawn) and gave its lease back, as the |
| +// wakeModeChange retry requires; otherwise the failure stands. |
| +func (a *Service) retryTake(ctx context.Context, e *actEntry, w *wokenInstance, err error) (*wokenInstance, error) { |
| + if w == nil || w.proc != nil || w.pend != 0 || w.stopOutcome == nil || !w.stopOutcome.leaseReleased { |
| + return w, err |
| + } |
| + a.mu.Lock() |
| + unproven := a.unprovenWakes[e.host] != nil || len(a.straySidecars[e.host]) > 0 || a.releaseOps[e.host] != nil |
| + a.mu.Unlock() |
| + if unproven { |
| + return w, err |
| + } |
| + log.Printf("activator: %s: %v; the lease is back, retrying the wake once", e.host, err) |
| + return a.doWakeOnce(ctx, e) |
| +} |
diff --git a/internal/console/hap2_wiring_test.go b/internal/console/hap2_wiring_test.go| index a3c18daa4..bfef79432 100644 |
| --- a/internal/console/hap2_wiring_test.go |
| +++ b/internal/console/hap2_wiring_test.go |
| @@ -172,6 +172,40 @@ func hap2Refusal(t *testing.T, tr *hap2Transport, status int, out string, wantSt |
| } |
| } |
| +// importBeginRail checks the data reads of a refused import begin. The |
| +// create door retains main's leftover rail before dispatch to import; the |
| +// regional refusal adds no reads of its own. Each prefix's replica is |
| +// resolved first: one head.json read (absent here: the root layout), then |
| +// its levels; then one bounded listing of instances/<host>/g- for an |
| +// abandoned generation. |
| +func importBeginRail(t *testing.T, tr *hap2Transport) { |
| + t.Helper() |
| + var got, want []string |
| + for _, a := range tr.all() { |
| + if a.bucket != "data-test" { |
| + continue |
| + } |
| + if a.method == http.MethodGet && strings.HasSuffix(a.key, "/head.json") { |
| + got = append(got, "head "+a.key) |
| + continue |
| + } |
| + if a.method != http.MethodGet || a.query.Get("list-type") != "2" { |
| + t.Errorf("import begin data request: %+v", a) |
| + } |
| + got = append(got, a.query.Get("prefix")) |
| + } |
| + for _, prefix := range []string{"instances/", "moves/"} { |
| + want = append(want, "head "+prefix+importHost+"/head.json") |
| + for level := 0; level < 10; level++ { |
| + want = append(want, fmt.Sprintf("%s%s/%04x/", prefix, importHost, level)) |
| + } |
| + } |
| + want = append(want, "instances/"+importHost+"/g-") |
| + if !reflect.DeepEqual(got, want) { |
| + t.Errorf("import begin retained rail = %v, want %v", got, want) |
| + } |
| +} |
| + |
| func TestHAP2ProductionDoors(t *testing.T) { |
| t.Run("ingress", func(t *testing.T) { |
| w := newRegionalWorld(t, "hap2-ingress") |
| @@ -428,36 +462,7 @@ func TestHAP2ProductionDoors(t *testing.T) { |
| raw, _ := json.Marshal(out) |
| hap2Refusal(t, tr, code, string(raw), 409, haImportC2) |
| if door == "begin" { |
| - // The create door retains main's leftover rail before dispatch |
| - // to import. The regional refusal adds no reads of its own. |
| - // Each prefix's replica is resolved first: one head.json |
| - // read (absent here: the root layout), then its levels; |
| - // then one bounded listing of instances/<host>/g- for an |
| - // abandoned generation. |
| - var got, want []string |
| - for _, a := range tr.all() { |
| - if a.bucket != "data-test" { |
| - continue |
| - } |
| - if a.method == http.MethodGet && strings.HasSuffix(a.key, "/head.json") { |
| - got = append(got, "head "+a.key) |
| - continue |
| - } |
| - if a.method != http.MethodGet || a.query.Get("list-type") != "2" { |
| - t.Errorf("import begin data request: %+v", a) |
| - } |
| - got = append(got, a.query.Get("prefix")) |
| - } |
| - for _, prefix := range []string{"instances/", "moves/"} { |
| - want = append(want, "head "+prefix+importHost+"/head.json") |
| - for level := 0; level < 10; level++ { |
| - want = append(want, fmt.Sprintf("%s%s/%04x/", prefix, importHost, level)) |
| - } |
| - } |
| - want = append(want, "instances/"+importHost+"/g-") |
| - if !reflect.DeepEqual(got, want) { |
| - t.Errorf("import begin retained rail = %v, want %v", got, want) |
| - } |
| + importBeginRail(t, tr) |
| } else { |
| tr.noData(t) |
| } |