opencode icon indicating copy to clipboard operation
opencode copied to clipboard

server: custom providers from global config not registered on service boot

Open s0nspark opened this issue 1 week ago • 6 comments

Summary

Custom providers defined in the global config (~/.config/opencode/opencode.json) are not registered when the background service boots, and subsequent file-watcher reload cycles never register them either. Sessions referencing their models fail with ModelUnavailableError. Only an explicit POST /api/location/reload registers them, after which everything works.

Environment

  • opencode version: 2.3.0
  • OS: Linux 7.2.15-1-omarchy (linux x64)
  • Terminal: ghostty (TERM=xterm-ghostty, COLORTERM=truecolor)
  • Shell: /usr/bin/bash
  • Install/channel: latest
  • Active plugins: none configured

Reproduction

  1. Define a custom provider in the global config ~/.config/opencode/opencode.json:
{
  "$schema": "https://opencode.ai/config.json",
  "providers": {
    "main": {
      "name": "llama.cpp main",
      "package": "@opencode/ai/providers/openai-compatible",
      "settings": {
        "baseURL": "http://100.x.x.x:8080/v1"
      },
      "models": {
        "qwen": {
          "modelID": "qwen-main",
          "name": "Qwen3.6-35B-A3B",
          "capabilities": {
            "tools": true,
            "input": ["text"],
            "output": ["text"]
          },
          "limit": {
            "context": 65536,
            "output": 8192
          }
        }
      }
    }
  }
}
  1. Confirm it works: opencode run --model main/qwen "..." succeeds.
  2. Restart the background service (serve --service).
  3. opencode api get /api/provider → the custom provider is absent (only catalog providers opencode and fireworks-ai are listed).
  4. Any session using the model fails: SessionRunnerModel.ModelUnavailableError: Model unavailable: main/qwen.
  5. opencode api post /api/location/reload → the provider immediately appears with activation=enabled, and inference works again.

Expected Behavior

Custom providers from the global config are registered when the service boots (and when config file changes are picked up by the watcher), without requiring a manual location reload.

Actual Behavior

After a service restart, the custom providers are never registered. The watcher fires provider.updated events on location boot and on later reload cycles, but the providers remain absent for as long as the service keeps running (observed >25 hours across multiple watcher cycles). GET /api/config during the broken state shows the parsed global config document with the providers key missing entirely ({"$schema": "...", "update": "disable", "instructions": [...]}); after the manual reload, the same endpoint includes providers and the providers work.

Additional Context

Timeline from ~/.local/share/opencode/log/opencode.log (UTC):

  • 2026-11-19 18:49:45 — POST /api/location/reload → provider.updated, model.updated; subsequent opencode run --model main/qwen / small/qwen succeeded.
  • 2026-11-23 11:33:48 — service started (serve --service, v2.3.0); location services booted; provider.updated fired.
  • 2026-11-23 12:33 / 12:35 / 13:35 and 2026-11-24 19:24 — further location boots / watcher reload cycles with provider.updated events; providers still absent.
  • 2026-11-24 19:24:08 — session drain failed:
SessionRunnerModel.ModelUnavailableError: Model unavailable: main/qwen
    at <anonymous> (/$bunfs/root/chunk-1wt015yk.js:13:21186)
    at SessionRunnerModel.select (/$bunfs/root/chunk-1wt015yk.js:13:21523)
    at SessionRunnerModel.resolve (/$bunfs/root/chunk-zngf6fdt.js:100:8858)
    at SessionContext.load (/$bunfs/root/chunk-7559ejtv.js:493:2814)
    at SessionRunner.advanceToStep (/$bunfs/root/chunk-7559ejtv.js:493:2869)
    at SessionRunner.drain (/$bunfs/root/chunk-7559ejtv.js:493:6652)
  • 2026-11-24 ~19:38 — POST /api/location/reload → both providers registered and verified working.

Both llama.cpp endpoints were reachable throughout (verified via GET /v1/models directly), so this is not an endpoint outage. The config validates against the published schema. Reproducible: yes, across every service boot observed since 2026-11-23. Workaround: opencode api post /api/location/reload after each service start.

s0nspark avatar Nov 24 '26 19:11 s0nspark

Thanks for the detailed report. I couldn't reproduce this on 2.3.0 yet.

What I tried, on Linux with an isolated home directory and no plugins:

  1. Put your providers.main block in ~/.config/opencode/opencode.json, pointed at a local mock OpenAI-compatible server. In a second run I also added "update": "disable" and an instructions entry, to match the keys your /api/config output showed.
  2. Ran opencode service start, then checked opencode api get /api/provider and /api/config, and ran opencode run --model main/qwen.
  3. Stopped and started the service again (the process ID changed) and repeated the checks, then ran opencode api post /api/location/reload.

Every time, including right after the restart, main was listed in /api/provider, providers was in the config document, and main/qwen was selected without a ModelUnavailableError.

One detail stands out: in your broken state, /api/config showed the global document with the providers key missing. That suggests the service read a different version of the file, or a different file. These would help narrow it down:

  • Is ~/.config/opencode or opencode.json a symlink, e.g. into a dotfiles repo? #55119 is a related report where config changes weren't picked up from a symlinked ~/.config/opencode.
  • How is the service started after a reboot or restart: opencode service start, a systemd unit, the desktop app, or auto-start from another opencode command? Does that environment set a different HOME, XDG_CONFIG_HOME or OPENCODE_CONFIG* variable?
  • Was providers added to the file, or the file rewritten, after the service started? Is there also an opencode.jsonc in that folder?
  • In the broken state, the full output of opencode api get /api/config (the path of each document), and the log lines around location services booted that mention config or providers.

You can reply here with the details, or edit the issue and leave a short comment saying you've updated it.

opencodejr[bot] avatar Nov 24 '26 19:11 opencodejr[bot]

  1. Yes, this is a symlinked config
  2. systemd service
  3. no, and no
  4. will provide if broken state returns

Thanks :)

On Tue, Nov 24, 2026 at 2:50 PM opencodejr[bot] @.***> wrote:

opencodejr[bot] left a comment (anomalyco/opencode#66166) https://github.com/anomalyco/opencode/issues/66166#issuecomment-7142648847

Thanks for the detailed report. I couldn't reproduce this on 2.3.0 yet.

What I tried, on Linux with an isolated home directory and no plugins:

  1. Put your providers.main block in ~/.config/opencode/opencode.json, pointed at a local mock OpenAI-compatible server. In a second run I also added "update": "disable" and an instructions entry, to match the keys your /api/config output showed.
  2. Ran opencode service start, then checked opencode api get /api/provider and /api/config, and ran opencode run --model main/qwen.
  3. Stopped and started the service again (the process ID changed) and repeated the checks, then ran opencode api post /api/location/reload.

Every time, including right after the restart, main was listed in /api/provider, providers was in the config document, and main/qwen was selected without a ModelUnavailableError.

One detail stands out: in your broken state, /api/config showed the global document with the providers key missing. That suggests the service read a different version of the file, or a different file. These would help narrow it down:

  • Is ~/.config/opencode or opencode.json a symlink, e.g. into a dotfiles repo? #55119 https://github.com/anomalyco/opencode/issues/55119 is a related report where config changes weren't picked up from a symlinked ~/.config/opencode.
  • How is the service started after a reboot or restart: opencode service start, a systemd unit, the desktop app, or auto-start from another opencode command? Does that environment set a different HOME, XDG_CONFIG_HOME or OPENCODE_CONFIG* variable?
  • Was providers added to the file, or the file rewritten, after the service started? Is there also an opencode.jsonc in that folder?
  • In the broken state, the full output of opencode api get /api/config (the path of each document), and the log lines around location services booted that mention config or providers.

You can reply here with the details, or edit the issue and leave a short comment saying you've updated it.

— Reply to this email directly, view it on GitHub https://github.com/anomalyco/opencode/issues/66166?email_source=notifications&email_token=AAAB5BSX323XYSJRUYUYT6T52XQ7JA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTOMJUGI3DIOBYGQ32M4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2KYZTPN52GK4S7MNWGSY3L#issuecomment-7142648847, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAB5BSYCIMRXZRRSODUKW352XQ7JAVCNFSNUABFKJSXA33TNF2G64TZHM4TONJXGM2DGMJZHNEXG43VMU5TMNJYHE4TGNZTG422C5QC . You are receiving this because you authored the thread.Message ID: <anomalyco/opencode/issues/66166/7142648847 @.***>

s0nspark avatar Nov 24 '26 19:11 s0nspark

Thanks for the details. I tried again with them, but it still doesn't reproduce on 2.3.0.

What I did, with your providers.main block plus "update": "disable" kept in a separate dotfiles folder:

  1. Symlinked it two ways: ~/.config/opencode pointing at the dotfiles folder, and only opencode.json as a symlink.
  2. Started opencode serve --service the way systemd would (only HOME and PATH set, working directory /).
  3. Checked /api/provider and /api/config, restarted the service, checked again, then ran POST /api/location/reload and checked once more.

In every check main was listed and providers was in the config document.

The symlinked folder does show the known watcher problem from #55119. The log has failed to subscribe ... inotify_add_watch on '.../.config/opencode' failed: Not a directory, so the service doesn't watch that folder for edits. Even so, the file was read in full at each boot, so this alone doesn't explain the missing providers you saw.

When the broken state comes back, these would help:

  • The full output of opencode api get /api/config
  • The log lines from that boot around location services booted, and any failed to subscribe or config errors
  • Your systemd unit file (leave out any secrets), especially Environment=, WorkingDirectory=, ExecStart= and any After=/Requires= lines
  • Where the symlink points: is the target on another mount or drive, or inside a git repo that might be on another branch or checkout when the service starts?

A reply here with those is enough.

opencodejr[bot] avatar Nov 24 '26 19:11 opencodejr[bot]

Taking this. The shape I'm chasing: the config plugin reads config.entries() once at construction and re-applies on config.updated; if the global document lands after the Location's plugins were built and that arrival doesn't publish config.updated, the provider transforms never see it — and POST /api/location/reload rebuilding the Location is exactly what would fix it, which matches the report. I'll confirm against packages/core/src/config.ts and the boot path before touching anything.

Guembri01 avatar Nov 24 '26 20:11 Guembri01

Withdrawing my offer too — same reason as #66146, and I'd rather not open a guess.

The race I described in my last comment is already closed in the code:

  • packages/core/src/config/plugin/entry-observer.ts:14-19 reads the entries, then subscribes, then re-reads with the comment "Close the race between the first read and establishing the subscription."
  • :20-23 re-reads and calls the plugin's reload on every config.updated, and the provider plugin's reload is ctx.integration.reload().pipe(Effect.andThen(ctx.provider.reload())) (config/plugin/provider.ts:21-25).
  • The provider transform itself derives from loaded.entries, which that observer keeps current (:57-95).

So a global document that arrives late does land, provided config.updated is published and config.entries() contains it. The remaining hole I can name is the one the bot already probed: a symlinked config directory, where the file watcher may not observe the real path — which would explain "only an explicit POST /api/location/reload registers them", because that rebuilds the Location and re-reads config without needing a watch event.

That is testable, but not by me from here: it needs your dotfiles layout (which path is the symlink, and whether the real path is inside the watched config directory). If you can paste, for the broken state:

  • readlink -f ~/.config/opencode and readlink -f ~/.config/opencode/opencode.json
  • the log lines around service start that mention config or watch
  • whether touching the real file (not the symlink) makes the provider appear without a reload

…then this becomes a real bug with a real seam, and I'll take it. Without that, a patch here would be a change to code that already handles the case it is being blamed for.

Guembri01 avatar Nov 24 '26 20:11 Guembri01

Thanks @s0nspark, and thanks @Guembri01 for looking into the code.

I'm closing this for now because we couldn't reproduce it. On 2.3.0, I set up your provider config with a symlinked ~/.config/opencode (and separately a symlinked opencode.json) and started serve --service the way systemd would. The custom provider was registered at every boot, after a restart, and after a reload. The symlink does trigger the known watcher error from #55119 (inotify_add_watch ... Not a directory), but the config was still read in full at boot.

We were waiting for details from the broken state:

  • the output of opencode api get /api/config
  • the log lines from that boot
  • your systemd unit
  • where the symlink points (readlink -f ~/.config/opencode)
  • whether editing the real file makes the provider appear without a manual reload

If the problem comes back, reply here with those details and the issue will reopen.

opencodejr[bot] avatar Nov 25 '26 01:11 opencodejr[bot]