You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
opencode service set/unset silently does nothing when run from inside a session #63138
I wanted to turn remote access off after pairing my phone, and ran opencode service set remote false through OpenCode itself. It appeared to do nothing — opencode service get remote still said true. It took several tries before it stuck. Running it myself in a normal terminal worked first time.
The cause looks like ordering in ServiceConfig.set (packages/cli/src/services/service-config.ts): every key calls Service.stop(...) before write(...). Tool shells run as children of the background service, so stopping the service kills the process running the command before it reaches the write, and the setting is silently lost. unset has the same ordering.
I confirmed this on v2.2.7 without touching remote access, using cors because it shares the identical code path. Run from a normal shell, the service is stopped and cors is written. Run from a shell owned by the service, the process dies mid-command and cors is not written — 3 out of 3 attempts. To get a process that is genuinely a child of the service I created a PTY via POST /api/pty and confirmed its PPID was the service PID; the command wrote a marker before and after calling set, and only the "before" marker ever appeared.
Since terminate() sends SIGTERM and polls for 50ms before escalating to SIGKILL, this is a race and may occasionally succeed. It also always succeeds when the service is already stopped, because terminate() returns early without killing anything, which is probably why retrying eventually appears to work.
Writing the config before stopping the service would fix it. Separately, set stops the service without restarting it, so the setting appears to do nothing and the server is gone as well.
Plugins
None
OpenCode version
2.2.7
Steps to reproduce
opencode service start
From inside an OpenCode session, have the agent run opencode service set cors http://example.com
opencode service get cors — still empty. The same command run directly in a terminal writes it.
Thanks for the detailed write-up and for tracking down the cause. I think this is a duplicate of #58220. That issue reports the same problem with opencode service set env: ServiceConfig.set stops the service before it writes the config, so running the command from a shell the service owns (such as the agent's shell tool) kills it before the write and the value is lost. The fix is the same for every key, so it also covers cors and remote.
Possible duplicates and related items, ordered by likelihood:
Until that's fixed, #58220 describes a workaround: run the command detached from the service's process tree, e.g. setsid sh -c 'opencode service set remote false' &, or run it in a normal terminal.
Your separate point, that set stops the service and never restarts it, isn't covered by #58220. Feel free to open a separate issue for it.
The bot will close this issue as a duplicate in 1 day unless you reply explaining how your problem is different.
Closing this as a duplicate of #58220, since there's been no reply in the past day saying how this problem is different. Both have the same root cause: service set/unset stops the background service before writing the config, so the command dies when it runs from a shell the service owns. Please follow #58220 for updates. The open PR #55957, which writes the config before stopping the service, would fix it for every key, including cors and remote. Until then, running the command from a normal terminal or detached (setsid sh -c 'opencode service set remote false' &) works.
The point about set not restarting the service isn't covered by #58220, so feel free to open a separate issue for it. If you think this was closed by mistake, reply here and we'll take another look. Thanks again for the thorough investigation.
Activity
opencodejr commentedon Nov 10, 2026
Thanks for the detailed write-up and for tracking down the cause. I think this is a duplicate of #58220. That issue reports the same problem with
opencode service set env:ServiceConfig.setstops the service before it writes the config, so running the command from a shell the service owns (such as the agent's shell tool) kills it before the write and the value is lost. The fix is the same for every key, so it also coverscorsandremote.Possible duplicates and related items, ordered by likelihood:
service set envrun from a session is cancelled and nothing is stored), reproduced ondevset/unsetbranchservice set envreport that the PR above links toservice set/unsetloses the stored config (whenservice.jsoncan't be decoded)Until that's fixed, #58220 describes a workaround: run the command detached from the service's process tree, e.g.
setsid sh -c 'opencode service set remote false' &, or run it in a normal terminal.Your separate point, that
setstops the service and never restarts it, isn't covered by #58220. Feel free to open a separate issue for it.The bot will close this issue as a duplicate in 1 day unless you reply explaining how your problem is different.
neriousy commentedon Nov 10, 2026
Thanks for the report. This is the same issue as #58220, so we're tracking it there. Closing as a duplicate. Please add any extra details on #58220.
opencodejr commentedon Nov 11, 2026
Closing this as a duplicate of #58220, since there's been no reply in the past day saying how this problem is different. Both have the same root cause:
service set/unsetstops the background service before writing the config, so the command dies when it runs from a shell the service owns. Please follow #58220 for updates. The open PR #55957, which writes the config before stopping the service, would fix it for every key, includingcorsandremote. Until then, running the command from a normal terminal or detached (setsid sh -c 'opencode service set remote false' &) works.The point about
setnot restarting the service isn't covered by #58220, so feel free to open a separate issue for it. If you think this was closed by mistake, reply here and we'll take another look. Thanks again for the thorough investigation.