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
5 changes: 5 additions & 0 deletions .changeset/prelude-esbuild-only.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cloudhal/cloudflare": patch
---

Docs: `workerd-prelude` is only for entries that wrangler bundles with esbuild, such as the admin entry from `cloudhal deploy`. An entry that Astro's Vite build bundles, such as a playground, must not import it: with Astro 7.4.13 its top-level await deadlocks the Worker at startup (#392).
2 changes: 1 addition & 1 deletion docs/adr/0012-cloudflare-deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Sprint 6 puts a Cloudhal site on Cloudflare. Publishing and rollback must be ins

## Consequences
- Positive: agent → approval → live in one request; rollback is instant; previews are safe; the whole loop is tested on workerd in CI.
- Negative: on-demand SSR on cache misses (bounded by the edge cache); two Workers to deploy; the generated admin entry needs `@cloudhal/cloudflare/workerd-prelude` first — esbuild does not initialise lazily-wrapped zod before `@modelcontextprotocol/core` evaluates (remove when fixed upstream).
- Negative: on-demand SSR on cache misses (bounded by the edge cache); two Workers to deploy; the generated admin entry needs `@cloudhal/cloudflare/workerd-prelude` first — esbuild does not initialise lazily-wrapped zod before `@modelcontextprotocol/core` evaluates (remove when fixed upstream). Entries that Vite/Rollup bundles (the Astro site Worker, a playground) must not import it: Rollup orders zod correctly, and from Astro 7.4.13 the prelude's top-level `await import()` can form a chunk cycle that stops the Worker at startup (#392, 2026-12-03).
- Risks: Workers Cache purge rate limits are the Free-tier limits — purges are per publish, not per edit (and at most three tag requests per publish, see the addendum). Enabling D1 read replication later requires `withSession("first-primary")` for the pointer read. Real deployment was not exercised from CI (no account); the dry run bundles both Workers with the real wrangler.

## Addendum (2026-10-08): custom domains
Expand Down
5 changes: 3 additions & 2 deletions packages/cloudflare/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@ export default createAdminWorker({ skills });
| `CLOUDHAL_AGENT_UPLOADS`, `CLOUDHAL_AGENT_UPLOAD_BYTES` | `off` turns agents' upload links off; their cap per file in bytes |
| `CLOUDHAL_SIGNUP` | `first-user` (default — only the first account, the owner, can sign up), `closed` or `open` |

`workerd-prelude` is only for entries that wrangler bundles with esbuild, like the generated admin entry above. An entry that Astro's Vite build bundles (the site Worker, a playground) must not import it: Rollup orders zod correctly, and with Astro 7.4.13 the prelude's top-level `await import()` forms a chunk cycle that stops the Worker at startup (#392).

The site Worker itself is the project's Astro build (`@cloudhal/astro-renderer/cloudflare-entry`). Both are deployed, configured and tested by `@cloudhal/cli` (`cloudhal deploy`, `test/cloudflare*.test.ts` on workerd).

## Playground Worker (RFC-0036)

`@cloudhal/cloudflare/playground` runs a public playground: every visitor gets a disposable Cloudhal in their own SQLite-backed Durable Object (`PlaygroundSite`), seeded on first use and deleted an hour after the last request (two hours at most), or at once on Reset.

```ts
// worker.ts in the deploying repo (e.g. cloudhal-dev/try)
import "@cloudhal/cloudflare/workerd-prelude";
// worker.ts in the deploying repo (e.g. cloudhal-dev/try), bundled by Astro's Vite build
import { handle } from "@astrojs/cloudflare/handler";
import { serveMedia, withRequestStore } from "@cloudhal/astro-renderer/runtime";
import { createPlaygroundWorker } from "@cloudhal/cloudflare/playground";
Expand Down
5 changes: 5 additions & 0 deletions packages/cloudflare/src/workerd-prelude.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
* Worker then fails at startup with "ZodLazy is not a constructor". Awaiting a dynamic import here
* forces the initializer to run before any later module in the bundle evaluates.
* Remove once the bundler orders wrapped modules correctly (ADR-0012).
*
* Only for entries that wrangler bundles with esbuild (the admin entry `cloudhal deploy` writes).
* Never import it from an entry that Vite/Rollup bundles (an Astro build, a playground): Rollup
* orders zod correctly, and it may put zod in a chunk that imports the entry chunk back, so this
* top-level await never settles and the Worker fails at startup (#392).
*/
const z = await import("zod/v4");

Expand Down