Repository navigation
Create Dynamic Worker bindings in the request that loads the Worker - #446
Merged
Merged
Conversation
Deploying with
|
| 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
force-pushed
the
loader-request-bindings
branch
from
November 27, 2026 09:11
8c5ddb0 to
d5d5765
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 withctx.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 intoworkerSource(modules and compatibility settings, which no request owns) andworkerBindings(D1, R2, KV and queue stubs).workerDefinitioncombines the two for callers that load in the same request.packages/app-runtime/src/worker.ts:appWorkercaches only the app source.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.Verification
RUN_SERVICE_TESTS=1app services suite: 46/46 on workerd and celld.RUN_DYNAMIC_TESTS=1dynamic and workflow suites: 76/76.pnpm checkpasses.