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
- Fresh ubuntu-latest runner
opencode_version: 1.14.25
- Dynamic-SDK model, e.g.
cloudflare-ai-gateway/openai/gpt-5.4
- Set
CLOUDFLARE_ACCOUNT_ID, CLOUDFLARE_GATEWAY_ID, CLOUDFLARE_API_TOKEN
- 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.
Description
1.14.x added
loadOptions(dir)via@npmcli/configto the reify path inpackages/opencode/src/npm/index.ts. It runsnew Config({...}).load()againstcwd: <cache>/packages/<pkg>beforearborist.reify. On CI runners (GitHub Actions, ubuntu-latest), this throws and bubbles asInstallFailedError, whichprovider.ts:1522re-wraps asInitError, which the session path strips toUnknownError: ProviderInitError(see #24430).Scope: only affects models whose
models.devprovider.npmis not in opencode'sBUNDLED_PROVIDERSmap. Bundled SDKs skipNpm.addentirely. Forcloudflare-ai-gatewaythis is asymmetric:models.devnpmopenai/*ai-gateway-providerNpm.add→ hitsloadOptions→ failsanthropic/*@ai-sdk/anthropicgoogle-ai-studio/*@ai-sdk/googleThis is why anthropic/google on cf-ai-gateway works on 1.14.x while OpenAI is broken: same gateway, different install path.
Expected:
Npm.addshould not depend on@npmcli/config.load()succeeding for a fresh empty dir. Either skiploadOptionswhen no.npmrc/package.jsonexists yet, or catch and continue withnpmOptions = {}.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
opencode_version: 1.14.25cloudflare-ai-gateway/openai/gpt-5.4CLOUDFLARE_ACCOUNT_ID,CLOUDFLARE_GATEWAY_ID,CLOUDFLARE_API_TOKENUnknownError: ProviderInitErrorwithin ~1sVerified locally on 1.14.25:
cloudflare-ai-gateway/anthropic/claude-opus-4-7reaches AI Gateway (real auth error visible)cloudflare-ai-gateway/openai/gpt-5.4fails insideNpm.addreify, surfaces asUnknownError: ProviderInitErrorOperating System
Linux (GitHub Actions ubuntu-latest), reproduced on macOS 25.4
Workaround in the wild
1.4.6: ci: pin OpenCode for CI jobs cloudflare/workers-sdk#136241.4.6/1.2.27for the same symptomMost 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.addatnpm/index.ts:195:If a prior
reifyleftdirpopulated butnode_modules/<pkg>missing (e.g. crash mid-install),Npm.addreturnsentrypoint: Option.none()forever. Fix: checknode_modules/<pkg>exists, otherwise re-reify.