fix(core): run dynamic provider fallback after plugin hooks - #42789
Open
abhishekbiyala wants to merge 1 commit into
Open
fix(core): run dynamic provider fallback after plugin hooks#42789abhishekbiyala wants to merge 1 commit into
abhishekbiyala wants to merge 1 commit into
Conversation
Contributor
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
abhishekbiyala
force-pushed
the
dynamic-provider-fallback
branch
from
August 15, 2026 16:24
92f076b to
b5fcfbe
Compare
Author
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.
Issue for this PR
Closes #42788
Type of change
What does this PR do?
A plugin that registers a provider with an
aisdk:package that is not on npm never gets itsctx.aisdk.hook("sdk", ...)callback invoked, and the session fails withUnsupportedPackageError.DynamicProviderPluginwas inPluginInternal.pre, so its hook always ran before hooks from config-loaded plugins. For an unrecognised package it callsnpm.add(...)withEffect.orDie, and the 404 defect aborts the wholerunSDKhook chain, skipping every hook registered after it. Built-in providers were unaffected because their own hooks setevt.sdkearlier, so theif (evt.sdk) returnguard short-circuited before the npm call.Two changes:
postso it runs after plugin hooks. It is a last-resort resolver, so it should only run once nothing else has claimed the package.Using a package name that is not on npm is an established pattern here:
GithubCopilotPluginsetsmodel.package = "@ai-sdk/github-copilot", claims it in its ownsdkhook, and supplies the SDK from a local module, and that name is not published. It works only becauseProviderPluginsis ordered ahead ofDynamicProviderPluginwithinpre, which a config-loaded plugin cannot do.I confirmed the ordering with temporary logging of each hook index in
AISDK.run: hooks 0-21 completed, index 22 (this plugin) entered and never finished, and the chain ended there.How did you verify your code works?
Reproduced first on the released
0.0.0-next-17444binary using the standalone plugin in #42788: the hook never ran and the session failed withUnsupportedPackageError. After the fix, running the server from source, the same plugin's hook runs and can supply an SDK. I also confirmed a real third-party provider plugin now completes requests end to end.Added two tests in
packages/core/test/plugin/provider-dynamic.test.ts:v2, passes here)ProviderPlugins, which is registered ahead of config pluginsFrom
packages/core:bun test test/plugin/passes (218),bun typecheckclean, andoxlintreports no new warnings on the changed files.Screenshots / recordings
Not a UI change.
Checklist