carlos / platform Public

edge, host: HostAssets names the primary route it was decided for (asset cache plan 3 drift D4)

The home box's policy snapshot fills Primary (the host for a route's own
name, the target for an alias); the edges-file block publishes it as the
additive "primary" field and AssetsFor parses it. The golden host entry
and its writer test carry it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 25e459240d8294d3a3c68f9410fd2013c26c87d5 parent 982edfd
9 files changed, +49 −23
  • internal/edge/assettypes.go +9 −0
  • internal/edge/homemap.go +5 −3
  • internal/edge/homemap_assets_test.go +2 −2
  • internal/edgesfile/edgesfile.go +9 −6
  • internal/edgesfile/edgesfile_test.go +1 −1
  • internal/edgesfile/testdata/assets-host.golden.json +2 −1
  • internal/host/assetpolicy.go +10 −6
  • internal/host/assetpublish_test.go +10 −3
  • internal/host/edgesfile.go +1 −1
diff --git a/internal/edge/assettypes.go b/internal/edge/assettypes.go
index b14f327c2..c0076cd26 100644
--- a/internal/edge/assettypes.go
+++ b/internal/edge/assettypes.go
@@ -9,6 +9,14 @@ import "time"
// box knew every input of the catch decision for the host was complete and
// applied; a reader serves nothing for a host whose At is over an hour old.
//
+// Primary is the primary route hostname the decision was made for: the host
+// itself for a route's own name, the alias's target for an alias. The home
+// box compares it with the route its own route snapshot serves the request
+// with, so a policy snapshot and a route snapshot that disagree about which
+// route a name belongs to fill nothing (design §5.3, plan 3 drift D4). It is
+// published as the block's additive "primary" field; a block from an older
+// publisher leaves it empty.
+//
// A far edge builds these from the edges files it folds; the home box builds
// them from its own registry through LocalAssets.
type HostAssets struct {
@@ -16,6 +24,7 @@ type HostAssets struct {
Paths []string
Gen string
At time.Time
+ Primary string
}
// LocalAssets is the home box's own view (design §4.2: "a box serves and
diff --git a/internal/edge/homemap.go b/internal/edge/homemap.go
index 02ecde86a..32a044764 100644
--- a/internal/edge/homemap.go
+++ b/internal/edge/homemap.go
@@ -206,9 +206,10 @@ type edgesHostView struct {
// edgesAssetsView is the wire shape of the assets block: path prefixes, the
// instance's asset generation, and the host's authority time in Unix seconds.
type edgesAssetsView struct {
- Paths []string `json:"paths,omitempty"`
- Gen string `json:"gen,omitempty"`
- At int64 `json:"at,omitempty"`
+ Paths []string `json:"paths,omitempty"`
+ Gen string `json:"gen,omitempty"`
+ At int64 `json:"at,omitempty"`
+ Primary string `json:"primary,omitempty"`
}
// homeEntry is one folded answer: where to dial, and which box that is.
@@ -1051,6 +1052,7 @@ func (m *homeMap) AssetsFor(host string, now time.Time) (HostAssets, bool) {
return HostAssets{
Account: h.account, App: h.app,
Paths: slices.Clone(h.assets.Paths), Gen: h.assets.Gen, At: at,
+ Primary: h.assets.Primary,
}, true
}
diff --git a/internal/edge/homemap_assets_test.go b/internal/edge/homemap_assets_test.go
index e983fbfe1..1a66002a9 100644
--- a/internal/edge/homemap_assets_test.go
+++ b/internal/edge/homemap_assets_test.go
@@ -47,8 +47,8 @@ func TestHomeMapParsesAssets(t *testing.T) {
if !ok {
t.Fatal("AssetsFor = false for a fresh published block")
}
- want := HostAssets{Account: "abc", App: "shop", Paths: []string{"/_app/immutable/", "/assets/"}, Gen: "0123456789abcdef", At: goldenAt}
- if got.Account != want.Account || got.App != want.App || got.Gen != want.Gen ||
+ want := HostAssets{Account: "abc", App: "shop", Paths: []string{"/_app/immutable/", "/assets/"}, Gen: "0123456789abcdef", At: goldenAt, Primary: "shop.example.com"}
+ if got.Account != want.Account || got.App != want.App || got.Gen != want.Gen || got.Primary != want.Primary ||
!got.At.Equal(want.At) || !slices.Equal(got.Paths, want.Paths) {
t.Fatalf("AssetsFor = %+v, want %+v", got, want)
}
diff --git a/internal/edgesfile/edgesfile.go b/internal/edgesfile/edgesfile.go
index fb2cf2cf6..0d0e7802d 100644
--- a/internal/edgesfile/edgesfile.go
+++ b/internal/edgesfile/edgesfile.go
@@ -70,13 +70,16 @@ type Host struct {
}
// HostAssets is the decoded assets block: the path prefixes the host's
-// serving builds declare, the instance's asset generation, and the host's
-// authority time in Unix seconds. A reader serves nothing for a host whose
-// At is over an hour old (design §4.2).
+// serving builds declare, the instance's asset generation, the host's
+// authority time in Unix seconds, and the primary route hostname the block
+// was decided for (the host itself, or an alias's target; empty from a
+// publisher that predates it). A reader serves nothing for a host whose At
+// is over an hour old (design §4.2).
type HostAssets struct {
- Paths []string `json:"paths"`
- Gen string `json:"gen"`
- At int64 `json:"at"`
+ Paths []string `json:"paths"`
+ Gen string `json:"gen"`
+ At int64 `json:"at"`
+ Primary string `json:"primary,omitempty"`
}
// File is one box's published file.
diff --git a/internal/edgesfile/edgesfile_test.go b/internal/edgesfile/edgesfile_test.go
index 571caa2b4..4262e71f7 100644
--- a/internal/edgesfile/edgesfile_test.go
+++ b/internal/edgesfile/edgesfile_test.go
@@ -33,7 +33,7 @@ func TestParseKeepsAssets(t *testing.T) {
if want := []string{"/_app/immutable/", "/assets/"}; !slices.Equal(a.Paths, want) {
t.Fatalf("paths = %v, want %v", a.Paths, want)
}
- if a.Gen != "0123456789abcdef" || a.At != 1792832400 {
+ if a.Gen != "0123456789abcdef" || a.At != 1792832400 || a.Primary != "shop.example.com" {
t.Fatalf("assets = %+v", *a)
}
if p := f.Hosts["plain.example.com"].Assets; p != nil {
diff --git a/internal/edgesfile/testdata/assets-host.golden.json b/internal/edgesfile/testdata/assets-host.golden.json
index 197270a1b..1bcc7a7a2 100644
--- a/internal/edgesfile/testdata/assets-host.golden.json
+++ b/internal/edgesfile/testdata/assets-host.golden.json
@@ -6,6 +6,7 @@
"assets": {
"paths": ["/_app/immutable/", "/assets/"],
"gen": "0123456789abcdef",
- "at": 1792832400
+ "at": 1792832400,
+ "primary": "shop.example.com"
}
}
diff --git a/internal/host/assetpolicy.go b/internal/host/assetpolicy.go
index 4f0421467..a0484c3b9 100644
--- a/internal/host/assetpolicy.go
+++ b/internal/host/assetpolicy.go
@@ -21,13 +21,17 @@ import (
// edgeAssets is a host's "assets" block in the edges file:
//
-// "assets": {"paths": ["/assets/"], "gen": "9f2c41d07a3be516", "at": 1792828800}
+// "assets": {"paths": ["/assets/"], "gen": "9f2c41d07a3be516", "at": 1792828800, "primary": "shop.example.com"}
//
// At is the host's authority time in Unix seconds (assetAuthority.hostAt).
+// Primary is the route hostname the block was decided for: the host itself,
+// or an alias's target (plan 3 drift D4). Additive: a reader that predates it
+// ignores it.
type edgeAssets struct {
- Paths []string `json:"paths"`
- Gen string `json:"gen"`
- At int64 `json:"at"`
+ Paths []string `json:"paths"`
+ Gen string `json:"gen"`
+ At int64 `json:"at"`
+ Primary string `json:"primary,omitempty"`
}
const (
@@ -269,7 +273,7 @@ func (p *assetPolicy) decide(ctx context.Context, in assetInputs, clocks assetCl
if r.Pool != "" && !pooledOK {
return edge.HostAssets{}, false
}
- return edge.HostAssets{Account: acct, App: app, Paths: paths, Gen: r.AssetGen, At: at}, true
+ return edge.HostAssets{Account: acct, App: app, Paths: paths, Gen: r.AssetGen, At: at, Primary: r.Host}, true
}
// Publish is the edges file's rule for host, over the registry as it is now.
@@ -287,7 +291,7 @@ func (p *assetPolicy) Publish(host string) (edgeAssets, bool) {
if !ok {
return edgeAssets{}, false
}
- return edgeAssets{Paths: a.Paths, Gen: a.Gen, At: a.At.Unix()}, true
+ return edgeAssets{Paths: a.Paths, Gen: a.Gen, At: a.At.Unix(), Primary: a.Primary}, true
}
// For is the home's own catch for host (edge.LocalAssets): the rule without
diff --git a/internal/host/assetpublish_test.go b/internal/host/assetpublish_test.go
index 24a918e41..3d4de1694 100644
--- a/internal/host/assetpublish_test.go
+++ b/internal/host/assetpublish_test.go
@@ -754,10 +754,17 @@ func TestAliasPublishesItsPrimarysBlock(t *testing.T) {
if _, ok := hosts["pending.shop.example.com"]; ok {
t.Fatal("an alias whose DNS is not pointing was published")
}
- for _, h := range []string{"www.shop.example.com", "pending.shop.example.com"} {
+ for _, h := range []string{"shop.example.com", "www.shop.example.com", "pending.shop.example.com"} {
got, ok := w.policy.For(h)
- if !ok || got.Gen != assetGen1 || got.App != "shop" {
- t.Fatalf("For(%s) = %+v %v, want the primary's block", h, got, ok)
+ if !ok || got.Gen != assetGen1 || got.App != "shop" || got.Primary != "shop.example.com" {
+ t.Fatalf("For(%s) = %+v %v, want the primary's block, decided for shop.example.com", h, got, ok)
+ }
+ }
+ // The published block names the primary route too (drift D4): the
+ // alias's is its target's, the primary's its own.
+ for _, h := range []string{"shop.example.com", "www.shop.example.com"} {
+ if got := hosts[h].Assets.Primary; got != "shop.example.com" {
+ t.Fatalf("%s published primary %q, want shop.example.com", h, got)
}
}
// The primary gated: its aliases stop with it.
diff --git a/internal/host/edgesfile.go b/internal/host/edgesfile.go
index fa82ba1e5..ba1c1a8ad 100644
--- a/internal/host/edgesfile.go
+++ b/internal/host/edgesfile.go
@@ -677,7 +677,7 @@ func edgesFileWriteClaims(ctx context.Context, s release.Store, reg *registry.Re
continue
}
if a, ok := assets.decide(ctx, in, clocks, host, false); ok {
- h.Assets = &edgeAssets{Paths: a.Paths, Gen: a.Gen, At: a.At.Unix()}
+ h.Assets = &edgeAssets{Paths: a.Paths, Gen: a.Gen, At: a.At.Unix(), Primary: a.Primary}
hosts[host] = h
}
}