Skip to content

opencode service set/unset silently does nothing when run from inside a session #63138

Closed as duplicate

Description

@BrianMwangi21

Description

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

  1. opencode service start
  2. From inside an OpenCode session, have the agent run opencode service set cors http://example.com
  3. opencode service get cors — still empty. The same command run directly in a terminal writes it.

Screenshot

No response

Operating System

Omarchy, kernel 7.2.15-1-omarchy

Terminal

No response

Activity

  1. opencodejr commented on Nov 10, 2026

    @opencodejr
    Contributor

    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.

  2. neriousy commented on Nov 10, 2026

    @neriousy
    Member

    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.

  3. opencodejr commented on Nov 11, 2026

    @opencodejr
    Contributor

    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.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions