Skip to content

fix(windows): resolve paths with the native realpath - #53509

Closed
ReinisLusis wants to merge 1 commit into
anomalyco:devfrom
ReinisLusis:fix/windows-realpath-native
Closed

ReinisLusis wants to merge 1 commit into
anomalyco:devfrom
ReinisLusis:fix/windows-realpath-native

Conversation

@ReinisLusis

Copy link
Copy Markdown

Issue for this PR

Closes #53508

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

On Windows, Filesystem.resolve and FSUtil.resolve call the JS realpathSync, which lstats the drive root and every ancestor. A process that cannot read C:\ (for example an AppContainer with no capabilities) exits at startup with EPERM: operation not permitted, lstat 'C:\'.

On Windows these helpers now call realpathSync.native, which opens only the target. ENOENT keeps the existing fallback to the unresolved path. Any other native failure falls back to the JS realpathSync, which throws its errors as before. Other platforms are unchanged.

Resolved paths do not change: normalizePath already passes the result through realpathSync.native on Windows. I compared old and new output on Windows for a plain folder, a lowercased path, an 8.3 short path, a junction, a subst drive and its root, and a missing path; all matched. A mapped network drive was not available to test; it takes the same native call through normalizePath today.

Effect's FileSystem.realPath (used by the Effect FSUtil.resolve, see #52458) is not changed here.

How did you verify your code works?

  • New Windows tests in packages/opencode/test/util/filesystem.test.ts and packages/core/test/filesystem/filesystem.test.ts: a junction resolves through the native call, and a failing native call falls back to the JS realpath. The junction test fails without this change.
  • bun test test/util/filesystem.test.ts (opencode): 61 pass; the 2 existing symlink tests fail on this machine at fs.symlink (no symlink privilege), before and after the change.
  • bun test test/filesystem/filesystem.test.ts (core): 29 pass. bun run typecheck passes in both packages.
  • In a capability-less AppContainer with a grant on one folder, a Bun 1.3.14 compiled executable running the old resolve body throws EPERM ... lstat 'C:\'; the new body returns the folder path, and the ENOENT fallback for a missing child also works.

Found while running OpenCode inside a Windows AppContainer sandbox.

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

🤖 Generated with Claude Code

Filesystem.resolve and FSUtil.resolve called the JS realpathSync, which on
Windows lstats every ancestor starting at the drive root. A process that
cannot read attributes of the drive root, such as one in an AppContainer
without capabilities, fails at startup with
"EPERM: operation not permitted, lstat 'C:\'".

On Windows, use realpathSync.native, which opens only the target. ENOENT
keeps the existing fallback; any other native failure falls back to the JS
realpath as before. normalizePath already passes the result through the
native call, so resolved paths are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

@thdxr

thdxr commented Oct 10, 2026

Copy link
Copy Markdown
Member

This branch has been upgraded to V2. We're no longer taking PRs for V1. If you think this is still relevant, please port it over and open it for V2.

— from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows: startup fails with EPERM lstat 'C:\' when the drive root is unreadable (AppContainer)

2 participants