provision: walk the fleet door's records per app, not the whole tree
Over the fleet store door, listAppSubtree fell back to List("apps/"),
which the door answers with every key of the account's apps/<sqid>/
subtree (artifacts, log chunks), paged from S3 at the hub, on every
record walk. The door client now declares release.AccountScopedListDirs:
its ListDirs("apps/") is the account's app directories (aclListScope
maps apps/ to apps/<sqid>/, unchanged since the door was built). The
walk lists those once, then one List per app of a known account at the
sub it needs. A listing not of the declared shape falls back to the
whole tree; one app's listing failing is partial, the app listing
failing is an error.
The startup counting wrapper forwards the capability, so the walk takes
the same branch through it. Door test: real fleetapi client against the
real edge door; key set, records, completeness and unreadable hosts
equal the whole-tree listing's, and no whole subtree is listed.
Census: envelopes re-pinned (fleet-first-reconcile-speed-2).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
12 files changed,
+702
−21
docs/superpowers/notes/census-proposal-fleet-first-reconcile-speed-2.md+11 −0internal/fleetapi/fleetapi.go+10 −0internal/host/startupmeasure_e2e_test.go+12 −4internal/host/startuptiming.go+11 −2internal/host/startuptiming_test.go+4 −1internal/provision/export_test.go+11 −0internal/provision/reconcile.go+92 −14internal/provision/scopedwalk_door_test.go+452 −0internal/provision/scopedwalk_test.go+69 −0internal/provision/testdata/plan14-root-reads-chain.tsv+1 −0internal/provision/testdata/plan14-root-reads-fleet-first-reconcile-speed-2.tsv+6 −0internal/release/store.go+23 −0
diff --git a/docs/superpowers/notes/census-proposal-fleet-first-reconcile-speed-2.md b/docs/superpowers/notes/census-proposal-fleet-first-reconcile-speed-2.md| new file mode 100644 |
| index 000000000..cb5d312cf |
| --- /dev/null |
| +++ b/docs/superpowers/notes/census-proposal-fleet-first-reconcile-speed-2.md |
| @@ -0,0 +1,11 @@ |
| +# Census approval: fleet-first-reconcile-speed-2 |
| + |
| +Ruling `census-ruling-fleet-first-reconcile-speed-2`. The independent reviewer approves or rejects every change below, 0 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26). |
| + |
| +Envelopes re-pinned: `internal/fleetapi`, `internal/host`, `internal/provision`, `internal/release`. |
| + |
| +Review: a model from the other family than the author reads the branch's diff against main on the amadan.net remote (`origin` or `amadan`, whichever points at amadan.net) and gives a verdict for every unit and every re-pinned envelope above. For a unit, compare the change with its recorded disposition and basis below; for an envelope, read every changed function in the package and what it reaches. Reject if the change lets root open, run, query or follow anything it did not before from a path or input a tenant, an app or a box agent can create, write or name; if it weakens a check, refusal, validation, argument or environment the basis relies on; or if the diff cannot settle either. Otherwise approve. Record each verdict on #280 with the tip. A rejected unit goes back to the author to correct; nothing escalates to the census owner. |
| + |
| +Seal: `9206205b2a3bf27b8b85310f4a44f94ef0c5886d85d6e55dbf2f22e073a8af11` → `9206205b2a3bf27b8b85310f4a44f94ef0c5886d85d6e55dbf2f22e073a8af11`. |
| + |
| +Overlay: `internal/provision/testdata/plan14-root-reads-fleet-first-reconcile-speed-2.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`. |
diff --git a/internal/fleetapi/fleetapi.go b/internal/fleetapi/fleetapi.go| index df0203718..5579f46b9 100644 |
| --- a/internal/fleetapi/fleetapi.go |
| +++ b/internal/fleetapi/fleetapi.go |
| @@ -320,6 +320,16 @@ func (s *store) ListDirs(ctx context.Context, prefix string) ([]string, error) { |
| return s.listDecode(ctx, "/store/dirs", prefix) |
| } |
| +var _ release.AccountScopedListDirs = (*store)(nil) |
| + |
| +// AccountScopedListDirs: the door scopes a box to its own account. It maps |
| +// /store/dirs?prefix=apps/ to the account's own apps/<sqid>/, so the answer |
| +// is the account's app directories, and it serves /store/list under |
| +// apps/<sqid>/<app>/ as asked (storedoor.go, aclListScope and aclDir; the |
| +// same since the door was first built). Not bucket-shaped: ListDirs("apps/") |
| +// is never the account directories. |
| +func (s *store) AccountScopedListDirs() bool { return true } |
| + |
| func (s *store) listDecode(ctx context.Context, path, prefix string) ([]string, error) { |
| req, err := s.newRequest(ctx, http.MethodGet, s.listURL(path, prefix), nil) |
| if err != nil { |
diff --git a/internal/host/startupmeasure_e2e_test.go b/internal/host/startupmeasure_e2e_test.go| index f64ab8d3e..a4f82049f 100644 |
| --- a/internal/host/startupmeasure_e2e_test.go |
| +++ b/internal/host/startupmeasure_e2e_test.go |
| @@ -89,11 +89,12 @@ func TestStartupMeasure(t *testing.T) { |
| } |
| } |
| -// slowDoor is the fleet store door's shape (Store, Opener, ETagLister) over |
| -// a fast store: every op waits lat first, then is noted with its key and |
| -// how many ops were in flight when it began. |
| +// slowDoor is the fleet store door's shape (Store, Opener, ETagLister, |
| +// AccountScopedListDirs) over a fast store: every op waits lat first, then |
| +// is noted with its key and how many ops were in flight when it began. |
| type slowDoor struct { |
| inner release.Store // a DirStore: Opener and ETagLister both |
| + acct string // the box's account: the door scopes apps/ to it |
| lat time.Duration |
| inflight atomic.Int32 |
| @@ -143,11 +144,18 @@ func (d *slowDoor) List(ctx context.Context, prefix string) ([]string, error) { |
| return d.inner.List(ctx, prefix) |
| } |
| +// ListDirs maps apps/ to the account's own apps/<acct>/, as the door's |
| +// aclListScope does, so ListDirs("apps/") is the account's app directories. |
| func (d *slowDoor) ListDirs(ctx context.Context, prefix string) ([]string, error) { |
| defer d.begin(opDirs, prefix)() |
| + if prefix == "apps" || prefix == "apps/" { |
| + prefix = "apps/" + d.acct + "/" |
| + } |
| return d.inner.ListDirs(ctx, prefix) |
| } |
| +func (d *slowDoor) AccountScopedListDirs() bool { return true } |
| + |
| func (d *slowDoor) Delete(ctx context.Context, key string) error { |
| defer d.begin(opDelete, key)() |
| return d.inner.Delete(ctx, key) |
| @@ -221,7 +229,7 @@ func measureStartup(t *testing.T, n int, lat time.Duration) string { |
| } |
| armMeasuredBox(t, b, getenv, judge) |
| ctx = provision.WithLifetimes(ctx, judge) |
| - door := &slowDoor{inner: w.store, lat: lat} |
| + door := &slowDoor{inner: w.store, acct: w.acct, lat: lat} |
| if storeExts(door) != doorShape { |
| t.Fatal("fixture: the fake door is not the fleet door's shape") |
| } |
diff --git a/internal/host/startuptiming.go b/internal/host/startuptiming.go| index 5004ed6d6..e78c4f0a8 100644 |
| --- a/internal/host/startuptiming.go |
| +++ b/internal/host/startuptiming.go |
| @@ -167,9 +167,15 @@ func (s *opCountingStore) listETags(ctx context.Context, prefix string) ([]relea |
| } |
| // doorCountingStore is the shape of the fleet store door (fleetapi): Store, |
| -// Opener and ETagLister. |
| +// Opener, ETagLister and AccountScopedListDirs. |
| type doorCountingStore struct{ *opCountingStore } |
| +// AccountScopedListDirs answers as the door does, so the record walk lists |
| +// through this wrapper exactly as it lists through the door. |
| +func (s doorCountingStore) AccountScopedListDirs() bool { |
| + return release.HasAccountScopedListDirs(s.inner) |
| +} |
| + |
| func (s doorCountingStore) Open(ctx context.Context, key string) (io.ReadCloser, string, error) { |
| return s.open(ctx, key) |
| } |
| @@ -259,13 +265,14 @@ const ( |
| extVersionDirLister |
| extBucketListDirs |
| extAppMutationRunner |
| + extAccountScopedListDirs |
| ) |
| type storeExt uint32 |
| const ( |
| plainShape = storeExt(0) |
| - doorShape = extOpener | extETagLister |
| + doorShape = extOpener | extETagLister | extAccountScopedListDirs |
| dirShape = extOpener | extPutStreamer | extPageLister | extModLister | extSizeLister | |
| extConditionalGetter | extETagLister | extConditionalDeleter | extIndexedDeleter | extBatchDeleter |
| ) |
| @@ -311,6 +318,8 @@ func storeExts(s release.Store) storeExt { |
| has(extBucketListDirs, ok) |
| _, ok = s.(release.AppMutationRunner) |
| has(extAppMutationRunner, ok) |
| + _, ok = s.(release.AccountScopedListDirs) |
| + has(extAccountScopedListDirs, ok) |
| return e |
| } |
diff --git a/internal/host/startuptiming_test.go b/internal/host/startuptiming_test.go| index 7d1c9ed03..033b09b9c 100644 |
| --- a/internal/host/startuptiming_test.go |
| +++ b/internal/host/startuptiming_test.go |
| @@ -18,9 +18,12 @@ import ( |
| // plainShapedStore is a Store with none of release's optional interfaces. |
| type plainShapedStore struct{ release.Store } |
| -// doorShapedStore has the fleet door's shape: Store, Opener and ETagLister. |
| +// doorShapedStore has the fleet door's shape: Store, Opener, ETagLister and |
| +// AccountScopedListDirs. |
| type doorShapedStore struct{ inner *release.DirStore } |
| +func (doorShapedStore) AccountScopedListDirs() bool { return true } |
| + |
| func (s doorShapedStore) Get(ctx context.Context, k string) ([]byte, string, error) { |
| return s.inner.Get(ctx, k) |
| } |
diff --git a/internal/provision/export_test.go b/internal/provision/export_test.go| new file mode 100644 |
| index 000000000..6a5980b93 |
| --- /dev/null |
| +++ b/internal/provision/export_test.go |
| @@ -0,0 +1,11 @@ |
| +package provision |
| + |
| +// Hooks for the external door test (scopedwalk_door_test.go), which lives in |
| +// package provision_test because it stands up the real edge, and edge |
| +// imports this package. |
| + |
| +// ListAppSubtreeForTest is listAppSubtree. |
| +var ListAppSubtreeForTest = listAppSubtree |
| + |
| +// KnownAccountsForTest is knownAccounts. |
| +var KnownAccountsForTest = knownAccounts |
diff --git a/internal/provision/reconcile.go b/internal/provision/reconcile.go| index 780da7732..d6b91c2b3 100644 |
| --- a/internal/provision/reconcile.go |
| +++ b/internal/provision/reconcile.go |
| @@ -3374,12 +3374,19 @@ func readAllRecords(ctx context.Context, s release.Store, strict bool) (recs []R |
| // directory directly under the account, so no record lives anywhere the walk |
| // does not look — PROVIDED ListDirs answers in the bucket's shape. Only a |
| // store that says so (release.HasBucketListDirs: the S3 store, and a prefix |
| -// store over one) is walked; the fleet door, whose ListDirs("apps/") is its |
| -// own account's app directories, and DirStore, which lists by walking its |
| -// whole root, are listed the old way. Assuming the shape on the fleet door |
| +// store over one) is walked that way. Assuming the shape on the fleet door |
| // found no records at all, and the reconcile pass would have read that as |
| // every route retired. |
| // |
| +// The fleet door has the other shape, and says so |
| +// (release.HasAccountScopedListDirs): its ListDirs("apps/") is its own |
| +// account's APP directories. It is walked one level shallower |
| +// (listScopedAppSubtree): that one ListDirs, then one small List per app of a |
| +// known account. Over the door the whole-tree List("apps/") was every |
| +// artifact and log chunk of the account, paged from S3 at the hub and sent to |
| +// the box, on every walk. DirStore, which lists by walking its whole root, |
| +// declares neither and is listed the old way. |
| +// |
| // Failure comes in two sizes. The top-level listing failing is an error, as |
| // the single List failing was. One account's or one app's listing failing is |
| // PARTIAL: the keys that were listed come back, and partial reports that some |
| @@ -3390,9 +3397,10 @@ func readAllRecords(ctx context.Context, s release.Store, strict bool) (recs []R |
| // routes from being minted. |
| func listAppSubtree(ctx context.Context, s release.Store, known map[string]bool, sub string) (keys []string, partial bool, err error) { |
| if !release.HasBucketListDirs(s) { |
| - keys, err := s.List(ctx, "apps/") |
| - slices.Sort(keys) // Store.List promises no order; the walk's is sorted |
| - return keys, false, err |
| + if release.HasAccountScopedListDirs(s) { |
| + return listScopedAppSubtree(ctx, s, known, sub) |
| + } |
| + return listWholeAppTree(ctx, s) |
| } |
| accts, err := s.ListDirs(ctx, "apps/") |
| if err != nil { |
| @@ -3408,12 +3416,7 @@ func listAppSubtree(ctx context.Context, s release.Store, known map[string]bool, |
| var ( |
| mu sync.Mutex |
| prefixes []string |
| - out []string |
| ) |
| - fail := func(what string, err error) { |
| - log.Printf("provision: listing %s: %v — its records are unseen this pass", what, err) |
| - partial = true |
| - } |
| // A handful at a time, accounts and apps alike: each is one small round |
| // trip, and a box walks a few dozen accounts and a few hundred apps. |
| forEach(acctPrefixes, func(ap string) { |
| @@ -3421,25 +3424,100 @@ func listAppSubtree(ctx context.Context, s release.Store, known map[string]bool, |
| mu.Lock() |
| defer mu.Unlock() |
| if err != nil { |
| - fail(ap, err) |
| + unseenListing(ap, err) |
| + partial = true |
| return |
| } |
| for _, p := range apps { |
| prefixes = append(prefixes, p+sub) |
| } |
| }) |
| + out, appsPartial := listEachPrefix(ctx, s, prefixes) |
| + return out, partial || appsPartial, nil |
| +} |
| + |
| +// listWholeAppTree is the old way: every key under apps/, sorted. A store |
| +// that declares no directory shape is read so. |
| +func listWholeAppTree(ctx context.Context, s release.Store) ([]string, bool, error) { |
| + keys, err := s.List(ctx, "apps/") |
| + slices.Sort(keys) // Store.List promises no order; the walk's is sorted |
| + return keys, false, err |
| +} |
| + |
| +// listScopedAppSubtree is listAppSubtree over an account-scoped store (the |
| +// fleet door): ListDirs("apps/") names the scope's app directories, |
| +// "apps/<acct>/<app>/", and each one of a known account is listed at sub. |
| +// It finds the same records the whole-tree listing did: a record key is |
| +// apps/<acct>/<app>/<sub><name>, its app is one of those directories, and |
| +// its account must be known for any caller to parse it. |
| +// |
| +// It trusts the shape only as far as it can see it. An entry that is not an |
| +// app directory (a bucket-shaped "apps/<acct>/", say, from a store that |
| +// declares the wrong shape) means the listing is not what this walk assumes, |
| +// and the walk falls back to the whole-tree listing rather than look in the |
| +// wrong place and find nothing. Failure sizes are listAppSubtree's: the |
| +// ListDirs failing is an error, one app's listing failing is partial. |
| +func listScopedAppSubtree(ctx context.Context, s release.Store, known map[string]bool, sub string) ([]string, bool, error) { |
| + dirs, err := s.ListDirs(ctx, "apps/") |
| + if err != nil { |
| + return nil, false, err |
| + } |
| + var prefixes []string |
| + for _, d := range dirs { |
| + acct, ok := scopedAppDirAccount(d) |
| + if !ok { |
| + log.Printf("provision: the account-scoped app listing answered %q, not an app directory: listing apps/ whole", d) |
| + return listWholeAppTree(ctx, s) |
| + } |
| + if known[acct] { |
| + prefixes = append(prefixes, d+sub) |
| + } |
| + } |
| + keys, partial := listEachPrefix(ctx, s, prefixes) |
| + return keys, partial, nil |
| +} |
| + |
| +// scopedAppDirAccount reports the account of an app directory, |
| +// "apps/<acct>/<app>/" with both segments non-empty, and whether d is one. |
| +func scopedAppDirAccount(d string) (string, bool) { |
| + rest, ok := strings.CutPrefix(d, "apps/") |
| + if !ok { |
| + return "", false |
| + } |
| + rest, ok = strings.CutSuffix(rest, "/") |
| + if !ok { |
| + return "", false |
| + } |
| + acct, app, ok := strings.Cut(rest, "/") |
| + if !ok || acct == "" || app == "" || strings.Contains(app, "/") { |
| + return "", false |
| + } |
| + return acct, true |
| +} |
| + |
| +// listEachPrefix lists every prefix, a handful at a time, and returns all |
| +// the keys sorted. partial reports that a listing failed: its keys are |
| +// unseen this pass. |
| +func listEachPrefix(ctx context.Context, s release.Store, prefixes []string) (out []string, partial bool) { |
| + var mu sync.Mutex |
| forEach(prefixes, func(p string) { |
| keys, err := s.List(ctx, p) |
| mu.Lock() |
| defer mu.Unlock() |
| if err != nil { |
| - fail(p, err) |
| + unseenListing(p, err) |
| + partial = true |
| return |
| } |
| out = append(out, keys...) |
| }) |
| slices.Sort(out) |
| - return out, partial, nil |
| + return out, partial |
| +} |
| + |
| +// unseenListing logs a listing that failed in a record walk. |
| +func unseenListing(what string, err error) { |
| + log.Printf("provision: listing %s: %v: its records are unseen this pass", what, err) |
| } |
| // readChunk is how many keys a judging loop prefetches at once: enough to keep |
diff --git a/internal/provision/scopedwalk_door_test.go b/internal/provision/scopedwalk_door_test.go| new file mode 100644 |
| index 000000000..5e08007cd |
| --- /dev/null |
| +++ b/internal/provision/scopedwalk_door_test.go |
| @@ -0,0 +1,452 @@ |
| +package provision_test |
| + |
| +import ( |
| + "context" |
| + "crypto/sha256" |
| + "encoding/hex" |
| + "errors" |
| + "fmt" |
| + "net/http" |
| + "net/http/httptest" |
| + "net/url" |
| + "path/filepath" |
| + "reflect" |
| + "slices" |
| + "sort" |
| + "strings" |
| + "sync" |
| + "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/domains" |
| + "github.com/carlosframework/platform/internal/edge" |
| + "github.com/carlosframework/platform/internal/fleetapi" |
| + "github.com/carlosframework/platform/internal/provision" |
| + "github.com/carlosframework/platform/internal/registry" |
| + "github.com/carlosframework/platform/internal/release" |
| +) |
| + |
| +// The record walk over the fleet store door: the real fleetapi client |
| +// against the real door (a real edge, its credential table and ACL, a |
| +// DirStore behind it). The door-shaped walk must find exactly the records |
| +// the whole-tree listing found, and never list an app's whole subtree. |
| + |
| +// s3Page is the S3 ListObjectsV2 page size: the hub pays one LIST request |
| +// per page of the backing listing. |
| +const s3Page = 1000 |
| + |
| +func s3Pages(n int) int { |
| + if n <= s3Page { |
| + return 1 |
| + } |
| + return (n + s3Page - 1) / s3Page |
| +} |
| + |
| +// hubList is one listing the door made of the bucket behind it. |
| +type hubList struct { |
| + dirs bool |
| + prefix string |
| + n int // entries the bucket answered, before the door's ACL filter |
| +} |
| + |
| +// hubStore is the bucket behind the door: a DirStore that notes every |
| +// listing the door makes of it and can fail chosen ones. |
| +type hubStore struct { |
| + *release.DirStore |
| + mu sync.Mutex |
| + lists []hubList |
| + fail map[string]bool // listing prefixes that fail |
| +} |
| + |
| +func (h *hubStore) note(dirs bool, prefix string, n int) { |
| + h.mu.Lock() |
| + defer h.mu.Unlock() |
| + h.lists = append(h.lists, hubList{dirs, prefix, n}) |
| +} |
| + |
| +func (h *hubStore) List(ctx context.Context, prefix string) ([]string, error) { |
| + if h.fail[prefix] { |
| + h.note(false, prefix, 0) |
| + return nil, errors.New("bucket listing failed") |
| + } |
| + keys, err := h.DirStore.List(ctx, prefix) |
| + h.note(false, prefix, len(keys)) |
| + return keys, err |
| +} |
| + |
| +func (h *hubStore) ListDirs(ctx context.Context, prefix string) ([]string, error) { |
| + if h.fail[prefix] { |
| + h.note(true, prefix, 0) |
| + return nil, errors.New("bucket listing failed") |
| + } |
| + dirs, err := h.DirStore.ListDirs(ctx, prefix) |
| + h.note(true, prefix, len(dirs)) |
| + return dirs, err |
| +} |
| + |
| +func (h *hubStore) take() []hubList { |
| + h.mu.Lock() |
| + defer h.mu.Unlock() |
| + out := h.lists |
| + h.lists = nil |
| + return out |
| +} |
| + |
| +// doorReq is one request the box made of the door. |
| +type doorReq struct{ path, prefix string } |
| + |
| +// doorLog notes every request at the door's HTTP handler. |
| +type doorLog struct { |
| + mu sync.Mutex |
| + reqs []doorReq |
| +} |
| + |
| +func (l *doorLog) wrap(h http.Handler) http.Handler { |
| + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| + l.mu.Lock() |
| + l.reqs = append(l.reqs, doorReq{r.URL.Path, r.URL.Query().Get("prefix")}) |
| + l.mu.Unlock() |
| + h.ServeHTTP(w, r) |
| + }) |
| +} |
| + |
| +func (l *doorLog) take() []doorReq { |
| + l.mu.Lock() |
| + defer l.mu.Unlock() |
| + out := l.reqs |
| + l.reqs = nil |
| + return out |
| +} |
| + |
| +// walkDoor is the hub (its bucket and the door's request log) and one fleet |
| +// box's store over the door. |
| +type walkDoor struct { |
| + hub *hubStore |
| + reqs *doorLog |
| + box release.Store |
| +} |
| + |
| +const walkFleet = "pi" |
| + |
| +// newWalkDoor builds the hub for fleet pi, owned by acct, and dials the door |
| +// as pi/box-1, as openDeployStoreEnv does on a fleet box. |
| +func newWalkDoor(t *testing.T, acct string) *walkDoor { |
| + t.Helper() |
| + reg, err := registry.Open(filepath.Join(t.TempDir(), "registry.db")) |
| + if err != nil { |
| + t.Fatalf("open registry: %v", err) |
| + } |
| + t.Cleanup(func() { _ = reg.Close() }) |
| + if err := reg.UpsertFleet(registry.Fleet{Name: walkFleet, Account: acct, Bucket: walkFleet + "-data"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + const token = "pi-box-1-token" |
| + sum := sha256.Sum256([]byte(token)) |
| + if err := reg.AddFleetBox(registry.FleetBox{Fleet: walkFleet, Label: "box-1", TokenHash: hex.EncodeToString(sum[:]), Status: "active"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + _, pubB64, err := release.GenerateKey() |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + pub, err := release.ParsePublicKey(pubB64, "test") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + e, err := edge.New(reg, nil) |
| + if err != nil { |
| + t.Fatalf("edge.New: %v", err) |
| + } |
| + d := &walkDoor{hub: &hubStore{DirStore: release.NewDirStore(t.TempDir()), fail: map[string]bool{}}, reqs: &doorLog{}} |
| + srv := httptest.NewServer(d.reqs.wrap(e)) |
| + t.Cleanup(srv.Close) |
| + u, err := url.Parse(srv.URL) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + e.EnableStatic(d.hub, pub, filepath.Join(t.TempDir(), "cache")) |
| + e.EnableTunnels(edge.NewTunnelHub(u.Hostname(), nil)) |
| + if err := e.Reload(); err != nil { |
| + t.Fatalf("Reload: %v", err) |
| + } |
| + d.box, err = fleetapi.New(srv.URL, walkFleet+"/box-1", token) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + return d |
| +} |
| + |
| +// wholeTreeStore hides every optional interface of the door client, so the |
| +// walk reads it the old way: one List("apps/"). |
| +type wholeTreeStore struct{ release.Store } |
| + |
| +// walkFixture is what newWalkFixture put in the bucket. |
| +type walkFixture struct { |
| + acct, other string |
| + apps []string // the account's app directories |
| + objects int // objects under apps/<acct>/ |
| +} |
| + |
| +// newWalkFixture fills the hub's bucket: the box's account with two apps |
| +// with records (sidecar keys, artifacts, channel pointers, a malformed |
| +// record, and logChunks log chunks under shop), an app with only an |
| +// artifact, a key at the account level, and a second account with records |
| +// the box must never see. |
| +func newWalkFixture(t *testing.T, s release.Store, acct, other string, logChunks int) walkFixture { |
| + t.Helper() |
| + ctx := context.Background() |
| + f := walkFixture{acct: acct, other: other, apps: []string{"blog", "docs", "shop"}} |
| + put := func(key, body string) { |
| + t.Helper() |
| + if _, err := s.Put(ctx, key, []byte(body), ""); err != nil { |
| + t.Fatalf("put %s: %v", key, err) |
| + } |
| + if strings.HasPrefix(key, "apps/"+acct+"/") { |
| + f.objects++ |
| + } |
| + } |
| + for i, a := range []string{acct, other} { |
| + id := int64(41 + i) |
| + if domains.Sqid(id) != a { |
| + t.Fatalf("fixture: account %d is %q, not %q", id, domains.Sqid(id), a) |
| + } |
| + put(domains.AccountManifestKey(a), fmt.Sprintf(`{"id":%d,"sqid":%q,"name":"Account %d","created_at":"2026-08-02T09:00:00Z"}`, id, a, id)) |
| + } |
| + record := func(a, app, host string) { |
| + t.Helper() |
| + rec := provision.Record{Schema: 1, Host: host, Slug: strings.SplitN(host, ".", 2)[0], App: app, |
| + Account: a, Pool: "main", Region: "ie", Channel: "stable", CreatedAt: time.Unix(1_700_000_000, 0).UTC()} |
| + if err := provision.CreateRecord(ctx, s, rec); err != nil { |
| + t.Fatalf("record %s: %v", host, err) |
| + } |
| + if a == acct { |
| + f.objects++ |
| + } |
| + } |
| + for _, app := range []string{"shop", "blog"} { |
| + p := release.AppPrefix(acct, app) |
| + for i := range 3 { |
| + record(acct, app, fmt.Sprintf("%s-%d.example.com", app, i)) |
| + } |
| + put(p+"instances/broken-"+app+".example.com.json", `{"schema":`) |
| + put(p+"instances.json", `{}`) |
| + put(p+"channels/stable.json", `{}`) |
| + put(p+"sidecars/cache.json", `{}`) |
| + put(p+"sidecars/queue.json", `{}`) |
| + for v := range 4 { |
| + put(fmt.Sprintf("%sartifacts/v%d/app.tar.gz", p, v), "tar") |
| + put(fmt.Sprintf("%sartifacts/v%d/manifest.json", p, v), "{}") |
| + } |
| + } |
| + for c := range logChunks { |
| + put(fmt.Sprintf("%slogs/box-1/%06d.jsonl.gz", release.AppPrefix(acct, "shop"), c), "log") |
| + } |
| + put(release.AppPrefix(acct, "docs")+"artifacts/v1/app.tar.gz", "tar") |
| + put("apps/"+acct+"/notes.txt", "not an app") |
| + record(other, "shop", "theirs.example.com") |
| + put(release.AppPrefix(other, "shop")+"sidecars/cache.json", `{}`) |
| + return f |
| +} |
| + |
| +// callerKeys is what a record reader takes from a listing: keys under |
| +// apps/<known acct>/<app>/<sub>. |
| +func callerKeys(keys []string, known map[string]bool, sub string) []string { |
| + var out []string |
| + for _, k := range keys { |
| + parts := strings.SplitN(k, "/", 4) |
| + if len(parts) == 4 && parts[0] == "apps" && known[parts[1]] && strings.HasPrefix(parts[3], sub) { |
| + out = append(out, k) |
| + } |
| + } |
| + return out |
| +} |
| + |
| +func sortedRecords(recs []provision.Record) []provision.Record { |
| + out := slices.Clone(recs) |
| + sort.Slice(out, func(i, j int) bool { return out[i].Host < out[j].Host }) |
| + return out |
| +} |
| + |
| +// TestScopedWalkOverTheDoorFindsTheWholeTreeRecords: over the door, the walk |
| +// finds exactly the keys and records the whole-tree listing found, with the |
| +// same completeness and the same unreadable hosts, by one /store/dirs of |
| +// apps/ and one /store/list per app. It never lists a whole app or account |
| +// subtree. The S3 listings it costs the hub are counted against the old |
| +// walk's. |
| +func TestScopedWalkOverTheDoorFindsTheWholeTreeRecords(t *testing.T) { |
| + ctx := context.Background() |
| + acct, other := domains.Sqid(41), domains.Sqid(42) |
| + d := newWalkDoor(t, acct) |
| + f := newWalkFixture(t, d.hub, acct, other, 40) |
| + |
| + if !release.HasAccountScopedListDirs(d.box) || release.HasBucketListDirs(d.box) { |
| + t.Fatal("the door client must declare the account-scoped shape and not the bucket shape") |
| + } |
| + if release.HasAccountScopedListDirs(release.NewPrefixStore(d.box, "fleets/"+walkFleet+"/")) { |
| + t.Fatal("a prefix store over the door changes the keyspace and must not declare the door's shape") |
| + } |
| + old := wholeTreeStore{d.box} |
| + if release.HasAccountScopedListDirs(old) { |
| + t.Fatal("fixture: the whole-tree store must declare nothing") |
| + } |
| + |
| + known, readFailed, err := provision.KnownAccountsForTest(ctx, d.box) |
| + if err != nil || readFailed { |
| + t.Fatalf("knownAccounts over the door: %v, readFailed %v", err, readFailed) |
| + } |
| + if !known[acct] || known[other] { |
| + t.Fatalf("known = %v: want the box's account and not the other", known) |
| + } |
| + d.reqs.take() |
| + d.hub.take() |
| + |
| + for _, sub := range []string{"instances/", "sidecars/"} { |
| + oldKeys, oldPartial, err := provision.ListAppSubtreeForTest(ctx, old, known, sub) |
| + if err != nil || oldPartial { |
| + t.Fatalf("%s whole tree: %v, partial %v", sub, err, oldPartial) |
| + } |
| + oldReqs, oldHub := d.reqs.take(), d.hub.take() |
| + |
| + newKeys, newPartial, err := provision.ListAppSubtreeForTest(ctx, d.box, known, sub) |
| + if err != nil || newPartial { |
| + t.Fatalf("%s scoped: %v, partial %v", sub, err, newPartial) |
| + } |
| + newReqs, newHub := d.reqs.take(), d.hub.take() |
| + |
| + want := callerKeys(oldKeys, known, sub) |
| + if len(want) == 0 { |
| + t.Fatalf("fixture: no %s keys in the whole-tree listing", sub) |
| + } |
| + if !slices.Equal(newKeys, want) { |
| + t.Errorf("%s: scoped walk keys\n %v\nwant the whole-tree listing's\n %v", sub, newKeys, want) |
| + } |
| + if len(oldKeys) != f.objects { |
| + t.Errorf("%s: whole-tree listing had %d keys, the account holds %d objects", sub, len(oldKeys), f.objects) |
| + } |
| + |
| + // Requests at the door: the old walk is one list of apps/; the new |
| + // one is one dirs of apps/ and one list per app at sub. |
| + if want := []doorReq{{"/store/list", "apps/"}}; !reflect.DeepEqual(oldReqs, want) { |
| + t.Errorf("%s whole tree: door requests %v, want %v", sub, oldReqs, want) |
| + } |
| + var lists []string |
| + dirs := 0 |
| + for _, r := range newReqs { |
| + switch r.path { |
| + case "/store/dirs": |
| + dirs++ |
| + if r.prefix != "apps/" { |
| + t.Errorf("%s: /store/dirs of %q, want only apps/", sub, r.prefix) |
| + } |
| + case "/store/list": |
| + lists = append(lists, r.prefix) |
| + default: |
| + t.Errorf("%s: unexpected door request %v", sub, r) |
| + } |
| + } |
| + sort.Strings(lists) |
| + var wantLists []string |
| + for _, app := range f.apps { |
| + wantLists = append(wantLists, release.AppPrefix(acct, app)+sub) |
| + } |
| + if dirs != 1 || !slices.Equal(lists, wantLists) { |
| + t.Errorf("%s: %d dirs and lists %v, want 1 dirs and %v", sub, dirs, lists, wantLists) |
| + } |
| + for _, p := range lists { |
| + if !strings.HasSuffix(p, "/"+sub) { |
| + t.Errorf("%s: listed %q, a whole subtree", sub, p) |
| + } |
| + } |
| + |
| + // The hub's S3 cost, one LIST request per 1000-entry page. |
| + oldPages, newPages := 0, 0 |
| + for _, l := range oldHub { |
| + oldPages += s3Pages(l.n) |
| + } |
| + for _, l := range newHub { |
| + newPages += s3Pages(l.n) |
| + } |
| + if len(oldHub) != 1 || oldHub[0].dirs || oldHub[0].prefix != "apps/"+acct+"/" { |
| + t.Errorf("%s whole tree: hub listings %+v, want one list of apps/%s/", sub, oldHub, acct) |
| + } |
| + if wantNew := 1 + len(f.apps); len(newHub) != wantNew || newPages != wantNew { |
| + t.Errorf("%s scoped: hub listings %+v (%d pages), want %d one-page listings", sub, newHub, newPages, wantNew) |
| + } |
| + t.Logf("%s: door requests old %d new %d; hub listings old %d (%d entries, %d S3 pages) new %d (%d S3 pages)", |
| + sub, len(oldReqs), len(newReqs), len(oldHub), oldHub[0].n, oldPages, len(newHub), newPages) |
| + } |
| + |
| + // The record readers: the same records, completeness and unreadable |
| + // hosts, tolerant and strict. |
| + oldRecs, oldComplete, oldUnreadable, err := provision.ListAllRecordsTolerantUnreadable(ctx, old) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + newRecs, newComplete, newUnreadable, err := provision.ListAllRecordsTolerantUnreadable(ctx, d.box) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if len(oldRecs) != 6 || !oldComplete || len(oldUnreadable) != 2 { |
| + t.Fatalf("fixture: whole tree read %d records, complete %v, unreadable %v; want 6, true, 2", len(oldRecs), oldComplete, oldUnreadable) |
| + } |
| + if !reflect.DeepEqual(sortedRecords(newRecs), sortedRecords(oldRecs)) || newComplete != oldComplete || !reflect.DeepEqual(newUnreadable, oldUnreadable) { |
| + t.Errorf("scoped walk read %d records (complete %v, unreadable %v), want the whole tree's %d (complete %v, unreadable %v)", |
| + len(newRecs), newComplete, newUnreadable, len(oldRecs), oldComplete, oldUnreadable) |
| + } |
| + oldStrict, oldStrictUnreadable, err := provision.ListAllRecordsStrict(ctx, old) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + newStrict, newStrictUnreadable, err := provision.ListAllRecordsStrict(ctx, d.box) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if !reflect.DeepEqual(sortedRecords(newStrict), sortedRecords(oldStrict)) || !reflect.DeepEqual(newStrictUnreadable, oldStrictUnreadable) { |
| + t.Errorf("strict: scoped walk read %d records, want the whole tree's %d", len(newStrict), len(oldStrict)) |
| + } |
| +} |
| + |
| +// TestScopedWalkOverTheDoorReportsFailures: one app's listing failing at |
| +// the hub is partial, never "no records" (the tolerant reader reports |
| +// incomplete, the strict one refuses), and the other apps' records are |
| +// still read. The app listing failing is an error, as the whole-tree |
| +// listing failing was. |
| +func TestScopedWalkOverTheDoorReportsFailures(t *testing.T) { |
| + ctx := context.Background() |
| + acct, other := domains.Sqid(41), domains.Sqid(42) |
| + d := newWalkDoor(t, acct) |
| + newWalkFixture(t, d.hub, acct, other, 3) |
| + known, _, err := provision.KnownAccountsForTest(ctx, d.box) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + |
| + d.hub.fail[release.AppPrefix(acct, "blog")+"instances/"] = true |
| + keys, partial, err := provision.ListAppSubtreeForTest(ctx, d.box, known, "instances/") |
| + if err != nil || !partial { |
| + t.Fatalf("one app's listing failed: err %v, partial %v; want partial and no error", err, partial) |
| + } |
| + for _, k := range keys { |
| + if strings.HasPrefix(k, release.AppPrefix(acct, "blog")) { |
| + t.Fatalf("listed %s from the app whose listing failed", k) |
| + } |
| + } |
| + if !slices.Contains(keys, provision.RecordKey(acct, "shop", "shop-0.example.com")) { |
| + t.Fatalf("the other app's records are missing: %v", keys) |
| + } |
| + recs, complete, _, err := provision.ListAllRecordsTolerantUnreadable(ctx, d.box) |
| + if err != nil || complete || len(recs) != 3 { |
| + t.Fatalf("tolerant: %d records, complete %v, err %v; want shop's 3, incomplete", len(recs), complete, err) |
| + } |
| + if _, _, err := provision.ListAllRecordsStrict(ctx, d.box); err == nil { |
| + t.Fatal("strict: a partial record set was reported whole") |
| + } |
| + |
| + d.hub.fail = map[string]bool{"apps/" + acct + "/": true} |
| + if keys, partial, err := provision.ListAppSubtreeForTest(ctx, d.box, known, "instances/"); err == nil { |
| + t.Fatalf("the app listing failed but the walk answered %v (partial %v)", keys, partial) |
| + } |
| + if _, _, _, err := provision.ListAllRecordsTolerantUnreadable(ctx, d.box); err == nil { |
| + t.Fatal("tolerant: the app listing failed but the reader answered") |
| + } |
| +} |
diff --git a/internal/provision/scopedwalk_test.go b/internal/provision/scopedwalk_test.go| new file mode 100644 |
| index 000000000..54f2ebf07 |
| --- /dev/null |
| +++ b/internal/provision/scopedwalk_test.go |
| @@ -0,0 +1,69 @@ |
| +package provision |
| + |
| +import ( |
| + "context" |
| + "slices" |
| + "testing" |
| + |
| + "github.com/carlosframework/platform/internal/release" |
| +) |
| + |
| +// misshapenScopedStore declares the account-scoped shape but answers |
| +// ListDirs as the bucket does (apps/ is the account directories). The walk |
| +// must notice and list the whole tree, not look one level too deep and find |
| +// nothing. |
| +type misshapenScopedStore struct { |
| + *release.DirStore |
| + lists []string |
| +} |
| + |
| +func (s *misshapenScopedStore) AccountScopedListDirs() bool { return true } |
| + |
| +func (s *misshapenScopedStore) List(ctx context.Context, prefix string) ([]string, error) { |
| + s.lists = append(s.lists, prefix) |
| + return s.DirStore.List(ctx, prefix) |
| +} |
| + |
| +func TestScopedWalkFallsBackWhenTheShapeIsWrong(t *testing.T) { |
| + inner, sqid := seedRecords(t, 3) |
| + ds := inner.(*release.DirStore) |
| + s := &misshapenScopedStore{DirStore: ds} |
| + known := map[string]bool{sqid: true} |
| + |
| + want, _, err := listAppSubtree(ctx, struct{ release.Store }{ds}, known, "instances/") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + got, partial, err := listAppSubtree(ctx, s, known, "instances/") |
| + if err != nil || partial { |
| + t.Fatalf("listAppSubtree: %v, partial %v", err, partial) |
| + } |
| + if !slices.Equal(got, want) { |
| + t.Fatalf("keys %v, want the whole tree's %v", got, want) |
| + } |
| + if !slices.Equal(s.lists, []string{"apps/"}) { |
| + t.Fatalf("lists %v, want the whole tree once", s.lists) |
| + } |
| + recs, err := ListAllRecords(ctx, s) |
| + if err != nil || len(recs) != 3 { |
| + t.Fatalf("ListAllRecords: %d records, %v; want 3", len(recs), err) |
| + } |
| +} |
| + |
| +// scopedAppDirAccount accepts only "apps/<acct>/<app>/". |
| +func TestScopedAppDirAccount(t *testing.T) { |
| + for d, want := range map[string]string{ |
| + "apps/a1/shop/": "a1", |
| + "apps/a1/": "", |
| + "apps/a1/shop": "", |
| + "apps//shop/": "", |
| + "apps/a1//": "", |
| + "apps/a1/b/c/": "", |
| + "other/a1/b/": "", |
| + } { |
| + got, ok := scopedAppDirAccount(d) |
| + if got != want || ok != (want != "") { |
| + t.Errorf("scopedAppDirAccount(%q) = %q, %v; want %q", d, got, ok, want) |
| + } |
| + } |
| +} |
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv| index 241ab02c2..82126b509 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-chain.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-chain.tsv |
| @@ -230,3 +230,4 @@ plan14-root-reads-fleet-unrouted-503.tsv 0f148cc5106065040691da81c9705da76b3663f |
| plan14-root-reads-fleet-unrouted-503-fix1.tsv e8043922abe9911a69ed6f5a9f8ec1d8f1db1aaf0c250f369cadff8ed394b079 |
| plan14-root-reads-omr-run.tsv f82b5e513d7434e1440c13aa4aa8bc06348745749a21593cf453f761ded0781b |
| plan14-root-reads-fleet-first-reconcile-speed.tsv 9206205b2a3bf27b8b85310f4a44f94ef0c5886d85d6e55dbf2f22e073a8af11 |
| +plan14-root-reads-fleet-first-reconcile-speed-2.tsv 9206205b2a3bf27b8b85310f4a44f94ef0c5886d85d6e55dbf2f22e073a8af11 |
diff --git a/internal/provision/testdata/plan14-root-reads-fleet-first-reconcile-speed-2.tsv b/internal/provision/testdata/plan14-root-reads-fleet-first-reconcile-speed-2.tsv| new file mode 100644 |
| index 000000000..1dd12b55b |
| --- /dev/null |
| +++ b/internal/provision/testdata/plan14-root-reads-fleet-first-reconcile-speed-2.tsv |
| @@ -0,0 +1,6 @@ |
| +# Census overlay fleet-first-reconcile-speed-2, written by census-propose (#369). census-ruling-fleet-first-reconcile-speed-2, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-fleet-first-reconcile-speed-2.md. |
| +# 0 body, 0 sites, 4 envelope: each changed unit re-frozen at its existing disposition with its claim appended. |
| +@coverage internal/fleetapi 9f9b22d82580627a074bd75b764ffd2c994b4b50dc2411ce857114f7c9cb302f |
| +@coverage internal/host 9c3839810d153f69d0e6ead21e505f6098b0d5a9d62ea52fa7bb25abd6fcb0a4 |
| +@coverage internal/provision 03006dd629a956aa48d4375d42e91ee03c642c0401a7b1f4ae84eee4be9f5298 |
| +@coverage internal/release 5092583f14bdd8fc440a9c406ce4356d90d746c11b7e5bfe2e128dc4cc80bfa3 |
diff --git a/internal/release/store.go b/internal/release/store.go| index 0e9198d6d..0ee951eb7 100644 |
| --- a/internal/release/store.go |
| +++ b/internal/release/store.go |
| @@ -111,6 +111,29 @@ func HasBucketListDirs(s Store) bool { |
| // BucketShapedListDirs: rebasing keeps the shape of the store underneath. |
| func (p prefixStore) BucketShapedListDirs() bool { return HasBucketListDirs(p.Store) } |
| +// AccountScopedListDirs is the optional half of Store that says the store is |
| +// scoped to ONE account and its directory listing answers in that scope's |
| +// shape: ListDirs("apps/") is that account's APP directories |
| +// ("apps/<acct>/<app>/"), and List under one of them answers that app's keys. |
| +// That is the fleet door (internal/edge/storedoor.go, aclListScope maps |
| +// "apps/" to the box's own "apps/<sqid>/"). A reader may then list each app's |
| +// records instead of every key of the account. |
| +// |
| +// A store that declares it must not also declare BucketListDirs: the two |
| +// shapes answer ListDirs("apps/") one level apart. A wrapper that changes |
| +// the keyspace (prefixStore) does not keep the shape, so it does not |
| +// declare it. |
| +type AccountScopedListDirs interface { |
| + AccountScopedListDirs() bool |
| +} |
| + |
| +// HasAccountScopedListDirs reports whether s promises account-scoped |
| +// ListDirs. |
| +func HasAccountScopedListDirs(s Store) bool { |
| + a, ok := s.(AccountScopedListDirs) |
| + return ok && a.AccountScopedListDirs() |
| +} |
| + |
| // NewPrefixStore wraps s so every key is rebased under prefix. An empty |
| // prefix returns s UNCHANGED (not a prefixStore with an empty base) — every |
| // deployment that never sets the namespacing env var (every platform box |