Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions ai/context/operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,20 @@ Payload CMS 3.89 on Workers (OpenNext), deployed as `lumen-payload-cms-<env>`
on stage and prod, beside the fleet rather than inside it: nothing routes to
it through `api-edge`, and no worker calls it.

- **Database path:** its own Hyperdrive config, `lumen-payload-cms-<env>`
(`infra/terraform/cloudflare-hyperdrive-cms`), over the same Supabase origin
- **Database path:** its own Hyperdrive config, `stg-lumen-payload-cms-stage`
and `prod-lumen-payload-cms-prod` (`infra/terraform/cloudflare-hyperdrive-cms`), over the same Supabase origin
as the fleet's, with query caching disabled so an editor reads back what they
saved. Each query or transaction opens its own client; Hyperdrive pools.
- **Schema:** `cms`, created by migration `200_cms_payload_core` in the
`db-migrate` lane, like every other schema. Payload never pushes or migrates
the database itself.
- **Schema:** `cms`, created by migrations `200_cms_payload_core` and
`205_cms_media` in the `db-migrate` lane, like every other schema. Payload
never pushes or migrates the database itself.
- **Media:** images (JPEG, PNG, GIF, WebP, AVIF) and PDFs up to 10 MiB, with
alt text, in a private R2 bucket per environment
(`stg-lumen-payload-cms-media-stage`, `prod-lumen-payload-cms-media-prod`;
`infra/terraform/cloudflare-r2-cms`), bound to the Worker as `R2_MEDIA` and
served at `/api/media/file/<filename>`. SVG is refused. The bucket component
runs with `CLOUDFLARE_R2_TOKEN` (project rung, from the Cloudflare
connection's `r2-data` template, rotated by the platform every 30 days).
- **Secrets:** `CMS_PAYLOAD_SECRET` is generated and published by
`cloudflare-hyperdrive-cms` (nobody chooses or sees it) and pushed to the
Worker as `PAYLOAD_SECRET`. `CMS_SETUP_TOKEN` exists only if the owner sets
Expand Down Expand Up @@ -187,6 +194,7 @@ curl -fsS $B/health # {"status":"ok","db":"ok"
curl -s -o /dev/null -w '%{http_code}\n' $B/admin # 200
curl -s -o /dev/null -w '%{http_code}\n' -X POST $B/api/users/first-register \
-H content-type:application/json -d '{"email":"x@example.com","password":"x"}' # 403 until setup is opened
curl -fsS "$B/api/media?limit=1" # the media collection answers
```

The CMS lane's smoke check asserts the first two after every deploy.
Expand All @@ -200,10 +208,15 @@ The CMS lane's smoke check asserts the first two after every deploy.
stage *and* prod, but `dependsOn` only orders within one environment.
Land `cloudflare-hyperdrive-cms` before the CMS (as this repository did),
or re-run the CMS lanes once both environments' apply has published.
- **Media uploads** wait on R2 (milestone PC4 of `lumen-payload-cms`): the
brokered `workers-deploy` token cannot create buckets, so an owner mints
`CLOUDFLARE_R2_TOKEN` from the Cloudflare connection's `r2-data` template
first.
- **R2 needs two owner steps, once per Cloudflare account:** enabling R2 in
the dashboard (without it a bucket apply fails with "Please enable R2 through
the Cloudflare Dashboard. (10042)"), and minting `CLOUDFLARE_R2_TOKEN` from
the `r2-data` template, because the brokered `workers-deploy` token cannot
create buckets. Both were done for this account on 2026-10-28.
- **The CMS deploys with `skipResourceProvisioning: true`** (stack-tectonic
0.21.0 or later). Without it, wrangler reads the R2 bucket with the
`workers-deploy` token before the upload and fails with "Authentication
error [code: 10000]". Any Worker that gains an R2 binding needs the same.

## Setting the domain later

Expand Down
54 changes: 52 additions & 2 deletions specs/epics/lumen-payload-cms/IMPLEMENTATION-STATUS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ the code departed from `design.md`.
| PC1 — the CMS database path | ✅ Shipped: `lumen-payload-cms-stage` and `-prod` applied, wiring and `CMS_PAYLOAD_SECRET` published | sourceplane/lumen-payload#7 |
| PC2 — the CMS schema | ✅ Shipped: `200_cms_payload_core` applied on stage and prod | sourceplane/lumen-payload#8 |
| PC3 — the CMS on Workers | ✅ Shipped: `lumen-payload-cms-stage` and `-prod` live | sourceplane/lumen-payload#9 |
| PC4 — media on R2 | ⏸ Gated: needs `CLOUDFLARE_R2_TOKEN` from the Cloudflare connection's `r2-data` template (PC-F) | — |
| PC4 — media on R2 | ✅ Shipped: buckets `stg-lumen-payload-cms-media-stage` and `prod-lumen-payload-cms-media-prod` applied, `media` live on stage and prod | sourceplane/lumen-payload#15 (bucket), #16 (media), #18 (deploy fix), #17 (record) |
| PC5 — the record | ✅ Shipped | sourceplane/lumen-payload#14 |

## Live verification (2026-10-28)
Expand All @@ -28,6 +28,25 @@ On both `https://lumen-payload-cms-stage.nexo-7be.workers.dev` and

The CMS lane's smoke check asserted the first two after each deploy.

Media (PC4), after #18's main run (40666021733) deployed both environments:

- The deploy log of each environment lists `env.R2_MEDIA` bound to that
environment's bucket (`stg-lumen-payload-cms-media-stage`,
`prod-lumen-payload-cms-media-prod`), deployed with the brokered
`workers-deploy` token and `--x-provision=false`.
- `GET /api/media` answers an empty, anonymous-readable list.
- An anonymous upload (`POST /api/media`) answers 403.
- The CMS suite (65 tests, including the media suite) passed in each lane.

**Not yet verified live: a staff upload served back from R2.** It needs a
staff account, and none exists on either environment: the admin is closed until
the owner sets `CMS_SETUP_TOKEN` and opens `/setup`. The same path ran
end to end on the built Worker in workerd with a local R2 bucket (upload, the
file served back byte for byte and present in the bucket, SVG, missing alt text
and over-limit uploads refused, editor delete refused, admin delete removing
it from the bucket). The first owner upload on stage is the live check
(`apps/cms/docs/runbook.md`, Media).

## Departures from the design

- **The wiring and the Payload secret are optional references.** The CMS
Expand All @@ -46,7 +65,8 @@ The CMS lane's smoke check asserted the first two after each deploy.
- **The CMS suite runs inside the CMS lane's build** (PC-I): the `cms`
component's `buildCommand` runs `tests/cms` after the OpenNext build, and the
suite's own `build` script runs it too, because stack-tectonic 0.20.0's
turbo-package lanes ignore their command parameters.
turbo-package lanes ignored their command parameters (0.20.1 fixed that;
this repository pins 0.21.0 since #18).
- **Landing order.** PC1, PC2 and PC3 were developed as a stack and landed one
at a time after the baseline's bootstrap finished. PC2's own run was
plan-only (lanes run only for pull requests into `main`, and it was pushed
Expand All @@ -56,8 +76,38 @@ The CMS lane's smoke check asserted the first two after each deploy.
baseline's own 04-workers phase stopped on Free's cron limit, and the owner
upgraded the account.

- **PC4 landed as two tasks and three pull requests.** PC-5 is the bucket
(`cloudflare-r2-cms`, #15) and PC-7 is the CMS side (#16), so the bucket
could apply and publish its wiring on both environments before the CMS
rendered `R2_MEDIA` (PC-J). #18 then moved the stack pin to 0.21.0 so the CMS
could deploy at all (PC-K).
- **Resource names carry the environment's namespace prefix.** The plan says
`lumen-payload-cms-media-<env>`; Terraform builds every name from the
environment's `namespacePrefix`, so the buckets are
`stg-lumen-payload-cms-media-stage` and `prod-lumen-payload-cms-media-prod`.
The same holds for the Hyperdrive configs (`stg-lumen-payload-cms-stage`,
`prod-lumen-payload-cms-prod`).
- **The R2 token is a rotated project secret.** `CLOUDFLARE_R2_TOKEN` sits on
the project's rung, minted from the `r2-data` template in rotated mode (the
platform rotates it every 30 days). It is not a value anyone pasted, and only
`cloudflare-r2-cms` reads it.
- **Uploads over the limit are refused, not truncated.** Payload's default
`upload.limits.fileSize` stops reading at the limit and stores what it has:
in the local run an 11 MiB PNG came back 201, stored cut off at the limit. The root config sets
`abortOnLimit: true`, so an upload over 10 MiB answers 413 and nothing is
stored.
- **No SVG, and no resizing.** The plan said "images". SVG is refused because
it can carry script on the admin's origin. workerd has no `sharp`, so there
is no cropping, focal point or image sizes: a file is stored and served as
uploaded.

## Found while landing

- **PC-J:** the first landing of a wiring source and its consumer in one push
races across environments. Avoided here by landing PC1 on its own; seen and
recovered on multi-tenant-saas-2.
- **PC-K:** wrangler's default resource provisioning reads every R2 bucket
binding with the deploy token, which has no R2 permission. Fixed by
stack-tectonic 0.21.0's `skipResourceProvisioning` (sourceplane/stack-tectonic#22).
- **R2 is off on a new Cloudflare account** until the owner enables it in the
dashboard (10042). This account's owner did so on 2026-10-28.
4 changes: 2 additions & 2 deletions specs/epics/lumen-payload-cms/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ read.

| Field | Value |
|-------|-------|
| Status | Shipped (PC0–PC3, PC5); PC4 gated on an `r2-data` secret |
| Status | Shipped (PC0–PC5) |
| Cluster | **PC** (PC0–PC5) |
| Owner(s) | `apps/cms` (the CMS) · `infra/terraform/cloudflare-hyperdrive-cms` (its database path) · `packages/db` (its schema, as a migration) |
| Builds on | `lumen baseline-v32` — reuses Supabase, the `db-migrate` lane and the wiring model; touches no worker |
| Changes | Adds three components and one migration. Every existing component is unchanged. |
| Decisions locked | (1) Payload is a deployable **beside** the fleet, not a bounded context inside it. (2) It reads through its **own cache-disabled Hyperdrive config**. (3) Its schema is **SQL in the `db-migrate` lane**, in schema `cms`. (4) Payload is pinned to **3.89.0**. (5) The admin is **closed by default**; the owner opens it. |
| Gate | PC1 and PC2 are invisible (a database path and a schema). PC3 is the first visible change: `/admin` and `/health` answer on stage and prod. |
| Shipped as | sourceplane/lumen-payload#6 (spec), #7 (database path), #8 (schema), #9 (the CMS), #14 (the record) |
| Shipped as | sourceplane/lumen-payload#6 (spec), #7 (database path), #8 (schema), #9 (the CMS), #14 (the record), #15 and #16 (media on R2) |

## Read order

Expand Down
35 changes: 30 additions & 5 deletions specs/epics/lumen-payload-cms/risks-and-open-questions.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,13 @@ owner, by design of the secrets model), or an owner-held setup token.
**Decided:** the setup token. It costs the owner one secret and one visit, and
it means the pipeline never holds a credential it would have to show someone.

## PC-F — Media needs a token this workspace does not have (RISK)
## PC-F — Media needs a token this workspace does not have (RESOLVED)

The `workers-deploy` token cannot create R2 buckets. PC4 waits on an
`r2-data` mint. Until then the CMS has no uploads; nothing else depends on PC4.
The `workers-deploy` token cannot create R2 buckets. The owner minted
`CLOUDFLARE_R2_TOKEN` from the Cloudflare connection's `r2-data` template
(project rung, rotated by the platform every 30 days), and enabled R2 on the
account, which a first bucket apply needs ("Please enable R2 through the
Cloudflare Dashboard. (10042)"). Both are once per account.

## PC-G — `workers.dev` and the subdomain in smoke checks (ACCEPTED)

Expand Down Expand Up @@ -101,8 +104,14 @@ For the CMS: `tests/cms`'s own `build` script runs the suite, the component
subscribes on `verify`, and the `cms` component's `buildCommand` (the worker
composition renders it correctly) runs the suite too, so every pull request that
touches the CMS runs it. Turning the other suites on is a separate change,
because it may surface failures that have gone unseen; the newer stack-tectonic
fixes the guards.
because it may surface failures that have gone unseen. stack-tectonic 0.20.1
fixed the guards, and this repository pins 0.21.0 since sourceplane/lumen-payload#18,
but the suites still subscribe on `quick-check`, so nothing changed for them.
Run locally on 2026-10-28, 16 of the 19 suites that declare a test
`preBuildCommand` pass. `api-edge-tests`, `membership-worker-tests` and
`web-console-next-tests` fail: the api-edge suite reads a rendered
`wrangler.jsonc` that is not committed, and the other two each have one suite
that fails to load.

## PC-J — The first landing of a wiring source races across environments (FOUND, avoided here)

Expand All @@ -117,3 +126,19 @@ this when it landed the whole layer in one pull request, and one re-run of the
failed lanes converged it. This repository landed the Hyperdrive component
first (PC1, its own merge), so the CMS never deployed before both wirings
existed. Any later product built from this layer should keep that order.

## PC-K — wrangler checks every R2 bucket with the deploy token (FOUND, fixed in stack-tectonic 0.21.0)

wrangler 4 provisions resources by default on `wrangler deploy`. For an R2
binding it first reads the bucket from the R2 API, unless the deployed Worker
already has that binding. The brokered `workers-deploy` token has no R2
permission, so the first CMS deploy with `R2_MEDIA` failed on stage and prod
with "Authentication error [code: 10000]" on `/r2/buckets/<name>`, after
`wire-live` had passed (main run 40659792149). There is no environment
variable or config field to turn it off, only `--x-provision=false`.
stack-tectonic 0.21.0 (sourceplane/stack-tectonic#22) added
`skipResourceProvisioning`, and the CMS sets it (sourceplane/lumen-payload#18).
Terraform owns the bucket, so nothing is lost. Main run 40666021733 then
deployed both environments with `R2_MEDIA` bound, so the Workers upload accepts
an R2 binding from a token without R2 permission; only the provisioning check
needed it. A Worker that later gains an R2 binding needs the same setting.
Loading