carlos / platform Public

assets: the home withholds a throttled or lapsed host's block; a fill hop passes the throttle (asset cache plan 3 final F2/F3)

Far edges hold no plan state of their own (controller ruling: no new
per-account state, no new S3 reads). assetPolicy.decide now publishes
and catches nothing for a host while its account has a plan throttle in
force or a lapse turned off the host or the primary it resolves to,
from the plans snapshot the home already holds (planThrottleFor,
planDisabledFor). Far edges then forward ordinary hops and the home
enforces.

In the window before the next writer pass, a verified fill hop at the
home now passes planThrottleAdmit before the store or the app answers
it; its 429 is unacknowledged and metered at the home as a hop. The
disabled page already came first (planDisabledAdmit in ServeHTTP);
TestHomeFillMeetsTheLapse pins that order for the primary and an alias.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev f6d3333af112136c93dcde29e4db68b242596f55 parent 11601fa
4 files changed, +235 −0
  • internal/edge/asset_local_test.go +125 −0
  • internal/edge/assetcatch.go +12 −0
  • internal/host/assetpolicy.go +9 −0
  • internal/host/plans_disabled_test.go +89 −0
diff --git a/internal/edge/asset_local_test.go b/internal/edge/asset_local_test.go
index fc3c24c57..e55840047 100644
--- a/internal/edge/asset_local_test.go
+++ b/internal/edge/asset_local_test.go
@@ -23,6 +23,7 @@ import (
"github.com/carlosframework/platform/internal/plans"
"github.com/carlosframework/platform/internal/ratelimit"
"github.com/carlosframework/platform/internal/registry"
+ "github.com/carlosframework/platform/internal/release"
)
// The local catch and fill, and the home side of a far fill (edge asset cache
@@ -1161,3 +1162,127 @@ func TestAppSetAssetTrailersAreStripped(t *testing.T) {
}
}
}
+
+// ---- plans on the home's fill path (final review F2, F3) -----------------
+
+// serveFill serves one far fill of path on host, signed for c.
+func (s *laScene) serveFill(key []byte, host, path string, c assetFillClaims) (*httptest.ResponseRecorder, string) {
+ req, assertion := fillRequest(key, host, path, c)
+ rec := httptest.NewRecorder()
+ s.e.ServeHTTP(rec, req)
+ return rec, assertion
+}
+
+// A verified fill hop reaching the home meets the account throttle as an
+// ordinary request does, before the home's store answers it: in the window
+// before the home's next writer pass withholds the host's block, which the
+// policy here still holds. The refusal is the home's ordinary 429: no
+// acknowledgement, metered here as a hop with its plan-throttle count, so the
+// far edge passes it on unstored and unbilled. The hook answers as the home's
+// plans snapshot does for an account it serves (internal/host's
+// planThrottleFor: the route's account, an instance route). Not acceptance.
+func TestHomeFillMeetsThePlanThrottle(t *testing.T) {
+ s := newLAScene(t, assetOK(laBody))
+ key := s.armMesh(t)
+ frozen := time.Date(2026, 10, 25, 12, 0, 0, 0, time.UTC)
+ s.e.planLimiter = ratelimit.NewLimiter(func() time.Time { return frozen }, 1000)
+ var on atomic.Bool
+ s.e.SetPlanThrottleFor(func(rt registry.Route) (plans.Throttle, bool) {
+ if !on.Load() || release.RouteAccount(rt) != "abc" || rt.Kind != "instance" {
+ return plans.Throttle{}, false
+ }
+ return plans.Throttle{Bandwidth: true, Until: frozen.Add(time.Hour)}, true
+ })
+ m := NewUsageMeter()
+ s.e.EnableUsage(m)
+ s.homeFill(t, key, "/assets/app.js")
+ m.Drain()
+
+ on.Store(true)
+ refused := 0
+ for i := 0; i <= plans.ThrottleRule.Burst; i++ {
+ rec, assertion := s.serveFill(key, laHost, "/assets/app.js", laClaims("/assets/app.js"))
+ if rec.Code == http.StatusTooManyRequests {
+ refused++
+ for _, h := range []string{assetAckHeader, assetExpiresHeader, assetCacheHeader} {
+ if v := rec.Header().Get(h); v != "" {
+ t.Fatalf("the throttle's 429 carried %s %q", h, v)
+ }
+ }
+ continue
+ }
+ wantCache(t, rec, "hit")
+ exp, err := strconv.ParseInt(rec.Header().Get(assetExpiresHeader), 10, 64)
+ if err != nil || !verifyAssetAck(key, assertion, exp, rec.Header().Get(assetAckHeader)) {
+ t.Fatalf("an admitted fill hit is not acknowledged: %v", rec.Header())
+ }
+ }
+ if refused != 1 {
+ t.Fatalf("%d fill hops refused past the throttle's burst, want 1", refused)
+ }
+ if row := m.Drain()[laHost]; row.PlanThrottled != 1 || row.Requests != 1 || row.HopRequests != 1 {
+ t.Fatalf("row = %+v, want the one refusal metered as a hop with its plan-throttle count", row)
+ }
+ if n := s.b.n.Load(); n != 1 {
+ t.Fatalf("the app saw %d requests, want 1", n)
+ }
+}
+
+// A fill hop for a host a lapse turned off, the primary or an alias of it,
+// gets the disabled page and no acknowledgement, even with the home's entry
+// warm and the policy still catching (the window before the next writer
+// pass). The hook answers as internal/host's planDisabledFor does: the
+// route's account, the route's own host or the request host. Not acceptance.
+func TestHomeFillMeetsTheLapse(t *testing.T) {
+ const alias = "www.example.com"
+ for _, tc := range []struct {
+ off string
+ primary, aliased bool // whether a fill for each is refused
+ }{
+ {off: laHost, primary: true, aliased: true},
+ {off: alias, aliased: true},
+ } {
+ t.Run(tc.off, func(t *testing.T) {
+ s := newLAScene(t, assetOK(laBody))
+ if err := s.reg.UpsertAlias(registry.RouteAlias{Alias: alias, Host: laHost, Account: "abc", App: "shop"}); err != nil {
+ t.Fatal(err)
+ }
+ if err := s.e.Reload(); err != nil {
+ t.Fatal(err)
+ }
+ s.local.set(alias, laAssets())
+ key := s.armMesh(t)
+ s.homeFill(t, key, "/assets/app.js")
+ var off atomic.Value
+ off.Store("")
+ s.e.SetPlanDisabledFor(func(rt registry.Route, host string) bool {
+ d := off.Load().(string)
+ return d != "" && release.RouteAccount(rt) == "abc" && (rt.Host == d || host == d)
+ })
+ off.Store(tc.off)
+ for host, refused := range map[string]bool{laHost: tc.primary, alias: tc.aliased} {
+ c := laClaims("/assets/app.js")
+ c.Host = host
+ rec, _ := s.serveFill(key, host, "/assets/app.js", c)
+ if !refused {
+ wantCache(t, rec, "hit")
+ if rec.Header().Get(assetAckHeader) == "" {
+ t.Fatalf("a fill for %s, still on, was not acknowledged", host)
+ }
+ continue
+ }
+ if rec.Code != http.StatusServiceUnavailable || !bytes.Equal(rec.Body.Bytes(), disabledPage) {
+ t.Fatalf("a fill for %s = %d %q, want the disabled page", host, rec.Code, rec.Body.String())
+ }
+ for _, h := range []string{assetAckHeader, assetExpiresHeader, assetCacheHeader} {
+ if v := rec.Header().Get(h); v != "" {
+ t.Fatalf("the disabled page for %s carried %s %q", host, h, v)
+ }
+ }
+ }
+ if n := s.b.n.Load(); n != 1 {
+ t.Fatalf("the app saw %d requests, want 1", n)
+ }
+ })
+ }
+}
diff --git a/internal/edge/assetcatch.go b/internal/edge/assetcatch.go
index 434199cb1..bed6f12f6 100644
--- a/internal/edge/assetcatch.go
+++ b/internal/edge/assetcatch.go
@@ -325,6 +325,9 @@ func (e *Edge) serveAssetLocal(w http.ResponseWriter, r *http.Request, host stri
// request is marked unbilled: the far edge meters what it delivers. Only
// billing is skipped (drift D9); the other observers see the response.
//
+// A fill that verifies first passes the account throttle; its 429 is an
+// ordinary, unacknowledged and metered answer.
+//
// A far fill is a plain GET (Task 6 sends nothing else); any other shape is
// an ordinary hop.
func (e *Edge) serveAssetFillForHop(w http.ResponseWriter, r *http.Request, host string, up upstream) bool {
@@ -347,6 +350,15 @@ func (e *Edge) serveAssetFillForHop(w http.ResponseWriter, r *http.Request, host
if !ok {
return false
}
+ // The account throttle, which the ordinary path would apply to this hop
+ // (plans 4c), before anything is answered from the store or the app: a
+ // refusal is this home's ordinary answer, unacknowledged and metered here
+ // as a hop, as for an uncaught request (final review F2). A lapse's
+ // disabled page came earlier, in ServeHTTP (planDisabledAdmit, before the
+ // meter), which never let a turned-off host's fill reach this hook.
+ if !e.planThrottleAdmit(w, r, up) {
+ return true
+ }
markUnbilled(r)
ack := func(h http.Header, expires int64) {
h.Del(assetAckHeader)
diff --git a/internal/host/assetpolicy.go b/internal/host/assetpolicy.go
index e9bf05460..5ae832c93 100644
--- a/internal/host/assetpolicy.go
+++ b/internal/host/assetpolicy.go
@@ -279,6 +279,15 @@ func (p *assetPolicy) decide(ctx context.Context, in assetInputs, clocks assetCl
if r.AssetsOff || r.AssetGen == "" || r.Gate != "" || r.ImportGate != "" {
return edge.HostAssets{}, false
}
+ // A plan throttle in force on the row's account, or a lapse that turned
+ // off the hostname or the primary it resolves to (plans 4c, 4d), as the
+ // plans snapshot this box already holds says (plansPass; no read of its
+ // own). Nothing is published or caught for it, so a far edge forwards an
+ // ordinary hop and this box throttles it or answers the disabled page
+ // (final review F2, F3).
+ if _, throttled := planThrottleFor(r); throttled || planDisabledFor(r, host) {
+ return edge.HostAssets{}, false
+ }
// Any path-prefix row at all, on the name or on the primary it is served
// with: one hostname-wide declaration cannot describe what different
// targets serve.
diff --git a/internal/host/plans_disabled_test.go b/internal/host/plans_disabled_test.go
index 445ad4c3a..42abdf130 100644
--- a/internal/host/plans_disabled_test.go
+++ b/internal/host/plans_disabled_test.go
@@ -4,10 +4,13 @@ package host
import (
"context"
+ "slices"
"testing"
+ "time"
"github.com/carlosframework/platform/internal/plans"
"github.com/carlosframework/platform/internal/registry"
+ "github.com/carlosframework/platform/internal/release"
)
// putDisabledLimits writes sqid's record listing turned-off hosts.
@@ -99,3 +102,89 @@ func TestDisabledOffWithPlanLimitsOff(t *testing.T) {
t.Fatal("disabled without the marker")
}
}
+
+// Final review F2, F3 (controller ruling): far edges hold no plan state of
+// their own, so the home publishes no assets block for a host while the
+// host's account has a plan throttle in force, or while a lapse has turned
+// off the host or the primary it is served with; far edges then forward
+// ordinary hops and the home throttles them or answers the disabled page.
+// The home's own catch (For) answers false for it too.
+//
+// Production wiring: the real plansPass over the account's limits record in a
+// bucket fills the snapshot, and the real policy, the real writer pass
+// (edgesFileWriteClaims) and the production reader (internal/edgesfile) do
+// the rest. No hook is faked. When the record lifts, the next pass publishes
+// again.
+//
+// Serial: writes the package-level plans cache.
+func TestAssetBlocksWithheldWhileThrottledOrLapsed(t *testing.T) {
+ const (
+ primary = "shop.example.com"
+ alias = "www.shop.example.com"
+ other = "blog.example.com"
+ )
+ all := []string{primary, alias, other}
+ for _, tc := range []struct {
+ name string
+ record func(t *testing.T, s *plansCountingStore)
+ withheld []string
+ }{
+ {"throttled account", func(t *testing.T, s *plansCountingStore) {
+ putThrottledLimits(t, s, "abc", &plans.Throttle{Bandwidth: true, Until: time.Now().Add(24 * time.Hour)})
+ }, []string{primary, alias, other}},
+ {"lapsed primary", func(t *testing.T, s *plansCountingStore) {
+ putDisabledLimits(t, s, "abc", primary)
+ }, []string{primary, alias}},
+ {"lapsed alias", func(t *testing.T, s *plansCountingStore) {
+ putDisabledLimits(t, s, "abc", alias)
+ }, []string{alias}},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ t.Cleanup(func() { planLimits.Store(nil) })
+ ctx := context.Background()
+ w := newAssetWorld(t)
+ w.ship("v1", "/assets/")
+ w.instance(primary, assetGen1, "v1")
+ w.instance(other, assetGen1, "v1")
+ if err := w.reg.UpsertAlias(registry.RouteAlias{Alias: alias, Host: primary, Account: "abc", App: "shop"}); err != nil {
+ t.Fatal(err)
+ }
+ if err := w.reg.SetAliasDNSStatus(alias, "pointing", assetT0.Unix()); err != nil {
+ t.Fatal(err)
+ }
+ w.confirm()
+ ps := &plansCountingStore{Store: release.NewDirStore(t.TempDir()), fail: map[string]bool{}}
+ putMarker(t, ps, true)
+ putDisabledLimits(t, ps, "abc") // plans on, the account read, nothing in force
+ plansPass(ctx, ps, w.reg, plansNoEnv)
+ hosts := w.hosts()
+ for _, h := range all {
+ wantAssets(t, hosts, h, []string{"/assets/"}, assetGen1, assetT0)
+ }
+
+ tc.record(t, ps)
+ plansPass(ctx, ps, w.reg, plansNoEnv)
+ hosts = w.hosts()
+ for _, h := range all {
+ if slices.Contains(tc.withheld, h) {
+ wantNoAssets(t, hosts, h)
+ if a, ok := w.policy.For(h); ok {
+ t.Fatalf("the home's own catch still answers %s: %+v", h, a)
+ }
+ continue
+ }
+ wantAssets(t, hosts, h, []string{"/assets/"}, assetGen1, assetT0)
+ if _, ok := w.policy.For(h); !ok {
+ t.Fatalf("the home's own catch dropped %s", h)
+ }
+ }
+
+ putDisabledLimits(t, ps, "abc") // the record lifts: no throttle, nothing turned off
+ plansPass(ctx, ps, w.reg, plansNoEnv)
+ hosts = w.hosts()
+ for _, h := range all {
+ wantAssets(t, hosts, h, []string{"/assets/"}, assetGen1, assetT0)
+ }
+ })
+ }
+}