[PR #12822] fix(env): remove Env namespace, use direct process.env access #14386

Open
opened 2026-02-16 18:19:11 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/12822

State: open
Merged: No


Summary

Removes the Env namespace entirely. Fixes #12698.

Why Remove Instead of Conditional Caching?

The suggested fix proposed conditional caching. However, the Env namespace has caused repeated issues since its introduction:

Direct bugs

  • #11481: Env.set() mutates internal copy, not process.env — breaks provider SDKs
  • #12698: Env.all() returns stale snapshot

Workaround required

  • 7ebe352af (#11482): bypass Env in provider code for SAP/Bedrock SDKs

Root cause

The API semantics are misleading: Env.set(key, value) appears to set an env var but external code (AWS SDK, child processes) never sees the change. This leaky abstraction led to mixed Env.* / process.env usage and inconsistent behavior.

Conditional caching preserves these problems. Removal eliminates them.

Changes

Area Change
src/env/ Deleted
src/**/*.ts Env.*process.env[key]
test/preload.ts Env snapshot/restore per test (beforeEach/afterEach)
test/env/env.test.ts Deleted

Verification

  • bun test — 980 pass, 5 skip, 0 fail
  • bun run typecheck — clean
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/12822 **State:** open **Merged:** No --- ## Summary Removes the `Env` namespace entirely. Fixes #12698. ## Why Remove Instead of Conditional Caching? The [suggested fix](https://github.com/anomalyco/opencode/issues/12698#issuecomment-3867177758) proposed conditional caching. However, the `Env` namespace has caused repeated issues since its introduction: ### Direct bugs - **#11481**: `Env.set()` mutates internal copy, not `process.env` — breaks provider SDKs - **#12698**: `Env.all()` returns stale snapshot ### Workaround required - `7ebe352af` (#11482): bypass `Env` in provider code for SAP/Bedrock SDKs ### Root cause The API semantics are misleading: `Env.set(key, value)` appears to set an env var but external code (AWS SDK, child processes) never sees the change. This leaky abstraction led to mixed `Env.*` / `process.env` usage and inconsistent behavior. Conditional caching preserves these problems. Removal eliminates them. ## Changes | Area | Change | |------|--------| | `src/env/` | **Deleted** | | `src/**/*.ts` | `Env.*` → `process.env[key]` | | `test/preload.ts` | Env snapshot/restore per test (beforeEach/afterEach) | | `test/env/env.test.ts` | **Deleted** | ## Verification - `bun test` — 980 pass, 5 skip, 0 fail - `bun run typecheck` — clean
yindo added the pull-request label 2026-02-16 18:19:11 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#14386