Skip to content

fix(cloudflare): raise default sandbox subrequest limit from 10 to 32 - #4274

Closed
minemeraj wants to merge 1 commit into
emdash-cms:mainfrom
minemeraj:fix/sandbox-subrequest-default
Closed

minemeraj wants to merge 1 commit into
emdash-cms:mainfrom
minemeraj:fix/sandbox-subrequest-default

Conversation

@minemeraj

Copy link
Copy Markdown

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.storage read/write, each ctx.kv op, 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 with Too 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 /subscribe always 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 limits to the sandbox runner (SandboxOptions.limits); this only changes the fallback.

Closes #

Type of change

  • Bug fix
  • Feature (requires an accepted feature plan or RFC)
  • Refactor (no behavior change)
  • Translation
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Your connection to this change

  • I use EmDash and ran into the problem this PR addresses
  • I maintain a tool, dependency, or service that EmDash uses, and this change concerns that integration
  • A Maintainer approved this specific change before I opened the PR

I run a multi-site EmDash deployment on Cloudflare Workers Paid and hit this when enabling registry plugin installs for tenants.

Checklist

  • I have read CONTRIBUTING.md
  • pnpm typecheck passes (@emdash-cms/cloudflare, after building emdash core; the two DownloadOptions/DownloadResult errors seen before the core rebuild are pre-existing and unrelated to this change)
  • pnpm lint passes (no package-level lint script in @emdash-cms/cloudflare)
  • pnpm test passes 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 format has been run
  • I have added/updated tests for my changes — the value is a single configuration default with no test asserting it; a test pinning the literal would only restate the constant
  • User-visible strings — not applicable
  • I have added and reviewed the user-facing changeset (@emdash-cms/cloudflare patch)
  • New features link to their merged design PR — not applicable (bug fix)
  • I have included screenshots below if this PR changes the UI — not applicable (no UI change)

AI assistance disclosure

  • This PR includes AI-generated code or text — model/tool: Claude (Sonnet 4.5) via an agent. I reviewed the complete diff, ran the build, typecheck and tests, and verified the fix against the real failing flow before authorising this PR.

Screenshots / test output

Not applicable (no UI change). The behavioural change was verified live: the newsletter plugin's POST /subscribe returns 200 {ok:true,status:"pending"} after the bump, where it previously returned ROUTE_ERROR / "Too many subrequests by single Worker invocation".

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-bot

changeset-bot Bot commented Oct 19, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ab9af4b

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

This PR includes changesets to release 12 packages
Name Type
@emdash-cms/cloudflare Patch
@emdash-cms/plugin-test Patch
@emdash-cms/admin Patch
@emdash-cms/auth Patch
@emdash-cms/blocks Patch
emdash Patch
create-emdash Patch
@emdash-cms/gutenberg-to-portable-text Patch
@emdash-cms/x402 Patch
@emdash-cms/auth-atproto Patch
@emdash-cms/plugin-embeds Patch
@emdash-cms/sandbox-workerd 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

@github-actions github-actions Bot added the query-count changed PR diff modifies query-count snapshot files label Oct 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Query-count snapshot changes

22 routes changed, total Δ +82 queries.

SQLite

Route Before After Δ
GET /search (cold) 6 10 +4
GET /search (warm) 6 10 +4

D1

Route Before After Δ
GET / (cold) 22 24 +2
GET / (warm) 5 8 +3
GET /category/development (cold) 21 24 +3
GET /category/development (warm) 9 12 +3
GET /contributors (cold) 15 19 +4
GET /contributors (warm) 5 8 +3
GET /contributors-naive (cold) 22 26 +4
GET /contributors-naive (warm) 12 15 +3
GET /pages/about (cold) 15 19 +4
GET /pages/about (warm) 5 8 +3
GET /posts (cold) 15 19 +4
GET /posts (warm) 5 8 +3
GET /related (cold) 18 22 +4
GET /related (warm) 8 11 +3
GET /related-baseline (cold) 15 19 +4
GET /related-baseline (warm) 5 8 +3
GET /search (cold) 16 24 +8
GET /search (warm) 6 13 +7
GET /tag/webdev (cold) 21 24 +3
GET /tag/webdev (warm) 9 12 +3

Comparing snapshot files between base and head. Updated automatically on each push.

@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

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

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.

Comment on lines +63 to +65
// 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 } })`.

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.

[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:

Suggested change
// 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.

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.

[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,

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.

[needs fixing] Update the existing references to the old limit in this PR:

  • docs/src/content/docs/deployment/plugin-sandbox.mdx still lists 10 in its Resource limits table.
  • docs/src/content/docs/plugins/creating-plugins/capabilities.mdx:264 still says the Cloudflare runner defaults to 10 subrequests.
  • The JSDoc for ResourceLimits.subrequests in packages/core/src/plugins/sandbox/types.ts:36 still 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.

@minemeraj

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request Oct 19, 2026

@danielmlr danielmlr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for working on this!

  1. 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.
  2. The override hint in the code comment and the changeset doesn't work today. sandbox() takes no options, and core never passes limits to 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.
  3. The docs still say 10, in the Resource limits table in docs/src/content/docs/deployment/plugin-sandbox.mdx and in the resource limits part of docs/src/content/docs/plugins/creating-plugins/capabilities.mdx. It'd be great to update both. The subrequests JSDoc in packages/core/src/plugins/sandbox/types.ts could then say that the Cloudflare runner defaults to 30.

Comment on lines +5 to +7
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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
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.

@emdashbot emdashbot Bot added review/needs-review No maintainer or bot review yet and removed review/needs-review No maintainer or bot review yet labels Oct 28, 2026
@github-actions github-actions Bot added review/awaiting-author Reviewed; waiting on the author to respond and removed review/needs-review No maintainer or bot review yet labels Oct 28, 2026
Comment on lines +63 to +66
// 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,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
// 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,

@emdashbot emdashbot Bot added review/awaiting-author Reviewed; waiting on the author to respond and removed review/awaiting-author Reviewed; waiting on the author to respond labels Oct 28, 2026
@danielmlr

Copy link
Copy Markdown
Member

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.

@danielmlr danielmlr closed this Nov 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/cloudflare cla: signed query-count changed PR diff modifies query-count snapshot files review/awaiting-author Reviewed; waiting on the author to respond size/S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants