Skip to content

opencode attach segfaults (Bun panic in drainMicrotasks) when --dir has no matching session #28214

Description

@arnm

Description

opencode attach <url> --dir <PATH> reliably segfaults (Bun crash) when no existing session on the server has a cwd matching <PATH>. Attaching to a --dir that does have matching sessions works (TUI loads).

This looks related to the session().parentID family (#6874, #6964, #6867, #6977) — the TUI route appears to assume a session exists, and Bun then panics in the microtask drain instead of erroring gracefully.

panic(main thread): Segmentation fault at address 0x103EE1B5C
oh no: Bun has crashed.

Bun crash report (consistent hash across runs):
https://bun.report/1.3.13/Ma1bf2e2ceEugogC_______2lumjD2lumjD2lumjD2lumjDurr8iDm8t3zC+ml0zC29vz2C2ovz2C+94r4C29u7B__A2C41t49D

Stack frame from bun.report:

  • Bun::jsFunctionDrainMicrotaskQueue (BunProcess.cpp:3532)
  • JSC::MicrotaskQueue::drain<true>
  • JSC::runMicrotaskJSC::runInternalMicrotask (JSMicrotask.cpp)
  • llint call → unknown JS code

Plugins

None relevant — reproduces with stock config.

OpenCode version

1.15.4 (embedded Bun 1.3.13)

Steps to reproduce

  1. Start an opencode server (e.g. opencode serve --port 4096).
  2. Confirm no session on that server has a cwd matching /tmp/empty-dir-test:
    curl -s http://localhost:4096/session | jq -r '.[].directory' | sort -u
    
  3. Run:
    mkdir -p /tmp/empty-dir-test
    cd /tmp/empty-dir-test
    opencode attach http://localhost:4096 --dir "$PWD"
  4. Expected: friendly error like "no session for this directory" or new-session prompt.
  5. Actual: Bun segfault within ~2s.

Reproduces with and without a PTY (script -q /dev/null bash -c '…' also crashes).

Sanity check — attaching to a dir that does have sessions works:

opencode attach http://localhost:4096 --dir /   # TUI loads

Screenshot and/or share link

n/a

Operating System

macOS 26.3.1 (Darwin 25.3.0) arm64

Terminal

Reproduces in zsh, bash, and under script/PTY. Not terminal-specific.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions