Skip to content

fix(server): emit one process entry per (PID, port) pair#242

Merged
nickjvandyke merged 1 commit into
nickjvandyke:mainfrom
erroris3:fix/server-multiple-ports-per-pid
Apr 27, 2026
Merged

fix(server): emit one process entry per (PID, port) pair#242
nickjvandyke merged 1 commit into
nickjvandyke:mainfrom
erroris3:fix/server-multiple-ports-per-pid

Conversation

@erroris3
Copy link
Copy Markdown
Contributor

@erroris3 erroris3 commented Apr 27, 2026

Tasks

  • I read CONTRIBUTING.md
  • I filled out this PR template
  • I reviewed AI-generated code myself
  • I made sure my changes pass automated checks
  • I responded to and/or resolved automated PR comments

Description

A single opencode PID can listen on multiple ports (e.g. when its TUI and HTTP server bind separately, or when multiple listeners are opened during startup). The previous get_ports implementation in lua/opencode/server/process/unix.lua collected results into a pids_to_ports map keyed by PID, so each new port for the same PID overwrote the previous one. Only the last port emitted by lsof survived, 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 by lsof. Every listening port now surfaces to the discovery layer, which already deals in opencode.server.process.Process[].

While here:

  • Renamed get_ports to get_processes_with_ports to reflect the new return shape.
  • Added a nil guard on the parsed port so malformed lsof lines do not insert a { pid, port = nil } entry.
  • Removed the now-redundant map-to-list conversion in M.get, which just forwards the helper's return value.

No public API changes; the function is local to the module and M.get keeps its existing return type.

Related Issue(s)

image

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.
@nickjvandyke
Copy link
Copy Markdown
Owner

Nice find, thank you for a fix!

e.g. when its TUI and HTTP server bind separately

Is it possible to change the pgrep or lsof command to only capture the server? We don't send requests to the TUI. I assume not, and the later Server.new checks should filter out the TUI. But would be nice to pre-empt that.

@nickjvandyke nickjvandyke merged commit 0e3ae21 into nickjvandyke:main Apr 27, 2026
2 checks passed
@erroris3
Copy link
Copy Markdown
Contributor Author

Nice find, thank you for a fix!

e.g. when its TUI and HTTP server bind separately

Is it possible to change the pgrep or lsof command to only capture the server? We don't send requests to the TUI. I assume not, and the later Server.new checks should filter out the TUI. But would be nice to pre-empt that.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants