Skip to content

feat(wrangler): Support disabling state persistence in unstable_startWorker()#12815

Merged
NuroDev merged 21 commits intomainfrom
fix/start-worker-disable-persistence
Mar 10, 2026
Merged

feat(wrangler): Support disabling state persistence in unstable_startWorker()#12815
NuroDev merged 21 commits intomainfrom
fix/start-worker-disable-persistence

Conversation

@NuroDev
Copy link
Copy Markdown
Member

@NuroDev NuroDev commented Mar 9, 2026

Fixes #3652.

As mentioned in the issue above, a nice QoL improvement would be having the ability to disable persistence entirely, which is especially helpful when running tests. This change adds support to both startWorker() and unstable_dev() to be able to set the persist option to false or null.

Note

This only applies to state persistence. .wrangler/tmp will still be required for module bundling.


  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: startWorker() is still marked as "unstable" in the docs so individual property documentation has not been added yet.

A picture of a cute animal (not mandatory, but encouraged)

IMG_2150
Open with Devin

@NuroDev NuroDev self-assigned this Mar 9, 2026
@github-project-automation github-project-automation Bot moved this to Untriaged in workers-sdk Mar 9, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 9, 2026

✅ All changesets look good

@NuroDev NuroDev changed the title feat(wrangler): Support disabling persistence in unstable_startWorker() feat(wrangler): Support disabling state persistence in unstable_startWorker() Mar 9, 2026
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Mar 9, 2026

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@12815

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@12815

miniflare

npm i https://pkg.pr.new/miniflare@12815

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@12815

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@12815

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@12815

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@12815

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@12815

wrangler

npm i https://pkg.pr.new/wrangler@12815

commit: 34b6ae0

@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk Bot commented Mar 9, 2026

OK so it's re-exported as unstable_startWorker in cli.ts:68. The changeset name is correct.

Now let me think about whether there are any actual issues with this PR:

  1. Type correctness: The flow is sound. false | nullgetLocalPersistencePath returns null → Miniflare gets undefined for defaultPersistRoot → in-memory storage. Correct.

  2. Overload signatures: Clean and type-safe. Existing callers that pass string | undefined get back string (never null). New callers passing false | null get back null.

  3. Test coverage: Tests cover both the getLocalPersistencePath function directly and the LocalRuntimeController integration with persist: null.

  4. unstable_dev path: The persist?: boolean field already existed on Unstable_DevOptions (line 30). The new persist?: boolean on StartDevOptions (line 368) mirrors it. start-dev.ts:260 bridges them correctly: args.persist === false ? false : args.persistTo.

  5. Backward compatibility: The input type changes from persist?: string to persist?: string | false | null. This is purely additive — existing callers passing string | undefined continue to work identically.

  6. One potential concern: The Unstable_DevOptions.persist (line 30 of api/dev.ts) was already boolean before this PR. But the new StartDevOptions.persist is also boolean. When persist is true (not just undefined), the code at start-dev.ts:260 does args.persist === false ? false : args.persistTo. If persist is true and persistTo is undefined, this passes undefined to StartDevWorkerInput.dev.persist, which defaults to the .wrangler/state path. That's the correct behavior for persist: true.

  7. The Unstable_DevOptions.persist comment says "Enable persistence for local mode" — but unstable_dev has had persistence enabled by default for a while. Setting persist: true is a no-op (same as undefined). Setting persist: false now actually disables it. This is fine and consistent with the existing API shape.

Everything looks correct. The types, the runtime behavior, the tests, and the changeset all align properly. The implementation is clean and handles all edge cases.

LGTM

github run

Comment thread .changeset/kind-socks-beam.md
@NuroDev NuroDev marked this pull request as ready for review March 9, 2026 15:23
@NuroDev NuroDev requested a review from a team as a code owner March 9, 2026 15:23
Copy link
Copy Markdown
Contributor

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

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

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 9, 2026

🦋 Changeset detected

Latest commit: 0adc313

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

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
Copy link
Copy Markdown
Contributor

workers-devprod commented Mar 9, 2026

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

@petebacondarwin petebacondarwin self-requested a review March 10, 2026 10:39
Copy link
Copy Markdown
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

Can we ditch the null option and just have string|false?
I think that would be clearer for the user, and simpler to implement.

Comment thread packages/wrangler/src/__tests__/api/startDevWorker/LocalRuntimeController.test.ts Outdated
Comment thread packages/wrangler/src/api/startDevWorker/types.ts Outdated
Comment thread packages/wrangler/src/api/startDevWorker/types.ts Outdated
@github-project-automation github-project-automation Bot moved this from Untriaged to In Review in workers-sdk Mar 10, 2026
@NuroDev NuroDev requested a review from petebacondarwin March 10, 2026 11:07
devin-ai-integration[bot]

This comment was marked as resolved.

Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@github-project-automation github-project-automation Bot moved this from In Review to Approved in workers-sdk Mar 10, 2026
@NuroDev NuroDev merged commit e63539d into main Mar 10, 2026
35 checks passed
@NuroDev NuroDev deleted the fix/start-worker-disable-persistence branch March 10, 2026 23:16
@github-project-automation github-project-automation Bot moved this from Approved to Done in workers-sdk Mar 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Support disabling persistence in startWorker()

4 participants