carlos / platform Public

edge: step 3 ends with its context; no public server is an error

CloseIngress now joins the requests it cut within the caller's context as
well as drainJoinBound, so the driver's absolute step-3 deadline holds
(W6 final review F1). With no public server registered (dev mode's plain
HTTP listener) it closes nothing and returns ErrNoPublicListeners instead
of reporting the listeners closed (F7).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev f25e10c6a8be4f7c4b6753ea2e05807265dfd7dd parent 697a58a
2 files changed, +57 −3
  • internal/edge/ingressdrain.go +15 −3
  • internal/edge/ingressdrain_test.go +42 −0

Intent

Human

<task-notification> <task-id>a14f56a7ddada51be</task-id> <tool-use-id>toolu_01LBAfcPbsVgadspYM7R2vbg</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. Option 1 is in, so the fixture's departure controller can now start, but whether fixed admission opens is unproven until your runner rerun. Commits: 697a58ab "host: departure controller sees a stand-in bucket in the root fixture". Build/vet: the linux/arm64 rootrunner test binary builds (deleted after). `go vet` is clean with and without the rootrunner tag. `go build ./...` passes for linux, darwin and windows. `TestIngressRootLoopClassify`, `TestIngressRootDepartureSeam` and the Departure/Termination tests in `./internal/host/` pass. What changed: - **`agent.go`:** in the departure arming call, `Getenv: os.Getenv` is now `Getenv: fixtureDepartureGetenv()`, plus an updated comment. The staged diff of `agent.go` contains only that hunk. - **Seam files:** the `!rootrunner` version returns `os.Getenv`, so production is unchanged. The rootrunner version fills in the stand-in bucket only when the fixture sets one and the real value is empty; only the departure controller reads through it, and the agent keeps its directory store. - **Fixture:** sets the stand-in to the fixture's control bucket, `deployment`, before the agent clears `CARLOS_DEPLOYMENT_BUCKET`. - **Unit check:** `TestIngressRootDepartureSeam` shows the controller refusing without a bucket, the seam passing the environment through untouched when unarmed, and, with the agent's call shape, the controller built and the consumer at its first receive ("Termination recovery is running."). Concerns: - The "hosting" condition has never been reached on the runner. If it still blocks admission, the 120 s check will name it. - The other agent's uncommitted `internal/edge/ingressdrain.go` and `ingressdrain_test.go` changes are still in the worktree; I left them out of the commit and untouched. Report (round 3 continuation 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>318528</subagent_tokens><tool_uses>13</tool_uses><duration_ms>728709</duration_ms></usage> </task-notification>

diff --git a/internal/edge/ingressdrain.go b/internal/edge/ingressdrain.go
index 319eed315..6134455d2 100644
--- a/internal/edge/ingressdrain.go
+++ b/internal/edge/ingressdrain.go
@@ -25,6 +25,12 @@ var ErrConnectionDrainOn = errors.New("ingress drain: a region HA connection dra
// drain is on.
var ErrIngressDrainOn = errors.New("connection drain: an ingress drain is on")
+// ErrNoPublicListeners is step 3 on an edge with no public server
+// registered: dev mode's plain HTTP listener is not one, so there is
+// nothing for the ingress drain to close, and it must not report the
+// listeners closed.
+var ErrNoPublicListeners = errors.New("ingress drain: no public listener is registered (dev mode's plain HTTP listener is not drained)")
+
// IngressClose is what step 3 did, for the drain's report.
type IngressClose struct {
// HeldClosed: edge-held streams closed at the start of the wait.
@@ -104,10 +110,13 @@ func (e *Edge) publicServers(https, challenge http.Handler, tlsCfg *tls.Config,
// 4. At the bound, or when ctx ends, what is still running on either
// listener is cancelled and its connection closed, as DrainConnections
// does, and both servers are closed; then the cut requests are joined
-// within drainJoinBound, or it fails with ErrDrainNotIdle.
+// within drainJoinBound and within ctx, or it fails with
+// ErrDrainNotIdle. ctx bounds the whole step: the driver's deadline
+// for step 3 holds even when the join would run longer.
//
// It starts the ingress drain if BeginIngressDrain has not, and refuses
-// with ErrConnectionDrainOn while §25's drain is on. The SIGTERM shutdown
+// with ErrConnectionDrainOn while §25's drain is on. With no public server
+// registered it closes nothing and fails with ErrNoPublicListeners. The SIGTERM shutdown
// that follows finds both servers shut and returns at once.
func (e *Edge) CloseIngress(ctx context.Context, wait time.Duration) (IngressClose, error) {
var out IngressClose
@@ -118,6 +127,9 @@ func (e *Edge) CloseIngress(ctx context.Context, wait time.Duration) (IngressClo
}
srvs := append([]*http.Server(nil), e.conns.servers...)
e.conns.mu.Unlock()
+ if len(srvs) == 0 {
+ return out, ErrNoPublicListeners
+ }
listeners := []*connDrain{&e.conns, &e.plain}
endedBefore := make([]uint64, len(listeners))
for i, d := range listeners {
@@ -162,7 +174,7 @@ func (e *Edge) CloseIngress(ctx context.Context, wait time.Duration) (IngressClo
if idle {
return out, nil
}
- jctx, jcancel := context.WithTimeout(context.Background(), drainJoinBound)
+ jctx, jcancel := context.WithTimeout(ctx, drainJoinBound)
defer jcancel()
for _, d := range listeners {
if !d.waitIdle(jctx.Done()) {
diff --git a/internal/edge/ingressdrain_test.go b/internal/edge/ingressdrain_test.go
index 8304ee6e1..bb4fee4be 100644
--- a/internal/edge/ingressdrain_test.go
+++ b/internal/edge/ingressdrain_test.go
@@ -481,6 +481,48 @@ func TestCloseIngressFailsWhenZeroIsNotReached(t *testing.T) {
}
}
+// The caller's context bounds the whole of step 3, the join included: the
+// driver's absolute deadline (W6 final review F1). A handler that ignores
+// its cancel holds the join only until ctx ends, never for a further
+// drainJoinBound.
+func TestCloseIngressJoinEndsWithTheContext(t *testing.T) {
+ prev := drainJoinBound
+ drainJoinBound = 10 * time.Second
+ defer func() { drainJoinBound = prev }()
+ e := &Edge{}
+ stuck := make(chan struct{})
+ defer close(stuck)
+ ie := newIngressEdge(t, e, func(w http.ResponseWriter, r *http.Request) {
+ w.WriteHeader(200)
+ w.(http.Flusher).Flush()
+ <-stuck
+ })
+ resp := ie.get(t, ie.client(t, false), "/stuck")
+ defer resp.Body.Close()
+ waitInFlight(t, e, 1)
+ ctx, cancel := context.WithTimeout(context.Background(), 300*time.Millisecond)
+ defer cancel()
+ start := time.Now()
+ out, err := e.CloseIngress(ctx, 100*time.Millisecond)
+ if in := time.Since(start); in > 2*time.Second {
+ t.Fatalf("step 3 ran %s past a 300ms context", in)
+ }
+ if out.Closed != 1 || !errors.Is(err, ErrDrainNotIdle) {
+ t.Fatalf("step 3: %+v %v; want ErrDrainNotIdle", out, err)
+ }
+}
+
+// With no public server registered (dev mode's plain HTTP listener is not
+// one) step 3 closes nothing, and says so rather than reporting the
+// listeners closed (W6 final review F7).
+func TestCloseIngressWithNoPublicServersFails(t *testing.T) {
+ e := &Edge{}
+ out, err := e.CloseIngress(context.Background(), time.Second)
+ if !errors.Is(err, ErrNoPublicListeners) || out != (IngressClose{}) {
+ t.Fatalf("step 3: %+v %v; want ErrNoPublicListeners", out, err)
+ }
+}
+
// Edge-held SSE streams are closed at the start of the wait, at an event
// boundary, so they do not hold step 3 to its bound.
func TestCloseIngressClosesHeldStreams(t *testing.T) {