Title: Local proxy discovery: port files, sockets, or a registry instead of fixed ports? · Issue #437 · developing-today/code · GitHub
Open Graph Title: Local proxy discovery: port files, sockets, or a registry instead of fixed ports? · Issue #437 · developing-today/code
X Title: Local proxy discovery: port files, sockets, or a registry instead of fixed ports? · Issue #437 · developing-today/code
Description: Question (Drew, 2026-10-20) The four local proxies in bin/ (clef 18742, agy 18743, codex 18744, antigravity-ls 18745) bind fixed localhost ports that other config must agree with. PR #431 + its follow-up single-sourced the numbers, so th...
Open Graph Description: Question (Drew, 2026-10-20) The four local proxies in bin/ (clef 18742, agy 18743, codex 18744, antigravity-ls 18745) bind fixed localhost ports that other config must agree with. PR #431 + its fol...
X Description: Question (Drew, 2026-10-20) The four local proxies in bin/ (clef 18742, agy 18743, codex 18744, antigravity-ls 18745) bind fixed localhost ports that other config must agree with. PR #431 + its fol...
Opengraph URL: https://github.com/developing-today/code/issues/437
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Local proxy discovery: port files, sockets, or a registry instead of fixed ports?","articleBody":"## Question (Drew, 2026-10-20)\n\nThe four local proxies in `bin/` (clef 18742, agy 18743, codex 18744, antigravity-ls 18745) bind fixed localhost ports that other config must agree with. PR #431 + its follow-up single-sourced the numbers, so the copies can no longer drift — but a fixed port is still a fixed port: it can be taken by something else, and it must be known in advance by every consumer. Is there a better discovery mechanism? Options Drew named: pick ports randomly/nearby but stay findable; or first-launcher-takes-a-well-known-port and serves a registry of all running helpers. What do established apps actually do?\n\n## The binding constraint\n\nThe main consumer, `.opencode/opencode.jsonc`, is **static config**: at load time it can substitute `{env:VAR}` and nothing else (developing-today/opencode `packages/core/src/config/variable.ts`). It cannot read files, query a registry, or follow a redirect. Any design that moves the port at runtime therefore needs one of:\n\n- a launcher/shim that resolves the endpoint and exports the env vars before opencode starts, or\n- a fork change (e.g. a `{file:...}` substitution, or `{env:VAR:-default}` fallback syntax — related: #434, the unset-variable case).\n\nEvery option below is judged against that constraint.\n\n## Options\n\n### (a) Port-file discovery — service binds, writes its endpoint to a well-known file\n\nThe service writes `$XDG_STATE_HOME/\u003cname>/endpoint.json` (`{host, port, pid, url}`) on listen and unlinks it on exit. Clients that can read files always find the one running instance, whatever port it landed on.\n\nPrecedents: Chrome DevTools writes `DevToolsActivePort` (port + path) into the user-data dir for exactly this; Jupyter writes runtime connection files (`jpserver-*.json` with URL) under the runtime dir; VS Code's server/CLI handoff works the same way.\n\n**Status: the publish half is implemented** in the follow-up PR to #431 (all four proxies now write/remove their endpoint file). The consume half exists only for future tooling until opencode or a launcher reads it.\n\n### (b) Port fallback / increment — try the well-known port, else scan nearby\n\nDev servers do this (Vite, webpack-dev-server) — but their \"client\" is a human reading a printed URL. Here it is actively harmful: a proxy that lands on 18746 silently disagrees with the session's `{env:...}` value and the static config, recreating the exact silent-dead-provider failure #431 fixed, now nondeterministically. **Verdict: do not adopt** (except in combination with (a) + a file-reading client).\n\n### (c) Registry on a well-known port (Drew's sketch)\n\nFirst launcher binds a registry port and serves a stable interface listing every running helper and how to reach it.\n\nPrecedents: this is the classic **portmapper** pattern — Erlang's `epmd` (fixed port 4369) maps node names to the ephemeral ports nodes actually bound; ONC RPC's rpcbind is the same idea. It works there because the runtime speaks the protocol natively. Docker/Consul look similar but actually rendezvous on a Unix socket / agent API, not a TCP registry port.\n\nProblems here: the recursion doesn't bottom out (the registry itself needs a fixed port or socket — if it uses a socket, option (d) alone was simpler); the loser of the bind race must reliably become a registry client; the registry is a new always-on component and a single point of failure; and opencode still can't query it. **Verdict: real pattern, wrong fit** — the registry's job is already done by systemd (it knows every unit and its state; `systemctl --user show` is the registry interface) for the service-managed case.\n\n### (d) Unix domain sockets instead of TCP\n\nNo ports at all; each service listens on a deterministic path in `$XDG_RUNTIME_DIR`/state dir. **This repo already does it**: mcpx's daemon listens on `daemon-\u003cconfhash>.sock` in its state dir, overridable via `MCPX_DAEMON_ENDPOINT`, with `mcpx resolve` as the resolver. Also Docker (`docker.sock`), tmux, ssh-agent (`$SSH_AUTH_SOCK` env publication), D-Bus session bus.\n\nBlocker: an opencode provider `baseURL` is an HTTP URL; the AI SDK cannot dial a Unix socket from a URL (undici needs a custom dispatcher). Closing this needs a fork change or a TCP→socket forwarder — which reintroduces a port. **Verdict: right answer for socket-capable consumers (mcpx proves it in-repo); blocked for opencode providers today.**\n\n### (e) systemd socket activation\n\nsystemd owns the well-known listener and hands the fd to the service. Already in use in this repo: OpenChamber's `systemd.user.sockets.openchamber` holds `127.0.0.1:3000` across restarts so connections queue instead of being refused. Extending it to the four proxies removes the crash-loop failure when a previous instance still holds the port and makes restarts seamless, at the cost of a small `LISTEN_FDS` shim in each `.mjs` (`server.listen({ fd: 3 })`). It keeps fixed ports, so it solves reliability, not discovery. **Verdict: pragmatic, worth doing independently.**\n\n## In-repo evidence that fixed ports already fail one layer up\n\nThe Antigravity language server — the upstream `antigravity-ls-proxy` wraps — binds a **random port every start**. `bin/antigravity-ls-proxy.mjs` and `bin/sync-models.mjs` discover it by scraping the process command line and logs for `--http_server_port N` / \"listening on random port at N\" and probing candidates. Log-scraping is the fragile worst form of discovery; it's what you're forced into when the service publishes nothing. (a) is the same idea with the service cooperating.\n\n## Recommendation\n\n1. Keep the single-sourced fixed ports as the default contract (done: #431 + follow-up PR fixing #435).\n2. Port-file publication (a) is implemented publish-side in that PR; file-capable tooling should prefer it over assuming the port.\n3. **Decision for Drew**: the only route to true dynamic ports (bind port 0 + port file, no fixed contract at all) is a fork change — teach opencode's config a `{file:...}` substitution (or `{env:VAR:-default}` fallback, cf. #434) so `baseURL` can resolve from `endpoint.json`. With that, the proxies could bind ephemeral ports and the fixed-port era ends. Without it, (e) is the pragmatic ceiling.\n4. Do not adopt (b); (c) is superseded by systemd + (a).\n\n## Related\n\n- #431 — codex-proxy single-source\n- #435 — single-source the remaining three proxies (fixed by the follow-up PR)\n- #434 — `{env:...}` has no fallback when the variable is unset\n\n## Acceptance criteria\n\n- A decision is recorded on this issue (chosen option, or explicitly keep the fixed ports) with the reasoning against the static-config constraint in `.opencode/opencode.jsonc`.\n- If a new discovery mechanism is adopted, follow-up implementation issues are filed and linked; if not, the port-file publish behaviour already shipped is documented as the standing answer.\n- The decision addresses how a consumer that can only substitute `{env:VAR}` at load time finds a helper whose port moved, or states why that case cannot arise.\n","author":{"url":"https://github.com/dezren39","@type":"Person","name":"dezren39"},"datePublished":"2026-10-20T20:11:08Z","url":"https://github.com/developing-today/code/issues/437"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:70e8e23b-8ff5-c1f3-a3b6-e7dfec9aacd2 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 84AC:1FD7D4:3FBD66:55C888:6B061DE3 |
| html-safe-nonce | 9ea1bf16010f4bc91adf12db58ee86e3b128fbaf6a98624ad6a48bea531fbd04 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NEFDOjFGRDdENDozRkJENjY6NTVDODg4OjZCMDYxREUzIiwidmlzaXRvcl9pZCI6IjM0ODg3MjA4Njg4Mjg2NTA5NzkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 0dc67567e71051858b9e80c01ef92db992d59ab4f33b6167f85ffaa9f878ea0c |
| hovercard-subject-tag | issue:5948857387 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/developing-today/code/437/issue_layout |
| twitter:image | https://opengraph.githubassets.com/97882a7cca0722b649859b3770316a867b35235e4fa94a397216ccc61e65ff82/developing-today/code/issues/437 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/97882a7cca0722b649859b3770316a867b35235e4fa94a397216ccc61e65ff82/developing-today/code/issues/437 |
| og:image:alt | Question (Drew, 2026-10-20) The four local proxies in bin/ (clef 18742, agy 18743, codex 18744, antigravity-ls 18745) bind fixed localhost ports that other config must agree with. PR #431 + its fol... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dezren39 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9a7c5824b75ea2ec5e3de73a483229c7bb9f32a774ffd401f010dd9bacf1483d |
| turbo-cache-control | no-preview |
| go-import | github.com/developing-today/code git https://github.com/developing-today/code.git |
| octolytics-dimension-user_id | 26439447 |
| octolytics-dimension-user_login | developing-today |
| octolytics-dimension-repository_id | 627308783 |
| octolytics-dimension-repository_nwo | developing-today/code |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 627308783 |
| octolytics-dimension-repository_network_root_nwo | developing-today/code |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | b25c3080e84402f75431d8dc7a96b2635219cec7 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width