fleets: take ack fleet from the registry; read ack ETags unbuffered
#966 fix round 1 (Astra review). - P1 console: a fleet-corner ack's host fleet now comes from the console registry row alone (relayAckHosts): the row must be this account's and app's, name a fleet, and agree with the listed region. An instance record (a bucket object) can no longer move a host into a fleet; a missing row or any disagreement fails closed. - P2 appconfig: WriteConfigAck reads only the existing object's ETag (configAckETag). A stream that carries an ETag (S3, the door) is closed unread; one without (DirStore) is read through a 64 KiB cap and discarded, and a larger object is refused. The body is never buffered or parsed, since the root adopt pass may now read a fleet-writable key.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
internal/appconfig/configack.go+40 −1internal/appconfig/configack_read_test.go+118 −0internal/console/apirelay.go+1 −7internal/console/fleetsecrets_relay_test.go+79 −0internal/console/relayops.go+41 −3
Intent
<task-notification> <task-id>ba67u9ip1</task-id> <tool-use-id>toolu_01MkgFdn9YRobzn5HhDTgLET</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/2b517942-2259-467d-a8d0-994fd28c9e84/tasks/ba67u9ip1.output</output-file> <status>completed</status> <summary>Background command "P=.superpowers/sdd/plan-966 && 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 commit activator changes meanwhile; review only the diff file. Read: brief .superpowers/sdd/plan-966/task-1-brief.md; Global Constraints of .superpowers/sdd/2026-11-14-sr-followups/plan-966.md; triage §1, §2, §5 of .superpowers/sdd/2026-11-14-sr-followups/966-triage. ... [1341 characters truncated] ... indings 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-966/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>
<task-notification> <task-id>a9fd60e14bb47d1b0</task-id> <tool-use-id>toolu_01HrY6Hfj2nCkrtZMTG9sX5F</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/2b517942-2259-467d-a8d0-994fd28c9e84/tasks/a9fd60e14bb47d1b0.output</output-file> <status>completed</status> <summary>Agent "Implement #1061 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 Commit: `b523cb38 activator: bind a pre-deploy install wait to the first target (#1061)`. Earlier Task 1 commits: 882a3f34, a9455fe6, 9f1d6a98, 55b439c8. Tests: - The new `TestInstallWaitBindsToFirstTarget` follows Astra's scenario and fails on the 55b439c8 code: v3 inherited v2's wait. - It passes now, along with the seven W1 subtests and `TestInstallWaitRules`. - `go test ./internal/activator/ -run 'Install|Join|Replica' -count=1` is ok (16.6 s), and the build is clean. Fix: a wait that starts before any deploy is seen is now tied to the first target seen, when that deploy is seen, and keeps its start time. A later different target starts its own wait. I also corrected the outdated comment that still described the deploy and permit key. Concerns: none new. Report: /home/paulca/amadan.net/carlos/platform/.claude/worktrees/sr-followups/.superpowers/sdd/plan-1061/task-1-report.md</result> <usage><subagent_tokens>237577</subagent_tokens><tool_uses>6</tool_uses><duration_ms>133423</duration_ms></usage> </task-notification>
<paseo-system version="1" kind="agent-message" source-agent-id="8a3d302a-eac7-407c-b61c-f5ccc66b5544" message-id="1b7d5f86-f8c6-4637-90fd-ed9b5f721a9e"> Agent manager 8a3d302: Luna, under Paul's standing delegation for plan copy (memory large-copy-decks-delegated): codex exec -m gpt-5.6-luna with a brief carrying the house rules (no em dashes, curly quotes in prose, CLI lower case no full stop, plain words, about a dozen words per UI line; a state label is one or two words). Apply its changes verbatim, mark SR-6-C01..C06 approved by delegation, and send me only what Luna flags. Then census, merge request to me. </paseo-system>
Attributed to this commit: 10.3 g CO₂e (1,250,790 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/appconfig/configack.go b/internal/appconfig/configack.go| index ff99dce75..0912971ea 100644 |
| --- a/internal/appconfig/configack.go |
| +++ b/internal/appconfig/configack.go |
| @@ -23,6 +23,7 @@ import ( |
| "encoding/json" |
| "errors" |
| "fmt" |
| + "io" |
| "log" |
| "os" |
| "strings" |
| @@ -215,6 +216,10 @@ func LatestConfigAck(ctx context.Context, s release.Store, host string) (*Config |
| return best, nil |
| } |
| +// configAckReadMax bounds what WriteConfigAck reads of an existing ack when |
| +// the store hands no ETag with the stream. A real ack is well under 1 KiB. |
| +const configAckReadMax = 64 << 10 |
| + |
| // WriteConfigAck writes ack, get-then-put with the CAS etag of whatever is |
| // there now — "" (create) only when nothing is. An ack is rewritten on |
| // every sync that changes delivery, unlike release.Store.Put's create-only |
| @@ -232,7 +237,7 @@ func WriteConfigAck(ctx context.Context, s release.Store, ack ConfigAck) error { |
| var lastErr error |
| for attempt := 0; attempt < 2; attempt++ { |
| etag := "" |
| - _, curEtag, err := s.Get(ctx, key) |
| + curEtag, err := configAckETag(ctx, s, key) |
| switch { |
| case errors.Is(err, os.ErrNotExist): |
| // no existing record: create-only Put below. |
| @@ -253,6 +258,40 @@ func WriteConfigAck(ctx context.Context, s release.Store, ack ConfigAck) error { |
| return lastErr |
| } |
| +// configAckETag is the ETag of the ack at key, read without buffering or |
| +// parsing its body (#966 fix round 1). On a door box the key sits in the |
| +// fleet corner, which any box of that fleet can write, and the root adopt |
| +// pass writes acks too, so the existing object is untrusted bytes of any |
| +// size. A store that hands an ETag with the stream (S3, the store door, a |
| +// prefix over either) is closed unread. One that does not (DirStore) |
| +// is read through a configAckReadMax cap, discarded, and only then asked for |
| +// its ETag; a larger object is refused, never overwritten. A store with no |
| +// streaming read at all is a test fake and is read whole, as before. |
| +func configAckETag(ctx context.Context, s release.Store, key string) (string, error) { |
| + o, ok := s.(release.Opener) |
| + if !ok { |
| + _, etag, err := s.Get(ctx, key) |
| + return etag, err |
| + } |
| + rc, etag, err := o.Open(ctx, key) |
| + if err != nil { |
| + return "", err |
| + } |
| + defer rc.Close() |
| + if etag != "" { |
| + return etag, nil |
| + } |
| + n, err := io.Copy(io.Discard, io.LimitReader(rc, configAckReadMax+1)) |
| + if err != nil { |
| + return "", err |
| + } |
| + if n > configAckReadMax { |
| + return "", fmt.Errorf("config ack %s: the existing object is over %d bytes, so it is not an ack and is left alone", key, configAckReadMax) |
| + } |
| + _, etag, err = s.Get(ctx, key) |
| + return etag, err |
| +} |
| + |
| // carlosRelayVar is the well-known var name relay enable's config write |
| // (spec §5 step 5) uses — appconfig.Apply, same as any other app var. |
| const carlosRelayVar = "CARLOS_RELAY" |
diff --git a/internal/appconfig/configack_read_test.go b/internal/appconfig/configack_read_test.go| new file mode 100644 |
| index 000000000..46a043f83 |
| --- /dev/null |
| +++ b/internal/appconfig/configack_read_test.go |
| @@ -0,0 +1,118 @@ |
| +package appconfig |
| + |
| +import ( |
| + "bytes" |
| + "context" |
| + "io" |
| + "strings" |
| + "sync/atomic" |
| + "testing" |
| + |
| + "github.com/carlosframework/platform/internal/release" |
| +) |
| + |
| +// ackReadSpy is a DirStore whose Open counts the body bytes a caller reads |
| +// and can hand back a fixed ETag (the door's and S3's shape: an ETag with |
| +// the stream), and whose Get counts calls for one key. |
| +type ackReadSpy struct { |
| + *release.DirStore |
| + key string |
| + openETag string // "" = DirStore's own Open (no ETag) |
| + bodyBytes atomic.Int64 |
| + gets atomic.Int64 |
| +} |
| + |
| +type countingBody struct { |
| + io.ReadCloser |
| + n *atomic.Int64 |
| +} |
| + |
| +func (c countingBody) Read(p []byte) (int, error) { |
| + n, err := c.ReadCloser.Read(p) |
| + c.n.Add(int64(n)) |
| + return n, err |
| +} |
| + |
| +func (s *ackReadSpy) Open(ctx context.Context, key string) (io.ReadCloser, string, error) { |
| + rc, etag, err := s.DirStore.Open(ctx, key) |
| + if err != nil { |
| + return nil, "", err |
| + } |
| + if s.openETag != "" { |
| + etag = s.openETag |
| + } |
| + return countingBody{rc, &s.bodyBytes}, etag, nil |
| +} |
| + |
| +func (s *ackReadSpy) Get(ctx context.Context, key string) ([]byte, string, error) { |
| + if key == s.key { |
| + s.gets.Add(1) |
| + } |
| + return s.DirStore.Get(ctx, key) |
| +} |
| + |
| +// TestWriteConfigAckDoesNotBufferTheExistingObject (#966 fix round 1): on a |
| +// door box the ack key sits in the fleet corner, which any box of the fleet |
| +// can write, and the root adopt pass writes acks too. WriteConfigAck needs |
| +// only the existing object's ETag, so it must never buffer or parse the |
| +// body: with an ETag on the stream it reads none of it, and without one it |
| +// reads at most configAckReadMax+1 bytes and refuses a larger object. |
| +func TestWriteConfigAckDoesNotBufferTheExistingObject(t *testing.T) { |
| + ctx := context.Background() |
| + ack := ConfigAck{Box: "box-1", Host: "a.example.com", Shape: "unit"} |
| + key := ConfigAckKey(ack.Box, ack.Host) |
| + planted := bytes.Repeat([]byte("x"), 4<<20) |
| + |
| + t.Run("an ETag on the stream: no body read, no Get", func(t *testing.T) { |
| + dir := release.NewDirStore(t.TempDir()) |
| + etag, err := dir.Put(ctx, key, planted, "") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + s := &ackReadSpy{DirStore: dir, key: key, openETag: etag} |
| + if err := WriteConfigAck(ctx, s, ack); err != nil { |
| + t.Fatalf("WriteConfigAck: %v", err) |
| + } |
| + if n := s.bodyBytes.Load(); n != 0 { |
| + t.Fatalf("read %d body bytes of the existing ack, want 0", n) |
| + } |
| + if n := s.gets.Load(); n != 0 { |
| + t.Fatalf("Get called %d times on the ack key, want 0", n) |
| + } |
| + if body, _, _ := dir.Get(ctx, key); !strings.Contains(string(body), `"host":"a.example.com"`) { |
| + t.Fatalf("ack not rewritten: %.60q", body) |
| + } |
| + }) |
| + |
| + t.Run("no ETag on the stream: a capped read refuses a large object", func(t *testing.T) { |
| + dir := release.NewDirStore(t.TempDir()) |
| + if _, err := dir.Put(ctx, key, planted, ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + s := &ackReadSpy{DirStore: dir, key: key} |
| + if err := WriteConfigAck(ctx, s, ack); err == nil { |
| + t.Fatal("WriteConfigAck over a 4 MiB object succeeded, want a refusal") |
| + } |
| + if n := s.bodyBytes.Load(); n > configAckReadMax+1 { |
| + t.Fatalf("read %d body bytes, want at most %d", n, configAckReadMax+1) |
| + } |
| + if n := s.gets.Load(); n != 0 { |
| + t.Fatalf("Get called %d times on an oversized ack, want 0", n) |
| + } |
| + }) |
| + |
| + t.Run("bucket box: an existing small ack is rewritten", func(t *testing.T) { |
| + dir := release.NewDirStore(t.TempDir()) |
| + if err := WriteConfigAck(ctx, dir, ack); err != nil { |
| + t.Fatal(err) |
| + } |
| + again := ack |
| + again.Restarted = true |
| + if err := WriteConfigAck(ctx, dir, again); err != nil { |
| + t.Fatalf("rewrite: %v", err) |
| + } |
| + if body, _, _ := dir.Get(ctx, key); !strings.Contains(string(body), `"restarted":true`) { |
| + t.Fatalf("ack not rewritten: %s", body) |
| + } |
| + }) |
| +} |
diff --git a/internal/console/apirelay.go b/internal/console/apirelay.go| index 7b2014438..2eba9272e 100644 |
| --- a/internal/console/apirelay.go |
| +++ b/internal/console/apirelay.go |
| @@ -59,7 +59,6 @@ import ( |
| "time" |
| "github.com/carlosframework/platform/internal/appconfig" |
| - "github.com/carlosframework/platform/internal/registry" |
| "github.com/carlosframework/platform/internal/relay" |
| ) |
| @@ -365,12 +364,7 @@ func (s *Server) relayReply(ctx context.Context, acct *Account, app string, rec |
| // every status call). |
| var acks []appconfig.ConfigAck |
| if rec.Enabled && len(routes) > 0 { |
| - hosts := make(map[string]string, len(routes)) |
| - for _, rt := range routes { |
| - fleet, _ := registry.FleetPlacement(rt.Region) |
| - hosts[rt.Host] = fleet |
| - } |
| - acks, err = s.relayConfigAcks(ctx, acct.Sqid, app, hosts) |
| + acks, err = s.relayConfigAcks(ctx, acct.Sqid, app, s.relayAckHosts(acct.Sqid, app, routes)) |
| if err != nil { |
| return apiRelayReply{}, err |
| } |
diff --git a/internal/console/fleetsecrets_relay_test.go b/internal/console/fleetsecrets_relay_test.go| index 6aa15d3a9..3582c881a 100644 |
| --- a/internal/console/fleetsecrets_relay_test.go |
| +++ b/internal/console/fleetsecrets_relay_test.go |
| @@ -25,6 +25,7 @@ import ( |
| "github.com/carlosframework/platform/internal/appconfig" |
| "github.com/carlosframework/platform/internal/objstore" |
| + "github.com/carlosframework/platform/internal/provision" |
| "github.com/carlosframework/platform/internal/registry" |
| "github.com/carlosframework/platform/internal/relay" |
| "github.com/carlosframework/platform/internal/release" |
| @@ -723,3 +724,81 @@ func TestRelayStatusReadsFleetCornerAcks(t *testing.T) { |
| } |
| } |
| } |
| + |
| +// TestRelayFleetAckNeedsTheRegistryPlacement (#966 fix round 1): a host's |
| +// fleet for a fleet-corner ack comes from the console's registry row alone, |
| +// and only a row of this account and app. An instance record is a bucket |
| +// object, not a tenancy boundary: a record that names home cannot make a |
| +// host home's when the registry places it elsewhere, places it nowhere, or |
| +// belongs to another account or app, and a record and registry row that disagree |
| +// fail closed. Each such host reads awaiting delivery even with an ack in |
| +// home's corner. |
| +func TestRelayFleetAckNeedsTheRegistryPlacement(t *testing.T) { |
| + w := fsrRelayWorld(t, "code-fsr-acks-reg", true) |
| + ctx := context.Background() |
| + fskAway(t, w.fx) // cdef owns the fleet away |
| + if status, body := postJSON(t, fleetsURL(w.fx, w.fx.sqid)+"/new", map[string]string{"name": "spare", "bucket": "spare-data"}, w.token); status != http.StatusOK { |
| + t.Fatalf("create spare = %d %v", status, body) |
| + } |
| + for _, c := range []struct { |
| + host string |
| + recRegion string // "" = no record |
| + reg *registry.Route |
| + }{ |
| + // control: record and registry agree on home |
| + {"a.shop.example.com", "fleet/home", ®istry.Route{Account: w.fx.sqid, Region: "fleet/home"}}, |
| + // the record says home, the registry says spare |
| + {"e.shop.example.com", "fleet/home", ®istry.Route{Account: w.fx.sqid, Region: "fleet/spare"}}, |
| + // the record says home, the registry has no row |
| + {"f.shop.example.com", "fleet/home", nil}, |
| + // the record says home, the registry row is another account's |
| + {"g.shop.example.com", "fleet/home", ®istry.Route{Account: "cdef", Region: "fleet/home"}}, |
| + // the registry says home, the record says spare: they disagree |
| + {"i.shop.example.com", "fleet/spare", ®istry.Route{Account: w.fx.sqid, Region: "fleet/home"}}, |
| + // the registry row is another app's |
| + {"j.shop.example.com", "fleet/home", ®istry.Route{Account: w.fx.sqid, App: "cart", Region: "fleet/home"}}, |
| + // the registry places it on another account's fleet |
| + {"h.shop.example.com", "", ®istry.Route{Account: w.fx.sqid, Region: "fleet/away"}}, |
| + } { |
| + unit := "shop-" + c.host[:1] + ".service" |
| + if c.recRegion != "" { |
| + if err := provision.CreateRecord(ctx, w.fx.rel, provision.Record{ |
| + Schema: 1, Host: c.host, Slug: c.host[:1], App: "shop", Account: w.fx.sqid, |
| + Kind: "service", Unit: unit, Channel: "stable", Region: c.recRegion, |
| + CreatedAt: time.Now().UTC(), |
| + }); err != nil { |
| + t.Fatalf("record %s: %v", c.host, err) |
| + } |
| + } |
| + if c.reg != nil { |
| + rt := *c.reg |
| + if rt.App == "" { |
| + rt.App = "shop" |
| + } |
| + rt.Host, rt.Kind, rt.Unit, rt.Status = c.host, "service", unit, "ready" |
| + w.fx.addRoute(t, rt) |
| + } |
| + } |
| + fsrEnableRelay(t, w, "shop") |
| + issued := relayRecord(t, w.fx, "shop").IssuedSuffixes |
| + |
| + home := release.NewPrefixStore(w.fx.rel, "fleets/home/") |
| + for _, host := range []string{"a", "e", "f", "g", "h", "i", "j"} { |
| + if err := appconfig.WriteConfigAck(ctx, home, appconfig.ConfigAck{ |
| + Box: "box-1", Host: host + ".shop.example.com", Shape: "unit", At: time.Now(), |
| + Restarted: true, RelaySuffixes: maps.Clone(issued), |
| + }); err != nil { |
| + t.Fatalf("seed ack %s: %v", host, err) |
| + } |
| + } |
| + |
| + _, out := getJSON(t, relayURL(w.fx, "shop"), w.token) |
| + rows := relayRouteRows(t, out) |
| + wantRoute(t, rows, "a.shop.example.com", "unit", "adopted at") |
| + for _, host := range []string{"e", "f", "g", "h", "i", "j"} { |
| + h := host + ".shop.example.com" |
| + if got := str(t, rows[h], "delivery"); got != "written, awaiting delivery" { |
| + t.Fatalf("%s delivery = %q, want a fleet-corner ack ignored without the registry's own placement", h, got) |
| + } |
| + } |
| +} |
diff --git a/internal/console/relayops.go b/internal/console/relayops.go| index 3f8c00af8..3bb067a28 100644 |
| --- a/internal/console/relayops.go |
| +++ b/internal/console/relayops.go |
| @@ -869,7 +869,7 @@ type relayRoute struct { |
| Socket string |
| Unit string |
| Environment string |
| - Region string // the host's own placement: "fleet/<name>" on a fleet |
| + Region string // the listing's region: the record's, else the registry row's |
| } |
| // relayAppRoutes enumerates an app's routes from both places the console can |
| @@ -1354,8 +1354,8 @@ func (s *Server) relayHeartbeats(ctx context.Context) ([]relay.Heartbeat, error) |
| } |
| // relayConfigAcks reads every per-route config-adoption acknowledgement |
| -// for acct/app's route hosts. hosts maps each host to the fleet its own |
| -// placement names ("" for none). |
| +// for acct/app's route hosts. hosts maps each host to the fleet its |
| +// registry row places it on ("" for none; relayAckHosts). |
| // |
| // Two places hold acks. A box with a bucket writes the platform-root |
| // configAckPrefix, which no fleet credential can write, so an ack there is |
| @@ -1407,6 +1407,44 @@ func (s *Server) relayConfigAcks(ctx context.Context, acct, app string, hosts ma |
| return append(out, more...), nil |
| } |
| +// relayAckHosts maps each of acct/app's route hosts to the fleet a |
| +// fleet-corner ack may be read from for it ("" for none: such a host takes |
| +// root acks only). The fleet comes from the console's own registry row for |
| +// the host, never from an instance record: records are bucket objects, not a |
| +// tenancy boundary (AGENTS.md). A host gets a fleet only when its registry |
| +// row is this account's and this app's, names a fleet, and agrees with the |
| +// region the route listing carried (a record's, when one exists); any |
| +// disagreement, a missing row, or a registry this console cannot read fails |
| +// closed to "". |
| +func (s *Server) relayAckHosts(acct, app string, routes []relayRoute) map[string]string { |
| + hosts := make(map[string]string, len(routes)) |
| + for _, rt := range routes { |
| + hosts[rt.Host] = "" |
| + } |
| + if s.cfg.Registry == "" { |
| + return hosts |
| + } |
| + reg, err := openRegistry(s.cfg.Registry) |
| + if err != nil { |
| + log.Printf("console: relay config acks %s/%s: registry: %v", acct, app, err) |
| + return hosts |
| + } |
| + for _, rt := range routes { |
| + row, err := reg.Get(rt.Host) |
| + if err != nil { |
| + log.Printf("console: relay config acks %s/%s: registry %s: %v", acct, app, rt.Host, err) |
| + continue |
| + } |
| + if row == nil || row.App != app || release.RouteAccount(*row) != acct || row.Region != rt.Region { |
| + continue |
| + } |
| + if fleet, ok := registry.FleetPlacement(row.Region); ok { |
| + hosts[rt.Host] = fleet |
| + } |
| + } |
| + return hosts |
| +} |
| + |
| // relayAckFleet is the fleet acct/app is placed on, checked to be acct's own |
| // (placedFleet), or "" for an app placed nowhere. |
| func (s *Server) relayAckFleet(acctSqid, app string) (string, error) { |