Skip to content

loadOptions(dir) in Npm.add reify path fails on CI runners → silent ProviderInitError for dynamic providers #24431

@NathanDrake2406

Description

@NathanDrake2406

Description

1.14.x added loadOptions(dir) via @npmcli/config to the reify path in packages/opencode/src/npm/index.ts. It runs new Config({...}).load() against cwd: <cache>/packages/<pkg> before arborist.reify. On CI runners (GitHub Actions, ubuntu-latest), this throws and bubbles as InstallFailedError, which provider.ts:1522 re-wraps as InitError, which the session path strips to UnknownError: ProviderInitError (see #24430).

Scope: only affects models whose models.dev provider.npm is not in opencode's BUNDLED_PROVIDERS map. Bundled SDKs skip Npm.add entirely. For cloudflare-ai-gateway this is asymmetric:

Upstream models.dev npm path
openai/* ai-gateway-provider dynamic Npm.add → hits loadOptions → fails
anthropic/* @ai-sdk/anthropic bundled → no install → works
google-ai-studio/* @ai-sdk/google bundled → works

This is why anthropic/google on cf-ai-gateway works on 1.14.x while OpenAI is broken: same gateway, different install path.

Expected: Npm.add should not depend on @npmcli/config.load() succeeding for a fresh empty dir. Either skip loadOptions when no .npmrc / package.json exists yet, or catch and continue with npmOptions = {}.

OpenCode version

1.14.22, 1.14.25 (any 1.14.x). Pre-1.14 reify path (no loadOptions) is known-good.

Steps to reproduce

  1. Fresh ubuntu-latest runner
  2. opencode_version: 1.14.25
  3. Dynamic-SDK model, e.g. cloudflare-ai-gateway/openai/gpt-5.4
  4. Set CLOUDFLARE_ACCOUNT_ID, CLOUDFLARE_GATEWAY_ID, CLOUDFLARE_API_TOKEN
  5. Send any prompt → UnknownError: ProviderInitError within ~1s

Verified locally on 1.14.25:

  • cloudflare-ai-gateway/anthropic/claude-opus-4-7 reaches AI Gateway (real auth error visible)
  • cloudflare-ai-gateway/openai/gpt-5.4 fails inside Npm.add reify, surfaces as UnknownError: ProviderInitError

Operating System

Linux (GitHub Actions ubuntu-latest), reproduced on macOS 25.4

Workaround in the wild

Most CF repos running anthropic on cf-ai-gateway only hit this when something else triggers a non-bundled install. vinext is the only one running OAI through cf-ai-gateway, hence deterministic failure.

Bonus: stale-cache short-circuit

Npm.add at npm/index.ts:195:

if (yield* afs.existsSafe(dir)) {
  return resolveEntryPoint(name, path.join(dir, "node_modules", name))
}

If a prior reify left dir populated but node_modules/<pkg> missing (e.g. crash mid-install), Npm.add returns entrypoint: Option.none() forever. Fix: check node_modules/<pkg> exists, otherwise re-reify.

Metadata

Metadata

Assignees

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions