fix(project): use path-aware project identity to prevent clone collisions#17943
fix(project): use path-aware project identity to prevent clone collisions#17943oddvalue wants to merge 1 commit intoanomalyco:devfrom
Conversation
…ions When multiple local clones of the same git repo exist, the project ID was derived solely from the root commit hash, causing all clones to share one snapshot directory and project record. The last-opened clone would overwrite the worktree path, breaking file tracking for others. Combine the root commit with the worktree path (Hash.fast) so that separate clones get distinct project IDs while git worktrees of the same repo continue to share one ID via their common root. Fixes anomalyco#17940
|
The following comment was made by an LLM, it may be inaccurate: Potential Related PRs Found:
These PRs appear to address similar concerns around project identity and worktree/clone collisions. PR #14287 specifically mentions "repair split project IDs across worktrees" and PR #5647 addresses "worktree collision" with a separate ID approach—both are conceptually related to this PR's fix of using path-aware identity to prevent clone collisions. |
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
Issue for this PR
Closes #17940
Type of change
What does this PR do?
When multiple local clones of the same git repo exist, they all get the same project ID because it's derived solely from the root commit hash. This means they share one snapshot directory and one project record — the last-opened clone overwrites the worktree path, breaking file tracking for the others.
The fix changes the project ID to
Hash.fast(rootCommit + "\0" + worktree). Since git worktrees all resolve to the same common root path via--git-common-dir, they continue to share one project ID. Separate clones have different worktree paths, so they now get distinct IDs.This works because the
worktreevariable already captures the right distinction: it's the common root for worktrees (shared across all worktrees of a repo) and the repo's own path for standalone clones.The cached ID read (
readCachedId) was also moved after worktree resolution so it's only called once we know whether--git-common-dirsucceeded, and the worktree fallback (sandbox !== worktree) is preserved for the case where.gitis a file (as in worktrees) rather than a directory.Existing
.git/opencodecache files will be invalidated on first run since the ID format changed from raw root commit to a hash. The new ID is computed and cached automatically with no user-visible impact.How did you verify your code works?
Ran
bun testinpackages/opencode/— all 19 project tests pass including the updated clone test that now asserts distinct IDs. Full suite: 1332 pass, 17 skip, 1 pre-existing failure (unrelated file permissions test).Screenshots / recordings
N/A — no UI changes.
Checklist