GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — service: start fails with EPERM on Windows when XDG_STATE_HOME equals XDG_CONFIG_HOME · Issue #56746 · anomalyco/opencode

service: start fails with EPERM on Windows when XDG_STATE_HOME equals XDG_CONFIG_HOME #56746

New issue
Copy link
New issue
Copy link
Open
Open
service: start fails with EPERM on Windows when XDG_STATE_HOME equals XDG_CONFIG_HOME#56746
Copy link
Labels
reproduced

Description

@Blind-Striker
Blind-Striker
opened on Oct 18, 2026
Issue body actions

Description

When XDG_STATE_HOME and XDG_CONFIG_HOME point at the same directory, the service registration and the service configuration become the same file, <dir>/opencode/service.json. Both writers replace that path through a temp-file rename. On Windows the registration's rename is sometimes refused with EPERM, and service start fails.

Where the two paths come from (v2.0.32, 843a6c5):

  • packages/util/src/global-roots.ts:7-8, 15-16: config and state are XDG_CONFIG_HOME and XDG_STATE_HOME, each joined with opencode.
  • packages/cli/src/services/service-config.ts:41-44: filename() is service.json for the latest, dev, beta and next channels.
  • packages/cli/src/services/service-config.ts:115-130: file: path.join(global.state, name) and configFile: path.join(global.config, name). With equal roots, file === configFile.
  • packages/cli/src/services/service-registration.ts:22, 39: the registration is written to <file>.<id>.tmp and then renamed onto file.
  • packages/cli/src/services/service-config.ts:169-175: the configuration is written to <configFile>.tmp and then renamed onto configFile.

Observed on Windows 11, 30 cycles each:

Setup EPERM
Separate state and config directories 0/30
One directory for both 4/30, always at the first service start of a fresh root; the second start then succeeds
Error: Server process exited with code 1
PlatformError: Unknown: FileSystem.rename (...\xdg\opencode\service.json.<uuid>.tmp)
  [cause]: Error: EPERM: operation not permitted, rename '...\xdg\opencode\service.json.<uuid>.tmp' -> '...\xdg\opencode\service.json'

Expected: service start works for any pair of XDG roots, or refuses clearly when the two roots are equal.

Suggestion: either give the configuration and the registration different file names, or have the CLI detect global.state === global.config and fail with a message naming both variables. Equal roots are a natural shortcut when isolating a service, for example in tests or a sandboxed app; that's how we ran into it.

Related, but a different trigger: #56708 (discovery across different XDG_STATE_HOME values).

OpenCode version

2.0.32

Steps to reproduce

In PowerShell, on a fresh root each cycle; repeat the cycle in a loop:

$root = Join-Path $env:TEMP "oc-eperm-$(Get-Random)"
$env:XDG_STATE_HOME  = "$root\xdg"
$env:XDG_CONFIG_HOME = "$root\xdg"     # the same directory as STATE
$env:XDG_DATA_HOME   = "$root\data"
$env:XDG_CACHE_HOME  = "$root\cache"
opencode service start
opencode service start
opencode service stop

Operating System

Windows 11

Terminal

PowerShell 7 (Windows Terminal)

Activity

  1. opencode-agent commented on Oct 18, 2026

    @opencode-agent
    opencode-agentBot
    on Oct 18, 2026 – with OpenCode Agent
    Contributor
    More actions

    Thanks for the detailed report. I reproduced the underlying problem on Linux, with 2.0.32 and with the latest dev (60a5a6c).

    With XDG_STATE_HOME and XDG_CONFIG_HOME pointing at the same directory:

    1. opencode service set port 41234 writes {"port": 41234} to opencode/service.json.
    2. opencode service start succeeds, but the registration (id, version, url, pid, password) replaces that file.
    3. opencode service get port then prints nothing, so the stored service config is lost.

    With separate state and config directories, the config is kept. The script below reproduces it.

    I couldn't watch the EPERM itself here because this sandbox only runs Linux. It has the same cause, though: the config's service.json.tmp rename and the registration's service.json.<id>.tmp rename both target one file. The service code hasn't changed between 2.0.32 and dev.

    Related (not duplicates): #56708 (discovery across different XDG_STATE_HOME values), #51470 (Windows EPERM on rename in desktop persistence).

    Reproduction script (repro.sh)
    #!/usr/bin/env bash
    # Repro for #56746: XDG_STATE_HOME == XDG_CONFIG_HOME makes the service registration
    # and the service config the same file (<dir>/opencode/service.json).
    # Usage: OC="opencode" bash repro.sh   (or OC="bun ... packages/cli/src/index.ts")
    OC=${OC:-opencode}
    root=$(mktemp -d /tmp/opencode/oc-same-XXXX)
    export XDG_STATE_HOME=$root/xdg XDG_CONFIG_HOME=$root/xdg XDG_DATA_HOME=$root/data XDG_CACHE_HOME=$root/cache
    $OC --version
    echo "== set port"; $OC service set port 41234
    echo "-- service.json after set:"; cat $root/xdg/opencode/service*.json; echo
    echo "== start #1"; $OC service start; echo "exit=$?"
    echo "-- service.json after start:"; cat $root/xdg/opencode/service*.json; echo
    echo "== get port (expected 41234; empty means the config was overwritten by the registration)"; $OC service get port 2>&1
    echo "== start #2"; $OC service start; echo "exit=$?"
    echo "-- service.json after start #2:"; cat $root/xdg/opencode/service*.json; echo
    echo "== stop"; $OC service stop; echo "exit=$?"
    ls -la $root/xdg/opencode

    Run it: bash repro.sh

  2. opencode-agent
    added
    reproduced
    on Oct 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    reproduced

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.