Skip to content

fix(tui): canonicalize cwd after chdir - #16641

Merged
Hona merged 2 commits into
anomalyco:devfrom
Hona:fix/symlinks-broken
Mar 8, 2026
Merged

fix(tui): canonicalize cwd after chdir#16641
Hona merged 2 commits into
anomalyco:devfrom
Hona:fix/symlinks-broken

Conversation

@Hona

@Hona Hona commented Mar 8, 2026

Copy link
Copy Markdown
Member

Fixes #16522
Fixes #16528
Fixes #16596

Use the same canonical cwd for the TUI thread and worker, including relative --project paths resolved from PWD.


Before 1.2.21

  • thread/TUI used: real dir /tmp/opencode-test-abc
  • worker used: real dir /tmp/opencode-test-abc
  • aligned: yes

In broken 1.2.21

  • thread/TUI used: symlink dir /tmp/opencode-test-abc-link
  • worker used: real dir /tmp/opencode-test-abc
  • aligned: no

After this fix

  • thread/TUI uses: real dir /tmp/opencode-test-abc
  • worker uses: real dir /tmp/opencode-test-abc
  • aligned: yes

For relative --project from a symlinked PWD

  • it first resolves relative to the symlink-aware PWD
  • then after chdir, it canonicalizes with process.cwd()
  • final directory identity is again the real dir

@Hona
Hona marked this pull request as ready for review March 8, 2026 21:57
Copilot AI review requested due to automatic review settings March 8, 2026 21:57
@Hona
Hona merged commit e51ed46 into anomalyco:dev Mar 8, 2026
16 checks passed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes TUI hangs/blank responses when launching OpenCode from symlinked directories by ensuring the TUI main thread and worker use the same canonical working directory (and still resolve relative --project paths from PWD).

Changes:

  • Update TuiThreadCommand to chdir to the requested directory, then re-read process.cwd() and use that canonical value for Instance/TUI directory keys.
  • Add a regression test covering the PWD-symlink scenario with and without a relative --project path.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
packages/opencode/src/cli/cmd/tui/thread.ts Canonicalizes cwd after chdir so TUI thread and worker share the same directory key.
packages/opencode/test/cli/tui/thread.test.ts Adds regression coverage for symlinked PWD causing mismatched directory keys.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +125 to +131
globalThis.Worker = class extends EventTarget {
onerror = null
onmessage = null
onmessageerror = null
postMessage() {}
terminate() {}
} as unknown as typeof Worker

Copilot AI Mar 8, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The globalThis.Worker stub extends EventTarget without defining a constructor. Since TuiThreadCommand instantiates new Worker(file, { env: ... }), the default subclass constructor will forward those arguments to EventTarget, which typically throws because it expects no arguments. Add an explicit constructor(..._args: any[]) { super() } (or otherwise accept and ignore args) so the test doesn’t fail during Worker construction.

Copilot uses AI. Check for mistakes.
@brndnblck

Copy link
Copy Markdown

This fix completely broke MacOS and POSIX file systems if the working folder is a symlink. This needs to be reverted.

@brndnblck

Copy link
Copy Markdown

#16641

tallpizza pushed a commit to tallpizza/ontology that referenced this pull request Mar 9, 2026
Grappeggia referenced this pull request in teamslop/slopcode Mar 16, 2026
demostanis pushed a commit to demostanis/opencode that referenced this pull request Mar 19, 2026
demostanis pushed a commit to demostanis/opencode that referenced this pull request Mar 20, 2026
balcsida pushed a commit to balcsida/opencode that referenced this pull request Mar 24, 2026
balcsida pushed a commit to balcsida/opencode that referenced this pull request Apr 8, 2026
xywsxp pushed a commit to xywsxp/opencode that referenced this pull request Apr 24, 2026
Rwanbt pushed a commit to Rwanbt/opencode that referenced this pull request May 5, 2026
AIALRA-0 pushed a commit to AIALRA-0/opencode-turn-engine that referenced this pull request Jun 10, 2026
AIALRA-0 pushed a commit to AIALRA-0/opencode-turn-engine that referenced this pull request Jun 10, 2026
avion23 pushed a commit to avion23/opencode that referenced this pull request Jun 10, 2026
Rwanbt pushed a commit to Rwanbt/opencode that referenced this pull request Jun 14, 2026
MarsQiu007 referenced this pull request in MarsQiu007/openNovel Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants