anomalyco / anomalyco/opencode

TUI crashes on launch via VSCode Remote-WSL: TypeError: undefined is not an object (evaluating 'U.directory') in zf/refresh

Open
#40,002 0 comments 0 reactions 1 assignee View on GitHub

@kommander is already working on this.

Since Aug 1, 2026.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

Summary

The opencode TUI crashes immediately on startup when launched via the VSCode extension ("Open opencode" command) over Remote-WSL. Running opencode directly in the WSL terminal (no args) works fine on the same machine. The crash is a TypeError from an unguarded property access on an undefined server response.

Environment

  • opencode CLI: 1.18.10 (latest, released 2026-07-30)
  • VSCode extension: sst-dev.opencode-0.0.13
  • OS: Windows 11 + WSL2 (Ubuntu-22.04), connected via Remote-WSL
  • Shell: bash with a source ~/env/tc/bin/activate line in rc (reproduces regardless)
  • Launch command from extension: opencode --port <random> with env OPENCODE_CALLER=vscode, _EXTENSION_OPENCODE_PORT=<port>

Reproduction

  1. Open a project folder in VSCode via Remote-WSL.
  2. Run the extension's "Open opencode" command (or click the opencode button).
  3. The extension creates a terminal and sends opencode --port <random>.
  4. The TUI flashes briefly, then crashes/exits.

Running opencode (no --port) in the same VSCode integrated terminal works without issue.

Error

Failed to refresh default location data

TypeError: undefined is not an object (evaluating 'U.directory')
      at zf (/$bunfs/root/chunk-ztxp1sde.js:8:6524)
      at refresh (/$bunfs/root/chunk-ztxp1sde.js:8:16108)

Followed by cascading AbortError: The operation was aborted. from the same chunk-0ahfhazp.js abort path.

A side effect: a stray SGR mouse report ^[[<35;79;11M is left in the terminal stdin (the TUI enabled mouse tracking but never restored the terminal mode before exiting), which the shell then tries to execute as commands.

Root cause (from inspection of the bundled binary)

The Data provider initializes by firing 8 concurrent refresh calls, one of which is location.refresh():

location: {
  async refresh(n) {
    let h = (await w.client.v2.location.get({ location: M0(n) }, { throwOnError: true })).data;
    let J = zf(h);                       // <-- crashes here
    ...
  }
}
function zf(U) { return JSON.stringify([U.directory, U.workspaceID]); }   // no null guard

When h (the .data field of the v2.location.get response) is undefined, zf(h) throws TypeError: undefined is not an object (evaluating 'U.directory'), which propagates up and kills the TUI.

The server logs show booting location services is async:

level=INFO message="booting location services" directory=/home/kai/code/<project> workspaceID=undefined

So under --port mode there's a race: the TUI's Promise.allSettled([...refresh...]) fires before the server's location services have a default location registered, causing v2.location.get to return a response whose data is undefined. Direct (opencode no-arg) startup takes a different path that does not hit this race.

Suggested fix

Add a null guard. Either:

function zf(U) { return JSON.stringify([U?.directory, U?.workspaceID]); }

or in refresh:

async refresh(n) {
  let h = (await w.client.v2.location.get({ location: M0(n) }, { throwOnError: true })).data;
  if (!h) return;          // location services not ready yet
  let J = zf(h);
  ...
}

Additionally, the TUI should restore terminal modes (disable SGR mouse tracking) in a finally/cleanup path so a crash doesn't leak escape sequences into the parent shell.

Logs

Server log (~/.local/share/opencode/log/opencode.log) around the crash shows normal booting location services entries for the project directory; no server-side ERROR is emitted — the crash is entirely client-side during the initial refresh burst.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.