carlos / platform Public

ship --check probe stops at redirects; reasonWord drops paths too

Astra review of ea91f292: carlos ship --check's readiness probe followed
redirects as well, so a force_ssl app still failed the local check; it
now stops at the first answer and says X-Forwarded-Proto: https. And a
failed dial puts the host inside a socket path
(/run/carlos/g/20/<host>.sock), which the path exception kept; reasonWord
now drops paths before dotted names.

Summary

Applies both Astra findings: the ship --check probe gets the same redirect and header policy, and reasonWord ignores paths so a host inside a socket path cannot pick the reason.
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev da877a06fcfa08840b8e1a7c284c5620c6f1cea9 parent ea91f29
4 files changed, +55 −10
  • internal/rollout/events.go +13 −9
  • internal/rollout/reason_host_test.go +3 −0
  • ship_check_probe.go +9 −1
  • ship_check_probe_test.go +30 −0

CI failed — run details

Intent

Human

<task-notification> <task-id>bimu6quv5</task-id> <tool-use-id>toolu_01AGX2SdytTV66sfwd4AhG4G</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/a272582f-d01a-4062-a285-1d78d1a6a793/tasks/bimu6quv5.output</output-file> <status>failed</status> <summary>Background command "Run the Astra review in the background" failed with exit code 1</summary> </task-notification>

Human

<task-notification> <task-id>b3bwfl56f</task-id> <tool-use-id>toolu_013y99pRkWQx1EVriQNBE3rP</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/a272582f-d01a-4062-a285-1d78d1a6a793/tasks/b3bwfl56f.output</output-file> <status>completed</status> <summary>Background command "Run the Astra review in the background" completed (exit code 0)</summary> </task-notification>

Attributed to this commit: 15.8 g CO₂e (1,791,164 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on health-check-no-redirects-845, 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/rollout/events.go b/internal/rollout/events.go
index cd83757f8..1f755c0db 100644
--- a/internal/rollout/events.go
+++ b/internal/rollout/events.go
@@ -27,14 +27,17 @@ const (
EvStagingRefused EventCode = "staging.refused"
)
-// dottedName matches a dotted name standing on its own: a host, an IP
-// address, a version. reasonWord drops them before it reads the text,
-// because a host is words its owner chose: a health check failed by a host
-// under staging.example.com read as a staging failure (discussion #845).
-// The submatch is the character before the name, kept. A name inside a
-// path (after a slash) is not dropped: a staged path is the platform's
-// word for what went wrong.
-var dottedName = regexp.MustCompile(`(^|[^a-z0-9_./-])[a-z0-9_-]+(?:\.[a-z0-9_-]+)+`)
+// 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
@@ -44,7 +47,8 @@ var dottedName = regexp.MustCompile(`(^|[^a-z0-9_./-])[a-z0-9_-]+(?:\.[a-z0-9_-]
// swap's checks are the health check, the settle and the exit watch, and the
// health check is the one a spawn or start error also fails.
func reasonWord(text string) string {
- t := dottedName.ReplaceAllString(strings.ToLower(text), "$1")
+ 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
index d5a92b634..009d22b83 100644
--- a/internal/rollout/reason_host_test.go
+++ b/internal/rollout/reason_host_test.go
@@ -22,6 +22,9 @@ func TestReasonWordIgnoresHostNames(t *testing.T) {
"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,
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