bug: v2 service discovery misses Nix-packaged OpenCode (writes service-prod.json, plugin reads service.json)
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
Research direction
Start in lua/opencode/server/discovery/init.lua at M.registration(), then reproduce with the isolated XDG state directory and the Nix package described in the issue. Verify discovery finds service-prod.json while preserving discovery of service.json, and confirm :checkhealth no longer reports that no service is registered.
Written by the indexing model from the issue text.
Description
Summary
Server discovery only looks for service.json in the XDG state directory, but OpenCode v2 names the registration file after OPENCODE_CHANNEL. The Nix package sets OPENCODE_CHANNEL = "prod", so it writes service-prod.json and the plugin never finds a server.
Why the filename is channel-dependent
packages/cli/src/services/service-config.ts:
export function filename(channel = OPENCODE_CHANNEL) {
if (channel === "latest" || channel === "dev" || channel === "beta" || channel === "next") return "service.json"
return `service-${channel.replace(/[^a-zA-Z0-9._-]/g, "-")}.json`
}
So only latest, dev, beta and next produce the plain name. nix/opencode.nix on v2 builds with env.OPENCODE_CHANNEL = "prod", which is not one of them, so Nix users get service-prod.json.
lua/opencode/server/discovery/init.lua hardcodes the plain name:
local path = vim.fs.joinpath(state_dir, "service.json")
Reproduction
From a Nix-packaged OpenCode v2 (nix build .#opencode), with an isolated state dir:
$ export XDG_STATE_HOME=/tmp/oc/state
export XDG_DATA_HOME=/tmp/oc/data XDG_CACHE_HOME=/tmp/oc/cache XDG_CONFIG_HOME=/tmp/oc/config
$ opencode service start
http://127.0.0.1:49374
$ ls $XDG_STATE_HOME/opencode/
service-prod.json
$ cat $XDG_STATE_HOME/opencode/service.json
cat: .../service.json: No such file or directory
Neovim then reports, in :checkhealth opencode:
No OpenCode background service registered yet. Run
opencodeto start it, or setvim.g.opencode_opts.server.url.
...even though the service is running and reachable, and even after opencode has been launched from the terminal.
For comparison, the same binary built with OPENCODE_CHANNEL=latest writes service.json and discovery works:
$ export XDG_STATE_HOME=/tmp/oc2/state # isolated again
$ opencode service start
http://127.0.0.1:49374
$ cat $XDG_STATE_HOME/opencode/service.json
{"id":"...","version":"2.0.18+dd786c6","url":"http://127.0.0.1:49374","pid":122289,"password":"..."}
Suggested fix
M.registration() should read the channel-suffixed files too, since that is what OpenCode writes. The registration payload is self-describing (url, password, pid, version), so a small glob over the state directory, newest service*.json first, would cover every channel without needing to know the channel name.
This keeps working for the channels that already write service.json, and adds the ones that do not. It also avoids tying the plugin to OpenCode's channel list, which is a separate upstream detail that can change.
Impact
Anyone consuming the Nix package (or any build that sets a channel other than latest/dev/beta/next) cannot use the plugin without hardcoding server.url and exporting OPENCODE_SERVER_PASSWORD by hand, which defeats the point of the background-service model.
Environment
- opencode.nvim
06770e2(main, the v2-supporting default) - OpenCode 2.0.18, Nix package,
x86_64-linux - Neovim 0.11
- Dominant language
- Lua
- Stars
- 3.8k
- Forks
- 161
- Avg merge
- 16h 31m
- Merged PRs (30d)
- 4
Getting set up
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from nickjvandyke/opencode.nvim
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 55/100
nickjvandyke/opencode.nvim#335 · 1 comment ·
-
enhancement
Difficulty 5/5 Over a week Newbie friendliness 45/100
nickjvandyke/opencode.nvim#321 · 2 comments · 1 reaction ·
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 52/100
nickjvandyke/opencode.nvim#41 · 1 comment · 9 reactions ·
All issues in nickjvandyke/opencode.nvim
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 95/100
-
Bug Feature Request Forever Module - Townsfolk Needs testing/reproduction
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
ai-authored model:claude-opus-5-5
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Unconfirmed bug
Difficulty 1/5 Under an hour Newbie friendliness 88/100
luanti-org/luanti#17605 · 1 comment ·
Maintainers usually reply within 2 days
-
agent-in-progress agent-research-recommend enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
codymikol/multiverse.nvim#337 · 1 comment ·
Maintainers usually reply within 1 day