Skip to content

[miniflare]: Fix local scheduled handler returning exception when assets is enabled#14177

Merged
petebacondarwin merged 7 commits into
cloudflare:mainfrom
ktKongTong:asset-scheduled
Jun 6, 2026
Merged

[miniflare]: Fix local scheduled handler returning exception when assets is enabled#14177
petebacondarwin merged 7 commits into
cloudflare:mainfrom
ktKongTong:asset-scheduled

Conversation

@ktKongTong

@ktKongTong ktKongTong commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Fixes #9882

bypass asset rpc worker for scheduled handler

Relate: #13704


  • 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: bug fix

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


Open in Devin Review

@changeset-bot

changeset-bot Bot commented Jun 4, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: bed00e4

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

This PR includes changesets to release 6 packages
Name Type
miniflare Patch
@cloudflare/pages-shared Patch
@cloudflare/vite-plugin Patch
@cloudflare/vitest-pool-workers Patch
wrangler Patch
@cloudflare/wrangler-bundler 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 penalosa and removed request for a team June 4, 2026 09:00
@workers-devprod

workers-devprod commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

@petebacondarwin petebacondarwin 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.

Is a simpler fix for this just to add the following to packages/miniflare/src/workers/assets/rpc-proxy.worker.ts

	scheduled(controller, env, ctx) {
		return this.env.USER_WORKER.scheduled(controller, env, ctx);
	}

Edit: It was not quite as easy as this but I think this is the right direction. Pushed a commit

@petebacondarwin petebacondarwin requested review from petebacondarwin and removed request for penalosa June 5, 2026 11:39
ktKongTong and others added 4 commits June 5, 2026 16:31
Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@petebacondarwin

Copy link
Copy Markdown
Contributor

I hope you don't mind but I have pushed a commit that is an alternative way to fix this.
Let me know what you think.

@petebacondarwin

Copy link
Copy Markdown
Contributor

What I changed

Instead of bypassing the assets RPC proxy with a new SERVICE_RAW_USER_FALLBACK binding, I made the proxy itself forward scheduled events correctly. Two small pieces:

  1. Added the service_binding_extra_handlers compatibility flag to the assets RPC proxy worker (packages/miniflare/src/plugins/assets/index.ts). Without this flag, calling this.env.USER_WORKER.scheduled() from inside the proxy is routed through JsRpc instead of the Fetcher.scheduled() built-in, which is what was producing outcome: "exception" (the user worker's scheduled handler was being called as a plain RPC method, so controller.noRetry() threw because the "controller" was just {cron, scheduledTime}). The entry worker already uses this flag.

  2. Added a scheduled method to RPCProxyWorker that:

    • Converts the inner ScheduledController into the { scheduledTime: Date, cron: string } shape expected by Fetcher.scheduled.
    • Propagates the user worker's noRetry() decision onto the proxy's own controller (otherwise it stays at the default false).
    • Re-throws when the inner outcome isn't "ok" so outcome: "exception" surfaces correctly through the proxy instead of being silently swallowed.

This let me revert the SERVICE_RAW_USER_FALLBACK binding, the new CoreBindings entry, and the entry-worker change — the dispatch flow stays unified through the proxy, which felt closer to the existing fetch/tail pattern in rpc-proxy.worker.ts.

All the tests you added still pass with this approach.

@pkg-pr-new

pkg-pr-new Bot commented Jun 5, 2026

Copy link
Copy Markdown
create-cloudflare

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

@cloudflare/deploy-helpers

npm i https://pkg.pr.new/@cloudflare/deploy-helpers@14177

@cloudflare/kv-asset-handler

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

miniflare

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

@cloudflare/pages-shared

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

@cloudflare/unenv-preset

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

@cloudflare/vite-plugin

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

@cloudflare/vitest-pool-workers

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

@cloudflare/workers-auth

npm i https://pkg.pr.new/@cloudflare/workers-auth@14177

@cloudflare/workers-editor-shared

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

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@14177

wrangler

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

@cloudflare/wrangler-bundler

npm i https://pkg.pr.new/@cloudflare/wrangler-bundler@14177

commit: bed00e4

Comment thread packages/miniflare/test/index.spec.ts

@workers-devprod workers-devprod 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.

Codeowners reviews satisfied

@ktKongTong

Copy link
Copy Markdown
Contributor Author
  1. Added the service_binding_extra_handlers compatibility flag to the assets RPC proxy worker (packages/miniflare/src/plugins/assets/index.ts). Without this flag, calling this.env.USER_WORKER.scheduled() from inside the proxy is routed through JsRpc instead of the Fetcher.scheduled() built-in, which is what was producing outcome: "exception" (the user worker's scheduled handler was being called as a plain RPC method, so controller.noRetry() threw because the "controller" was just {cron, scheduledTime}). The entry worker already uses this flag.

Thanks for pushing the update. I wasn’t aware of the service_binding_extra_handlers flag. This approach is much better.

@ktKongTong ktKongTong changed the title fix(miniflare): bypass assets' rpc proxy worker for scheduled handler [miniflare]: Fix local scheduled handler returning exception when assets is enabled Jun 6, 2026

@petebacondarwin petebacondarwin 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.

Let's go!

@github-project-automation github-project-automation Bot moved this from In Review to Approved in workers-sdk Jun 6, 2026
@petebacondarwin petebacondarwin merged commit 48c4ff0 into cloudflare:main Jun 6, 2026
52 checks passed
@github-project-automation github-project-automation Bot moved this from Approved to Done in workers-sdk Jun 6, 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.

can't test cron triggers locally with assets or redirected config

4 participants