Skip to content

Desktop: renaming a project folder breaks the project binding (phantom project, rename ignored, sessions silently fall back to global) #40986

Closed

Description

@White-Give2020

Description

On OpenCode Desktop (v1.18.14, macOS arm64), renaming a project folder in Finder (outside OpenCode) permanently breaks the project↔directory binding. The app keeps a phantom project whose worktree/project_directory point to non-existent paths, the project display name cannot be changed, and new sessions silently fall back to the global project (or fail to start when clicking the phantom).

To Reproduce

  1. Create a project in OpenCode Desktop (folder A). Rename the project in-app to e.g. "DarkRain" → Save.
  2. Rename folder A → B in Finder, then rename the project in-app → name does not change.
  3. Rename folder B → C in Finder. Delete the project in-app, then create a new project selecting folder C → the name auto-reverts to the original project name, and a phantom entry pointing at a dead path still shows in the sidebar.
  4. Click that phantom project and start a conversation → no output, no session is created.

Expected behavior

  • Renaming the project folder in Finder should either re-associate the same project (follow the rename) or the app should detect the stale record and clean it up / relink it.
  • In-app project rename should always persist.
  • Recreating a project on a new path must not reuse the stale DB record.

Environment

  • OpenCode Desktop 1.18.14
  • macOS arm64
  • SQLite storage at ~/.local/share/opencode/opencode.db

Root cause (from bundled code)

  • Project.fromDirectory does an exact-match lookup of the directory (via projectV2.resolve + project_directory). After a Finder rename the new path has no row, so it silently resolves to the global project (worktree = "/", per node-CU9-BMuP.js fromDirectory).
  • ProjectCopy.refresh only deletes stored directory rows whose paths no longer exist; it never adopts a renamed folder as the same project, so the old project.worktree / project_directory.directory stay stale.
  • The edit-project dialog (edit-project.js) special-cases the global project: for it the save path only calls sync.project.meta(...) (silent, no DB project row), which is why renames appear to do nothing.

Observed DB state after the sequence above:

project:      cfdc78b7…  name=DarkRain  worktree=/old/A  (deleted)
project_directory: cfdc78b7…  /old/B   (deleted)
session for folder C: project_id=global

The snapshot (.local/share/opencode/snapshot/<projectID>) also keeps a git worktree config pointing at the deleted path.

Related issues


中文版描述

问题描述

OpenCode Desktop (v1.18.14, macOS arm64) 中,在 Finder 里直接重命名项目文件夹(OpenCode 之外的操作)会永久破坏"项目 ↔ 目录"的绑定:应用里留下一个幽灵项目,其 worktree/project_directory 指向已不存在的路径;项目显示名无法修改;新会话会静默回退到 global 项目(点击幽灵项目发起会话则直接无响应)。

复现步骤

  1. 在 OpenCode Desktop 新建项目(文件夹 A),在应用内把项目改名为如 "DarkRain" → 保存。
  2. 在 Finder 里把文件夹 A 改名为 B,然后在应用内改名项目 → 名称不变化。
  3. 在 Finder 里把文件夹 B 改名为 C。在应用内删除该项目,再新建项目并选择文件夹 C → 名称自动变回最初的项目名,侧边栏仍显示一个指向死路径的幽灵条目。
  4. 点击该幽灵项目发起对话 → 无任何输出,不创建会话。

预期行为

  • 在 Finder 中重命名项目文件夹后,应用应能重新关联同一项目(跟随改名),或检测到失效记录并清理/重新关联。
  • 应用内修改项目名称应始终生效。
  • 在新路径重建项目时,不得复用旧的数据库残留记录。

环境

  • OpenCode Desktop 1.18.14
  • macOS arm64
  • 数据存储:~/.local/share/opencode/opencode.db(SQLite)

根因分析(来自打包代码)

  • Project.fromDirectory 对目录做精确匹配(通过 projectV2.resolve + project_directory)。Finder 改名后新路径无对应记录,便静默降级到 global 项目(worktree = "/",见 node-CU9-BMuP.js 的 fromDirectory)。
  • ProjectCopy.refresh 只会删除路径已不存在的目录记录,从不把改名后的新目录重新关联为同一项目,导致 project.worktree / project_directory.directory 一直残留旧路径。
  • 编辑项目对话框(edit-project.js)对 global 项目做了特判:保存时只调用 sync.project.meta(...)(静默,不写 project 表),这就是改名看起来"没生效"的原因。

上述操作序列后观察到的数据库状态:

project:            cfdc78b7…  name=DarkRain  worktree=/old/A  (已删除)
project_directory:  cfdc78b7…  /old/B                          (已删除)
文件夹 C 的会话:     project_id=global

快照目录(.local/share/opencode/snapshot/<projectID>)中的 git worktree 配置同样指向已删除的路径。

Activity

  1. github-actions commented on Aug 7, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing open issues that cover the same bugs. Please check:

    Your report combines symptoms from several of these existing issues. If you have new information or a reproducible sequence that ties them together in a way not already captured, please add a comment to the most relevant existing issue rather than opening a new one.

  2. hello2038 commented on Aug 16, 2026

    @hello2038

    project rename silently fails for non-git projects (id "global")

    #42853

    Description

    Renaming a project via the "Edit Project" dialog silently has no effect when the project's resolved ID is "global" (i.e., a plain/non-git folder, or a git repo with no remote, no commits, and no cached ID). The dialog closes but the displayed name never changes. Restarting, re-opening the project, or closing/re-adding the workspace does not help.

    Root cause: for such projects the app's save path (packages/app/src/components/edit-project.ts) only performs the real update when props.project.id is set and not "global":

    if (props.project.id && props.project.id !== "global") {
      ... await sdk.client.project.update({ projectID: props.project.id, ... }) // real, persisted save
      return
    }
    serverCtx().sync.project.meta(props.project.worktree, { name, ... }) // dead store: never read

    Project.resolve (packages/core/src/project.ts) returns ID.global for any directory that isn't a git repo, or whose repo has no remote / .git/opencode cache / root commit:

    if (!repo) return { id: ID.global, ... }
    return { id: id ?? ID.global, ... }

    The fallback sync.project.meta(...) writes to childStore.projectMeta (localStorage), but that store is write-only in the codebase — enrich() (global.tsx / layout.tsx) only ever reads the server's data.project. So the rename appears to succeed (dialog closes) but is never persisted or displayed.

    Plugins

    None (OpenCode Desktop, default plugins).

    OpenCode version

    1.18.18 (OpenCode Desktop;)

    Steps to reproduce

    1. Create a brand-new empty folder (no git), or run git init in a folder but do not commit / add a remote.
    2. In OpenCode Desktop (old layout) click + to add that folder, then open it.
    3. Open the project's Edit Project dialog and change the default name to something new, then click Save.
    4. The dialog closes, but the name in the sidebar stays unchanged.
    5. Repeat after restarting the app, after re-opening the project, and after closing + re-adding the workspace — the rename still has no effect.
    6. (Control) Repeating the same steps on a folder that is a git repo with at least one commit or a remote works fine.

    Operating System

    Windows 11

    Terminal

    N/A — OpenCode Desktop (Electron app), old layout

  3. Hona commented on Sep 2, 2026

    @Hona
    Member

    Fixed for opencode2 launch via #46713
    You can try the desktop beta here: https://github.com/anomalyco/opencode-beta

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