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 — shell: every tool call stalls ~5s while the PTY daemon fails to reconnect (ECONNREFUSED /tmp/opencode-pty-<uid>/*.sock) · Issue #64080 · anomalyco/opencode

shell: every tool call stalls ~5s while the PTY daemon fails to reconnect (ECONNREFUSED /tmp/opencode-pty-<uid>/*.sock) #64080

New issue
Copy link
New issue
Copy link
In review
#66802
In review
shell: every tool call stalls ~5s while the PTY daemon fails to reconnect (ECONNREFUSED /tmp/opencode-pty-<uid>/*.sock)#64080
#66802
Copy link
Labels
area/serviceBackground service and serverplatform/macosmacOSstatus/repro-simulatedReproduced with a simulated model or mocktype/bugSomething is brokenversion/v2OpenCode 2.x

Description

@georgantas
georgantas
opened on Nov 15, 2026
Issue body actions

Summary

Every shell tool call pays a fixed ~5s penalty before the command runs, because the persistent-PTY
daemon handshake fails, times out, and falls back to spawning the shell directly. The retry is
re-attempted on every call (and on a ~5s loop while idle) instead of latching to the fallback, so a
session accumulates 400+ failed handshakes and each command is ~5–10s late. The failure is also
masked: the only signal is a WARN line in the log, and the trusted service.json advertises a
socket that does not exist.

Environment

  • opencode version: 2.3.0 (latest)
  • OS: macOS, Darwin 27.2.0 ... arm64 (Apple Silicon)
  • Terminal: TERM=xterm-256color, TERM_PROGRAM=Apple_Terminal, COLORTERM=truecolor
  • Shell: /bin/zsh
  • Install/channel: release binary (/opt/homebrew/Cellar/opencode-v2/2.3.0/bin/opencode)
  • Active plugins: none in config (~/.config/opencode/opencode.jsonc has no plugin entries); a local
    plugin file ~/.config/opencode/plugins/nono-sandbox.ts is loaded
  • Embedded pty helper: opencode-pty 0.5.2 at ~/.cache/opencode/bin/opencode-pty/0.5.2-*/opencode-pty
  • Note: opencode is running inside the nono sandbox (nono 0.82.0, profile opencode). A separate
    integration report is filed against the pack; this issue is about the client-side behaviour that
    causes the 5s-per-command cost regardless of why the daemon is unavailable.

Reproduction

  1. Start opencode on macOS with a persistent-PTY-capable build and run any shell command.

  2. Watch the server log:

    grep -E "opencode-pty|process daemon" ~/.local/share/opencode/log/opencode.log | tail

    Each tool call produces, ~5s apart:

    WARN message="process daemon unavailable; spawning shell command instead"
         error="connect ECONNREFUSED /tmp/opencode-pty-<uid>/<uuid>.sock"
    WARN message="Starting opencode-pty in a fresh runtime directory"
         cause="connect ECONNREFUSED /tmp/opencode-pty-<uid>/<uuid>.sock"
    

    and the pattern repeats every ~5s even with no tool calls in flight.

  3. Count the damage on the log:

    grep -c "process daemon unavailable" ~/.local/share/opencode/log/opencode.log
    # 428
  4. Reproduce the daemon-side failure directly, with no client involved:

    B=~/.cache/opencode/bin/opencode-pty/0.5.2-*/opencode-pty
    D=/tmp/ptyprobe; mkdir -p "$D"
    $B daemon --name probe --runtime-dir "$D" &
    sleep 1.5
    cat "$D/probe/service.json"

    Result: service.json (and service.lock) are written and advertise
    "socket": "/tmp/opencode-pty-<uid>/<uuid>.sock", but that socket file is never created, so any
    client connect fails with ENOENT/ECONNREFUSED.

Timing baseline, same machine, same session: zsh -c echo ~4 ms, git status ~30 ms, git log ~10 ms.
The 5s delay is entirely the handshake.

Expected Behavior

Any one of these, in preference order:

  1. The first failed handshake is remembered for the server's lifetime; shell commands go straight to
    the direct-spawn path with backoff (one 5s hit per server, not one per command, and no idle loop).
  2. service.json is validated before it is trusted — if the advertised socket is not connectable, treat
    the registration as stale immediately instead of paying the full discover/spawn/poll timeout.
  3. Failure is surfaced (a single user-visible warning at startup) instead of only a WARN log line with
    no cause, so the fallback is diagnosable. This is the same masking problem reported in [v2] tui: "New terminal" fails with 503 on glibc < 2.28 — embedded opencode-pty is unrunnable, exec error masked as service.json ENOENT #51796.

Actual Behavior

  • Every shell tool call waits ~5s for the daemon, then runs via the fallback path. Commands succeed but
    arrive late; interactive work feels sluggish.
  • A fresh UUID runtime directory is minted per attempt (Starting opencode-pty in a fresh runtime directory), so retries never converge and stale service.json/socket paths accumulate under
    /tmp/opencode-pty-<uid>/.
  • The retry loop also runs while the session is idle (~one attempt / 5s), adding log churn and CPU
    (system load average was ~3.0 while the loop was running).
  • Nothing user-facing explains the delay.

Additional Context

What it is not. The sandbox is not generally unable to create sockets or PTYs. Verified from inside
the same session:

perl -MIO::Socket::UNIX -e '$s=IO::Socket::UNIX->new(Type=>SOCK_STREAM,Local=>"/tmp/t.sock",Listen=>1); print $s?"BIND OK\n":"FAIL: $!\n"'
# BIND OK   (also binds inside the granted cache dir)
python3 -c "import pty; pty.openpty()"   # OK, /dev/ttys000
ls -l /dev/ptmx                           # openable

A Unix socket bind succeeds, yet the embedded opencode-pty daemon never leaves a listening socket at
the path it advertises.

One concrete denial observed in the daemon launch path:

zsh:1: nice(5) failed: operation not permitted

i.e. setpriority is refused by the sandbox. It is not yet established whether the daemon's
socket-binding child dies because of that call, or whether the cause is elsewhere — but it is the only
denial visible on that path, and a daemonisation routine that treats a failed niceness change as fatal
would produce exactly this symptom (registration written, socket never bound).

Suggested hardening independent of the root cause (this is the part that belongs in opencode):
make "daemon unavailable" sticky with backoff, validate the socket from service.json before
connecting, and emit one diagnosable warning instead of an unqualified WARN + silent fallback.

Related

  • [v2] tui: "New terminal" fails with 503 on glibc < 2.28 — embedded opencode-pty is unrunnable, exec error masked as service.json ENOENT #51796 — embedded opencode-pty unrunnable (glibc) with the error masked as service.json ENOENT
    (same symptom shape: dead daemon, misleading registration error)
  • fix(core): keep PTY daemon ownership and registration in sync #61750 — PTY daemon ownership/registration state drift
  • pty: shell commands leave zombies under opencode-pty daemon on Linux (2.3.0) #63817 — zombies under the opencode-pty daemon (2.3.0, Linux)
  • Persistent PTY: every input lists all terminals, and the daemon sweeps /proc per terminal #60728 — persistent PTY performance (/proc sweep per terminal)

Activity

  1. opencodejr
    added
    area/serviceBackground service and server
    platform/macosmacOS
    type/bugSomething is broken
    version/v2OpenCode 2.x
    on Nov 15, 2026
  2. opencodejr
    marked shell: every tool call stalls ~5s while the PTY daemon fails to reconnect (ECONNREFUSED /tmp/opencode-pty-<uid>/*.sock) #64081 as a duplicate of this issue on Nov 15, 2026
  3. opencodejr
    unmarked shell: every tool call stalls ~5s while the PTY daemon fails to reconnect (ECONNREFUSED /tmp/opencode-pty-<uid>/*.sock) #64081 as a duplicate of this issue on Nov 15, 2026
  4. georgantas
    closed this as completedon Nov 15, 2026
  5. opencodejr commented on Nov 15, 2026

    @opencodejr
    opencodejrBot
    on Nov 15, 2026
    Contributor
    More actions

    Seen with a simulated model or a mock server, not a real provider; a maintainer should confirm.

    Thanks for the detailed report. I reproduced the per-command stall on 2.3.0, and it still happens on the latest dev (d432a06).

    How I tested: I ran opencode serve with OPENCODE_PTY_BIN pointing at a stand-in opencode-pty. It does what you saw your daemon do: it writes a valid service.json advertising a socket, but never creates that socket. I then ran shell commands through POST /api/shell, which uses the same path as the shell tool.

    What I saw:

    • Every command waited about 20 seconds before running through the direct-spawn fallback (20195, 20162, 20113 and 20132 ms for four echo hi calls).
    • Each call started the helper four times, 5 seconds apart, with a fresh runtime directory every second start. Nothing was remembered between calls.
    • Four calls logged 8× Starting opencode-pty in a fresh runtime directory and 4× process daemon unavailable; spawning shell command instead.
    • The same happened on dev.

    Where it differs from your report:

    • My delay is longer than your ~5s. That may be because my stand-in stays alive while your daemon probably exits early, but I haven't confirmed that.
    • I did not see the retries continue while idle: they stopped when the calls stopped.
    • I could not look into why the daemon never binds its socket under nono (the possible nice/setpriority denial), since that needs macOS and that sandbox.

    The script below reproduces it, including the stand-in helper. Related: #51796 (a dead helper's real error hidden behind a service.json ENOENT), #63817 (zombies under opencode-pty on 2.3.0).

    Reproduction script (repro.sh)
    #!/usr/bin/env bash
    # Repro for #64080: with an unreachable opencode-pty daemon, every shell command waits on repeated daemon start attempts before falling back.
    # Usage: ./repro.sh   (uses `opencode` from PATH)   |   OC_DEV=/path/to/repo ./repro.sh   (runs from source)
    set -u
    HERE=$(cd "$(dirname "$0")" && pwd)
    # Stand-in opencode-pty (written next to this script): registers service.json but never binds its socket.
    cat > "$HERE/fake-pty.sh" <<'FAKE'
    #!/bin/sh
    # Stand-in for opencode-pty: registers (service.json) but never binds the advertised socket,
    # as the daemon does under the reporter's sandbox.
    rt=""; name=""
    while [ $# -gt 0 ]; do case "$1" in --runtime-dir) rt="$2"; shift;; --name) name="$2"; shift;; esac; shift; done
    d="$rt/$name"; mkdir -p "$d"
    echo "$(date -u +%T.%N) spawn $name" >> "${FAKE_PTY_LOG:-/tmp/fake-pty.log}"
    printf '{"instance_id":"x","pid":%s,"protocol":8,"socket":"%s/missing.sock","token":"t","features":[]}' $$ "$d" > "$d/service.json"
    exec sleep 3600
    FAKE
    chmod +x "$HERE/fake-pty.sh"
    OC() {
      if [ -n "${OC_DEV:-}" ]; then
        bun --conditions=browser --preload="$OC_DEV/packages/tui/node_modules/@opentui/solid/scripts/preload.js" "$OC_DEV/packages/cli/src/index.ts" "$@"
      else opencode "$@"; fi
    }
    WORK=$(mktemp -d /tmp/opencode/repro64080.XXXX)
    export HOME=$WORK/home XDG_RUNTIME_DIR=$WORK/run FAKE_PTY_LOG=$WORK/fake-pty.log
    mkdir -p "$HOME" "$XDG_RUNTIME_DIR" "$WORK/proj"; chmod 700 "$XDG_RUNTIME_DIR"; cd "$WORK/proj"; git init -q
    echo "version: $(OC --version)"
    PORT=$((40000 + RANDOM % 20000))
    OPENCODE_PTY_BIN="$HERE/fake-pty.sh" OPENCODE_PASSWORD=pw OC serve --hostname 127.0.0.1 --port $PORT >"$WORK/serve.log" 2>&1 &
    PID=$!
    for i in $(seq 1 120); do curl -s -o /dev/null -u opencode:pw "http://127.0.0.1:$PORT/" && break; sleep 0.5; done
    sleep 2
    for n in 1 2 3 4; do
      s=$(date +%s%3N)
      out=$(curl -s -u opencode:pw -X POST "http://127.0.0.1:$PORT/api/shell" -H 'content-type: application/json' \
        -H "x-opencode-directory: $WORK/proj" -d '{"command":"echo hi"}')
      e=$(date +%s%3N)
      echo "call $n at $(date -u +%T): $((e - s)) ms  $(echo "$out" | grep -o '"status":"[a-z]*"')"
    done
    echo "idle 20s from $(date -u +%T) ..."; sleep 20
    echo "--- helper spawns (one line per daemon start attempt):"; cat "$FAKE_PTY_LOG"
    echo "--- log warnings:"; grep -rhoE "process daemon unavailable[^\"]*|Starting opencode-pty in a fresh runtime directory" "$HOME/.local/share/opencode/log" "$WORK/serve.log" 2>/dev/null | sort | uniq -c
    kill $PID; wait $PID 2>/dev/null; pkill -f "$HERE/fake-pty.sh" ; pkill -f "sleep 3600"; true

    Run it: bash repro.sh

  6. opencodejr
    added
    status/repro-simulatedReproduced with a simulated model or mock
    on Nov 15, 2026
  7. georgantas
    reopened this on Nov 15, 2026
  8. georgantas commented on Nov 15, 2026

    @georgantas
    georgantas
    on Nov 15, 2026
    Author
    More actions

    Correction: the daemon does bind — the client cannot connect()

    Further testing while the daemon was alive shows the socket is created. My original description's
    "the socket file never appears" was an artifact of sampling after the daemon had exited (it removes its
    runtime directory on shutdown). Live state:

    B=$(ls -d ~/.cache/opencode/bin/opencode-pty/0.5.2-*/opencode-pty)
    D=$(mktemp -d /tmp/ptyprobe.XXXX)
    "$B" daemon --name probe --runtime-dir "$D" &
    sleep 2
    
    ls -la /tmp/opencode-pty-$(id -u)/
    # srw-------  1 <user> <group> 0 <date> c582216845850a574fbbaf91ce4de1fa.sock     <- socket exists
    
    cat "$D/probe/service.json"
    # {"instance_id":"…","pid":65266,"protocol":8,
    #  "socket":"/tmp/opencode-pty-501/c5822168….sock","token":"…","features":[]}
    
    "$B" status --name probe --runtime-dir "$D"
    # error: failed to connect to /tmp/opencode-pty-501/c5822168….sock:
    #        Operation not permitted (os error 1)

    Even the daemon's own client gets EPERM on connect(). Minimal probe, no opencode in the loop:

    # create + listen + connect in one process
    /tmp:                    bind OK  / connect FAIL  [Errno 1] Operation not permitted
    ~/.cache/opencode/tmp:   bind OK  / connect FAIL  [Errno 1] Operation not permitted
    
    # controls
    TCP 127.0.0.1:<port>     connect OK
    socket.socketpair()      OK

    So path-based AF_UNIX connect() is denied in this environment while bind, TCP loopback and
    socketpair all work. That makes it a sandbox policy gap (nono Seatbelt profile, macOS), not an
    opencode-pty defect — and it means relocating the socket via OPENCODE_PTY_SOCKET_DIR cannot help,
    which I confirmed separately: the advertised path moves to a writable granted directory and the socket
    is created there, but the connect is still denied.

    Why the log says ECONNREFUSED and not EPERM: a stale socket left by an already-exited daemon fails
    with ECONNREFUSED, a live one with EPERM. Either way the client never reaches the daemon.

    Unchanged, and still opencode's side of this issue: the per-command retry is what turns a hard,
    permanent failure into a 5s tax on every shell call — PersistentPty.makeDaemonTransport re-runs
    spawn() (5s poll, then SIGTERM) for each request instead of caching "unavailable", and
    service.json is trusted without a connectivity check. A permanent connect failure should be detected
    once and latched, with a diagnosable message, rather than retried per command and per 5s while idle.

    Sorry for the wrong root cause in the first write-up; the symptoms and the timing numbers
    (428 process daemon unavailable entries, ~5–10s per call) stand. The sandbox half is being corrected
    in nolabs-ai/nono-packs#68.

  9. georgantas commented on Nov 15, 2026

    @georgantas
    georgantas
    on Nov 15, 2026
    Author
    More actions

    Implemented in #64087.

    DaemonTransport.connect now latches a failed start for the life of the transport: while the backoff
    window is open, connect(shouldStart) returns the previous failure instead of spawning again. The delay
    doubles 5 s → 2 min and is cleared by the first successful connect, and one warning is logged when the
    transport first gives up, so the fallback stops being silent. New test:
    does not re-run a start that failed outright on every request (a binary that cannot spawn is invoked
    once across two requests).

    Caveat, stated in the PR as well: bun cannot be executed in the environment where I wrote this, so the
    suite did not run there — esbuild parses the changed files, and the test needs a run on someone's
    machine before merge.

    The daemon itself is not fixable from this side; the sandbox half is nolabs-ai/nono-packs#69 (grant the
    socket subtree) with nolabs-ai/nono#2318 documenting the rule.

  10. r266-tech commented on Nov 15, 2026

    @r266-tech
    r266-tech
    on Nov 15, 2026
    Contributor
    More actions

    A focused candidate shares a failed startup for 30 seconds. Discovery stays active, so a daemon that becomes reachable during the backoff is usable immediately; successful ownership clears the failure. Startup can retry after the delay rather than being disabled permanently.

    I tested the real makeDaemonTransport at dev d432a06b9c on macOS/Bun 1.4.4 with a child helper that registers but never creates its socket:

    Two consecutive requests First Second Helper starts
    Base 20,174 ms 20,056 ms 8
    Candidate 10,038 ms 3 ms 2

    The committed regression covers concurrent failures, the retry boundary on a controlled monotonic clock, and discovery of a recovered real socket. It fails on base; 120 randomized daemon checks and 66 related checks pass (2 skipped), alongside root lint/35 typechecks and official Core TypeScript. Reproducer and commands.

    This probe calls the transport directly; I did not test the original nono sandbox, a provider, or the idle-loop claim. GitHub still blocks a fourth PR here; pty-start-backoff is available meanwhile. AI-assisted implementation and verification.

  11. georgantas
    added a commit that references this issue on Nov 15, 2026

    fix(core): stop retrying an unavailable PTY daemon per request

    00e2705
  12. georgantas commented on Nov 15, 2026

    @georgantas
    georgantas
    on Nov 15, 2026
    Author
    More actions

    Correction to my earlier comment: #64087 is closed, not merged. r266-tech's candidate
    (r266-tech/opencode@1def5d6) is the better fix and supersedes it.

    Why theirs wins, in short:

    • their backoff gate sits inside start(), so discovery still runs during the backoff — a daemon that
      becomes reachable mid-window is picked up immediately, which fix(core): stop retrying an unavailable PTY daemon per request #64087 could not do because its gate sits
      before discover()
    • it measures the window with Clock.monotonicTimeNanos instead of Date.now(), which also makes the
      retry boundary testable (their test drives 29.999 s / 30 s instead of sleeping)
    • one 30 s window is cheaper than my 5 s→2 min exponential curve for the pattern in this report (a shell
      command every few seconds re-pays the ~10 s start cost at 5 s, then 10 s, then 20 s)

    Their benchmark on the stand-in helper: second call 3 ms and 2 helper starts, against ~10 ms / 2 starts
    here; committed coverage includes concurrent failures, the retry boundary, and recovery mid-window.

    Status: no open PR currently carries it — r266-tech reports that GitHub blocks a further PR from their
    account. So this still needs a PR from whoever can open one; the design is in that commit.

  13. georgantas commented on Nov 15, 2026

    @georgantas
    georgantas
    on Nov 15, 2026
    Author
    More actions

    Timeline for when this started, since "which version regressed" is the first question triage asks.

    When Commit / release Effect
    2026-08-25 004b647311 — persistent PTY daemon API (#44969) spawnDaemon() already retried per request with no latch, but only terminal tabs and the experimental PTY API reached it. Dormant for shell.
    2026-11-10 d4bcde9121 — "run shell commands in the process daemon across handoffs" (#62978) The shell tool starts calling runs.create and gains the process daemon unavailable; spawning shell command instead fallback (that string exists nowhere earlier in history). A failed daemon now gates every shell command.
    2026-11-13 tag v2.3.0 First release containing it. v2.2.7 does not (git merge-base --is-ancestor d4bcde9121 v2.2.7 → no).

    Before #62978, packages/core/src/shell.ts had no daemon code at all — it always spawned directly, so a
    daemon that could not start never cost the shell path anything.

    Corroborated on the reporting machine: the first process daemon unavailable entry is
    2026-11-14T19:15:41Z (367 that day, 208 the next, none earlier), i.e. right after the 2.3.0 upgrade.
    Downgrading to v2.2.7 should remove the stall entirely and is a cheap confirmation.

    So the per-command cost is a 2.3.0 regression from #62978, while the underlying miss — no latch after a
    failed start — predates it in #44969 and only needed fixing once shell depended on the daemon. The
    reason the daemon fails at all in that environment is separate and sandbox-side: nolabs-ai/nono#2317 and
    nolabs-ai/nono-packs#68.

  14. r266-tech commented on Nov 15, 2026

    @r266-tech
    r266-tech
    on Nov 15, 2026
    Contributor
    More actions

    @georgantas I checked the candidate through the real CLI HTTP shell path as well, beyond the transport-only probe above. Two consecutive POST /api/shell calls used an OPENCODE_PTY_BIN helper that registers but never opens its advertised socket:

    Build First request Second request Total helper starts
    dev d432a06b9c 20166 ms 20155 ms 8
    Candidate 1def5d6749 10175 ms 12 ms 2

    Both commands exited 0 with the expected output. This confirms that the backoff survives separate HTTP requests and the direct-spawn fallback still runs the command. Standalone runner and recorded results. Timings are local macOS/Bun 1.4.4 observations; assertions use startup counts and command results.

    Neither build started another helper during a six-second idle observation, so I still cannot confirm the reported idle loop. The original nono sandbox remains untested. The candidate is unchanged; GitHub still shows the three-open-PR limit. AI-assisted verification.

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

    area/serviceBackground service and serverplatform/macosmacOSstatus/repro-simulatedReproduced with a simulated model or mocktype/bugSomething is brokenversion/v2OpenCode 2.x

    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.