carlos / platform Public

activator: health checks stop at redirects; hosts never pick a reason

A Rails app with force_ssl answered the health probe with a 301 to
https://carlos/. The probe followed it into a TLS handshake on the plain
socket, so the instance never became healthy and crash-looped (#845).
The exec, unit and ship --check probes now stop at the first answer (a
3xx is under 500, so healthy) and send X-Forwarded-Proto: https, as the
edge does on real requests.

The rollout reported that failure as "the copy on the box did not match
the release": reasonWord matched "staging" inside the host name. It
now drops paths and dotted names (hosts, addresses, versions) before
reading the platform's words.

Census: three envelopes re-pinned; Astra approved (#280).

Squashed from health-check-no-redirects-845 into main.
claude agent, operated by paul@keymail.dev 965e26f3d4711a7d0124185fe01b37691530926a parent 1a6e984
11 files changed, +312 −21
  • docs/superpowers/notes/census-proposal-health-check-no-redirects-845.md +11 −0
  • docs/superpowers/reviews/CODEX-REVIEW-BRIEF-health-check-845-census.md +47 −0
  • internal/activator/backend_exec.go +35 −10
  • internal/activator/backend_unit.go +3 −10
  • internal/activator/healthcheck_redirect_test.go +117 −0
  • internal/provision/testdata/plan14-root-reads-chain.tsv +1 −0
  • internal/provision/testdata/plan14-root-reads-health-check-no-redirects-845.tsv +5 −0
  • internal/rollout/events.go +14 −0
  • internal/rollout/reason_host_test.go +40 −0
  • ship_check_probe.go +9 −1
  • ship_check_probe_test.go +30 −0

CI passed — run details

diff --git a/docs/superpowers/notes/census-proposal-health-check-no-redirects-845.md b/docs/superpowers/notes/census-proposal-health-check-no-redirects-845.md
new file mode 100644
index 000000000..df32d7848
--- /dev/null
+++ b/docs/superpowers/notes/census-proposal-health-check-no-redirects-845.md
@@ -0,0 +1,11 @@
+# Census approval: health-check-no-redirects-845
+
+Ruling `census-ruling-health-check-no-redirects-845`. The independent reviewer approves or rejects every change below, 0 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26).
+
+Envelopes re-pinned: `.`, `internal/activator`, `internal/rollout`.
+
+Review: a model from the other family than the author reads the branch's diff against main on the amadan.net remote (`origin` or `amadan`, whichever points at amadan.net) and gives a verdict for every unit and every re-pinned envelope above. For a unit, compare the change with its recorded disposition and basis below; for an envelope, read every changed function in the package and what it reaches. Reject if the change lets root open, run, query or follow anything it did not before from a path or input a tenant, an app or a box agent can create, write or name; if it weakens a check, refusal, validation, argument or environment the basis relies on; or if the diff cannot settle either. Otherwise approve. Record each verdict on #280 with the tip. A rejected unit goes back to the author to correct; nothing escalates to the census owner.
+
+Seal: `e650a3ceb286df4457850d74ded9229d94ed9932057ae5b45b1d6c3d0d843ce2` → `e650a3ceb286df4457850d74ded9229d94ed9932057ae5b45b1d6c3d0d843ce2`.
+
+Overlay: `internal/provision/testdata/plan14-root-reads-health-check-no-redirects-845.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`.
diff --git a/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-health-check-845-census.md b/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-health-check-845-census.md
new file mode 100644
index 000000000..32c6db814
--- /dev/null
+++ b/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-health-check-845-census.md
@@ -0,0 +1,47 @@
+# Review brief: branch health-check-no-redirects-845 census, round 1 of 3
+
+Repo carlos/platform, branch `health-check-no-redirects-845`, the commit
+that adds this brief (`git log -1 -- docs/superpowers/reviews/CODEX-REVIEW-BRIEF-health-check-845-census.md`).
+Under review: the diff `origin/main...HEAD`, and the census card
+`docs/superpowers/notes/census-proposal-health-check-no-redirects-845.md`.
+Authorities: AGENTS.md, "The census" and "Getting a change approved".
+
+You are an independent reviewer. Read the card, then every changed
+function in the re-pinned envelopes and what it reaches.
+
+## Fixed: do not re-argue
+
+- The behaviour change itself (discussion #845): health probes stop at a
+ redirect and send X-Forwarded-Proto: https; reasonWord ignores paths and
+ dotted names. A correctness review already ran (two rounds, clean).
+
+## What to check
+
+1. The card re-pins three envelopes and changes no unit: `.`
+ (ship_check_probe.go: runRootfsCheckProbe, checkProbeGet),
+ `internal/activator` (backend_exec.go: waitHealthy, healthClient,
+ probeHealth; backend_unit.go: waitHealthyAddr), `internal/rollout`
+ (events.go: reasonWord, pathName, dottedName). For each envelope, give
+ a verdict: does the change let root open, run, query or follow
+ anything it did not before from a path or input a tenant, an app or a
+ box agent can create, write or name, or weaken a check, refusal,
+ validation, argument or environment root relies on? Note in
+ particular: the probes now do NOT follow a redirect an app answers
+ with (fewer follows than before), and add one fixed request header.
+
+## Severity
+
+- **P1**: unsafe, would not compile, a test fails, or it would not work.
+ Blocks merge.
+- **P2**: wrong or missing. Fixed without reopening this review.
+- **P3**: clarity or polish. Goes on a follow-up list; never a reason for
+ another round.
+
+## Output
+
+A verdict per envelope (approve or reject, citing the lines read), then
+findings ranked P1, P2, P3, each with file:line, failure scenario and fix.
+End with exactly one verdict: READY, READY AFTER FIXES, or NOT READY.
+
+Do not edit files. Do not spawn Anthropic-model reviewers or subagents of
+your own. Do not run the full test suites.
diff --git a/internal/activator/backend_exec.go b/internal/activator/backend_exec.go
index 0fa4851f3..1bd77ff5e 100644
--- a/internal/activator/backend_exec.go
+++ b/internal/activator/backend_exec.go
@@ -3880,19 +3880,12 @@ func socketClient(socket string) *http.Client {
// process) — and a broken binary that never becomes healthy fails the wake.
func waitHealthy(socket string, timeout time.Duration) error {
deadline := time.Now().Add(timeout)
- client := socketClient(socket)
+ client := healthClient(socketClient(socket))
var last error
var poll time.Duration
for time.Now().Before(deadline) {
- resp, err := client.Get("http://carlos/")
- if err == nil {
- resp.Body.Close()
- if resp.StatusCode < 500 {
- return nil
- }
- last = fmt.Errorf("unhealthy: HTTP %d", resp.StatusCode)
- } else {
- last = err
+ if last = probeHealth(client, "http://carlos/"); last == nil {
+ return nil
}
poll = nextHealthPoll(poll)
time.Sleep(poll)
@@ -3900,6 +3893,38 @@ func waitHealthy(socket string, timeout time.Duration) error {
return fmt.Errorf("instance not healthy within %s: %v", timeout, last)
}
+// healthClient is c made fit for a health probe: it never follows a
+// redirect. A redirect is an answer, and under 500, so the app is up.
+// Following one is worse than pointless: an app with Rails' force_ssl
+// redirects to https://carlos/, and the client then starts a TLS handshake
+// on a plain socket, so the probe fails until the deadline and the wake
+// with it (discussion #845).
+func healthClient(c *http.Client) *http.Client {
+ c.CheckRedirect = func(*http.Request, []*http.Request) error { return http.ErrUseLastResponse }
+ return c
+}
+
+// probeHealth makes one health request: nil for any answer under 500. It
+// says X-Forwarded-Proto: https, as the edge does on every real request
+// (they all arrive over TLS), so an app that redirects plain http takes its
+// normal path rather than answering the probe with a redirect (#845).
+func probeHealth(client *http.Client, url string) error {
+ req, err := http.NewRequest(http.MethodGet, url, nil)
+ if err != nil {
+ return err
+ }
+ req.Header.Set("X-Forwarded-Proto", "https")
+ resp, err := client.Do(req)
+ if err != nil {
+ return err
+ }
+ resp.Body.Close()
+ if resp.StatusCode >= 500 {
+ return fmt.Errorf("unhealthy: HTTP %d", resp.StatusCode)
+ }
+ return nil
+}
+
// The wait between health probes. A request is held open for the whole of
// a wake, and a fixed 150 ms gap cost it 75 ms on average after the app was
// already listening. A refused dial costs microseconds, so the wait starts
diff --git a/internal/activator/backend_unit.go b/internal/activator/backend_unit.go
index 9576469e3..7f2151505 100644
--- a/internal/activator/backend_unit.go
+++ b/internal/activator/backend_unit.go
@@ -265,19 +265,12 @@ func (unitRep) Close(context.Context) error { return nil }
// fallback note).
func waitHealthyAddr(addr string, timeout time.Duration) error {
deadline := time.Now().Add(timeout)
- client := &http.Client{Timeout: 3 * time.Second}
+ client := healthClient(&http.Client{Timeout: 3 * time.Second})
var last error
var poll time.Duration
for time.Now().Before(deadline) {
- resp, err := client.Get("http://" + addr + "/")
- if err == nil {
- resp.Body.Close()
- if resp.StatusCode < 500 {
- return nil
- }
- last = fmt.Errorf("unhealthy: HTTP %d", resp.StatusCode)
- } else {
- last = err
+ if last = probeHealth(client, "http://"+addr+"/"); last == nil {
+ return nil
}
poll = nextHealthPoll(poll)
time.Sleep(poll)
diff --git a/internal/activator/healthcheck_redirect_test.go b/internal/activator/healthcheck_redirect_test.go
new file mode 100644
index 000000000..c7d98be84
--- /dev/null
+++ b/internal/activator/healthcheck_redirect_test.go
@@ -0,0 +1,117 @@
+package activator
+
+import (
+ "net"
+ "net/http"
+ "strings"
+ "sync/atomic"
+ "testing"
+ "time"
+)
+
+// forceSSLApp answers the way a Rails app with config.force_ssl does: a 301
+// to https for any request that does not say it arrived over TLS. A request
+// that follows that redirect is a TLS handshake on a plain listener, which
+// the server sees as a malformed request and the client as a failed probe
+// (discussion #845). It counts every request that said https.
+func forceSSLApp(t *testing.T, ln net.Listener) *atomic.Int32 {
+ t.Helper()
+ var https atomic.Int32
+ srv := &http.Server{Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ if r.Header.Get("X-Forwarded-Proto") != "https" {
+ http.Redirect(w, r, "https://"+r.Host+r.URL.RequestURI(), http.StatusMovedPermanently)
+ return
+ }
+ https.Add(1)
+ w.WriteHeader(http.StatusOK)
+ })}
+ go srv.Serve(ln)
+ t.Cleanup(func() { srv.Close() })
+ return &https
+}
+
+// redirectingApp redirects every request to https, whatever it says.
+func redirectingApp(t *testing.T, ln net.Listener) {
+ t.Helper()
+ srv := &http.Server{Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ http.Redirect(w, r, "https://"+r.Host+"/", http.StatusMovedPermanently)
+ })}
+ go srv.Serve(ln)
+ t.Cleanup(func() { srv.Close() })
+}
+
+// A force_ssl app on its unix socket becomes healthy: the probe says it
+// came over https, as the edge does on a real request, so the app takes its
+// normal path (#845).
+func TestWaitHealthySaysHTTPS(t *testing.T) {
+ requireUnixSockets(t)
+ sock := tmpSock(t)
+ ln, err := net.Listen("unix", sock)
+ if err != nil {
+ t.Fatal(err)
+ }
+ https := forceSSLApp(t, ln)
+ if err := waitHealthy(sock, 2*time.Second); err != nil {
+ t.Fatalf("waitHealthy: %v", err)
+ }
+ if https.Load() == 0 {
+ t.Fatal("the probe never said https")
+ }
+}
+
+// A redirect is an answer under 500, so it is healthy. Following it would
+// start TLS on a plain socket and fail every probe until the deadline (#845).
+func TestWaitHealthyDoesNotFollowRedirects(t *testing.T) {
+ requireUnixSockets(t)
+ sock := tmpSock(t)
+ ln, err := net.Listen("unix", sock)
+ if err != nil {
+ t.Fatal(err)
+ }
+ redirectingApp(t, ln)
+ if err := waitHealthy(sock, 2*time.Second); err != nil {
+ t.Fatalf("waitHealthy on a redirecting app: %v", err)
+ }
+}
+
+// The TCP probe behaves the same way.
+func TestWaitHealthyAddrSaysHTTPSAndDoesNotFollowRedirects(t *testing.T) {
+ ln, err := net.Listen("tcp", "127.0.0.1:0")
+ if err != nil {
+ t.Fatal(err)
+ }
+ https := forceSSLApp(t, ln)
+ if err := waitHealthyAddr(ln.Addr().String(), 2*time.Second); err != nil {
+ t.Fatalf("waitHealthyAddr: %v", err)
+ }
+ if https.Load() == 0 {
+ t.Fatal("the probe never said https")
+ }
+
+ ln2, err := net.Listen("tcp", "127.0.0.1:0")
+ if err != nil {
+ t.Fatal(err)
+ }
+ redirectingApp(t, ln2)
+ if err := waitHealthyAddr(ln2.Addr().String(), 2*time.Second); err != nil {
+ t.Fatalf("waitHealthyAddr on a redirecting app: %v", err)
+ }
+}
+
+// A 500 is still unhealthy, and the error names the status rather than a
+// redirect target.
+func TestWaitHealthyStillFailsA500(t *testing.T) {
+ ln, err := net.Listen("tcp", "127.0.0.1:0")
+ if err != nil {
+ t.Fatal(err)
+ }
+ srv := &http.Server{Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ w.WriteHeader(http.StatusInternalServerError)
+ })}
+ go srv.Serve(ln)
+ t.Cleanup(func() { srv.Close() })
+ err = waitHealthyAddr(ln.Addr().String(), 200*time.Millisecond)
+ if err == nil || !strings.Contains(err.Error(), "HTTP 500") {
+ t.Fatalf("waitHealthyAddr on a 500 = %v, want HTTP 500", err)
+ }
+}
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv
index 7f01373e2..8023d731b 100644
--- a/internal/provision/testdata/plan14-root-reads-chain.tsv
+++ b/internal/provision/testdata/plan14-root-reads-chain.tsv
@@ -158,3 +158,4 @@ plan14-root-reads-litestream-quiet-802.tsv 6d3ea7fccce1a7f4bc507b6eb8d368ed0b62f
plan14-root-reads-group-roll-dr4-lock-refusal.tsv 6d3ea7fccce1a7f4bc507b6eb8d368ed0b62f83022504aa04c7684c72c93aa9a
plan14-root-reads-held-floor-capability.tsv b60c83f8ba4311222174284420b5327e92002882b4a1c6f291e74e69234c6f59
plan14-root-reads-litestream-unit-restart.tsv e650a3ceb286df4457850d74ded9229d94ed9932057ae5b45b1d6c3d0d843ce2
+plan14-root-reads-health-check-no-redirects-845.tsv e650a3ceb286df4457850d74ded9229d94ed9932057ae5b45b1d6c3d0d843ce2
diff --git a/internal/provision/testdata/plan14-root-reads-health-check-no-redirects-845.tsv b/internal/provision/testdata/plan14-root-reads-health-check-no-redirects-845.tsv
new file mode 100644
index 000000000..f53a78d02
--- /dev/null
+++ b/internal/provision/testdata/plan14-root-reads-health-check-no-redirects-845.tsv
@@ -0,0 +1,5 @@
+# Census overlay health-check-no-redirects-845, written by census-propose (#369). census-ruling-health-check-no-redirects-845, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-health-check-no-redirects-845.md.
+# 0 body, 0 sites, 3 envelope: each changed unit re-frozen at its existing disposition with its claim appended.
+@coverage . 48210208700473879c7c5bdec45b9c7f4b89131bf5b4679db5e70bd6611000bb
+@coverage internal/activator 399131b944444ad542fb17aa55cd8edcc9fabb8cff1d4e363eeb419899f00107
+@coverage internal/rollout ca9e6f2913b0038adec1be5344a721206f762ae92fcc38b58917f7467cec12d0
diff --git a/internal/rollout/events.go b/internal/rollout/events.go
index 88f78163b..1f755c0db 100644
--- a/internal/rollout/events.go
+++ b/internal/rollout/events.go
@@ -2,6 +2,7 @@ package rollout
import (
"fmt"
+ "regexp"
"strings"
"time"
@@ -26,6 +27,18 @@ const (
EvStagingRefused EventCode = "staging.refused"
)
+// reasonWord reads the platform's words, not the names between them: a
+// host is words its owner chose, and a health check failed by a host under
+// staging.example.com read as a staging failure (discussion #845). So it
+// drops every path first (a socket path carries the host:
+// /run/carlos/g/20/shop.staging.example.com.sock), then every dotted name
+// standing on its own (a host, an address, a version). A staging failure
+// still says so outside its paths ("staging:", "staged", "digest").
+var (
+ pathName = regexp.MustCompile(`/[^\s"':,()]*`)
+ dottedName = regexp.MustCompile(`[a-z0-9_-]+(?:\.[a-z0-9_-]+)+`)
+)
+
// reasonWord turns an attempt's diagnostic text (SwapResult.Reason, an error)
// into one of status's reason words (status.Reason*, the one vocabulary the
// events and the status report share), so no free text, which can name paths
@@ -35,6 +48,7 @@ const (
// health check is the one a spawn or start error also fails.
func reasonWord(text string) string {
t := strings.ToLower(text)
+ t = dottedName.ReplaceAllString(pathName.ReplaceAllString(t, " "), " ")
switch {
// A release command's failure (rootfs apps Plan 3, Group R) first:
// its text names the build's exit ("exited") and could name staging,
diff --git a/internal/rollout/reason_host_test.go b/internal/rollout/reason_host_test.go
new file mode 100644
index 000000000..009d22b83
--- /dev/null
+++ b/internal/rollout/reason_host_test.go
@@ -0,0 +1,40 @@
+package rollout
+
+import (
+ "testing"
+
+ "github.com/carlosframework/platform/internal/status"
+)
+
+// A host name is not a reason. Failure texts name the host they failed on,
+// and a host is any words its owner chose: one under staging.example.com
+// that failed its health check read as "the copy on the box did not match
+// the release" (discussion #845). reasonWord reads the platform's words,
+// never the names in between them.
+func TestReasonWordIgnoresHostNames(t *testing.T) {
+ for text, want := range map[string]string{
+ // The text from #845.
+ `wake tito-pro.bae.staging.platform.tito.io: start g20: instance not healthy within 2m0s: Get "https://carlos/": http: server gave HTTP response to HTTPS client`: status.ReasonHealth,
+ "shop.staging.example.com: instance not healthy within 30s: unhealthy: HTTP 502": status.ReasonHealth,
+ "staged.example.com: exited before it was ready": status.ReasonExit,
+ "digest.example.com: worker exited before it was observed": status.ReasonExit,
+ "settle.example.com: instance not healthy within 30s: EOF": status.ReasonHealth,
+ "reused.example.com: instance not healthy within 30s: EOF": status.ReasonHealth,
+ "release.example.com: instance not healthy within 30s: EOF": status.ReasonHealth,
+ `wake "app.staging.example.com": instance not healthy within 30s: EOF`: status.ReasonHealth,
+ // A socket path names the host too.
+ `wake shop.staging.example.com: instance not healthy within 30s: Get "http://carlos/": dial unix /run/carlos/g/20/shop.staging.example.com.sock: connect: no such file or directory`: status.ReasonHealth,
+ "dial unix /run/carlos/staging.example.com.sock: connect: connection refused": status.ReasonHealth,
+ // The platform's own words still win, host or no host.
+ "staging fallback for shop.staging.example.com: no such build": status.ReasonStaging,
+ "shop.example.com: build v2 is staged at /a, not at its version's path /b": status.ReasonStaging,
+ "staging: digest mismatch for shop.example.com": status.ReasonStaging,
+ "shop.example.com: worker exited before it was observed": status.ReasonExit,
+ `staged path "/opt/carlos/staging/app.bin" is not a regular file`: status.ReasonStaging,
+ "release: the release command of build v2 exited with status 1 on shop.example.com": status.ReasonRelease,
+ } {
+ if got := reasonWord(text); got != want {
+ t.Errorf("reasonWord(%q) = %q, want %q", text, got, want)
+ }
+ }
+}
diff --git a/ship_check_probe.go b/ship_check_probe.go
index 96184ff4c..0b928e713 100644
--- a/ship_check_probe.go
+++ b/ship_check_probe.go
@@ -77,7 +77,12 @@ func runRootfsCheckProbe(args []string) int {
return d.DialContext(ctx, "unix", *socket)
},
DisableKeepAlives: true,
- }}
+ },
+ // A redirect is an answer under 500. Following one from an app with
+ // force_ssl starts TLS on the plain socket and times out (#845), as
+ // the activator's own health check did.
+ CheckRedirect: func(*http.Request, []*http.Request) error { return http.ErrUseLastResponse },
+ }
start := time.Now()
last := 0
@@ -154,6 +159,9 @@ func checkProbeGet(ctx context.Context, client *http.Client) (int, error) {
if err != nil {
return 0, err
}
+ // Every real request reaches the app over TLS at the edge, which says
+ // so; the probe says the same, so the app takes its normal path (#845).
+ req.Header.Set("X-Forwarded-Proto", "https")
res, err := client.Do(req)
if err != nil {
return 0, err
diff --git a/ship_check_probe_test.go b/ship_check_probe_test.go
index 64c789e9e..82993f324 100644
--- a/ship_check_probe_test.go
+++ b/ship_check_probe_test.go
@@ -76,6 +76,36 @@ func TestCheckProbeAnswersOnTheFirstHealthyStatus(t *testing.T) {
}
}
+// A Rails app with force_ssl redirects plain http to https. The probe says
+// https, as the edge does, and a redirect is an answer under 500: following
+// it would start TLS on the plain socket and time out (discussion #845).
+func TestCheckProbeSaysHTTPSAndStopsAtARedirect(t *testing.T) {
+ sock := filepath.Join(probeSocketDir(t), "app.sock")
+ ln, err := net.Listen("unix", sock)
+ if err != nil {
+ t.Fatal(err)
+ }
+ var proto atomic.Value
+ srv := &http.Server{Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ proto.Store(r.Header.Get("X-Forwarded-Proto"))
+ http.Redirect(w, r, "https://"+r.Host+"/", http.StatusMovedPermanently)
+ })}
+ go srv.Serve(ln)
+ t.Cleanup(func() { srv.Close() })
+
+ out := captureStdout(t)
+ if code := runRootfsCheckProbe([]string{"--socket", sock, "--timeout", "2s"}); code != 0 {
+ t.Fatalf("exit %d: %s", code, out)
+ }
+ var got map[string]any
+ if err := json.Unmarshal(out.Bytes(), &got); err != nil || got["status"] != float64(http.StatusMovedPermanently) {
+ t.Fatalf("probe said %q (%v), want status 301", out, err)
+ }
+ if p, _ := proto.Load().(string); p != "https" {
+ t.Errorf("X-Forwarded-Proto %q, want https", p)
+ }
+}
+
const sampleProcNetTCP = ` sl local_address rem_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode
0: 00000000:0BB8 00000000:0000 0A 00000000:00000000 00:00000000 00000000 65534 0 12345 1 0000000000000000 100 0 0 10 0
1: 0100007F:1F90 0100007F:D431 01 00000000:00000000 00:00000000 00000000 65534 0 12346 1 0000000000000000 20 4 30 10 -1