anomalyco / anomalyco/opencode

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

Open
#50,023 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in packages/opencode/src/project/project.ts at Project.fromDirectory and trace how existing rows are read from ProjectTable. Reproduce the move from /path/A to /path/B, then verify that the active directory becomes the worktree rather than a sandbox while the SQLite project data remains consistent.

Written by the indexing model from the issue text.

Assessment

Tech stack
sqlite, typescript
Domain
backend, databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
74/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.