-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Description
Description
Env.all() in packages/opencode/src/env/index.ts creates a frozen snapshot of process.env on first invocation via Instance.state():
const state = Instance.state(() => {
return { ...process.env } as Record<string, string | undefined>
})This snapshot is never refreshed. When Provider.list() calls Env.all() (line 834 in provider/provider.ts) to detect env-based providers, it uses this cached snapshot.
Consequence: If any environment variable (e.g., AICORE_SERVICE_KEY, OPENAI_API_KEY) is set after the first call to Env.all(), it will never be detected, and the provider will never appear in the connected list.
This affects plugins/extensions that set environment variables dynamically or load them asynchronously.
Root Cause
The singleton pattern was introduced in commit ee4437ff3 ("core: add provider test coverage for upcoming refactor") and the shallow copy was later added in 90f39bf67 ("core: prevent parallel test runs from contaminating environment variables") to isolate parallel tests.
While this works for test isolation, it breaks runtime behavior where env vars may be set after OpenCode initializes.
Plugins
oh-my-opencode (reported in code-yeongyu/oh-my-opencode#1635)
OpenCode version
1.1.51
Steps to reproduce
- Start OpenCode without
AICORE_SERVICE_KEYset - Set
AICORE_SERVICE_KEYin the environment after OpenCode initializes - Call
provider.list()API - Observe:
sap-ai-corenever appears inconnectedarray
Screenshot and/or share link
N/A
Operating System
Linux
Terminal
N/A