carlos / platform Public

console: check the account manifest once per process

Every app tab Got accounts/<sqid>/account.json on each view. Once the
manifest has been read or backfilled it never needs checking again in this
process, so Server remembers the sqid (manifestSeen) and ensureAccountManifest
returns at once for it. Errors are never remembered; account deletion forgets
the sqid. The app-tab frame drops from 7 to 6 warm S3 calls.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev ddc4b11202b853b4e7384907a223882aa5e1860c parent b3caaf5
4 files changed, +119 −14
  • internal/console/ownership.go +3 −0
  • internal/console/perfquickwins_test.go +90 −0
  • internal/console/server.go +11 −0
  • internal/console/testdata/perf-budgets.txt +15 −14

CI failed — run details

diff --git a/internal/console/ownership.go b/internal/console/ownership.go
index f776ff4a5..98af50470 100644
--- a/internal/console/ownership.go
+++ b/internal/console/ownership.go
@@ -165,6 +165,9 @@ func (s *Server) handleDeleteAccount(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/a/"+acct.Sqid+"/settings", http.StatusSeeOther)
return
}
+ // The account is retired in the bucket now: forget that its manifest was
+ // seen, so nothing in this process vouches for it any more.
+ s.manifestSeen.Delete(acct.Sqid)
if err := s.store.DeleteAccount(acct.ID, time.Now()); err != nil {
log.Printf("console: delete account: %v", err)
s.setFlash(w, "err", deletionAdvice(err))
diff --git a/internal/console/perfquickwins_test.go b/internal/console/perfquickwins_test.go
new file mode 100644
index 000000000..137268f1e
--- /dev/null
+++ b/internal/console/perfquickwins_test.go
@@ -0,0 +1,90 @@
+package console
+
+import (
+ "context"
+ "net/http"
+ "strings"
+ "sync"
+ "testing"
+ "time"
+)
+
+// manifestRequests records the HTTP methods of the S3 requests that name one
+// key, from the fake's request hook.
+type manifestRequests struct {
+ mu sync.Mutex
+ methods []string
+}
+
+func recordKeyRequests(lat *perfLatency, key string) *manifestRequests {
+ m := &manifestRequests{}
+ lat.Fake().OnRequest(func(r *http.Request) (int, <-chan struct{}) {
+ if strings.Contains(r.URL.Path, key) {
+ m.mu.Lock()
+ m.methods = append(m.methods, r.Method)
+ m.mu.Unlock()
+ }
+ return 0, nil
+ })
+ return m
+}
+
+func (m *manifestRequests) count(method string) int {
+ m.mu.Lock()
+ defer m.mu.Unlock()
+ n := 0
+ for _, k := range m.methods {
+ if k == method {
+ n++
+ }
+ }
+ return n
+}
+
+// TestAccountManifestCheckedOncePerProcess: once the account manifest is
+// known to exist (read, or written by the backfill), later app tab views in
+// this process do not ask the bucket again.
+func TestAccountManifestCheckedOncePerProcess(t *testing.T) {
+ t.Run("existing manifest is read once", func(t *testing.T) {
+ fx, lat := newPerfFixture(t)
+ c := signInPaul(t, fx)
+ key := AccountManifestKey(fx.sqid)
+ if err := WriteAccountManifest(context.Background(), fx.rel, OpsAccountID, fx.sqid, "ops", time.Now()); err != nil {
+ t.Fatal(err)
+ }
+ reqs := recordKeyRequests(lat, key)
+ for range 2 {
+ if status, _, body := get(t, c, fx.u("/apps/kass/activity")); status != http.StatusOK {
+ t.Fatalf("activity = %d:\n%s", status, body)
+ }
+ }
+ if got := reqs.count(http.MethodGet); got != 1 {
+ t.Errorf("account.json read %d times across two views, want 1", got)
+ }
+ if got := reqs.count(http.MethodPut); got != 0 {
+ t.Errorf("account.json written %d times, want 0", got)
+ }
+ })
+ t.Run("backfilled manifest is not read again", func(t *testing.T) {
+ fx, lat := newPerfFixture(t)
+ c := signInPaul(t, fx)
+ key := AccountManifestKey(fx.sqid)
+ if err := fx.rel.Delete(context.Background(), key); err != nil {
+ t.Fatal(err)
+ }
+ reqs := recordKeyRequests(lat, key)
+ if status, _, body := get(t, c, fx.u("/apps/kass/activity")); status != http.StatusOK {
+ t.Fatalf("activity = %d:\n%s", status, body)
+ }
+ gets, puts := reqs.count(http.MethodGet), reqs.count(http.MethodPut)
+ if puts != 1 {
+ t.Errorf("first view wrote account.json %d times, want 1", puts)
+ }
+ if status, _, body := get(t, c, fx.u("/apps/kass/activity")); status != http.StatusOK {
+ t.Fatalf("activity = %d:\n%s", status, body)
+ }
+ if g, p := reqs.count(http.MethodGet), reqs.count(http.MethodPut); g != gets || p != puts {
+ t.Errorf("second view touched account.json (reads %d -> %d, writes %d -> %d), want nothing", gets, g, puts, p)
+ }
+ })
+}
diff --git a/internal/console/server.go b/internal/console/server.go
index f0b5e4670..925889c4f 100644
--- a/internal/console/server.go
+++ b/internal/console/server.go
@@ -890,6 +890,12 @@ type Config struct {
// Server is the console's http.Handler.
type Server struct {
+ // manifestSeen is the sqids whose accounts/<sqid>/account.json this
+ // process has seen exist (read, or written by the backfill), so an app
+ // tab stops asking the bucket for it on every view. Keyed by sqid, value
+ // struct{}; handleDeleteAccount forgets the sqid it retires.
+ manifestSeen sync.Map
+
// billing is nil when billing is off (Config.Billing, plans 6a).
billing *billingRuntime
@@ -4385,9 +4391,13 @@ func (s *Server) ensureAccountManifest(ctx context.Context, acct *Account) {
if s.cfg.Releases == nil {
return
}
+ if _, ok := s.manifestSeen.Load(acct.Sqid); ok {
+ return // seen in this process — nothing to check or backfill
+ }
key := AccountManifestKey(acct.Sqid)
_, _, err := s.cfg.Releases.Get(ctx, key)
if err == nil {
+ s.manifestSeen.Store(acct.Sqid, struct{}{})
return // already there — nothing to backfill
}
if !errors.Is(err, os.ErrNotExist) {
@@ -4398,6 +4408,7 @@ func (s *Server) ensureAccountManifest(ctx context.Context, acct *Account) {
log.Printf("console: backfill account manifest %s: %v", key, err)
return
}
+ s.manifestSeen.Store(acct.Sqid, struct{}{})
log.Printf("console: backfilled account manifest for %s (%s)", acct.Sqid, acct.Name)
}
diff --git a/internal/console/testdata/perf-budgets.txt b/internal/console/testdata/perf-budgets.txt
index f7be87057..44dba5ea2 100644
--- a/internal/console/testdata/perf-budgets.txt
+++ b/internal/console/testdata/perf-budgets.txt
@@ -33,21 +33,22 @@ GET /a/{sqid}/apps/{app}/logs/data deferred: deferred part (the Logs tab's data
# Known slow today (measured 2026-10-26, with 25 ms per S3 request and 40 ms
# per app-host call). Plan 2 deletes these. "the app-tab frame" is what every
-# app tab reads before its own part: the account manifest, the production
-# flag, the pipeline, and a listing plus one read per channel (7 S3 calls).
+# app tab reads before its own part: the production
+# flag, the pipeline, and a listing plus one read per channel (6 S3 calls; the account
+# manifest is read once per process and then remembered).
/fleet/architecture over: reads economics/active.json, infra/inventory.json and status/fleet.json, and lists and reads every box report (8 S3 calls warm)
-GET /a/{sqid}/apps/{app} over: Overview is the app-tab frame plus a second pipeline read, the release listing, every manifest and every box report (16 S3 calls warm); cold, also every box's metrics hours for two days (about 110)
-GET /a/{sqid}/apps/{app}/account-review over: the app-tab frame (7 S3 calls warm)
-GET /a/{sqid}/apps/{app}/activity over: the app-tab frame (7 S3 calls warm)
-GET /a/{sqid}/apps/{app}/analytics over: the app-tab frame plus both telemetry settings and the analytics day listing and reads (11 S3 calls warm)
-GET /a/{sqid}/apps/{app}/availability over: the app-tab frame plus both telemetry settings and three listings and a read each for the log and error chunks (17 S3 calls warm)
-GET /a/{sqid}/apps/{app}/errors over: the app-tab frame plus both telemetry settings and three listings and a read each for the log and error chunks (17 S3 calls warm)
-GET /a/{sqid}/apps/{app}/instances over: the app-tab frame plus instances.json, and every edges file and box report listed and read twice (24 S3 calls warm)
-GET /a/{sqid}/apps/{app}/instances/{host} over: the app-tab frame plus the instance record, and the box reports and the fleet box reports listed and read three times (31 S3 calls warm)
-GET /a/{sqid}/apps/{app}/logs over: the app-tab frame plus a listing and a read of every instance record and three listings for the log chunks (15 S3 calls warm)
-GET /a/{sqid}/apps/{app}/releases over: the app-tab frame plus a second pipeline read for the pending card, the release and tag listings, at most 20 manifests, retention and instances.json (14 S3 calls warm; 12 on the fixture's empty page 2)
-GET /a/{sqid}/apps/{app}/settings over: General builds the whole settings record: each environment and its store read twice, every instance record, the domain claims, cert-warm records, every box report and a listing of every key under the app, plus the swap policy (32 S3 calls warm)
-GET /a/{sqid}/apps/{app}/settings/{section} over: Domains, Environments, Storage, Email and Feature flags build the whole settings record, as General does (31 S3 calls warm; General 32); Errors and analytics 9, the pipeline section 8, Placement and Delete 7 (the app-tab frame); the advanced redirect none
+GET /a/{sqid}/apps/{app} over: Overview is the app-tab frame plus a second pipeline read, the release listing, every manifest and every box report (10 S3 calls warm); cold, also every box's metrics hours for two days (about 110)
+GET /a/{sqid}/apps/{app}/account-review over: the app-tab frame (6 S3 calls warm)
+GET /a/{sqid}/apps/{app}/activity over: the app-tab frame (6 S3 calls warm)
+GET /a/{sqid}/apps/{app}/analytics over: the app-tab frame plus both telemetry settings and the analytics day listing and reads (10 S3 calls warm)
+GET /a/{sqid}/apps/{app}/availability over: the app-tab frame plus both telemetry settings and three listings and a read each for the log and error chunks (16 S3 calls warm)
+GET /a/{sqid}/apps/{app}/errors over: the app-tab frame plus both telemetry settings and three listings and a read each for the log and error chunks (16 S3 calls warm)
+GET /a/{sqid}/apps/{app}/instances over: the app-tab frame plus instances.json, and every edges file and box report listed and read twice (23 S3 calls warm)
+GET /a/{sqid}/apps/{app}/instances/{host} over: the app-tab frame plus the instance record, and the box reports and the fleet box reports listed and read three times (30 S3 calls warm)
+GET /a/{sqid}/apps/{app}/logs over: the app-tab frame plus a listing and a read of every instance record and three listings for the log chunks (14 S3 calls warm)
+GET /a/{sqid}/apps/{app}/releases over: the app-tab frame plus a second pipeline read for the pending card, the release and tag listings, at most 20 manifests, retention and instances.json (13 S3 calls warm; 11 on the fixture's empty page 2)
+GET /a/{sqid}/apps/{app}/settings over: General builds the whole settings record: each environment and its store read twice, every instance record, the domain claims, cert-warm records, every box report and a listing of every key under the app, plus the swap policy (31 S3 calls warm)
+GET /a/{sqid}/apps/{app}/settings/{section} over: Domains, Environments, Storage, Email and Feature flags build the whole settings record, as General does (30 S3 calls warm; General 31); Errors and analytics 8, the pipeline section 7, Placement and Delete 6 (the app-tab frame); the advanced redirect none
GET /a/{sqid}/fleet over: reads status/fleet.json and lists and reads each customer fleet's box reports (3 S3 calls warm)
GET /a/{sqid}/fleets/{fleet} over: lists and reads the fleet's box reports (2 S3 calls warm)
GET /a/{sqid}/plan/keep over: the lapse inventory lists every app's instance records and reads each one, lists every app's sidecar records, and lists the domain claims (8 S3 calls warm for two apps and three instances, median 209 ms; it grows with the account)