carlos / platform Public

console: place raised copies now, not at the next relabel pass (#1061)

The copies door now kicks replica placement for the app's fleet after it
has answered and released the app lock, instead of leaving the new
assignment to the 5-minute FleetRelabel pass (copies 1->2 took 1m47s in
the incident). The kick runs in the background with a bounded context,
as one admitted unit of record work, under the fleet lock with a fresh
fleet view, and calls reconcileReplicaFleet, which bumps the serial on a
change. It is off on a host-claim console, logs its errors, and leaves
anything it cannot do to the next pass. Lowering goes through the same
reconcile, which already retires extra copies; no new removal logic.

Tests: copiesWorld turns the kick off (those tests drive passes
themselves); the new test turns it on, holds the fleet lock across the
request and waits on replicaKicks. The fixture waits for kicks before
closing. The placement census lists the new AppPlacement caller.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev c4ae2184f3453926cb8c4744fd1dbc4c53c74709 parent d84c1ac
7 files changed, +135 −9
  • internal/console/appcopies.go +9 −0
  • internal/console/appcopies_test.go +3 −0
  • internal/console/placement_census_test.go +10 −9
  • internal/console/replicakick_test.go +47 −0
  • internal/console/replicaplacement.go +57 −0
  • internal/console/server.go +6 −0
  • internal/console/server_test.go +3 −0

Intent

Human

<task-notification> <task-id>a23081d0a5d4bd0a5</task-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/2b517942-2259-467d-a8d0-994fd28c9e84/tasks/a23081d0a5d4bd0a5.output</output-file> <status>completed</status> <summary>Agent "Implement #1061 Task 2" 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_WITH_CONCERNS Commit: `d84c1ac3` hub: a copy that never passed reads starting, not failed (#1061) Tests: - New prober, console view and CLI tests each failed first, then passed. - Edge package: all passed. Root package: all passed after one test fix (below); its two golden tests pass with a TMPDIR outside `/tmp`. - Console package: the full run never finished. It hit the 10m and then the 30m timeout with zero failed tests. The targeted replica and overview tests pass. Concerns: 1. CI needs to confirm the full console package. 2. Task 1's SR-6-C01 copy row had already broken 3 root tests, because the deck's id check only accepted SR-1 to SR-4. I widened it to SR-1 to SR-6 in `approved_stateless_replicas_copy_test.go`. No Task 1 code was touched. 3. A stray `/tmp/.git` on this machine (not mine, left in place) breaks the golden tests whenever TMPDIR is under `/tmp`. 4. Instance word: a starting copy counts as unknown, never as failed. One failed copy plus one starting reads "can't tell", not "Not responding"; the overview tile shows the copy's status as unknown. 5. The console has no copy-state label of its own, so no new copy beyond SR-6-C02 `Starting`, which is pending Paul's review. Report: /home/paulca/amadan.net/carlos/platform/.claude/worktrees/sr-followups/.superpowers/sdd/plan-1061/task-2-report.md</result> <usage><subagent_tokens>125618</subagent_tokens><tool_uses>51</tool_uses><duration_ms>3503520</duration_ms></usage> </task-notification>

Human

<task-notification> <task-id>bcv9htxr4</task-id> <tool-use-id>toolu_012EJMVacyU1jWRjf6hadHHy</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/2b517942-2259-467d-a8d0-994fd28c9e84/tasks/bcv9htxr4.output</output-file> <status>completed</status> <summary>Background command "S=/home/paulca/.paseo/zerosub/homes/claude-37fe90ef3f56/plugins/cache/claude-plugins-official/superpowers/7.0.2/skills/subagent-driven-development; bash $S/scripts/review-package $PWD/.superpowers/sdd/2026-11-14-sr-followups/plan-1061.md 9f1d6a98 HEAD &amp;&amp; P=.superpowers/sdd/plan-1061 &amp;&amp; cat &gt; $P/task-2-astra-brief.md &lt;&lt;'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. Read: 1. Task brief (require ... [1579 characters truncated] ... h file:line, a concrete scenario and a fix. Be concise. EOF timeout 1800 codex exec -m gpt-6-astra -c model_reasoning_effort=high -s read-only "Read .superpowers/sdd/plan-1061/task-2-astra-brief.md and do what it says." &lt;/dev/null &gt; $P/task-2-astra-review.txt 2&gt;&amp;1; echo done" completed (exit code 0)</summary> </task-notification>

Human

<task-notification> <task-id>a17b099a61041ff5d</task-id> <tool-use-id>toolu_01GccpKNxJLgC2igzWhJTbnS</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/2b517942-2259-467d-a8d0-994fd28c9e84/tasks/a17b099a61041ff5d.output</output-file> <status>completed</status> <summary>Agent "Implement #1061 Task 3" is waiting on its own background work</summary> <note>This agent stopped with background work of its own still running. It may resume on its own when that work completes or reports, and the same task-id notifies again if it does; the result below may be interim.</note> <result>Waiting for the claim invariant run to finish.</result> <usage><subagent_tokens>110900</subagent_tokens><tool_uses>41</tool_uses><duration_ms>1470634</duration_ms></usage> </task-notification>

Attributed to this commit: 10.0 g CO₂e (1,212,686 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/console/appcopies.go b/internal/console/appcopies.go
index 1c47da896..7e5ceff18 100644
--- a/internal/console/appcopies.go
+++ b/internal/console/appcopies.go
@@ -96,6 +96,14 @@ func (s *Server) handleAPICopies(w http.ResponseWriter, r *http.Request) {
jsonError(w, http.StatusServiceUnavailable, copiesUnread)
return
}
+ // Registered before the app lock's unlock, so it runs after it: the
+ // kick's placement only tryLocks the app (#1061).
+ written := false
+ defer func() {
+ if written {
+ s.kickReplicaPlacement(acct.ID, app)
+ }
+ }()
ctx, cancel := context.WithTimeout(r.Context(), configStoreTimeout)
defer cancel()
// The existing app lock covers validation and publication. SetCopies joins
@@ -143,6 +151,7 @@ func (s *Server) handleAPICopies(w http.ResponseWriter, r *http.Request) {
}
s.auditActivity(acct, app, addr, Activity{Action: "copies", TargetType: "app", Target: app, Message: message, Detail: fmt.Sprintf("%s: %d copies requested for each instance", app, got)})
s.bumpSerial(ctx)
+ written = true
writeJSON(w, http.StatusOK, map[string]int{"copies": got})
}
diff --git a/internal/console/appcopies_test.go b/internal/console/appcopies_test.go
index 75bcc1972..98353543c 100644
--- a/internal/console/appcopies_test.go
+++ b/internal/console/appcopies_test.go
@@ -19,6 +19,9 @@ import (
func copiesWorld(t *testing.T) (*consoleFixture, string) {
t.Helper()
fx, token, _ := fleetBoxWorld(t, "copies", "pi-1", "pi-2")
+ // These tests drive placement passes themselves; the copies door's
+ // kick (#1061) is on only where a test turns it back on.
+ fx.srv.replicaKickOff = true
// The record label floor, above the replicas floor: a create on this
// two-box fleet is labelled, not refused (D1).
fx.srv.consoleBuild = release.FleetRecordLabelFloor
diff --git a/internal/console/placement_census_test.go b/internal/console/placement_census_test.go
index b32140eff..75aab311f 100644
--- a/internal/console/placement_census_test.go
+++ b/internal/console/placement_census_test.go
@@ -69,15 +69,16 @@ func TestEffectivePlacementIsTheOnlyRouteFallback(t *testing.T) {
// Folds: a call inside an effectivePlacement func literal is the rule.
foldInRule := map[string]bool{"legacyFleetFromRoutes": true, "fleetFromRoutes": true}
for where, why := range map[string]string{
- "appcopies.go:copiesRefusal": "a fleet test on the column",
- "claim_placement.go:Start": "the claim operation's recorded source",
- "plancaps.go:onOwnBoxes": "an empty column falls back through appPlacement",
- "replicafloor.go:replicaPolicyBarrier": "a fleet test on the column",
- "policysize.go:sizeAppPlacement": "a console with no registry has no route fallback",
- "replicaplacement.go:reconcileReplicaApp": "matches the column against a fleet target",
- "sealkey.go:sealPlacement": "a console with no registry has no route fallback",
- "sealkey.go:backfillAppPlacements": "picks candidates with an empty column; the write is guarded",
- "sealkey.go:backfillApp": "re-reads the column under its locks; the write is guarded",
+ "appcopies.go:copiesRefusal": "a fleet test on the column",
+ "claim_placement.go:Start": "the claim operation's recorded source",
+ "plancaps.go:onOwnBoxes": "an empty column falls back through appPlacement",
+ "replicafloor.go:replicaPolicyBarrier": "a fleet test on the column",
+ "policysize.go:sizeAppPlacement": "a console with no registry has no route fallback",
+ "replicaplacement.go:reconcileReplicaApp": "matches the column against a fleet target",
+ "replicaplacement.go:kickReplicaPlacement": "a fleet test on the column",
+ "sealkey.go:sealPlacement": "a console with no registry has no route fallback",
+ "sealkey.go:backfillAppPlacements": "picks candidates with an empty column; the write is guarded",
+ "sealkey.go:backfillApp": "re-reads the column under its locks; the write is guarded",
} {
census["AppPlacement"][where] = columnOnly + "; " + why
}
diff --git a/internal/console/replicakick_test.go b/internal/console/replicakick_test.go
new file mode 100644
index 000000000..4f0b2b552
--- /dev/null
+++ b/internal/console/replicakick_test.go
@@ -0,0 +1,47 @@
+package console
+
+import (
+ "slices"
+ "testing"
+)
+
+// #1061: raising copies places the new copy at once. The copies door kicks
+// placement for the app's fleet after it answers; no FleetRelabel pass runs.
+// The fleet lock is held across the request, as a running pass would hold
+// it: the door still answers, and the kick places once the lock is free.
+func TestCopiesRaisePlacesWithoutRelabelPass(t *testing.T) {
+ fx, token := copiesWorld(t)
+ fx.srv.replicaKickOff = false
+ before := serialNow(t, fx)
+ unlock := fx.srv.lockFleet("pi")
+ code, out := copiesPut(t, fx, token, `{"copies":2}`)
+ if a := shopRec(t, fx, "a.example.com").ReplicaAssignment; a != nil {
+ t.Fatalf("placed under a held fleet lock: %+v", a)
+ }
+ unlock()
+ if code != 200 {
+ t.Fatalf("copies: %d %s", code, out)
+ }
+ fx.srv.replicaKicks.Wait()
+ for _, host := range []string{"a.example.com", "b.example.com"} {
+ a := shopRec(t, fx, host).ReplicaAssignment
+ if a == nil || a.Desired != 2 || len(a.Boxes) != 2 || !slices.Contains(a.Boxes, "pi-1") || !slices.Contains(a.Boxes, "pi-2") {
+ t.Fatalf("%s: assignment %+v; want both boxes placed without a relabel pass", host, a)
+ }
+ }
+ if after := serialNow(t, fx); after < before+2 {
+ t.Fatalf("serial %d -> %d; want the door's bump and the placement's", before, after)
+ }
+
+ // Lowering goes through the same reconcile: the kick writes the lower
+ // count without a pass too.
+ if code, out := copiesPut(t, fx, token, `{"copies":1}`); code != 200 {
+ t.Fatalf("lower: %d %s", code, out)
+ }
+ fx.srv.replicaKicks.Wait()
+ for _, host := range []string{"a.example.com", "b.example.com"} {
+ if a := shopRec(t, fx, host).ReplicaAssignment; a != nil && a.Desired != 1 {
+ t.Fatalf("%s: assignment %+v after lowering; want desired 1", host, a)
+ }
+ }
+}
diff --git a/internal/console/replicaplacement.go b/internal/console/replicaplacement.go
index 9898939e8..ca997370b 100644
--- a/internal/console/replicaplacement.go
+++ b/internal/console/replicaplacement.go
@@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
+ "log"
"os"
"slices"
"sort"
@@ -430,6 +431,62 @@ func (s *Server) reconcileReplicaFleet(ctx context.Context, fleet string, v flee
return errors.Join(errs...)
}
+// replicaKickTimeout bounds one copies-door placement kick: the fleet
+// lock wait, the fleet view read and the assignment writes.
+const replicaKickTimeout = 2 * time.Minute
+
+// kickReplicaPlacement places app's copies now rather than at the next
+// FleetRelabel pass, up to fleetRelabelInterval away (#1061). The copies
+// door calls it after it has answered and released the app lock:
+// reconcileReplicaApp only tryLocks the app, so a kick under the door's
+// lock would do nothing. It runs in the background, does only what the
+// worker's pass does for one fleet (fleetRelabelPass: off on a host-claim
+// console, one admitted unit of record work, the fleet lock, a fresh view,
+// reconcileReplicaFleet and its serial bump), and logs its errors; a kick
+// that fails or finds the app busy leaves the work to the next pass.
+// Lowering the count goes through the same reconcile, which retires the
+// extra copies. replicaKicks lets a test wait for it.
+func (s *Server) kickReplicaPlacement(account int64, app string) {
+ if s.replicaKickOff || s.cfg.HostClaim || s.cfg.Releases == nil || s.cfg.Registry == "" {
+ return
+ }
+ s.replicaKicks.Add(1)
+ go func() {
+ defer s.replicaKicks.Done()
+ ctx, cancel := context.WithTimeout(context.Background(), replicaKickTimeout)
+ defer cancel()
+ placed, err := s.store.AppPlacement(account, app)
+ if err != nil {
+ log.Printf("console: replica placement kick %s: placement: %v (the relabel worker places it)", app, err)
+ return
+ }
+ fleet, ok := registry.FleetPlacement(placed)
+ if !ok {
+ return
+ }
+ s.lifetimesIteration(ctx, "replica placement kick", true, false, func(ctx context.Context) {
+ s.replicaPlacementKick(ctx, fleet)
+ })
+ }()
+}
+
+// replicaPlacementKick is fleetRelabelPass's placement step for one fleet,
+// as of the moment it holds the fleet lock.
+func (s *Server) replicaPlacementKick(ctx context.Context, fleet string) {
+ ctx = withWriteMemo(ctx)
+ unlock := s.lockFleet(fleet)
+ defer unlock()
+ now := time.Now()
+ v, err := s.loadFleetViewAt(ctx, fleet, now)
+ if err != nil {
+ log.Printf("console: replica placement kick %s: view: %v (the relabel worker places it)", fleet, err)
+ return
+ }
+ if err := s.reconcileReplicaFleet(ctx, fleet, v, now); err != nil {
+ log.Printf("console: replica placement kick %s: %v (the relabel worker retries)", fleet, err)
+ }
+}
+
func (s *Server) reconcileReplicaApp(ctx context.Context, fleet string, app AppRef, v fleetView, cache *replicaPlacementCache, now time.Time) (bool, error) {
unlock, ok := s.appLocks.tryLock(app.Sqid + "/" + app.App)
if !ok {
diff --git a/internal/console/server.go b/internal/console/server.go
index 82cca4228..e6d21ecdc 100644
--- a/internal/console/server.go
+++ b/internal/console/server.go
@@ -1452,6 +1452,12 @@ type Server struct {
// linkFirstSyncs counts the poll's background first syncs
// (firstLinkSync), so a test can wait for them.
linkFirstSyncs sync.WaitGroup
+ // replicaKicks counts the copies door's background placement kicks
+ // (kickReplicaPlacement), so a test can wait for them.
+ replicaKicks sync.WaitGroup
+ // replicaKickOff, when set, stops the copies door's placement kick.
+ // Tests only: worlds that drive placement passes themselves.
+ replicaKickOff bool
// linkPublishHook, when non-nil, is called at each stage of a publish
// (apilinks.go). Tests only: the barrier between the apps row and the
// forward row.
diff --git a/internal/console/server_test.go b/internal/console/server_test.go
index dac6be4bd..196a3a955 100644
--- a/internal/console/server_test.go
+++ b/internal/console/server_test.go
@@ -148,6 +148,9 @@ func newConsoleFixtureWith(t *testing.T, o consoleFixtureOptions) *consoleFixtur
if err != nil {
t.Fatal(err)
}
+ // No copies-door placement kick outlives the fixture: this cleanup runs
+ // before the store and listener close.
+ t.Cleanup(srv.replicaKicks.Wait)
// Fixture route hosts don't resolve; keep the not-reporting verdict quick.
srv.instances.timeout = 100 * time.Millisecond
// A console that has been up a while: the canary-retire guard does not