carlos / platform Public

region-ha-shutting-down-retry

Squashed from region-ha-shutting-down-retry into main.
claude agent, operated by paul@keymail.dev 321cc1ca4064d7fb9c483178441278a63751ef8a parent 06bb3f7
5 files changed, +100 −0
  • docs/superpowers/notes/census-proposal-region-ha-shutting-down-retry.md +19 −0
  • internal/activator/activator.go +9 −0
  • internal/activator/shuttingdown_answer_test.go +67 −0
  • internal/provision/testdata/plan14-root-reads-chain.tsv +1 −0
  • internal/provision/testdata/plan14-root-reads-region-ha-shutting-down-retry.tsv +4 −0

CI passed — run details

diff --git a/docs/superpowers/notes/census-proposal-region-ha-shutting-down-retry.md b/docs/superpowers/notes/census-proposal-region-ha-shutting-down-retry.md
new file mode 100644
index 000000000..1b09d83df
--- /dev/null
+++ b/docs/superpowers/notes/census-proposal-region-ha-shutting-down-retry.md
@@ -0,0 +1,19 @@
+# Census approval: region-ha-shutting-down-retry
+
+Ruling `census-ruling-region-ha-shutting-down-retry`. 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).
+
+| unit | change | read sites | what changed |
+|---|---|---|---|
+| `internal/activator/activator.go` `Service.serveWakeError` | body | unchanged (5) | Task 0: errShuttingDown (a request met by Shutdown, #292) is answered with the existing admission unavailable 503 (Retry-After: 10, no-store, holder removed), before answerForwarded, instead of the default wake-failed 503 with no Retry-After and a wake log line; no new read, read sites unchanged. |
+
+Envelopes re-pinned: `internal/activator`.
+
+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.
+
+Recorded dispositions, which each change must still satisfy:
+
+- `internal/activator/activator.go` `Service.serveWakeError`: diagnostic, task C,J4. Basis: rev3=PROPOSED-seed; incarnation-keyed missing-files diagnostics and indexed retry results; throttles output only and grants no retry, stop or launch;rev3=census-ruling-region-ha-p1a;basis=the agent as carlos: one more case, errLeaseRefused (a born-HA host outside the nested layout or an HA acquire's refusal): logged at most once per diagnostic window (allowFilesDiagnostic(rt.Host, ...)) and answered 503 with Retry-After: 10; the other cases unchanged; +registry:Host x2 are rt.Host in that call and the log line; it only answers;rev3=census-ruling-rootfs-apps-3;basis=rootfs Plan 3 Tasks 7 and 8: two new answers, a resident inside its backoff gets 503 with Retry-After (RFS-3-C16), and a rootfs row refused before the lease (errRootfsNotAdmitted) gets the existing wake-failed 503; no read added;rev3=census-ruling-region-ha-p1b2;basis=region HA P1b-2: for a verified HA hop, a held lease answers 503 Retry-After 1 with X-Carlos-Holder (answerForwarded) and every other refusal adds X-Carlos-Holder: none (noteNoHolder); legacy routes and cancellation unchanged; same reads;rev3=census-ruling-region-ha-p3a;basis=P3a Task 3: neutral admission 503 with Retry-After before forwarded-holder diagnostics; no new read, no holder identity. Fix R1: distinguish startup from drain/shutdown using the same admission state; retain 503, Retry-After, no-store and removal of holder identity. Read sites unchanged.;rev3=census-ruling-region-ha-g2-fixes;basis=Answer latched HA loss and pool refusal with the shared unavailable response; no new read.
+
+Seal: `75fb3eb24d0bf3a8405b929675d919ec88f15386d43e9ff687ce138a7ed968a4` → `75fb3eb24d0bf3a8405b929675d919ec88f15386d43e9ff687ce138a7ed968a4`.
+
+Overlay: `internal/provision/testdata/plan14-root-reads-region-ha-shutting-down-retry.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`.
diff --git a/internal/activator/activator.go b/internal/activator/activator.go
index 1325afa63..b0528e92e 100644
--- a/internal/activator/activator.go
+++ b/internal/activator/activator.go
@@ -6540,6 +6540,15 @@ func (a *Service) serveWakeError(w http.ResponseWriter, r *http.Request, rt regi
edge.HAUnavailableResponse(w, r)
return true
}
+ // A shutdown (errShuttingDown, #292) is a closed admission, not a wake
+ // failure: today's "unavailable" answer, with its Retry-After and no
+ // holder, and no wake log line. Checked before answerForwarded, so a
+ // forwarded hop names no holder either; the first box drops its cache
+ // entry, as for any 503 without a holder (region HA spec §25.1).
+ if errors.Is(err, errShuttingDown) {
+ edge.AdmissionUnavailableResponse(w, r)
+ return true
+ }
if errors.Is(err, ErrTenantAdmission) {
if a.TenantAdmissionStarting() {
edge.AdmissionResponse(w, r)
diff --git a/internal/activator/shuttingdown_answer_test.go b/internal/activator/shuttingdown_answer_test.go
new file mode 100644
index 000000000..66ddfc88b
--- /dev/null
+++ b/internal/activator/shuttingdown_answer_test.go
@@ -0,0 +1,67 @@
+package activator
+
+import (
+ "bytes"
+ "log"
+ "net/http"
+ "net/http/httptest"
+ "strings"
+ "testing"
+)
+
+// A request that meets a shutdown (errShuttingDown, #292) is answered like a
+// closed admission: 503, Retry-After: 10, no-store and the approved
+// "unavailable" copy, with no holder named. It is not a wake failure, so it
+// logs no wake line. Before this, it fell to serveWakeError's default: 503
+// "instance failed to wake" with no Retry-After, on every edge restart
+// (region HA spec §25.1, plan Task 0).
+func TestShuttingDownAnswersRetryAfter(t *testing.T) {
+ for _, tc := range []struct {
+ name string
+ forwarded bool
+ }{{"direct", false}, {"forwarded hop", true}} {
+ t.Run(tc.name, func(t *testing.T) {
+ if tc.forwarded {
+ asForwarded(t)
+ }
+ b := &fakeBackend{}
+ a := New(Config{}, b, nil)
+ a.mu.Lock()
+ a.shuttingDown = true
+ a.mu.Unlock()
+
+ var logs bytes.Buffer
+ prev, flags := log.Writer(), log.Flags()
+ log.SetOutput(&logs)
+ t.Cleanup(func() { log.SetOutput(prev); log.SetFlags(flags) })
+
+ rt := testRoute("shop.example.com")
+ rt.HA = tc.forwarded
+ w := httptest.NewRecorder()
+ a.ServeHTTP(w, httptest.NewRequest("GET", "https://"+rt.Host+"/", nil), rt,
+ http.HandlerFunc(func(http.ResponseWriter, *http.Request) { t.Fatal("proxied during shutdown") }))
+
+ if w.Code != http.StatusServiceUnavailable {
+ t.Fatalf("status %d", w.Code)
+ }
+ if got := w.Header().Get("Retry-After"); got != "10" {
+ t.Fatalf("Retry-After %q", got)
+ }
+ if got := w.Header().Get("Cache-Control"); got != "no-store" {
+ t.Fatalf("Cache-Control %q", got)
+ }
+ if got := w.Body.String(); got != "This service is unavailable. Try again later.\n" {
+ t.Fatalf("body %q", got)
+ }
+ if got := w.Header().Get(holderHeader); got != "" {
+ t.Fatalf("holder named during shutdown: %q", got)
+ }
+ if strings.Contains(logs.String(), "activator: wake") {
+ t.Fatalf("logged as a wake failure: %s", logs.String())
+ }
+ if b.acquires != 0 || b.restores != 0 {
+ t.Fatal("tenant work during shutdown")
+ }
+ })
+ }
+}
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv
index 5217f22f9..53bed2beb 100644
--- a/internal/provision/testdata/plan14-root-reads-chain.tsv
+++ b/internal/provision/testdata/plan14-root-reads-chain.tsv
@@ -129,3 +129,4 @@ plan14-root-reads-region-ha-dr5.tsv f19eb78c1da1475cbf8e11a3d6c394d828aa1c8f88ae
plan14-root-reads-instance-syscall-filter.tsv b970bb28c5a633d2572a1da549030e9258cfdabb6322ddffdd0ebf41b56c464c
plan14-root-reads-instance-restore-658-cli.tsv b970bb28c5a633d2572a1da549030e9258cfdabb6322ddffdd0ebf41b56c464c
plan14-root-reads-instance-stop-execstop-528.tsv 75fb3eb24d0bf3a8405b929675d919ec88f15386d43e9ff687ce138a7ed968a4
+plan14-root-reads-region-ha-shutting-down-retry.tsv 75fb3eb24d0bf3a8405b929675d919ec88f15386d43e9ff687ce138a7ed968a4
diff --git a/internal/provision/testdata/plan14-root-reads-region-ha-shutting-down-retry.tsv b/internal/provision/testdata/plan14-root-reads-region-ha-shutting-down-retry.tsv
new file mode 100644
index 000000000..dc5e3b907
--- /dev/null
+++ b/internal/provision/testdata/plan14-root-reads-region-ha-shutting-down-retry.tsv
@@ -0,0 +1,4 @@
+# Census overlay region-ha-shutting-down-retry, written by census-propose (#369). census-ruling-region-ha-shutting-down-retry, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-region-ha-shutting-down-retry.md.
+# 1 body, 0 sites, 1 envelope: each changed unit re-frozen at its existing disposition with its claim appended.
+internal/activator/activator.go Service.serveWakeError diagnostic C,J4 rev3=PROPOSED-seed; incarnation-keyed missing-files diagnostics and indexed retry results; throttles output only and grants no retry, stop or launch;rev3=census-ruling-region-ha-p1a;basis=the agent as carlos: one more case, errLeaseRefused (a born-HA host outside the nested layout or an HA acquire's refusal): logged at most once per diagnostic window (allowFilesDiagnostic(rt.Host, ...)) and answered 503 with Retry-After: 10; the other cases unchanged; +registry:Host x2 are rt.Host in that call and the log line; it only answers;rev3=census-ruling-rootfs-apps-3;basis=rootfs Plan 3 Tasks 7 and 8: two new answers, a resident inside its backoff gets 503 with Retry-After (RFS-3-C16), and a rootfs row refused before the lease (errRootfsNotAdmitted) gets the existing wake-failed 503; no read added;rev3=census-ruling-region-ha-p1b2;basis=region HA P1b-2: for a verified HA hop, a held lease answers 503 Retry-After 1 with X-Carlos-Holder (answerForwarded) and every other refusal adds X-Carlos-Holder: none (noteNoHolder); legacy routes and cancellation unchanged; same reads;rev3=census-ruling-region-ha-p3a;basis=P3a Task 3: neutral admission 503 with Retry-After before forwarded-holder diagnostics; no new read, no holder identity. Fix R1: distinguish startup from drain/shutdown using the same admission state; retain 503, Retry-After, no-store and removal of holder identity. Read sites unchanged.;rev3=census-ruling-region-ha-g2-fixes;basis=Answer latched HA loss and pool refusal with the shared unavailable response; no new read.;rev3=census-ruling-region-ha-shutting-down-retry;basis=Task 0: errShuttingDown (a request met by Shutdown, #292) is answered with the existing admission unavailable 503 (Retry-After: 10, no-store, holder removed), before answerForwarded, instead of the default wake-failed 503 with no Retry-After and a wake log line; no new read, read sites unchanged. registry:Host@1977,registry:Host@2041,registry:Host@3743,registry:Host@3807,whole:Route@1111 72d073d320cde353880ff27cf2ef339b83fee8c1d132e5a3c9c11da0524e9c99
+@coverage internal/activator e1afe8207c07d6fe11a46d48d8840a6e4fce521b861d6c98c7db5b69cd759a87