Repository navigation
Conversation
Each bridge call (storage, KV, email, content) is one subrequest, so a handler with a few reads plus a write exceeds the old default of 10 and fails with 'Too many subrequests', even on Workers Paid. 32 matches Cloudflare's per-request Worker invocation ceiling.
🦋 Changeset detectedLatest commit: ab9af4b The changes in this PR will be included in the next version bump. This PR includes changesets to release 12 packages
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 |
Query-count snapshot changes22 routes changed, total Δ +82 queries. SQLite
D1
Comparing snapshot files between base and head. Updated automatically on each push. |
|
All contributors have signed the CLA ✍️ ✅ |
There was a problem hiding this comment.
Raising the Cloudflare runner's default subrequest limit is a reasonable, narrowly scoped fix. The value flows correctly through resolveLimits into Worker Loader. The surrounding prose is the problem. The new code comment and the changeset both advertise a limits override that users of the sandbox() integration cannot use. Both also misstate why 32 was chosen, and the existing docs still say 10. The verdict is request_changes because the reviewers' findings are needs_fixing, though both agree the code change itself is fine.
Reviewed by anthropic/claude-opus-5-5 and openai/gpt-6.1-sol.
| // Every host call a plugin makes (storage read/write, KV, email, content) is one subrequest through the bridge binding, so a | ||
| // single handler that does a few reads plus a write already passes 10. 32 matches Cloudflare's own per-request Worker | ||
| // invocation ceiling and still bounds a runaway plugin. Override per deployment with `sandbox({ limits: { subRequests } })`. |
There was a problem hiding this comment.
[needs fixing] This comment points readers to an API that doesn't exist. sandbox() in packages/cloudflare/src/index.ts:552 takes no arguments. Core builds the runner through createSandboxRunnerOptions(...) in emdash-runtime.ts and never passes limits, so a site can't override this. The key is also misspelled: SandboxOptions.limits uses subrequests, not subRequests.
The reason given for 32 is also wrong. 32 is Cloudflare's limit on Worker invocations chained through service bindings, not its subrequest ceiling. One reviewer also noted that the block narrates the change, which goes against the AGENTS.md comment convention.
Keep only what helps a future reader:
| // Every host call a plugin makes (storage read/write, KV, email, content) is one subrequest through the bridge binding, so a | |
| // single handler that does a few reads plus a write already passes 10. 32 matches Cloudflare's own per-request Worker | |
| // invocation ceiling and still bounds a runaway plugin. Override per deployment with `sandbox({ limits: { subRequests } })`. | |
| // Each host call (storage, KV, email, content, http.fetch) is one bridge subrequest. |
|
|
||
| Raise the default sandboxed-plugin subrequest limit from 10 to 32. | ||
|
|
||
| Every host call a sandboxed plugin makes — storage read/write, KV, email send, content read — is one subrequest through the bridge binding. A single route handler that does a few reads and a write already exceeds 10 and fails with "Too many subrequests by single Worker invocation", even on a Workers Paid plan whose real ceiling is far higher. The default now matches Cloudflare's own per-request Worker invocation ceiling (32), which still bounds a runaway plugin. Deployments that need a different limit can still pass `limits` to the sandbox runner. |
There was a problem hiding this comment.
[needs fixing] The sentence "Deployments that need a different limit can still pass limits to the sandbox runner" is misleading for anyone using the integration. Core never sets SandboxOptions.limits when it creates the runner, and sandbox() takes no options. limits is only a runner-construction option for custom hosts or factories. Either drop the sentence or say that the default can't be configured through the normal integration yet.
The 32 is also described wrongly. It is the limit on chained Worker invocations, not a subrequest ceiling. Describe it as EmDash's chosen default budget.
The changeset should also say who is affected. For example: sandboxed plugins on Cloudflare can now make up to 32 host calls per invocation, up from 10.
| // Every host call a plugin makes (storage read/write, KV, email, content) is one subrequest through the bridge binding, so a | ||
| // single handler that does a few reads plus a write already passes 10. 32 matches Cloudflare's own per-request Worker | ||
| // invocation ceiling and still bounds a runaway plugin. Override per deployment with `sandbox({ limits: { subRequests } })`. | ||
| subrequests: 32, |
There was a problem hiding this comment.
[needs fixing] Update the existing references to the old limit in this PR:
docs/src/content/docs/deployment/plugin-sandbox.mdxstill lists 10 in its Resource limits table.docs/src/content/docs/plugins/creating-plugins/capabilities.mdx:264still says the Cloudflare runner defaults to 10 subrequests.- The JSDoc for
ResourceLimits.subrequestsinpackages/core/src/plugins/sandbox/types.ts:36still says(default: 10).
These are now false for Cloudflare. Qualify the shared type's default by runtime, since the Node.js setting didn't change.
One reviewer also noted that the workerd runner's DEFAULT_LIMITS.subrequests stays at 10 under a "Matches Cloudflare production limits" comment. The limit isn't enforced there, but the two runners now disagree.
|
I have read the CLA Document and I hereby sign the CLA |
danielmlr
left a comment
There was a problem hiding this comment.
Thanks for working on this!
- I think 30 is a safer default than 32. On Cloudflare, every bridge call counts as a Worker invocation, and one request gets 32 of those. The host Worker and the plugin's own worker already take two. So a plugin's 31st and 32nd calls could fail with Cloudflare's own error before our limit kicks in. #3383 lands on 30 for the same reason. I left a suggestion on the line.
- The override hint in the code comment and the changeset doesn't work today.
sandbox()takes no options, and core never passeslimitsto the runner, so a site can't change the limit. Dropping the hint would keep readers from looking for a setting that isn't there. #3383 would add that option. There's a suggestion for the changeset as well. - The docs still say 10, in the Resource limits table in
docs/src/content/docs/deployment/plugin-sandbox.mdxand in the resource limits part ofdocs/src/content/docs/plugins/creating-plugins/capabilities.mdx. It'd be great to update both. ThesubrequestsJSDoc inpackages/core/src/plugins/sandbox/types.tscould then say that the Cloudflare runner defaults to 30.
| Raise the default sandboxed-plugin subrequest limit from 10 to 32. | ||
|
|
||
| Every host call a sandboxed plugin makes — storage read/write, KV, email send, content read — is one subrequest through the bridge binding. A single route handler that does a few reads and a write already exceeds 10 and fails with "Too many subrequests by single Worker invocation", even on a Workers Paid plan whose real ceiling is far higher. The default now matches Cloudflare's own per-request Worker invocation ceiling (32), which still bounds a runaway plugin. Deployments that need a different limit can still pass `limits` to the sandbox runner. |
There was a problem hiding this comment.
| Raise the default sandboxed-plugin subrequest limit from 10 to 32. | |
| Every host call a sandboxed plugin makes — storage read/write, KV, email send, content read — is one subrequest through the bridge binding. A single route handler that does a few reads and a write already exceeds 10 and fails with "Too many subrequests by single Worker invocation", even on a Workers Paid plan whose real ceiling is far higher. The default now matches Cloudflare's own per-request Worker invocation ceiling (32), which still bounds a runaway plugin. Deployments that need a different limit can still pass `limits` to the sandbox runner. | |
| Raises the subrequest limit for sandboxed plugins on Cloudflare from 10 to 30 calls per invocation. Plugin routes and hooks that make several storage, KV or settings calls no longer fail with "Too many subrequests" after 10 calls. The limit can't be changed through the `sandbox()` integration. |
| // Every host call a plugin makes (storage read/write, KV, email, content) is one subrequest through the bridge binding, so a | ||
| // single handler that does a few reads plus a write already passes 10. 32 matches Cloudflare's own per-request Worker | ||
| // invocation ceiling and still bounds a runaway plugin. Override per deployment with `sandbox({ limits: { subRequests } })`. | ||
| subrequests: 32, |
There was a problem hiding this comment.
| // Every host call a plugin makes (storage read/write, KV, email, content) is one subrequest through the bridge binding, so a | |
| // single handler that does a few reads plus a write already passes 10. 32 matches Cloudflare's own per-request Worker | |
| // invocation ceiling and still bounds a runaway plugin. Override per deployment with `sandbox({ limits: { subRequests } })`. | |
| subrequests: 32, | |
| // Cloudflare allows 32 Worker invocations per request, and each bridge call is one. | |
| // The host Worker and the plugin worker use two of them. | |
| subrequests: 30, |
|
Thanks for working on this! I'm closing this one in favor of #4712, which makes the same change and is the one going ahead. |
What does this PR do?
Raises the default resource limit for sandboxed plugins from 10 subrequests per invocation to 32 (
packages/cloudflare/src/sandbox/runner.ts,DEFAULT_LIMITS.subrequests).Every host call a sandboxed plugin makes goes through the bridge binding as one subrequest: each
ctx.storageread/write, eachctx.kvop,ctx.email.send,ctx.content.get, and so on. A single public route handler that does a handful of reads plus a write therefore passes 10 quickly and fails withToo many subrequests by single Worker invocation— even on a Workers Paid plan, whose real ceiling is far higher. The isolate is hitting the runner's own hardcoded default, not a Cloudflare plan limit.I hit this installing a newsletter plugin from the registry: its double-opt-in subscribe handler does a KV rate-limit check (get + compare-and-set), a subscriber lookup, a subscriber write, and a confirmation email — comfortably over 10 bridge round-trips — so
POST /subscribealways failed until I patched this default locally. After the bump the same flow works end to end (subscribe → confirm → campaign send → unsubscribe).32 matches Cloudflare's own per-request Worker invocation ceiling, so it is a principled upper bound that still protects against a runaway plugin. Deployments that need a different value can still pass
limitsto the sandbox runner (SandboxOptions.limits); this only changes the fallback.Closes #
Type of change
Your connection to this change
I run a multi-site EmDash deployment on Cloudflare Workers Paid and hit this when enabling registry plugin installs for tenants.
Checklist
pnpm typecheckpasses (@emdash-cms/cloudflare, after buildingemdashcore; the twoDownloadOptions/DownloadResulterrors seen before the core rebuild are pre-existing and unrelated to this change)pnpm lintpasses (no package-levellintscript in@emdash-cms/cloudflare)pnpm testpasses for the relevant area — no test pins the subrequest default, so this change breaks none. The 3 failing tests in the suite (media-list-limit normalization timeouts, an encryption-key env test) are pre-existing and unrelated.pnpm formathas been run@emdash-cms/cloudflarepatch)AI assistance disclosure
Screenshots / test output
Not applicable (no UI change). The behavioural change was verified live: the newsletter plugin's
POST /subscribereturns200 {ok:true,status:"pending"}after the bump, where it previously returnedROUTE_ERROR/ "Too many subrequests by single Worker invocation".