carlos / platform Public

platform-host: bind the default manifest to its app; keep real refusals

The door's in-memory default manifest now carries the app incarnation its
own gate captured before it read the manifest and the app's HA row.
instanceManifest uses it only when the create handler's own admission and
the live row are that same incarnation; an app trashed, purged and
recreated under the name meanwhile gets the family's 404 and nothing is
written. No lock is added. A platformSeams hook between the door's reads
and the delegation drives the witness. The readEnableManifest and
haManifestBinding comments name the lock-free caller.

The CLI returns *enableError from platform-host only for 404 (an older
console) and 503 (no apps domain); every other refusal, a cap or a host
already held, is a plain error with the door's sentence, so the deploy
stops on it instead of on "no static host".

Also: a born-HA app with no manifest gets its row's pool and region on the
record (new test), and the decode error is a copy row,
PlatformHostUnreadable (pending copy review).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev ed350cade730563e3b799e738457e87eb9106512 parent c2c3667
9 files changed, +177 −19
  • deploy_platformhost.go +15 −7
  • deploy_test.go +26 −0
  • docs/superpowers/plans/2026-11-19-platform-accounts-1-platform-layer.md +2 −1
  • internal/console/apiinstances.go +9 −5
  • internal/console/apiplatformhost.go +48 −5
  • internal/console/apiplatformhost_test.go +64 −0
  • internal/console/hapool.go +4 −1
  • internal/console/platform_seams.go +5 −0
  • platform_copy.go +4 −0
diff --git a/deploy_platformhost.go b/deploy_platformhost.go
index 0873385b4..098bf2ed8 100644
--- a/deploy_platformhost.go
+++ b/deploy_platformhost.go
@@ -13,11 +13,15 @@ import (
// person gets through the instances-manifest door, which is person-only.
// The door's answer is the create door's, so the record decodes the same.
//
-// A refusal is an *enableError: it carries the status, so mintPlatformHost
-// can tell an older console (404) from a real refusal, and runDeploy's
-// enableUnavailable reads this door's "no platform host here" answers (503
-// no apps domain, 409 an instance domain an operator pinned) as it reads
-// the manifest door's.
+// Only the refusals the deploy's fallbacks act on are an *enableError, which
+// carries the status: 404 (a console without this door, which
+// mintPlatformHost answers with the manifest door's 403) and 503 (no apps
+// domain, which runDeploy's enableUnavailable turns into its own refusal).
+// Every other refusal is a plain error with the door's sentence, so a cap,
+// a host already held or another operation in progress stops the deploy
+// saying so, as the person path's create does. The 409 for an instance
+// domain an operator pinned elsewhere is among them: no code tells it apart
+// from the create's own 409s.
func (s *apiSession) platformHost(ctx context.Context, a apiAcct, app, channel, message string) (apiInstanceRecord, error) {
in := struct {
Channel string `json:"channel"`
@@ -27,12 +31,16 @@ func (s *apiSession) platformHost(ctx context.Context, a apiAcct, app, channel,
if err != nil {
return apiInstanceRecord{}, err
}
- if status != http.StatusCreated {
+ switch status {
+ case http.StatusCreated:
+ case http.StatusNotFound, http.StatusServiceUnavailable:
return apiInstanceRecord{}, &enableError{status: status, msg: apiErrorFromBody(status, body).Error()}
+ default:
+ return apiInstanceRecord{}, apiErrorFromBody(status, body)
}
var out apiInstanceRecord
if err := json.Unmarshal(body, &out); err != nil {
- return apiInstanceRecord{}, fmt.Errorf("platform host: unreadable response: %w", err)
+ return apiInstanceRecord{}, fmt.Errorf(cliPlatformCopyPlatformHostUnreadable, err)
}
return out, nil
}
diff --git a/deploy_test.go b/deploy_test.go
index 376caa951..2b97152ec 100644
--- a/deploy_test.go
+++ b/deploy_test.go
@@ -1903,6 +1903,32 @@ func TestMintPlatformHostOnAnOlderConsole(t *testing.T) {
}
}
+// A customer account at its running-things cap is refused by the create
+// behind platform-host with a 409. That is a real refusal, not "this
+// deployment has no platform host": the deploy must stop on the cap's own
+// sentence, not fall back to the no-static-host refusal (Fable r1 on Task 12).
+func TestMintPlatformHostCapRefusalIsNotUnavailable(t *testing.T) {
+ const capMsg = "this account has 3 apps and instances running, the most its plan allows"
+ ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ switch {
+ case strings.HasSuffix(r.URL.Path, "/instances-manifest"):
+ w.WriteHeader(http.StatusForbidden)
+ io.WriteString(w, `{"error":"this credential holds role \"publish\"; this door needs one of []"}`)
+ case strings.HasSuffix(r.URL.Path, "/platform-host"):
+ w.WriteHeader(http.StatusConflict)
+ json.NewEncoder(w).Encode(map[string]string{"error": capMsg, "code": "cap"})
+ default:
+ t.Errorf("unexpected %s %s", r.Method, r.URL.Path)
+ }
+ }))
+ defer ts.Close()
+
+ _, err := mintPlatformHost(context.Background(), newTestSession(ts.URL), apiAcct{Seg: "bab"}, "mysite", "edge")
+ if err == nil || enableUnavailable(err) || err.Error() != capMsg {
+ t.Fatalf("err = %v (unavailable %v), want the cap's own refusal %q, never classified unavailable", err, enableUnavailable(err), capMsg)
+ }
+}
+
// ---- the build probe: watching the app's own report, not the edge's header --
// TestWatchProbeMatchesAWholeToken: the probe body must carry the build as a
diff --git a/docs/superpowers/plans/2026-11-19-platform-accounts-1-platform-layer.md b/docs/superpowers/plans/2026-11-19-platform-accounts-1-platform-layer.md
index 990e7abd6..79c1bfbeb 100644
--- a/docs/superpowers/plans/2026-11-19-platform-accounts-1-platform-layer.md
+++ b/docs/superpowers/plans/2026-11-19-platform-accounts-1-platform-layer.md
@@ -1357,6 +1357,7 @@ Every row is pending copy review (Task 15). `%s`/`%d` are filled as named. CLI e
| SqidRequired | %s requires an account sqid |
| SqidInvalid | %s %q is not an account sqid |
| HelpLine | customer accounts a platform runs: customers \| credentials |
+| PlatformHostUnreadable | platform host: unreadable response: %w |
| accounts plan: cliPlanCopySourcePlatform | set by its platform account: %s (lives in `accounts_plan_copy.go` with the other `cliPlanCopy*` constants; pre-flight C6) |
A grant with no plans (no plan catalog) prints no `LabelPlans` or `LabelDefault` line in `carlos accounts platform`; a customer with no plan gets `CreatedNoPlan`, no PLAN or USAGE column, and the bare `ShowHeading` with no `plan` line or usage section. See the Task 1 no-catalog mocks (pre-flight C17).
@@ -1365,7 +1366,7 @@ Task 1's UX pass (2026-11-19) changed the text of `ValueByOn`, `LabelPlans`, `La
Task 11 added, all pending copy review: `FlagCreateRef` (`--ref` on `customers create`, where it is also what makes a retry safe: create is idempotent only on the ref, Task 8), `CreateRetry` (the last lines of `carlos platform`'s usage, which is otherwise command syntax), `HelpLine` (`platform`'s line in `carlos help`, under "Your deployment" after `services`; Task 11 follow-up), and `SqidRequired`/`SqidInvalid` (the CLI's refusal of a missing or malformed `--platform` or `--customer` before anything is sent, `%s` the flag; worded as the existing `--account` refusals in `store.go`).
-Task 12 added `host.not_static` (pending copy review): the platform-host door's 422 for a channel whose head is a release that is not a static site, filled with the channel and that release's version. The brief listed this refusal among the door's witnesses, but the create handler has no such check for a static record (`staticHeadRefusal` refuses only an instance on a static head), so the door makes it, read-only, before delegating.
+Task 12 also added `PlatformHostUnreadable` (pending copy review; fix round 1, Astra minor): the deploy's error when the platform-host door's answer cannot be decoded. Task 12 added `host.not_static` (pending copy review): the platform-host door's 422 for a channel whose head is a release that is not a static site, filled with the channel and that release's version. The brief listed this refusal among the door's witnesses, but the create handler has no such check for a static record (`staticHeadRefusal` refuses only an instance on a static head), so the door makes it, read-only, before delegating.
Task 6 added `ReasonRequired` (the CLI's refusal of `--grant` or `--revoke` without `--reason`, before anything is sent; the text of the console's `grant.reason`), `ReasonAlone` (its refusal of `--reason` with neither, pending copy review; Task 6 fix round 1) and `Usage` (the `platform` line in `carlos accounts`' usage).
diff --git a/internal/console/apiinstances.go b/internal/console/apiinstances.go
index 3fb00647b..9558740c6 100644
--- a/internal/console/apiinstances.go
+++ b/internal/console/apiinstances.go
@@ -165,10 +165,10 @@ func (s *Server) instanceManifest(ctx context.Context, w http.ResponseWriter, ac
return m, true
case errors.Is(err, os.ErrNotExist):
// The platform-host door's default manifest (apiplatformhost.go):
- // admission for this one request, never written. Read here and
- // nowhere else.
- if dm, ok := ctx.Value(defaultManifestKey{}).(*provision.Manifest); ok && dm != nil {
- return dm, true
+ // admission for this one request, never written, and only for the
+ // app incarnation it was read from. Read here and nowhere else.
+ if d, ok := ctx.Value(defaultManifestKey{}).(defaultManifest); ok {
+ return s.admitDefaultManifest(ctx, w, acct, app, d)
}
// Membership (or binding) is already proven, so this may name its
// cause and the operator act that fixes it.
@@ -3807,7 +3807,11 @@ func (s *Server) instancesDomain(acct *Account) (string, *doorRefusal) {
}
// readEnableManifest is the enable door's read, under beginCopiesMutation's
-// lock: app's manifest and the etag the write is guarded by. An absent
+// lock: app's manifest and the etag the write is guarded by. The
+// platform-host door (apiplatformhost.go) also calls it, with no lock and
+// for the read alone: its result is bound to the incarnation the door's
+// gate captured first, and instanceManifest uses it only while the app is
+// still that incarnation (admitDefaultManifest). An absent
// manifest is the FIRST create (created true): a new one under domain. A
// manifest under any other domain is refused. haManifestBinding then binds
// (first create) or checks (update) a born-HA app's Pool and Regions.
diff --git a/internal/console/apiplatformhost.go b/internal/console/apiplatformhost.go
index 3d87e139a..b33e2add9 100644
--- a/internal/console/apiplatformhost.go
+++ b/internal/console/apiplatformhost.go
@@ -37,11 +37,48 @@ import (
// instanceManifest, its only reader (TestDefaultManifestKeyIsReadOnlyByInstanceManifest).
type defaultManifestKey struct{}
+// defaultManifest is the value under defaultManifestKey: the manifest, and
+// the app incarnation the door's own gate admitted before it read the row
+// that manifest binds (haManifestBinding: a born-HA app's pool and region).
+type defaultManifest struct {
+ m *provision.Manifest
+ admitted copiesAdmission
+}
+
// withDefaultManifest is ctx carrying m as the manifest instanceManifest
-// answers when the app has none in the bucket. handleAPIPlatformHost is its
-// only caller.
-func withDefaultManifest(ctx context.Context, m *provision.Manifest) context.Context {
- return context.WithValue(ctx, defaultManifestKey{}, m)
+// answers when the app has none in the bucket, bound to the incarnation in
+// admitted. handleAPIPlatformHost is its only caller.
+func withDefaultManifest(ctx context.Context, m *provision.Manifest, admitted copiesAdmission) context.Context {
+ return context.WithValue(ctx, defaultManifestKey{}, defaultManifest{m: m, admitted: admitted})
+}
+
+// admitDefaultManifest is instanceManifest's answer for the door's default
+// manifest (Astra r1 on Task 12): d.m only when the app under the name is
+// still the incarnation the door read it from. That means the create
+// handler's own admission (captured by its gate, and the one its locks check
+// later) and the live row now must both be that incarnation. An app trashed,
+// purged and recreated under the same name since the door's read is another
+// app, and the binding read from the old row is not its policy: the stdlib
+// 404, the family's answer for an app that is not there, with nothing
+// written. A row that cannot be read is the manifest read's own 502. It
+// writes the refusal itself; ok=false means it did.
+func (s *Server) admitDefaultManifest(ctx context.Context, w http.ResponseWriter, acct *Account, app string, d defaultManifest) (*provision.Manifest, bool) {
+ create, present := ctx.Value(copiesAdmissionKey{}).(copiesAdmission)
+ inc, live, err := s.store.AppIncarnationContext(ctx, acct.ID, app)
+ if err != nil {
+ log.Printf("console: platform host %s/%s: read the app's incarnation: %v", acct.Sqid, app, err)
+ jsonError(w, http.StatusBadGateway, "could not read instance settings")
+ return nil, false
+ }
+ read := d.admitted
+ same := func(a copiesAdmission) bool {
+ return a.valid && a.captureErr == nil && a.account == acct.ID && a.app == app && a.incarnation == read.incarnation
+ }
+ if !present || !same(read) || !same(create) || !live || inc != read.incarnation {
+ http.NotFound(w, nil) // it reads nothing from the request
+ return nil, false
+ }
+ return d.m, true
}
// platformHostRequest is the door's whole body: unknown fields are refused,
@@ -94,7 +131,13 @@ func (s *Server) handleAPIPlatformHost(w http.ResponseWriter, r *http.Request) {
})
createCtx := r.Context()
if absent {
- createCtx = withDefaultManifest(createCtx, m)
+ // apiAccountApp captured the app's incarnation into r before the
+ // manifest and row reads above; the default is bound to it.
+ admitted, _ := r.Context().Value(copiesAdmissionKey{}).(copiesAdmission)
+ createCtx = withDefaultManifest(createCtx, m, admitted)
+ }
+ if s.platformHostBeforeCreate != nil {
+ s.platformHostBeforeCreate()
}
create := r.Clone(createCtx)
create.Body = io.NopCloser(bytes.NewReader(body))
diff --git a/internal/console/apiplatformhost_test.go b/internal/console/apiplatformhost_test.go
index fcc02af02..1800e07e8 100644
--- a/internal/console/apiplatformhost_test.go
+++ b/internal/console/apiplatformhost_test.go
@@ -331,3 +331,67 @@ func TestDefaultManifestKeyIsReadOnlyByInstanceManifest(t *testing.T) {
t.Errorf("withDefaultManifest appears in %q, want only its declaration and handleAPIPlatformHost: %q", setterAt, wantSetter)
}
}
+
+// TestPlatformHostDefaultIsBoundToTheAppItWasReadFrom (Astra r1 on Task 12):
+// the door reads the manifest and the app's row with no lock, so the app
+// can be trashed, purged and recreated under the same name before the
+// create runs. The default manifest belongs to the incarnation the door
+// admitted, so the create is refused with the family's 404 and writes
+// nothing: no record, no manifest, no audit row, no serial bump.
+func TestPlatformHostDefaultIsBoundToTheAppItWasReadFrom(t *testing.T) {
+ fx := platformHostFixture(t)
+ tok := serviceToken(t, fx.st, OpsAccountID, "ci", "", svcrole.Publish)
+ var before platformHostState
+ fx.srv.platformHostBeforeCreate = func() {
+ if err := fx.st.TrashAppRow(OpsAccountID, "site", time.Now()); err != nil {
+ t.Error(err)
+ }
+ if err := fx.st.PurgeAppRow(OpsAccountID, "site"); err != nil {
+ t.Error(err)
+ }
+ if _, err := fx.st.CreateAppIn(OpsAccountID, "site", "paul@keymail.dev", time.Now()); err != nil {
+ t.Error(err)
+ }
+ before = platformHostSnapshot(t, fx)
+ }
+ status, _, out := rawReq(t, http.MethodPost, platformHostURL(fx, "site"), tok, `{"channel":"edge"}`)
+ if status != http.StatusNotFound || out != "404 page not found\n" {
+ t.Fatalf("platform-host across a recreate = %d %q, want the stdlib 404", status, out)
+ }
+ after := platformHostSnapshot(t, fx)
+ if !after.manifestAbsent {
+ t.Error("a manifest was written")
+ }
+ if !reflect.DeepEqual(after.events, before.events) {
+ t.Errorf("audit rows written:\n before %+v\n after %+v", before.events, after.events)
+ }
+ if after.serial != before.serial || after.etag != before.etag {
+ t.Errorf("control/serial bumped: %q (%s) -> %q (%s)", before.serial, before.etag, after.serial, after.etag)
+ }
+ if _, err := provision.GetRecord(context.Background(), fx.rel, fx.sqid, "site", platformHostOf(fx, "site")); err == nil {
+ t.Error("a record was written for the recreated app")
+ }
+}
+
+// TestPlatformHostBindsABornHAAppsPoolAndRegion (Fable r1 on Task 12): a
+// born-HA app with no manifest takes its pool and region from its row,
+// in memory (readEnableManifest, haManifestBinding), and the static record
+// the door's create writes carries them. The world's HA region is the home,
+// the region a static create naming none lands in.
+func TestPlatformHostBindsABornHAAppsPoolAndRegion(t *testing.T) {
+ w := haEnableWorld(t, "ie", nil)
+ w.haApp(t, "haapp", "")
+ tok := serviceToken(t, w.st, OpsAccountID, "ci", "", svcrole.Publish)
+ u := w.ts.URL + "/api/cli/apps/bab/haapp/platform-host"
+ if code, _, out := rawReq(t, http.MethodPost, u, tok, `{"channel":"edge"}`); code != http.StatusCreated {
+ t.Fatalf("platform-host = %d %s, want 201", code, out)
+ }
+ host := haEnableHost("haapp")
+ rec, err := provision.GetRecord(context.Background(), w.evidence, "bab", "haapp", host)
+ if err != nil || rec.Kind != "static" || rec.Pool != "ha" || rec.Region != "" || rec.Channel != "edge" {
+ t.Fatalf("record = %+v %v, want static in pool ha at the home region on edge", rec, err)
+ }
+ if m, _ := w.manifestOf(t, "haapp"); m != nil {
+ t.Fatalf("a manifest was written: %+v", m)
+ }
+}
diff --git a/internal/console/hapool.go b/internal/console/hapool.go
index 5f277c908..e2524926f 100644
--- a/internal/console/hapool.go
+++ b/internal/console/hapool.go
@@ -159,7 +159,10 @@ func (s *Server) haCreateChoice(p Principal, acct *Account, app, raw, place stri
// beginCopiesMutation, which holds the app lock and pins the incarnation,
// so it is the row of the app this request resolved: a trashed-and-recreated
// name reads its own row, and a plain app reborn under an HA app's name
-// inherits nothing.
+// inherits nothing. The platform-host door reads it with no lock; there the
+// row may belong to a newer incarnation than the door admitted, and
+// admitDefaultManifest refuses the create that would use it (the window is
+// accepted, not locked: Astra r1 on Task 12).
//
// A legacy app (no ha_pool on its row: every app before G6, the canaries
// included) is untouched on create and update: nil, before anything else.
diff --git a/internal/console/platform_seams.go b/internal/console/platform_seams.go
index e87276a65..9ff96c787 100644
--- a/internal/console/platform_seams.go
+++ b/internal/console/platform_seams.go
@@ -37,6 +37,11 @@ type platformSeams struct {
// finished pending mints), before the mint's insert transaction
// begins, with no lock held: a test may revoke or re-grant there.
platformCredentialBeforeInsert func()
+ // platformHostBeforeCreate, when set (tests only), is called by the
+ // platform-host door after its reads (the head, the domain, the
+ // manifest and the HA row), just before it hands the request to the
+ // create handler, with no lock held: a test may recreate the app there.
+ platformHostBeforeCreate func()
}
// platformStep runs the platformMintStep seam, if one is set.
diff --git a/platform_copy.go b/platform_copy.go
index c6bd8d405..c803a9441 100644
--- a/platform_copy.go
+++ b/platform_copy.go
@@ -11,6 +11,10 @@ package main
// they come.
const (
+ // PlatformHostUnreadable is the deploy's error for a platform-host
+ // answer it cannot decode (deploy_platformhost.go).
+ cliPlatformCopyPlatformHostUnreadable = "platform host: unreadable response: %w"
+
cliPlatformCopyNeedsConsole = "carlos %s works through a console, and this shell is in direct bucket mode\n(CARLOS_DEPLOYMENT_BUCKET/CARLOS_DEPLOYMENT_DIR is set).\nunset the store env, then run carlos auth login --console <url> or set CARLOS_SERVICE_TOKEN"
// Usage is the line `carlos accounts` prints for platform (a row this