Skip to content

Create Dynamic Worker bindings in the request that loads the Worker - #446

Merged
tnkuehne merged 2 commits into
mainfrom
loader-request-bindings
Nov 27, 2026
Merged

tnkuehne merged 2 commits into
mainfrom
loader-request-bindings

Conversation

@tnkuehne

@tnkuehne tnkuehne commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Calls from one app to another failed now and then with Cannot perform I/O on behalf of a different request. … (I/O type: SubrequestChannel). This happened when the platform loaded the called app's Worker again.

The runtime cached each app version's Worker code together with its env. The loader factory then returned that cached object in later requests. Bindings made with ctx.exports.*({ props }) belong to the request that created them. As long as the loader keeps the Worker, the factory is not called again and nothing goes wrong. Once the loader drops the Worker, it calls the factory in the current request and gets the earlier request's stubs. The reloaded Worker's first call to a service, a secret or a resource then fails.

Changes

  • packages/app-runtime/src/worker-definition.ts: the definition is split into workerSource (modules and compatibility settings, which no request owns) and workerBindings (D1, R2, KV and queue stubs). workerDefinition combines the two for callers that load in the same request.
  • packages/app-runtime/src/worker.ts:
    • appWorker caches only the app source.
    • The loader factory creates the bindings, the outbound gateway and the tails. workerd runs the factory in the request that calls get(), and only when it has no Worker for the name, so warm calls create no stubs.
    • workerCode, which workflows use, combines both as before.
  • apps/control-plane/tests/app-services-runtime.test.ts: a fixture loader that drops the called app's Worker before each call, as the edge does with an idle one, while the calling app stays loaded. Two service calls must both reach the target's secret.
    • On workerd without this change, the first call fails with the error above.
    • celld does not check where a stub was created, so the test passes on celld either way.

Verification

  • RUN_SERVICE_TESTS=1 app services suite: 46/46 on workerd and celld.
  • RUN_DYNAMIC_TESTS=1 dynamic and workflow suites: 76/76.
  • pnpm check passes.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
widefleet-docs d5d5765 Nov 27 2026, 09:13 AM

The app runtime kept each app version's finished Worker code, bindings
included, and returned it from the loader factory in later requests. A
binding created through ctx.exports belongs to the request that created it.
When the loader had dropped the Worker and called the factory again, the
new Worker received another request's bindings, and its first call to a
service, secret or resource failed with "Cannot perform I/O on behalf of
a different request (I/O type: SubrequestChannel)".

Only modules and compatibility settings are kept between requests now.
Each request creates the bindings, outbound gateway and tails it may
hand to the loader.
The loader runs the factory in the request that calls get(), and only
when it has no Worker for the name. Warm calls no longer create stubs
they would discard. The regression test drops only the called app's
Worker, so its caller stays loaded as in production.
@tnkuehne
tnkuehne force-pushed the loader-request-bindings branch from 8c5ddb0 to d5d5765 Compare November 27, 2026 09:11
@tnkuehne
tnkuehne merged commit 1771115 into main Nov 27, 2026
15 checks passed
@tnkuehne
tnkuehne deleted the loader-request-bindings branch November 27, 2026 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant