fix(server): emit one process entry per (PID, port) pair#242
Conversation
A single opencode PID may listen on multiple ports. The previous
`pids_to_ports` map keyed by PID dropped all but the last port seen
for that PID, hiding valid servers from discovery.
Replace the map with a list of {pid, port} entries so every listening
port is surfaced. Rename `get_ports` to `get_processes_with_ports`
to reflect the new return shape.
|
Nice find, thank you for a fix!
Is it possible to change the |
Sorry, that was my mistake. I’m not very good at English, so I used AI to generate the description and didn’t check it carefully. The open port is not related to the TUI, and the current command that you did is already correct. I found that some opencode plugins can open additional ports for example something like CLIProxyAPI. So the port being detected is likely coming from one of those plugins, nothing relate to the TUI itself. |
Tasks
Description
A single
opencodePID can listen on multiple ports (e.g. when its TUI and HTTP server bind separately, or when multiple listeners are opened during startup). The previousget_portsimplementation inlua/opencode/server/process/unix.luacollected results into apids_to_portsmap keyed by PID, so each new port for the same PID overwrote the previous one. Only the last port emitted bylsofsurvived, and any earlier listening ports for that PID were silently dropped from server discovery.This change replaces the PID-keyed map with a flat list of
{ pid, port }entries, appending one entry per port reported bylsof. Every listening port now surfaces to the discovery layer, which already deals inopencode.server.process.Process[].While here:
get_portstoget_processes_with_portsto reflect the new return shape.nilguard on the parsed port so malformedlsoflines do not insert a{ pid, port = nil }entry.M.get, which just forwards the helper's return value.No public API changes; the function is local to the module and
M.getkeeps its existing return type.Related Issue(s)