carlos / platform Public

appconfig: classifier fixes from review (owned default, collisions)

Astra round 1, three P2s:
- An owned environment's route needs the default bundle to read, as
  both passes do; Unresolved otherwise (the notice's stamped answer is
  unchanged).
- SyncExec's <host>.config collision guard is shared (routeHostSet,
  configNameCollides); a colliding exec route is Unresolved.
- Pending is the legacy notice decided in the same pass, so rows the
  legacy addr predicate admits beside another shape (a sidecar with an
  Addr) project as before. A generated comparison against the old
  AwaitingRestart pins it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 5e5d3b5578c8ba9ba1a8236de072196e04899722 parent 8f16890
3 files changed, +528 −72
  • internal/appconfig/reach.go +120 −40
  • internal/appconfig/reach_test.go +388 −27
  • internal/appconfig/syncexec.go +20 −5

Intent

Human

<task-notification> <task-id>ae73859cee8eb4b00</task-id> <tool-use-id>toolu_016DAkC9783KmLQCLtgi4wSr</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/abe35d56-e4c2-40df-9005-6e66b76b1f50/tasks/ae73859cee8eb4b00.output</output-file> <status>completed</status> <summary>Agent "Implement Task 3 classifier" 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. Commit 8f168909: a route the write reaches that isn't ready now goes to Starting with Why "not-running" instead of disappearing. Its shape is read off a copy of the route with Status set to "ready". Addr routes are still skipped, and the bundle-unreadable and shadowing rules still apply. Pending() is byte-identical: the 24 AwaitingRestart/BlockedStamps guards pass unchanged. That holds because Pending() leaves out a not-ready route's Unresolved entry, which carries Why "not-running". Tests: `go test ./internal/appconfig -run 'Classify|AwaitingRestart|BlockedStamps' -count=1` is ok, including 11 new not-ready table rows, the updated property test and one new projection test. The tests caught all 3 deliberate breaks I made in the new code. Concern 2 is left as is. A fix note is appended to .superpowers/sdd/2026-11-08-console-secrets/task-3-report.md.</result> <usage><subagent_tokens>142319</subagent_tokens><tool_uses>40</tool_uses><duration_ms>973840</duration_ms></usage> </task-notification>

Human

<task-notification> <task-id>bsd2pqofw</task-id> <tool-use-id>toolu_016iductH4BgWs5rwvA1TT6b</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/abe35d56-e4c2-40df-9005-6e66b76b1f50/tasks/bsd2pqofw.output</output-file> <status>completed</status> <summary>Background command "until [ -f .superpowers/sdd/2026-11-08-console-secrets/astra-t3.done ]; do sleep 30; done; tail -3 .superpowers/sdd/2026-11-08-console-secrets/astra-t3-findings.md" completed (exit code 0)</summary> </task-notification>

Attributed to this commit: 4.03 g CO₂e (513,878 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on design-console-secrets, 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/appconfig/reach.go b/internal/appconfig/reach.go
index fa8033157..2a5b616b0 100644
--- a/internal/appconfig/reach.go
+++ b/internal/appconfig/reach.go
@@ -87,9 +87,16 @@ type WriteReach struct {
Self, Carloku, Yours, Starting []ReachHost // Carloku is always empty in this slice
Unseen []string
Blocked []BlockedHost
- Unresolved []ReachHost // Shape kept so the projection can filter
+ Unresolved []ReachHost
Undelivered []string
RecordsComplete bool
+
+ // legacy is the restart notice as AwaitingRestart has always computed
+ // it, decided in the same pass from the same reads. It is not read off
+ // the buckets because the legacy predicates overlap the exclusive
+ // shapes (a sidecar row with an Addr) and the buckets are stricter
+ // (an owned environment's default read, a config name collision).
+ legacy RestartPending
}
// reachShape is the one place a route's delivery shape is decided, in the
@@ -136,7 +143,9 @@ func reachShape(rt registry.Route) (ReachShape, bool) {
// only); the bound bundle's read (Unresolved when it fails or is missing);
// then per shape, the addr opt-in (Undelivered when off) or the layers the
// self-delivering passes need (Unresolved when one will not read); the
-// shadowing test; the bucket.
+// shadowing test; SyncExec's config name collision guard for the exec
+// shapes (Unresolved); the bucket. The legacy notice Pending projects is
+// decided in the same pass from the same reads (WriteReach.legacy).
func ClassifyWrite(ctx context.Context, s release.Store, routes []registry.Route, facts ReachFacts, acct, app, envName string, keys []string) WriteReach {
out := WriteReach{RecordsComplete: facts.RecordsComplete}
// The door-side rails over the full box list; a blocked host is
@@ -151,6 +160,8 @@ func ClassifyWrite(ctx context.Context, s release.Store, routes []registry.Route
// classification and the passes that write the files agree about what
// sits above a bundle. Lives for one call, like the caches below.
overlayFor := instanceOverlayLoader(ctx, s)
+ // Every host on the box, for SyncExec's config name collision guard.
+ hostSet := routeHostSet(routes)
// One read per bundle per call, however many routes share it.
var (
defM *Manifest
@@ -216,10 +227,19 @@ func ClassifyWrite(ctx context.Context, s release.Store, routes []registry.Route
}
h := ReachHost{Host: rt.Host, Unit: rt.Unit, Shape: shape}
if notReady {
- // Carried on an Unresolved entry too, so the projection can
- // leave out what the notice never covered.
+ // Carried on an Unresolved entry too: the route is waiting to
+ // start as well as unreadable.
h.Why = ReachWhyNotRunning
}
+ // The legacy notice's view of this route (AwaitingRestart before
+ // this classifier): the addr predicate and the stamped one, on the
+ // row as it is. Kept beside the exclusive shape because the two
+ // predicates can overlap with others (a sidecar row carrying an
+ // Addr is also an addr candidate), and Pending must say exactly
+ // what the notice always said.
+ legacyAddr := execAddrCandidate(rt)
+ legacyStamped := stampedForDelivery(rt)
+ notice := legacyAddr || legacyStamped
eb := envRes{}
def := loadDefault
standalone := false
@@ -239,10 +259,11 @@ func ClassifyWrite(ctx context.Context, s release.Store, routes []registry.Route
}
// Blocked is decided before bundle resolution (spec §3.4 of the
// named-unit design): a route the root pass will refuse is reported
- // as blocked, not as healthy and not as unresolved.
- // Keyed by host, which a registry holds once.
+ // as blocked, not as healthy and not as unresolved. Keyed by host,
+ // which a registry holds once; only ready stamped routes are named.
if reason, bad := blocked[rt.Host]; bad {
out.Blocked = append(out.Blocked, BlockedHost{Host: rt.Host, Reason: reason})
+ out.legacy.Blocked = append(out.legacy.Blocked, BlockedHost{Host: rt.Host, Reason: reason})
continue
}
if rt.Environment != "" && (eb.err != nil || !eb.found) {
@@ -250,11 +271,76 @@ func ClassifyWrite(ctx context.Context, s release.Store, routes []registry.Route
// refuses the route and every pass leaves its file as it was.
// Nothing was delivered, and the route is not fine either.
out.Unresolved = append(out.Unresolved, h)
+ if notice {
+ out.legacy.Unresolved = append(out.legacy.Unresolved, rt.Host)
+ }
continue
}
+ // The layers every outcome below is decided from, each read at most
+ // once per call (the loaders cache).
+ var (
+ v execDeliveryVerdict
+ vErr error
+ vDone bool
+ inst *Manifest
+ instErr error
+ instDone bool
+ )
+ verdict := func() (execDeliveryVerdict, error) {
+ if !vDone {
+ v, vErr = resolveExecDelivery(eb.m, eb.found, def)
+ vDone = true
+ }
+ return v, vErr
+ }
+ overlay := func() (*Manifest, error) {
+ if !instDone {
+ inst, _, instErr = overlayFor(acct, app, rt.Host)
+ instDone = true
+ }
+ return inst, instErr
+ }
+ shadowed := func() bool {
+ m, _ := overlay()
+ return len(keys) > 0 && allShadowed(keys, above(rt.Environment, eb, m)...)
+ }
+
+ // The legacy notice, decided exactly as AwaitingRestart always has.
+ if notice {
+ switch {
+ case legacyStamped:
+ // Delivered and restarted by the root pass; named only when a
+ // layer it renders from will not resolve.
+ if _, err := verdict(); err != nil {
+ out.legacy.Unresolved = append(out.legacy.Unresolved, rt.Host)
+ } else if _, _, err := loadDefault(); !standalone && err != nil {
+ out.legacy.Unresolved = append(out.legacy.Unresolved, rt.Host)
+ } else if _, err := overlay(); err != nil {
+ out.legacy.Unresolved = append(out.legacy.Unresolved, rt.Host)
+ }
+ default:
+ if v, err := verdict(); err != nil {
+ out.legacy.Unresolved = append(out.legacy.Unresolved, rt.Host)
+ } else if !v.On {
+ out.legacy.Undelivered = append(out.legacy.Undelivered, rt.Host)
+ } else if len(keys) == 0 {
+ out.legacy.Hosts = append(out.legacy.Hosts, RestartHost{Host: rt.Host, Unit: rt.Unit})
+ } else if _, err := overlay(); err != nil {
+ out.legacy.Unresolved = append(out.legacy.Unresolved, rt.Host)
+ } else if !shadowed() {
+ out.legacy.Hosts = append(out.legacy.Hosts, RestartHost{Host: rt.Host, Unit: rt.Unit})
+ }
+ }
+ }
+
+ // SyncExec refuses to write a route's file when another route on
+ // this box owns that name (configNameCollides): nothing is delivered
+ // to an exec shape that collides, so it is not fine either.
+ execShape := shape == ReachShapeSocket || shape == ReachShapeSidecar || shape == ReachShapeAddr
+ collides := execShape && configNameCollides(hostSet, rt.Host)
if shape == ReachShapeAddr {
- v, err := resolveExecDelivery(eb.m, eb.found, def)
+ v, err := verdict()
if err != nil {
out.Unresolved = append(out.Unresolved, h)
continue
@@ -266,18 +352,20 @@ func ClassifyWrite(ctx context.Context, s release.Store, routes []registry.Route
continue
}
// The overlay is consulted only when the shadowing test could
- // change the verdict (as AwaitingRestart always has): an addr
- // route's delivery is a file, and an empty keys asks nothing.
+ // change the verdict: an empty keys asks it nothing.
if len(keys) > 0 {
- inst, _, instErr := overlayFor(acct, app, rt.Host)
- if instErr != nil {
+ if _, err := overlay(); err != nil {
out.Unresolved = append(out.Unresolved, h)
continue
}
- if allShadowed(keys, above(rt.Environment, eb, inst)...) {
+ if shadowed() {
continue
}
}
+ if collides {
+ out.Unresolved = append(out.Unresolved, h)
+ continue
+ }
// An addr route's process is the app's own supervisor's; a
// sleep fact does not change who restarts it.
h.How = ReachHowAddr
@@ -285,24 +373,26 @@ func ClassifyWrite(ctx context.Context, s release.Store, routes []registry.Route
continue
}
- // The self-delivering shapes (stamped, unit, socket, sidecar). Each
- // pass renders from the default bundle (unless an owned environment
- // stands alone) and the instance overlay, and delivers nothing when
- // either will not read; so neither can it restart anything.
- if !standalone {
- if _, _, err := loadDefault(); err != nil {
- out.Unresolved = append(out.Unresolved, h)
- continue
- }
+ // The self-delivering shapes (stamped, unit, socket, sidecar). Both
+ // passes read the default bundle before any named one, an owned one
+ // included (sync.go, SyncExec, loadMergedETags), and the instance
+ // overlay; when either will not read they deliver nothing, so they
+ // restart nothing.
+ if _, _, err := loadDefault(); err != nil {
+ out.Unresolved = append(out.Unresolved, h)
+ continue
}
- inst, _, instErr := overlayFor(acct, app, rt.Host)
- if instErr != nil {
+ if _, err := overlay(); err != nil {
out.Unresolved = append(out.Unresolved, h)
continue
}
// Shadowed: the merged file is byte-identical, the pass writes
// nothing and restarts nothing. Not reported at all.
- if len(keys) > 0 && allShadowed(keys, above(rt.Environment, eb, inst)...) {
+ if shadowed() {
+ continue
+ }
+ if collides {
+ out.Unresolved = append(out.Unresolved, h)
continue
}
fact := facts.Hosts[rt.Host] // a nil map reads as no fact
@@ -382,24 +472,14 @@ func sortReachHosts(l []ReachHost) {
}
// Pending is the AwaitingRestart projection: what the CLI's restart notice
-// has always said, read off the classification. Hosts are the opted-in addr
-// routes (the files nothing here restarts); Unresolved is narrowed to the
-// addr and stamped shapes of ready routes, the ones the notice has always
-// covered (a not-ready route's entry carries Why "not-running").
+// has always said, decided in ClassifyWrite's pass (see WriteReach.legacy).
+// Every list sorted.
func (w WriteReach) Pending() RestartPending {
var p RestartPending
- for _, h := range w.Yours {
- if h.Shape == ReachShapeAddr {
- p.Hosts = append(p.Hosts, RestartHost{Host: h.Host, Unit: h.Unit})
- }
- }
- for _, h := range w.Unresolved {
- if (h.Shape == ReachShapeAddr || h.Shape == ReachShapeStamped) && h.Why == "" {
- p.Unresolved = append(p.Unresolved, h.Host)
- }
- }
- p.Blocked = append(p.Blocked, w.Blocked...)
- p.Undelivered = append(p.Undelivered, w.Undelivered...)
+ p.Hosts = append(p.Hosts, w.legacy.Hosts...)
+ p.Unresolved = append(p.Unresolved, w.legacy.Unresolved...)
+ p.Blocked = append(p.Blocked, w.legacy.Blocked...)
+ p.Undelivered = append(p.Undelivered, w.legacy.Undelivered...)
sort.Slice(p.Hosts, func(i, j int) bool { return p.Hosts[i].Host < p.Hosts[j].Host })
sort.Slice(p.Blocked, func(i, j int) bool { return p.Blocked[i].Host < p.Blocked[j].Host })
sort.Strings(p.Unresolved)
diff --git a/internal/appconfig/reach_test.go b/internal/appconfig/reach_test.go
index 68585a681..6d321841e 100644
--- a/internal/appconfig/reach_test.go
+++ b/internal/appconfig/reach_test.go
@@ -5,7 +5,9 @@ import (
"errors"
"fmt"
"math/rand/v2"
+ "reflect"
"slices"
+ "sort"
"strings"
"testing"
@@ -61,6 +63,12 @@ func reachRoute(shape, host, env string) registry.Route {
rt.Kind = "sidecar"
case "addr":
rt.Addr = "127.0.0.1:9003"
+ case "sidecar+addr": // overlapping predicates: sidecar and addr
+ rt.Kind, rt.Addr = "sidecar", "127.0.0.1:9004"
+ case "sidecar+addrs":
+ rt.Kind, rt.Addrs = "sidecar", "127.0.0.1:9005"
+ case "unit+stamp": // unit-backed and stamped: stays on carlos-app@
+ rt.Addr, rt.Backing, rt.Unit = "127.0.0.1:9006", registry.BackingUnit, "w-"+strings.SplitN(host, ".", 2)[0]+".service"
default:
panic(shape)
}
@@ -229,7 +237,7 @@ var (
return p
}()
reachOverlays = reachPool[:8] // these hosts have an INST_KEY overlay
- reachShapes = []string{"unit", "stamped", "blocked", "socket", "sidecar", "addr"}
+ reachShapes = []string{"unit", "stamped", "blocked", "socket", "sidecar", "addr", "sidecar+addr", "sidecar+addrs", "unit+stamp"}
reachEnvs = []string{"", "", "prod", "team", "ghost"}
reachKeySet = []string{"SHARED", "PROD_KEY", "INST_KEY", "TEAM_ONLY"}
)
@@ -267,6 +275,12 @@ func genReachCase(r *rand.Rand) reachCase {
}
c.routes = append(c.routes, rt)
}
+ // Some routes collide with another app's "<host>.config" route.
+ for _, rt := range slices.Clone(c.routes) {
+ if r.IntN(6) == 0 {
+ c.routes = append(c.routes, registry.Route{Host: rt.Host + ".config", Kind: "instance", App: "other", Account: "bab", Status: "ready", Socket: "/run/" + rt.Host + ".c.sock"})
+ }
+ }
for _, h := range hosts[n : n+r.IntN(6)] {
c.facts.Records = append(c.facts.Records, ReachRecord{Host: h, Environment: reachEnvs[r.IntN(len(reachEnvs))]})
}
@@ -328,14 +342,15 @@ func reachCandidate(rt registry.Route) bool {
}
// reachReached: a ready candidate, or a not-ready route a ready copy of
-// which is a candidate of a shape other than addr.
+// which is a candidate whose delivery shape is not addr.
func reachReached(rt registry.Route) bool {
if rt.Status == "" || rt.Status == "ready" {
return reachCandidate(rt)
}
ready := rt
ready.Status = "ready"
- return reachCandidate(ready) && !execAddrCandidate(ready)
+ shape, ok := reachShape(ready)
+ return ok && shape != ReachShapeAddr
}
func TestClassifyWriteProperty(t *testing.T) {
@@ -414,6 +429,7 @@ func TestClassifySelfMatchesDelivery(t *testing.T) {
c := genReachCase(r)
c.failKey, c.keys = "", nil
w := ClassifyWrite(ctx, worlds[c.optIn], c.routes, c.facts, "bab", "relay", c.envName, c.keys)
+ hostSet := routeHostSet(c.routes)
blocked := map[string]bool{}
for _, b := range BlockedStamps(c.routes, "bab", "relay", c.envName) {
blocked[b.Host] = true
@@ -424,6 +440,16 @@ func TestClassifySelfMatchesDelivery(t *testing.T) {
}
at, _ := reachWhere(t, w, rt.Host)
fact := c.facts.Hosts[rt.Host]
+ ready := rt
+ ready.Status = "ready"
+ if (execSyncable(ready) || execSidecarCandidate(ready) || execAddrCandidate(ready)) && configNameCollides(hostSet, rt.Host) {
+ // SyncExec refuses it: nothing delivered, nothing restarted.
+ // An addr route not opted in gets no file to refuse.
+ if at != "unresolved" && !(at == "undelivered" && execAddrCandidate(rt)) && !(at == "" && reachShapeIsAddr(ready)) {
+ t.Fatalf("case %d: colliding %s in %q, want unresolved", i, rt.Host, at)
+ }
+ continue
+ }
if rt.Status != "" && rt.Status != "ready" {
// Delivered by no pass now; its shape's pass once ready.
if want := reachReached(rt); want != (at == "starting") {
@@ -550,30 +576,6 @@ func TestClassifyNoAbsenceClaims(t *testing.T) {
}
}
-// TestClassifyPendingProjection: the projection keeps only what the notice
-// has always said, and orders every list.
-func TestClassifyPendingProjection(t *testing.T) {
- w := WriteReach{
- Self: []ReachHost{{Host: "s.example.com", Shape: ReachShapeSocket}},
- Yours: []ReachHost{{Host: "z.example.com", Shape: ReachShapeAddr, Unit: "z.service"}, {Host: "c.example.com", Shape: ReachShapeSidecar}, {Host: "a.example.com", Shape: ReachShapeAddr}},
- Starting: []ReachHost{{Host: "t.example.com", Shape: ReachShapeUnit}},
- Unresolved: []ReachHost{{Host: "u2.example.com", Shape: ReachShapeStamped}, {Host: "u3.example.com", Shape: ReachShapeSocket}, {Host: "u1.example.com", Shape: ReachShapeAddr}},
- Blocked: []BlockedHost{{Host: "b.example.com", Reason: "r"}},
- Undelivered: []string{"d2.example.com", "d1.example.com"},
- Unseen: []string{"x.example.com"},
- }
- p := w.Pending()
- if !slices.Equal(p.Hosts, []RestartHost{{Host: "a.example.com"}, {Host: "z.example.com", Unit: "z.service"}}) ||
- !slices.Equal(p.Unresolved, []string{"u1.example.com", "u2.example.com"}) ||
- !slices.Equal(p.Undelivered, []string{"d1.example.com", "d2.example.com"}) ||
- len(p.Blocked) != 1 {
- t.Fatalf("Pending = %+v", p)
- }
- if !(WriteReach{Self: w.Self, Starting: w.Starting, Unseen: w.Unseen}).Pending().Empty() {
- t.Fatal("Self, Starting and Unseen must project to nothing")
- }
-}
-
// TestClassifyNotReadyLeavesThePendingProjectionAlone: a not-ready route
// the notice never named stays out of it, Unresolved included.
func TestClassifyNotReadyLeavesThePendingProjectionAlone(t *testing.T) {
@@ -594,3 +596,362 @@ func TestClassifyNotReadyLeavesThePendingProjectionAlone(t *testing.T) {
t.Fatalf("Pending = %+v, want empty", p)
}
}
+
+// legacyAwaitingRestart is AwaitingRestart exactly as it stood before the
+// classifier (20d3367b^), kept here as the oracle the projection is
+// compared against over generated inputs.
+func legacyAwaitingRestart(ctx context.Context, s release.Store, routes []registry.Route, acct, app, envName string, keys []string) RestartPending {
+ var out RestartPending
+ // The door-side rails over the full box list; a blocked host is
+ // reported only once the loop below has established that this write
+ // reaches it (environment narrowing, and an owned environment's
+ // standalone boundary; review round 1 P2-5).
+ blocked := map[string]string{}
+ for _, b := range BlockedStamps(routes, acct, app, envName) {
+ blocked[b.Host] = b.Reason
+ }
+ // The instance layer, through the same loader the sweeps use, so this
+ // notice and the pass that writes the files agree about what sits above
+ // a bundle. One listing for the app, then a Get per route that has an
+ // overlay; both live for one call, like the caches below.
+ overlayFor := instanceOverlayLoader(ctx, s)
+ // Both caches exist for the same reason SyncExec's do: a box with many
+ // TCP-addr routes on one bundle must not cost more than one read for
+ // it. Unlike SyncExec's, they live for one call.
+ var (
+ defM *Manifest
+ defFound bool
+ defErr error
+ defDone bool
+ )
+ loadDefault := func() (*Manifest, bool, error) {
+ if !defDone {
+ defM, defFound, defErr = getIfExists(ctx, s, acct, app)
+ defDone = true
+ }
+ return defM, defFound, defErr
+ }
+ type envRes struct {
+ m *Manifest
+ found bool
+ err error
+ }
+ envBundles := map[string]envRes{}
+ loadEnv := func(env string) envRes {
+ if e, done := envBundles[env]; done {
+ return e
+ }
+ m, found, err := getIfExistsAt(ctx, s, EnvironmentKey(acct, app, env))
+ e := envRes{m: m, found: found, err: err}
+ envBundles[env] = e
+ return e
+ }
+ for _, rt := range routes {
+ stamped := stampedForDelivery(rt)
+ if (!execAddrCandidate(rt) && !stamped) || rt.App != app || release.RouteAccount(rt) != acct {
+ continue
+ }
+ // Which routes a write REACHES. A named bundle is read by the
+ // routes bound to it and by nothing else. The default bundle is
+ // read by every route of the app, bound or not, because a named
+ // bundle is an overlay ON it (environments.go, LoadMerged) rather
+ // than a replacement for it.
+ if envName != "" && rt.Environment != envName {
+ continue
+ }
+ eb := envRes{}
+ def := loadDefault
+ if rt.Environment != "" {
+ eb = loadEnv(rt.Environment)
+ // An OWNED environment is standalone (team-scoped credentials
+ // §3): a default-bundle write reaches none of its routes, and
+ // its opt-in never inherits the default bundle's. Decided
+ // before the blocked notice, which is about routes the write
+ // reaches; a bundle that cannot be read decides nothing here.
+ if eb.err == nil && eb.found && eb.m.Owned() {
+ if envName == "" {
+ continue
+ }
+ def = standaloneDefault
+ }
+ }
+ // Blocked is decided before bundle resolution (spec §3.4): a route
+ // the root pass will refuse is reported as blocked, not as healthy
+ // and not as unresolved.
+ if reason, bad := blocked[rt.Host]; bad {
+ out.Blocked = append(out.Blocked, BlockedHost{Host: rt.Host, Reason: reason})
+ continue
+ }
+ if rt.Environment != "" {
+ if eb.err != nil {
+ out.Unresolved = append(out.Unresolved, rt.Host)
+ continue
+ }
+ // A route bound to a bundle that does not exist resolves to an
+ // ERROR, not to the app default: LoadMerged refuses it, and
+ // SyncExec leaves the route's file exactly as it was. Nothing
+ // was delivered, so "delivered" would be a lie — but neither
+ // is this route fine, so it is not a skip either.
+ if !eb.found {
+ out.Unresolved = append(out.Unresolved, rt.Host)
+ continue
+ }
+ }
+ v, err := resolveExecDelivery(eb.m, eb.found, def)
+ if err != nil {
+ out.Unresolved = append(out.Unresolved, rt.Host)
+ continue
+ }
+ // A stamped route is delivered and restarted by the root pass within
+ // seconds of this write; it has nothing to be told about unless a
+ // layer it is rendered from would not resolve. The bundles were
+ // checked above; the instance overlay is checked here, because the
+ // root pass loads it for a stamped route and refuses delivery when
+ // it will not read (sync.go; review round 1 P2-6).
+ if stamped {
+ // The default bundle is required by delivery whatever the
+ // exec-delivery opt-in says (round 2 P2-5: resolveExecDelivery
+ // returns before reading it when the environment sets
+ // exec_delivery explicitly); only an owned environment stands
+ // alone without it.
+ if def != nil && !(eb.found && eb.m != nil && eb.m.Owned()) {
+ if _, _, defErr := loadDefault(); defErr != nil {
+ out.Unresolved = append(out.Unresolved, rt.Host)
+ continue
+ }
+ }
+ if _, _, instErr := overlayFor(acct, app, rt.Host); instErr != nil {
+ out.Unresolved = append(out.Unresolved, rt.Host)
+ }
+ continue
+ }
+ // Not opted in — including the Unknown case, which decides "off" —
+ // means no pass delivers a file to this route: this write reached
+ // nothing here. Say so (spec §3.4, codex R1-9: "this write", not
+ // "no file" — an opted-out route may hold a file from before).
+ if !v.On {
+ out.Undelivered = append(out.Undelivered, rt.Host)
+ continue
+ }
+ // The shadowing test, and the reason keys is a parameter: where every
+ // touched key is shadowed, the merged manifest is byte-identical,
+ // syncExecHost's bytes.Equal writes nothing, and naming the route
+ // would send someone to restart a process for a value it was never
+ // going to see. An empty keys disables this whole test (nothing to
+ // shadow — see keys' own doc comment), so the instance layer is
+ // consulted only when it could actually change the verdict: a route
+ // whose overlay is unreadable must not be downgraded to Unresolved
+ // over a call that was never going to ask it anything.
+ if len(keys) > 0 {
+ // Which layers sit ABOVE the bundle that was written, for this
+ // route. A write cannot change what a route resolves to for a
+ // key some higher layer states, and the third layer sits above
+ // both of the other two.
+ inst, _, instErr := overlayFor(acct, app, rt.Host)
+ if instErr != nil {
+ out.Unresolved = append(out.Unresolved, rt.Host)
+ continue
+ }
+ var above []*Manifest
+ if envName == "" && rt.Environment != "" {
+ above = append(above, eb.m)
+ }
+ above = append(above, inst)
+ if allShadowed(keys, above...) {
+ continue
+ }
+ }
+ out.Hosts = append(out.Hosts, RestartHost{Host: rt.Host, Unit: rt.Unit})
+ }
+ // Sorted so a caller's output — and any test pinning it — is stable
+ // across passes, where registry order is not. Same discipline as
+ // ExecConfigApps'.
+ sort.Slice(out.Hosts, func(i, j int) bool { return out.Hosts[i].Host < out.Hosts[j].Host })
+ sort.Slice(out.Blocked, func(i, j int) bool { return out.Blocked[i].Host < out.Blocked[j].Host })
+ sort.Strings(out.Unresolved)
+ sort.Strings(out.Undelivered)
+ return out
+}
+
+// TestClassifyPendingMatchesTheLegacyNotice: over generated inputs,
+// overlapping shapes and failing reads included, Pending is the old notice.
+func TestClassifyPendingMatchesTheLegacyNotice(t *testing.T) {
+ ctx := context.Background()
+ worlds := map[bool]release.Store{}
+ for _, on := range []bool{true, false} {
+ _, worlds[on] = reachWorld(t, on, reachOverlays...)
+ }
+ r := rand.New(rand.NewPCG(20261108, 11))
+ for i := range 2000 {
+ c := genReachCase(r)
+ s := worlds[c.optIn]
+ if c.failKey != "" {
+ s = &failingKeyStore{Store: s, failKey: c.failKey, err: errors.New("503 slow down")}
+ }
+ got := ClassifyWrite(ctx, s, c.routes, c.facts, "bab", "relay", c.envName, c.keys).Pending()
+ want := legacyAwaitingRestart(ctx, s, c.routes, "bab", "relay", c.envName, c.keys)
+ if !reflect.DeepEqual(got, want) {
+ t.Fatalf("case %d: Pending = %+v, the legacy notice = %+v\nroutes %+v", i, got, want, c.routes)
+ }
+ }
+}
+
+// TestClassifySidecarWithAnAddrKeepsTheLegacyNotice (Astra P2-3): a sidecar
+// row carrying Addr or Addrs is a sidecar for delivery and an addr route
+// for the notice, as it always was.
+func TestClassifySidecarWithAnAddrKeepsTheLegacyNotice(t *testing.T) {
+ for _, tc := range []struct {
+ name string
+ optIn bool
+ env string
+ failKey string
+ pending RestartPending
+ want string
+ }{
+ {name: "opted in", optIn: true, pending: RestartPending{Hosts: []RestartHost{{Host: "bot.example.com"}}}, want: "yours"},
+ {name: "opted out", pending: RestartPending{Undelivered: []string{"bot.example.com"}}, want: "yours"},
+ {name: "missing bound bundle", optIn: true, env: "ghost", pending: RestartPending{Unresolved: []string{"bot.example.com"}}, want: "unresolved"},
+ {name: "default unreadable", optIn: true, failKey: Key("bab", "relay"), pending: RestartPending{Unresolved: []string{"bot.example.com"}}, want: "unresolved"},
+ } {
+ for _, field := range []string{"Addr", "Addrs"} {
+ t.Run(tc.name+"/"+field, func(t *testing.T) {
+ ctx, s := reachWorld(t, tc.optIn)
+ if tc.failKey != "" {
+ s = &failingKeyStore{Store: s, failKey: tc.failKey, err: errors.New("503 slow down")}
+ }
+ rt := reachRoute("sidecar", "bot.example.com", tc.env)
+ if field == "Addr" {
+ rt.Addr = "127.0.0.1:9003"
+ } else {
+ rt.Addrs = "127.0.0.1:9003"
+ }
+ w := ClassifyWrite(ctx, s, []registry.Route{rt}, ReachFacts{}, "bab", "relay", "", []string{"SHARED"})
+ if got := w.Pending(); !reflect.DeepEqual(got, tc.pending) {
+ t.Fatalf("Pending = %+v, want %+v", got, tc.pending)
+ }
+ if at, rh := reachWhere(t, w, rt.Host); at != tc.want || rh.Shape != ReachShapeSidecar {
+ t.Fatalf("classified %q shape %q, want %q as a sidecar", at, rh.Shape, tc.want)
+ }
+ })
+ }
+ }
+}
+
+// TestClassifyOwnedEnvironmentNeedsTheDefaultRead (Astra P2-1): both passes
+// read the default bundle before an owned one, so when it will not read the
+// route is Unresolved, not Self; the passes restart nothing.
+func TestClassifyOwnedEnvironmentNeedsTheDefaultRead(t *testing.T) {
+ ctx, s, reg, dd, priv, _ := execKit(t)
+ pk, err := ParsePrivateKey(priv, "test")
+ if err != nil {
+ t.Fatal(err)
+ }
+ if err := SetEnv(ctx, s, "bab", "relay", map[string]string{"SHARED": "d"}); err != nil {
+ t.Fatal(err)
+ }
+ if _, err := ApplyEnvironmentOwned(ctx, s, "bab", "relay", "team", "alta", map[string]Var{"TEAM_ONLY": {Kind: "env", Value: "one"}}, nil); err != nil {
+ t.Fatal(err)
+ }
+ routes := []registry.Route{reachRoute("unit", "un.example.com", "team"), reachRoute("socket", "so.example.com", "team"), reachRoute("stamped", "st.example.com", "team")}
+ for _, rt := range routes {
+ if err := reg.Upsert(rt); err != nil {
+ t.Fatal(err)
+ }
+ }
+ envDir := t.TempDir()
+ var restarted []string
+ record := func(h string) error { restarted = append(restarted, h); return nil }
+ pass := func(st release.Store) {
+ t.Helper()
+ if err := Sync(ctx, reg, st, pk, envDir, record, nil); err != nil {
+ t.Fatalf("Sync: %v", err)
+ }
+ if err := SyncExec(ctx, reg, st, pk, dd, record, "", nil); err != nil {
+ t.Fatalf("SyncExec: %v", err)
+ }
+ }
+ pass(s)
+ restarted = nil
+ if _, err := ApplyEnvironmentOwned(ctx, s, "bab", "relay", "team", "alta", map[string]Var{"TEAM_ONLY": {Kind: "env", Value: "two"}}, nil); err != nil {
+ t.Fatal(err)
+ }
+ blip := &failingKeyStore{Store: s, failKey: Key("bab", "relay"), err: errors.New("503 slow down")}
+ w := ClassifyWrite(ctx, blip, routes, ReachFacts{}, "bab", "relay", "team", []string{"TEAM_ONLY"})
+ for _, rt := range routes {
+ if at, _ := reachWhere(t, w, rt.Host); at != "unresolved" {
+ t.Fatalf("%s in %q, want unresolved: %+v", rt.Host, at, w)
+ }
+ }
+ // The notice keeps its old answer: a stamped route on an owned
+ // environment stands alone there.
+ if p, want := w.Pending(), legacyAwaitingRestart(ctx, blip, routes, "bab", "relay", "team", []string{"TEAM_ONLY"}); !reflect.DeepEqual(p, want) {
+ t.Fatalf("Pending = %+v, legacy = %+v", p, want)
+ }
+ pass(blip)
+ if len(restarted) != 0 {
+ t.Fatalf("the passes restarted %v with the default bundle unreadable", restarted)
+ }
+}
+
+// TestClassifyConfigNameCollision (Astra P2-2): the registry fixture of
+// TestSyncExecRefusesConfigNamespaceCollision, plus a managed sidecar in
+// the same position. SyncExec refuses both, so both are Unresolved, and the
+// pass neither bounces them nor reports their delivery.
+func TestClassifyConfigNameCollision(t *testing.T) {
+ ctx, s, reg, dd, priv, _ := execKit(t)
+ pk, err := ParsePrivateKey(priv, "test")
+ if err != nil {
+ t.Fatal(err)
+ }
+ if err := SetEnv(ctx, s, "bab", "eleven", map[string]string{"X": "1"}); err != nil {
+ t.Fatal(err)
+ }
+ if err := SetEnv(ctx, s, "bab", "titogo", map[string]string{"Y": "2"}); err != nil {
+ t.Fatal(err)
+ }
+ routes := []registry.Route{
+ {Host: "x", Kind: "instance", App: "eleven", Account: "bab", Status: "ready", Socket: "/run/carlos/x.sock"},
+ {Host: "x.config", Kind: "instance", App: "titogo", Account: "bab", Status: "ready", Socket: "/run/carlos/xc.sock"},
+ {Host: "y", Kind: "sidecar", App: "eleven", Account: "bab", Status: "ready"},
+ {Host: "y.config", Kind: "instance", App: "titogo", Account: "bab", Status: "ready", Socket: "/run/carlos/yc.sock"},
+ }
+ for _, rt := range routes {
+ if err := reg.Upsert(rt); err != nil {
+ t.Fatal(err)
+ }
+ }
+ w := ClassifyWrite(ctx, s, routes, ReachFacts{Hosts: map[string]HostFact{"y": {Managed: true}}}, "bab", "eleven", "", []string{"X"})
+ for _, h := range []string{"x", "y"} {
+ if at, _ := reachWhere(t, w, h); at != "unresolved" {
+ t.Fatalf("%s in %q, want unresolved: %+v", h, at, w)
+ }
+ }
+ if at, _ := reachWhere(t, w, "x.config"); at != "" {
+ t.Fatalf("another app's host x.config is in %q", at)
+ }
+ var bounced, delivered []string
+ cb := Callbacks{
+ Restart: func(h string) error { bounced = append(bounced, h); return nil },
+ Managed: func(rt registry.Route) bool { return rt.Host == "y" },
+ Unmanaged: func(h string) error { bounced = append(bounced, h); return nil },
+ Delivered: func(h, _ string) { delivered = append(delivered, h) },
+ }
+ if err := SyncExecWithCallbacks(ctx, reg, s, pk, dd, "", cb); err != nil {
+ t.Fatalf("SyncExec: %v", err)
+ }
+ for _, h := range []string{"x", "y"} {
+ if slices.Contains(bounced, h) || slices.Contains(delivered, h) {
+ t.Fatalf("bounced %v, delivered %v: %s was refused, not delivered", bounced, delivered, h)
+ }
+ }
+ // The control: the same pass did deliver the routes nothing collides
+ // with, so the absence above is the guard's and not a dead fixture.
+ if !slices.Contains(delivered, "x.config") && !slices.Contains(bounced, "x.config") {
+ t.Fatalf("x.config neither bounced nor delivered (bounced %v, delivered %v): the fixture proves nothing", bounced, delivered)
+ }
+}
+
+func reachShapeIsAddr(rt registry.Route) bool {
+ shape, ok := reachShape(rt)
+ return ok && shape == ReachShapeAddr
+}
diff --git a/internal/appconfig/syncexec.go b/internal/appconfig/syncexec.go
index 8f4b5653d..3098af7e4 100644
--- a/internal/appconfig/syncexec.go
+++ b/internal/appconfig/syncexec.go
@@ -141,10 +141,7 @@ func SyncExecWithCallbacks(ctx context.Context, reg *registry.Registry, s releas
// x.config itself may never reach syncExecHost. Built once: the guard
// runs once per in-scope route in the materialization loop, and every
// route's Host is fixed for the pass.
- hostSet := make(map[string]bool, len(routes))
- for _, rt := range routes {
- hostSet[rt.Host] = true
- }
+ hostSet := routeHostSet(routes)
type groupKey struct{ acct, app, env string }
// The same three states Sync resolves to, with this path's own file
// semantics for the middle one: a manifest to converge to; "never
@@ -588,7 +585,7 @@ func SyncExecWithCallbacks(ctx context.Context, reg *registry.Registry, s releas
// would write here. Refuse loudly rather than clobber another
// owner's file; see reapConfigEnv's twin guard for the
// deletion-side half of the same hazard.
- if hostSet[rt.Host+".config"] {
+ if configNameCollides(hostSet, rt.Host) {
fmt.Printf(" %s: not converging — route %q exists on this box and %s%s is its instance-env file (<host>.env); refusing to write into another owner's namespace\n", rt.Host, rt.Host+".config", rt.Host, configEnvSuffix)
continue
}
@@ -1199,6 +1196,24 @@ func allShadowed(keys []string, above ...*Manifest) bool {
return true
}
+// routeHostSet names every route's host, in or out of scope: the set the
+// config name collision guard is checked against.
+func routeHostSet(routes []registry.Route) map[string]bool {
+ hostSet := make(map[string]bool, len(routes))
+ for _, rt := range routes {
+ hostSet[rt.Host] = true
+ }
+ return hostSet
+}
+
+// configNameCollides reports whether converging host's exec config file
+// would write into another route's namespace: a route "<host>.config" has
+// an instance env named "<host>.config.env", the name host's own file
+// takes. SyncExec refuses such a route; ClassifyWrite reports it.
+func configNameCollides(hostSet map[string]bool, host string) bool {
+ return hostSet[host+".config"]
+}
+
// execAddrConfigHeader is prepended to a TCP-addr (issue #18) route's
// <host>.config.env — and ONLY that shape. RenderEnv itself stays
// header-free, deliberately: it is shared by sync.go's unit path AND this