Skip to content

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

Closed as not planned

Description

@kai1949

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.

Activity

  1. github-actions commented on Oct 2, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions