From f72c233a66c322bcbadb167ac3681e995df0d30a Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 28 Oct 2026 08:52:20 +0000 Subject: [PATCH 1/4] docs(cms): media on R2 in the operating contract and the epic README (PC4 record) operations.md's CMS section gains media (the buckets, the binding, the file route, what may be uploaded, the R2 token), migration 205, the resources' real prefixed names, a media verify command, and the two one-time R2 owner steps in place of "media waits on R2". The epic README reads shipped for PC0-PC5. Orun-Task: PC-7 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013JuHbkZCjDrGgHdzCrCRqG --- ai/context/operations.md | 29 ++++++++++++++++--------- specs/epics/lumen-payload-cms/README.md | 4 ++-- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/ai/context/operations.md b/ai/context/operations.md index 30a5afd..078e7c5 100644 --- a/ai/context/operations.md +++ b/ai/context/operations.md @@ -150,13 +150,20 @@ Payload CMS 3.89 on Workers (OpenNext), deployed as `lumen-payload-cms-` 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-` - (`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/`. 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 @@ -187,23 +194,25 @@ 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. ### Caveats -- **Workers Paid.** The bundle is about 3.3 MiB compressed, over Free's +- **Workers Paid.** The bundle is about 3.8 MiB compressed, over Free's 3 MiB, and Payload needs more CPU than Free's 10 ms. - **First landing of a wiring source.** The CMS's wrangler config names both environments' Hyperdrive ids, so each deploy needs the wiring of 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. ## Setting the domain later diff --git a/specs/epics/lumen-payload-cms/README.md b/specs/epics/lumen-payload-cms/README.md index 8f7d672..def415f 100644 --- a/specs/epics/lumen-payload-cms/README.md +++ b/specs/epics/lumen-payload-cms/README.md @@ -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 From ac15e2e13f0d0dbf2d20862252340dfcd8078da3 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 28 Oct 2026 09:42:27 +0000 Subject: [PATCH 2/4] docs(cms): PC4 shipped in the epic's status, PC-F resolved, PC-K recorded IMPLEMENTATION-STATUS marks PC4 shipped (#15, #16, #18) and records its departures: two tasks and three pull requests, namespace-prefixed resource names, the R2 token as a rotated project secret, abortOnLimit, no SVG and no resizing. The risks file resolves PC-F (token minted, R2 enabled), records PC-K (wrangler's provisioning reads R2 with the deploy token, fixed by stack-tectonic 0.21.0's skipResourceProvisioning) and brings PC-I up to date with the 0.21.0 pin. The operating contract names the deploy setting. Orun-Task: PC-7 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013JuHbkZCjDrGgHdzCrCRqG --- ai/context/operations.md | 4 +++ .../IMPLEMENTATION-STATUS.md | 35 +++++++++++++++++-- .../risks-and-open-questions.md | 33 ++++++++++++++--- 3 files changed, 65 insertions(+), 7 deletions(-) diff --git a/ai/context/operations.md b/ai/context/operations.md index 078e7c5..0d6d577 100644 --- a/ai/context/operations.md +++ b/ai/context/operations.md @@ -213,6 +213,10 @@ The CMS lane's smoke check asserts the first two after every deploy. 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 diff --git a/specs/epics/lumen-payload-cms/IMPLEMENTATION-STATUS.md b/specs/epics/lumen-payload-cms/IMPLEMENTATION-STATUS.md index d4cbc6a..99e5856 100644 --- a/specs/epics/lumen-payload-cms/IMPLEMENTATION-STATUS.md +++ b/specs/epics/lumen-payload-cms/IMPLEMENTATION-STATUS.md @@ -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) @@ -46,7 +46,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 @@ -56,8 +57,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-`; 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. diff --git a/specs/epics/lumen-payload-cms/risks-and-open-questions.md b/specs/epics/lumen-payload-cms/risks-and-open-questions.md index 6daba59..6bcc9dc 100644 --- a/specs/epics/lumen-payload-cms/risks-and-open-questions.md +++ b/specs/epics/lumen-payload-cms/risks-and-open-questions.md @@ -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) @@ -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) @@ -117,3 +126,17 @@ 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/`, 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. A Worker that later gains an R2 +binding needs the same setting. From 8005f737658e7625079f9ce5a081b9621ca9da24 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 28 Oct 2026 09:45:41 +0000 Subject: [PATCH 3/4] docs(cms): keep the CMS bundle size at about 3.3 MiB The stage deploy of bc8c24c reports 3356 KiB gzipped, so the operating contract's "about 3.8 MiB" was wrong; it goes back to 3.3 MiB. Orun-Task: PC-7 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013JuHbkZCjDrGgHdzCrCRqG --- ai/context/operations.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ai/context/operations.md b/ai/context/operations.md index 0d6d577..45b2ab9 100644 --- a/ai/context/operations.md +++ b/ai/context/operations.md @@ -201,7 +201,7 @@ The CMS lane's smoke check asserts the first two after every deploy. ### Caveats -- **Workers Paid.** The bundle is about 3.8 MiB compressed, over Free's +- **Workers Paid.** The bundle is about 3.3 MiB compressed, over Free's 3 MiB, and Payload needs more CPU than Free's 10 ms. - **First landing of a wiring source.** The CMS's wrangler config names both environments' Hyperdrive ids, so each deploy needs the wiring of From b0a4036cdb39a96db0124d47b7cd5951da85858f Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 28 Oct 2026 09:47:11 +0000 Subject: [PATCH 4/4] docs(cms): PC4's live verification on stage and prod Main run 40666021733 deployed the CMS with R2_MEDIA bound on both environments through the workers-deploy token: /api/media answers, an anonymous upload is refused, and the suite passed in each lane. A staff upload served back from R2 is not yet verified live, because no staff account exists until the owner opens setup; the same path passed end to end in workerd. PC-K notes the live confirmation. Orun-Task: PC-7 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013JuHbkZCjDrGgHdzCrCRqG --- .../IMPLEMENTATION-STATUS.md | 19 +++++++++++++++++++ .../risks-and-open-questions.md | 6 ++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/specs/epics/lumen-payload-cms/IMPLEMENTATION-STATUS.md b/specs/epics/lumen-payload-cms/IMPLEMENTATION-STATUS.md index 99e5856..777beac 100644 --- a/specs/epics/lumen-payload-cms/IMPLEMENTATION-STATUS.md +++ b/specs/epics/lumen-payload-cms/IMPLEMENTATION-STATUS.md @@ -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 diff --git a/specs/epics/lumen-payload-cms/risks-and-open-questions.md b/specs/epics/lumen-payload-cms/risks-and-open-questions.md index 6bcc9dc..fa9b823 100644 --- a/specs/epics/lumen-payload-cms/risks-and-open-questions.md +++ b/specs/epics/lumen-payload-cms/risks-and-open-questions.md @@ -138,5 +138,7 @@ with "Authentication error [code: 10000]" on `/r2/buckets/`, after 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. A Worker that later gains an R2 -binding needs the same setting. +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.