console: bound the fleet-corner config-ack read (#966)
Final review (Astra P1). Fleet boxes write the fleet corner, so a compromised one could flood it with keys or large acks and exhaust the shared console's memory on relay status. - list at most fleetAckListMax keys, by page where the store can - read at most 2 x eligible hosts x fleet boxes matching acks per call; the rest stay unread - stream each ack through a 16 KiB limit; a bigger one is skipped, not an error - keep at most 512 bytes of restart_error The platform-root ack read is unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
internal/console/relayacks_bound_test.go+168 −0internal/console/relayops.go+171 −3
Intent
<task-notification> <task-id>a9b3e2da465980c28</task-id> <tool-use-id>toolu_01KSZjVN8e4L4cF1wjPFiGfu</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/2b517942-2259-467d-a8d0-994fd28c9e84/tasks/a9b3e2da465980c28.output</output-file> <status>completed</status> <summary>Agent "Implement #966 fix" 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. On a door box the root adopt pass no longer reads anything from the fleet corner; it now writes its ack as a DELETE followed by a create-only PUT. Commit: 74734bdf `host: root writes door-box config acks blind, no fleet-corner read`. It includes the code and the regenerated census files. - **Why the old code read first:** the store's Put can only create a new object or replace one by ETag, and the door refuses a PUT without a precondition. Ack contents have no version order, so the read was only there to fetch the ETag. - **Which option:** (a), done as delete-then-create, because a plain unconditional PUT can't get through the door without changing it. On a door box root uses the new `configAckRootFunc`, which calls the new `appconfig.ReplaceConfigAckBlind`. Bucket boxes get the same callback as before, and agent paths still read before writing. - **Race:** if another writer recreates the key between the two calls, root's PUT fails and is logged, and that writer's ack stands until the next sync. Any box in the fleet can already overwrite that key, so this loses nothing new. Tests: the door-box test sees only DELETE and PUT on the fleet-corner key, and fails with a GET if the old writer is put back. The new appconfig test sees no Get and no Open. The census tests (`TestPlan14RootReadCensus|TestCensusScopeIsTheRootBinary`), appconfig, rollout, the targeted host runs and the console ack tests all pass. Concerns: - **Census claims:** the census tool rejected claims for `configAckRootFunc` and `ReplaceConfigAckBlind` as "not a change the census sees". I described both in the `runAdoptUnderRootRelease` claim instead, and the `configAckETag` claim now says root no longer reads the fleet corner. - **Brief gap:** between the DELETE and the PUT the ack doesn't exist, so relay status can show "awaiting delivery" for that moment. Report (census fix appended): /home/paulca/amadan.net/carlos/platform/.claude/worktrees/sr-followups/.superpowers/sdd/plan-966/task-1-report.md</result> <usage><subagent_tokens>216019</subagent_tokens><tool_uses>16</tool_uses><duration_ms>369982</duration_ms></usage> </task-notification>
<task-notification> <task-id>b82bafwyl</task-id> <tool-use-id>toolu_01PZ4rcffzYLZiBwnJdpiCLW</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/2b517942-2259-467d-a8d0-994fd28c9e84/tasks/b82bafwyl.output</output-file> <status>completed</status> <summary>Background command "git push origin HEAD:refs/heads/sr-followups 2>&1 | tail -1; P=.superpowers/sdd/2026-11-14-sr-followups; timeout 2400 codex exec -m gpt-6-astra -c model_reasoning_effort=high -s read-only "Census review round 2 of 3, read-only (do not edit files). Your round-1 census review is $P/census-astra-review.txt (verdict READY AFTER FIXES; P2-1: the root adopt pass GETs a fleet-writable config-ack key; REJECT configAckETag and envelopes internal/appconfig and internal/host). The fix c ... [1122 characters truncated] ... . End with exactly one verdict: READY / READY AFTER FIXES / NOT READY. Do not spawn reviewers or run full suites." </dev/null > $P/census-astra-review-2.txt 2>&1; f=$P/census-astra-review-2.txt; n=$(grep -n '^codex$' $f | tail -1 | cut -d: -f1); sed -n "$n,\$p" $f | head -40" completed (exit code 0)</summary> </task-notification>
<task-notification> <task-id>b1gqykqnj</task-id> <tool-use-id>toolu_01JbfG4Dq16hRWR1n9dkJHXj</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/2b517942-2259-467d-a8d0-994fd28c9e84/tasks/b1gqykqnj.output</output-file> <status>completed</status> <summary>Background command "P=.superpowers/sdd/2026-11-14-sr-followups && cat > $P/final-review-brief.md <<'EOF' # Review brief: branch sr-followups (whole-branch final review), round 1 of 3 Repo carlos/platform, branch `sr-followups`, tip 74734bdf31214938bd0f7326999826e80d74b511. Under review: the branch diff in .superpowers/sdd/plan-1061/review-d279e904..74734bdf.diff (merge base with main d279e904; main is merged in). Read-only: do not edit files, the index or branches; do not spawn reviewers or sub ... [2881 characters truncated] ... ict: READY / READY AFTER FIXES / NOT READY. EOF timeout 3000 codex exec -m gpt-6-astra -c model_reasoning_effort=high -s read-only "Read .superpowers/sdd/2026-11-14-sr-followups/final-review-brief.md and do what it says." </dev/null > $P/final-astra.txt 2>&1; echo astra-done" completed (exit code 0)</summary> </task-notification>
<task-notification> <task-id>b7agg90a1</task-id> <tool-use-id>toolu_014ZGNikxiF5VxQtcFo6gNrM</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/2b517942-2259-467d-a8d0-994fd28c9e84/tasks/b7agg90a1.output</output-file> <status>completed</status> <summary>Background command "P=.superpowers/sdd/2026-11-14-sr-followups && timeout 3000 claude -p --model claude-fable-5-2 --permission-mode plan --output-format text "Read $PWD/$P/final-review-brief.md and do what it says. Write nothing to disk; return your review as your answer." > $P/final-fable.txt 2>&1; echo fable-done; tail -5 $P/final-fable.txt" completed (exit code 0)</summary> </task-notification>
diff --git a/internal/console/relayacks_bound_test.go b/internal/console/relayacks_bound_test.go| new file mode 100644 |
| index 000000000..4472b2f76 |
| --- /dev/null |
| +++ b/internal/console/relayacks_bound_test.go |
| @@ -0,0 +1,168 @@ |
| +package console |
| + |
| +import ( |
| + "bytes" |
| + "context" |
| + "encoding/json" |
| + "fmt" |
| + "io" |
| + "strings" |
| + "sync" |
| + "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/appconfig" |
| + "github.com/carlosframework/platform/internal/release" |
| +) |
| + |
| +// ackCountingStore wraps a DirStore and counts, per key, the Opens and Gets |
| +// issued and the bytes read through each Open. |
| +type ackCountingStore struct { |
| + *release.DirStore |
| + mu sync.Mutex |
| + opened map[string]int |
| + read map[string]int |
| + gets int |
| +} |
| + |
| +func (c *ackCountingStore) Open(ctx context.Context, key string) (io.ReadCloser, string, error) { |
| + rc, etag, err := c.DirStore.Open(ctx, key) |
| + if err != nil { |
| + return nil, "", err |
| + } |
| + c.mu.Lock() |
| + c.opened[key]++ |
| + c.mu.Unlock() |
| + return &countingRC{rc: rc, n: func(n int) { c.mu.Lock(); c.read[key] += n; c.mu.Unlock() }}, etag, nil |
| +} |
| + |
| +func (c *ackCountingStore) Get(ctx context.Context, key string) ([]byte, string, error) { |
| + c.mu.Lock() |
| + c.gets++ |
| + c.mu.Unlock() |
| + return c.DirStore.Get(ctx, key) |
| +} |
| + |
| +type countingRC struct { |
| + rc io.ReadCloser |
| + n func(int) |
| +} |
| + |
| +func (r *countingRC) Read(p []byte) (int, error) { |
| + n, err := r.rc.Read(p) |
| + r.n(n) |
| + return n, err |
| +} |
| + |
| +func (r *countingRC) Close() error { return r.rc.Close() } |
| + |
| +func newAckCountingStore(t *testing.T) *ackCountingStore { |
| + return &ackCountingStore{DirStore: release.NewDirStore(t.TempDir()), opened: map[string]int{}, read: map[string]int{}} |
| +} |
| + |
| +func putAck(t *testing.T, st release.Store, key string, a appconfig.ConfigAck) { |
| + t.Helper() |
| + b, err := json.Marshal(a) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, err := st.Put(context.Background(), key, b, ""); err != nil { |
| + t.Fatal(err) |
| + } |
| +} |
| + |
| +const boundPrefix = "fleets/home/" + configAckPrefix |
| + |
| +// TestFleetAcksOversizedObjectIgnoredUnread (Astra final review, #966): a |
| +// fleet box can write a fleet-corner ack up to the door's upload limit. One |
| +// over fleetAckMaxBytes is skipped, not an error, after reading at most the |
| +// limit plus one byte; a normal ack beside it is still read, and a long |
| +// restart_error is kept only up to fleetAckTextMax. |
| +func TestFleetAcksOversizedObjectIgnoredUnread(t *testing.T) { |
| + st := newAckCountingStore(t) |
| + ctx := context.Background() |
| + big := boundPrefix + "box-1/a.example.com.json" |
| + body := []byte(`{"box":"box-1","host":"a.example.com","restart_error":"` + strings.Repeat("x", 4<<20) + `"}`) |
| + if _, err := st.Put(ctx, big, body, ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + putAck(t, st, boundPrefix+"box-2/a.example.com.json", appconfig.ConfigAck{ |
| + Box: "box-2", Host: "a.example.com", Shape: "unit", At: time.Now(), |
| + RestartError: strings.Repeat("é", 2*fleetAckTextMax), |
| + }) |
| + s := &Server{cfg: Config{Releases: st}} |
| + acks, err := s.relayFleetAcksUnder(ctx, boundPrefix, func(h string) bool { return h == "a.example.com" }, 10) |
| + if err != nil { |
| + t.Fatalf("relayFleetAcksUnder: %v", err) |
| + } |
| + if len(acks) != 1 || acks[0].Box != "box-2" { |
| + boxes := make([]string, 0, len(acks)) |
| + for _, a := range acks { |
| + boxes = append(boxes, a.Box) |
| + } |
| + t.Fatalf("acks from boxes %v, want only box-2's", boxes) |
| + } |
| + if n := len(acks[0].RestartError); n > fleetAckTextMax || !strings.HasPrefix(strings.Repeat("é", fleetAckTextMax), acks[0].RestartError) { |
| + t.Fatalf("restart_error kept %d bytes (cut on a rune boundary to <= %d wanted)", n, fleetAckTextMax) |
| + } |
| + if got := st.read[big]; got > fleetAckMaxBytes+1 { |
| + t.Fatalf("read %d bytes of the oversized ack, want <= %d", got, fleetAckMaxBytes+1) |
| + } |
| + if st.gets != 0 { |
| + t.Fatalf("%d whole-object Gets, want every ack streamed", st.gets) |
| + } |
| +} |
| + |
| +// TestFleetAcksStopAtReadCap: matching keys past the per-request cap are |
| +// left unread, and keys for other hosts are never read at all. |
| +func TestFleetAcksStopAtReadCap(t *testing.T) { |
| + st := newAckCountingStore(t) |
| + ctx := context.Background() |
| + for i := range 50 { |
| + box := fmt.Sprintf("box-%02d", i) |
| + putAck(t, st, boundPrefix+box+"/a.example.com.json", appconfig.ConfigAck{Box: box, Host: "a.example.com", Shape: "unit"}) |
| + putAck(t, st, boundPrefix+box+"/other.example.com.json", appconfig.ConfigAck{Box: box, Host: "other.example.com", Shape: "unit"}) |
| + } |
| + s := &Server{cfg: Config{Releases: st}} |
| + acks, err := s.relayFleetAcksUnder(ctx, boundPrefix, func(h string) bool { return h == "a.example.com" }, 4) |
| + if err != nil { |
| + t.Fatalf("relayFleetAcksUnder: %v", err) |
| + } |
| + if len(acks) != 4 { |
| + t.Fatalf("got %d acks, want the cap of 4", len(acks)) |
| + } |
| + opened := 0 |
| + for key, n := range st.opened { |
| + if strings.HasSuffix(key, "/other.example.com.json") { |
| + t.Fatalf("read %s, a host outside the eligible set", key) |
| + } |
| + opened += n |
| + } |
| + if opened != 4 { |
| + t.Fatalf("opened %d acks, want 4", opened) |
| + } |
| +} |
| + |
| +// TestListBoundedStopsAtLimit: the corner listing pages and stops at its |
| +// limit, so a flood of keys is never listed whole. |
| +func TestListBoundedStopsAtLimit(t *testing.T) { |
| + st := release.NewDirStore(t.TempDir()) |
| + ctx := context.Background() |
| + for i := range 25 { |
| + if _, err := st.Put(ctx, fmt.Sprintf("%sbox/h%03d.json", boundPrefix, i), []byte("{}"), ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + for _, c := range []struct{ limit, want int }{{10, 10}, {25, 25}, {100, 25}} { |
| + keys, err := listBounded(ctx, st, boundPrefix, c.limit) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if len(keys) != c.want { |
| + t.Fatalf("limit %d: listed %d keys, want %d", c.limit, len(keys), c.want) |
| + } |
| + } |
| + if !bytes.Equal([]byte(cutText("abc", 5)), []byte("abc")) || cutText("aé", 2) != "a" { |
| + t.Fatal("cutText does not cut on a rune boundary") |
| + } |
| +} |
diff --git a/internal/console/relayops.go b/internal/console/relayops.go| index 3bb067a28..08972b04f 100644 |
| --- a/internal/console/relayops.go |
| +++ b/internal/console/relayops.go |
| @@ -43,6 +43,7 @@ import ( |
| "encoding/json" |
| "errors" |
| "fmt" |
| + "io" |
| "log" |
| "maps" |
| "os" |
| @@ -51,6 +52,7 @@ import ( |
| "strings" |
| "sync" |
| "time" |
| + "unicode/utf8" |
| "github.com/carlosframework/platform/internal/appconfig" |
| "github.com/carlosframework/platform/internal/registry" |
| @@ -1372,7 +1374,10 @@ func (s *Server) relayHeartbeats(ctx context.Context) ([]relay.Heartbeat, error) |
| // whole; but hosts filters the listing down to this app's own routes |
| // before a single Get is issued, so a status call costs a List per place |
| // plus a Get per THIS APP's route, never a Get per ack in the whole fleet |
| -// (review finding 2026-09-07). |
| +// (review finding 2026-09-07). The fleet corner is fleet-writable, so its |
| +// read is bounded besides (relayFleetAcksUnder): it lists at most |
| +// fleetAckListMax keys, not the whole corner, and bounds objects read, |
| +// bytes per object and the free text an ack keeps. |
| func (s *Server) relayConfigAcks(ctx context.Context, acct, app string, hosts map[string]string) ([]appconfig.ConfigAck, error) { |
| out, err := s.relayAcksUnder(ctx, configAckPrefix, func(host string) bool { |
| _, ok := hosts[host] |
| @@ -1398,15 +1403,178 @@ func (s *Server) relayConfigAcks(ctx context.Context, acct, app string, hosts ma |
| if fleet == "" { |
| return out, nil |
| } |
| - more, err := s.relayAcksUnder(ctx, "fleets/"+fleet+"/"+configAckPrefix, func(host string) bool { |
| + eligible := 0 |
| + for _, f := range hosts { |
| + if f == fleet { |
| + eligible++ |
| + } |
| + } |
| + if eligible == 0 { |
| + return out, nil |
| + } |
| + more, err := s.relayFleetAcksUnder(ctx, "fleets/"+fleet+"/"+configAckPrefix, func(host string) bool { |
| return hosts[host] == fleet |
| - }) |
| + }, s.fleetAckReadCap(fleet, eligible)) |
| if err != nil { |
| return nil, err |
| } |
| return append(out, more...), nil |
| } |
| +// The fleet corner is written by fleet boxes, so what one holds is bounded |
| +// here, not by the writer (Astra final review, #966): a compromised box can |
| +// write any number of keys, each up to the door's upload limit. |
| +const ( |
| + // fleetAckMaxBytes bounds one fleet-corner ack. A real ack is a few |
| + // hundred bytes; a bigger object is skipped unread past this limit. |
| + fleetAckMaxBytes = 16 << 10 |
| + // fleetAckListMax bounds the keys one status call lists in the corner. |
| + fleetAckListMax = 10000 |
| + // fleetAckListPage is the page size for a store that lists by page. |
| + fleetAckListPage = 1000 |
| + // fleetAckReadsPerBox scales the per-request read cap: a host has one |
| + // ack per fleet box that ever served it, so eligible hosts times fleet |
| + // boxes is the most a real fleet holds, and this leaves room for |
| + // stale acks of boxes since removed. |
| + fleetAckReadsPerBox = 2 |
| + // fleetAckTextMax bounds the free-text field (RestartError) a |
| + // fleet-corner ack keeps once decoded. |
| + fleetAckTextMax = 512 |
| +) |
| + |
| +// fleetAckReadCap is the most fleet-corner acks one status call reads for |
| +// eligible hosts on fleet: fleetAckReadsPerBox x eligible x the fleet's |
| +// registered boxes (one when the registry cannot say). |
| +func (s *Server) fleetAckReadCap(fleet string, eligible int) int { |
| + boxes := 1 |
| + if s.cfg.Registry != "" { |
| + if reg, err := openRegistry(s.cfg.Registry); err == nil { |
| + if listed, err := reg.ListFleetBoxes(fleet); err == nil && len(listed) > boxes { |
| + boxes = len(listed) |
| + } |
| + } |
| + } |
| + return fleetAckReadsPerBox * eligible * boxes |
| +} |
| + |
| +// relayFleetAcksUnder is relayAcksUnder for the fleet-writable corner, with |
| +// every cost bounded: at most fleetAckListMax keys are listed, at most |
| +// maxReads matching objects are read (the rest are left unread), each |
| +// through a fleetAckMaxBytes limit (a bigger one is skipped, not an error), |
| +// and the free text an ack keeps is cut to fleetAckTextMax bytes. |
| +func (s *Server) relayFleetAcksUnder(ctx context.Context, prefix string, want func(host string) bool, maxReads int) ([]appconfig.ConfigAck, error) { |
| + keys, err := listBounded(ctx, s.cfg.Releases, prefix, fleetAckListMax) |
| + if err != nil { |
| + return nil, err |
| + } |
| + var out []appconfig.ConfigAck |
| + reads := 0 |
| + for _, key := range keys { |
| + host, ok := configAckKeyHost(key) |
| + if !ok || !want(host) { |
| + continue |
| + } |
| + if reads >= maxReads { |
| + log.Printf("console: relay config acks under %s: read cap %d reached, the rest unread", prefix, maxReads) |
| + break |
| + } |
| + reads++ |
| + body, err := readAckLimited(ctx, s.cfg.Releases, key) |
| + if err != nil { |
| + if errors.Is(err, os.ErrNotExist) { |
| + continue |
| + } |
| + if errors.Is(err, release.ErrTooLarge) { |
| + log.Printf("console: relay config ack %s: over %d bytes, ignored", key, fleetAckMaxBytes) |
| + continue |
| + } |
| + return nil, err |
| + } |
| + var a appconfig.ConfigAck |
| + if err := json.Unmarshal(body, &a); err != nil { |
| + log.Printf("console: relay config ack %s: %v", key, err) |
| + continue |
| + } |
| + if a.Host != host { |
| + continue |
| + } |
| + a.RestartError = cutText(a.RestartError, fleetAckTextMax) |
| + out = append(out, a) |
| + } |
| + return out, nil |
| +} |
| + |
| +// listBounded lists at most limit keys under prefix: by page where the |
| +// store can, else whole and cut. |
| +func listBounded(ctx context.Context, st release.Store, prefix string, limit int) ([]string, error) { |
| + pl, ok := st.(release.PageLister) |
| + if !ok { |
| + keys, err := st.List(ctx, prefix) |
| + if len(keys) > limit { |
| + keys = keys[:limit] |
| + } |
| + return keys, err |
| + } |
| + var keys []string |
| + after := "" |
| + for len(keys) < limit { |
| + want := min(fleetAckListPage, limit-len(keys)) |
| + page, err := pl.ListPage(ctx, prefix, after, want) |
| + if err != nil { |
| + return nil, err |
| + } |
| + keys = append(keys, page...) |
| + if len(page) < want { |
| + break |
| + } |
| + after = page[len(page)-1] |
| + } |
| + return keys, nil |
| +} |
| + |
| +// readAckLimited reads key through a fleetAckMaxBytes limit, streaming where |
| +// the store can, so an oversized object costs at most the limit plus one |
| +// byte. release.ErrTooLarge marks one over the limit. |
| +func readAckLimited(ctx context.Context, st release.Store, key string) ([]byte, error) { |
| + rc, _, err := release.OpenObject(ctx, st, key) |
| + if err != nil { |
| + return nil, err |
| + } |
| + defer rc.Close() |
| + body, err := io.ReadAll(io.LimitReader(rc, fleetAckMaxBytes+1)) |
| + if err != nil { |
| + return nil, err |
| + } |
| + if len(body) > fleetAckMaxBytes { |
| + return nil, release.ErrTooLarge |
| + } |
| + return body, nil |
| +} |
| + |
| +// cutText cuts s to at most n bytes on a rune boundary. |
| +func cutText(s string, n int) string { |
| + if len(s) <= n { |
| + return s |
| + } |
| + for n > 0 && !utf8.RuneStart(s[n]) { |
| + n-- |
| + } |
| + return s[:n] |
| +} |
| + |
| +// configAckKeyHost is the host a config-ack key names (its basename, |
| +// ConfigAckKey's "<box>/<host>.json"), and false for a key of another shape. |
| +func configAckKeyHost(key string) (string, bool) { |
| + if !strings.HasSuffix(key, ".json") { |
| + return "", false |
| + } |
| + host := strings.TrimSuffix(key, ".json") |
| + if idx := strings.LastIndexByte(host, '/'); idx >= 0 { |
| + host = host[idx+1:] |
| + } |
| + return host, true |
| +} |
| + |
| // 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 |