feat(sdk): configure session-selected instances - #46496
Merged
Merged
Conversation
kitlangton
force-pushed
the
sdk-instances
branch
from
September 1, 2026 13:51
5c333e7 to
5cc1265
Compare
This was referenced Sep 1, 2026
kitlangton
force-pushed
the
sdk-instances
branch
from
September 1, 2026 15:22
365958a to
e758cf0
Compare
kitlangton
force-pushed
the
strict-plugin-readiness
branch
from
September 1, 2026 15:44
b350c7a to
f217621
Compare
kitlangton
force-pushed
the
sdk-instances
branch
from
September 1, 2026 15:47
e758cf0 to
5804f74
Compare
kitlangton
force-pushed
the
strict-plugin-readiness
branch
from
September 1, 2026 19:38
f217621 to
7c8eda8
Compare
kitlangton
force-pushed
the
sdk-instances
branch
from
September 1, 2026 19:40
5804f74 to
e09b2dc
Compare
kitlangton
force-pushed
the
sdk-instances
branch
from
September 2, 2026 01:37
e09b2dc to
b957103
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.
Why
An embedded application can already replace Core's Session-aware instance selector, but doing so requires Effect graph wiring. Host-wide plugin registration cannot give two application threads in the same directory different plugin stacks, and post-construction registration is too late to configure automatic restart recovery.
What Changes
Add
instances: { key, configure }to the Promise, Effect, and Workerd SDK constructors:threadsandslackPluginare application code. Effect callers return an Effect fromconfigureinstead.pluginsentry, or a supplied plugin's setup failsinstancesoptionInstance Lifetimes
The selector is a global
Instance.nodereplacement over a scopedLayerMap. Successful instances remain cached until the host closes;configureruns on cache misses, not on every prompt. Server supplies its final replacement set so selected graphs share the correct host Database, Bus, and runtime-profile overrides rather than creating another host. Both instance caches use the existing canonical Location normalization.Inside each selected instance,
Instance.nodeandLocationServiceMap.nodeare bound to cheap borrowers of the selector and the host Location map, mirroringbuildLocationServiceMap. Retaining the selector's own Layer from its entries would make host shutdown wait on those entries to release it first, and plugin cleanups would never run.After construction, the selector waits on
Plugin.awaitActivationand rejects supplied plugins reportedfailed. A host/instance plugin ID collision fails the whole generation before anything reaches the inventory, so it is rejected before construction instead. Failed lookup eviction runs in the selector's host Scope so cancelling the last borrower cannot leave the lookup waiting for itself.Scope
This PR targets
v2directly and contains only the keyed SDK adapter, its Server wiring, theLocationServiceMap.canonicalextraction, documentation, and SDK regressions. The former Core prerequisite #46615 was closed: #46639 removedPluginSupervisor.Service, and the collision it guarded is now handled here without new Core surface.Independent ACP startup repair is #46613. The former SDK fixture maintenance #46614 was closed as superseded by #46639.
This does not share plugin activations across Locations. Selection is not an authorization or plugin-storage isolation boundary. No Protocol or HTTP resource contracts change.
Existing HTTP prompt middleware remains eager: a cold idempotent retry can reconstruct its instance before Core returns the original admission. Preparation and prompt hooks do not repeat. This PR preserves that eager capability acquisition on idempotent retries.
Verification
Using Bun 1.4.0:
Rebased onto
v2atc8f81c8b83, after #46639 removedPluginSupervisor.Service,Instance.provideIfLoaded, andInstance.byLocationNode. SDK, Server, and Core typechecking passed. All eight instance-selection cases passed 40/40 repeated runs, including host/instance collision rejection and cleanup on host close. The full Server suite passed 48 tests with 3 skipped.Full SDK run: 26 passed, 2 failed. Both failures reproduce 3/3 on a pristine
v2checkout at the same commit without this branch:embedded client exposes plugin-backed web search(Web search provider not found) and the cancellation assertion attest/promise.test.ts:73. Neither file is changed here.Packed-consumer validation: all four entrypoints load, the Workerd bundle passes the no-Bun checks, and a real Miniflare consumer exercises selected-instance reuse and prompt hooks against injected Durable Object SQLite. Wrangler ran in dry-run mode; nothing was deployed.