Skip to content

Bundle the runtime release once in the Cloudflare Worker - #262

Closed
tnkuehne wants to merge 1 commit into
mainfrom
build/release-once
Closed

tnkuehne wants to merge 1 commit into
mainfrom
build/release-once

Conversation

@tnkuehne

@tnkuehne tnkuehne commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

The Cloudflare Worker contained the runtime release twice. The SvelteKit build inlined it for the server routes, and Wrangler bundled it again for the Workflow entrypoints that tools/cloudflare-entry.ts adds from source.

The Cloudflare build now leaves @platform/app-runtime/release external, so Wrangler resolves both dynamic imports to one module. The Node build is unchanged.

Measured with pnpm build:cloudflare and wrangler deploy --dry-run:

Before After
worker.js 30,779 KiB 21,835 KiB
gzip 5,493 KiB 3,838 KiB

The bundle source map lists packages/app-runtime/dist/release.json once, and both imports call the same module initializer.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no actionable issues were found.

Summary

Leaves @platform/app-runtime/release external during the Cloudflare Vite build so Wrangler can bundle one shared copy.

  • Cloudflare routes and workflows now share one runtime release module.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[SvelteKit server output] --> C[Wrangler bundle]
  B[Workflow source] --> C
  C --> D[One shared release module]
Loading

Reviews (1) · Last reviewed commit: "Bundle the runtime release once in the C..." · Reviewed by Greptile

The Cloudflare Worker combines the SvelteKit output with the Workflow
entrypoints, and both import the bundled runtime release. Vite inlined
one copy and Wrangler added a second from source. Leaving the release
external in the SvelteKit build lets Wrangler resolve both imports to
the same module, which removes about 9 MB from the Worker.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 21, 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 Updated (UTC)
✅ Deployment successful!
View logs
widefleet-docs 183c1d8 Nov 21 2026, 01:28 PM

tnkuehne added a commit that referenced this pull request Nov 21, 2026
A Cloudflare installation runs one runtime Worker for all of its
organizations. App operations nevertheless recorded an
organization-level runtime: an organization without one received the
release bundled with the control plane at its first operation, and
installation runtime updates never changed it afterwards. The recorded
value did not affect which code served the app, because activation
already checks the version the runtime Worker reports. To support that
path, the Cloudflare Worker bundled the full runtime release — twice,
because the SvelteKit output and the Workflow entrypoints each included
a copy.

Changes:

- **Cloudflare app operations** record the installation organization's
applied runtime for every organization. Until a deployment has installed
the installation runtime, they fail with a conflict instead of
installing a bundled release.
- **Bundled release only in the Node distribution.**
`ensureOrganizationRuntime` takes the bundled release as a parameter.
`runtime-node.ts` passes `loadBundledRuntime`; the Cloudflare
composition does not. Agent job claims were already rejected for
Cloudflare execution, so no Worker code path imports the release any
more.
- **Migration `0036`** clears `runtime` and `applied_runtime` for
Cloudflare organizations other than the installation organization.
Agent-backed organizations and the installation organization keep their
selections.
- `docs/architecture.md` records the difference between agent-backed and
Cloudflare runtime selection.

Agent-backed installations are unchanged: each organization keeps its
own selection, the first app job installs the bundled release, and
`widefleet runtime update` stays the explicit upgrade path.

Cloudflare Worker size, measured with `pnpm build:cloudflare` and
`wrangler deploy --dry-run`:

| | `worker.js` | gzip |
|---|---|---|
| Before | 30,779 KiB | 5,493 KiB |
| After | 12,984 KiB | 2,197 KiB |

This supersedes #262, which removed only the duplicate copy.

Validation:

- Type checks, lint and format pass.
- `RUN_CLOUDFLARE_TESTS=1 vitest run
apps/control-plane/tests/cloudflare`: 253 of 253 pass. The workerd tests
now record the installation runtime in their setup, as a Hosted
deployment does.
- The default suite passes except `runtime-errors.integration.test.ts`,
which fails identically on `main` locally without a built Node server.
- New tests: operations for another organization target the installation
runtime and leave that organization's selection empty; operations fail
before the installation runtime exists; `ensureOrganizationRuntime`
without a bundled release requires an explicit installation; the
migration clears only Cloudflare organizations other than the
installation.


<!-- greptile_comment -->

<!-- greptile_summary -->

<h2><a
href="https://app.greptile.com/api/retrigger?id=115293433&amp;sig=7eb31f5f8103464b9c2cd3f1239127c85ab67f3df8366d031a4c17ddf6e8d153"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/RetriggerDark.svg?v=2"><source
media="(prefers-color-scheme: light)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/Retrigger.svg?v=2"><img
alt="Retrigger"
src="https://greptile-static-assets.s3.amazonaws.com/badges/Retrigger.svg?v=2"
align="right"></picture></a><a
href="https://app.greptile.com/-/switch-tenant?tenant=mendra&amp;next=%2Fwidefleet%2Fwidefleet%2Fpull%2F274&amp;utm_source=greptile_review&amp;utm_medium=github&amp;utm_campaign=view_in_greptile"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptileDark.svg?v=2"><source
media="(prefers-color-scheme: light)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptile.svg?v=2"><img
alt="View in Greptile"
src="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptile.svg?v=2"
align="right"></picture></a>Confidence Score: 5/5</h2>

<!-- greptile-impact-verdict --> The PR appears safe to merge; no
actionable issues were found.

<details open><summary><h3>Summary</h3></summary>

Cloudflare app operations now record the installation’s applied runtime
instead of selecting a separate release for each organization.
- Cloudflare app operations use the installation’s applied runtime.
- Node still loads its bundled runtime, while Cloudflare does not bundle
it.

No actionable issues were found.
</details>

<details open><summary><h3>Diagram</h3></summary>

```mermaid
%%{init: {'theme': 'neutral'}}%%
flowchart LR
    Node["Node composition"] --> Bundle["Bundled release loader"]
    Bundle --> Agent["First agent app job"]
    Hosted["Hosted deployment"] --> Installation["Installation applied runtime"]
    Installation --> Cloudflare["Cloudflare app operations for every organization"]
    Cloudflare --> Ready["Activation checks the serving Worker's release"]
```
</details>

<!-- greptile_confidence_score:5 -->

<sub>Reviews (1) · Last reviewed commit: ["Serve every organization from
the
Cloudf..."](34ceb9d)
· [Reviewed by
Greptile](https://www.greptile.com/?utm_source=greptile_review&utm_medium=github&utm_campaign=review_public&utm_content=widefleet/widefleet)</sub>

<!-- /greptile_comment -->
@tnkuehne

Copy link
Copy Markdown
Contributor Author

Superseded by #274, which removes the bundled release from the Cloudflare Worker entirely.

@tnkuehne tnkuehne closed this Nov 21, 2026
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