Skip to content

fix(opencode): reuse local server for review flows#567

Merged
backnotprop merged 2 commits intobacknotprop:mainfrom
oorestisime:fix/opencode-reuse-existing-server
Apr 15, 2026
Merged

fix(opencode): reuse local server for review flows#567
backnotprop merged 2 commits intobacknotprop:mainfrom
oorestisime:fix/opencode-reuse-existing-server

Conversation

@oorestisime
Copy link
Copy Markdown
Contributor

@oorestisime oorestisime commented Apr 15, 2026

Summary

The last 2 items were needed to fully test the ./tests/manual/local/sandbox-opencode.sh --keep as otherwise i wasnt hitting the right bundled files. I also had to remove it from my global opencode config.

What I explored

  • reproduced the original failure where the review AI path tried to start a second opencode serve and collided with an existing local server
  • traced the OpenCode command flow in the sandbox and found a separate local-testing issue: the source-loaded plugin was resolving bundled HTML from the wrong directory, so local runs could fail before opening the UI

Main issue

  • When spawning the opencode serve command for a local server it stays open until someone kills it manually. Can confirm this by doing pgrep -af opencode. So on subsequent review commands the server was still running and hence the port conflict.

Final approach

  • keep the existing review command UX intact
  • keep the fix minimal: attach to the default local OpenCode server if it exists, otherwise spawn a new one
  • avoid extra host-specific plumbing and keep only the runtime changes needed for local plugin runs and server reuse

Open questions

  • I am not sure if your intention was to always generate a new opencode server. If thats the idea then we should kill the server when the review is done. I feel this might be problematic to be honest since we don't know where the ask might come from nor i am sure if there'a reliable way to kill the server after we are done.
  • I am not sure if we should be reusing the existing client as a fallback if it exists either.
  • Could make this more reliable and spawn to another port than 4096, but if we dont kill this correctly then we end up with many ports open spammable :D

Try the default local OpenCode server before spawning a new one, and resolve bundled assets and command paths correctly when the plugin is loaded from source during local testing.
@backnotprop
Copy link
Copy Markdown
Owner

@oorestisime could you do the typecheck fixes? lmk if they are a pain

@oorestisime
Copy link
Copy Markdown
Contributor Author

@oorestisime could you do the typecheck fixes? lmk if they are a pain

Yeap done. this was due to changing the opencode client type to be more honest with the sdk.
image

@backnotprop backnotprop merged commit 14bff36 into backnotprop:main Apr 15, 2026
7 checks passed
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.

OpenCode AI tab: spawns new opencode serve instead of reusing existing server (port conflict)

2 participants