carlos / platform Public

console: walk pointer digest accounts four at a time

The report walked every bucket account and app in sequence under the
door's 60 s deadline (Fable R3 P2-1). Accounts now run four at a time,
each into its own slot, so rows, error rows and order are unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 1ef464d17b6b2afda59e0db5a70133341763c30e parent c8b943a
2 files changed, +197 −63
  • internal/console/apidigests.go +99 −63
  • internal/console/apidigests_test.go +98 −0
diff --git a/internal/console/apidigests.go b/internal/console/apidigests.go
index d81d42182..d2e9cfed9 100644
--- a/internal/console/apidigests.go
+++ b/internal/console/apidigests.go
@@ -7,6 +7,7 @@ import (
"log"
"net/http"
"slices"
+ "sync"
"time"
"github.com/carlosframework/platform/internal/release"
@@ -235,77 +236,112 @@ func (s *Server) handleAPISystemPointerDigests(w http.ResponseWriter, r *http.Re
sqids = append(sqids, sqid)
}
}
- type acctRow struct {
- Account string `json:"account"`
- On bool `json:"on"`
- Since string `json:"since,omitempty"`
- Error string `json:"error,omitempty"`
- // BucketOnly is an account the bucket holds and this console does
- // not: listed for its heads; a marker request never names it.
- BucketOnly bool `json:"bucket_only,omitempty"`
+ // Accounts are walked digestWalkers at a time, each into its own slot,
+ // so the report keeps the sequential walk's order under the deadline
+ // (Fable R3 P2-1).
+ walks := make([]digestAccountWalk, len(sqids))
+ sem := make(chan struct{}, digestWalkers)
+ var wg sync.WaitGroup
+ for i, sqid := range sqids {
+ sem <- struct{}{}
+ wg.Go(func() {
+ defer func() { <-sem }()
+ walks[i] = s.walkDigestAccount(ctx, sqid, !known[sqid])
+ })
}
- type chRow struct {
- Account string `json:"account"`
- App string `json:"app"`
- Channel string `json:"channel"`
- Version string `json:"version"`
- Straggler bool `json:"straggler"`
+ wg.Wait()
+ acctRows, chRows, repRows := []digestAcctRow{}, []digestChRow{}, []digestRepRow{}
+ for _, wk := range walks {
+ acctRows = append(acctRows, wk.row)
+ chRows = append(chRows, wk.channels...)
+ repRows = append(repRows, wk.repairs...)
}
- // repRow is a channel whose head a fresh or replaced box would refuse
- // (release.ChannelDigestState.NeedsRepair), listed whatever the
- // account's marker says: the account binding's rollout waits on none.
- type repRow struct {
- Account string `json:"account"`
- App string `json:"app"`
- Channel string `json:"channel"`
- Version string `json:"version"`
- Unbound bool `json:"unbound,omitempty"`
- NoRecord bool `json:"no_record,omitempty"`
+ writeJSON(w, http.StatusOK, map[string]any{"accounts": acctRows, "channels": chRows, "repairs": repRows})
+}
+
+// digestWalkers is how many accounts the pointer digests report walks at once.
+const digestWalkers = 4
+
+type digestAcctRow struct {
+ Account string `json:"account"`
+ On bool `json:"on"`
+ Since string `json:"since,omitempty"`
+ Error string `json:"error,omitempty"`
+ // BucketOnly is an account the bucket holds and this console does
+ // not: listed for its heads; a marker request never names it.
+ BucketOnly bool `json:"bucket_only,omitempty"`
+}
+
+type digestChRow struct {
+ Account string `json:"account"`
+ App string `json:"app"`
+ Channel string `json:"channel"`
+ Version string `json:"version"`
+ Straggler bool `json:"straggler"`
+}
+
+// digestRepRow is a channel whose head a fresh or replaced box would refuse
+// (release.ChannelDigestState.NeedsRepair), listed whatever the
+// account's marker says: the account binding's rollout waits on none.
+type digestRepRow struct {
+ Account string `json:"account"`
+ App string `json:"app"`
+ Channel string `json:"channel"`
+ Version string `json:"version"`
+ Unbound bool `json:"unbound,omitempty"`
+ NoRecord bool `json:"no_record,omitempty"`
+}
+
+// digestAccountWalk is one account's part of the pointer digests report.
+type digestAccountWalk struct {
+ row digestAcctRow
+ channels []digestChRow
+ repairs []digestRepRow
+}
+
+// walkDigestAccount reads one account's marker and every app's channels
+// for handleAPISystemPointerDigests. A read that fails is the row's error,
+// never a shorter listing.
+func (s *Server) walkDigestAccount(ctx context.Context, sqid string, bucketOnly bool) digestAccountWalk {
+ wk := digestAccountWalk{row: digestAcctRow{Account: sqid, BucketOnly: bucketOnly}}
+ row := &wk.row
+ m, err := release.ReadDigestMarker(ctx, s.cfg.Releases, s.cfg.ReleasePub, sqid)
+ if err != nil {
+ row.Error = err.Error()
+ return wk
}
- acctRows, chRows, repRows := []acctRow{}, []chRow{}, []repRow{}
- for _, sqid := range sqids {
- row := acctRow{Account: sqid, BucketOnly: !known[sqid]}
- m, err := release.ReadDigestMarker(ctx, s.cfg.Releases, s.cfg.ReleasePub, sqid)
+ if m != nil {
+ row.On, row.Since = true, m.At.UTC().Format(time.RFC3339)
+ }
+ apps, err := release.BucketApps(ctx, s.cfg.Releases, sqid)
+ if err != nil {
+ row.Error = fmt.Sprintf(textBucketListApps, sqid, err)
+ return wk
+ }
+ for _, app := range apps {
+ states, _, err := release.DigestReport(ctx, s.cfg.Releases, s.cfg.ReleasePub, sqid, app)
if err != nil {
row.Error = err.Error()
- acctRows = append(acctRows, row)
- continue
- }
- if m != nil {
- row.On, row.Since = true, m.At.UTC().Format(time.RFC3339)
+ break
}
- apps, err := release.BucketApps(ctx, s.cfg.Releases, sqid)
- if err != nil {
- row.Error = fmt.Sprintf(textBucketListApps, sqid, err)
- acctRows = append(acctRows, row)
- continue
- }
- for _, app := range apps {
- states, _, err := release.DigestReport(ctx, s.cfg.Releases, s.cfg.ReleasePub, sqid, app)
- if err != nil {
- row.Error = err.Error()
- break
- }
- for _, st := range states {
- switch {
- case st.Err != "":
- // Unknown, not "has digests": the account's report is
- // incomplete, so the CLI never calls the fleet ready.
- if row.Error == "" {
- row.Error = st.Err
- }
- case !st.HeadDigest:
- chRows = append(chRows, chRow{Account: sqid, App: app, Channel: st.Channel, Version: st.Version, Straggler: st.Straggler})
- }
- if st.Err == "" && st.RecordErr != "" && row.Error == "" {
- row.Error = st.RecordErr // unknown whether it needs a repair
- }
- if st.Err == "" && st.NeedsRepair() {
- repRows = append(repRows, repRow{Account: sqid, App: app, Channel: st.Channel, Version: st.Version, Unbound: st.Unbound, NoRecord: st.NoRecord})
+ for _, st := range states {
+ switch {
+ case st.Err != "":
+ // Unknown, not "has digests": the account's report is
+ // incomplete, so the CLI never calls the fleet ready.
+ if row.Error == "" {
+ row.Error = st.Err
}
+ case !st.HeadDigest:
+ wk.channels = append(wk.channels, digestChRow{Account: sqid, App: app, Channel: st.Channel, Version: st.Version, Straggler: st.Straggler})
+ }
+ if st.Err == "" && st.RecordErr != "" && row.Error == "" {
+ row.Error = st.RecordErr // unknown whether it needs a repair
+ }
+ if st.Err == "" && st.NeedsRepair() {
+ wk.repairs = append(wk.repairs, digestRepRow{Account: sqid, App: app, Channel: st.Channel, Version: st.Version, Unbound: st.Unbound, NoRecord: st.NoRecord})
}
}
- acctRows = append(acctRows, row)
}
- writeJSON(w, http.StatusOK, map[string]any{"accounts": acctRows, "channels": chRows, "repairs": repRows})
+ return wk
}
diff --git a/internal/console/apidigests_test.go b/internal/console/apidigests_test.go
index b15184ea3..fddc22f49 100644
--- a/internal/console/apidigests_test.go
+++ b/internal/console/apidigests_test.go
@@ -5,10 +5,13 @@ import (
"crypto/ed25519"
"encoding/base64"
"encoding/json"
+ "errors"
"fmt"
"net/http"
"os"
+ "slices"
"strings"
+ "sync"
"testing"
"time"
@@ -551,3 +554,98 @@ func TestSystemDigestsDoorListsHeadsTheConsoleDoesNotKnow(t *testing.T) {
t.Fatalf("the console's own account reads as bucket-only: %s", out)
}
}
+
+// slowAppListStore answers every account's app listing ("apps/<acct>/") only
+// after a pause, counting how many are in flight at once, and fails the one
+// for failApps as an unreachable bucket would.
+type slowAppListStore struct {
+ release.Store
+ failApps string
+ mu sync.Mutex
+ inFlight int
+ most int
+}
+
+func (s *slowAppListStore) ListDirs(ctx context.Context, prefix string) ([]string, error) {
+ if prefix == "apps/" || !strings.HasPrefix(prefix, "apps/") || strings.Count(prefix, "/") != 2 {
+ return s.Store.ListDirs(ctx, prefix)
+ }
+ s.mu.Lock()
+ s.inFlight++
+ s.most = max(s.most, s.inFlight)
+ s.mu.Unlock()
+ defer func() { s.mu.Lock(); s.inFlight--; s.mu.Unlock() }()
+ time.Sleep(50 * time.Millisecond)
+ if prefix == "apps/"+s.failApps+"/" {
+ return nil, errors.New("bucket unreachable for this account")
+ }
+ return s.Store.ListDirs(ctx, prefix)
+}
+
+// Fable R3 P2-1: the report walks accounts four at a time under the door's
+// deadline, and still answers every account, each account's rows together,
+// in the order the sequential walk gave (the console's accounts, then the
+// bucket-only ones sorted), with an account it cannot list as an error row.
+func TestSystemDigestsDoorWalksAccountsInParallelInOrder(t *testing.T) {
+ fx := newDigestsFixture(t)
+ ctx := context.Background()
+ strangers := []string{"zqa", "zqb", "zqc", "zqd", "zqe", "zqf", "zqg", "zqh", "zqj"}
+ for _, acct := range strangers {
+ legacy := release.ChannelPointer{Schema: 1, App: "shop", Channel: "stable", Version: "v1", PromotedAt: time.Date(2026, 6, 1, 0, 0, 0, 0, time.UTC)}
+ payload, _ := json.MarshalIndent(legacy, "", " ")
+ b64 := base64.StdEncoding.EncodeToString(payload)
+ wire, _ := json.Marshal(map[string]string{"payload": b64, "sig": base64.StdEncoding.EncodeToString(ed25519.Sign(fx.priv, []byte(b64)))})
+ if _, err := fx.store.Put(ctx, release.ChannelKey(acct, "shop", "stable"), wire, ""); err != nil {
+ t.Fatal(err)
+ }
+ }
+ slow := &slowAppListStore{Store: fx.srv.cfg.Releases, failApps: "zqd"}
+ fx.srv.cfg.Releases = slow
+ st, out := getRaw(t, fx.ts.URL+"/api/cli/system/pointer-digests", fx.operator)
+ if st != http.StatusOK {
+ t.Fatalf("report: %d %s", st, out)
+ }
+ var rep struct {
+ Accounts []struct{ Account, Error string } `json:"accounts"`
+ Repairs []struct{ Account, App, Channel string } `json:"repairs"`
+ }
+ if err := json.Unmarshal([]byte(out), &rep); err != nil {
+ t.Fatalf("report body %s: %v", out, err)
+ }
+ accts, err := fx.st.Accounts()
+ if err != nil {
+ t.Fatal(err)
+ }
+ var want []string
+ for _, a := range accts {
+ want = append(want, a.Sqid)
+ }
+ want = append(want, strangers...)
+ var got []string
+ for _, a := range rep.Accounts {
+ got = append(got, a.Account)
+ wantErr := ""
+ if a.Account == "zqd" {
+ wantErr = fmt.Sprintf(textBucketListApps, "zqd", "bucket unreachable for this account")
+ }
+ if a.Error != wantErr {
+ t.Fatalf("%s's row error = %q, want %q", a.Account, a.Error, wantErr)
+ }
+ }
+ if !slices.Equal(got, want) {
+ t.Fatalf("account rows = %v, want %v", got, want)
+ }
+ var repaired []string
+ for _, r := range rep.Repairs {
+ if strings.HasPrefix(r.Account, "zq") {
+ repaired = append(repaired, r.Account)
+ }
+ }
+ wantRepaired := slices.DeleteFunc(slices.Clone(strangers), func(a string) bool { return a == "zqd" })
+ if !slices.Equal(repaired, wantRepaired) {
+ t.Fatalf("bucket-only repairs = %v, want %v", repaired, wantRepaired)
+ }
+ if slow.most < 2 || slow.most > 4 {
+ t.Fatalf("at most %d account walks ran at once, want 2 to 4", slow.most)
+ }
+}