Repository navigation
Conversation
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
There was a problem hiding this comment.
As written, this breaks service registration for every service start, not just wildcard binds. formatClientAddress reads address.hostname and checks _tag === "UnixAddress", but Effect's NetAddress.SocketAddress is InetAddressV4 | InetAddressV6 | UnixPathAddress, and the IP is in address.address. So hostname is always undefined and hostname.includes throws before the registration file is written.
How I checked it:
tsc -binpackages/cli: 5 errors inservice-registration.ts(TS2367 and TS2339); the base is clean.bun test test/service.test.ts: 12 failures withTypeError: undefined is not an object (evaluating 'hostname.includes')fromformatClientAddress; the base passes 28 with 0 failures.
Public API: the url in the registration file (~/.local/state/opencode/service.json) would change from the wildcard address to loopback for services bound to 0.0.0.0/::. No CLI, config or SDK changes.
Other concerns:
pair.tstreats a loopback registered URL as "only reachable locally". It then prints the SSH port-forward hint and "runopencode service set hostname 0.0.0.0". A service already bound to0.0.0.0would now register127.0.0.1and get that advice. Either keep the wildcard in the registration file and rewrite it on the client side, or adjustpair.tsin the same PR.- The same wildcard-to-loopback rewrite now lives in
serviceURL,formatClientAddress, the tunnel target and desktop. A single shared helper would keep them consistent.
Related: #49796
1be12cd to
289c6e4
Compare
There was a problem hiding this comment.
The crash from the last review is fixed: formatClientAddress now uses NetAddress.isInetAddress/formatIp. The wildcard rewrite is now one shared normalizeLoopback helper, and opencode pair no longer suggests setting hostname 0.0.0.0 when it is already set.
How I checked it:
- Called
ServiceRegistration.registerdirectly on both checkouts. On the base,0.0.0.0/::binds registerhttp://0.0.0.0:…/http://[::]:…. With this PR they registerhttp://127.0.0.1:…/http://[::1]:…, and other addresses are unchanged. I didn't reproduce the proxy case from #49796 end to end. tsc -binpackages/cliis clean, andtest/service.test.tspasses as on the base.
Public API: the url in the registration file ~/.local/state/opencode/service.json changes from the wildcard to loopback for wildcard binds. Readers in this repo are compatible.
One small change in behaviour, not blocking: with remote access on and the service bound to ::, the tunnel target is now [::1]:<port> instead of 127.0.0.1:<port>.
No other concerns.
289c6e4 to
d2f9958
Compare
There was a problem hiding this comment.
The new commit restores the base behaviour for the remote tunnel target: a service bound to :: targets 127.0.0.1:<port> again instead of [::1]:<port>, which was the small change I noted last time. tsc -b in packages/cli is clean and test/service.test.ts passes. Public API: no change from the last review (the registration file url is loopback for wildcard binds). No concerns.
805c6d5 to
7f92614
Compare
7f92614 to
f46d5d4
Compare
There was a problem hiding this comment.
The new push only merges dev. The change against dev is the same as in my last review.
I ran the #49796 reproduction from source against a proxy that returns 502 for 0.0.0.0:
- On
dev, the service registershttp://0.0.0.0:<port>,service statusprintsstopped, andsession listfails with "port already in use" after about 1300 probes through the proxy. - With this PR, it registers
http://127.0.0.1:<port>,statusandsession listboth work, and no requests reach the proxy.
tsc -b in packages/cli is clean and test/service.test.ts passes.
Public API: unchanged since the last review (the registration file url is loopback for wildcard binds). No concerns.
When hostname is set to 0.0.0.0 (listen on all interfaces), the service registration file recorded http://0.0.0.0:port as the client connection URL. Since 0.0.0.0 is a bind wildcard rather than a routable address, client auto-discovery could fail to connect to the background service.
Normalize 0.0.0.0 to 127.0.0.1 and :: to ::1 in both the registration URL and the incumbent check probe URL, matching the existing behavior in the remote tunnel target construction.
Issue for this PR
Closes #49796
Type of change
What does this PR do?
When
hostnameis set to0.0.0.0in~/.config/opencode/service.json(listen on all interfaces), the service registration file at~/.local/state/opencode/service.jsonrecordedhttp://0.0.0.0:portas the client connection URL. Since0.0.0.0is a bind wildcard, not a routable destination address, the secondopencodeclient's auto-discovery fails to connect to the running background service.service-registration.tsusedHttpServer.formatAddress(address)which passes the bind hostname directly into the URL. The remote tunnel target construction already normalizes0.0.0.0→127.0.0.1, but the registration path missed this step.Added
formatClientAddress()to normalize0.0.0.0→127.0.0.1and::→::1for the registration URL, and applied the same normalization inserviceURL()used by thefindIncumbentstartup probe.How did you verify your code works?
Tested locally: with
hostname: "0.0.0.0"andport: 14096in~/.config/opencode/service.json, the registration file now containshttp://127.0.0.1:14096instead ofhttp://0.0.0.0:14096, and a secondopencodeterminal connects to the running service without issues.Checklist
Added by the opencode bot (AI-generated).
Related: #49796
Public API: registration file
urlis now loopback instead of 0.0.0.0/:: for wildcard binds (compatible with existing readers)