Skip to content

Run WordPress within Cloudflare Worker memory limits#1872

Merged
chubes4 merged 15 commits into
mainfrom
fix/1838-cloudflare-memory-boot
Jul 18, 2026
Merged

Run WordPress within Cloudflare Worker memory limits#1872
chubes4 merged 15 commits into
mainfrom
fix/1838-cloudflare-memory-boot

Conversation

@chubes4

@chubes4 chubes4 commented Jul 18, 2026

Copy link
Copy Markdown
Collaborator

Summary

Run a full seeded WordPress 7.0.2 runtime inside Cloudflare Workers' fixed 128 MB isolate limit, with canonical Markdown/JSON revisions persisted in R2 and mutation coordination limited to a Durable Object lease/CAS protocol.

What changed

  • Stream and filter the WordPress archive to the server files required by the runtime.
  • Boot from a disposable installed WordPress SQLite seed rather than running wp_install() in the isolate.
  • Bundle the constrained primary runtime from Add constrained primary runtime and explicit flush contract markdown-database-integration#126 at immutable commit 94b9f875ffb8402d5e8eb726893a12324e20f45c.
  • Execute normal MDI driver SQL mutations in PHP-WASM and explicitly flush deterministic relative Markdown/JSON paths.
  • Store content-addressed canonical objects and immutable revision manifests in R2; SQLite remains disposable and is never uploaded.
  • Use the Durable Object only for persisted mutation leases, base-revision validation, and atomic current-pointer promotion.
  • Preserve cold reconstruction and serialize concurrent mutations without running PHP-WASM inside the Durable Object.

Stack

  1. Fix range-filtered remote ZIP decoding WordPress/wordpress-playground#4110 provides bounded workerd-compatible filtered Range decoding.
  2. Add constrained primary runtime and explicit flush contract markdown-database-integration#126 provides the public constrained primary runtime and explicit flush contract.

Tracking issue: #1838.

How to test

  1. Install dependencies from a fresh checkout with npm install.
  2. Until Fix range-filtered remote ZIP decoding WordPress/wordpress-playground#4110 is released, install the @php-wasm/stream-compression artifact produced from that PR.
  3. Run npm run generate:cloudflare-mdi-runtime-bundle; expect nine deterministic MDI runtime files from revision 94b9f875ffb8402d5e8eb726893a12324e20f45c.
  4. Run npm run test:cloudflare-runtime; expect all Cloudflare runtime tests and TypeScript checks to pass.
  5. Run npm run cloudflare:dry-run; expect Wrangler to package the Worker with the WORDPRESS_STATE Durable Object and WORDPRESS_STATE_BUCKET R2 bindings.
  6. Run npm run cloudflare:local-gate; expect two HTTP 200 WordPress health envelopes.
  7. In an authorized disposable Cloudflare account with the declared R2 bucket, deploy the committed branch and send sequential and concurrent POST /?phase=r2-mutate requests. Expect monotonic revision values, previousPostFound: true, deterministic canonicalChanges, and sqlitePersisted: false.

Verification

  • npm run test:cloudflare-runtime passed: 5 tests.
  • npm run cloudflare:dry-run passed. Wrangler reports a pre-existing duplicate test:php-browser-preview-only-session package-script warning.
  • Extracted mutation PHP passed php -l.
  • GitHub workflow-lint passed; contracts is pending.

Supplementary deployed proof

Disposable Worker commit a900ae51, version 5c9c2452-9cf8-478f-8318-81c61eaaccc1:

  • Health returned WordPress 7.0.2 and PHP 8.5.8.
  • The first upgraded cold mutation restored prior R2 state and advanced revision value 4 to 5.
  • MDI flush reported post/cloudflare-r2-proof-5.md as created and _options/wp_codebox_mdi_revision.json as changed.
  • Two concurrent requests serialized as values 6 and 7, each recovering the preceding post and promoting a distinct pointer.
  • Final R2 pointer revision: b35e7137-71e0-4551-97fb-23bee79e76f8.
  • Every response reported sqlitePersisted: false.

Worker: https://wp-codebox-cloudflare-runtime.chubes.workers.dev

Compatibility

This is an additive draft runtime package. Existing WP Codebox runtime behavior and extension APIs are unchanged. The Cloudflare path depends on unreleased upstream contracts in WordPress/wordpress-playground#4110 and Automattic/markdown-database-integration#126.

AI assistance

  • AI assistance: Yes
  • Tool(s): OpenCode and Homeboy
  • Model: OpenAI GPT-5.6 Sol and openai/gpt-5.6-terra
  • Used for: Memory-boundary investigation, upstream contract design, implementation, review, deterministic verification, and disposable Cloudflare proof in collaboration with Chris Huber.

@chubes4
chubes4 marked this pull request as ready for review July 18, 2026 21:51
@chubes4
chubes4 merged commit 3418cfa into main Jul 18, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant