Skip to content

[miniflare] Route storage/remote bindings through shared services via props#14743

Merged
penalosa merged 2 commits into
mainfrom
penalosa/shared-services-props
Jul 20, 2026
Merged

[miniflare] Route storage/remote bindings through shared services via props#14743
penalosa merged 2 commits into
mainfrom
penalosa/shared-services-props

Conversation

@penalosa

@penalosa penalosa commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Move the per-binding configuration for storage and remote (mixed-mode) bindings out of per-resource workerd services and into runtime ctx.props, so a single shared service can serve any number of bindings.

  • Local KV namespaces now share one entry service — the namespace id is passed via props and resolved in object-entry.worker.ts (idFromName)
  • remoteProxyClientWorker() is now script-only — the connection string, binding name and trace id travel via props (buildRemoteProxyProps), read in remote-proxy-client.worker.ts and the dispatch-namespace proxy
  • All remote-binding plugins emit one shared remote-proxy service instead of one per resource
  • explorer.ts reads the KV namespace id from binding props rather than parsing it out of the service name

No user-facing behaviour change — this is internal plumbing that lets a single service back any number of bindings, replacing the previous one-service-per-resource model.


  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because: this is a behaviour-preserving refactor — the existing miniflare plugin suites (KV / R2 / D1 / email / remote bindings) exercise the affected paths and pass unchanged.
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: internal miniflare refactor with no user-facing surface.

Open in Devin Review

… props

Move the per-binding configuration for storage and remote (mixed-mode)
bindings out of per-resource workerd services and into runtime `ctx.props`,
so a single shared service can serve any number of bindings.

- Local KV namespaces now share one entry service; the namespace id is
  passed via props and resolved in object-entry.worker.ts (idFromName).
- remoteProxyClientWorker() is now script-only; the connection string,
  binding name and trace id travel via props (buildRemoteProxyProps),
  read in remote-proxy-client.worker.ts and the dispatch-namespace proxy.
- All remote-binding plugins emit one shared remote-proxy service instead
  of one per resource.
- explorer.ts reads the KV namespace id from binding props rather than
  parsing it out of the service name.
@penalosa penalosa added the ci:no-changeset-required Skip pull request checks for a valid changeset label Jul 17, 2026
@changeset-bot

changeset-bot Bot commented Jul 17, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 9519409

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@github-project-automation github-project-automation Bot moved this to Untriaged in workers-sdk Jul 17, 2026
@workers-devprod
workers-devprod requested review from a team and dario-piotrowicz and removed request for a team July 17, 2026 12:50
@workers-devprod

workers-devprod commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

@pkg-pr-new

pkg-pr-new Bot commented Jul 17, 2026

Copy link
Copy Markdown
@cloudflare/autoconfig

npm i https://pkg.pr.new/@cloudflare/autoconfig@14743

@cloudflare/config

npm i https://pkg.pr.new/@cloudflare/config@14743

create-cloudflare

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

@cloudflare/deploy-helpers

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

@cloudflare/kv-asset-handler

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

miniflare

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

@cloudflare/pages-shared

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

@cloudflare/unenv-preset

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

@cloudflare/vite-plugin

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

@cloudflare/vitest-pool-workers

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

@cloudflare/workers-auth

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

@cloudflare/workers-editor-shared

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

@cloudflare/workers-utils

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

wrangler

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

commit: 9519409

@ask-bonk ask-bonk 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.

I'm Bonk, and I've done a quick review of your PR.

Summary: Moves per-binding storage/remote config out of per-resource workerd services and into ctx.props, letting one shared service back many bindings. The local storage path is exercised by the existing KV/R2/D1 suites and the remote service-binding path by remote-bindings-access-warning.spec.ts, so the behaviour-preserving claim is reasonably supported.

Explorer registers a colliding "remote" id for remote bindings (low severity). Remote KV/R2/D1 bindings now all point at a shared service name (kv:ns:remote, r2:bucket:remote, d1:db:remote), but constructExplorerBindingMap still derives the resource id by string-stripping that name. Every remote binding of a given type therefore registers the literal id "remote", so multiple remote bindings overwrite each other in IDToBindingName, and a bogus "remote" id leaks into the explorer map (selecting it would try to open storage for a namespace literally named remote). KV reads the id from props but still falls through to the name parse for remote (yielding "remote"); the R2 block (explorer.ts:218, const bucketName = binding.r2Bucket.name.replace(/^r2:bucket:/, "")) and the D1 block (explorer.ts:177, const databaseId = innerBinding.service?.name?.replace(/^d1:db:/, "")) weren't updated at all and have the same problem. Since remote resources aren't locally browsable, the cleanest fix is to skip the shared remote service name in all three blocks. Inline suggestion below covers the KV block; please apply the equivalent !== "remote" guard to the R2 and D1 blocks.

Comment thread packages/miniflare/src/plugins/core/explorer.ts
@ask-bonk

ask-bonk Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Review posted successfully to PR #14743.

I reviewed the PR and posted a single COMMENT review with one inline suggestion. The one actionable finding:

Explorer registers a colliding "remote" id for remote bindings (low severity). After collapsing remote KV/R2/D1 bindings onto shared service names (kv:ns:remote, r2:bucket:remote, d1:db:remote), constructExplorerBindingMap still derives the resource id by stripping the service-name prefix, so every remote binding registers the literal id "remote" — they overwrite each other and a bogus entry leaks into the explorer map. KV attempts a props lookup but falls through to the same buggy parse; R2/D1 weren't updated. Suggested a !== "remote" guard (inline suggestion for KV, prose note for R2/D1).

Everything else checks out: the local storage path is covered by the existing KV/R2/D1 plugin suites and the remote service-binding path by remote-bindings-access-warning.spec.ts (which exercises the new ctx.props mechanism), so the behaviour-preserving claim is reasonably supported.

github run

devin-ai-integration[bot]

This comment was marked as resolved.

@dario-piotrowicz dario-piotrowicz 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.

Looks good to me, although bonk's comment seems legitimate so think it would be worth looking into it

(as far as I can tell the local explorer doesn't currently support remote bindings, but even if it doesn't right now. this issue would need to be resolved for when(/if) it eventually does)

Comment thread packages/miniflare/src/workers/shared/object-entry.worker.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

@github-project-automation github-project-automation Bot moved this from Untriaged to Approved in workers-sdk Jul 20, 2026
@penalosa
penalosa force-pushed the penalosa/shared-services-props branch from b5df334 to 0c17f28 Compare July 20, 2026 12:54
Remote KV/R2/D1 bindings now share one proxy service (`kv:ns:remote`,
`r2:bucket:remote`, `d1:db:remote`), so the explorer's service-name parse
collapsed every remote resource of a type to the literal id "remote" —
overwriting each other in the binding map and leaking a bogus "remote" entry.

Remote resources aren't supported in the local explorer, so skip them in
`constructExplorerBindingMap` for all three types rather than register the
shared service name. Local resources are unaffected.
@penalosa
penalosa force-pushed the penalosa/shared-services-props branch from 0c17f28 to 9519409 Compare July 20, 2026 15:33
@penalosa
penalosa merged commit a7b9e65 into main Jul 20, 2026
58 checks passed
@penalosa
penalosa deleted the penalosa/shared-services-props branch July 20, 2026 17:21
@github-project-automation github-project-automation Bot moved this from Approved to Done in workers-sdk Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:no-changeset-required Skip pull request checks for a valid changeset

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants