Skip to content

fix(filesystem): crash when project directory does not exist #50548

Closed as duplicate
perinst/opencode
#2

Description

@hyydra

Bug

OpenCode Desktop opens but does not return any answers when a previously-used project directory no longer exists on disk.

Root Cause

In packages/core/src/filesystem.ts:65, the FileSystem service layer calls fs.realPath(location.directory).pipe(Effect.orDie). When the location directory (e.g. a deleted project directory) no longer exists, fs.realPath throws a PlatformError(NotFound) which is turned into a fatal defect by .orDie. This kills the entire FileSystem service, making all tools (read, list, glob, grep) and prompts fail silently.

The same issue exists on line 70 for path resolution within resolve().

Fix

Replace the two fs.realPath(...).pipe(Effect.orDie) calls with fs.resolve(...), which already handles NotFound gracefully (see packages/core/src/fs-util.ts:94-99):

- const root = yield* fs.realPath(location.directory).pipe(Effect.orDie)
+ const root = yield* fs.resolve(location.directory)

and:

- const real = yield* fs.realPath(absolute).pipe(Effect.orDie)
+ const real = yield* fs.resolve(absolute)

The FSUtil.resolve method catches PlatformError(NotFound) and returns the normalized path string as-is, while still failing on other errors via Effect.orDie. This prevents a deleted project directory from crashing the entire service.

Activity

  1. github-actions commented on Sep 22, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of an existing issue. Please check:

  2. alecgib77 commented on Sep 26, 2026

    @alecgib77

    Adding evidence from a full reproduction on 2.0.18 (desktop, macOS 26, arm64) — same root cause as described here, plus a second layer that the fs.resolve fix alone does not cover.

    The symptom here is a hard failure, not a silent one. The desktop renderer dies during startup with a "server request failed — HTTP 500" screen, and the bundled service returns 500 on every directory-scoped endpoint:

    cause="PlatformError: NotFound: FileSystem.realPath (<deleted dir>)
      [cause]: Error: ENOENT: no such file or directory, lstat '<deleted dir>'"
      http.url=/api/skill http.status=500
    

    /api/skill, /api/mcp, /api/plugin, /api/provider, /api/model, /api/integration, /api/location all returned 500. The same request with x-opencode-directory pointing at an existing directory returns 200, so the failure is purely location resolution.

    The deleted path is persisted in two places, and nothing in the product surfaces them:

    1. Client — ~/Library/Application Support/ai.opencode.desktop/drafts.sqlite, table state, document opencode.global.dat, key layout → home.selection.directory. This is what makes startup fatal. server.projects.local[].worktree in the same document also keeps the dead project in the sidebar.
    2. Server — opencode.db, table project, column worktree (plus session.directory / session_v2.directory for that project's sessions).

    So fixing the crash is necessary but not sufficient: the client still reopens the dead path on every launch — the same conclusion as the closed #35240 — and the error screen only offers Restart, which loops back into the identical failure. Expected instead: fall back to a valid location, or at minimum name the missing path in a recoverable message.

    Server-side registry cache. Even with both files corrected while the service was running, GET /api/project still returned the deleted project and the server re-inserted the row I had just deleted. POST /api/location/reload did not clear it. PATCH /api/project/{projectID} with a corrected canonical did, without restarting the service.

    Still reproduces on 2.0.18. The closed #30750 reported the same startup symptom on 1.15.11, so this looks like a regression or an unfixed path rather than a one-off.

    Unrelated aside noticed while investigating: ~/.local/share/opencode/log/opencode.log has no rotation or size bound — it reached 47 MB in about two days.

    (Consolidating my duplicate report #51465 into this issue.)

  3. neriousy commented on Oct 20, 2026

    @neriousy
    Member

    Thanks for the report and the detailed investigation. We're tracking this same failure when a project's directory has been deleted in #50137, so I'm closing this as a duplicate. Please follow that issue for updates.

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