Repository navigation
Closed
Description
Summary
Remote mode currently defaults every Plannotator server to the fixed port 19432 so SSH/devcontainer port forwarding stays predictable. That works for a single session, but breaks when multiple Claude Code / OpenCode sessions are started on the same remote machine: the second session and later hit EADDRINUSE and fail.
Today the server only retries the same port a few times; it never searches for another free port.
Environment
- OpenCode v1.3.6
- Plannotator v0.16.0
- Remote mode via SSH (connecting from a local client to a remote dev machine running OpenCode)
Why this happens
- Local mode uses port
0, so the OS picks a free port. - Remote mode uses fixed port
19432inpackages/server/remote.ts. - Plan/review/annotate servers retry the same port instead of falling back to another one.
PLANNOTATOR_PORTworks as a manual escape hatch, but requiring users to manage ports in~/.zshrcis not ideal.
Proposed solution
Use a small remote port range instead of a single fixed port.
Suggested behavior:
- Keep
19432as the default starting port. - In remote mode, if
19432is busy, try19433,19434, ... up to19439. - If
PLANNOTATOR_PORTis explicitly set, preserve current behavior and only try that exact port. - Keep local behavior unchanged (
0=> OS-assigned free port).
Why this approach
Pros:
- Fixes multi-session collisions for the common case.
- Still keeps remote port forwarding predictable.
- Requires relatively small backend changes.
- No frontend changes.
- No new long-lived daemon/service.
Tradeoffs:
- Remote users should forward a small range instead of a single port.
- More than ~8 simultaneous sessions would still fail.
Files likely involved
packages/server/remote.tspackages/server/index.tspackages/server/review.tspackages/server/annotate.tsapps/pi-extension/server/network.tspackages/server/remote.test.ts- remote/devcontainer docs
Considered alternative: shared reverse proxy
A single stable proxy port with per-session routing is possible, but it looks much heavier than the problem warrants:
- frontend currently hardcodes many root-relative
/api/...calls - would require a long-lived proxy/daemon and session registration lifecycle
- would add more complexity around SSE/streaming and cleanup
For this problem, port-range fallback seems like the better tradeoff.
Metadata
Metadata
Assignees
Labels
No labels
Activity
foxytanuki commentedon Mar 31, 2026
Here's the workaround I've been using in
~/.zshrcso far:This works for the most part, but it has a race condition: the port is probed at launch time, but the socket isn't actually bound until Plannotator needs it. If two shells open in quick succession, both may see the same port as free before either has claimed it.
The port-range fallback proposed here would fix this properly by doing the selection atomically at bind time on the server side.
foxytanuki commentedon Mar 31, 2026
Closing this as not pursuing upstream in the current form.
Reference implementations in my fork:
What the remote port fallback PR does:
19432-19439instead of failing immediately on19432PLANNOTATOR_PORTis setEADDRINUSEdetection so the fallback actually worksWhy I’m not upstreaming it as-is:
PermissionRequest/ExitPlanModesuccess path does not provide a clean user-visible channel for a customPlannotator is ready at http://...messageThe OpenCode PR shows one possible workaround, but it relies on
session.prompt()rather than a proper status/tool UI surface, so it comes with tradeoffs like queued delivery and session noise.So at this point:
Because of that, I think this is better kept as a fork/reference implementation rather than merged upstream in its current form.