Skip to content

fix(provider): preserve config precedence after model hooks#30211

Open
shlroland wants to merge 4 commits into
anomalyco:devfrom
shlroland:fix/provider-hook-config-precedence
Open

fix(provider): preserve config precedence after model hooks#30211
shlroland wants to merge 4 commits into
anomalyco:devfrom
shlroland:fix/provider-hook-config-precedence

Conversation

@shlroland
Copy link
Copy Markdown

Issue for this PR

Closes #25630

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

After PR #25167, the plugin provider.models() hook runs before config providers are merged into the providers map. This means the hook looks up database[providerID] which only contains providers from the models.dev catalog. Custom providers declared in opencode.json that aren't in the catalog are skipped entirely.

This PR fixes the regression by:

  1. Extracting config application into a reusable applyConfig() function — the inline config-to-database merge is now a function that can operate on any Record<string, Info> target.

  2. Running plugin model hooks on providers after env/auth/custom loaders — this ensures custom providers from user config are present in the providers map when hooks execute.

  3. Calling applyConfig(providers) after hooks — this restores the intended precedence: user config overrides hook-supplied models, while still allowing hooks to add new models to custom providers.

How did you verify your code works?

  • Added a test "provider hook runs for config-only providers and preserves config model overrides" that:

    • Creates a custom provider "demo" in config with a "chat" model named "Config Chat"
    • Creates a plugin hook that adds a "live" model and renames "chat" to "Hook Chat"
    • Verifies the "live" model from the hook exists (hook can add models to custom providers)
    • Verifies "chat" model name is "Config Chat" (config takes precedence over hook)
  • All existing provider tests pass

  • Typecheck passes

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@shlroland shlroland force-pushed the fix/provider-hook-config-precedence branch from 6bceb6a to f39864e Compare June 1, 2026 08:00
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.

Regression: plugin provider.models() hook no longer populates custom providers (post #25167)

1 participant