console: a label door read failure is 503 with C37 (M2 review P3-1)
The app, record, registry and fleet reads that fail before any write answer 503, so the CLI prints the console's C37 (nothing attempted) rather than C38. 502 stays for a record write whose outcome is unknown. Witnesses on the door and on the CLI's handling of a write's 503.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 files changed,
+32
−5
instances_cli_label_test.go+10 −0internal/console/instancelabel.go+7 −5internal/console/instancelabel_test.go+15 −0
diff --git a/instances_cli_label_test.go b/instances_cli_label_test.go| index 7d0068f6b..e3248b407 100644 |
| --- a/instances_cli_label_test.go |
| +++ b/instances_cli_label_test.go |
| @@ -403,6 +403,16 @@ func TestInstancesLabelUnknownOutcome(t *testing.T) { |
| }) |
| } |
| + // M2 review P3-1: the door's 503 is a read that failed before any |
| + // write. The CLI prints its C37 and exits non-zero, not C38. |
| + t.Run("a write's 503 is the console's own text", func(t *testing.T) { |
| + stub := newLabelStub(t, http.StatusServiceUnavailable, `{"error":"could not read the instance or its fleet, so it was not tied. try again"}`) |
| + out, ok := runLabelCLI(t, stub.ts.URL, "--app", "shop", "--account", "bab", "--box", "box-1", "shop.example.com") |
| + if ok || strings.Contains(out, labelC38) || !strings.Contains(out, "could not read the instance or its fleet, so it was not tied. try again") { |
| + t.Fatalf("want C37 and a non-zero exit, got ok=%v:\n%s", ok, out) |
| + } |
| + }) |
| + |
| t.Run("a dry run's 502 is the console's own text", func(t *testing.T) { |
| stub := newLabelStub(t, http.StatusBadGateway, `{"error":"could not read the instance or its fleet, so it was not tied. try again"}`) |
| out, ok := runLabelCLI(t, stub.ts.URL, "--app", "shop", "--account", "bab", "shop.example.com") |
diff --git a/internal/console/instancelabel.go b/internal/console/instancelabel.go| index 85e207fe5..a3816ff15 100644 |
| --- a/internal/console/instancelabel.go |
| +++ b/internal/console/instancelabel.go |
| @@ -109,7 +109,9 @@ const labelOwnerPurpose = "tie an instance to a box" // approved copy (C18), Lun |
| const claimInstanceLabelUnsupportedMsg = "tying instances to boxes is not available on this console" // approved copy (C33), Luna review by Paul's delegation 2026-11-14 |
| // msgLabelReadFailed is the door's answer when it cannot read the app, the |
| -// record or the fleet before it has an answer to give. |
| +// record or the fleet before it has an answer to give. It is a 503: nothing |
| +// was attempted, so the CLI prints it (C37) rather than C38 (M2 review |
| +// P3-1); 502 is kept for a record write whose outcome is unknown. |
| const msgLabelReadFailed = "could not read the instance or its fleet, so it was not tied. try again" // approved copy (C37), Luna review by Paul's delegation 2026-11-14 |
| // msgLabelUnknown is the door's answer when the record write failed in a |
| @@ -137,7 +139,7 @@ func (s *Server) handleAPIInstanceLabel(w http.ResponseWriter, r *http.Request) |
| found, err := s.store.HasAppIn(acct.ID, app) |
| if err != nil { |
| log.Printf("console: api instance label %s/%s: has-app: %v", acct.Sqid, app, err) |
| - jsonError(w, http.StatusBadGateway, msgLabelReadFailed) |
| + jsonError(w, http.StatusServiceUnavailable, msgLabelReadFailed) |
| return |
| } |
| if !found { |
| @@ -181,7 +183,7 @@ func (s *Server) handleAPIInstanceLabel(w http.ResponseWriter, r *http.Request) |
| return |
| case err != nil: |
| log.Printf("console: api instance label %s/%s/%s: read: %v", acct.Sqid, app, host, err) |
| - jsonError(w, http.StatusBadGateway, msgLabelReadFailed) |
| + jsonError(w, http.StatusServiceUnavailable, msgLabelReadFailed) |
| return |
| case rec.Retired: |
| http.NotFound(w, r) |
| @@ -200,13 +202,13 @@ func (s *Server) handleAPIInstanceLabel(w http.ResponseWriter, r *http.Request) |
| reg, err := s.openPassRegistry() |
| if err != nil { |
| log.Printf("console: api instance label %s/%s/%s: registry: %v", acct.Sqid, app, host, err) |
| - jsonError(w, http.StatusBadGateway, msgLabelReadFailed) |
| + jsonError(w, http.StatusServiceUnavailable, msgLabelReadFailed) |
| return |
| } |
| f, err := reg.GetFleet(fleet) |
| if err != nil { |
| log.Printf("console: api instance label %s/%s/%s: fleet %s: %v", acct.Sqid, app, host, fleet, err) |
| - jsonError(w, http.StatusBadGateway, msgLabelReadFailed) |
| + jsonError(w, http.StatusServiceUnavailable, msgLabelReadFailed) |
| return |
| } |
| if f == nil || f.Account != acct.Sqid { |
diff --git a/internal/console/instancelabel_test.go b/internal/console/instancelabel_test.go| index 3b2f5272e..33957de1f 100644 |
| --- a/internal/console/instancelabel_test.go |
| +++ b/internal/console/instancelabel_test.go |
| @@ -720,3 +720,18 @@ func TestLabelDoorCoordinatorFoundByTheWriterIsNamed(t *testing.T) { |
| t.Fatalf("answer %+v; want coordinator_box pi-2", a) |
| } |
| } |
| + |
| +// M2 review P3-1 (Fable): a read that fails before any write is 503 with |
| +// C37, so the CLI says nothing was attempted rather than C38. |
| +func TestLabelDoorReadFailureIs503(t *testing.T) { |
| + fx, token, reg, created := labelWorld(t, "code-ld-read-503", "pi-1", "pi-2") |
| + servingEvidence(t, fx, reg, created, "pi-1") |
| + fx.srv.cfg.Releases = &getFailStore{Store: fx.srv.cfg.Releases, key: provision.RecordKey(fx.sqid, "shop", labelHost), n: -1} |
| + code, _, raw := rawReq(t, http.MethodPost, labelURL(fx, labelHost), token, labelBody("pi-1", false)) |
| + if code != http.StatusServiceUnavailable || errorOf(t, raw) != "could not read the instance or its fleet, so it was not tied. try again" { |
| + t.Fatalf("a failed read = %d %s; want 503 with C37", code, raw) |
| + } |
| + if b := boxRow(t, reg, "pi-1"); b.LabelledAt != 0 { |
| + t.Fatal("pi-1 was marked") |
| + } |
| +} |