carlos / platform Public

console: account-wide frame clears match the account name as well as the sqid

A write addressed by account name (POST /api/cli/apps/<name>/new, POST
/a/<name>/apps/new) passed the raw name to clearAccount, but frame slots are
keyed by sqid, so the clear and its generation bump missed. Each slot now
records the account name its last view used, and clearAccount matches the
raw segment against the sqid or that name (no lookup; an unknown segment
allocates nothing). Regression test holds the create's pipeline write while
a view caches the incomplete frame, for both the CLI and browser doors.
Census overlay re-pinned for the internal/console envelope.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev ca50187dbd6c0c533b3b52a5946ffc6ec20a4321 parent 53d5b09
5 files changed, +170 −13
  • internal/console/appframe.go +36 −9
  • internal/console/appframe_test.go +124 −0
  • internal/console/remoteinstances.go +7 −1
  • internal/console/server.go +2 −2
  • internal/provision/testdata/plan14-root-reads-console-perf-quick-wins.tsv +1 −1

CI failed — run details

diff --git a/internal/console/appframe.go b/internal/console/appframe.go
index 22ee8821b..48ae009f4 100644
--- a/internal/console/appframe.go
+++ b/internal/console/appframe.go
@@ -22,7 +22,10 @@ import (
// sits under an {app} route, and registerRoute clears that app's entry
// before the door's response goes out (frameClearingWriter), so the page a
// write redirects to always loads fresh. A door with only {sqid} (or
-// {account}) clears the whole account: the new-app and trash doors. Rename
+// {account}) clears the whole account: the new-app and trash doors. That
+// segment may be the account's NAME as well as its sqid (the browser and
+// the CLI both resolve either), so a slot also remembers the account name
+// its last view used and a clear matches the segment against both. Rename
// clears the new name itself. A writer outside the console (another
// console, a box, an operator's script) is seen within appFrameTTL.
//
@@ -143,8 +146,12 @@ type frameKey struct{ acct, app string }
// frameSlot is one (account, app)'s place in the cache: the stored frame,
// if any, and the generation every clear of it bumps. A slot exists only
-// while it holds a frame or a load for it is in flight.
+// while it holds a frame or a load for it is in flight. name is the
+// account's name as the last view of the slot knew it ("" when that view
+// did not say), so an account-wide clear addressed by name finds the slot
+// without a lookup.
type frameSlot struct {
+ name string
frame appFrame
at time.Time
has bool
@@ -188,10 +195,19 @@ func (c *appFrames) lifetime() time.Duration {
// load, storing the result only when it has no error and no clear of this
// app happened while it loaded. Either way the caller gets its own copy.
func (c *appFrames) get(ctx context.Context, acct, app string, load func(context.Context) appFrame) appFrame {
+ return c.getAs(ctx, acct, "", app, load)
+}
+
+// getAs is get for a caller that knows the account's name: the slot keeps
+// it for clearAccount (see frameSlot).
+func (c *appFrames) getAs(ctx context.Context, acct, name, app string, load func(context.Context) appFrame) appFrame {
k := frameKey{acct, app}
c.mu.Lock()
now := c.clock()
sl := c.slots[k]
+ if sl != nil && name != "" {
+ sl.name = name
+ }
if sl != nil && sl.has && now.Before(sl.at.Add(c.lifetime())) {
f := sl.frame.clone()
c.mu.Unlock()
@@ -201,7 +217,7 @@ func (c *appFrames) get(ctx context.Context, acct, app string, load func(context
if c.slots == nil {
c.slots = make(map[frameKey]*frameSlot)
}
- sl = &frameSlot{}
+ sl = &frameSlot{name: name}
c.slots[k] = sl
}
sl.loading++
@@ -234,10 +250,15 @@ func (c *appFrames) dropIfIdle(k frameKey, sl *frameSlot) {
// clearWhere drops the frame of every slot match picks and bumps its
// generation, so a load in flight for it will not store.
func (c *appFrames) clearWhere(match func(frameKey) bool) {
+ c.clearSlots(func(k frameKey, _ *frameSlot) bool { return match(k) })
+}
+
+// clearSlots is clearWhere for a match that also reads the slot.
+func (c *appFrames) clearSlots(match func(frameKey, *frameSlot) bool) {
c.mu.Lock()
defer c.mu.Unlock()
for k, sl := range c.slots {
- if !match(k) {
+ if !match(k, sl) {
continue
}
sl.gen++
@@ -252,9 +273,14 @@ func (c *appFrames) clearApp(app string) {
c.clearWhere(func(k frameKey) bool { return k.app == app })
}
-// clearAccount drops every frame of the account.
-func (c *appFrames) clearAccount(sqid string) {
- c.clearWhere(func(k frameKey) bool { return k.acct == sqid })
+// clearAccount drops every frame of the account that seg names: seg is a
+// request's raw path segment, so it matches a slot's account sqid or its
+// account name (compared as matchAccounts does, ignoring case). It looks
+// nothing up: a segment no slot knows clears, and allocates, nothing.
+func (c *appFrames) clearAccount(seg string) {
+ c.clearSlots(func(k frameKey, sl *frameSlot) bool {
+ return k.acct == seg || (sl.name != "" && strings.EqualFold(sl.name, seg))
+ })
}
// frameBypassKey marks a non-GET request's context: appFrame loads fresh
@@ -263,14 +289,15 @@ type frameBypassKey struct{}
// appFrame is the frame for a page view: the cache over the console's
// release store, or a fresh load for a write door's request.
-func (s *Server) appFrame(ctx context.Context, acct, app string) appFrame {
+// acctName is the account's name when the caller has it (see frameSlot).
+func (s *Server) appFrame(ctx context.Context, acct, acctName, app string) appFrame {
load := func(ctx context.Context) appFrame {
return loadAppFrame(ctx, s.cfg.Releases, s.cfg.ReleasePub, acct, app)
}
if ctx.Value(frameBypassKey{}) != nil {
return load(ctx)
}
- return s.frames.get(ctx, acct, app, load)
+ return s.frames.getAs(ctx, acct, acctName, app, load)
}
// frameClear is the clear registerRoute runs for a write request: the app
diff --git a/internal/console/appframe_test.go b/internal/console/appframe_test.go
index 35bd2ba43..96bce6268 100644
--- a/internal/console/appframe_test.go
+++ b/internal/console/appframe_test.go
@@ -789,3 +789,127 @@ func TestAppFrameRenameClearsNewName(t *testing.T) {
}
}
}
+
+// TestAppFrameNamedAccountWriteClears: an account-wide write door addressed
+// by the account's NAME (the browser and the CLI both accept it) clears the
+// account's frames and bumps their generations just as the sqid does. The
+// create is held after inserting the app's row and before writing its
+// default pipeline; a view in that gap caches a frame with no pipeline, and the
+// first view after the create must show the pipeline.
+func TestAppFrameNamedAccountWriteClears(t *testing.T) {
+ for _, tc := range []struct {
+ name string
+ create func(t *testing.T, fx *consoleFixture, c *http.Client, token, acctName, app string) int
+ }{
+ {"CLI POST /api/cli/apps/{account}/new", func(t *testing.T, fx *consoleFixture, c *http.Client, token, acctName, app string) int {
+ status, out := postJSON(t, fx.ts.URL+"/api/cli/apps/"+acctName+"/new", map[string]string{"name": app}, token)
+ if status != http.StatusCreated && status != http.StatusOK {
+ t.Errorf("CLI create = %d %v", status, out)
+ }
+ return status
+ }},
+ {"browser POST /a/{sqid}/apps/new", func(t *testing.T, fx *consoleFixture, c *http.Client, token, acctName, app string) int {
+ status, loc, body := postForm(t, c, fx.ts.URL+"/a/"+acctName+"/apps/new",
+ url.Values{"csrf": {sessionToken(t, fx, c)}, "name": {app}})
+ if status != http.StatusSeeOther || strings.Contains(loc, "/apps/new") {
+ t.Errorf("browser create = %d -> %q:\n%s", status, loc, body)
+ }
+ return status
+ }},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ fx, lat := newPerfFixture(t)
+ // The seeded plan allows no fourth app; the cap is not under test.
+ fx.srv.cfg.PlanCatalog = nil
+ token := cliToken(t, fx, "paul@keymail.dev", "code-frame-named")
+ c := signInPaul(t, fx)
+ accts, err := fx.st.AccountsFor("paul@keymail.dev")
+ if err != nil {
+ t.Fatal(err)
+ }
+ var acctName string
+ for _, a := range accts {
+ if a.Sqid == fx.sqid {
+ acctName = a.Name
+ }
+ }
+ if acctName == "" || acctName == fx.sqid {
+ t.Fatalf("the fixture account has no name distinct from its sqid: %q", acctName)
+ }
+ const app = "sprout"
+ pipeKey := release.PipelineKey(fx.sqid, app)
+ var mu sync.Mutex
+ armed := true
+ reached := make(chan struct{})
+ hold, releaseHold := releaseOnce()
+ defer releaseHold()
+ lat.Fake().OnRequest(func(r *http.Request) (int, <-chan struct{}) {
+ mu.Lock()
+ defer mu.Unlock()
+ // The fake runs a held request's operation and holds only its
+ // response, so hold the create's first look at the pipeline
+ // key (SetPipeline reads it before it writes): the write is
+ // still to come.
+ if armed && strings.HasSuffix(r.URL.Path, pipeKey) {
+ armed = false
+ close(reached)
+ return 0, hold
+ }
+ return 0, nil
+ })
+ created := make(chan int, 1)
+ go func() { created <- tc.create(t, fx, c, token, acctName, app) }()
+ frameWait(t, reached, "the create's first read of the pipeline key")
+ // The row exists and the pipeline does not: this view caches
+ // the incomplete frame.
+ if status, _, body := get(t, c, fx.u("/")); status != http.StatusOK || !strings.Contains(body, app) {
+ t.Fatalf("account home during the create = %d, want 200 listing %s:\n%s", status, app, body)
+ }
+ if !fx.srv.frames.cached(fx.sqid, app) {
+ t.Fatal("the view during the create did not cache a frame; the test is not exercising the race")
+ }
+ if f := fx.srv.appFrame(context.Background(), fx.sqid, acctName, app); f.Pipeline != nil {
+ t.Fatalf("the frame cached during the create already has a pipeline: %+v", f.Pipeline)
+ }
+ releaseHold()
+ frameWait(t, created, "the create's response")
+ if fx.srv.frames.cached(fx.sqid, app) {
+ t.Error("the incomplete frame survived the create's response")
+ }
+ if status, _, body := get(t, c, fx.u("/apps/"+app)); status != http.StatusOK {
+ t.Fatalf("app page after the create = %d:\n%s", status, body)
+ }
+ if f := fx.srv.appFrame(context.Background(), fx.sqid, acctName, app); f.Pipeline == nil {
+ t.Fatal("the first view after the create has no pipeline: the name-addressed write missed the account-wide clear")
+ }
+ })
+ }
+}
+
+// TestAppFrameClearAccountByName: clearAccount matches a slot's account
+// sqid or the account name its last view gave, ignoring case, and a name no
+// slot knows allocates nothing.
+func TestAppFrameClearAccountByName(t *testing.T) {
+ var c appFrames
+ ctx := context.Background()
+ load := func(context.Context) appFrame { return testFrame("v1") }
+ c.getAs(ctx, "bab", "Ops", "kass", load)
+ c.getAs(ctx, "bab", "Ops", "shop", load)
+ c.getAs(ctx, "other", "elsewhere", "kass", load)
+ c.get(ctx, "unnamed", "kass", load)
+ c.clearAccount("ops")
+ if c.cached("bab", "kass") || c.cached("bab", "shop") {
+ t.Error("clearAccount(name) left the named account's frames")
+ }
+ if !c.cached("other", "kass") || !c.cached("unnamed", "kass") {
+ t.Error("clearAccount(name) cleared another account")
+ }
+ c.clearAccount("unnamed")
+ if c.cached("unnamed", "kass") {
+ t.Error("clearAccount(sqid) left a frame whose view gave no name")
+ }
+ c.clearAccount("nobody")
+ if n := len(c.slots); n != 1 {
+ t.Errorf("%d slots after clearing an unknown name, want the 1 that was cached", n)
+ }
+}
diff --git a/internal/console/remoteinstances.go b/internal/console/remoteinstances.go
index 30f3a3ada..b358e5f3d 100644
--- a/internal/console/remoteinstances.go
+++ b/internal/console/remoteinstances.go
@@ -539,8 +539,14 @@ func (s *Server) remoteSource(ctx context.Context, acct string) *remoteRows {
// plus the account's instances on other boxes, each app's release-store
// reads from the frame cache (appframe.go).
func (s *Server) assembleApps(ctx context.Context, acct string, apps []string) ([]AppView, error) {
+ return s.assembleAppsNamed(ctx, acct, "", apps)
+}
+
+// assembleAppsNamed is assembleApps for a caller that knows the account's
+// name, which the frame cache keeps so a write addressed by name clears it.
+func (s *Server) assembleAppsNamed(ctx context.Context, acct, acctName string, apps []string) ([]AppView, error) {
return assembleViews(ctx, s.cfg.Registry, acct, apps, s.dnsTargets(ctx), s.remoteSource(ctx, acct), func(app string) appFrame {
- return s.appFrame(ctx, acct, app)
+ return s.appFrame(ctx, acct, acctName, app)
})
}
diff --git a/internal/console/server.go b/internal/console/server.go
index 000c1b39a..858a937cd 100644
--- a/internal/console/server.go
+++ b/internal/console/server.go
@@ -3553,7 +3553,7 @@ func (s *Server) handleAccountHome(w http.ResponseWriter, r *http.Request) {
return
}
if len(apps) > 0 {
- views, err := s.assembleApps(r.Context(), acct.Sqid, apps)
+ views, err := s.assembleAppsNamed(r.Context(), acct.Sqid, acct.Name, apps)
if err != nil {
log.Printf("console: assemble: %v", err)
s.renderMessage(w, r, http.StatusInternalServerError, "Error", "Could not read platform state. Please try again.")
@@ -3726,7 +3726,7 @@ func (s *Server) appPage(w http.ResponseWriter, r *http.Request, tab string) (pa
// bucket hiccup there is deliberately non-fatal, and this is where it gets
// another chance. Best-effort — a page view never fails on it.
s.ensureAccountManifest(r.Context(), acct)
- views, err := s.assembleApps(r.Context(), acct.Sqid, []string{app})
+ views, err := s.assembleAppsNamed(r.Context(), acct.Sqid, acct.Name, []string{app})
if err != nil || len(views) != 1 {
log.Printf("console: assemble %s: %v", app, err)
s.renderMessage(w, r, http.StatusInternalServerError, "Error", "Could not read platform state. Please try again.")
diff --git a/internal/provision/testdata/plan14-root-reads-console-perf-quick-wins.tsv b/internal/provision/testdata/plan14-root-reads-console-perf-quick-wins.tsv
index 67b1aed4c..9aecccd43 100644
--- a/internal/provision/testdata/plan14-root-reads-console-perf-quick-wins.tsv
+++ b/internal/provision/testdata/plan14-root-reads-console-perf-quick-wins.tsv
@@ -8,4 +8,4 @@ internal/console/apiinstances.go Server.loadRolloutJoin legacy accepted-legacy a
internal/console/apisystemupdate.go Server.systemBoxes legacy accepted-legacy accepted-legacy;rev3=J1;basis=root-route;rev3=census-ruling-instance-egress-sizes-328-329;basis=#329 plan 3 Task 9: the fleet lookup (openPassRegistry on the configured registry, then ListFleets) moves unchanged into the new unit Server.systemFleets, which systemBoxes now calls; no registry and no registry file still mean no fleets, any other error still goes to systemFleetsUnreadable. The same three registry:Name sites and one whole:Fleet site, offsets moved; no read added.;rev3=census-ruling-console-perf-quick-wins;basis=same reads, fewer calls: the platform and each fleet's box reports come through Server.loadBoxes (read once per request) instead of status.LoadBoxes; the same four read sites, no read added registry:Name@408,registry:Name@580,registry:Name@655,whole:Fleet@340 79e3c4f65df1679ea115402f00184db1d2d8e21a3fa4d10e17003e49626db6c6
internal/console/server.go Server.handleAppLogs legacy accepted-legacy accepted-legacy;rev3=census-ruling-self-serve-moves-1;basis=the console (cmd/console serve under console.service, user carlos-console): the log page's host listing is the listRecords wrapper, judged under a unit admitted on and unjudged before; read sites unchanged, offsets moved;rev3=census-ruling-console-ux-nav;basis=the log copy struct gains a Level label ("Level"); copy only; no root read added, read sites unchanged;rev3=census-ruling-console-perf-quick-wins;basis=same reads, fewer calls: the log page's host list takes the instance records from pageRecords (the page's own record read, held for the request) instead of a second listRecords; one read site, unchanged, no read added file:Query@141 ad6b01ce7077bbd2df0c3a06d492120b1f2b3cf54c7563d49301dbb425e1f7de
internal/console/apisystemgeoip.go Server.geoipInventory legacy accepted-legacy accepted-legacy;rev3=J1;basis=root-route;rev3=census-ruling-console-perf-quick-wins;basis=same reads, fewer calls: add takes the fleet name and builds the fleets/<name>/ prefix itself, reading through Server.loadBoxes; one fewer registry:Name site (the name is passed, not read twice), no read added registry:Label@1770,registry:Name@1602,registry:Name@1762,registry:Name@1813,registry:Status@1709,whole:Fleet@1560,whole:FleetBox@1697 4412ad7d72f9849376ddf74df77696de0e2a58e0640b9f1e3df7431b8059967e
-@coverage internal/console a1568e01dd925082c02ac3c2184d17541cf90dba2f5526c672620be31107d2e5
+@coverage internal/console 0b54a03dcd6a1bacc0c47df245b008a289fc18305ab5af56f0f0e88e2a0be516