activator: key the install wait by row lifetime and target (#1061 r3)
Final fix for Task 1 (Astra re-review 2; option A). The install wait was keyed by permit, so a refusal seen before this box's permit was orphaned when the permit landed, and a step 32 s later with no fresh wake (starts queued behind backoff or the start limit) answered switched-failed though nothing started. The key is now the row lifetime and the observed deploy's target only. The deploy ID is dropped too: a retry of the same target is a new ID. A wait begun before any deploy was observed counts for the target seen since, keeping its start. A stale wait from an earlier permit of the same target can only make a step answer kept (halt), never switched. Set/clear stays in noteInstallWaitLocked; backoff is unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
internal/activator/replica_install_wait_test.go+68 −26internal/activator/replicadeploy.go+4 −3internal/activator/rootfs_service.go+25 −14
Intent
<task-notification> <task-id>acd7d7bafd03b7613</task-id> <tool-use-id>toolu_018smgkGGaByXyrmwkvdneVL</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/2b517942-2259-467d-a8d0-994fd28c9e84/tasks/acd7d7bafd03b7613.output</output-file> <status>completed</status> <summary>Agent "Implement #1060 Task 1" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>Status: DONE. All five parts of #1060 are in. The label floor and fleet create strings are SR-6-C04 and SR-6-C06, each pending in the stateless replicas deck as you ruled. Commits on sr-followups: - bc805026 console: say when the build is not a release, at start and on copies - 47d1c0c1 instances: say not a release build on the label floor and fleet create Tests: each new test failed before its fix. The targeted root tests (label copy, fleet-record-labels and stateless-replicas decks), the console run (`Copies|FleetCreate|Floor|Label|NotReleaseBuild|TestCreateRefuses`) and the release tests (the full package in round 1) now pass. vet and gofmt are clean. Concerns: none new. The fleet-record-labels tests did not object to the new strings, and `docs/drafts/fleet-record-labels/strings.json` is untouched. The fleet create case keeps the 503 but sends no Retry-After, because the door adds Retry-After only for the C39 message. Report (round 2 appended, string keys corrected): /home/paulca/amadan.net/carlos/platform/.claude/worktrees/sr-followups/.superpowers/sdd/plan-1060/task-1-report.md</result> <usage><subagent_tokens>112382</subagent_tokens><tool_uses>47</tool_uses><duration_ms>1173619</duration_ms></usage> </task-notification>
<task-notification> <task-id>bqa6jhzp4</task-id> <tool-use-id>toolu_018Yrk3aX9sqiJyu14FWW7mB</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/2b517942-2259-467d-a8d0-994fd28c9e84/tasks/bqa6jhzp4.output</output-file> <status>completed</status> <summary>Background command "P=.superpowers/sdd/plan-1060 && cat > $P/task-1-astra-brief.md <<'EOF' You are reviewing one task of a Go change in the CARLOS platform, read-only. Do not modify files, the index or branch state. Another agent may be committing activator changes on this branch meanwhile; review only the diff file. Read: brief .superpowers/sdd/plan-1060/task-1-brief.md; Global Constraints of .superpowers/sdd/2026-11-14-sr-followups/plan-1060.md; the controller ruling: the label floor and fleet ... [1237 characters truncated] ... ndings P1/P2/P3 with file:line, scenario, fix. Concise. EOF timeout 1800 codex exec -m gpt-6-astra -c model_reasoning_effort=high -s read-only "Read .superpowers/sdd/plan-1060/task-1-astra-brief.md and do what it says." </dev/null > $P/task-1-astra-review.txt 2>&1; echo done" completed (exit code 0)</summary> </task-notification>
Attributed to this commit: 19.9 g CO₂e (2,395,283 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on sr-followups, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.
diff --git a/internal/activator/replica_install_wait_test.go b/internal/activator/replica_install_wait_test.go| index e7d1f19a8..3e16544ff 100644 |
| --- a/internal/activator/replica_install_wait_test.go |
| +++ b/internal/activator/replica_install_wait_test.go |
| @@ -39,11 +39,17 @@ var ( |
| ) |
| func newInstallRig(t *testing.T) *installRig { |
| + t.Helper() |
| + return newInstallRigIn(t, installJoin(5)) |
| +} |
| + |
| +// newInstallRigIn is newInstallRig with the record's deploy in state. |
| +func newInstallRigIn(t *testing.T, state func(string) *replicas.Deploy) *installRig { |
| t.Helper() |
| prev := swapSettle |
| swapSettle = 20 * time.Millisecond |
| t.Cleanup(func() { swapSettle = prev }) |
| - r := newReplicaSetRig(t, "b", installJoin(5)) |
| + r := newReplicaSetRig(t, "b", state) |
| r.rt.Hibernate = false |
| r.routes.set(r.rt) |
| r.setPlan(planNotInstalled) |
| @@ -146,8 +152,8 @@ func (r *installRig) switchedFailed(res SwapResult, when string) { |
| // releaseInstallBound from the first such refusal, and is never answered |
| // switched-failed while it waits. The refusal grows no backoff. The wait |
| // is set and cleared in one place (noteInstallWaitLocked): only a started |
| -// generation, its crash, or a new row lifetime, deploy, target or permit |
| -// clears it; a registry outage or the moving refusal does not. |
| +// generation, its crash, or a new row lifetime or target clears it; a |
| +// registry outage, the moving refusal or a new permit does not. |
| func TestJoinInstallWaitKeepsStepOpen(t *testing.T) { |
| t.Run("installed at 60s", func(t *testing.T) { |
| r := newInstallRig(t) |
| @@ -238,31 +244,40 @@ func TestJoinInstallWaitKeepsStepOpen(t *testing.T) { |
| r.backedOff(planMoving, "moving past the bound") |
| r.kept(r.step(false), "past the one deadline") |
| }) |
| - // A new permit (a retry of the join) gets its own install window: an |
| - // expired wait of the old permit is not inherited (concern 3). |
| - t.Run("a new permit starts its own wait", func(t *testing.T) { |
| - r := newInstallRig(t) |
| - r.refused("first wake") |
| - for gone := time.Duration(0); gone <= releaseInstallBound; gone += time.Minute { |
| - r.clk.advance(time.Minute) |
| - r.refused("waiting") |
| + // Astra re-review 2 (final fix, option A): a confirmed install refusal |
| + // seen before this box's permit; the permit and the first step at |
| + // t=0; no further wake of this copy (starts queue behind the backoff |
| + // and the start limit); the step at 45 s stays open, never |
| + // switched-failed. The wait is keyed by row lifetime and target only, |
| + // so the permit's arrival does not orphan it. |
| + t.Run("an install refusal before the permit", func(t *testing.T) { |
| + r := newInstallRigIn(t, func(inc string) *replicas.Deploy { |
| + d := installJoin(4)(inc) |
| + d.Swap = replicas.Swap{Order: []string{"a", "b"}, Completed: []string{"a"}, ActiveBox: "a", Permit: 4} |
| + return d |
| + }) |
| + r.a.mu.Lock() |
| + p := r.a.replicaPolicies[r.rt.Host] |
| + r.a.mu.Unlock() |
| + if p.deploy.Swap.ActiveBox != "a" { |
| + t.Fatalf("setup: the observed deploy is not before b's permit: %+v", p.deploy.Swap) |
| } |
| - next := *installJoin(6)(r.inc) |
| + r.refused("before the permit") |
| + first := r.since() |
| + r.clk.advance(10 * time.Second) |
| + permitted := *installJoin(5)(r.inc) |
| r.store.mu.Lock() |
| - r.store.d = &next |
| + r.store.d = &permitted |
| r.store.mu.Unlock() |
| - r.a.SetReplicaDeploy(r.rt.Host, next, "b") |
| - if !r.since().IsZero() { |
| - t.Fatal("the old permit's wait counts for the new permit") |
| + r.a.SetReplicaDeploy(r.rt.Host, permitted, "b") |
| + r.open(r.step(false), "the permit's first step") |
| + if got := r.since(); !got.Equal(first) { |
| + t.Fatalf("the permit's arrival moved the install wait: %s, want %s", got, first) |
| } |
| - r.refused("first wake under the new permit") |
| - if got := r.since(); !got.Equal(r.clk.now()) { |
| - t.Fatalf("the new permit's wait starts at %s, want now (%s)", got, r.clk.now()) |
| - } |
| - r.open(r.step(false), "the new permit's first step") |
| - r.clk.advance(time.Minute) |
| - r.refused("a minute into the new permit") |
| - r.open(r.step(false), "a minute into the new permit") |
| + r.clk.advance(45 * time.Second) |
| + r.open(r.step(false), "45 s after the permit, no wake since") |
| + r.clk.advance(releaseInstallBound) |
| + r.kept(r.step(false), "past the bound from the first refusal") |
| }) |
| // The old rules stand where no install wait is set: a started |
| // generation that crashes, then cold wakes that fail, answers |
| @@ -313,10 +328,11 @@ func TestJoinInstallWaitKeepsStepOpen(t *testing.T) { |
| // TestInstallWaitRules (#1061 fix round 2): noteInstallWaitLocked is the |
| // one place the wait is set and cleared. Set by an install refusal for a |
| -// key with no wait; kept by every other wake outcome that started nothing |
| +// key (row lifetime, target) with no wait; kept by every other wake outcome that started nothing |
| // (a registry outage, the moving refusal, a fence, a crash-classified |
| // refusal); cleared by a started generation and by its crash; and a wait |
| -// of another key (target, permit, row lifetime) is no wait. |
| +// of another target or row lifetime is no wait; a new permit or deploy |
| +// of the same target keeps it. |
| func TestInstallWaitRules(t *testing.T) { |
| r := newInstallRig(t) |
| rt := r.rt |
| @@ -350,6 +366,19 @@ func TestInstallWaitRules(t *testing.T) { |
| if !crashed.IsZero() { |
| t.Fatalf("a started generation's crash kept the wait %s", crashed) |
| } |
| + // Another permit, or another deploy, of the same target keeps the wait |
| + // (final fix, option A): it can only make a step answer kept. |
| + note(rt, planRefusal(rt.Host, planNotInstalled)) |
| + kept := note(rt, planRefusal(rt.Host, planNotInstalled)) |
| + retry := *installJoin(7)(r.inc) |
| + retry.ID = "deploy-v2-retry" |
| + r.a.SetReplicaDeploy(rt.Host, retry, "b") |
| + r.a.mu.Lock() |
| + same := r.a.installWaitLocked(rt) |
| + r.a.mu.Unlock() |
| + if kept.IsZero() || !same.Equal(kept) { |
| + t.Fatalf("a new permit of the same target lost the wait: %s, want %s", same, kept) |
| + } |
| // Another target: the observed deploy moves to v3. |
| note(rt, planRefusal(rt.Host, planNotInstalled)) |
| moved := *installJoin(5)(r.inc) |
| @@ -374,6 +403,19 @@ func TestInstallWaitRules(t *testing.T) { |
| if !gone.IsZero() { |
| t.Fatalf("another row lifetime inherited the wait %s", gone) |
| } |
| + // A wait begun before any deploy was observed counts for the target |
| + // observed since, from its own start. |
| + note(rt, nil) |
| + r.a.SetReplicaDeploy(rt.Host, replicas.Deploy{}, "b") |
| + r.clk.advance(time.Minute) |
| + early := note(rt, planRefusal(rt.Host, planNotInstalled)) |
| + r.a.SetReplicaDeploy(rt.Host, *installJoin(5)(r.inc), "b") |
| + r.a.mu.Lock() |
| + adopted := r.a.installWaitLocked(rt) |
| + r.a.mu.Unlock() |
| + if early.IsZero() || !adopted.Equal(early) { |
| + t.Fatalf("a wait begun before any target was observed: %s, want %s", adopted, early) |
| + } |
| // Backoff is separate: an install refusal counts nothing, the same |
| // words unmarked do. |
| if residentFailure(planRefusal(rt.Host, planNotInstalled)) || !residentFailure(planRefusal(rt.Host, planUnconfirmed)) { |
diff --git a/internal/activator/replicadeploy.go b/internal/activator/replicadeploy.go| index 34c966d72..863ab02a0 100644 |
| --- a/internal/activator/replicadeploy.go |
| +++ b/internal/activator/replicadeploy.go |
| @@ -497,8 +497,8 @@ func (a *Service) replicaRestartedFailure(ctx context.Context, at Attempt, deplo |
| if st := a.residents[at.Host]; st != nil { |
| configSince = st.configSince |
| } |
| - // The install wait, for this row lifetime, deploy, target and permit |
| - // (installKeyLocked: SetReplicaDeploy above observed this deploy). |
| + // The install wait, for this row lifetime and target (installKeyLocked: |
| + // SetReplicaDeploy above observed this deploy). |
| installSince := a.installWaitLocked(*rt) |
| if !configSince.IsZero() && a.now().Before(configSince.Add(releaseConfigBound)) { |
| a.mu.Unlock() |
| @@ -512,7 +512,8 @@ func (a *Service) replicaRestartedFailure(ctx context.Context, at Attempt, deplo |
| // first such refusal; past it, it answers kept with the install's |
| // reason, so the ACK halts the join without blaming the build. While |
| // the wait is set it is never answered switched-failed (fix round 2): |
| - // only a started generation, its crash, or a new key clears it. |
| + // only a started generation, its crash, or a new row lifetime or |
| + // target clears it. |
| if !installSince.IsZero() && a.now().Before(installSince.Add(releaseInstallBound)) { |
| a.mu.Unlock() |
| res := abandon(errSwapNotAwake) |
diff --git a/internal/activator/rootfs_service.go b/internal/activator/rootfs_service.go| index 4ca0e48f9..f0edce8c9 100644 |
| --- a/internal/activator/rootfs_service.go |
| +++ b/internal/activator/rootfs_service.go |
| @@ -1144,27 +1144,33 @@ type installWait struct { |
| key installKey |
| } |
| -// installKey is what an install wait is for: the row lifetime and, for a |
| -// copy with a replica deploy observed (SetReplicaDeploy), that deploy, its |
| -// target and this box's permit (zero while the permit is another box's). |
| -// A wait of another key is no wait. |
| +// installKey is what an install wait is for: the row lifetime and the |
| +// target build of the replica deploy observed for it (SetReplicaDeploy), |
| +// "" while none is observed. Not the permit, and not the deploy's ID |
| +// (final fix, option A): a wait seen before this box's permit arrived |
| +// must still count once it has, and a later permit or deploy of the same |
| +// target inherits the wait, which can only make its step answer kept |
| +// (halt), never switched. |
| type installKey struct { |
| - incarnation, deploy, target string |
| - permit uint64 |
| + incarnation, target string |
| } |
| // installKeyLocked is rt's install key now. The caller holds a.mu. |
| func (a *Service) installKeyLocked(rt registry.Route) installKey { |
| k := installKey{incarnation: rt.ReplicaIncarnation} |
| if p, ok := a.replicaPolicies[rt.Host]; ok && p.deploy.Incarnation == rt.ReplicaIncarnation { |
| - k.deploy, k.target = p.deploy.ID, p.deploy.Target.Version |
| - if p.box != "" && p.deploy.Swap.ActiveBox == p.box { |
| - k.permit = p.deploy.Swap.Permit |
| - } |
| + k.target = p.deploy.Target.Version |
| } |
| return k |
| } |
| +// covers reports whether a wait of key w counts for key k: the same row |
| +// lifetime, and the same target, or a wait begun before any target was |
| +// observed (w.target ""), which counts for the target observed since. |
| +func (w installKey) covers(k installKey) bool { |
| + return w.incarnation == k.incarnation && (w.target == "" || w.target == k.target) |
| +} |
| + |
| // The events of an install wait (noteInstallWaitLocked). |
| type installEvent int |
| @@ -1177,8 +1183,9 @@ const ( |
| // noteInstallWaitLocked is the one place the install wait (#1061) is set |
| // and cleared (fix round 2, the controller's invariant): |
| // - set by a refusal for no installed build, when there is no wait for |
| -// rt's key now (none, or one of an older key: another row lifetime, |
| -// deploy, target or permit starts its own); |
| +// rt's key now (none, or one of another row lifetime or target starts |
| +// its own); a wait begun before any target was observed takes the |
| +// target observed since and keeps its start; |
| // - cleared only by a generation that started (a wake that served) or |
| // a started generation's crash (the build's failure). |
| // |
| @@ -1188,8 +1195,12 @@ const ( |
| func (a *Service) noteInstallWaitLocked(st *residentState, rt registry.Route, ev installEvent) { |
| switch ev { |
| case installRefused: |
| - if k := a.installKeyLocked(rt); st.install.since.IsZero() || st.install.key != k { |
| + k := a.installKeyLocked(rt) |
| + switch { |
| + case st.install.since.IsZero() || !st.install.key.covers(k): |
| st.install = installWait{since: a.now(), key: k} |
| + default: |
| + st.install.key = k // a wait begun with no target takes this one |
| } |
| case installStarted, installCrashed: |
| st.install = installWait{} |
| @@ -1201,7 +1212,7 @@ func (a *Service) noteInstallWaitLocked(st *residentState, rt registry.Route, ev |
| // holds a.mu. |
| func (a *Service) installWaitLocked(rt registry.Route) time.Time { |
| st := a.residents[rt.Host] |
| - if st == nil || st.install.since.IsZero() || st.install.key != a.installKeyLocked(rt) { |
| + if st == nil || st.install.since.IsZero() || !st.install.key.covers(a.installKeyLocked(rt)) { |
| return time.Time{} |
| } |
| return st.install.since |