Skip to content

location: cannot open folders on DriveCrypt virtual drives (native realpath returns ENOENT) #64905

Open

Description

@davide-vecchi

Summary

On Windows, OpenCode 2.3.2 cannot create a Location for any folder on a DriveCrypt (SecurStar) encrypted drive. realpathSync.native returns ENOENT for those paths, the boot probe in packages/core/src/filesystem.ts turns that into DirectoryNotFoundError, and every API call for that folder answers 404 LocationNotFoundError. The TUI then shows "Session location unavailable", and opencode session list prints Location not found: <dir>. Plain file I/O (open, stat, opendir) and the JS fs.realpathSync work fine on the same paths.

Environment

  • opencode version: 2.3.2
  • OS: Windows 10.0.19045 (win32 x64)
  • Terminal: Windows Terminal
  • Shell: PowerShell 7.6.10 (launching opencode); %COMSPEC%: C:\windows\system32\cmd.exe
  • Install/channel: npm global @opencode/[email protected], channel latest, not standalone
  • Active plugins: none

Reproduction

  1. Install DriveCrypt 6.1.4 and mount an encrypted container as drive H:. The drive reports as a fixed NTFS volume and is fully read/write.
  2. Create a folder on it, e.g. H:\work\my-project.
  3. From that folder run opencode session list (or start opencode).
  4. Observe Location not found: H:\work\my-project (exit 1). In the TUI, opening any session whose directory is on that drive shows "Session location unavailable", and "Choose directory" only offers a worktree list that is empty.
  5. As a control, run the same command from a folder on C:. A Location is created and sessions are listed.

The same happens with a private server: opencode --standalone --print-logs --log-level trace session list in the affected folder starts the server, subscribes watchers for the folder, and then GET /api/location returns 404.

Expected Behavior

A Location is created for the folder, exactly as it is for a folder on C:, and the session in that folder can be opened.

Actual Behavior

GET /api/location returns 404, the CLI prints Location not found: H:\work\my-project, the TUI shows "Session location unavailable", and every existing session whose directory is on that drive becomes unreachable.

Measurements on the affected machine (Node v24.15.0 and Bun 1.4.4, i.e. the runtime inside opencode.exe, behave identically):

path realpathSync.native realpathSync (JS) open/stat/opendir
H:\ ENOENT OK OK
H:\work\my-project ENOENT OK OK
G:\ (second DriveCrypt container) ENOENT OK OK
C:\ and folders on it OK OK OK
C:\Users\<user>\.config\<dir> (a symlink pointing into H:) ENOENT OK OK

\\?\H:\... and \\.\H:\... fail the same way.

Volume facts for the affected drives: Win32_LogicalDisk reports DriveType 3, NTFS, with size and free space, but mountvol H: /L answers "The parameter is incorrect", Get-Volume -DriveLetter H finds no MSFT_Volume, and fsutil volume diskfree H: prints "A local NTFS volume is required for this operation" before it reports sizes. The DriveCrypt FileCrypt driver is loaded and DriveCryptService is running. In other words, the drive is a virtual device with a drive-letter alias but no volume mount point, so GetFinalPathNameByHandleW(FILE_NAME_NORMALIZED | VOLUME_NAME_DOS) cannot produce a final path for it.

Additional Context

Where it fails on the current dev sources:

  1. packages/core/src/filesystem.ts, FileSystem.node boot probe: yield* fs.realPath(location.directory) with Effect.catch mapping NotFound to DirectoryNotFoundError. There is no fallback, so a Location on such a drive can never be constructed.
  2. packages/server/src/location.ts maps FileSystem.DirectoryNotFoundError to LocationNotFoundError, which is what every endpoint for that directory returns.
  3. FSUtil.resolve in packages/util/src/fs-util.ts already has the tolerant behaviour (Effect.catchIf(NotFound | access denied, () => resolved)), and Project.resolve goes through that path. Only the boot probe is strict, which is why the symptom presents as "the folder does not exist" even though it is readable and writable.

Suggested fix: let the boot probe tolerate a native realpath failure the way FSUtil.resolve does, for example by falling back to the configured directory when fs.stat(directory) (or the JS realpathSync) succeeds after the native call reports NotFound, and by failing only when the directory is genuinely missing. A JS realpath fallback would also cover other virtual or filter-driver volumes where the native call is unavailable, such as the WinFsp case in #60449.

Related: #60449 (realpath EUNKNOWN on WinFsp virtual drives breaks most API endpoints with 500), #61085 (no typed-directory recovery in the "Session location unavailable" panel; this report hits that dead end too).

Workaround for users: start OpenCode from a folder on a real volume. Files on the affected drive stay readable and editable from such a session, because only Location construction fails.

Activity

  1. added
    area/core
    type/bug
    version/v2
    on Nov 19, 2026
  2. opencodejr commented on Nov 19, 2026

    @opencodejr
    Contributor

    Thanks for the detailed measurements and the code walkthrough. I couldn't reproduce this here: it needs Windows with a DriveCrypt (or similar) virtual drive, where the native realpath call fails even though the folder itself is readable. This sandbox runs only Linux, and there a readable folder always resolves.

    A maintainer with a Windows machine and such a drive will need to confirm it. Until then, starting OpenCode from a folder on a regular volume is the workaround you describe.

    Closely related: #60449, where a WinFsp drive returns EUNKNOWN from realpath through a different code path and gets HTTP 500 instead of 404. A fix there may well cover this case too.

  3. davide-vecchi commented on Nov 19, 2026

    @davide-vecchi
    Author

    Added by the human : it was working fine with OpenCode V1.

  4. Guembri01 commented on Nov 27, 2026

    @Guembri01

    Fixed on branch filesystem-realpath-enoent (a248906).

    You had the exact line: the boot probe used native realpath and turned its ENOENT into DirectoryNotFoundError. Only NotFound now falls back to the lexical path, and the access probe that already follows decides whether the directory exists:

    ? yield* fs.realPath(location.directory).pipe(
        Effect.catchIf((cause) => cause.reason._tag === "NotFound", () => Effect.succeed(location.directory)),
        Effect.tap((real) => fs.access(real, { readable: true })),

    That keeps the neighbouring behaviour intact:

    • a genuinely missing directory still fails the access probe → DirectoryNotFoundError
    • an unreadable one still → DirectoryAccessDeniedError
    • PermissionDenied, Unknown and other realpath failures keep their classification (I first tried the existing fs.resolve helper and it swallowed access denials — the EACCES/EPERM/EIO classification tests caught it)
    • a symlinked root is still canonicalized, since the fallback only runs when realpath could not answer

    New test reuses the layer-replacement harness in location-filesystem.test.ts: a real temp directory whose realPath is overridden to fail with NotFound for the root — what the driver does. Boot fails with filesystem.ts reverted and succeeds with the change. location-filesystem, filesystem and the new file are 37 pass; the only failure is canonicalizes local symlinked directories, which fails the same way on dev here because this shell cannot create symlinks. Typecheck and oxlint are clean.

    PR creation is 404 for this account again, so it waits as a branch with the body written.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/coreplatform/windowstype/bugversion/v2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions