carlos / platform Public

host: journal the whole ingress drain report, not only its summary

Task 6 fix round 1. Spec 4.2 step 4 has the caller journal the report,
and the 10 witness reads it after the agent stops. __ingress-drain and
the verbs now print the summary line and then the whole report as one
compact JSON line: target states over time, step times, counts and the
close error. An answer with no report is still one line saying why.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 5408ff60c488aff626e2e0de6347f8de05fa8e07 parent f42b6ad
4 files changed, +128 −28
  • internal/host/hadrain_call.go +23 −4
  • internal/host/ingressdrain_call_linux_test.go +33 −22
  • internal/host/systemapply.go +3 −1
  • internal/host/systemapply_ingress_test.go +69 −1

Intent

Human

<task-notification> <task-id>ab52d0991e8a15736</task-id> <tool-use-id>toolu_018MhN64PSLbCycMfUhyd6dW</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/a373aecd-faa9-4b83-8736-ff726fb2d3af/tasks/ab52d0991e8a15736.output</output-file> <status>completed</status> <summary>Agent "Implement W6 Task 6 (helper+verbs)" 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. Task 6 is built and committed. Git printed a `packed-refs.lock` error during the commit (another git process was running in the repo), but the commit and branch ref are both in place. Commits: f42b6ade, on top of c74af0b7 (the Task 4+5 fix round, which landed while I worked). Tests: all new and affected tests pass: 195 tests in the systemapply, drain-call and ingress-drain files, plus the CLI projection, top-level words and golden tests. `go vet` and the darwin/windows builds are clean. Removing either ask makes its tests fail. Concerns: 1. Recovery restarts the edge without asking for the drain. The spec names only apply and rollback, and the edge is usually already dead when recovery runs. 2. The activation guard can still refuse at the rename after the drain. The box then stays drained until the agent's 3-minute exit, as §5.3 accepts. 3. Apply now asks before writing its journal, not right before quiesce, so an apply killed mid-drain leaves nothing to recover. The verb can wait up to 155 s; Task 7's SSM timeout check covers its callers. 4. Group members ask too and get `group_member` back at once, at the cost of one child process per run. 5. Census (Task 11): install, rollback, `restoreFiles` (now takes a drain flag) and `drainClient.call` changed, plus several new functions. The census test was already failing on the branch before this task. 6. The transition test models the pre-W6 verb as one with no way to ask. The real two-binary run is Task 9's root runner. Report: /home/paulca/amadan.net/carlos/platform/.claude/worktrees/w6-build/.superpowers/sdd/2026-11-10-fixed-edge-ingress-drain/task-6-report.md (`.superpowers/` is git-excluded, so it is not committed).</result> <usage><subagent_tokens>197960</subagent_tokens><tool_uses>93</tool_uses><duration_ms>1070394</duration_ms></usage> </task-notification>

Attributed to this commit: 10.3 g CO₂e (1,284,281 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/hadrain_call.go b/internal/host/hadrain_call.go
index 517d292f2..7093c144d 100644
--- a/internal/host/hadrain_call.go
+++ b/internal/host/hadrain_call.go
@@ -283,9 +283,9 @@ func (c *cappedBuffer) Write(p []byte) (int, error) {
var ingressAskBound = ingressCallBound + 5*time.Second
// ingressDrainEntry is __ingress-drain's body (the drain unit's ExecStop,
-// spec §5.2, run as the agent's user; dispatched beside __drain-call): ask the agent at path for
-// the ingress drain and print one line, the report or why there is none.
-// It has no failure: the stop it runs in goes on whatever happens here,
+// spec §5.2, run as the agent's user; dispatched beside __drain-call): ask
+// the agent at path for the ingress drain and print ingressCallLines, the
+// report or one line saying why there is none. It has no failure: the stop it runs in goes on whatever happens here,
// and the entry exits 0. Root never dials the socket, so as root it asks
// nothing.
func ingressDrainEntry(args []string, euid int, path string, out io.Writer) {
@@ -303,7 +303,26 @@ func ingressDrainEntry(args []string, euid int, path string, out io.Writer) {
if err != nil {
r = drainCallResult{Error: err.Error()}
}
- fmt.Fprintln(out, ingressCallLine(r))
+ for _, l := range ingressCallLines(r) {
+ fmt.Fprintln(out, l)
+ }
+}
+
+// ingressCallLines is one ask's answer for the journal (spec §4.2 step 4):
+// with a report, a summary line and then the whole report (target states
+// over time, step times, counts, close error) as one compact JSON line,
+// which the dev witness (§10) reads after the agent has stopped; without
+// one, a single line saying why.
+func ingressCallLines(r drainCallResult) []string {
+ lines := []string{ingressCallLine(r)}
+ if r.Ingress != nil {
+ b, err := json.Marshal(r.Ingress)
+ if err != nil {
+ b = []byte(fmt.Sprintf("%q", "unprintable: "+err.Error()))
+ }
+ lines = append(lines, "ingress drain report: "+string(b))
+ }
+ return lines
}
// ingressCallLine is one ask's answer as one line: the report's result,
diff --git a/internal/host/ingressdrain_call_linux_test.go b/internal/host/ingressdrain_call_linux_test.go
index 5223309ce..be586ef4e 100644
--- a/internal/host/ingressdrain_call_linux_test.go
+++ b/internal/host/ingressdrain_call_linux_test.go
@@ -48,37 +48,40 @@ func answerIngress(rep ingressReport) http.Handler {
}
// __ingress-drain (spec §5.2 "Never blocks a stop", §9): every way the
-// call can end prints exactly one line and the entry exits 0 whatever
-// happened (it has no other exit code to give).
-func TestIngressDrainEntryPrintsOneLineOnEveryPath(t *testing.T) {
+// call can end without a report prints exactly one line saying why; a
+// report prints a summary line and the whole report as one compact JSON
+// line, for the journal (§4.2 step 4). The entry returns (exits 0)
+// whatever happened.
+func TestIngressDrainEntryPrintsOnEveryPath(t *testing.T) {
defer shorten(&ingressAskBound, 300*time.Millisecond)()
hang := make(chan struct{})
t.Cleanup(func() { close(hang) })
+ refused := ingressReport{V: 1, Result: "refused", Reason: "a region HA drain is running"}
+ notArmed := ingressReport{V: 1, Result: ingressNotArmed, Reason: "CARLOS_INGRESS_TARGET_GROUPS is not set"}
+ withdrawn := ingressReport{V: 1, Result: "done", Verdict: ingressWithdrawn}
+ full := fullIngressReport()
for _, tc := range []struct {
- name string
- h http.Handler
- want []string
+ name string
+ h http.Handler
+ report *ingressReport
+ want []string
}{
- {"no socket", nil, []string{"not answering", "nothing to drain"}},
- {"old agent (404)", http.NotFoundHandler(), []string{"no ingress drain", "older release"}},
- {"refused", answerIngress(ingressReport{V: 1, Result: "refused", Reason: "a region HA drain is running"}),
- []string{"result refused", "a region HA drain is running"}},
- {"not armed", answerIngress(ingressReport{V: 1, Result: ingressNotArmed, Reason: "CARLOS_INGRESS_TARGET_GROUPS is not set"}),
- []string{"result not_armed", "CARLOS_INGRESS_TARGET_GROUPS is not set"}},
+ {"no socket", nil, nil, []string{"not answering", "nothing to drain"}},
+ {"old agent (404)", http.NotFoundHandler(), nil, []string{"no ingress drain", "older release"}},
{"error answer", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusInternalServerError)
_ = json.NewEncoder(w).Encode(drainError{Error: "the agent broke"})
- }), []string{"no report", "the agent broke"}},
+ }), nil, []string{"no report", "the agent broke"}},
{"timeout", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
select {
case <-hang:
case <-r.Context().Done():
}
- }), []string{"no report", "deadline exceeded"}},
- {"withdrawn", answerIngress(ingressReport{V: 1, Result: "done", Verdict: ingressWithdrawn}),
- []string{"result done", "verdict withdrawn"}},
- {"unverified", answerIngress(ingressReport{V: 1, Result: "done", Verdict: ingressUnverified,
- Reasons: []string{"no other healthy target", "tg-a: healthy"}}),
+ }), nil, []string{"no report", "deadline exceeded"}},
+ {"refused", answerIngress(refused), &refused, []string{"result refused", "a region HA drain is running"}},
+ {"not armed", answerIngress(notArmed), &notArmed, []string{"result not_armed", "CARLOS_INGRESS_TARGET_GROUPS is not set"}},
+ {"withdrawn", answerIngress(withdrawn), &withdrawn, []string{"result done", "verdict withdrawn"}},
+ {"unverified, full report", answerIngress(*full), full,
[]string{"result done", "verdict unverified", "no other healthy target; tg-a: healthy"}},
} {
t.Run(tc.name, func(t *testing.T) {
@@ -90,14 +93,22 @@ func TestIngressDrainEntryPrintsOneLineOnEveryPath(t *testing.T) {
t.Fatalf("took %v", time.Since(start))
}
got := out.String()
- if strings.Count(got, "\n") != 1 || !strings.HasSuffix(got, "\n") || !strings.HasPrefix(got, "ingress drain: ") {
- t.Fatalf("want exactly one line, got %q", got)
+ lines := strings.Split(strings.TrimSuffix(got, "\n"), "\n")
+ want := 1
+ if tc.report != nil {
+ want = 2
+ }
+ if !strings.HasSuffix(got, "\n") || len(lines) != want || !strings.HasPrefix(lines[0], "ingress drain: ") {
+ t.Fatalf("want %d line(s), got %q", want, got)
}
for _, w := range tc.want {
- if !strings.Contains(got, w) {
- t.Fatalf("%q lacks %q", got, w)
+ if !strings.Contains(lines[0], w) {
+ t.Fatalf("%q lacks %q", lines[0], w)
}
}
+ if tc.report != nil {
+ assertReportLine(t, lines[1], tc.report)
+ }
})
}
}
diff --git a/internal/host/systemapply.go b/internal/host/systemapply.go
index 050a61896..b034608f1 100644
--- a/internal/host/systemapply.go
+++ b/internal/host/systemapply.go
@@ -322,7 +322,9 @@ func (a *systemApplier) ingressDrainBeforeSwap(ctx context.Context) {
a.ops.logf("system apply: ingress drain: no report: %s (continuing)", oneLine(err.Error()))
return
}
- a.ops.logf("system apply: %s", ingressCallLine(r))
+ for _, l := range ingressCallLines(r) {
+ a.ops.logf("system apply: %s", l)
+ }
}
func (a *systemApplier) rootDir() string { return systemRootDir(a.optDir) }
diff --git a/internal/host/systemapply_ingress_test.go b/internal/host/systemapply_ingress_test.go
index a31863b0a..7fb4d8cc9 100644
--- a/internal/host/systemapply_ingress_test.go
+++ b/internal/host/systemapply_ingress_test.go
@@ -2,6 +2,7 @@ package host
import (
"context"
+ "encoding/json"
"errors"
"fmt"
"os"
@@ -186,9 +187,13 @@ func TestApplyGoesOnWhenTheAgentCannotDrain(t *testing.T) {
if r := f.result(); r == nil || r.Outcome != systemOutcomeApplied {
t.Fatalf("result = %+v", r)
}
- if agent.asks != 1 || agent.logged("ingress drain") != 1 || agent.logged(tc.line) != 1 {
+ if agent.asks != 1 || agent.logged("ingress drain: ") != 1 || agent.logged(tc.line) != 1 {
t.Fatalf("asks %d, logs %q", agent.asks, agent.logs)
}
+ // Only an answer that is a report carries a report line.
+ if want := map[bool]int{true: 1, false: 0}[tc.name == "refused"]; agent.logged("ingress drain report: ") != want {
+ t.Fatalf("report lines: logs %q", agent.logs)
+ }
})
}
}
@@ -280,3 +285,66 @@ func TestApplyPreW6ToW6GateFailureRollsBackUndrainedAndServes(t *testing.T) {
t.Fatal("the box is not serving after the rollback")
}
}
+
+// fullIngressReport is a report with every field populated: target-state
+// history, step times, counters and a close error, as the §10 witness
+// reads it from the journal.
+func fullIngressReport() *ingressReport {
+ at := func(s int) *time.Time { t := time.Date(2026, 11, 10, 12, 0, s, 0, time.UTC); return &t }
+ return &ingressReport{
+ V: 1, Incarnation: "inc-1", Result: "done", Verdict: ingressUnverified,
+ Reasons: []string{"no other healthy target", "tg-a: healthy"},
+ TargetGroups: []string{"tg-a", "tg-b"},
+ StartedAt: at(0), HealthFailedAt: at(1), WaitEndedAt: at(91), ListenersClosedAt: at(121), FinishedAt: at(121),
+ Reads: 46,
+ Polls: []ingressPoll{
+ {At: *at(1), Groups: []ingressPollGroup{{TargetGroup: "tg-a", Self: []ingressPollTarget{{Port: 443, State: "healthy"}}, OtherHealthy: 0}}},
+ {At: *at(31), Error: "tg-b: throttled"},
+ },
+ HeldClosed: 2, Finished: 7, Closed: 1, CloseError: ":80 shutdown: context deadline exceeded",
+ }
+}
+
+// assertReportLine checks line is the whole report as one compact JSON
+// line after its prefix.
+func assertReportLine(t *testing.T, line string, want *ingressReport) {
+ t.Helper()
+ body, ok := strings.CutPrefix(line, "ingress drain report: ")
+ if !ok || strings.Contains(body, "\n") {
+ t.Fatalf("not a report line: %q", line)
+ }
+ var got ingressReport
+ if err := json.Unmarshal([]byte(body), &got); err != nil {
+ t.Fatalf("report line does not parse: %v: %q", err, body)
+ }
+ g, _ := json.Marshal(got)
+ w, _ := json.Marshal(want)
+ if string(g) != string(w) || body != string(w) {
+ t.Fatalf("report line\n got %s\nwant %s", body, w)
+ }
+}
+
+// The verbs journal the whole report too, not only its summary.
+func TestApplyLogsTheWholeIngressReport(t *testing.T) {
+ f, _ := applyHappy(t)
+ full := fullIngressReport()
+ agent := f.ingressAgent(func() (drainCallResult, error) { return drainCallResult{V: 1, Ingress: full}, nil })
+ if err := f.a.Run(context.Background(), false); err != nil {
+ t.Fatal(err)
+ }
+ var summary, report []string
+ for _, l := range agent.logs {
+ if r, ok := strings.CutPrefix(l, "system apply: "); ok {
+ switch {
+ case strings.HasPrefix(r, "ingress drain report: "):
+ report = append(report, r)
+ case strings.HasPrefix(r, "ingress drain: "):
+ summary = append(summary, r)
+ }
+ }
+ }
+ if len(summary) != 1 || !strings.Contains(summary[0], "verdict unverified: no other healthy target; tg-a: healthy") || len(report) != 1 {
+ t.Fatalf("logs %q", agent.logs)
+ }
+ assertReportLine(t, report[0], full)
+}