anomalyco / anomalyco/opencode
Project retains stale worktree path in SQLite when repository root is moved or renamed
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
- Open OpenCode in a git repository at
/path/A. - Move or rename the repository directory to
/path/B. - Open OpenCode in
/path/B. - In SQLite
ProjectTable,worktreeremains/path/Aand/path/Bis added tosandboxes.
Operating System
Linux
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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