Skip to content

Custom loaders run before enabled_providers filtering, causing unnecessary package installs that can fail #12407

Closed

Description

@ShanePresley

Description

Custom provider loaders in CUSTOM_LOADERS are executed for providers that are not in enabled_providers, causing unnecessary dynamic package installations that can fail in restricted network environments.

Verified in upstream dev branch at commit 8bf97ef (2026-02-06)

The custom loader loop at packages/opencode/src/provider/provider.ts:903-904 only checks disabled_providers:

// Line 903-904
for (const [providerID, fn] of Object.entries(CUSTOM_LOADERS)) {
  if (disabled.has(providerID)) continue  // ← Only checks disabled, NOT enabled!
  // ... runs custom loader which may install packages
}

However, the isProviderAllowed() function at lines 706-709 checks both enabled_providers and disabled_providers:

// Line 706-709
function isProviderAllowed(providerID: string): boolean {
  if (enabled && !enabled.has(providerID)) return false
  if (disabled.has(providerID)) return false
  return true
}

The correct isProviderAllowed() check is only applied later at line 929, after custom loaders have already run and potentially failed.

Impact

If a user configures:

{
  "enabled_providers": ["anthropic", "openai"],
  "disabled_providers": ["opencode-zen", "copilot", "openrouter"]
}

The amazon-bedrock custom loader will still run (because it's not in disabled_providers), and if the user has AWS credentials in their environment (AWS_PROFILE, AWS_ACCESS_KEY_ID, etc.), it will attempt to install @aws-sdk/credential-providers via BunProc.install() - even though bedrock is not in enabled_providers.

In corporate/restricted network environments where:

  • npm registry access is blocked or requires special proxy/SSL configuration
  • Users have AWS credentials configured for other purposes (not OpenCode)

OpenCode fails to start with BunInstallFailedError for a provider the user never intended to use.

Proposed Fix

Change line 904 from:

if (disabled.has(providerID)) continue

To:

if (!isProviderAllowed(providerID)) continue

This ensures custom loaders respect the full provider allowlist/blocklist logic, matching the filtering applied later at line 929.

Related Issues

These issues address why bun install fails, but not why it attempts to install for providers the user didn't enable.

Environment

  • OpenCode version: Current dev branch (commit 8bf97ef9e5a4039e80bfb3d565d4718da6114afd)
  • Affected file: packages/opencode/src/provider/provider.ts
  • Bug location: Line 904
  • Proposed fix location: Line 904

Plugins

No response

OpenCode version

Current dev branch (commit 8bf97ef9e5a4039e80bfb3d565d4718da6114afd)

Steps to reproduce

  1. Configure AWS credentials in environment (e.g., export AWS_PROFILE=my-profile)
  2. Create config with enabled_providers that does NOT include amazon-bedrock:
    {
      "enabled_providers": ["anthropic"],
      "disabled_providers": ["opencode-zen", "copilot", "openrouter"]
    }
  3. Block or restrict npm registry access (or use corporate proxy without proper SSL config)
  4. Run opencode

Expected: OpenCode starts successfully (bedrock not in enabled_providers)
Actual: BunInstallFailedError for @aws-sdk/credential-providers

{
  "name": "BunInstallFailedError",
  "data": {
    "pkg": "@aws-sdk/credential-providers",
    "version": "latest"
  }
}

Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

Activity

  1. github-actions commented on Feb 6, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    Feel free to ignore if none of these address your specific case.

  2. github-actions commented on Apr 7, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 90 days of no activity. If the issue is still relevant please open a new one.

  3. LPFchan commented on Apr 24, 2026

    @LPFchan

    Still present in v1.14.24 — and the scope is broader than described

    The original report covers the case where a provider is absent from enabled_providers. I hit a more severe variant: the package is loaded and blocks the event loop even when the provider is completely absent from opencode.jsonc — not just filtered, but not defined at all.

    Setup: headless opencode serve on macOS, desktop app on a second machine connecting over LAN.

    Repro:

    1. Add a custom npm provider (e.g. @ai-sdk/openai-compatible) to the config and run npm install in ~/.config/opencode/
    2. Remove the provider block from opencode.jsonc entirely (empty "provider": {})
    3. Start opencode serve
    4. Server receives requests but /session never starts processing — event loop is blocked

    Finding: @ai-sdk/openai-compatible sitting in node_modules is enough to trigger the blocking load. The config is irrelevant. The only fix is npm uninstall @ai-sdk/openai-compatible in ~/.config/opencode/.

    The proposed fix in this issue (if (!isProviderAllowed(providerID)) continue) would fix the enabled_providers case but likely not this one — the loader seems to scan node_modules independently of config. Might be worth tracing where that scan originates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions