edge: the control socket acts for the route it was built for
ListenControl and ListenPurge take the spawning instance's route instead of its hostname, and every socket purge acts for that route: page clears are of its own pages, and "all" expands only to the hosts the edge's table serves as its instance. The listener no longer pins an owner from the edge's table, which can still hold the instance being replaced when a start outruns the reload. The activator's two start sites pass rt.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
internal/activator/activator_test.go+2 −2internal/activator/backend_exec.go+1 −1internal/activator/prepare.go+1 −1internal/edge/cache.go+0 −3internal/edge/edge_test.go+1 −1internal/edge/pagecache.go+0 −10internal/edge/pageclear_test.go+55 −3internal/edge/purge.go+17 −38internal/edge/purge_test.go+10 −8
CI failed — run details
Intent
<task-notification> <task-id>ac22e61fd10fe7542</task-id> <tool-use-id>toolu_016wXtTN2fhwNs5pWzxueC5T</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/d79ef2b4-4291-4945-bd45-b3f16796c4ba/tasks/ac22e61fd10fe7542.output</output-file> <status>completed</status> <summary>Agent "Implement Task 8: clears reach the index" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>Status: DONE. Both Important findings are fixed in a new commit; nothing was amended. Commits: - 6ca0baba edge: Carlos-Purge and the control socket clear pages; add the all target - f6ada519 edge: purges act for the authorized instance; all reaches wildcard hosts Tests: - All 9 Task 8 tests pass (4 new ones fail on the old code), including under `-race`. - `-run 'Purge|Page|Alias|Cache'` in edge passes, and so do the activator purge/inputs/control tests. - The windows and darwin builds pass. - 8 of 9 mutations were caught. The one that survived changes nothing now, because every page clear stays inside the responding route's own pages. Concerns: 1. **How I applied your ruling:** the default host and its aliases act for `rt`. A host named in Carlos-Purge-Host acts for the route it was checked against, in the same snapshot. Clearing only `rt`'s pages there would break page clears on sibling instances, which is what Carlos-Purge-Host exists for. A host admitted only by the path-routing exception acts for `rt`. 2. **Socket:** the listener's route is reachable through the bridge, so the socket locks onto it when the listener is created. If the route table doesn't hold the host yet, it locks on at the first purge, which leaves a narrow window. Passing `rt` into `ListenControl` from the activator would close it; I didn't change the activator. 3. The purged host's own LRU entries are still purged even after the hostname has moved to another instance, as they were before this task. That only costs a refetch; pages and the `all` expansion stay with the right instance. 4. `GOOS=windows go vet ./internal/edge` fails with `readerConn` undefined. The same failure happens on base e231c7fd, so it predates this task; I've listed it as unverified-pre-existing in the report. Report (fix section appended): /home/paulca/amadan.net/carlos/platform/.claude/worktrees/edge-page-cache-1/.superpowers/sdd/2026-11-08-edge-page-cache-plan-1-home/task-8-report.md</result> <usage><subagent_tokens>215198</subagent_tokens><tool_uses>20</tool_uses><duration_ms>771870</duration_ms></usage> </task-notification>
<task-notification> <task-id>by00xgito</task-id> <tool-use-id>toolu_01SUJJYdzgLiSLQdJJrxBv1p</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/d79ef2b4-4291-4945-bd45-b3f16796c4ba/tasks/by00xgito.output</output-file> <status>completed</status> <summary>Background command "Run scoped Astra re-review of Task 8 fix" completed (exit code 0)</summary> </task-notification>
Attributed to this commit: 27.6 g CO₂e (3,602,732 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on edge-page-cache-1, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.
diff --git a/internal/activator/activator_test.go b/internal/activator/activator_test.go| index 015d28034..4519b8e56 100644 |
| --- a/internal/activator/activator_test.go |
| +++ b/internal/activator/activator_test.go |
| @@ -6617,7 +6617,7 @@ func TestChildProcStopKeepsTheControlSocketUpUntilTheChildExits(t *testing.T) { |
| } |
| ctlSock := tmpSock(t) |
| - ctl, err := edge.ListenControl(ctlSock, "drain.example.com", nil, func(mux *http.ServeMux) { |
| + ctl, err := edge.ListenControl(ctlSock, registry.Route{Host: "drain.example.com"}, nil, func(mux *http.ServeMux) { |
| mux.HandleFunc("GET /schedule", func(w http.ResponseWriter, r *http.Request) { |
| w.WriteHeader(http.StatusOK) |
| }) |
| @@ -6695,7 +6695,7 @@ func TestChildProcStopKeepsTheControlSocketUpUntilTheChildExits(t *testing.T) { |
| func TestChildProcStopClosesTheControlSocketWhenTheChildIsAlreadyGone(t *testing.T) { |
| requireUnixSockets(t) |
| ctlSock := tmpSock(t) |
| - ctl, err := edge.ListenControl(ctlSock, "gone.example.com", nil, nil) |
| + ctl, err := edge.ListenControl(ctlSock, registry.Route{Host: "gone.example.com"}, nil, nil) |
| if err != nil { |
| t.Fatalf("ListenControl: %v", err) |
| } |
diff --git a/internal/activator/backend_exec.go b/internal/activator/backend_exec.go| index 73978417e..40574e5a5 100644 |
| --- a/internal/activator/backend_exec.go |
| +++ b/internal/activator/backend_exec.go |
| @@ -2448,7 +2448,7 @@ func (b *ExecBackend) spawnChildFrom(ctx context.Context, rt registry.Route, soc |
| } |
| } |
| } |
| - ctl, err := edge.ListenControl(controlSocket, rt.Host, b.Cache, mount) |
| + ctl, err := edge.ListenControl(controlSocket, rt, b.Cache, mount) |
| if err != nil { |
| log.Printf("activator: control listener for %s: %v (continuing without it)", rt.Host, err) |
| ctl = nil |
diff --git a/internal/activator/prepare.go b/internal/activator/prepare.go| index 34b9216af..56ed54d64 100644 |
| --- a/internal/activator/prepare.go |
| +++ b/internal/activator/prepare.go |
| @@ -287,7 +287,7 @@ func (b *ExecBackend) listenControl(rt registry.Route, control, envPath string, |
| } |
| } |
| } |
| - ctl, err := edge.ListenControl(control, rt.Host, b.Cache, mount) |
| + ctl, err := edge.ListenControl(control, rt, b.Cache, mount) |
| if err != nil { |
| log.Printf("activator: control listener for %s: %v (continuing without it)", rt.Host, err) |
| return nil |
diff --git a/internal/edge/cache.go b/internal/edge/cache.go| index 29c07bb8e..d49f1bb47 100644 |
| --- a/internal/edge/cache.go |
| +++ b/internal/edge/cache.go |
| @@ -109,9 +109,6 @@ type Cache struct { |
| // resolved afresh: a hostname can move to another instance while a purge |
| // is on its way, and a purge must never clear another instance's cache. |
| type purgeBridge interface { |
| - // ownerOf is the route the live table gives host as its own primary: |
| - // false when host is not routed, or is routed as another route's alias. |
| - ownerOf(host string) (registry.Route, bool) |
| // clearPages applies c to owner's pages, with host as the one host of |
| // a per-host clear (c with targets). An edge with no page cache clears |
| // nothing. |
diff --git a/internal/edge/edge_test.go b/internal/edge/edge_test.go| index 1dcf1c912..9cd3489af 100644 |
| --- a/internal/edge/edge_test.go |
| +++ b/internal/edge/edge_test.go |
| @@ -1410,7 +1410,7 @@ func TestCacheBeforeWakeFullCycleOverPurgeSocket(t *testing.T) { |
| // The control socket the activator would create for this instance and |
| // hand it as CARLOS_CONTROL_SOCKET. |
| controlSocket := filepath.Join(t.TempDir(), "instance.sock.control") |
| - pl, err := ListenPurge(controlSocket, "sock-cycle.example.com", cache) |
| + pl, err := ListenPurge(controlSocket, registry.Route{Host: "sock-cycle.example.com"}, cache) |
| if err != nil { |
| if errors.Is(err, syscall.EPERM) || strings.Contains(err.Error(), "operation not permitted") { |
| t.Skipf("unix-socket listeners not permitted in this environment: %v", err) |
diff --git a/internal/edge/pagecache.go b/internal/edge/pagecache.go| index e4c39e425..9e5f5dbfe 100644 |
| --- a/internal/edge/pagecache.go |
| +++ b/internal/edge/pagecache.go |
| @@ -51,16 +51,6 @@ func routeScope(rt registry.Route) pageindex.Scope { return pageScopeOf(upstream |
| // host, app and account, which is to say the same page scope. |
| func sameInstance(a, b registry.Route) bool { return routeScope(a) == routeScope(b) } |
| -// ownerOf is host's own route in the live table (purgeBridge): false when |
| -// host is not routed, or its entry is another route's (an alias). |
| -func (e *Edge) ownerOf(host string) (registry.Route, bool) { |
| - up, ok := e.current()[host] |
| - if !ok || up.route.Host != host { |
| - return registry.Route{}, false |
| - } |
| - return up.route, true |
| -} |
| - |
| // clearPages applies c to the pages of owner's instance (purgeBridge). The |
| // scope is owner's own, never one looked up by host, so a hostname that has |
| // moved to another instance since owner was authorized cannot carry the |
diff --git a/internal/edge/pageclear_test.go b/internal/edge/pageclear_test.go| index bc8c0213f..47020c5e6 100644 |
| --- a/internal/edge/pageclear_test.go |
| +++ b/internal/edge/pageclear_test.go |
| @@ -300,7 +300,7 @@ func TestControlSocketClearsPageAndAll(t *testing.T) { |
| hosts := []string{pcHost, pcAlias, pcAlias2} |
| listen := func(t *testing.T, s *pcScene) *http.Client { |
| sock := filepath.Join(shortPurgeSocketDir(t), "c.sock") |
| - ctl, err := ListenControl(sock, pcHost, s.e.cache, nil) |
| + ctl, err := ListenControl(sock, s.rt, s.e.cache, nil) |
| if err != nil { |
| t.Fatalf("ListenControl: %v", err) |
| } |
| @@ -519,7 +519,7 @@ func TestControlSocketCannotReachAReplacementInstance(t *testing.T) { |
| t.Fatal(err) |
| } |
| sock := filepath.Join(shortPurgeSocketDir(t), "c.sock") |
| - ctl, err := ListenControl(sock, pcHost, s.e.cache, nil) |
| + ctl, err := ListenControl(sock, s.rt, s.e.cache, nil) |
| if err != nil { |
| t.Fatalf("ListenControl: %v", err) |
| } |
| @@ -582,7 +582,7 @@ func TestPurgeAllClearsWildcardServedHosts(t *testing.T) { |
| s.do(http.MethodPost, "http://"+pcHost+"/admin") |
| } else { |
| sock := filepath.Join(shortPurgeSocketDir(t), "c.sock") |
| - ctl, err := ListenControl(sock, pcHost, s.e.cache, nil) |
| + ctl, err := ListenControl(sock, s.rt, s.e.cache, nil) |
| if err != nil { |
| t.Fatalf("ListenControl: %v", err) |
| } |
| @@ -649,3 +649,55 @@ func TestPurgeAllOnAPathRoutedHostStaysInTheServingApp(t *testing.T) { |
| t.Fatal("all expanded into another app's instance") |
| } |
| } |
| + |
| +// TestControlSocketActsForTheSpawningRoute: B's listener is built while the |
| +// edge's table still holds A at the hostname (a start can outrun the |
| +// reload). Its purges act for B, the route it was built for: before the |
| +// reload they clear nothing of A's, and after it they clear B's pages on |
| +// the host and its alias. |
| +func TestControlSocketActsForTheSpawningRoute(t *testing.T) { |
| + for _, path := range []string{"all", "*", "/p"} { |
| + t.Run(path, func(t *testing.T) { |
| + s := newPCScene(t, pageOK(pcBody)) |
| + upsertAlias(t, s.reg, pcAlias, pcHost) |
| + if err := s.e.Reload(); err != nil { |
| + t.Fatal(err) |
| + } |
| + s.keep(pcHost, "/p") |
| + s.keep(pcAlias, "/p") |
| + |
| + b := s.rt |
| + b.App = "shop" |
| + sock := filepath.Join(shortPurgeSocketDir(t), "c.sock") |
| + ctl, err := ListenControl(sock, b, s.e.cache, nil) |
| + if err != nil { |
| + t.Fatalf("ListenControl: %v", err) |
| + } |
| + t.Cleanup(func() { ctl.Close() }) |
| + c := dialPurgeSocket(t, sock) |
| + |
| + // The table still holds A: B's purge is not A's. |
| + if code := postSocketPurge(t, c, map[string]string{"path": path}); code != http.StatusOK { |
| + t.Fatalf("purge status = %d", code) |
| + } |
| + s.wantKept("A's page, before the reload", pcHost, "/p") |
| + s.wantKept("A's alias page, before the reload", pcAlias, "/p") |
| + |
| + // The reload lands: the hostname and its alias are B's. |
| + s.decl.loadFor("abc", "shop", pcBuild, "/assets/") |
| + s.setRoute(func(r *registry.Route) { r.App = "shop" }) |
| + s.publish() |
| + s.keep(pcHost, "/p") |
| + s.keep(pcAlias, "/p") |
| + if code := postSocketPurge(t, c, map[string]string{"path": path}); code != http.StatusOK { |
| + t.Fatalf("purge status = %d", code) |
| + } |
| + s.wantCleared("B's page", pcHost, "/p") |
| + if path == "all" { |
| + s.wantCleared("B's alias page", pcAlias, "/p") |
| + } else { |
| + s.wantKept("B's alias page, not named", pcAlias, "/p") |
| + } |
| + }) |
| + } |
| +} |
diff --git a/internal/edge/purge.go b/internal/edge/purge.go| index 9efa190fe..3cdd41e82 100644 |
| --- a/internal/edge/purge.go |
| +++ b/internal/edge/purge.go |
| @@ -4,7 +4,6 @@ import ( |
| "encoding/json" |
| "net" |
| "net/http" |
| - "sync" |
| "github.com/carlosframework/platform/internal/pageindex" |
| "github.com/carlosframework/platform/internal/registry" |
| @@ -71,6 +70,14 @@ const purgeAllPath = "*" |
| // behind it would be a lie. mount, when non-nil, adds the caller's own verbs |
| // to the same mux (the scheduled-work ones, schedule.Mount). |
| // |
| +// rt is the route of the instance this listener is built for, the one the |
| +// caller is starting, and host is rt.Host. Every purge acts for rt: its page |
| +// clears are of rt's own pages, and "all" expands only to the hosts the |
| +// edge's table serves as rt's instance. rt is taken from the caller, never |
| +// looked up in the edge's table, because the table can lag the start (it may |
| +// still hold the instance this one replaces) and purge authority belongs to |
| +// the instance that owns the listener. |
| +// |
| // What the host scoping actually guarantees: host is fixed here, at |
| // construction, and never taken from the request — purgeRequest carries |
| // only Path and Query, never a host — so no request body, however |
| @@ -137,7 +144,8 @@ const purgeAllPath = "*" |
| // result (see backend_unit.go); their cached routes rely on the TTL |
| // ceiling alone, and their once-timers go through the console rather than |
| // the socket, until that gets its own design. |
| -func ListenControl(socketPath, host string, cache *Cache, mount func(*http.ServeMux)) (*ControlListener, error) { |
| +func ListenControl(socketPath string, rt registry.Route, cache *Cache, mount func(*http.ServeMux)) (*ControlListener, error) { |
| + host := rt.Host |
| ln, err := SecureUnixListen(socketPath) |
| if err != nil { |
| return nil, err |
| @@ -145,28 +153,6 @@ func ListenControl(socketPath, host string, cache *Cache, mount func(*http.Serve |
| mux := http.NewServeMux() |
| if cache != nil { |
| - // owner is the instance this listener purges for: host's own route |
| - // in the edge's table, pinned when the listener is built, so a purge |
| - // arriving after host has moved to another instance clears only this |
| - // one's pages and never expands to the newcomer's hosts. A host the |
| - // table does not hold yet (a first start can outrun the edge's |
| - // reload) is pinned at the first purge instead. |
| - var ( |
| - ownerMu sync.Mutex |
| - owner registry.Route |
| - pinned bool |
| - ) |
| - ownerFor := func(b purgeBridge) (registry.Route, bool) { |
| - ownerMu.Lock() |
| - defer ownerMu.Unlock() |
| - if !pinned { |
| - owner, pinned = b.ownerOf(host) |
| - } |
| - return owner, pinned |
| - } |
| - if b := cache.purgeBridgeOf(); b != nil { |
| - ownerFor(b) |
| - } |
| mux.HandleFunc("POST /purge", func(w http.ResponseWriter, r *http.Request) { |
| var req purgeRequest |
| if err := json.NewDecoder(r.Body).Decode(&req); err != nil { |
| @@ -176,16 +162,9 @@ func ListenControl(socketPath, host string, cache *Cache, mount func(*http.Serve |
| // The bridge to the edge's page index: nil when no edge armed |
| // this cache, and then only the LRU is purged. |
| bridge := cache.purgeBridgeOf() |
| - var own registry.Route |
| - if bridge != nil { |
| - var ok bool |
| - if own, ok = ownerFor(bridge); !ok { |
| - bridge = nil // no instance to act for: the LRU only |
| - } |
| - } |
| clearPages := func(c pageindex.Clear) { |
| if bridge != nil { |
| - bridge.clearPages(own, host, c) |
| + bridge.clearPages(rt, host, c) |
| } |
| } |
| switch req.Path { |
| @@ -203,11 +182,11 @@ func ListenControl(socketPath, host string, cache *Cache, mount func(*http.Serve |
| http.Error(w, "bad request", http.StatusBadRequest) |
| return |
| } |
| - // Every host of the pinned instance, found in the edge's live |
| - // route table, never by anything in the body. |
| + // Every host the edge's live route table serves as rt's |
| + // instance, never anything named by the body. |
| cache.PurgeHost(host) |
| if bridge != nil { |
| - for _, h := range bridge.instanceHosts(own, cache.cachedHosts()) { |
| + for _, h := range bridge.instanceHosts(rt, cache.cachedHosts()) { |
| if h != host { |
| cache.PurgeHost(h) |
| } |
| @@ -238,10 +217,10 @@ func ListenControl(socketPath, host string, cache *Cache, mount func(*http.Serve |
| // before the channel generalized, kept for callers that only want the |
| // purge verb and none of the scheduled-work ones. It is not a promise that |
| // /purge itself is registered: ListenControl only mounts it when cache is |
| -// non-nil, so ListenPurge(socketPath, host, nil) serves nothing at all, |
| +// non-nil, so ListenPurge(socketPath, rt, nil) serves nothing at all, |
| // same as ListenControl would. |
| -func ListenPurge(socketPath, host string, cache *Cache) (*PurgeListener, error) { |
| - return ListenControl(socketPath, host, cache, nil) |
| +func ListenPurge(socketPath string, rt registry.Route, cache *Cache) (*PurgeListener, error) { |
| + return ListenControl(socketPath, rt, cache, nil) |
| } |
| // Close stops accepting control requests, removes the socket file, and tears |
diff --git a/internal/edge/purge_test.go b/internal/edge/purge_test.go| index 74055078e..d95a17c96 100644 |
| --- a/internal/edge/purge_test.go |
| +++ b/internal/edge/purge_test.go |
| @@ -10,6 +10,8 @@ import ( |
| "path/filepath" |
| "testing" |
| "time" |
| + |
| + "github.com/carlosframework/platform/internal/registry" |
| ) |
| func dialPurgeSocket(t *testing.T, socketPath string) *http.Client { |
| @@ -31,7 +33,7 @@ func TestListenPurgeRemovesCachedEntry(t *testing.T) { |
| StatusCode: 200, Header: http.Header{}, Body: []byte("hi"), StoredAt: time.Now(), TTL: time.Minute, |
| }) |
| - pl, err := ListenPurge(sock, "a.example", cache) |
| + pl, err := ListenPurge(sock, registry.Route{Host: "a.example"}, cache) |
| if err != nil { |
| t.Fatalf("ListenPurge: %v", err) |
| } |
| @@ -61,7 +63,7 @@ func TestListenPurgeCannotAffectAnotherHost(t *testing.T) { |
| StatusCode: 200, Header: http.Header{}, Body: []byte("hi"), StoredAt: time.Now(), TTL: time.Minute, |
| }) |
| - pl, err := ListenPurge(sock, "a.example", cache) // bound to a.example, not other.example |
| + pl, err := ListenPurge(sock, registry.Route{Host: "a.example"}, cache) // bound to a.example, not other.example |
| if err != nil { |
| t.Fatalf("ListenPurge: %v", err) |
| } |
| @@ -80,7 +82,7 @@ func TestListenPurgeCannotAffectAnotherHost(t *testing.T) { |
| func TestListenPurgeSocketFileIsOwnerOnly(t *testing.T) { |
| dir := t.TempDir() |
| sock := filepath.Join(dir, "instance.sock") |
| - pl, err := ListenPurge(sock, "a.example", NewCache(10, 1<<20)) |
| + pl, err := ListenPurge(sock, registry.Route{Host: "a.example"}, NewCache(10, 1<<20)) |
| if err != nil { |
| t.Fatalf("ListenPurge: %v", err) |
| } |
| @@ -109,7 +111,7 @@ func TestListenPurgeSocketFileIsOwnerOnly(t *testing.T) { |
| func TestListenPurgeCloseImmediatelyAfterOpenRemovesSocketFile(t *testing.T) { |
| dir := shortPurgeSocketDir(t) |
| sock := filepath.Join(dir, "instance.sock") |
| - pl, err := ListenPurge(sock, "a.example", NewCache(10, 1<<20)) |
| + pl, err := ListenPurge(sock, registry.Route{Host: "a.example"}, NewCache(10, 1<<20)) |
| if err != nil { |
| t.Fatalf("ListenPurge: %v", err) |
| } |
| @@ -139,7 +141,7 @@ func TestListenPurgeCloseRefusesRequestsOnAlreadyEstablishedConnections(t *testi |
| StatusCode: 200, Header: http.Header{}, Body: []byte("hi"), StoredAt: time.Now(), TTL: time.Minute, |
| }) |
| - pl, err := ListenPurge(sock, "a.example", cache) |
| + pl, err := ListenPurge(sock, registry.Route{Host: "a.example"}, cache) |
| if err != nil { |
| t.Fatalf("ListenPurge: %v", err) |
| } |
| @@ -177,7 +179,7 @@ func TestListenPurgeRemovesStaleSocketFile(t *testing.T) { |
| if err := os.WriteFile(sock, []byte("stale"), 0600); err != nil { |
| t.Fatal(err) |
| } |
| - pl, err := ListenPurge(sock, "a.example", NewCache(10, 1<<20)) |
| + pl, err := ListenPurge(sock, registry.Route{Host: "a.example"}, NewCache(10, 1<<20)) |
| if err != nil { |
| t.Fatalf("ListenPurge should clean up a stale socket file, got: %v", err) |
| } |
| @@ -200,7 +202,7 @@ func TestListenPurgeStarPurgesTheWholeHost(t *testing.T) { |
| mine := []CacheKey{put("a.example", "/one", ""), put("a.example", "/two", "q=1")} |
| other := put("other.example", "/one", "") |
| - pl, err := ListenPurge(sock, "a.example", cache) |
| + pl, err := ListenPurge(sock, registry.Route{Host: "a.example"}, cache) |
| if err != nil { |
| t.Fatalf("ListenPurge: %v", err) |
| } |
| @@ -236,7 +238,7 @@ func TestListenPurgeStarWithAQueryIsRefused(t *testing.T) { |
| StatusCode: 200, Header: http.Header{}, Body: []byte("hi"), StoredAt: time.Now(), TTL: time.Minute, |
| }) |
| - pl, err := ListenPurge(sock, "a.example", cache) |
| + pl, err := ListenPurge(sock, registry.Route{Host: "a.example"}, cache) |
| if err != nil { |
| t.Fatalf("ListenPurge: %v", err) |
| } |