carlos / platform Public

host: ingress drain witness names why admission waits; first write only

Fix round 2 for the W6 task 9 root-runner witness.

The fixture's agent watches the termination consumer and says once in
the journal whether it started, was never armed, or is armed and stuck,
with the departure goroutines' stacks; the test fails at once on the
negative lines. A non-root rootrunner test proves the agent's
armHADepartures call shape starts the consumer on the fixture queue seam.

The request loop records only the first successful write as dispatch
evidence, so a retry after step 3 cannot hide a failure; two new
classification cases cover it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev c12bfce9867a6b2033c66882c85389bf9c7905cf parent 7db08cb
1 file changed, +136 −13
  • internal/host/ingressdrain_rootrunner_linux_test.go +136 −13

Intent

Human

<task-notification> <task-id>a14f56a7ddada51be</task-id> <tool-use-id>toolu_01LScvv4skkxZBjVJKtkHZnt</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/a373aecd-faa9-4b83-8736-ff726fb2d3af/tasks/a14f56a7ddada51be.output</output-file> <status>completed</status> <summary>Agent "Implement W6 Task 9 (root runner)" 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_WITH_CONCERNS. Review findings 2 to 4 are fixed and the fixture's termination queue is supplied, but whether fixed admission now opens will only be known from your rerun. Finding 1 is unchanged, per ruling 20. Commits: 7db08cb4 "host: ingress drain witness keeps every request, opens fixed admission", on top of c82c1f6f. Build/vet: linux/arm64 rootrunner test binary builds (deleted after); `go vet -tags rootrunner` is clean on linux/arm64 and the host; plain `go vet ./internal/host/` is clean; `go build ./...` passes for linux, darwin and windows; the new `TestIngressRootLoopClassify` passes, and so do the Departure tests in `./internal/host/`. Fixes: - **2:** stopping the loop now stops new requests only, then waits up to 45 s for every request already sent. One still outstanding at that point counts as a failure. The reboot capture uses the same path. - **3:** the blanket 50 ms exclusion is gone. Any failure that ended before step 3 counts. A request spanning step 3 counts if the client had finished writing it before step 3 (taken from `httptrace`). Only the spec §3 case, a request not fully written by step 3, is left out. - **4:** response bodies are read to EOF, capped at 4 KiB, with the error checked. - **Admission:** "TerminationStarted" waits for the termination consumer's first receive from its SQS queue, which the runner cannot reach. A rootrunner-tagged seam (`departure_queue_rootrunner.go`, used from `agent.go`) lets the fixture's agent supply an empty queue; production builds pass nil and behave as before. The tests now fail within 90 s if admission does not open, naming the last waiting line. Concerns: - "hosting" should follow once the other admission facts are in. If a health condition still fails in the fixture, the 90 s check will name it on your rerun. - `agent.go` changed by one argument, so production code is touched, though only through the build-tagged seam. Report (fix section appended): /home/paulca/amadan.net/carlos/platform/.claude/worktrees/w6-build/.superpowers/sdd/2026-11-10-fixed-edge-ingress-drain/task-9-report.md</result> <usage><subagent_tokens>256877</subagent_tokens><tool_uses>15</tool_uses><duration_ms>832108</duration_ms></usage> </task-notification>

Human

<task-notification> <task-id>bp84d83ko</task-id> <tool-use-id>toolu_017JZ4oTb1eSR628JAPJYruR</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/a373aecd-faa9-4b83-8736-ff726fb2d3af/tasks/bp84d83ko.output</output-file> <status>completed</status> <summary>Background command "Wait for Restart rerun result" completed (exit code 0)</summary> </task-notification>

Attributed to this commit: 36.9 g CO₂e (4,609,766 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on w6-ingress-drain, 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/host/ingressdrain_rootrunner_linux_test.go b/internal/host/ingressdrain_rootrunner_linux_test.go
index adb71a6d6..a97ef12f3 100644
--- a/internal/host/ingressdrain_rootrunner_linux_test.go
+++ b/internal/host/ingressdrain_rootrunner_linux_test.go
@@ -42,6 +42,7 @@ import (
"os/exec"
"os/signal"
"path/filepath"
+ "runtime"
"slices"
"sort"
"strconv"
@@ -54,6 +55,7 @@ import (
"github.com/carlosframework/platform/internal/hadeparture"
"github.com/carlosframework/platform/internal/ingresshealth"
+ "github.com/carlosframework/platform/internal/lease"
)
const (
@@ -135,13 +137,70 @@ func (ingressRootQueue) Delete(context.Context, string) error { return nil }
// rootrunner-tagged seam supplies an empty queue. The consumer's journal and
// proof-store checks still run against the fixture's stores.
func ingressRootArmFake() {
- rootrunnerDepartureQueue = func(context.Context) (hadeparture.Queue, error) { return ingressRootQueue{}, nil }
+ var asked atomic.Int64
+ rootrunnerDepartureQueue = func(context.Context) (hadeparture.Queue, error) {
+ if asked.Add(1) == 1 {
+ log.Printf("ingress root fixture: termination queue asked for; answering an empty queue")
+ }
+ return ingressRootQueue{}, nil
+ }
+ go ingressRootWatchDepartures(time.Now(), &asked)
newIngressReader = func(_ context.Context, region string, groups []string) (ingresshealth.Reader, error) {
log.Printf("ingress root fixture: fake target health for %d group(s) in %s: healthy until %s from now, then unhealthy", len(groups), region, ingressRootUnhealthyAfter)
return &ingressRootFake{start: time.Now(), groups: groups}, nil
}
}
+// ingressRootDepartureBound is how long after the agent's start the
+// termination consumer has to start (fixed admission's TerminationStarted).
+// Arming waits for the activator, about 30 s in on the runner.
+const ingressRootDepartureBound = 75 * time.Second
+
+// ingressRootWatchDepartures runs in the agent process and says, once, in
+// the journal whether the termination consumer started, and if not why:
+// never armed (armHADepartures stored no controller), or armed and not
+// started (its last notice, and whether it got as far as the queue). The
+// test fails at once on the negative lines.
+func ingressRootWatchDepartures(began time.Time, asked *atomic.Int64) {
+ for {
+ c := metricsDepartures.Load()
+ if c != nil {
+ select {
+ case <-c.consumer.Started():
+ log.Printf("ingress root fixture: termination consumer started")
+ return
+ default:
+ }
+ }
+ if time.Since(began) > ingressRootDepartureBound {
+ if c == nil {
+ log.Printf("ingress root fixture: termination consumer never armed: no departure controller after %s (CARLOS_REGION_HA=%q, self %+v)", ingressRootDepartureBound, os.Getenv("CARLOS_REGION_HA"), lease.CurrentSelf())
+ return
+ }
+ c.telemetry.mu.Lock()
+ notice := c.telemetry.sample.Error
+ c.telemetry.mu.Unlock()
+ // The consumer logs every failed start; silence means a call that
+ // never returned. Its goroutines' stacks name the call.
+ stacks := make([]byte, 4<<20)
+ stacks = stacks[:runtime.Stack(stacks, true)]
+ var keep []string
+ for _, g := range strings.Split(string(stacks), "\n\n") {
+ if strings.Contains(g, "hadeparture") || strings.Contains(g, "departure") {
+ keep = append(keep, g)
+ }
+ }
+ dump := strings.Join(keep, "\n\n")
+ if len(dump) > 16<<10 {
+ dump = dump[:16<<10]
+ }
+ log.Printf("ingress root fixture: termination consumer armed but not started after %s: last notice %q, queue asked %d time(s), running %t; departure goroutines:\n%s", ingressRootDepartureBound, notice, asked.Load(), c.consumer.Running(), dump)
+ return
+ }
+ time.Sleep(time.Second)
+ }
+}
+
// ingressRootEnv arms the drain in the fixture's host.env (spec §4.1): a
// fixed box (tenant admission the fixed kind), region HA on (the fixture
// already sets it), and target groups in the runner's own account and
@@ -256,7 +315,7 @@ func (x *ingressRootFixture) awaitServing(why string, since time.Time) {
// start), naming the admission's last waiting line.
func ingressRootAwaitAdmission(t *testing.T, why string, since time.Time) {
t.Helper()
- deadline := time.Now().Add(90 * time.Second)
+ deadline := time.Now().Add(ingressRootDepartureBound + 45*time.Second)
for {
args := []string{"-b", "--no-pager", "-o", "cat", "-u", ingressRootEdgeUnit}
if !since.IsZero() {
@@ -272,13 +331,17 @@ func ingressRootAwaitAdmission(t *testing.T, why string, since time.Time) {
open = false
case strings.Contains(l, "tenant admission is still closed") || strings.Contains(l, "tenant admission is closed."):
waiting = l
+ case strings.Contains(l, "ingress root fixture: termination consumer never armed") || strings.Contains(l, "ingress root fixture: termination consumer armed but not started"):
+ // The line is followed by the consumer's goroutine stacks.
+ tail, _ := exec.Command("journalctl", "-b", "--no-pager", "-o", "cat", "-u", ingressRootEdgeUnit, "-n", "300").CombinedOutput()
+ t.Fatalf("%s: fixed admission cannot open: %s\n%s\nedge journal tail:\n%s", why, l, ingressRootAdmissionLog(), tail)
}
}
if open {
return
}
if time.Now().After(deadline) {
- t.Fatalf("%s: fixed admission did not open within 90 s; last: %q\n%s", why, waiting, ingressRootAdmissionLog())
+ t.Fatalf("%s: fixed admission did not open within %s; last: %q\n%s", why, ingressRootDepartureBound+45*time.Second, waiting, ingressRootAdmissionLog())
}
time.Sleep(time.Second)
}
@@ -288,7 +351,7 @@ func ingressRootAdmissionLog() string {
out, _ := exec.Command("journalctl", "-b", "--no-pager", "-u", ingressRootEdgeUnit, "-n", "400").CombinedOutput()
var keep []string
for _, l := range strings.Split(string(out), "\n") {
- if strings.Contains(l, "admission") || strings.Contains(l, "ingress") || strings.Contains(l, "change index") || strings.Contains(l, "role") {
+ if strings.Contains(l, "admission") || strings.Contains(l, "ingress") || strings.Contains(l, "change index") || strings.Contains(l, "role") || strings.Contains(l, "Termination") || strings.Contains(l, "departure") {
keep = append(keep, l)
}
}
@@ -349,8 +412,11 @@ func ingressRootKeys(m map[string]bool) []string {
}
// IngressRootSample is one request of the loop. Wrote is when the client
-// finished writing the request (httptrace WroteRequest): the dispatch
-// evidence for a request that spans step 3. Unfinished marks a request
+// first finished writing the request without error (httptrace
+// WroteRequest): the dispatch evidence for a request that spans step 3.
+// Client write completion is the closest observable to the server's
+// dispatch that this process has; the server's own read is not visible
+// from here. Unfinished marks a request
// still outstanding when the loop's bounded wait ran out.
type IngressRootSample struct {
Start time.Time `json:"start"`
@@ -402,6 +468,16 @@ type ingressRootFlight struct {
wrote atomic.Int64
}
+// noteWrote keeps the first successful write only. A failed write sets
+// nothing, and a later write (the transport's retry on a new connection,
+// which may come after step 3) never replaces an earlier one, so a
+// request written before step 3 stays counted whatever its retry did.
+func (f *ingressRootFlight) noteWrote(info httptrace.WroteRequestInfo, at time.Time) {
+ if info.Err == nil {
+ f.wrote.CompareAndSwap(0, at.UnixNano())
+ }
+}
+
func (f *ingressRootFlight) wroteAt() time.Time {
if ns := f.wrote.Load(); ns != 0 {
return time.Unix(0, ns)
@@ -432,7 +508,7 @@ func (x *ingressRootFixture) startLoop() *ingressRootLoop {
l.mu.Lock()
l.inflight[w] = f
l.mu.Unlock()
- trace := &httptrace.ClientTrace{WroteRequest: func(httptrace.WroteRequestInfo) { f.wrote.Store(time.Now().UnixNano()) }}
+ trace := &httptrace.ClientTrace{WroteRequest: func(info httptrace.WroteRequestInfo) { f.noteWrote(info, time.Now()) }}
// Not the stop's context: a request already sent runs to
// its answer or the client's timeout.
req := x.request.Clone(httptrace.WithClientTrace(context.Background(), trace))
@@ -487,10 +563,10 @@ func (l *ingressRootLoop) finish() []IngressRootSample {
// - a request that ended before step 3 must have succeeded, whatever it
// met (a 503, a reset);
// - a request that started before step 3 and ended after it, or never
-// ended, must have succeeded if the client had finished writing it
-// before step 3: it was the box's to answer (§3). One not fully
-// written by then is the incomplete-header case §3 leaves out, and is
-// only logged;
+// ended, must have succeeded if the client had first finished writing
+// it without error before step 3: it was the box's to answer (§3). Only
+// one with no successful write before step 3 is the incomplete-header
+// case §3 leaves out, and is only logged;
// - a request that started at or after step 3 is not counted.
//
// Requests must also have been served during the drain, with
@@ -951,11 +1027,58 @@ func TestIngressRootLoopClassify(t *testing.T) {
// Started after step 3: not counted.
{Start: at(time.Second), End: at(2 * time.Second), Detail: "refused"},
}
+ // Written before step 3, then retried after it: the first successful
+ // write stands, so the failure counts.
+ var f ingressRootFlight
+ f.noteWrote(httptrace.WroteRequestInfo{Err: errors.New("broken pipe")}, at(-3*time.Second))
+ f.noteWrote(httptrace.WroteRequestInfo{}, at(-2*time.Second))
+ f.noteWrote(httptrace.WroteRequestInfo{}, at(time.Second))
+ if !f.wroteAt().Equal(at(-2 * time.Second)) {
+ t.Fatalf("first successful write: %s", f.wroteAt())
+ }
+ samples = append(samples, IngressRootSample{Start: at(-3 * time.Second), Wrote: f.wroteAt(), End: at(2 * time.Second), Detail: "retried"})
+ // Only failed writes before step 3: §3's exclusion.
+ var g ingressRootFlight
+ g.noteWrote(httptrace.WroteRequestInfo{Err: errors.New("reset")}, at(-time.Millisecond))
+ samples = append(samples, IngressRootSample{Start: at(-2 * time.Millisecond), Wrote: g.wroteAt(), End: at(time.Millisecond), Detail: "write failed"})
c := classifyIngressRootLoop(samples, step1, step3)
- if len(c.failed) != 3 || c.failed[0].Detail != "503" || c.failed[1].Detail != "reset" || !c.failed[2].Unfinished {
+ if len(c.failed) != 4 || c.failed[0].Detail != "503" || c.failed[1].Detail != "reset" || !c.failed[2].Unfinished || c.failed[3].Detail != "retried" {
t.Fatalf("failed: %+v", c.failed)
}
- if len(c.excluded) != 2 || c.before != 1 || c.during != 1 || c.closing != 1 {
+ if len(c.excluded) != 3 || c.before != 1 || c.during != 1 || c.closing != 1 {
t.Fatalf("counts: %+v", c)
}
}
+
+// The agent's departure wiring with the fixture's queue seam, without
+// root: the same armHADepartures call shape the agent makes (MakeQueue from
+// fixtureDepartureQueue under the rootrunner tag) starts the consumer, so
+// fixed admission's TerminationStarted can arrive.
+func TestIngressRootDepartureSeam(t *testing.T) {
+ saved, savedC := rootrunnerDepartureQueue, metricsDepartures.Load()
+ t.Cleanup(func() { rootrunnerDepartureQueue = saved; metricsDepartures.Store(savedC) })
+ if fixtureDepartureQueue() != nil && saved == nil {
+ t.Fatal("seam set before the fixture armed it")
+ }
+ rootrunnerDepartureQueue = func(context.Context) (hadeparture.Queue, error) { return ingressRootQueue{}, nil }
+ a, _, _ := departureArmFixture(t)
+ a.MakeQueue = fixtureDepartureQueue()
+ if a.MakeQueue == nil {
+ t.Fatal("the rootrunner build's seam returned no queue")
+ }
+ ctx, cancel := context.WithCancel(t.Context())
+ defer cancel()
+ c, life, err := armHADepartures(ctx, a)
+ if err != nil || c == nil || life == nil {
+ t.Fatalf("arm: %v %v %v", c, life, err)
+ }
+ defer life.Stop(t.Context())
+ if metricsDepartures.Load() != c {
+ t.Fatal("controller not published for the fixture's watcher")
+ }
+ select {
+ case <-life.Started():
+ case <-time.After(5 * time.Second):
+ t.Fatal("the termination consumer did not start on the fixture queue")
+ }
+}