Skip to content

Project retains stale worktree path in SQLite when repository root is moved or renamed #50023

Description

@rapha4lx

Description

In packages/opencode/src/project/project.ts, Project.fromDirectory resolves the active directory (worktree = data.id === ProjectV2.ID.make("global") && !data.vcs ? "/" : data.directory).

However, when an existing project row is fetched from SQLite (ProjectTable), it unconditionally preserves the historical worktree:

const result: Info = {
  ...existing,
  worktree: projectID === ProjectV2.ID.global ? worktree : existing.worktree,
  vcs: data.vcs?.type ?? fakeVcs,
  time: { ...existing.time, updated: Date.now() },
}

If a repository is moved to a new path or migrated across users, existing.worktree points to an obsolete directory that no longer exists on disk. Because data.directory !== result.worktree, OpenCode treats the active repository as a sandbox of the dead worktree (result.sandboxes.push(data.directory)). Downstream operations (such as favicon discovery or watchers) then continue targeting the non-existent worktree.

OpenCode version

1.18.31

Steps to reproduce

  1. Open OpenCode in a git repository at /path/A.
  2. Move or rename the repository directory to /path/B.
  3. Open OpenCode in /path/B.
  4. In SQLite ProjectTable, worktree remains /path/A and /path/B is added to sandboxes.

Operating System

Linux

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions