region HA P3b T5: name hairpin configuration refusal causes
Keep the configuration sentinel and refusal conditions unchanged while naming each internal refusal site. Include bounded nft readback evidence for the diagnostic root-runner pass.
Co-Authored-By: GPT-6 Astra (codex) <noreply@openai.com>
internal/edge/hairpin.go+6 −5internal/hairpin/native_linux.go+19 −19internal/hairpin/native_linux_test.go+6 −1internal/hairpin/rules.go+12 −12internal/hairpin/snapshot.go+1 −1internal/host/claimstop_run.go+2 −1internal/host/group_hairpin.go+4 −3internal/instancectl/hairpin.go+6 −5
Intent
<task-notification> <task-id>bf1t09cw5</task-id> <tool-use-id>toolu_014hYt6gBX5bpUPB4JBeifgk</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/05c816f1-0a2d-43e3-9285-de8352549786/tasks/bf1t09cw5.output</output-file> <status>completed</status> <summary>Background command "D=/home/paulca/amadan.net/carlos/platform/.claude/worktrees/region-ha-p3b-build/.superpowers/sdd/2026-11-04-region-ha-p3b-group; $D/wait-astra.sh t5rl $D/task-5-report.md" completed (exit code 0)</summary> </task-notification>
Attributed to this commit: 5.56 g CO₂e (672,102 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on region-ha-p3b-build, 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/edge/hairpin.go b/internal/edge/hairpin.go| index 716a84bcc..6d9465b2f 100644 |
| --- a/internal/edge/hairpin.go |
| +++ b/internal/edge/hairpin.go |
| @@ -4,6 +4,7 @@ import ( |
| "context" |
| "crypto/tls" |
| "errors" |
| + "fmt" |
| "net" |
| "net/http" |
| "net/netip" |
| @@ -31,11 +32,11 @@ type hairpinListener struct { |
| func (h *hairpinIngress) classify(local, peer net.Addr) (string, error) { |
| dst, ok := local.(*net.TCPAddr) |
| if !ok { |
| - return "", hairpin.ErrConfig |
| + return "", fmt.Errorf("%w: local socket address is not TCP", hairpin.ErrConfig) |
| } |
| a, ok := netip.AddrFromSlice(dst.IP) |
| if !ok { |
| - return "", hairpin.ErrConfig |
| + return "", fmt.Errorf("%w: local socket IP invalid", hairpin.ErrConfig) |
| } |
| a = a.Unmap() |
| ingress := false |
| @@ -50,14 +51,14 @@ func (h *hairpinIngress) classify(local, peer net.Addr) (string, error) { |
| } |
| src, ok := peer.(*net.TCPAddr) |
| if !ok { |
| - return "", hairpin.ErrConfig |
| + return "", fmt.Errorf("%w: peer socket address is not TCP", hairpin.ErrConfig) |
| } |
| p, ok := netip.AddrFromSlice(src.IP) |
| if !ok || (!h.local[p.Unmap()] && !p.Unmap().IsLoopback()) || (dst.Port != 80 && dst.Port != 443) { |
| - return "", hairpin.ErrConfig |
| + return "", fmt.Errorf("%w: ingress peer or destination port invalid", hairpin.ErrConfig) |
| } |
| if !hairpin.PublicIPv4(h.config.PublicIPv4) { |
| - return "", hairpin.ErrConfig |
| + return "", fmt.Errorf("%w: derived public source invalid", hairpin.ErrConfig) |
| } |
| return h.config.PublicIPv4, nil |
| } |
diff --git a/internal/hairpin/native_linux.go b/internal/hairpin/native_linux.go| index 3f85f7eed..cc9b787c0 100644 |
| --- a/internal/hairpin/native_linux.go |
| +++ b/internal/hairpin/native_linux.go |
| @@ -24,7 +24,7 @@ import ( |
| func Identity(pid int) (Process, error) { |
| var p Process |
| if pid <= 0 { |
| - return p, ErrConfig |
| + return p, fmt.Errorf("%w: process PID invalid", ErrConfig) |
| } |
| b, err := os.ReadFile(fmt.Sprintf("/proc/%d/stat", pid)) |
| if err != nil { |
| @@ -33,11 +33,11 @@ func Identity(pid int) (Process, error) { |
| // comm may contain spaces and parentheses; starttime is field 22. |
| i := strings.LastIndexByte(string(b), ')') |
| if i < 0 { |
| - return p, ErrConfig |
| + return p, fmt.Errorf("%w: process stat has no closing comm delimiter", ErrConfig) |
| } |
| fields := strings.Fields(string(b[i+1:])) |
| if len(fields) < 20 { |
| - return p, ErrConfig |
| + return p, fmt.Errorf("%w: process stat lacks start time", ErrConfig) |
| } |
| if _, err := strconv.ParseUint(fields[19], 10, 64); err != nil { |
| return p, err |
| @@ -60,7 +60,7 @@ func Authenticate(ctx context.Context, conn net.Conn, p Process) error { |
| } |
| c, ok := conn.(*net.UnixConn) |
| if !ok { |
| - return ErrConfig |
| + return fmt.Errorf("%w: peer connection is not Unix", ErrConfig) |
| } |
| raw, err := c.SyscallConn() |
| if err != nil { |
| @@ -70,7 +70,7 @@ func Authenticate(ctx context.Context, conn net.Conn, p Process) error { |
| var inner error |
| err = raw.Control(func(fd uintptr) { cred, inner = unix.GetsockoptUcred(int(fd), unix.SOL_SOCKET, unix.SO_PEERCRED) }) |
| if err != nil || inner != nil || cred == nil || int(cred.Uid) != uid || int(cred.Pid) != p.PID { |
| - return ErrConfig |
| + return fmt.Errorf("%w: peer credentials unavailable or do not match agent", ErrConfig) |
| } |
| return Current(ctx, p) |
| } |
| @@ -90,7 +90,7 @@ func MainProcess(ctx context.Context) (Process, error) { |
| } |
| pid, err := strconv.Atoi(fields["MainPID"]) |
| if err != nil || pid < 0 { |
| - return Process{}, ErrConfig |
| + return Process{}, fmt.Errorf("%w: systemd MainPID invalid", ErrConfig) |
| } |
| if pid == 0 { |
| return Process{}, nil |
| @@ -100,7 +100,7 @@ func MainProcess(ctx context.Context) (Process, error) { |
| func Current(ctx context.Context, p Process) error { |
| now, err := MainProcess(ctx) |
| if err != nil || p.PID <= 0 || now != p { |
| - return ErrConfig |
| + return fmt.Errorf("%w: process is not the current agent", ErrConfig) |
| } |
| return nil |
| } |
| @@ -113,7 +113,7 @@ func Acquire(ctx context.Context) (*Lease, error) { |
| return nil, err |
| } |
| if _, ok := ctx.Deadline(); !ok { |
| - return nil, ErrConfig |
| + return nil, fmt.Errorf("%w: lock context has no deadline", ErrConfig) |
| } |
| if err := os.Mkdir(RuntimeDir, 0700); err != nil && !errors.Is(err, os.ErrExist) { |
| return nil, err |
| @@ -126,7 +126,7 @@ func Acquire(ctx context.Context) (*Lease, error) { |
| fail := func(err error) (*Lease, error) { f.Close(); return nil, err } |
| var st unix.Stat_t |
| if unix.Fstat(fd, &st) != nil || st.Uid != 0 || st.Mode&unix.S_IFMT != unix.S_IFREG || st.Mode&0777 != 0600 || st.Nlink != 1 { |
| - return fail(ErrConfig) |
| + return fail(fmt.Errorf("%w: lock metadata invalid", ErrConfig)) |
| } |
| // The protected directory is read through the file checker as well. |
| if _, err := hostenv.ReadGroupFile(RuntimeDir+"/lock", 0, 0600); err != nil { |
| @@ -154,7 +154,7 @@ func Acquire(ctx context.Context) (*Lease, error) { |
| return l, nil |
| } |
| if err != nil || json.Unmarshal(b, &l.State) != nil { |
| - return fail(ErrConfig) |
| + return fail(fmt.Errorf("%w: saved state unreadable or invalid", ErrConfig)) |
| } |
| return l, nil |
| } |
| @@ -229,7 +229,7 @@ func (l *Lease) Verify(ctx context.Context) error { |
| } |
| compact := func(s string) string { return strings.Join(strings.Fields(s), "") } |
| if compact(string(got)) != compact(want) { |
| - return ErrConfig |
| + return fmt.Errorf("%w: nft readback differs: got=%q want=%q", ErrConfig, string(got[:min(len(got), 8192)]), want) |
| } |
| return nil |
| } |
| @@ -253,7 +253,7 @@ func (l *Lease) Addresses(ctx context.Context, on bool) error { |
| if !on { |
| return nil |
| } |
| - return ErrConfig |
| + return fmt.Errorf("%w: address assignment requires dummy interface", ErrConfig) |
| } |
| if !on { |
| _, err = run(ctx, "", "ip", "-4", "addr", "flush", "dev", Interface) |
| @@ -265,7 +265,7 @@ func (l *Lease) Addresses(ctx context.Context, on bool) error { |
| for _, setting := range []struct{ name, value string }{{"arp_ignore", "1"}, {"arp_announce", "2"}} { |
| b, err := os.ReadFile(filepath.Join("/proc/sys/net/ipv4/conf/all", setting.name)) |
| if err != nil || strings.TrimSpace(string(b)) != setting.value { |
| - return ErrConfig |
| + return fmt.Errorf("%w: ARP suppression setting invalid", ErrConfig) |
| } |
| } |
| // No broader destination can reach the interface, even after a partial |
| @@ -296,7 +296,7 @@ func WatchExit(p Process, exited func()) (func(), error) { |
| now, err := Identity(p.PID) |
| if err != nil || now != p { |
| unix.Close(fd) |
| - return nil, ErrConfig |
| + return nil, fmt.Errorf("%w: process identity changed while opening pidfd", ErrConfig) |
| } |
| stopR, stopW, err := os.Pipe() |
| if err != nil { |
| @@ -361,17 +361,17 @@ func (l *Lease) CheckAddresses(ctx context.Context, on bool) error { |
| } `json:"addr_info"` |
| } |
| if json.Unmarshal(raw, &links) != nil || len(links) != 1 { |
| - return ErrConfig |
| + return fmt.Errorf("%w: address inventory invalid", ErrConfig) |
| } |
| seen := map[string]bool{} |
| for _, a := range links[0].Addrs { |
| if !on || a.Prefix != 32 || !slices.Contains(l.Config.PublicIPs, a.Local) || seen[a.Local] { |
| - return ErrConfig |
| + return fmt.Errorf("%w: address inventory contains unexpected or duplicate entry", ErrConfig) |
| } |
| seen[a.Local] = true |
| } |
| if on && len(seen) != len(l.Config.PublicIPs) { |
| - return ErrConfig |
| + return fmt.Errorf("%w: address inventory missing ingress entries", ErrConfig) |
| } |
| return nil |
| } |
| @@ -388,13 +388,13 @@ func (l *Lease) dummyPresent(ctx context.Context) (bool, error) { |
| } `json:"linkinfo"` |
| } |
| if json.Unmarshal(raw, &links) != nil { |
| - return false, ErrConfig |
| + return false, fmt.Errorf("%w: link inventory invalid", ErrConfig) |
| } |
| found := false |
| for _, link := range links { |
| if link.Name == Interface { |
| if link.LinkInfo.Kind != "dummy" { |
| - return false, ErrConfig |
| + return false, fmt.Errorf("%w: hairpin interface is not dummy", ErrConfig) |
| } |
| found = true |
| } |
diff --git a/internal/hairpin/native_linux_test.go b/internal/hairpin/native_linux_test.go| index 656e79f80..b63ce6b22 100644 |
| --- a/internal/hairpin/native_linux_test.go |
| +++ b/internal/hairpin/native_linux_test.go |
| @@ -4,6 +4,7 @@ package hairpin |
| import ( |
| "context" |
| + "errors" |
| "os" |
| "path/filepath" |
| "strings" |
| @@ -35,9 +36,13 @@ func TestHairpinFenceReadback(t *testing.T) { |
| t.Fatal(err) |
| } |
| l := &Lease{Config: c} |
| - if err := l.Verify(context.Background()); (err == nil) != tc.ok { |
| + err := l.Verify(context.Background()) |
| + if (err == nil) != tc.ok { |
| t.Fatalf("readback %s: %v", tc.name, err) |
| } |
| + if !tc.ok && (!errors.Is(err, ErrConfig) || !strings.Contains(err.Error(), "nft readback differs") || !strings.Contains(err.Error(), "got=")) { |
| + t.Fatalf("readback refusal lost cause or evidence: %v", err) |
| + } |
| }) |
| } |
| } |
diff --git a/internal/hairpin/rules.go b/internal/hairpin/rules.go| index e8c707bba..c28d1708b 100644 |
| --- a/internal/hairpin/rules.go |
| +++ b/internal/hairpin/rules.go |
| @@ -63,20 +63,20 @@ func PublicIPv4(s string) bool { |
| func (c Config) Validate() error { |
| if c.V != 1 || !regionCode.MatchString(c.Region) || !bootID.MatchString(c.BootID) || !accountID.MatchString(c.Account) || !instanceID.MatchString(c.InstanceID) || !PublicIPv4(c.PublicIPv4) || len(c.PublicIPs) < 1 || len(c.PublicIPs) > 16 { |
| - return ErrConfig |
| + return fmt.Errorf("%w: snapshot identity, version, public source or ingress count invalid", ErrConfig) |
| } |
| primary, err := netip.ParseAddr(c.PrimaryIPv4) |
| if err != nil || !primary.Is4() || !primary.IsPrivate() || primary.String() != c.PrimaryIPv4 { |
| - return ErrConfig |
| + return fmt.Errorf("%w: primary IPv4 invalid", ErrConfig) |
| } |
| cidr, err := netip.ParsePrefix(c.PrivateCIDR) |
| if err != nil || !cidr.Addr().Is4() || !cidr.Addr().IsPrivate() || cidr.Masked().String() != c.PrivateCIDR || !cidr.Contains(primary) { |
| - return ErrConfig |
| + return fmt.Errorf("%w: private CIDR invalid", ErrConfig) |
| } |
| seen := map[string]bool{} |
| for _, ip := range c.PublicIPs { |
| if !PublicIPv4(ip) || seen[ip] || ip == c.PublicIPv4 { |
| - return ErrConfig |
| + return fmt.Errorf("%w: ingress IPv4 invalid, duplicate or equal to source", ErrConfig) |
| } |
| seen[ip] = true |
| } |
| @@ -88,37 +88,37 @@ func (c Config) Validate() error { |
| func Parse(raw []byte, region, boot, account, iid string) (Config, error) { |
| var c Config |
| if len(raw) > 65536 { |
| - return c, ErrConfig |
| + return c, fmt.Errorf("%w: snapshot exceeds size limit", ErrConfig) |
| } |
| d := json.NewDecoder(bytes.NewReader(raw)) |
| tok, err := d.Token() |
| if err != nil || tok != json.Delim('{') { |
| - return c, ErrConfig |
| + return c, fmt.Errorf("%w: snapshot is not a JSON object", ErrConfig) |
| } |
| keys := map[string]bool{} |
| for d.More() { |
| tok, err := d.Token() |
| if err != nil { |
| - return c, ErrConfig |
| + return c, fmt.Errorf("%w: snapshot key cannot be decoded", ErrConfig) |
| } |
| key, ok := tok.(string) |
| if !ok || keys[key] || !slices.Contains([]string{"v", "region", "public_ips", "public_ipv4", "primary_ipv4", "private_cidr", "boot_id", "account", "iid"}, key) { |
| - return c, ErrConfig |
| + return c, fmt.Errorf("%w: snapshot key invalid or repeated", ErrConfig) |
| } |
| keys[key] = true |
| var value json.RawMessage |
| if d.Decode(&value) != nil || bytes.Equal(value, []byte("null")) { |
| - return c, ErrConfig |
| + return c, fmt.Errorf("%w: snapshot value invalid or null", ErrConfig) |
| } |
| } |
| if _, err := d.Token(); err != nil || len(keys) != 9 { |
| - return c, ErrConfig |
| + return c, fmt.Errorf("%w: snapshot closing token or key count invalid", ErrConfig) |
| } |
| if d.Decode(new(any)) != io.EOF || json.Unmarshal(raw, &c) != nil { |
| - return c, ErrConfig |
| + return c, fmt.Errorf("%w: snapshot trailing data or field type invalid", ErrConfig) |
| } |
| if c.Region != region || c.BootID != boot || c.Account != account || c.InstanceID != iid { |
| - return c, ErrConfig |
| + return c, fmt.Errorf("%w: snapshot does not match group identity", ErrConfig) |
| } |
| return c, c.Validate() |
| } |
diff --git a/internal/hairpin/snapshot.go b/internal/hairpin/snapshot.go| index 990f527ea..09122ea90 100644 |
| --- a/internal/hairpin/snapshot.go |
| +++ b/internal/hairpin/snapshot.go |
| @@ -26,7 +26,7 @@ func loadGroupIdentity() (*hostenv.GroupConfig, error) { |
| } |
| boot, err := os.ReadFile("/proc/sys/kernel/random/boot_id") |
| if err != nil || g.BootID != strings.TrimSpace(string(boot)) { |
| - return nil, ErrConfig |
| + return nil, fmt.Errorf("%w: group marker boot identity unavailable or mismatched", ErrConfig) |
| } |
| identity, err := hostenv.ReadGroupFile("/etc/carlos/group-identity.json", 0, 0644) |
| if err != nil { |
diff --git a/internal/host/claimstop_run.go b/internal/host/claimstop_run.go| index 49563ed6c..ed7b30a55 100644 |
| --- a/internal/host/claimstop_run.go |
| +++ b/internal/host/claimstop_run.go |
| @@ -2,6 +2,7 @@ package host |
| import ( |
| "context" |
| + "fmt" |
| "log" |
| "net/http" |
| "os" |
| @@ -22,7 +23,7 @@ import ( |
| func RunInstanceControl(args []string) { |
| if len(args) == 1 && args[0] == "--group-hairpin-verify-identity" { |
| if os.Geteuid() != 0 { |
| - log.Fatal(hairpin.ErrConfig) |
| + log.Fatal(fmt.Errorf("%w: identity verification requires root", hairpin.ErrConfig)) |
| } |
| if err := hairpin.VerifyIdentity(); err != nil { |
| log.Fatal(err) |
diff --git a/internal/host/group_hairpin.go b/internal/host/group_hairpin.go| index 5396dc75f..ea3ad27dc 100644 |
| --- a/internal/host/group_hairpin.go |
| +++ b/internal/host/group_hairpin.go |
| @@ -2,6 +2,7 @@ package host |
| import ( |
| "context" |
| + "fmt" |
| "os" |
| "time" |
| @@ -16,13 +17,13 @@ func groupHairpinSnapshot() (*hairpin.Config, error) { |
| return nil, err |
| } |
| if v := os.Getenv("CARLOS_PUBLIC_IP"); v != "" && v != c.PublicIPv4 { |
| - return nil, hairpin.ErrConfig |
| + return nil, fmt.Errorf("%w: public IPv4 override conflicts with snapshot", hairpin.ErrConfig) |
| } |
| if v := os.Getenv("CARLOS_PRIVATE_IP"); v != "" && v != c.PrimaryIPv4 { |
| - return nil, hairpin.ErrConfig |
| + return nil, fmt.Errorf("%w: primary IPv4 override conflicts with snapshot", hairpin.ErrConfig) |
| } |
| if v := os.Getenv("CARLOS_PRIVATE_CIDR"); v != "" && v != c.PrivateCIDR { |
| - return nil, hairpin.ErrConfig |
| + return nil, fmt.Errorf("%w: private CIDR override conflicts with snapshot", hairpin.ErrConfig) |
| } |
| return c, nil |
| } |
diff --git a/internal/instancectl/hairpin.go b/internal/instancectl/hairpin.go| index f6c75b425..f22fe2c08 100644 |
| --- a/internal/instancectl/hairpin.go |
| +++ b/internal/instancectl/hairpin.go |
| @@ -5,6 +5,7 @@ import ( |
| "context" |
| "encoding/json" |
| "errors" |
| + "fmt" |
| "io" |
| "net/http" |
| "net/netip" |
| @@ -165,7 +166,7 @@ func (s *Server) hairpinExited(p hairpin.Process) { |
| // may subsequently enable. The group-only reset unit also runs after a crash. |
| func ClearGroupHairpin(ctx context.Context) error { |
| if os.Geteuid() != 0 { |
| - return hairpin.ErrConfig |
| + return fmt.Errorf("%w: hairpin reset requires root", hairpin.ErrConfig) |
| } |
| s := &Server{LocalAddrs: LocalAddresses, Systemctl: func(ctx context.Context, args ...string) (string, error) { |
| out, err := exec.CommandContext(ctx, "systemctl", args...).CombinedOutput() |
| @@ -239,7 +240,7 @@ func (s *Server) resumeGroupHairpin(ctx context.Context) error { |
| // A saved state requires reset/maintenance, never another initial install. |
| func InstallDormantGroupHairpin(ctx context.Context) error { |
| if os.Geteuid() != 0 { |
| - return hairpin.ErrConfig |
| + return fmt.Errorf("%w: dormant install requires root", hairpin.ErrConfig) |
| } |
| ctx, unlock, err := hairpinLocked(ctx) |
| if err != nil { |
| @@ -248,13 +249,13 @@ func InstallDormantGroupHairpin(ctx context.Context) error { |
| defer unlock() |
| l, ok := ctx.Value(hairpinLeaseKey{}).(*hairpin.Lease) |
| if !ok { |
| - return hairpin.ErrConfig |
| + return fmt.Errorf("%w: dormant install has no group lease", hairpin.ErrConfig) |
| } |
| if l.State != (hairpin.State{}) { |
| - return hairpin.ErrConfig |
| + return fmt.Errorf("%w: dormant install found saved state", hairpin.ErrConfig) |
| } |
| if current, err := hairpin.MainProcess(ctx); err != nil || current.PID != 0 { |
| - return hairpin.ErrConfig |
| + return fmt.Errorf("%w: dormant install agent lookup failed or agent exists", hairpin.ErrConfig) |
| } |
| if err := l.Prepare(ctx); err != nil { |
| return err |