console: D1 verifies the head manifest and refuses units first
fleetCreateLabel re-reads the channel head version through release.AuthorizedManifest and refuses with C39 (503, Retry-After 30) before any mark or write when it cannot be verified. A unit-backed record is refused with C42 before any manifest logic. Witnesses: a tampered manifest (zero writes) and a unit with no manifest.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
internal/console/apiinstances.go+4 −7internal/console/apiinstances_test.go+77 −2internal/console/fleetcreate.go+24 −5
CI failed — run details
Intent
<task-notification> <task-id>a318744e3eec06800</task-id> <tool-use-id>toolu_01AJZUGSKeAaXhhpbuHDv9uR</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ac77363b-5830-422c-9f38-d7f2540dd398/tasks/a318744e3eec06800.output</output-file> <status>completed</status> <summary>Agent "Implement Task 6 Part A: D1 creates" 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. Part A only, with no writes to move. - **Commit:** `ae17b62c` "console: no unlabelled process creates on multi-box fleets (D1)". I used `movable(rec, chHead.Manifest)`, with the stateless flag from the same manifest, not `movableVerified`. - **Tests:** all 12 new D1 tests failed first, then passed with Step 5's command. Step 7's runs and the neighbour runs pass; darwin build, vet and gofmt are clean. - **Concerns:** 1. **Extra test runs.** Two-box test setups (`fleetBoxWorld`, `copiesWorld`, the host e2e world) needed the record floor, and their "created unlabelled" checks now expect C39. To check those edits I ran every test in the affected console files once and `./internal/host -run TestTwoBoxFleetEndToEnd_Real`. That is outside your run list; all passed. 2. **C42 can't be reached through the door today.** It never sets `Hibernate` or `Unit` on a binary, so the stateful case and the Q11 half of the stateless test call `fleetCreateLabel` directly. 3. **`chHead.Manifest` isn't digest-checked** against the signed promotion record, as `AuthorizedManifest` would be. 4. **Creates stop during the roll.** Until every active box and the console run v0.35.4 (still provisional), every process create on a multi-box fleet gets 503 C39. A fleet whose registry can't be read gets it too. 5. **Copy not reviewed.** C39, C42 and the console's own copy of C31's reasons are drafts that need Paul's copy review. - **Report:** /home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-record-labels/.superpowers/sdd/2026-11-14-fleet-record-labels/task-6a-report.md</result> <usage><subagent_tokens>239453</subagent_tokens><tool_uses>94</tool_uses><duration_ms>2312041</duration_ms></usage> </task-notification>
Attributed to this commit: 18.2 g CO₂e (2,218,501 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on fleet-record-labels-m2, 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/console/apiinstances.go b/internal/console/apiinstances.go| index 2cfda245e..4f68ff250 100644 |
| --- a/internal/console/apiinstances.go |
| +++ b/internal/console/apiinstances.go |
| @@ -2525,18 +2525,15 @@ func (s *Server) handleAPIInstanceCreate(w http.ResponseWriter, r *http.Request) |
| // |
| // On a fleet with two or more active boxes a process create is labelled |
| // or refused here (fleetCreateLabel): every check above reads, and |
| - // nothing has been written yet. The channel head's manifest decides an |
| - // always-on binary's eligibility and a stateless release's box. |
| + // nothing has been written yet. The channel head's manifest, verified |
| + // against its signed promotion record, decides an always-on binary's |
| + // eligibility and a stateless release's box. |
| // |
| // On a host-claim console D1 is off, as before it: a static record, a |
| // record the platform cannot move (rule 11), no box to choose and a mark |
| // that fails all leave the record unlabelled. |
| if fleetName != "" && s.fleetCreateApplies(fleetSeen, fleetErr, rec) { |
| - var head *release.Manifest |
| - if chHead != nil { |
| - head = chHead.Manifest |
| - } |
| - if ref := s.fleetCreateLabel(ctx, reg, fleetName, fleetSeen, fleetErr, &rec, head); ref != nil { |
| + if ref := s.fleetCreateLabel(ctx, reg, fleetName, fleetSeen, fleetErr, &rec, chHead); ref != nil { |
| if ref.Msg == msgFleetCreateUnavailable(fleetName) { |
| w.Header().Set("Retry-After", fleetCreateRetryAfter) // C39 only |
| } |
diff --git a/internal/console/apiinstances_test.go b/internal/console/apiinstances_test.go| index 8f23835c7..eaa573951 100644 |
| --- a/internal/console/apiinstances_test.go |
| +++ b/internal/console/apiinstances_test.go |
| @@ -3233,7 +3233,7 @@ func TestCreateRefusesAlwaysOnStatefulOnMultiBox(t *testing.T) { |
| c.mut(&rec) |
| } |
| v, verr := fx.srv.loadFleetView(ctx, "pi") |
| - ref := fx.srv.fleetCreateLabel(ctx, reg, "pi", v, verr, &rec, head.Manifest) |
| + ref := fx.srv.fleetCreateLabel(ctx, reg, "pi", v, verr, &rec, head) |
| want := "a.example.com cannot run on a fleet with more than one box: " + c.reason |
| if ref == nil || ref.Status != http.StatusConflict || ref.Msg != want { |
| t.Fatalf("refusal %+v; want 409 %q", ref, want) |
| @@ -3264,7 +3264,7 @@ func TestCreateLabelsAlwaysOnStateless(t *testing.T) { |
| t.Fatal("an always-on binary is movable without its manifest") |
| } |
| v, verr := fx.srv.loadFleetView(ctx, "pi") |
| - if ref := fx.srv.fleetCreateLabel(ctx, reg, "pi", v, verr, &rec, head.Manifest); ref != nil { |
| + if ref := fx.srv.fleetCreateLabel(ctx, reg, "pi", v, verr, &rec, head); ref != nil { |
| t.Fatalf("refusal %+v; want labelled", ref) |
| } |
| wantLabel(t, &rec, "pi-1") |
| @@ -3324,3 +3324,78 @@ func TestCreateOnOneBoxFleetUnchanged(t *testing.T) { |
| t.Fatal("pi-1 marked labelled") |
| } |
| } |
| + |
| +// Fix round 1: the channel head's manifest is changed in the bucket after |
| +// its signed promotion. D1 verifies it (release.AuthorizedManifest) before |
| +// it decides anything, so the create is refused with C39 and nothing is |
| +// written or marked. |
| +func TestCreateRefusesATamperedManifest(t *testing.T) { |
| + ctx := context.Background() |
| + fx, token, reg := d1World(t, "code-d1-tampered", "pi-1", "pi-2") |
| + shipVersion(t, fx, "shop", "v1") |
| + seedChannel(t, fx, "shop", "edge", "v1") |
| + key := release.ManifestKey(fx.sqid, "shop", "v1") |
| + raw, etag, err := fx.rel.Get(ctx, key) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + var m map[string]any |
| + if err := json.Unmarshal(raw, &m); err != nil { |
| + t.Fatal(err) |
| + } |
| + m["built_at"] = "2026-11-14T00:00:00Z" // any change to the signed bytes |
| + changed, err := json.Marshal(m) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, err := fx.rel.Put(ctx, key, changed, etag); err != nil { |
| + t.Fatal(err) |
| + } |
| + fx.forgetFrame("shop") |
| + if _, err := release.AuthorizedManifest(ctx, fx.rel, fx.srv.cfg.ReleasePub, fx.sqid, "shop", "v1"); err == nil { |
| + t.Fatal("the changed manifest still verifies") |
| + } |
| + cs := newCountStore(fx.srv.cfg.Releases) |
| + fx.srv.cfg.Releases = cs |
| + code, hdr, out := rawReq(t, http.MethodPost, instancesURL(fx, fx.sqid, "shop"), token, `{"host":"a.example.com","environment":"prod"}`) |
| + if code != http.StatusServiceUnavailable || hdr.Get("Retry-After") != "30" || errorOf(t, out) != fleetCreateC39 { |
| + t.Fatalf("create = %d (Retry-After %q) %s; want 503, Retry-After 30 and C39", code, hdr.Get("Retry-After"), out) |
| + } |
| + if n := cs.putsAll(); n != 0 { |
| + t.Fatalf("a refused create made %d writes: %v", n, cs.puts) |
| + } |
| + noShopRecord(t, fx, "a.example.com") |
| + if rt, err := reg.Get("a.example.com"); err != nil || rt != nil { |
| + t.Fatalf("route for a refused create: %+v, %v", rt, err) |
| + } |
| + for _, b := range []string{"pi-1", "pi-2"} { |
| + if boxRow(t, reg, b).LabelledAt != 0 { |
| + t.Fatalf("%s marked labelled", b) |
| + } |
| + } |
| +} |
| + |
| +// Fix round 1: a unit-backed record is refused with C42 even with no |
| +// manifest at all (no release shipped yet), though movable alone would |
| +// admit one with default hibernation. |
| +func TestCreateRefusesAUnitWithNoManifest(t *testing.T) { |
| + ctx := context.Background() |
| + fx, _, reg := d1World(t, "code-d1-unit-nil", "pi-1", "pi-2") |
| + rec := provision.Record{Schema: 1, Host: "a.example.com", Slug: "a", App: "shop", Account: fx.sqid, |
| + Region: "fleet/pi", Channel: "edge", CreatedAt: time.Now().UTC(), Unit: "shop.service"} |
| + if !movable(rec) { |
| + t.Fatal("movable alone refuses it; the witness needs the gap") |
| + } |
| + v, verr := fx.srv.loadFleetView(ctx, "pi") |
| + ref := fx.srv.fleetCreateLabel(ctx, reg, "pi", v, verr, &rec, nil) |
| + want := "a.example.com cannot run on a fleet with more than one box: it runs as a system unit" |
| + if ref == nil || ref.Status != http.StatusConflict || ref.Msg != want { |
| + t.Fatalf("refusal %+v; want 409 %q", ref, want) |
| + } |
| + wantNoLabel(t, &rec) |
| + for _, b := range []string{"pi-1", "pi-2"} { |
| + if boxRow(t, reg, b).LabelledAt != 0 { |
| + t.Fatalf("%s marked labelled", b) |
| + } |
| + } |
| +} |
diff --git a/internal/console/fleetcreate.go b/internal/console/fleetcreate.go| index d2a533a4d..8b8df7a73 100644 |
| --- a/internal/console/fleetcreate.go |
| +++ b/internal/console/fleetcreate.go |
| @@ -65,19 +65,38 @@ func (s *Server) fleetCreateApplies(v fleetView, verr error, rec provision.Recor |
| } |
| // fleetCreateLabel is D1's decision for rec on fleet, whose view (v, verr) |
| -// the caller read under the fleet's lock and still holds. m is the |
| -// channel head's manifest the create follows (nil when there is none yet). |
| -// In order: a record the platform cannot place or move is C42 (409); then |
| -// an incomplete view, sidecars on the fleet, any active box or the console |
| +// the caller read under the fleet's lock and still holds. head is the |
| +// channel head the create follows (nil when there is none yet); only its |
| +// version is trusted. In order: a unit-backed record is C42 (409), whatever |
| +// its manifest; the head's manifest is read again and verified against its |
| +// signed promotion record (release.AuthorizedManifest), and one that cannot |
| +// be is C39 (503); a record the platform cannot place or move, judged with |
| +// that verified manifest, is C42; then an incomplete view, sidecars on the fleet, any active box or the console |
| // below release.FleetRecordLabelFloor (fleetAtRecordFloor, the label |
| // door's check), no destination, and a failed mark are C39 (503), with the |
| // stateless publication refusal between the destination and the mark. |
| // Otherwise the box is marked labelled and rec carries it (FleetBox, |
| // FleetBoxAt). A new record has no data, so it is not FleetBoxMoved: an |
| // empty first start is right for it. |
| -func (s *Server) fleetCreateLabel(ctx context.Context, reg consoleRegistry, fleet string, v fleetView, verr error, rec *provision.Record, m *release.Manifest) *doorRefusal { |
| +func (s *Server) fleetCreateLabel(ctx context.Context, reg consoleRegistry, fleet string, v fleetView, verr error, rec *provision.Record, head *channelHead) *doorRefusal { |
| unavailable := &doorRefusal{Status: http.StatusServiceUnavailable, Msg: msgFleetCreateUnavailable(fleet)} |
| tag := fmt.Sprintf("console: api instances create %s/%s/%s: fleet %s", rec.Account, rec.App, rec.Host, fleet) |
| + // A system unit is never placed on one box (movable admits one with |
| + // default hibernation when it is asked without a manifest). |
| + if rec.Unit != "" { |
| + return &doorRefusal{Status: http.StatusConflict, Msg: msgFleetCreateUnplaceable(rec.Host, unmovableReasonText["unit"])} |
| + } |
| + // The head's manifest was read without its digest checked |
| + // (readChannelHead): only the verified one decides eligibility and the |
| + // stateless destination. |
| + var m *release.Manifest |
| + if head != nil { |
| + var err error |
| + if m, err = release.AuthorizedManifest(ctx, s.cfg.Releases, s.cfg.ReleasePub, rec.Account, rec.App, head.Version); err != nil || m == nil { |
| + log.Printf("%s: manifest %s cannot be verified (%v); refused", tag, head.Version, err) |
| + return unavailable |
| + } |
| + } |
| ok := movable(*rec) |
| if m != nil { |
| ok = movable(*rec, m) |