Repository navigation
Conversation
|
/review |
There was a problem hiding this comment.
Thanks — this is a focused, well-tested fix and the description explains the "why" clearly. CI (stylua + LuaLS) is green and the contributor checklist is complete. I don't see any blocking issues.
A few non-blocking thoughts (suggestions only — the human can decide):
-
Channel selection / stale registrations. Picking the newest parseable registration is a reasonable heuristic and matches the issue's suggestion. However, when multiple channels share the state dir, a newer-but-stale
service-<channel>.json(server since exited) will shadow an older liveservice.json.find()only triesregistration()'s single result, then falls through toserver.startinstead of using the live registration. If you want to harden this, expose the ordered candidates and havefind()try each until one connects, or prefer plainservice.jsonfirst and only fall back to channel files. Fine as a follow-up; not a blocker for this fix. -
mtime.nsec(nit).stat.mtime.nseccan be absent on older libuv/luv builds. In practice all stats in one process come from the same library, so nil/number mixing is unlikely, but(a.mtime.nsec or 0)/(b.mtime.nsec or 0)would make the comparator obviously safe. -
The
^service%-.+%.json$pattern deliberately (and correctly) rejectsservicex.json/service-prod.json.tmp, andfs_stat+type == "file"handles symlinks andservice-*.jsondirectories as described. Nice.
Skipping invalid/URL-less newer files in favor of older valid ones, and keeping the single-service.json behavior unchanged, both look correct.
|
Thanks for your contribution @taekop ! It generally LGTM. I agree with the risk of stale registration files though. Sequentially attempting to connect to each discovered registration in |
OpenCode v2 names the registration file service-<channel>.json for channels other than latest/dev/beta/next (e.g. Nix builds use prod), so only reading service.json missed those servers. Read the newest valid service.json or service-*.json in the state directory instead. Fixes nickjvandyke#336
A newer registration left behind by an exited server (e.g. a stale service-prod.json) shadowed an older live service.json, so find() fell through to starting a server. Return all valid registrations newest first and try them in order.
ca959ab to
60fd038
Compare
|
Agreed, done in 60fd038: discovery now returns every valid registration newest first ( |
|
Nice! Cool solution with imo we can remove Then LGTM! |
Tasks
Description
OpenCode v2 writes
service-<channel>.jsoninstead ofservice.jsonfor channels other thanlatest/dev/beta/next(filename()inpackages/cli/src/services/service-config.ts). The Nix package usesprod, so discovery only looking atservice.jsonnever found the server.registration()now listsservice.jsonandservice-*.jsonin the state directory, newest first, and returns the first one with a validurl, as suggested in the issue. Symlinked files are followed as before, and on an mtime tieservice.jsonwins. Behaviour with onlyservice.jsonis unchanged. Also updated the doc comments and AGENTS.md mentions ofservice.json.Testing
$XDG_STATE_HOME/opencode/service-prod.json(noservice.json).:checkhealth opencode. On main: "No OpenCode background service registered yet". With this change: "OpenCode background service (v2.0.18) registered athttp://127.0.0.1:49374".require("opencode.server.discovery").registration()headless against these state dirs. Before/after:service.json, onlyother.json/servicex.json, onlyservice-prod.json.tmp, a directory namedservice-x.json:nilboth before and afterservice.json: same result both before and afterservice-prod.json/service-local.json/service-my[chan]-1.json:nilbefore, now foundurl-less newer file is skipped in favour of the older valid onestylua --check .andlua-language-server --check=.(the CI config, with library paths pointed at local Neovim 0.12.5 runtime, snacks.nvim and blink.cmp) report no problems.Related Issue(s)
Fixes #336
Screenshots/Videos
N/A