Skip to content

fix(opencode): fall back to opened directory when stored worktree is missing - #47326

Open
zbh-lzu wants to merge 2 commits into
anomalyco:devfrom
zbh-lzu:stale-worktree-recovery
Open

fix(opencode): fall back to opened directory when stored worktree is missing#47326
zbh-lzu wants to merge 2 commits into
anomalyco:devfrom
zbh-lzu:stale-worktree-recovery

Conversation

@zbh-lzu

@zbh-lzu zbh-lzu commented Sep 4, 2026

Copy link
Copy Markdown

Issue for this PR

Fixes #46330. That issue was closed by #46713, which fixed one frontend consumer, but the server still persists the stale project.worktree row.

Type of change

  • Bug fix

What does this PR do?

When a project directory is moved or renamed, project.id stays the same (it is derived from the git remote / root commit), so fromDirectory reuses the existing row and keeps its old worktree value — a path that no longer exists. Every consumer that resolves through that column (project list, session list project info, desktop) then opens a missing directory, and prompts fail with ENOENT or die silently.

This PR makes fromDirectory check whether the stored worktree exists on disk: if it is gone, fall back to the directory being opened and persist that through the existing upsert. When the stored worktree still exists (a second clone of the same repo), behavior is unchanged.

How did you verify your code works?

  • Added two regression tests in Project.fromDirectory: "replaces missing stored worktree with the opened directory" fails on dev and passes with this change; "keeps stored worktree when another clone exists on disk" pins the second-clone behavior.
  • Full packages/opencode/test/project/ suite passes (91 tests, 0 fail), typecheck and prettier clean.
  • Manual repro of Desktop: moving a project directory leaves stale worktree in project table — project shows "no git" and all prompts fail with ENOENT #46330: moved a repo on disk, pointed project.worktree back at the old path via sqlite, reopened the project through the API — worktree self-heals to the new path and new sessions attach to the right project instead of falling into global.

Screenshots / recordings

N/A (server-side only).

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@zbh-lzu

zbh-lzu commented Sep 13, 2026

Copy link
Copy Markdown
Author

Hi, friendly ping on this one. It's the server-side half of #46330#46713 fixed the frontend consumer and #47642 added the manual update API, but the stored worktree still isn't healed automatically when a project is reopened from its new location. Also, the required workflows (e2e / typecheck / unit) are still awaiting maintainer approval to run — would you mind approving them? Happy to make any changes if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Desktop: moving a project directory leaves stale worktree in project table — project shows "no git" and all prompts fail with ENOENT

1 participant