Skip to content

[miniflare] Support workerd V8 flags via MINIFLARE_WORKERD_V8_FLAGS environment variable#14702

Open
Sipixer wants to merge 1 commit into
cloudflare:mainfrom
Sipixer:miniflare-v8-flags-env
Open

[miniflare] Support workerd V8 flags via MINIFLARE_WORKERD_V8_FLAGS environment variable#14702
Sipixer wants to merge 1 commit into
cloudflare:mainfrom
Sipixer:miniflare-v8-flags-env

Conversation

@Sipixer

@Sipixer Sipixer commented Jul 15, 2026

Copy link
Copy Markdown

Relates to #14701 (immediate mitigation — the underlying heap retention and crash recovery are tracked there and in #13045).

Support passing V8 flags to workerd via a MINIFLARE_WORKERD_V8_FLAGS environment variable, mirroring the existing MINIFLARE_WORKERD_AUTOGATES passthrough (#8431). The generated workerd config already supports v8Flags; Miniflare just never populated it, so the runtime always runs with V8's default ~1.4 GB heap limit and there is no way to raise it.

Large dev applications served through @cloudflare/vite-plugin can reach that limit during a normal editing session (each server-file edit re-evaluates the invalidated module graph inside the isolate — measurements in #14701). When it happens, workerd aborts with V8 fatal error; location = Reached heap limit and every subsequent dispatchFetch() returns fetch failed until the dev server is manually restarted. Setting e.g. MINIFLARE_WORKERD_V8_FLAGS="--max-old-space-size=4096" keeps those sessions alive.


  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows: patched a local install and verified the flag reaches V8 — with MINIFLARE_WORKERD_V8_FLAGS="--max-old-space-size=256" workerd OOMs at exactly 255.9 MB on first render (vs the ~1.4 GB default); with --max-old-space-size=4096, 70 consecutive edit/request cycles that previously crashed the runtime complete with zero failures. Also verified the variable being unset produces a config identical to before (empty v8Flags list).
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: this mirrors the undocumented MINIFLARE_WORKERD_AUTOGATES escape hatch; both are internal/debugging environment variables.

Open in Devin Review

@Sipixer
Sipixer requested a review from workers-devprod as a code owner July 15, 2026 08:54
@changeset-bot

changeset-bot Bot commented Jul 15, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4136d01

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 7 packages
Name Type
miniflare Minor
@cloudflare/deploy-helpers Patch
@cloudflare/pages-shared Patch
@cloudflare/runtime-types Patch
@cloudflare/vite-plugin Patch
@cloudflare/vitest-pool-workers Patch
wrangler Patch

Not sure what this means? Click here to learn what changesets are.

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

@workers-devprod
workers-devprod requested review from a team and petebacondarwin and removed request for a team July 15, 2026 08:54
@workers-devprod

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • @cloudflare/wrangler
Show detailed file reviewers
  • .changeset/miniflare-v8-flags-env.md: [@cloudflare/wrangler]
  • packages/miniflare/src/index.ts: [@cloudflare/wrangler]
  • packages/miniflare/types/env.d.ts: [@cloudflare/wrangler]

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Open in Devin Review

@petebacondarwin

Copy link
Copy Markdown
Contributor

I think that the fact that the memory keeps growing in a Vite setup on each build indicates we have a real memory leak in the system somewhere. So far we have not been able to identify the cause, but we would rather try to fix it than patch over it with an increased heap size.

We're going to have a dig around to see if we can fix the leak, but if not then we can return to this fix later next week.

@petebacondarwin petebacondarwin added blocked Blocked on other work package:vite-plugin Relating to the `@cloudflare/vite-plugin` package labels Jul 17, 2026
@Sipixer

Sipixer commented Jul 17, 2026

Copy link
Copy Markdown
Author

I dug into the leak you mentioned and prototyped a fix (13 lines in the bundled runner-worker, −58% live memory, stack traces unaffected) — details and measurements in #14701 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blocked Blocked on other work package:vite-plugin Relating to the `@cloudflare/vite-plugin` package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants