Skip to content

Renaming a project's local folder leaves stale worktree path in project DB, causing persistent 500 errors on relaunch #41420

Description

@Pallavikumarimdb

Description

When a project's local directory is renamed on disk (e.g. via File Explorer or mv), opencode desktop does not update the worktree column in the project table of its SQLite database (~/.local/share/opencode/opencode.db). This causes every subsequent request to /api/... and /file/... for that project to fail with a 500 Internal Server Error, since the sidecar tries to resolve a path that no longer exists.

Interestingly, the name and sandboxes columns for the project do get updated to reflect the new folder name/path, but worktree does not — leaving the row in an inconsistent state.

Steps to Reproduce

  1. Open a project folder in opencode desktop.
  2. Rename the folder on disk, while opencode is closed, or via an external tool.
  3. Reopen opencode and try to access the renamed project (either via a restored tab/session, or by opening the new folder path).

Expected Behavior

opencode should either:

  • Detect that the worktree path no longer exists and prompt the user to relink/reselect the folder, or
  • Correctly update the worktree value when the project is reopened at its new location (consistent with how name/sandboxes already get updated).

Actual Behavior

  • Requests to GET /file?path=&directory=<old_path> and /api/... fail with 500 Internal Server Error.

  • Renderer console shows repeated errors like: PlatformError: NotFound: FileSystem.realPath, [cause]: Error: ENOENT: no such file or directory, lstat

  • This happens even after fully quitting and relaunching the app, since the stale path is persisted, not just cached in memory.

Root Cause (found via manual DB inspection)

In ~/.local/share/opencode/opencode.db, table project:

  • The row for the renamed project has name and sandboxes updated to the new path, but worktree still contains the old, deleted path:
  SELECT id, worktree, name, sandboxes FROM project WHERE id = '<project_id>';
  -- worktree: C:/project-name  (stale)
  -- name: project-name1                                    (updated)
  -- sandboxes: ["C:/project-name1"]          (updated)

Additionally, stale references to the old path were found in several other places that also needed manual cleanup before the fix took full effect:

  • Electron store files (opencode.global.dat, opencode.window.<id>.dat in %APPDATA%\ai.opencode.desktop\) — server.projects, layout.home.selection.directory, tabs.info[].directory, etc.
  • These didn't cause the 500s directly, but did cause stale tabs/sessions to keep attempting to reopen the old path on launch.

Environment

Plugins

No response

OpenCode version

1.18.15

Steps to reproduce

No response

Screenshot and/or share link

No response

Operating System

  • OS: Windows

Terminal

No response

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