Skip to content

infra: Add Workers Previews config blocks to all four workers - #683

Merged
Zach Dunn (zachdunn) merged 8 commits into
mainfrom
claude/cloudflare-workers-previews-8e9af2
Aug 17, 2026
Merged

infra: Add Workers Previews config blocks to all four workers#683
Zach Dunn (zachdunn) merged 8 commits into
mainfrom
claude/cloudflare-workers-previews-8e9af2

Conversation

@zachdunn

@zachdunn Zach Dunn (zachdunn) commented Aug 17, 2026

Copy link
Copy Markdown
Member

What

Adopts Cloudflare Workers Previews (branch environments via npx wrangler preview), just enabled on our account. Each app's wrangler.jsonc gets a previews block; CONTRIBUTING's Deployment section gets a short note.

Two facts drive the shape of the blocks, both confirmed against a live deploy:

  1. Bindings do not inherit. A preview gets only what the previews block lists — wrangler warns "configuration has diverged" for anything at top level that's missing from it. So every block spells out its full binding set: stateful bindings re-pointed at preview-tier resources, stateless/shared-safe ones repeated verbatim.
  2. Without re-pointing, previews would write production data. The preview-tier resources exist and are wired in (see below).
App Preview-tier isolation
uploads-web Own SESSION KV; UI runs against prod api/auth (what UI review wants)
uploads-api Own REGISTRY KV, D1 (uploads-preview, migrations applied), default R2 bucket, webhook queue (producer-only), AE dataset; GITHUB_CACHE deliberately shared (TTL'd public-data cache)
uploads-mcp Same preview registry/database/buckets as api, preserving their production parity
uploads-auth Own D1 (uploads-auth-preview, migrations applied); BETTER_AUTH_URL needs a per-preview override, GitHub social login can't work on preview origins

Shared on purpose (repeated verbatim, documented in config comments): BROWSER/MEDIA, FLAGS, EMAIL, rate limiters, and service bindings — service bindings always call the bound Worker's production deployment. Cron triggers and queue consumers never run in Previews. Preview secrets start unset and every secret-gated path fails closed.

Gotchas found while verifying

  • wrangler d1 migrations cannot resolve a database declared inside previews — api and auth each get a minimal wrangler.preview.jsonc used only for applying migrations to the preview D1.
  • The Astro Cloudflare adapter's generated config injects an id-less SESSION KV binding and relies on deploy-time auto-provisioning, which the Previews deployment API does not support (error 10021) — web's block pins an explicit preview-only namespace.

Setup status — complete

All resources created and ids wired in: UPLOADS_REGISTRY_PREVIEW + UPLOADS_WEB_SESSION_PREVIEW KV, uploads-preview + uploads-auth-preview D1 (all migrations applied), uploads-preview-default R2, uploads-github-webhook-preview queue. Nothing left to run.

Verification

Decision: previews stay on workers.dev URLs

Custom preview domains were considered and deliberately rejected for now. Our session cookies are .uploads.sh-scoped by design (crossSubDomainCookies in apps/auth/src/auth.ts — the only cookie shape that covers both uploads.sh and auth.uploads.sh), so any preview hostname under uploads.sh would receive real production session cookies from signed-in visitors — meaning unreviewed branch code sees live sessions. workers.dev URLs sit outside the cookie scope, so previews are cleanly logged-out. Revisiting (dedicated preview zone, or previews_enabled + Cloudflare Access with the cookie exposure accepted) is tracked in a follow-up issue.

Also deliberately out of scope

  • Dropping the legacy preview_urls: true flags — keep during transition. Note the Workers Builds bot comment below: its "Branch Preview URL" is this legacy mechanism (an aliased version URL running against production bindings), not a Workers Preview — only npx wrangler preview gets the isolated preview-tier resources from this PR.

Workers Previews (branch environments via `wrangler preview`) is now
enabled on the account. A Preview starts from a copy of the production
config, so each app's wrangler.jsonc gains a `previews` block that
re-points stateful bindings at preview-tier resources:

- web: vars-only (stateless; previews serve branch UI against prod api/auth)
- api: isolated REGISTRY KV, D1, default R2 bucket, webhook queue, and
  Analytics Engine dataset; GITHUB_CACHE deliberately shared
- mcp: mirrors api's preview registry/database/buckets
- auth: isolated D1; documented BETTER_AUTH_URL / OAuth-callback limits

Preview KV/D1 ids are TODO placeholders until the one-time resource
creation commands (in the api/auth config comments) are run. Also adds a
short Previews note to CONTRIBUTING's Deployment section.
@changeset-bot

changeset-bot Bot commented Aug 17, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: fb97782

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai

coderabbitai Bot commented Aug 17, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are limited based on label configuration.

🏷️ Required labels (at least one) (2)
  • coderabbit:review
  • review
🚫 Excluded labels (none allowed) (1)
  • wip

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 560db62a-035b-405b-b6cd-ae79ef5c4129

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

UPLOADS_REGISTRY_PREVIEW KV and the uploads-preview D1 now exist; paste
their ids into api and mcp. `wrangler d1 migrations` cannot resolve a
database declared inside the `previews` block, so each app with a
preview D1 gets a minimal wrangler.preview.jsonc used only for
migrations (api's already applied cleanly; auth's carries a TODO id
until uploads-auth-preview is created).
All preview-tier resources now exist; auth migrations applied.
First live preview deploy showed bindings do NOT inherit from the
production config — a preview gets only what the previews block lists
(wrangler warns "configuration has diverged" otherwise). Repeat the
stateless/shared-safe bindings verbatim in every block and correct the
comments that claimed inheritance.

Also pin an explicit preview-only SESSION KV namespace for uploads-web:
the Astro Cloudflare adapter's generated config injects an id-less
SESSION binding and relies on deploy-time auto-provisioning, which the
Previews deployment API does not support (error 10021).

Verified end-to-end: uploads-web preview "previews-adoption-test"
deploys warning-free and serves the site.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 17, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
uploads-auth fb97782 Commit Preview URL

Branch Preview URL
Aug 17 2026, 03:59 PM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 17, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
uploads-api fb97782 Commit Preview URL

Branch Preview URL
Aug 17 2026, 04:00 PM

@zachdunn Zach Dunn (zachdunn) changed the title Add Workers Previews config blocks to all four workers infra: Add Workers Previews config blocks to all four workers Aug 17, 2026
docs/previews.md holds the model (shared preview tier vs per-branch
overrides), the which-app-to-preview table, and the migration/seeding/
secrets recipes; CONTRIBUTING and AGENTS.md slim to pointers.
wrangler preview auto-creates KV/D1/R2 when the identifier is omitted
and writes the id back to the config — the scratch-database recipe now
uses that instead of manual creation. Corrects the SESSION comment: the
Astro-generated config fails because write-back has no user config to
target, not because previews lack provisioning.
The bindings reference (previews docs, raw .md) shows previews declare
rate limiters via a dedicated ratelimits field (name/namespace_id/simple)
rather than production's unsafe wrapper. Same values, correct field.
Dry-run validates on all three apps.
@zachdunn
Zach Dunn (zachdunn) merged commit 7b87152 into main Aug 17, 2026
6 of 7 checks passed
@zachdunn
Zach Dunn (zachdunn) deleted the claude/cloudflare-workers-previews-8e9af2 branch August 17, 2026 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant