Skip to content

fix(core): respect OPENCODE_CONFIG and OPENCODE_CONFIG_CONTENT in serve/web - #23318

Closed
brian-dlee wants to merge 2 commits into
anomalyco:devfrom
brian-dlee:fix/serve-respects-opencode-config
Closed

brian-dlee wants to merge 2 commits into
anomalyco:devfrom
brian-dlee:fix/serve-respects-opencode-config

Conversation

@brian-dlee

@brian-dlee brian-dlee commented Apr 18, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #19078

Type of change

  • Bug fix

What does this PR do?

opencode serve and opencode web call resolveNetworkOptions(), which only loaded the global config via cfg.getGlobal(). This completely ignored the OPENCODE_CONFIG and OPENCODE_CONFIG_CONTENT environment variables, despite those being explicitly designed as global-scope config augmentation mechanisms.

The fix adds a new getGlobalWithOverrides() method to the Config service that:

  1. Starts with the cached global config (same as getGlobal())
  2. Merges OPENCODE_CONFIG file on top if set
  3. Merges OPENCODE_CONFIG_CONTENT inline JSON on top if set

The merge order matches the existing order in loadInstanceState. Both Flag.OPENCODE_CONFIG and OPENCODE_CONFIG_CONTENT are read at effect-execution time (not module load) so the cache invalidates correctly. The cache is invalidated via invalidateGlobalWithOverrides inside the existing invalidate() method, matching the same lifecycle as cachedGlobal.

resolveNetworkOptions() is updated to call getGlobalWithOverrides() instead of getGlobal(). Since both serve and web go through this function, both are fixed.

How did you verify your code works?

Added 3 new tests in test/config/config.test.ts under a getGlobalWithOverrides describe block:

  • Returns global config when no env vars are set
  • OPENCODE_CONFIG merges on top of global (additive — fields not in the override are preserved from global)
  • OPENCODE_CONFIG_CONTENT merges on top of both global and OPENCODE_CONFIG

All 3 pass. The one pre-existing failure (permission config preserves key order) is unrelated and present on dev.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR
image

Note: This is my first contribution to this project and I did use AI to help me investigate the issue, the code structure in this area and craft the fix. I spent time manually reviewing the code and the proposed solution before submitting.

@brian-dlee
brian-dlee force-pushed the fix/serve-respects-opencode-config branch from 7520e61 to 3219607 Compare April 18, 2026 16:43
@brian-dlee
brian-dlee marked this pull request as ready for review April 18, 2026 16:52
@brian-dlee
brian-dlee force-pushed the fix/serve-respects-opencode-config branch 3 times, most recently from eef8d5e to 5f13ece Compare April 22, 2026 14:45
@brian-dlee
brian-dlee force-pushed the fix/serve-respects-opencode-config branch 2 times, most recently from 28e1c7b to 1347535 Compare April 29, 2026 15:42
@brian-dlee
brian-dlee force-pushed the fix/serve-respects-opencode-config branch from 1347535 to f0f6242 Compare May 11, 2026 19:53
@brian-dlee
brian-dlee force-pushed the fix/serve-respects-opencode-config branch 3 times, most recently from d4590b2 to 060dbc0 Compare May 26, 2026 21:17
@brian-dlee
brian-dlee force-pushed the fix/serve-respects-opencode-config branch from 060dbc0 to 621d70c Compare July 21, 2026 03:40
@brian-dlee
brian-dlee force-pushed the fix/serve-respects-opencode-config branch from 621d70c to 740642a Compare August 9, 2026 07:11
opencode and others added 2 commits August 21, 2026 14:50
…ve/web commands

opencode serve and opencode web only loaded the global config, completely
ignoring the OPENCODE_CONFIG and OPENCODE_CONFIG_CONTENT environment variables.
This adds getGlobalWithOverrides() to the Config service which merges the
global config with those two env-var sources (in the same order as the full
instance config chain), and uses it in resolveNetworkOptions() so that serve
and web honor user-level config overrides.

Closes anomalyco#19078
@thdxr

thdxr commented Oct 10, 2026

Copy link
Copy Markdown
Member

This branch has been upgraded to V2. We're no longer taking PRs for V1. If you think this is still relevant, please port it over and open it for V2.

— from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

@thdxr thdxr closed this Oct 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

opencode serve ignores configuration

2 participants