Files
magpie/internal/plugin/testdata/stuck/index.js
T
yetone fed0055da8 plugin: a plugin stuck on its vendor no longer holds up the plugins loaded or listed with it
shualaitianduai on Discord: a plugin whose sign-in kept failing (401)
held up the plugins behind it. host.js loaded the plugins one after
another and answered init only when all were in, so a plugin function
that never returned held every other plugin until init's two-minute
deadline failed the whole host. providers() listed the providers one
after another too, so one stuck models hook held the whole list past
refreshDeadline (30s), and every provider's list went stale.

Now loadPlugins loads every plugin side by side, each given
pluginLoadWait (20s) for its import and plugin function, and each
config hook as long; one still loading is told as not loaded ("the
plugin's load didn't finish in 20s") and init answers with the rest.
Hooks are kept in the list's order, as before. providers() lists every
provider side by side and gives each models hook pluginListWait (20s,
inside refreshDeadline): one that hasn't answered is listed as fallen
back with that as its listError, so magpie keeps the list it had, and
that answer isn't kept for requests (keepInfo). Documented in
docs/subsystems/provider-plugins.md.

Run at this head (base origin/main e5dd86965), sandbox HOME, caches
pinned:
- TestStuckPluginLoadHoldsNoOther and TestStuckModelListHoldsNoOther
  (testdata/stuck): red on origin/main's host.js ("Plugins = [],
  starting plugins: context deadline exceeded" after 30s; "Providers
  = [], context deadline exceeded" after 15s), green here (2.1s each).
- go test -count=1 -timeout 45m ./internal/plugin/: ok (165s).
- go test ./internal/provider/: ok with
  -skip TestUnreadLoginsWriteErrorsKeepCredentials, which crashes with
  "close of synctest channel from outside bubble" in filememo.Forget,
  filed as #3632 and not touched here.
- go test -run Plugin ./internal/gateway/: ok.
- gofmt -l clean; go vet, GOOS=linux and GOOS=windows go vet -tags
  nogui on internal/plugin: ok.
Not run before the push: the whole go test ./... (run after it); not
tried with the reporter's own plugin, which wasn't named.
2026-10-26 15:09:09 +08:00

33 lines
1.0 KiB
JavaScript

// A plugin whose vendor never lets it through, as one whose sign-in is
// answered 401 and tried again for ever: with $STUCK_LOAD set its plugin
// function never returns, and with $STUCK_MODELS set its models hook
// never does.
const never = () => new Promise(() => {})
export const StuckPlugin = async () => {
if (process.env.STUCK_LOAD) await never()
return {
config: async (cfg) => {
cfg.provider = cfg.provider ?? {}
cfg.provider.stuckco = {
name: "StuckCo",
npm: "@ai-sdk/openai-compatible",
api: "https://stuck.invalid/v1",
models: { "stuck-1": { name: "Stuck One", limit: { context: 1000, output: 100 } } },
}
},
provider: {
id: "stuckco",
async models(provider) {
if (process.env.STUCK_MODELS) await never()
return provider.models
},
},
auth: {
provider: "stuckco",
methods: [{ type: "api", label: "API key" }],
loader: async () => ({ baseURL: "https://stuck.invalid/v1" }),
},
}
}